fileio and thumb drive help.
Hello,
I try to use fileio with usb host. (PIC24FJ256GB110)
In my project I include :
-Header
-Framework
-fileio
fileio.h
-usb
usb.h
usb_ch9.h
usb_common.h
usb_hal.h
usb_hal_pic24.h
usb_hal_pic24f.h
usb_host.h
usb_host_msd.h
usb_host_msd_scsi.h
sytem_config.h
usb_config.h
fileio_config.h
- Source Files
-Framework
-fileio
fileio.c
-usb
usb_hal_pic24.c
usb_host.c
usb_host_msd.c
usb_host_msd_scsi.c
usb_config.c
**************************************************************************
for init in main :
//Initialize the stack
FILEIO_Initialize();
FILEIO_RegisterTimestampGet(GetTimestamp);
//Initialize the stack
USBHostInit(0);
and add task :
USBHostTasks();
USBHostMSDTasks();
IN main.c add :
/****************************************************************************
Function:
bool USB_ApplicationEventHandler( uint8_t address, USB_EVENT event,
void *data, uint32_t size )
Summary:
This is the application event handler. It is called when the stack has
an event that needs to be handled by the application layer rather than
by the client driver.
Description:
This is the application event handler. It is called when the stack has
an event that needs to be handled by the application layer rather than
by the client driver. If the application is able to handle the event, it
returns true. Otherwise, it returns false.
Precondition:
None
Parameters:
uint8_t address - Address of device where event occurred
USB_EVENT event - Identifies the event that occured
void *data - Pointer to event-specific data
uint32_t size - Size of the event-specific data
Return Values:
true - The event was handled
false - The event was not handled
Remarks:
The application may also implement an event handling routine if it
requires knowledge of events. To do so, it must implement a routine that
matches this function signature and define the USB_HOST_APP_EVENT_HANDLER
macro as the name of that function.
***************************************************************************/
bool USB_ApplicationEventHandler(uint8_t address, USB_EVENT event, void *data, uint32_t size) {
switch ((int) event) {
case EVENT_VBUS_REQUEST_POWER:
// The data pointer points to a byte that represents the amount of power
// requested in mA, divided by two. If the device wants too much power,
// we reject it.
return true;
case EVENT_VBUS_RELEASE_POWER:
//This means that the device was removed
return true;
break;
/* Here are various other events that a user might want to handle
* or be aware of. In this demo we are not handling them so we
* will just return true to allow the stack to move on from the error.
*/
case EVENT_HUB_ATTACH:
case EVENT_UNSUPPORTED_DEVICE:
case EVENT_CANNOT_ENUMERATE:
case EVENT_CLIENT_INIT_ERROR:
case EVENT_OUT_OF_MEMORY:
case EVENT_UNSPECIFIED_ERROR: // This should never be generated.
return true;
break;
case EVENT_MSD_ATTACH:
//APP_MountDrive (address);
deviceAddress = address;
deviceAttached = true;
break;
default:
break;
}
return false;
}
// Placeholder function to get the timestamp for FILEIO operations
void GetTimestamp(FILEIO_TIMESTAMP * timestamp) {
// Populate the timestamp field with some inaccurate timestamp information
timestamp->date.bitfield.day = 5;
timestamp->date.bitfield.month = 1;
timestamp->date.bitfield.year = 33;
timestamp->time.bitfield.hours = 8;
timestamp->time.bitfield.secondsDiv2 = 20;
timestamp->time.bitfield.minutes = 10;
timestamp->timeMs = 0;
}
Declarations in main.c :
static uint8_t deviceAddress = 0;
void GetTimestamp(FILEIO_TIMESTAMP * timestamp);
// Placeholder function for the File I/O driver structure's IO Initialize function
void USBDummyIOInitialize(void * mediaParameters);
void USBDummyIOInitialize(void * mediaParameters) {
}
// Declare a FILEIO_DRIVE_CONFIG structure to describe which functions the File I/O library will use to communicate with the media
const FILEIO_DRIVE_CONFIG gUSBDrive = {
(FILEIO_DRIVER_IOInitialize) USBDummyIOInitialize, // Function to initialize the I/O pins used by the driver.
(FILEIO_DRIVER_MediaDetect) USBHostMSDSCSIMediaDetect, // Function to detect that the media is inserted.
(FILEIO_DRIVER_MediaInitialize) USBHostMSDSCSIMediaInitialize, // Function to initialize the media.
(FILEIO_DRIVER_MediaDeinitialize) USBHostMSDSCSIMediaReset, // Function to de-initialize the media.
(FILEIO_DRIVER_SectorRead) USBHostMSDSCSISectorRead, // Function to read a sector from the media.
(FILEIO_DRIVER_SectorWrite) USBHostMSDSCSISectorWrite, // Function to write a sector to the media.
(FILEIO_DRIVER_WriteProtectStateGet) USBHostMSDSCSIWriteProtectState, // Function to determine if the media is write-protected.
};