…or, in fact, the cc_slave
core.
I’ve been looking into the code, and noticed that a hardware serial rx interrupt initiates a rather long chain of calls:
in ReUART.cpp
-
ISR
on an USART0_RX_vect vector calls_rx_complete_irq()
-
_rx_complete_irq()
callsuart_byte_recv()
-
uart_byte_recv()
callscc_parse()
fromcore.c
, and, if the incoming message is complete, -
cc_parse()
callsparcer()
, also incore.c
I think this last step is a bit too much to be processed in an interrupt, so what I’ve done is I’ve included a simple flag into cc_handle_t
:
typedef struct cc_handle_t {
void (*response_cb)(void *arg);
void (*events_cb)(void *arg);
int comm_state, msg_state;
cc_msg_t *msg_rx, *msg_tx;
int device_id;
int msg_rx_ok; // <-- ADDED
} cc_handle_t;
that in cc_parser
I set to 1 if a message is received, and let the code finish processing the interrupt without calling the parser()
:
// crc
case 6:
if (crc8(msg->header, CC_MSG_HEADER_SIZE + msg->data_size) == byte)
{
//parser(handle); // commented this out, we'll do this later
handle->msg_rx_ok = 1; // ADDED for quicker exit out of an interrupt
msg_ok = 1;
}
and then I process the received message with parcer()
in cc_process()
, basically in the loop()
of a main sketch, right before we get to checking the actuators’ states!
void cc_process(void)
{
// ADDED BEGIN
// see if we have an incoming message to process
cc_handle_t *handle = &g_cc_handle;
if (handle->msg_rx_ok) {
handle->msg_rx_ok = 0;
parser(handle);
}
// ADDED END
// process each actuator going through all assignments
// data update messages will be queued and sent in the next frame
cc_actuators_process(g_cc_handle.events_cb);
}
It seems to work smoothly. This even has allowed me to do some more heavy coding in the parcer()
, like introducing new events and calling callbacks on those with output to LCD - for debugging purposes et al, which in case of the original code was not possible, e.g.:
raise_event(handle, CC_EV_HANDSHAKE_INITIATED, 0);
...
raise_event(handle, CC_EV_HANDSHAKE_SUCCESSFULL, 0);
...
raise_event(handle, CC_EV_DEBUG, 0);
@jon, if you guys can also look into this, if it makes sense for the future incarnations of the code?
Cheers!
P.S. Ooh, now that I’m on a break form my band, I’m having so much fun digging this code!
P.P.S. But I can’t, for the life of me, get the library running on Arduino Mega. I hope this little change helps me debugging it.