The default output for (System_printf) in the examples I have been looking at is the CIO console. I wanted to also send it to UART0 (where I also have a command prompt). This is what I HAVE been doing:
- In my RTOS config:
SysMin.outputFxn = "&externOutputFunc"; - In code I have a multiple console facility where a session is either a telnet sesison or a UART - too large to paste all here. But the output function mentioned in the RTOS config looks like this (potentially writing to both):
#define PDB_ENABLE_CIO_OUTPUT
extern int HOSTwrite(int, const char *, unsigned);
int externOutputFunc(const char *buf, unsigned int size)
{
int ret = 0;if (stg_defOutputSession)
ret = SessWrite(stg_defOutputSession, buf, size);#ifdef PDB_ENABLE_CIO_OUTPUT
{
// This chunk taken from generated (default) code when outputFxn is
// left at "null"
int printCount;
while (size != 0) {
printCount = HOSTwrite(1, buf, size);
if ((printCount <= 0) || (printCount > size)) {
break; /* ensure we never get stuck in an infinite loop */
}
size -= printCount;
buf = buf + printCount;
}
}
#endifreturn ret;
} - The UART in this case was opened as follows:
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_TEXT;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
sess->uart = UART_open(uartId, &uartParams); - When the session is a UART (and in the case in question it is) SessWrite() just executes a
UART_write(sess->uart, (void*)buffer, size);
The above works quite well, with the only gotcha that System_printf()/flush calls from the main() context are only sent to the CIO console. I tried to move the setting of stg_defOutputSession into main and the UART_write dies because we are not in a task context (semaphore).
So my questions/options are:
- Really? We don't expect folks to write to UART in main() that does not seem reasonable.
- I don't think I can just delay the flush - because a flush will occur if a buffer is filled and then I have an unpredictable system
- I'm pretty sure I don't want to switch to UART in callback mode just for this issue
- I'm also pretty sure that while I launch the UART task from main() that it does not actually run till I call BIOS_Start()
- Are System_printf() logs intended only for development only (CIO console connected)
- Should I just buffer (another layer of buffer) if not in Task context? Also seems a little heavy
Please let me know if I'm looking it all wrong
Thanks!