/* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. ChibiOS/RT is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ChibiOS/RT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Concepts and parts of this file have been contributed by Scott (skute). */ /** * @file chevents.c * @brief Events code. * * @addtogroup events * @details Event Flags, Event Sources and Event Listeners. *

Operation mode

* Each thread has a mask of pending event flags inside its @p Thread * structure. * Operations defined for event flags: * - Wait, the invoking thread goes to sleep until a certain * AND/OR combination of event flags becomes pending. * - Clear, a mask of event flags is cleared from the pending * events mask, the cleared event flags mask is returned (only the * flags that were actually pending and then cleared). * - Signal, an event mask is directly ORed to the mask of the * signaled thread. * - Broadcast, each thread registered on an Event Source is * signaled with the event flags specified in its Event Listener. * - Dispatch, an events mask is scanned and for each bit set * to one an associated handler function is invoked. Bit masks are * scanned from bit zero upward. * . * An Event Source is a special object that can be "broadcasted" by * a thread or an interrupt service routine. Broadcasting an Event * Source has the effect that all the threads registered on the * Event Source will be signaled with an events mask.
* An unlimited number of Event Sources can exists in a system and * each thread can be listening on an unlimited number of * them. * @pre In order to use the Events APIs the @p CH_USE_EVENTS option must be * enabled in @p chconf.h. * @post Enabling events requires 1-4 (depending on the architecture) * extra bytes in the @p Thread structure. * @{ */ #include "ch.h" #if CH_USE_EVENTS || defined(__DOXYGEN__) /** * @brief Registers an Event Listener on an Event Source. * @details Once a thread has registered as listener on an event source it * will be notified of all events broadcasted there. * @note Multiple Event Listeners can specify the same bits to be ORed to * different threads. * * @param[in] esp pointer to the @p EventSource structure * @param[in] elp pointer to the @p EventListener structure * @param[in] mask the mask of event flags to be ORed to the thread when * the event source is broadcasted * * @api */ void chEvtRegisterMask(EventSource *esp, EventListener *elp, eventmask_t mask) { chDbgCheck((esp != NULL) && (elp != NULL), "chEvtRegisterMask"); chSysLock(); elp->el_next = esp->es_next; esp->es_next = elp; elp->el_listener = currp; elp->el_mask = mask; elp->el_flags = 0; chSysUnlock(); } /** * @brief Unregisters an Event Listener from its Event Source. * @note If the event listener is not registered on the specified event * source then the function does nothing. * @note For optimal performance it is better to perform the unregister * operations in inverse order of the register operations (elements * are found on top of the list). * * @param[in] esp pointer to the @p EventSource structure * @param[in] elp pointer to the @p EventListener structure * * @api */ void chEvtUnregister(EventSource *esp, EventListener *elp) { EventListener *p; chDbgCheck((esp != NULL) && (elp != NULL), "chEvtUnregister"); p = (EventListener *)esp; chSysLock(); while (p->el_next != (EventListener *)esp) { if (p->el_next == elp) { p->el_next = elp->el_next; break; } p = p->el_next; } chSysUnlock(); } /** * @brief Clears the pending events specified in the mask. * * @param[in] mask the events to be cleared * @return The pending events that were cleared. * * @api */ eventmask_t chEvtGetAndClearEvents(eventmask_t mask) { eventmask_t m; chSysLock(); m = currp->p_epending & mask; currp->p_epending &= ~mask; chSysUnlock(); return m; } /** * @brief Adds (OR) a set of event flags on the current thread, this is * @b much faster than using @p chEvtBroadcast() or @p chEvtSignal(). * * @param[in] mask the event flags to be added * @return The current pending events mask. * * @api */ eventmask_t chEvtAddEvents(eventmask_t mask) { chSysLock(); mask = (currp->p_epending |= mask); chSysUnlock(); return mask; } /** * @brief Signals all the Event Listeners registered on the specified Event * Source. * @details This function variants ORs the specified event flags to all the * threads registered on the @p EventSource in addition to the event * flags specified by the threads themselves in the * @p EventListener objects. * @post This function does not reschedule so a call to a rescheduling * function must be performed before unlocking the kernel. Note that * interrupt handlers always reschedule on exit so an explicit * reschedule must not be performed in ISRs. * * @param[in] esp pointer to the @p EventSource structure * @param[in] flags the flags set to be added to the listener flags mask * * @iclass */ void chEvtBroadcastFlagsI(EventSource *esp, flagsmask_t flags) { EventListener *elp; chDbgCheckClassI(); chDbgCheck(esp != NULL, "chEvtBroadcastMaskI"); elp = esp->es_next; while (elp != (EventListener *)esp) { elp->el_flags |= flags; chEvtSignalI(elp->el_listener, elp->el_mask); elp = elp->el_next; } } /** * @brief Returns the flags associated to an @p EventListener. * @details The flags are returned and the @p EventListener flags mask is * cleared. * * @param[in] elp pointer to the @p EventListener structure * @return The flags added to the listener by the associated * event source. * * @iclass */ flagsmask_t chEvtGetAndClearFlags(EventListener *elp) { flagsmask_t flags; chSysLock(); flags = elp->el_flags; elp->el_flags = 0; chSysUnlock(); return flags; } /** * @brief Adds a set of event flags directly to specified @p Thread. * * @param[in] tp the thread to be signaled * @param[in] mask the event flags set to be ORed * * @api */ void chEvtSignal(Thread *tp, eventmask_t mask) { chDbgCheck(tp != NULL, "chEvtSignal"); chSysLock(); chEvtSignalI(tp, mask); chSchRescheduleS(); chSysUnlock(); } /** * @brief Adds a set of event flags directly to specified @p Thread. * @post This function does not reschedule so a call to a rescheduling * function must be performed before unlocking the kernel. Note that * interrupt handlers always reschedule on exit so an explicit * reschedule must not be performed in ISRs. * * @param[in] tp the thread to be signaled * @param[in] mask the event flags set to be ORed * * @iclass */ void chEvtSignalI(Thread *tp, eventmask_t mask) { chDbgCheckClassI(); chDbgCheck(tp != NULL, "chEvtSignalI"); tp->p_epending |= mask; /* Test on the AND/OR conditions wait states.*/ if (((tp->p_state == THD_STATE_WTOREVT) && ((tp->p_epending & tp->p_u.ewmask) != 0)) || ((tp->p_state == THD_STATE_WTANDEVT) && ((tp->p_epending & tp->p_u.ewmask) == tp->p_u.ewmask))) chSchReadyI(tp)->p_u.rdymsg = RDY_OK; } /** * @brief Signals all the Event Listeners registered on the specified Event * Source. * @details This function variants ORs the specified event flags to all the * threads registered on the @p EventSource in addition to the event * flags specified by the threads themselves in the * @p EventListener objects. * * @param[in] esp pointer to the @p EventSource structure * @param[in] flags the flags set to be added to the listener flags mask * * @api */ void chEvtBroadcastFlags(EventSource *esp, flagsmask_t flags) { chSysLock(); chEvtBroadcastFlagsI(esp, flags); chSchRescheduleS(); chSysUnlock(); } /** * @brief Returns the flags associated to an @p EventListener. * @details The flags are returned and the @p EventListener flags mask is * cleared. * * @param[in] elp pointer to the @p EventListener structure * @return The flags added to the listener by the associated * event source. * * @iclass */ flagsmask_t chEvtGetAndClearFlagsI(EventListener *elp) { flagsmask_t flags; flags = elp->el_flags; elp->el_flags = 0; return flags; } /** * @brief Invokes the event handlers associated to an event flags mask. * * @param[in] mask mask of the event flags to be dispatched * @param[in] handlers an array of @p evhandler_t. The array must have size * equal to the number of bits in eventmask_t. * * @api */ void chEvtDispatch(const evhandler_t *handlers, eventmask_t mask) { eventid_t eid; chDbgCheck(handlers != NULL, "chEvtDispatch"); eid = 0; while (mask) { if (mask & EVENT_MASK(eid)) { chDbgAssert(handlers[eid] != NULL, "chEvtDispatch(), #1", "null handler"); mask &= ~EVENT_MASK(eid); handlers[eid](eid); } eid++; } } #if CH_OPTIMIZE_SPEED || !CH_USE_EVENTS_TIMEOUT || defined(__DOXYGEN__) /** * @brief Waits for exactly one of the specified events. * @details The function waits for one event among those specified in * @p mask to become pending then the event is cleared and returned. * @note One and only one event is served in the function, the one with the * lowest event id. The function is meant to be invoked into a loop in * order to serve all the pending events.
* This means that Event Listeners with a lower event identifier have * an higher priority. * * @param[in] mask mask of the event flags that the function should wait * for, @p ALL_EVENTS enables all the events * @return The mask of the lowest id served and cleared event. * * @api */ eventmask_t chEvtWaitOne(eventmask_t mask) { Thread *ctp = currp; eventmask_t m; chSysLock(); if ((m = (ctp->p_epending & mask)) == 0) { ctp->p_u.ewmask = mask; chSchGoSleepS(THD_STATE_WTOREVT); m = ctp->p_epending & mask; } m &= -m; ctp->p_epending &= ~m; chSysUnlock(); return m; } /** * @brief Waits for any of the specified events. * @details The function waits for any event among those specified in * @p mask to become pending then the events are cleared and returned. * * @param[in] mask mask of the event flags that the function should wait * for, @p ALL_EVENTS enables all the events * @return The mask of the served and cleared events. * * @api */ eventmask_t chEvtWaitAny(eventmask_t mask) { Thread *ctp = currp; eventmask_t m; chSysLock(); if ((m = (ctp->p_epending & mask)) == 0) { ctp->p_u.ewmask = mask; chSchGoSleepS(THD_STATE_WTOREVT); m = ctp->p_epending & mask; } ctp->p_epending &= ~m; chSysUnlock(); return m; } /** * @brief Waits for all the specified events. * @details The function waits for all the events specified in @p mask to * become pending then the events are cleared and returned. * * @param[in] mask mask of the event flags that the function should wait * for, @p ALL_EVENTS requires all the events * @return The mask of the served and cleared events. * * @api */ eventmask_t chEvtWaitAll(eventmask_t mask) { Thread *ctp = currp; chSysLock(); if ((ctp->p_epending & mask) != mask) { ctp->p_u.ewmask = mask; chSchGoSleepS(THD_STATE_WTANDEVT); } ctp->p_epending &= ~mask; chSysUnlock(); return mask; } #endif /* CH_OPTIMIZE_SPEED || !CH_USE_EVENTS_TIMEOUT */ #if CH_USE_EVENTS_TIMEOUT || defined(__DOXYGEN__) /** * @brief Waits for exactly one of the specified events. * @details The function waits for one event among those specified in * @p mask to become pending then the event is cleared and returned. * @note One and only one event is served in the function, the one with the * lowest event id. The function is meant to be invoked into a loop in * order to serve all the pending events.
* This means that Event Listeners with a lower event identifier have * an higher priority. * * @param[in] mask mask of the event flags that the function should wait * for, @p ALL_EVENTS enables all the events * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. * - @a TIME_INFINITE no timeout. * . * @return The mask of the lowest id served and cleared event. * @retval 0 if the operation has timed out. * * @api */ eventmask_t chEvtWaitOneTimeout(eventmask_t mask, systime_t time) { Thread *ctp = currp; eventmask_t m; chSysLock(); if ((m = (ctp->p_epending & mask)) == 0) { if (TIME_IMMEDIATE == time) { chSysUnlock(); return (eventmask_t)0; } ctp->p_u.ewmask = mask; if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK) { chSysUnlock(); return (eventmask_t)0; } m = ctp->p_epending & mask; } m &= -m; ctp->p_epending &= ~m; chSysUnlock(); return m; } /** * @brief Waits for any of the specified events. * @details The function waits for any event among those specified in * @p mask to become pending then the events are cleared and * returned. * * @param[in] mask mask of the event flags that the function should wait * for, @p ALL_EVENTS enables all the events * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. * - @a TIME_INFINITE no timeout. * . * @return The mask of the served and cleared events. * @retval 0 if the operation has timed out. * * @api */ eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t time) { Thread *ctp = cur
/*
    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 "shell.h"
#include "chprintf.h"

#include "ff.h"

#define SDC_DATA_DESTRUCTIVE_TEST   FALSE

#define SDC_BURST_SIZE      8 /* how many sectors reads at once */
static uint8_t outbuf[MMCSD_BLOCK_SIZE * SDC_BURST_SIZE + 1];
static uint8_t  inbuf[MMCSD_BLOCK_SIZE * SDC_BURST_SIZE + 1];

/* FS object.*/
static FATFS SDC_FS;

/* FS mounted and ready.*/
static bool_t fs_ready = FALSE;

/**
 * @brief   Parody of UNIX badblocks program.
 *
 * @param[in] start       first block to check
 * @param[in] end         last block to check
 * @param[in] blockatonce number of blocks to check at once
 * @param[in] pattern     check pattern
 *
 * @return              The operation status.
 * @retval SDC_SUCCESS  operation succeeded, the requested blocks have been
 *                      read.
 * @retval SDC_FAILED   operation failed, the state of the buffer is uncertain.
 */
bool_t badblocks(uint32_t start, uint32_t end, uint32_t blockatonce, uint8_t pattern){
  uint32_t position = 0;
  uint32_t i = 0;

  chDbgCheck(blockatonce <= SDC_BURST_SIZE, "badblocks");

  /* fill control buffer */
  for (i=0; i < MMCSD_BLOCK_SIZE * blockatonce; i++)
    outbuf[i] = pattern;

  /* fill SD card with pattern. */
  position = start;
  while (position < end){
    if (sdcWrite(&SDCD1, position, outbuf, blockatonce))
      goto ERROR;
    position += blockatonce;
  }

  /* read and compare. */
  position = start;
  while (position < end){
    if (sdcRead(&SDCD1, position, inbuf, blockatonce))
      goto ERROR;
    if (memcmp(inbuf, outbuf, blockatonce * MMCSD_BLOCK_SIZE) != 0)
      goto ERROR;
    position += blockatonce;
  }
  return FALSE;

ERROR:
  return TRUE;
}

/**
 *
 */
void fillbuffer(uint8_t pattern, uint8_t *b){
  uint32_t i = 0;
  for (i=0; i < MMCSD_BLOCK_SIZE * SDC_BURST_SIZE; i++)
    b[i] = pattern;
}

/**
 *
 */
void fillbuffers(uint8_t pattern){
  fillbuffer(pattern, inbuf);
  fillbuffer(pattern, outbuf);
}

/**
 *
 */
void cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]){
  (void)argc;
  (void)argv;
  uint32_t i = 0;

  chprintf(chp, "Trying to connect SDIO... ");
  chThdSleepMilliseconds(100);

  if (!sdcConnect(&SDCD1)) {

    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]);

    chprintf(chp, "Single aligned read...");
    chThdSleepMilliseconds(100);
    if (sdcRead(&SDCD1, 0, inbuf, 1))
      chSysHalt();
    chprintf(chp, " OK\r\n");
    chThdSleepMilliseconds(100);


    chprintf(chp, "Single unaligned read...");
    chThdSleepMilliseconds(100);
    if (sdcRead(&SDCD1, 0, inbuf + 1, 1))
      chSysHalt();
    if (sdcRead(&SDCD1, 0, inbuf + 2, 1))
      chSysHalt();
    if (sdcRead(&SDCD1, 0, inbuf + 3, 1))
      chSysHalt();
    chprintf(chp, " OK\r\n");
    chThdSleepMilliseconds(100);


    chprintf(chp, "Multiple aligned reads...");
    chThdSleepMilliseconds(100);
    fillbuffers(0x55);
    /* fill reference buffer from SD card */
    if (sdcRead(&SDCD1, 0, inbuf, SDC_BURST_SIZE))
      chSysHalt();
    for (i=0; i<1000; i++){
      if (sdcRead(&SDCD1, 0, outbuf, SDC_BURST_SIZE))
        chSysHalt();
      if (memcmp(inbuf, outbuf, SDC_BURST_SIZE * MMCSD_BLOCK_SIZE) != 0)
        chSysHalt();
    }
    chprintf(chp, " OK\r\n");
    chThdSleepMilliseconds(100);


    chprintf(chp, "Multiple unaligned reads...");
    chThdSleepMilliseconds(100);
    fillbuffers(0x55);
    /* fill reference buffer from SD card */
    if (sdcRead(&SDCD1, 0, inbuf + 1, SDC_BURST_SIZE))
      chSysHalt();
    for (i=0; i<1000; i++){
      if (sdcRead(&SDCD1, 0, outbuf + 1, SDC_BURST_SIZE))
        chSysHalt();
      if (memcmp(inbuf, outbuf, SDC_BURST_SIZE * MMCSD_BLOCK_SIZE) != 0)
        chSysHalt();
    }
    chprintf(chp, " OK\r\n");
    chThdSleepMilliseconds(100);

