Author Topic: Proper task state for UART reading  (Read 8948 times)

Offline akorud

  • Newbie
  • *
  • Posts: 31
    • View Profile
Proper task state for UART reading
« on: May 29, 2009, 03:36:00 PM »
Hi, maybe this is really simple question, but:
what is the proper state for task that only read data from UART? UTASKER_GO or UTASKER_STOP?
The task function looks like
Code: [Select]
if (debug_task_state == STATE_INIT) {
debug_uart_init();
debug_task_state = STATE_RUN;
}
while (fnRead(PortIDInternal, ucInputMessage, HEADER_LENGTH)) {
fnRead(PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // flush any unexpected messages (assuming they arrived from another task)
}

if (SerialPortID != 0 && (uart_rx_len = fnMsgs(SerialPortID))) {
while ((uart_rx_len = fnRead(SerialPortID, ucInputMessage, MEDIUM_MESSAGE)) != 0) {
console_cmd_receive((char*)ucInputMessage, uart_rx_len);
}
}
I'm not sure if data on UART will activate and schedule the task.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Proper task state for UART reading
« Reply #1 on: May 29, 2009, 03:49:08 PM »
Hi

UTASKER_GO is only used when a task should act as a polling task. It would however also receive UART messages since it would always check the UART input each time it runs.

Most task are mostly in the UTASKER_STOP state.
When UART data is received it will automatically be set to the UTASKER_ACTIVATE state so that it reads the data. The task will always return back to the UTASKER_STOP state after it has been run once.

Therefore the normal (and most logical) state for a task which only reacts to UART input is UTASKER_STOP.

Regards

Mark

Offline akorud

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Proper task state for UART reading
« Reply #2 on: June 01, 2009, 11:15:18 AM »
Thanks, and can you please confirm that:
Code: [Select]
{ "app",       fnApplication,  SMALL_QUEUE, (DELAY_LIMIT)(0.1 * SEC), 0, UTASKER_STOP},task will be invoked in 0.1s by uTasker (single shot)
Code: [Select]
{ "maintenace",fnTaskDebug,    SMALL_QUEUE, (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO), 0, UTASKER_ACTIVATE},task will be invoked immediately by uTasker (single shot)
Code: [Select]
{ "period",    fnTimer,        SMALL_QUEUE, (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO), 0, UTASKER_STOP},task will not be invoked by uTasker at all util another task send event to it or change state with uTaskerStateChange() call

regards,
Andriy

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Proper task state for UART reading
« Reply #3 on: June 01, 2009, 06:53:13 PM »
Hi Andriy

Yes, these tasks have the characteristics as you state.

Regards

Mark