My thinking was that the printf() logic is going to take exactly the same time to generate a character stream regardless of where it goes. It's the time to save that stream somewhere that varies with method (and even with your 2-thread solution you can reach a point where there is no more temporary output buffer space). I simply sized my serial port output buffer such that writing should never block. (But I did find in stress testing that I had far too much to say, and writing to the serial port was slowing things down. Solution: be more to the point in messages).
I've initialised mailbox queues from all over the place; usually I do it as part of setting up one of the tasks that uses it (which is often off the main thread), but as long as you set things up in the right order and don't try to use an uninitialised mailbox (and use permanently allocated memory for buffer and scratchpad, of course), I don't see why you would have a problem.
Strings to mailboxes
Re: Strings to mailboxes
Isnt the chprintf function blocking? If not that could be a solution as well. Need to take care of syslock like you did though.
Hmmm, weird. If I do this it works:
If I move the Object init to my main function (after ch init) it stops working for some reason.
Hmmm, weird. If I do this it works:
Code: Select all
THD_WORKING_AREA(serial_output_thread_wa, 256);
THD_FUNCTION(serial_output_thread, arg) {
(void)arg;
chRegSetThreadName("Uart Comm Thread");
msg_t msg = 0;
chMBObjectInit(&serial_mb, serial_mb_buffer, 10);
BaseSequentialStream *stream = (BaseSequentialStream *)&SD3;
while (true) {
chMBFetchTimeout(&serial_mb, &msg, TIME_INFINITE);
const char *s_msg = (const char *)msg;
chprintf(stream, "%010d: %s \r\n",chVTGetSystemTime(), s_msg);
}
}
If I move the Object init to my main function (after ch init) it stops working for some reason.
Re: Strings to mailboxes
chprintf() isn't of itself blocking; it just passes characters on to a character stream, which is what determines blocking behaviour. If you use Chibi's SERIAL driver (think I said 'UART' earlier, which might have confused things), that has a circular output buffer of configurable size. So as long as the buffer doesn't get full, chprintf() won't block.
Re: Strings to mailboxes
Neat, thanks!
I see to have a general issue with using mailboxes defined in other c files though.
When I define:
In my header file and then initialize the Mailbox from the same c file, I can post messages to it from within that same c file. However when I include the .h file in another c file and try to post a message there I receive a timeout. Not sure whats happening there....
I see to have a general issue with using mailboxes defined in other c files though.
When I define:
Code: Select all
static mailbox_t state_mb;
static msg_t state_mb_buffer[10];
In my header file and then initialize the Mailbox from the same c file, I can post messages to it from within that same c file. However when I include the .h file in another c file and try to post a message there I receive a timeout. Not sure whats happening there....
Re: Strings to mailboxes
Its the 'static' qualifier - means the variable is local to the source file in which it appears.
So you will have a copy of the mailbox structure in each source file.
I tend to create my own API which hides the Chibi-specific bits.
So you will have a copy of the mailbox structure in each source file.
I tend to create my own API which hides the Chibi-specific bits.
Who is online
Users browsing this forum: No registered users and 11 guests