402
« on: June 03, 2008, 12:05:18 PM »
Hi Mark,
I am starting my first task again (had a break for quiet a few months from utasker, another project came up, but now have time to start working on it again), and looked at this thread.
What I wish to do (just to get familiar with tasks again), is to have a serial task woken up with every key pressed. After the first key is pressed, a 5 second timer is set, and I have to press 'Enter' before the 5 seconds elapsed.
The task gets woken up okay with the key pressed, but doesnt get called when timer times out, here is what I done:
#define TASK_OWNSERIAL 'O'
{ "OSerialComm",fnTaskSerialComm, SMALL_QUEUE, 0, 0, UTASKER_STOP}, // and have included in node.
set up serial port to wake up task 'fnTaskSerialComm' when key pressed with following line:
tInterfaceParameters.Task_to_wake = TASK_OWNSERIAL;
Task rountine:
#define E_TIMER_TIMEOUT 1
void fnTaskSerialComm(TTASKTABLE *ptrTaskTable)
{
unsigned char ucInputMessage[RX_BUFFER_SIZE]; // reserve space for receiving messages
char Tmp[10];
static char RecReturn=0,TimerOn=0;
QUEUE_HANDLE PortIDInternal = ptrTaskTable->TaskID; // queue ID for task input
while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH ))
{ // check input queue
switch ( ucInputMessage[ MSG_SOURCE_TASK ] )
{ // switch depending on message source
case TIMER_EVENT: // timer event
if (E_TIMER_TIMEOUT == ucInputMessage[ MSG_TIMER_EVENT ])
{
if(!RecReturn) //only if Enter key not pressed.. BUT also left this out to make sure below called, but didnt work
fnDebugMsg("\n\r ** RET NOT ENTERED IN 5 SECONDS ** \n\r");
RecReturn=TimerOn=0;
}
}
}
//serial catch here... simply display 'pressed' if a key is pressed...
while (fnMsgs(SerialPortID))
{
fnRead( SerialPortID, &ucInputMessage[0], 1) ;
if(ucInputMessage[0]==13)
RecReturn=1;
fnDebugMsg("pressed");
if(!TimerOn)
{
uTaskerMonoTimer( TASK_OWNSERIAL, (DELAY_LIMIT)(5*SEC), E_TIMER_TIMEOUT );// start monitor timer
TimerOn=1;
}
}
}
I tried removing the 'if(!TimerOn) ' and 'if(!RecReturn)' , and press key once,just to make sure the timer gets called. But The timer never times out. I never get 'fnDebugMsg("\n\r ** RET NOT ENTERED IN 5 SECONDS ** \n\r");'
I set a breakpoint at when the timer gets called, so I know it does get called, and when it does, I then set breakpoint at start of task to catch timeout , which never gets called..
Can you point me to where I am going wrong?
Thanks
Neil