147 lines
3.7 KiB
C
147 lines
3.7 KiB
C
/*
|
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
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.
|
|
*/
|
|
static THD_WORKING_AREA(waThread1, 128);
|
|
static msg_t Thread1(void *arg) {
|
|
|
|
(void)arg;
|
|
chRegSetThreadName("blinker");
|
|
while (TRUE) {
|
|
palSetPad(GPIOC, GPIOC_LED);
|
|
chThdSleepMilliseconds(500);
|
|
palClearPad(GPIOC, GPIOC_LED);
|
|
chThdSleepMilliseconds(500);
|
|
}
|
|
}
|
|
|
|
/*===========================================================================*/
|
|
/* 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.
|
|
* - HAL initialization, this also initializes the configured device drivers
|
|
* and performs the board-specific initializations.
|
|
* - Kernel initialization, the main() function becomes a thread and the
|
|
* RTOS is active.
|
|
*/
|
|
halInit();
|
|
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);
|
|
|
|
/*
|
|
* Normal main() thread activity, in this demo it does nothing.
|
|
*/
|
|
while (TRUE) {
|
|
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);
|
|
}
|
|
}
|