chibiosでLチカの練習


グリーン、イエロー、レッドの順に点滅。

#include "ch.h"
#include "hal.h"

#define CONSOLE_WA_SIZE         THD_WORKING_AREA_SIZE(4096)
#define cputs(msg)              chMsgSend(cdtp, (msg_t) msg)
static thread_t * cdtp;
static THD_FUNCTION(console_thread, arg)
{
    (void) arg;
    while (!chThdShouldTerminateX())
    {
        thread_t * tp = chMsgWait();
        puts((char *) chMsgGet(tp));
        fflush(stdout);
        chMsgRelease(tp, MSG_OK);
    }
}
int main(void)
{
    halInit();
    chSysInit();
    cdtp = chThdCreateFromHeap(NULL, CONSOLE_WA_SIZE, NORMALPRIO, console_thread, NULL);
    while (!chThdShouldTerminateX())
    {
        cputs("green on");
        chThdSleepMilliseconds(500);
        cputs("green off");
        cputs("yellow on");
        chThdSleepMilliseconds(500);
        cputs("yellow off");
        cputs("red on");
        chThdSleepMilliseconds(500);
        cputs("red off");
    }
    return 0;
}