I'd like to know if its possible to have an interrupt force the scheduler to switch context to a specific task in RTOS. I'm working with microCOS OS
Here is the task which performs the keyscan and posts the character into a mailbox, I need to add some more features to this code like debounce and auto repeat but I need to sort out a trigger mechanism to get it working properly.
I am not sure how to use polling or interrupts to accomplish this
static void AppTaskKeyscan (void *p_arg)
{
CPU_INT08U debouncing = 1;
CPU_INT16U key;
key_t button={0,0,0};
(void)p_arg;
while (DEF_TRUE)
{
static CPU_INT08U pattern;
key=P10;
OSTimeDlyHMSM(0, 0, 0, 50);
P10=0x0E;
if ((pattern=P10)==0xee)
{button.data='1', button.live=1;}
else if (pattern==0xde)
{button.data='4', button.live=1;}
else if (pattern==0xbe)
{button.data='7', button.live=1;}
else if (pattern==0x7e)
{button.data='*', button.live=1;}
else
{
P10=0x0d;
if ((pattern=P10)==0xed)
{button.data='2', button.live=1;}
else if (pattern==0xdd)
{button.data='5', button.live=1;}
else if (pattern==0xbd)
{button.data='8', button.live=1;}
else if (pattern==0x7d)
{button.data='0', button.live=1;}
else
{
P10=0x0b;
if ((pattern=P10)==0xeb)
{button.data='3', button.live=1;}
else if (pattern==0xdb)
{button.data='6', button.live=1;}
else if (pattern==0xbb)
{button.data='9', button.live=1;}
else if (pattern==0x7b)
{button.data='#', button.live=1;}
else
{
P10=0x07;
if ((pattern=P10)==0xe7)
{button.data='A', button.live=1;}
else if (pattern==0xd7)
{button.data='B', button.live=1;}
else if (pattern==0xb7)
{button.data='C', button.live=1;}
else if (pattern==0x77)
{button.data='D', button.live=1;}
else
button.live=0;
}
}
}
P10=pattern;
if (button.live==0)
OSTimeDlyHMSM(0, 0, 0, 50);
else
{
if (P10==pattern)
OSTimeDlyHMSM(0, 0, 0, 50);
else
button.live=0;
}
P10=0x00;
if (button.live) //if button live, set unread flag to 1 and start count down
{
button.unread=1;
}
if(button.unread&&button.data!='X')
{
key=button.data;
OSMboxPost(KeyMbox, (void *) &key);
button.live=0;
button.unread=0;
}
OSTimeDlyHMSM(0, 0, 0, 200);
} // End of While
}