#if SDC_DATA_DESTRUCTIVE_TEST

    chprintf(chp, "Single aligned write...");
    chThdSleepMilliseconds(100);
    fillbuffer(0xAA, inbuf);
    if (sdcWrite(&SDCD1, 0, inbuf, 1))
      chSysHalt();
    fillbuffer(0, outbuf);
    if (sdcRead(&SDCD1, 0, outbuf, 1))
      chSysHalt();
    if (memcmp(inbuf, outbuf, MMCSD_BLOCK_SIZE) != 0)
      chSysHalt();
    chprintf(chp, " OK\r\n");

    chprintf(chp, "Single unaligned write...");
    chThdSleepMilliseconds(100);
    fillbuffer(0xFF, inbuf);
    if (sdcWrite(&SDCD1, 0, inbuf+1, 1))
      chSysHalt();
    fillbuffer(0, outbuf);
    if (sdcRead(&SDCD1, 0, outbuf+1, 1))
      chSysHalt();
    if (memcmp(inbuf+1, outbuf+1, MMCSD_BLOCK_SIZE) != 0)
      chSysHalt();
    chprintf(chp, " OK\r\n");

    chprintf(chp, "Running badblocks at 0x10000 offset...");
    chThdSleepMilliseconds(100);
    if(badblocks(0x10000, 0x11000, SDC_BURST_SIZE, 0xAA))
      chSysHalt();
    chprintf(chp, " OK\r\n");
