Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on Storage events #1246

Merged
merged 1 commit into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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