summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbdoulaye Walsimou Gaye <walsimou@walsimou.com>2009-04-19 19:54:20 +0200
committerAbdoulaye Walsimou Gaye <walsimou@walsimou.com>2009-04-19 19:54:20 +0200
commit9dd0713b1ba8b0ea0b79a2a8804a345545e4fb68 (patch)
treefde781ca1fad1216ad6f1955dc91457299cc93c3
parent693e891448b0ab4e2672aeba12b4425c32094ba1 (diff)
downloadfreertos-9dd0713b1ba8b0ea0b79a2a8804a345545e4fb68.tar.gz
freertos-9dd0713b1ba8b0ea0b79a2a8804a345545e4fb68.tar.bz2
freertos-9dd0713b1ba8b0ea0b79a2a8804a345545e4fb68.tar.xz
PIC18_SDCC: Reduce C usage in assembly macro
This patch reduces usage of C language in assembly macro. Signed-off-by: Abdoulaye Walsimou Gaye <walsimou@walsimou.com>
-rw-r--r--Source/portable/SDCC/PIC18/portmacro.h134
1 files changed, 73 insertions, 61 deletions
diff --git a/Source/portable/SDCC/PIC18/portmacro.h b/Source/portable/SDCC/PIC18/portmacro.h
index 08da03cc..c3280d44 100644
--- a/Source/portable/SDCC/PIC18/portmacro.h
+++ b/Source/portable/SDCC/PIC18/portmacro.h
@@ -1,7 +1,7 @@
/**
* #######################################################################################
* GAYE Abdoulaye Walsimou, <walsimou@walsimou.com>
-* Copyright(C) 2009 GAYE Abdoulaye walsimou, <walsimou@walsimou.com>. All rights reserved.
+* Copyright (C) 2009 GAYE Abdoulaye walsimou. All rights reserved.
*
* This program is free software; you can distribute it and/or modify it
* under the terms of the GNU General Public License
@@ -54,7 +54,7 @@
area's get used by the compiler for temporary storage, especially when
performing mathematical operations, or when using 32bit data types. This
constant defines the size of memory area which must be saved. */
-#define portCOMPILER_MANAGED_MEMORY_SIZE ((unsigned portCHAR)20)
+#define portCOMPILER_MANAGED_MEMORY_SIZE (20)
#if(configUSE_16_BIT_TICKS==1)
@@ -76,7 +76,12 @@ constant defines the size of memory area which must be saved. */
/*
* Critical section management.
*/
-#define portDISABLE_INTERRUPTS() INTCONbits.GIE = 0
+#define portDISABLE_INTERRUPTS() \
+do \
+{ \
+ INTCONbits.GIE = 0; \
+}while(INTCONbits.GIE)
+
#define portENABLE_INTERRUPTS() INTCONbits.GIE = 1
/* Push the INTCON register onto the stack, then disable interrupts. */
@@ -209,33 +214,39 @@ _endasm
_endasm
#pragma preproc_asm +
-#define portSAVE_CONTEXT(ucForcedInterruptFlags) \
-{ \
- portSAVE_CONTEXT_GLOBAL_REGISTERS(); \
- _asm \
+#define portSAVE_CONTEXT(ucForcedInterruptFlags) \
+{ \
+ portSAVE_CONTEXT_GLOBAL_REGISTERS(); \
+ _asm \
MOVFF INTCON,WREG \
- _endasm; \
- _asm \
- IORLW ucForcedInterruptFlags \
- _endasm; \
- _asm \
- MOVFF WREG,POSTDEC1 \
- _endasm; \
- portDISABLE_INTERRUPTS(); \
- portSAVE_CONTEXT_HW_REGISTERS(); \
- portSAVE_CONTEXT_DOT_REGISTERS_START(); \
- while(FSR0L<(unsigned portCHAR)(portCOMPILER_MANAGED_MEMORY_SIZE-1)) \
- { \
- _asm \
- MOVFF POSTINC0,POSTDEC1 \
- _endasm; \
- } \
- portSAVE_CONTEXT_DOT_REGISTERS_END(); \
- while(STKPTR>(unsigned portCHAR)0) \
- { \
- portSAVE_CONTEXT_HWSTACK(); \
- } \
- portSAVE_CONTEXT_END(); \
+ _endasm; \
+ _asm \
+ IORLW ucForcedInterruptFlags \
+ _endasm; \
+ _asm \
+ MOVFF WREG,POSTDEC1 \
+ _endasm; \
+ portDISABLE_INTERRUPTS(); \
+ portSAVE_CONTEXT_HW_REGISTERS(); \
+ portSAVE_CONTEXT_DOT_REGISTERS_START(); \
+ _asm \
+ MOVLW (portCOMPILER_MANAGED_MEMORY_SIZE-1) \
+ _endasm; \
+ _asm \
+ MOVFF POSTINC0,POSTDEC1 \
+ _endasm; \
+ _asm \
+ DECFSZ WREG,ACCESS \
+ _endasm; \
+ _asm \
+ BRA ($ - 5) \
+ _endasm; \
+ portSAVE_CONTEXT_DOT_REGISTERS_END(); \
+ while(STKPTR>(unsigned portCHAR)0) \
+ { \
+ portSAVE_CONTEXT_HWSTACK(); \
+ } \
+ portSAVE_CONTEXT_END(); \
}
/*-----------------------------------------------------------*/
@@ -281,8 +292,6 @@ _endasm
;Start to restore the .registers section.
MOVFF PREINC1,FSR0H
MOVFF PREINC1,FSR0L
- ;Use FSR2L as temp register
- CLRF FSR2L,ACCESS
_endasm
#pragma preproc_asm +
@@ -330,42 +339,45 @@ _endasm
#pragma preproc_asm -
#define portRESTORE_CONTEXT_RETURN() _asm
MOVFF PREINC1, STATUS
- MOVFF PREINC1, W
+ MOVFF PREINC1, WREG
;Return without effecting interrupts. The context may have
;been saved from a critical region.
RETURN 0
_endasm
#pragma preproc_asm +
-#define portRESTORE_CONTEXT() \
-{ \
- portRESTORE_CONTEXT_GET_PXCURRENTTCB(); \
- portRESTORE_CONTEXT_GET_STACKDEPTH(); \
- STKPTR = 0; \
- while( STKPTR < FSR0L) \
- { \
- portRESTORE_CONTEXT_FILL_HWSTACK(); \
- } \
- portRESTORE_CONTEXT_DOT_REGISTERS_START(); \
- while(FSR2L<(unsigned portCHAR)(portCOMPILER_MANAGED_MEMORY_SIZE-1)) \
- { \
- _asm \
- MOVFF PREINC1,POSTDEC0 \
- _endasm; \
- _asm \
- INCF FSR2L,F,ACCESS \
- _endasm; \
- } \
- portRESTORE_CONTEXT_DOT_REGISTERS_END(); \
- portRESTORE_CONTEXT_HW_REGISTERS(); \
- if(WREG & portGLOBAL_INTERRUPT_FLAG) \
- { \
- portRESTORE_CONTEXT_RETFIE(); \
- } \
- else \
- { \
- portRESTORE_CONTEXT_RETURN(); \
- } \
+#define portRESTORE_CONTEXT() \
+{ \
+ portRESTORE_CONTEXT_GET_PXCURRENTTCB(); \
+ portRESTORE_CONTEXT_GET_STACKDEPTH(); \
+ STKPTR = 0; \
+ while(STKPTR < FSR0L) \
+ { \
+ portRESTORE_CONTEXT_FILL_HWSTACK(); \
+ } \
+ portRESTORE_CONTEXT_DOT_REGISTERS_START(); \
+ _asm \
+ MOVLW (portCOMPILER_MANAGED_MEMORY_SIZE-1) \
+ _endasm; \
+ _asm \
+ MOVFF PREINC1,POSTDEC0 \
+ _endasm; \
+ _asm \
+ DECFSZ WREG,ACCESS \
+ _endasm; \
+ _asm \
+ BRA ($ - 5) \
+ _endasm; \
+ portRESTORE_CONTEXT_DOT_REGISTERS_END(); \
+ portRESTORE_CONTEXT_HW_REGISTERS(); \
+ if(WREG & portGLOBAL_INTERRUPT_FLAG) \
+ { \
+ portRESTORE_CONTEXT_RETFIE(); \
+ } \
+ else \
+ { \
+ portRESTORE_CONTEXT_RETURN(); \
+ } \
}
#endif /*PORTMACRO_H*/