#endif /* !SDC_DATA_DESTRUCTIVE_TEST */


    /**
     * Now perform some FS tests.
     */

    FRESULT err;
    uint32_t clusters;
    FATFS *fsp;
    FIL FileObject;
    uint32_t bytes_written;
    uint32_t bytes_read;
    FILINFO filinfo;
    uint8_t teststring[] = {"This is test file\r\n"};

    chprintf(chp, "Register working area for filesystem... ");
    chThdSleepMilliseconds(100);
    err = f_mount(0, &SDC_FS);
    if (err != FR_OK){
      chSysHalt();
    }
    else{
      fs_ready = TRUE;
      chprintf(chp, "OK\r\n");
    }


#if SDC_DATA_DESTRUCTIVE_TEST
    chprintf(chp, "Formatting... ");
    chThdSleepMilliseconds(100);
    err = f_mkfs (0,0,0);
    if (err != FR_OK){
      chSysHalt();
    }
    else{
      chprintf(chp, "OK\r\n");
    }
#endif /* SDC_DATA_DESTRUCTIVE_TEST */


    chprintf(chp, "Mount filesystem... ");
    chThdSleepMilliseconds(100);
    err = f_getfree("/", &clusters, &fsp);
    if (err != FR_OK) {
      chSysHalt();
    }
    chprintf(chp, "OK\r\n");
    chprintf(chp,
             "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n",
             clusters, (uint32_t)SDC_FS.csize,
             clusters * (uint32_t)SDC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE);


    chprintf(chp, "Create file \"chtest.txt\"... ");
    chThdSleepMilliseconds(100);
    err = f_open(&FileObject, "0:chtest.txt", FA_WRITE | FA_OPEN_ALWAYS);
    if (err != FR_OK) {
      chSysHalt();
    }
    chprintf(chp, "OK\r\n");
    chprintf(chp, "Write some data in it... ");
    chThdSleepMilliseconds(100);
    err = f_write(&FileObject, teststring, sizeof(teststring), (void *)&bytes_written);
    if (err != FR_OK) {
      chSysHalt();
    }
    else
      chprintf(chp, "OK\r\n");

    chprintf(chp, "Close file \"chtest.txt\"... ");
    err = f_close(&FileObject);
    if (err != FR_OK) {
      chSysHalt();
    }
    else
      chprintf(chp, "OK\r\n");

    chprintf(chp, "Check file size \"chtest.txt\"... ");
    err = f_stat("0:chtest.txt", &filinfo);
    chThdSleepMilliseconds(100);
    if (err != FR_OK) {
      chSysHalt();
    }
    else{
      if (filinfo.fsize == sizeof(teststring))
        chprintf(chp, "OK\r\n");
      else
        chSysHalt();
    }

    chprintf(chp, "Check file content \"chtest.txt\"... ");
    err = f_open(&FileObject, "0:chtest.txt", FA_READ | FA_OPEN_EXISTING);
    chThdSleepMilliseconds(100);
    if (err != FR_OK) {
      chSysHalt();
    }
    uint8_t buf[sizeof(teststring)];
    err = f_read(&FileObject, buf, sizeof(teststring), (void *)&bytes_read);
    if (err != FR_OK) {
      chSysHalt();
    }
    else{
      if (memcmp(teststring, buf, sizeof(teststring)) != 0){
        chSysHalt();
      }
      else{
        chprintf(chp, "OK\r\n");
      }
    }

    chprintf(chp, "Umount filesystem... ");
    f_mount(0, NULL);
    chprintf(chp, "OK\r\n");

    chprintf(chp, "Disconnecting from SDIO...");
    chThdSleepMilliseconds(100);
    if (sdcDisconnect(&SDCD1))
      chSysHalt();
    chprintf(chp, " OK\r\n");
    chprintf(chp, "------------------------------------------------------\r\n");
    chprintf(chp, "All tests passed successfully.\r\n");
    chThdSleepMilliseconds(100);
  }
  else{
    chSysHalt();
  }
}


/*
 * SDIO configuration.
 */
static const SDCConfig sdccfg = {
  0
};

/**
 *
 */
static SerialConfig ser_cfg = {
    115200,
    0,
    0,
    0,
};
static const ShellCommand commands[] = {
  {"sdiotest", cmd_sdiotest},
  {NULL, NULL}
};
static const ShellConfig shell_cfg1 = {
  (BaseSequentialStream *)&SD2,
  commands
};

/*
 * Application entry point.
 */
int main(void) {
  halInit();
  chSysInit();

  /* start debugging serial link */
  sdStart(&SD2, &ser_cfg);
  shellInit();
  static WORKING_AREA(waShell, 2048);
  shellCreateStatic(&shell_cfg1, waShell, sizeof(waShell), NORMALPRIO);

  /*
   * Initializes the SDIO drivers.
   */
  sdcStart(&SDCD1, &sdccfg);

  /*
   * Normal main() thread activity.
   * Blinking signaling about successful passing.
   */
  while (TRUE) {
    palTogglePad(GPIOB, GPIOB_LED_R);
    chThdSleepMilliseconds(100);
  }
}