I have to realize a thread to manage the serial port. Exactly, i would use thread system to verify continually if my USART2-Rx pin receive a character.
Looking to the various example on net and also on this forum, I'm trying to write code in this way:
Code: Select all
static THD_WORKING_AREA(waSerThd, 128);
static msg_t SerThd(void *arg) {
while(TRUE) {
// --- Enable GPIOA Port, at Pin: 2-3, to use USART. [Tx-Rx]
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
sdStart(&SD2, &uartCfg); // starts the serial driver with uartCfg as a config
// // --- Show welcome message
// sdWrite(&SD2, (uint8_t *) stringRUN, strlen(stringRUN));
// chThdSleepMilliseconds(500);
event_listener_t elSerData;
eventmask_t flags;
chEvtRegisterMask((EventSource *)chnGetEventSource(&SD2), &elSerData, EVENT_MASK(1));
while(TRUE) {
chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
flags = chEvtGetAndClearFlags(&elSerData);
if(flags & CHN_INPUT_AVAILABLE) {
msg_t charbuf;
do {
charbuf = chnGetTimeout(&SD2, TIME_IMMEDIATE);
if( charbuf != Q_TIMEOUT ) {
chSequentialStreamPut(&SD2, charbuf);
}
}
while (charbuf != Q_TIMEOUT);
}
}
return 0;
}
}
..but i have a compilation error when Thread-code launch the command
Code: Select all
chEvtRegisterMask..an error regarding on the eventSource.
Where I wrong..?? Is possible do what i would do or there are gap in my conception of ChibiOS system..??
Thanks, Alfonso