LoginSignup
0
0

More than 5 years have passed since last update.

chibiosでLチカの練習

Posted at

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

#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;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0