Towards more robust start-up code

Document created by John Winters Employee on Feb 27, 2015Last modified by Diana Torres on Feb 28, 2017
Version 2Show Document
  • View in full screen mode

Standard DSC startup code most often includes a do loop.

That do loop execution assigns a known value to the LA register.

If you are using startup code that does NOT include a do loop, you need to explicitly initialize the LA register to an address that is not inside of an interrupt service routine.

Why?  Standard save all and restore all code included by the IDE for interrupt handlers can itself be interrupted.

There is a window of opportunity to be interrupted after the  restore all routine pushes the HWS (Hardware stack register) twice (thus setting both Loop flag in the SR and NL in the OMR registers).

If you get interrupted just after doing the HWS pushes,  you can enter a fast ISR without clearing the LF, and then if your PC matches the uninitialized LA register (which aquires any possible value after power up) while in the middle of the interrupting ISR, then end of loop is recongnized and program flow becomes erratic after that.   


Just initialize LA if you change the default stationery, please.


Depending on the version of IDE you are using, you may need to worry about the shadow register for M01 as well.

Version 8.3 for DSC does not initialize this register, which can lead to issues.

If you are using CW 10.6, the currently supported version, this register is initialized by default.


Please compare your start-up code to that produced by CW 10.6 for the part you are using if it fits this mask:  MC56F8xx, ..8xxx, ..8xxxx.