diff options
Diffstat (limited to 'testhal/STM32F4xx/SDC/main.c')
-rw-r--r-- | testhal/STM32F4xx/SDC/main.c | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/testhal/STM32F4xx/SDC/main.c b/testhal/STM32F4xx/SDC/main.c index f02221398..33975654a 100644 --- a/testhal/STM32F4xx/SDC/main.c +++ b/testhal/STM32F4xx/SDC/main.c @@ -14,10 +14,20 @@ limitations under the License.
*/
+#include <string.h>
+
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
+#include "shell.h"
+
+/*
+ * SDIO configuration.
+ */
+static const SDCConfig sdccfg = {
+ 0
+};
/*
* LED blinker thread, times are in milliseconds.
@@ -35,10 +45,61 @@ static msg_t Thread1(void *arg) { }
}
+/*===========================================================================*/
+/* Command line related. */
+/*===========================================================================*/
+
+#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
+
+void cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]) {
+
+ if (argc != 1) {
+ chprintf(chp, "Usage: sdiotest read|write|all\r\n");
+ return;
+ }
+
+ /* Card presence check.*/
+ if (!blkIsInserted(&SDCD1)) {
+ chprintf(chp, "Card not inserted, aborting.\r\n");
+ return;
+ }
+
+ /* Connection to the card.*/
+ chprintf(chp, "Connecting: ");
+ if (sdcConnect(&SDCD1)) {
+ chprintf(chp, "failed\r\n");
+ return;
+ }
+ chprintf(chp, "OK\r\n");
+ chprintf(chp, "*** Card CSD content is: ");
+ chprintf(chp, "%X %X %X %X \r\n", (&SDCD1)->csd[3], (&SDCD1)->csd[2],
+ (&SDCD1)->csd[1], (&SDCD1)->csd[0]);
+
+ if ((strcmp(argv[0], "read") == 0) ||
+ (strcmp(argv[0], "all") == 0)) {
+
+ }
+ if ((strcmp(argv[0], "write") == 0) ||
+ (strcmp(argv[0], "all") == 0)) {
+
+ }
+}
+
+static const ShellCommand commands[] = {
+ {"sdio", cmd_sdiotest},
+ {NULL, NULL}
+};
+
+static const ShellConfig shell_cfg1 = {
+ (BaseSequentialStream *)&SD6,
+ commands
+};
+
/*
* Application entry point.
*/
int main(void) {
+ thread_t *shelltp = NULL;
/*
* System initializations.
@@ -51,6 +112,21 @@ int main(void) { chSysInit();
/*
+ * Shell manager initialization.
+ */
+ shellInit();
+
+ /*
+ * Activates the serial driver 6 using the driver default configuration.
+ */
+ sdStart(&SD6, NULL);
+
+ /*
+ * Initializes the SDIO drivers.
+ */
+ sdcStart(&SDCD1, &sdccfg);
+
+ /*
* Creates the blinker thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
@@ -59,6 +135,12 @@ int main(void) { * Normal main() thread activity, in this demo it does nothing.
*/
while (TRUE) {
- chThdSleepMilliseconds(500);
+ if (!shelltp)
+ shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
+ else if (chThdTerminatedX(shelltp)) {
+ chThdRelease(shelltp); /* Recovers memory of the previous shell. */
+ shelltp = NULL; /* Triggers spawning of a new shell. */
+ }
+ chThdSleepMilliseconds(1000);
}
}
|