Page 1 of 1
Threads switching problem
Posted: Mon Sep 30, 2013 2:02 pm
by Adam
Hello,
My code has many threads as lwip stack, http_server, UDP sender, UDP receiver etc. Everything worked fine. Until...:
I created a simple Thread, where is only infinite loop with variable test:
Code: Select all
WORKING_AREA(waThread_485toETH, 1024);
msg_t Thread_485toETH(void *arg) {
while(1){
if(ptr_var != NULL) {do some stuff}
}
return (msg_t)0;
}
MCU works and dont freeze, but in debuuger it looks like he won´ts yield a control to another thread. Another threads are(look like?) stopped and solution is putting some delay into the loop. Delay in loop is not wantable, the thread is necessary to be "every-ready".
How can I fix this problem? Thank you very much for your help;)
Adam
Re: Threads switching problem
Posted: Mon Sep 30, 2013 2:08 pm
by Giovanni
Hi,
That thread would block any thread at lower priority because it never releases the CPU. Working as intended, probably you just need to redefine the priorities of your threads.
Giovanni
Re: Threads switching problem
Posted: Mon Sep 30, 2013 4:20 pm
by Adam
Hi Giovanni,
thanks for your reply.
The thread "Thread_485toETH" has LOWPRIO priority. Other threads have NORMALPRIO priority. I tried "chThdYield()" at the end of loop, but problem is still here:(
Adam
Re: Threads switching problem
Posted: Mon Sep 30, 2013 5:24 pm
by Giovanni
There is some other kind of problem then, are you running with all debug options enabled? is something caught?
Giovanni
Re: Threads switching problem
Posted: Wed Oct 02, 2013 11:07 am
by Adam
Hi,
I had turned on all debug options and I didnt catch anything about threads switching problem. Then I tried redefine all priorities of the all threads again and seems to be working.
Another question: When I had turned on all debug options, system is halted on chMtxTryLock() and the reason is "dbg_isr_cnt = 1". chMtxLock is located in "rxchar()" callback of UART driver. What does it mean "dbg_isr_cnt" and where is set? I found only this description: "dbg_isr_cnt ... ISR nesting level".
- Does my function trying to lock again, when the mutex is already locked?
- Can I use mutexes in callback?
I´m sorry of my english and maybe my stupid questions.
Adam.
Re: Threads switching problem
Posted: Wed Oct 02, 2013 11:28 am
by Giovanni
Hi,
When the system is halted the global variable dbg_panic_msg points to a string that describes the problem or is an encoded error message, something like "SV#4".
After stopping the program retrieve the message. In chdebug.c there is the documentation of error codes.
Giovanni
Re: Threads switching problem
Posted: Wed Oct 02, 2013 11:50 am
by Adam
Yes, the error code is "SV#4, misplaced @p chSysLock().", but I dont know, how to fix.
Re: Threads switching problem
Posted: Wed Oct 02, 2013 12:23 pm
by Giovanni
There are two possible causes for that error:
1) You call chSysLock() from an ISR or a callback, this can also happen by calling a normal API from ISR or callback, see your stack trace after stopping the program.
2) You have two consecutive calls to chSysLock(), the function cannot be called recursively.
Giovanni