Re: [atomthreads] Porting atomthread on Arduino Uno
On Tue, Sep 11, 2012 at 4:19 PM, Kelvin Lawson i...@atomthreads.com wrote: Hi Ashwin, I would confirm that the timer interrupt is occurring. The timer ISR is in atomport.c (TIMER1_COMPA_vect). Thanks for the reply. Yes timer interrupts are occurring but by default scheduler is not called. It works by calling scheduler in timer interrupt. If you replaced the standard Atomthreads timer ISR with an alternative one that didn't call the scheduler then that makes sense. Actually I havn't replaced timer. Here is diff for working case. diff --git a/atomthreads/kernel/atomtimer.c b/atomthreads/kernel/atomtimer.c index 3693295..91eb053 100755 --- a/atomthreads/kernel/atomtimer.c +++ b/atomthreads/kernel/atomtimer.c @@ -68,7 +68,7 @@ #include atom.h /* Data types */ @@ -299,7 +299,7 @@ void atomTimerTick (void) { /* Increment the system tick count */ system_ticks++; - + atomSched(TRUE); /* Check for any callbacks that are due */ atomTimerCallbacks (); } Thanks, Kelvin. I am new to embedded and have very little experience but I'm very enthu abt it. Few days back I bought Arduino Uno with 32KB memory and 16Mhz. Later I found atomthread multi threading RTOS kernel on Internet. By changing some configuration port file for avr in the kernel I am able to run main thread (Thanks for excellent documentation). Even I have ported some cpp files from arduino to kernel and did some changes in Makefile to run LED blinking code in thread context that that too worked :-). I am using default uart port provided by atomthread and its working. Even I am using printf for printing on serial port but I dont knw whether should I use printf or prinf_P but it working. Even I am able to create multiple threads and I can see all the prints in those thread. But I am not able to use atomTimerDelay in threadContex. Thread is going in hang state when I call this function. Here do I need to do some time call to so ?? Even when thread contex is over then this thread is recreated or board is re-booted. Is something wrong with scheduler or timer ?? -- With Regards, Ashwin Vasani +91 8446611430 -- With Regards, Ashwin Vasani +91 8446611430
Re: [atomthreads] A qustion about atomThreadSwitch
Hi Elvin, It might be a bit easier to understand with the comments left in: if (old_tcb != new_tcb) { /* Set the new currently-running thread pointer */ curr_tcb = new_tcb; /* Call the architecture-specific context switch */ archContextSwitch (old_tcb, new_tcb); } /** * The context switch shifted execution to a different thread. By the time * we get back here, we are running in old_tcb context again. Clear its * suspend status now that we're back. */ old_tcb-suspended = FALSE; The suspended flag is set to TRUE when a thread is being suspended, and is set to FALSE when it runs again. This is used as housekeeping, to keep a track of what suspension state a thread is in. For any thread that calls into this function, the calling thread (itself) is old_tcb and the new thread being switched in is new_tcb. When you return from archContextSwitch() *in the context of the original calling thread* then the running thread is back to the original thread (old_tcb), so it needs to mark itself as not suspended any more, by setting its flag to FALSE again. Thanks, Kelvin. On 11 September 2012 12:29, elvinwds elvin...@gmail.com wrote: Hi All: I am a new to RTOS and have been studying the source code of atomthreads for a while, and now I have question about the atomThreadSwitch function in atomkernel.c. The source code without comments of atomThreadSwitch is : static void atomThreadSwitch(ATOM_TCB *old_tcb, ATOM_TCB *new_tcb) { if (old_tcb != new_tcb) { /* Set the new currently-running thread pointer */ curr_tcb = new_tcb; /* Call the architecture-specific context switch */ archContextSwitch (old_tcb, new_tcb); } old_tcb-suspended = FALSE; } My question is about the last line : old_tcb-suspended = FALSE. Only when the old thread been scheduled back in, the RTOS can run to here. This means that when the RTOS runs to here , the old thread has been scheduled out, so the state of the old thread can not be suspended, And why have to set the state of suspended false here? With Regards, Elvin