Page 1 of 1

MSP430 dbg_check_lock

Posted: Fri Jan 18, 2013 3:00 am
by saraben
In the MSP430 port, if CH_DBG_SYSTEM_STATE_CHECK is enabled I find the program panics at the first chThdSleepMilliseconds it meets in a new thread.
The sequence is like this

Code: Select all

   chThdCreateStatic
      chSysLock();
      Creates new thread
      Switches to new thread
          chThdSleepMilliseconds
              chSysLock(); > Panic as dbg_lock_cnt is already 1


Is this a limitation for the MSP430 or is there an issue.
I found if i put a dbg_check_unlock(); at the begining of every thread, before the while loop, it overcomes the issue but it does not appear to be a good solution. It should be a part of thread creation if required. I couldn't see the eatra unlock on other ports.

Regards
saraben

Re: MSP430 dbg_check_lock

Posted: Fri Jan 18, 2013 9:14 am
by Giovanni
This is definitely a bug, probably it should go in the threads trampoline code like for other ports. I will very and eventually open a ticket.

Giovanni

Re: MSP430 dbg_check_lock

Posted: Sat Jan 19, 2013 3:14 am
by saraben
Giovanni,
I had a closer look and found out why this has happend.

In the update for 5.0.1, the C routine _port_thread_start() was replaced by pure assembly code.
The line chSysUnlock(); was just replaced by eint which of course is fine for the operation of ChibiOS but looses track of the dbg_lock_cnt.
While the switch to the new thread is successful, the next attempt at switching fails because dbg_lock_cnt is not 0.

A few things I noticed. dbg_lock_cnt is only ever 0 or 1. If eveything is done correctly, dbg_lock_cnt should be the inverted state of the OS enable interrupts (global in most ports ). The test could then be of the state of the OS enable interrupts without using a dbg_lock_cnt.
This would also check against code that locks interrupts directly and then calls Chibios routines, which it shouldn't do.

EDIT: Testing the irq enable bit is not a good idea for debuging. Between testing and locking, another thread could jump in and invalidate the test.

Regards
saraben

Re: MSP430 dbg_check_lock

Posted: Sat Jan 19, 2013 8:10 am
by Giovanni
Hi,

Thanks for finding, I'll add a call in the asm module to release the lock counter.

Giovanni