Originally Posted by
CommonTater
Ok... so it's formatted with FAT32 ... no worries.
Now we know your problem is elsewhere...
Post your complete code as it is now, lets see what we're up against.
what do you mean by formatted with FAT32?
this is my function that contain the code
Code:
void firmware()
{
FILE *file;
FILE *fileRead;
long lSize;
char * buffer;
char buf[100];
size_t result;
gpio_ioctl_cb_t gpio_iocb;
unsigned char leds;
open_drivers();
gpio_iocb.ioctl_code = VOS_IOCTL_GPIO_SET_MASK;
gpio_iocb.value = 0xff;
vos_dev_ioctl(hGPIO_PORT_A, &gpio_iocb);
do
{
if (usbhost_connect_state(hUSBHOST_2) == PORT_STATE_ENUMERATED)
{
hBOMS = boms_attach(hUSBHOST_2, VOS_DEV_BOMS);
if (hBOMS == NULL)
{
leds = led3;
vos_dev_write(hGPIO_PORT_A, &leds, 1, NULL);
vos_delay_msecs(1000);
break;
}
hFAT_FILE_SYSTEM = fat_attach(hBOMS, VOS_DEV_FAT_FILE_SYSTEM);
if (hFAT_FILE_SYSTEM == NULL)
{
leds = led3;
vos_dev_write(hGPIO_PORT_A, &leds, 1, NULL);
vos_delay_msecs(1000);
break;
}
fsAttach(hFAT_FILE_SYSTEM);
fileRead = fopen("F:\\02\\read.txt", "r");
file = fopen("F:\\02\\write.txt","w");
if (file == NULL)
{
leds = led3;
vos_dev_write(hGPIO_PORT_A, &leds, 1, NULL);
vos_delay_msecs(1000);
break;
}
fseek (fileRead , 0 , SEEK_END);
lSize = ftell (fileRead);
rewind (fileRead);
buffer = (char*) malloc (sizeof(char)*lSize);
result = fread (buffer,1,50,fileRead);
if (fwrite((buffer), strlen(buffer), sizeof(char), file) == -1)
{
leds = led3;
vos_dev_write(hGPIO_PORT_A, &leds, 1, NULL);
vos_delay_msecs(1000);
}
if (fclose(file) == -1)
{
leds = led3;
vos_dev_write(hGPIO_PORT_A, &leds, 1, NULL);
vos_delay_msecs(1000);
}
if (fclose(fileRead) == -1)
{
leds = led3;
vos_dev_write(hGPIO_PORT_A, &leds, 1, NULL);
vos_delay_msecs(1000);
}
leds = led1;
vos_dev_write(hGPIO_PORT_A, &leds, 1, NULL);
fat_detach(hFAT_FILE_SYSTEM);
boms_detach(hBOMS);
leds = 0;
vos_dev_write(hGPIO_PORT_A, &leds, 1, NULL);
vos_delay_msecs(5000);
}
}
while (1);
}