Hello, i use RTOS 1.21. i want to post a mail from the rs232 callback function. but at runtime i get the bios error "A_badContext: bad calling context. Must be called from a Task." is this not possible?
best regards
Franz
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello, i use RTOS 1.21. i want to post a mail from the rs232 callback function. but at runtime i get the bios error "A_badContext: bad calling context. Must be called from a Task." is this not possible?
best regards
Franz
Hello, one aditional info. in the rs232 callback function mailbox_post is working. but in this function i call CmdLineProcess(...) and in this function mailbox_post is not working.
Thank you
Franz
Hello, i have one other question about UART read with callback. i have configured the uart with recive callback. but the callback function is not called. but if i add the line UART_read(uart0, uart_buffer,80); in a task the callback fkt is called immediately after the UART_read. why i had to do a UART_read in callback mode?
best regards
Franz
Hi Franz,
I'm somewhat confused as to when the UART_read() is and is not working. Can you provide an example or a C file?
What device are you using?
Hello, thank you for your answer. I think you misunderstood me.
this is the configuration of the UART:
/* Create a UART with data processing off. */
UART_Params_init(&uart0_Params);
uart0_Params.baudRate = 115200;//921600;//460800; //230400;
uart0_Params.writeMode = UART_MODE_BLOCKING; //UART_MODE_CALLBACK; //;
uart0_Params.writeDataMode = UART_DATA_TEXT;
uart0_Params.readDataMode = UART_DATA_TEXT;
uart0_Params.readReturnMode = UART_RETURN_NEWLINE;
uart0_Params.readEcho = UART_ECHO_ON;
uart0_Params.readMode = UART_MODE_CALLBACK;
uart0_Params.readCallback = &uart_callback_fxn; // pointer to a function
uart0 = UART_open(Board_UART, &uart0_Params);
if (uart0 == NULL) {
System_abort("Error opening the UART\n");
}
This is the callback fkt.
void uart_callback_fxn(UART_Handle handle, Char *p_buffer, int size)
{
// uint8_t uart_bytes_recived;
char char_buffer[80];
const char cmd_not_fnd[]={"command not found \r\n"};
const char to_few_arg[]={"too few arguments \r\n"};
const char arg_invaid[]={"argument is invalid\r\n"};
// char char_buffer[80];
p_buffer[size-1] = 0;
int16_t cmd_return = CmdLineProcess(p_buffer);
if (cmd_return)
{
switch (cmd_return)
{
// case 0: break;
case -1: //ustrncpy(char_buffer, cmd_not_fnd, ustrlen(cmd_not_fnd));
Mailbox_post (mail_debugger, &cmd_not_fnd, BIOS_NO_WAIT);
break;
case -2: //ustrncpy(char_buffer, "too many arguments \r\n",21);
Mailbox_post (mail_debugger, &to_few_arg, BIOS_NO_WAIT);
break;
case -3: //ustrncpy(char_buffer, "too few arguments \r\n",21);
Mailbox_post (mail_debugger, &char_buffer, BIOS_NO_WAIT);
break;
case -4: //ustrncpy(char_buffer, "argument is invalid\r\n",21);
Mailbox_post (mail_debugger, &arg_invaid, BIOS_NO_WAIT);
break;
}
}
}
1. But if i do it this way the callback fkt is never called. I think the callback fkt should called after receiving a newline, is it.
2. Why it is not possible to send a mail inside the CmdLineProcess fuktion?
if i add this line it is working.
void task_GPIO(void)
{
Task_sleep(1000); // sleep 1 sec. to let the USB connect
uint8_t char_buffer[80];
// MsgObj msg;
// msg.task_id = TASK_ID_GPIO;
char uart_buffer[20];
while(1)
{
Event_pend(event_GPIO, Event_Id_00, Event_Id_NONE, BIOS_WAIT_FOREVER);
UART_read(uart0, uart_buffer,80);
best regards Franz
Franz,
the readCallback function is run in a context from a Hwi. Within a Hwi (interrupt) context, you can't block on any SYS/BIOS APIs. I can see that the Mailbox_post() calls within the callback function take in a BIOS_NO_WAIT tick timeout, which is why it works in the callback, but I don't know what's happening in the CmdLineProcess() call.
For the UART callback itself, yes, you should get a callback when you either receive a "newline character" or when the buffer is full. Can you insert a breakpoint at the beginning of the function?
I also noticed this in you snippet...
char uart_buffer[20];
while(1)
{
Event_pend(event_GPIO, Event_Id_00, Event_Id_NONE, BIOS_WAIT_FOREVER);
UART_read(uart0, uart_buffer,80);
Thank you, i understand that i can not block within a HWI (callback_flt). (BP= break point)
My 2. Problem is still not solved. My main problem is that the callback fkt is not called. i insert a breakpoint at the beginning of the fkt but the program do no stop.
void uart_callback_fxn(UART_Handle handle, Char *p_buffer, int size)
{
// uint8_t uart_bytes_recived;
char char_buffer[80];
const char cmd_not_fnd[]={"command not found \r\n"};
const char to_few_arg[]={"too few arguments \r\n"};
const char arg_invaid[]={"argument is invalid\r\n"};
p_buffer[size-1] = 0;
BP int16_t cmd_return = CmdLineProcess(p_buffer);
But if i add the line in red in a task. the uart_callback_fxn works normally.
void task_GPIO(void)
{
Task_sleep(1000); // sleep 1 sec. to let the USB connect
char char_buffer[80];
// MsgObj msg;
// msg.task_id = TASK_ID_GPIO;
while(1)
{
Event_pend(event_GPIO, Event_Id_00, Event_Id_NONE, BIOS_WAIT_FOREVER);
UART_read(uart0, uart_buffer,80);
if (Mailbox_pend (mail_debugger, &char_buffer, BIOS_NO_WAIT) != 0) // if a new message is here
best regards
Franz
Franz,
Ah, I understand your question now.
Yes, a callback to your UART callback function will only occur after you call UART_read(). This is by design and this model is used throughout all the TI-RTOS drivers. Opening the UART on its own does not enable the triggering of the callback function.