#include "ch.h"
#include "hal.h"
#include "test.h"
#define CONSOLE_WA_SIZE THD_WORKING_AREA_SIZE(4096)
#define cputs(msg) chMsgSend(cdtp, (msg_t) msg)
static memory_pool_t mp1;
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);
}
}
static THD_FUNCTION(Thread1, arg)
{
(void) arg;
chRegSetThreadName("green");
while (TRUE)
{
cputs("green on");
chThdSleepMilliseconds(1000);
cputs("green off");
chThdSleepMilliseconds(2000);
}
}
static THD_FUNCTION(Thread2, arg)
{
(void) arg;
chRegSetThreadName("yellow");
while (TRUE)
{
cputs("yellow on");
chThdSleepMilliseconds(1000);
cputs("yellow off");
chThdSleepMilliseconds(2000);
}
}
static THD_FUNCTION(Thread3, arg)
{
(void) arg;
chRegSetThreadName("red");
while (TRUE)
{
cputs("red on");
chThdSleepMilliseconds(1000);
cputs("red off");
chThdSleepMilliseconds(2000);
}
}
int main(void)
{
halInit();
chSysInit();
chPoolObjectInit(&mp1, 4096, NULL);
int i;
for (i = 0; i < 3; i++) chPoolFree(&mp1, wa[i]);
cdtp = chThdCreateFromHeap(NULL, CONSOLE_WA_SIZE, NORMALPRIO, console_thread, NULL);
chThdCreateFromMemoryPool(&mp1, NORMALPRIO + 1, Thread1, NULL);
chThdSleepMilliseconds(1000);
chThdCreateFromMemoryPool(&mp1, NORMALPRIO + 1, Thread2, NULL);
chThdSleepMilliseconds(1000);
chThdCreateFromMemoryPool(&mp1, NORMALPRIO + 1, Thread3, NULL);
while (!chThdShouldTerminateX())
{
chThdSleepMilliseconds(1000);
}
return 0;
}