diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-06-05 08:39:49 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-06-05 08:39:49 +0000 |
commit | 03b4c7ddcb08a565104c91859f51e56e513e3fd0 (patch) | |
tree | 231f4fa2c172739f5f7bebd4a7ea7245c4e7622b /demos/ARMCM3-STM32F103ZG-FATFS/main.c | |
parent | 9b147c25513490e959acf299a0fed9beaee04457 (diff) | |
download | ChibiOS-03b4c7ddcb08a565104c91859f51e56e513e3fd0.tar.gz ChibiOS-03b4c7ddcb08a565104c91859f51e56e513e3fd0.tar.bz2 ChibiOS-03b4c7ddcb08a565104c91859f51e56e513e3fd0.zip |
FatFs demo for the STM32F103ZG using the SDC driver.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3028 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'demos/ARMCM3-STM32F103ZG-FATFS/main.c')
-rw-r--r-- | demos/ARMCM3-STM32F103ZG-FATFS/main.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/demos/ARMCM3-STM32F103ZG-FATFS/main.c b/demos/ARMCM3-STM32F103ZG-FATFS/main.c index 49fa093f0..fc128abb8 100644 --- a/demos/ARMCM3-STM32F103ZG-FATFS/main.c +++ b/demos/ARMCM3-STM32F103ZG-FATFS/main.c @@ -286,7 +286,7 @@ static const ShellCommand commands[] = { };
static const ShellConfig shell_cfg1 = {
- (BaseChannel *)&SD2,
+ (BaseChannel *)&SD1,
commands
};
@@ -302,11 +302,11 @@ static void InsertHandler(eventid_t id) { (void)id;
/*
- * On insertion MMC initialization and FS mount.
+ * On insertion SDC initialization and FS mount.
*/
- if (sdcConnect(&SDCD1)) {
+ if (sdcConnect(&SDCD1))
return;
- }
+
err = f_mount(0, &SDC_FS);
if (err != FR_OK) {
sdcDisconnect(&SDCD1);
@@ -321,7 +321,8 @@ static void InsertHandler(eventid_t id) { static void RemoveHandler(eventid_t id) {
(void)id;
- sdcDisconnect(&SDCD1);
+ if (sdcGetDriverState(&SDCD1) == SDC_ACTIVE)
+ sdcDisconnect(&SDCD1);
fs_ready = FALSE;
}
@@ -352,6 +353,12 @@ static msg_t Thread1(void *arg) { * Application entry point.
*/
int main(void) {
+ static const evhandler_t evhndl[] = {
+ InsertHandler,
+ RemoveHandler
+ };
+ Thread *shelltp = NULL;
+ struct EventListener el0, el1;
/*
* System initializations.
@@ -364,9 +371,16 @@ int main(void) { chSysInit();
/*
- * Activates the serial driver 1 using the driver default configuration.
+ * Activates the serial driver 1 and SDC driver 1 using default
+ * configuration.
*/
sdStart(&SD1, NULL);
+ sdcStart(&SDCD1, NULL);
+
+ /*
+ * Shell manager initialization.
+ */
+ shellInit();
/*
* Activates the card insertion monitor.
@@ -380,11 +394,17 @@ int main(void) { /*
* Normal main() thread activity, in this demo it does nothing except
- * sleeping in a loop and check the button state.
+ * sleeping in a loop and listen for events.
*/
+ chEvtRegister(&inserted_event, &el0, 0);
+ chEvtRegister(&removed_event, &el1, 1);
while (TRUE) {
- if (!palReadPad(GPIOG, GPIOG_USER_BUTTON))
- TestThread(&SD1);
- chThdSleepMilliseconds(500);
+ if (!shelltp)
+ shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
+ else if (chThdTerminated(shelltp)) {
+ chThdRelease(shelltp); /* Recovers memory of the previous shell. */
+ shelltp = NULL; /* Triggers spawning of a new shell. */
+ }
+ chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS));
}
}
|