diff code_part1/OSTC_code_c_part2/p2_deco.c @ 235:ade0848c8b8b

New runtime asserts when compiled in DEBUG more. When __DEBUG is defined, the assert() calls are checked, and PLED_resetdebugger is called when the condition fails.
author JeanDo
date Sat, 19 Mar 2011 11:34:32 +0100
parents bb8940caebe1
children 3dbeacf42e9e
line wrap: on
line diff
--- a/code_part1/OSTC_code_c_part2/p2_deco.c	Thu Mar 17 18:32:16 2011 +0100
+++ b/code_part1/OSTC_code_c_part2/p2_deco.c	Sat Mar 19 11:34:32 2011 +0100
@@ -467,6 +467,50 @@
 //////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////
 
+//////////////////////////////////////////////////////////////////////////////
+#ifdef __DEBUG
+void assert_failed(PARAMETER short int line)
+{
+    extern void PLED_resetdebugger(void);
+    extern unsigned short temp10;
+
+    temp10 = line;
+    PLED_resetdebugger();
+}
+#endif
+//////////////////////////////////////////////////////////////////////////////
+// When calling C code from ASM context, the data stack pointer and
+// frames should be reset. Bank8 is used by stack, when not doing hashing.
+
+#ifdef CROSS_COMPILE
+#       define RESET_C_STACK
+#else
+#   ifdef __DEBUG
+#       define RESET_C_STACK fillDataStack();
+        void fillDataStack(void)
+        {
+            _asm
+                LFSR    1,C_STACK
+                MOVLW   0xCC
+        loop:   MOVWF   POSTINC1,0
+                TSTFSZ  FSR1L,0
+                BRA     loop
+        
+                LFSR    1,C_STACK
+                LFSR    2,C_STACK
+            _endasm
+        }
+#   else
+#       define RESET_C_STACK    \
+        _asm                    \
+            LFSR    1, C_STACK  \
+            LFSR    2, C_STACK  \
+        _endasm
+#   endif
+#endif
+
+//////////////////////////////////////////////////////////////////////////////
+
 static short read_custom_function(PARAMETER unsigned char cf)
 {
 #ifdef CROSS_COMPILE
@@ -777,40 +821,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////
 
-void fillDataStack(void)
-{
-#ifndef CROSS_COMPILE
-    _asm
-        LFSR    1,C_STACK
-        MOVLW   0xCC
-loop:   MOVWF   POSTINC1,0
-        TSTFSZ  FSR1L,0
-        BRA     loop
-
-        LFSR    1,C_STACK
-        LFSR    2,C_STACK
-    _endasm
-#endif
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// When calling C code from ASM context, the data stack pointer and
-// frames should be reset. Bank3 is dedicated to the stack (see the
-// .lkr script).
-#ifdef CROSS_COMPILE
-#       define RESET_C_STACK
-#else
-#   ifdef __DEBUG
-#       define RESET_C_STACK fillDataStack();
-#   else
-#       define RESET_C_STACK    \
-        _asm                    \
-            LFSR    1, C_STACK  \
-            LFSR    2, C_STACK  \
-        _endasm
-#   endif
-#endif
-
 //////////////////////////////////////////////////////////////////////////////
 // Called every 2 seconds during diving.
 // update tissues every time.