I would like to use event driven serialdriver. I made a test environment:
hw: I connected TxD to RxD to receive my sent characters.
sw: I sent only one 73 bytes length package with a console command. (7 bytes framing, 64 bytes data with incremental contents and 2 bytes of crc.)
HAL configuration is:
#define SERIAL_BUFFERS_SIZE 64
Here is my event listener code:
Code: Select all
event_listener_t serial_listener;
chEvtRegisterMaskWithFlags(chnGetEventSource(&SD_DRIVER), &serial_listener,
EVENT_MASK(1),
CHN_INPUT_AVAILABLE|SD_PARITY_ERROR|SD_FRAMING_ERROR|SD_OVERRUN_ERROR|SD_NOISE_ERROR|SD_BREAK_DETECTED);
while(TRUE) {
palSetPad(GPIOD, GPIOD_LED5);
eventmask_t evt = chEvtWaitAny(ALL_EVENTS);
if (evt & EVENT_MASK(1)) {
eventflags_t flags = chEvtGetAndClearFlags(&serial_listener);
if (flags&CHN_INPUT_AVAILABLE)
handle_serial_data(&motorola);
if (flags&SD_FRAMING_ERROR)
++motorola.receive_framing_error;
if (flags&SD_OVERRUN_ERROR)
++motorola.receive_overrun;
if (flags&SD_NOISE_ERROR)
++motorola.receive_noise_error;
}
chThdSleepMicroseconds(SERIAL_SLEEP_TIME_US);
}I send data with chnWrite(&SD1, buffer, bufferlen)
An interest thing is that, when I sent a packet which is 73 bytes length I cannot get any event. I can get an event after I send 12 packets (which is 876bytes!). Of course the receive buffer is mixed to an unusable data content.
When event subsystem have to send an event, when the input queue filled?
Maybe I made a mistake in event configuration?
thx
Zamek