Skip to content

Commit

Permalink
Work on Storage events (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Mar 7, 2019
1 parent b9c0f9e commit 4adee56
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 58 deletions.
4 changes: 4 additions & 0 deletions src/HAL/Include/nanoHAL_Windows_Storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#define USB_MSD_DRIVE_LETTER "E:"
#define USB_MSD_DRIVE_PATH USB_MSD_DRIVE_LETTER"\\"

// Storage events sub-categories
#define EVENT_STORAGE_DEVICE_INSERTION 0x01
#define EVENT_STORAGE_DEVICE_REMOVAL 0x02

// enum with the supported drives in Windows.Storage
typedef enum Storage_Drives
{
Expand Down
2 changes: 1 addition & 1 deletion targets/CMSIS-OS/ChibiOS/Include/Target_Windows_Storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define SDCARD_POLLING_DELAY (500)


#define USB_MSD_POLLING_INTERVAL (2)
#define USB_MSD_POLLING_INTERVAL (1000)
#define USB_MSD_POLLING_DELAY (1000)

#ifdef __cplusplus
Expand Down
80 changes: 23 additions & 57 deletions targets/CMSIS-OS/ChibiOS/common/Target_Windows_Storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
#include <target_windows_storage_config.h>
#include <nanoHAL_Windows_Storage.h>
#include <Target_Windows_Storage.h>
#include <nanoHAL_v2.h>

#if HAL_USBH_USE_MSD
#include "usbh/dev/msd.h"
#endif

extern void PostManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uint32_t data2);

///////////////////////////////////////////
// code specific to USB MSD

Expand Down Expand Up @@ -101,6 +104,9 @@ void SdcardInsertHandler(eventid_t id)
else
{
sdCardFileSystemReady = true;

// post event to managed app
PostManagedEvent( EVENT_STORAGE, 0, EVENT_STORAGE_DEVICE_INSERTION, Storage_Drives_SDCard );
}
}

Expand All @@ -112,6 +118,9 @@ void SdCardRemoveHandler(eventid_t id)
sdcDisconnect(&SD_CARD_DRIVER);

sdCardFileSystemReady = false;

// post event to managed app
PostManagedEvent( EVENT_STORAGE, 0, EVENT_STORAGE_DEVICE_REMOVAL, Storage_Drives_SDCard );
}

__attribute__((noreturn))
Expand Down Expand Up @@ -167,67 +176,11 @@ static bool usbCardFileSystemReady = false;

static FATFS usbMsd_FS;

// USB MSD monitor timer
//static virtual_timer_t usbMsdMonitorTimer;

// USB MSD event sources
//static event_source_t usbInsertedEvent;

// Insertion monitor timer callback function.
// static void UsbMsdMonitorCallback(void *p)
// {
// USBHMassStorageLUNDriver* msBlk = p;

// chSysLockFromISR();

// if (blkGetDriverState(msBlk) == BLK_ACTIVE)
// {
// // BLK: Active, connect
// usbhmsdLUNConnect(msBlk);
// }

// if (blkGetDriverState(msBlk) == BLK_READY)
// {
// // BLK: Ready
// chEvtBroadcastI(&usbInsertedEvent);
// }

// chVTSetI(&usbMsdMonitorTimer, TIME_MS2I(USB_MSD_POLLING_DELAY), UsbMsdMonitorCallback, msBlk);
// chSysUnlockFromISR();
// }

// USB Mass storage device monitor
// static void StartUsbMsdMonitor(void *p)
// {
// chEvtObjectInit(&usbInsertedEvent);

// chSysLock();

// chVTSetI(&usbMsdMonitorTimer, TIME_MS2I(USB_MSD_POLLING_DELAY), UsbMsdMonitorCallback, p);

// chSysUnlock();
// }

// USB MSD insertion event handler
// static void UsbMsdInsertHandler(eventid_t id)
// {
// (void)id;

// // TODO
// }

__attribute__((noreturn))
void UsbMsdWorkingThread(void const * argument)
{
FRESULT err;

// static const evhandler_t usbEventHandler[] =
// {
// UsbMsdInsertHandler
// };

// event_listener_t usbEventListener0;

// start USB host
usbhStart(&USB_MSD_DRIVER);

Expand Down Expand Up @@ -263,9 +216,22 @@ void UsbMsdWorkingThread(void const * argument)
else
{
usbCardFileSystemReady = true;

// post event to managed app
PostManagedEvent( EVENT_STORAGE, 0, EVENT_STORAGE_DEVICE_INSERTION, Storage_Drives_UsbMsd );
}
}
//chEvtBroadcastI(&usbInsertedEvent);
}

if (blkGetDriverState(msBlk) == BLK_STOP)
{
if(usbCardFileSystemReady)
{
usbCardFileSystemReady = false;

// post event to managed app
PostManagedEvent( EVENT_STORAGE, 0, EVENT_STORAGE_DEVICE_REMOVAL, Storage_Drives_UsbMsd );
}
}

usbhMainLoop(&USB_MSD_DRIVER);
Expand Down

0 comments on commit 4adee56

Please sign in to comment.