summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichardBarry <RichardBarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>2009-02-04 16:53:52 +0000
committerRichardBarry <RichardBarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>2009-02-04 16:53:52 +0000
commit4c25fe40a6d59d11a9db14c19aabe29f90966ccd (patch)
treeca2f1fcb5d41a05588842036127ac84b846a4bc8
parent57ac49f1221badd88724efe03f3da1305c23127a (diff)
downloadfreertos-4c25fe40a6d59d11a9db14c19aabe29f90966ccd.tar.gz
freertos-4c25fe40a6d59d11a9db14c19aabe29f90966ccd.tar.bz2
freertos-4c25fe40a6d59d11a9db14c19aabe29f90966ccd.tar.xz
Tidy up and comment.
git-svn-id: https://freertos.svn.sourceforge.net/svnroot/freertos/trunk@674 1d2547de-c912-0410-9cb9-b8ca96c0e9e2
-rw-r--r--Source/portable/IAR/78K0R/ISR_Support.h40
-rw-r--r--Source/portable/IAR/78K0R/port.c52
-rw-r--r--Source/portable/IAR/78K0R/portasm.s2644
3 files changed, 64 insertions, 72 deletions
diff --git a/Source/portable/IAR/78K0R/ISR_Support.h b/Source/portable/IAR/78K0R/ISR_Support.h
index 6b291cc9..126d738b 100644
--- a/Source/portable/IAR/78K0R/ISR_Support.h
+++ b/Source/portable/IAR/78K0R/ISR_Support.h
@@ -39,29 +39,28 @@
;------------------------------------------------------------------------------
; portSAVE_CONTEXT MACRO
-; Saves the context of the remaining general purpose registers, CS and ES
-; (only in far memory mode) registers
-; the usCriticalNesting Value and the Stack Pointer
+; Saves the context of the general purpose registers, CS and ES (only in far
+; memory mode) registers the usCriticalNesting Value and the Stack Pointer
; of the active Task onto the task stack
;------------------------------------------------------------------------------
portSAVE_CONTEXT MACRO
- PUSH AX ; save AX Register to stack
+ PUSH AX ; Save AX Register to stack.
PUSH HL
#if configMEMORY_MODE == 1
- MOV A, CS ; save CS register
+ MOV A, CS ; Save CS register.
XCH A, X
- MOV A, ES ; save ES register
+ MOV A, ES ; Save ES register.
PUSH AX
#else
- MOV A, CS ; save CS register
+ MOV A, CS ; Save CS register.
PUSH AX
#endif
- PUSH DE ; save the remaining general purpose registers
+ PUSH DE ; Save the remaining general purpose registers.
PUSH BC
- MOVW AX, usCriticalNesting ; save the usCriticalNesting value
+ MOVW AX, usCriticalNesting ; Save the usCriticalNesting value.
PUSH AX
- MOVW AX, pxCurrentTCB ; save the Stack pointer
+ MOVW AX, pxCurrentTCB ; Save the Stack pointer.
MOVW HL, AX
MOVW AX, SP
MOVW [HL], AX
@@ -70,30 +69,29 @@ portSAVE_CONTEXT MACRO
;------------------------------------------------------------------------------
; portRESTORE_CONTEXT MACRO
-; Restores the context of the Stack Pointer, usCriticalNesting
-; value, general purpose registers and the CS and ES (only in far memory mode)
+; Restores the task Stack Pointer then use this to restore usCriticalNesting,
+; general purpose registers and the CS and ES (only in far memory mode)
; of the selected task from the task stack
;------------------------------------------------------------------------------
-
portRESTORE_CONTEXT MACRO
- MOVW AX, pxCurrentTCB ; restore the Stack pointer
+ MOVW AX, pxCurrentTCB ; Restore the Stack pointer.
MOVW HL, AX
MOVW AX, [HL]
MOVW SP, AX
- POP AX ; restore usCriticalNesting value
+ POP AX ; Restore usCriticalNesting value.
MOVW usCriticalNesting, AX
- POP BC ; restore the necessary general purpose registers
+ POP BC ; Restore the necessary general purpose registers.
POP DE
#if configMEMORY_MODE == 1
- POP AX ; restore the ES register
+ POP AX ; Restore the ES register.
MOV ES, A
- XCH A, X ; restore the CS register
+ XCH A, X ; Restore the CS register.
MOV CS, A
#else
POP AX
- MOV CS, A ; restore CS register
+ MOV CS, A ; Restore CS register.
#endif
- POP HL ; restore general purpose register HL
- POP AX ; restore AX
+ POP HL ; Restore general purpose register HL.
+ POP AX ; Restore AX.
ENDM
;------------------------------------------------------------------------------
diff --git a/Source/portable/IAR/78K0R/port.c b/Source/portable/IAR/78K0R/port.c
index 73658f8a..a14c2e51 100644
--- a/Source/portable/IAR/78K0R/port.c
+++ b/Source/portable/IAR/78K0R/port.c
@@ -54,20 +54,22 @@
#include "FreeRTOS.h"
#include "task.h"
+/* The critical nesting value is initialised to a non zero value to ensure
+interrupts don't accidentally become enabled before the scheduler is started. */
#define portINITIAL_CRITICAL_NESTING (( unsigned portSHORT ) 10)
-/* default Initialization of the PSW for the task:
+/* Initial PSW value allocated to a newly created task.
* 1100011000000000
* ||||||||-------------- Fill byte
- * |||||||--------------- Cary Flag cleared
+ * |||||||--------------- Carry Flag cleared
* |||||----------------- In-service priority Flags set to low level
* ||||------------------ Register bank Select 0 Flag cleared
- * |||------------------- Auxiliary Cary Flag cleared
+ * |||------------------- Auxiliary Carry Flag cleared
* ||-------------------- Register bank Select 1 Flag cleared
* |--------------------- Zero Flag set
* ---------------------- Global Interrupt Flag set (enabled)
*/
-#define portPSW (0xc6000000UL)
+#define portPSW (0xc6UL)
/* We require the address of the pxCurrentTCB variable, but don't want to know
any details of its type. */
@@ -112,36 +114,39 @@ unsigned long *pulLocal;
#if configMEMORY_MODE == 1
{
- /* Parameters are passed in on the stack. */
+ /* Parameters are passed in on the stack, and written using a 32bit value
+ hence a space is left for the second two bytes. */
pxTopOfStack--;
+
+ /* Write in the parameter value. */
pulLocal = ( unsigned long * ) pxTopOfStack;
*pulLocal = ( unsigned long ) pvParameters;
pxTopOfStack--;
- /* Dummy values on the stack because there normaly the return address
- of the funtion is written. */
+ /* These values are just spacers. The return address of the function
+ would normally be written here. */
*pxTopOfStack = ( portSTACK_TYPE ) 0xcdcd;
pxTopOfStack--;
*pxTopOfStack = ( portSTACK_TYPE ) 0xcdcd;
pxTopOfStack--;
- /* Initial PSW value. */
-// *pxTopOfStack = portPSW;
-
+ /* The start address / PSW value is also written in as a 32bit value,
+ so leave a space for the second two bytes. */
pxTopOfStack--;
-
- /* Task function start address. */
+ /* Task function start address combined with the PSW. */
pulLocal = ( unsigned long * ) pxTopOfStack;
- *pulLocal = ( ( ( unsigned long ) pxCode ) | portPSW );
+ *pulLocal = ( ( ( unsigned long ) pxCode ) | ( portPSW << 24UL ) );
pxTopOfStack--;
- /* Next general purpose register AX. */
+ /* An initial value for the AX register. */
*pxTopOfStack = ( portSTACK_TYPE ) 0x1111;
pxTopOfStack--;
}
#else
{
+ TBD
+
pxTopOfStack--;
/* Task function start address. */
@@ -159,7 +164,7 @@ unsigned long *pulLocal;
}
#endif
- /* HL. */
+ /* An initial value for the HL register. */
*pxTopOfStack = ( portSTACK_TYPE ) 0x2222;
pxTopOfStack--;
@@ -172,12 +177,13 @@ unsigned long *pulLocal;
pxTopOfStack--;
*pxTopOfStack = ( portSTACK_TYPE ) 0xBCBC;
pxTopOfStack--;
+
+ /* Finally the critical section nesting count is set to zero when the task
+ first starts. */
*pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;
- /*
- * Return a pointer to the top of the stack we have generated so this can
- * be stored in the task control block for the task.
- */
+ /* Return a pointer to the top of the stack we have generated so this can
+ be stored in the task control block for the task. */
return pxTopOfStack;
}
/*-----------------------------------------------------------*/
@@ -198,17 +204,15 @@ portBASE_TYPE xPortStartScheduler( void )
void vPortEndScheduler( void )
{
- /* It is unlikely that the 78K0R/Kx3 port will get stopped. If required simply
+ /* It is unlikely that the 78K0R port will get stopped. If required simply
disable the tick interrupt here. */
}
/*-----------------------------------------------------------*/
-/*
- * Hardware initialisation to generate the RTOS tick. This uses Channel 5 of
- * the Timer Array Unit (TAU). Any other Channel could also be used.
- */
static void prvSetupTimerInterrupt( void )
{
+ /* Setup channel 5 of the TAU to generate the tick interrupt. */
+
/* First the Timer Array Unit has to be enabled. */
TAU0EN = 1;
diff --git a/Source/portable/IAR/78K0R/portasm.s26 b/Source/portable/IAR/78K0R/portasm.s26
index 2bb46e1c..a2ba1892 100644
--- a/Source/portable/IAR/78K0R/portasm.s26
+++ b/Source/portable/IAR/78K0R/portasm.s26
@@ -41,7 +41,6 @@
; Functions implemented in this file
;------------------------------------------------------------------------------
-
PUBLIC vPortYield
PUBLIC vPortStart
@@ -63,7 +62,9 @@ MD_INTTM05 SYMBOL "MD_INTTM05"
;------------------------------------------------------------------------------
-; Port Yield function to check for a Task switch in the cooperative mode
+; Yield to another task. Implemented as a software interrupt. The return
+; address and PSW will have been saved to the stack automatically before
+; this code runs.
;
; Input: NONE
;
@@ -75,9 +76,9 @@ MD_INTTM05 SYMBOL "MD_INTTM05"
RSEG CODE:CODE
vPortYield:
portSAVE_CONTEXT ; Save the context of the current task.
- call vTaskSwitchContext ; Call the scheduler.
- portRESTORE_CONTEXT ; Restore the context of whichever task the ...
- RETB
+ call vTaskSwitchContext ; Call the scheduler to select the next task.
+ portRESTORE_CONTEXT ; Restore the context of the next task to run.
+ retb
;------------------------------------------------------------------------------
@@ -93,8 +94,8 @@ vPortYield:
RSEG CODE:CODE
vPortStart:
portRESTORE_CONTEXT ; Restore the context of whichever task the ...
-; POP PSW ; restore active task PSW
- reti ; ... scheduler decided should run.
+ reti ; An interrupt stack frame is used so the task
+ ; is started using a RETI instruction.
;------------------------------------------------------------------------------
; Perform the necessary steps of the Tick Count Increment and Task Switch
@@ -107,42 +108,31 @@ vPortStart:
; Output: NONE
;
;------------------------------------------------------------------------------
-#if configUSE_PREEMPTION == 1
MD_INTTM05:
portSAVE_CONTEXT ; Save the context of the current task.
call vTaskIncrementTick ; Call the timer tick function.
- call vTaskSwitchContext ; Call the scheduler.
- portRESTORE_CONTEXT ; Restore the context of whichever task the ...
- RETI
-#else
-
-MD_INTTM05:
- PUSH AX ; save necessary general purpose register...
- PUSH HL ; ...used by the ISR
- MOVW AX, CS ; save CS register
- PUSH AX
- CALL vTaskIncrementTick ; Call the timer tick function.
- POP AX
- MOVW CS, AX ; restore CS register
- POP HL ; restore used general purpose registers
- POP AX
- RETI
+#if configUSE_PREEMPTION == 1
+ call vTaskSwitchContext ; Call the scheduler to select the next task.
#endif
+ portRESTORE_CONTEXT ; Restore the context of the next task to run.
+ reti
+
+
REQUIRE ?CL78K0R_V2_L00
- COMMON INTVEC:CODE:ROOT(1) ; set ISR location to the Interrupt vector table
+ COMMON INTVEC:CODE:ROOT(1) ; Set ISR location to the Interrupt vector table.
ORG 68
`??MD_INTTM05??INTVEC 68`:
DW MD_INTTM05
- COMMON INTVEC:CODE:ROOT(1) ; set ISR location to the Interrupt vector table
+ COMMON INTVEC:CODE:ROOT(1) ; Set ISR location to the Interrupt vector table.
ORG 126
`??vPortYield??INTVEC 126`:
DW vPortYield
- ; set value for the usCriticalNesting
+ ; Set value for the usCriticalNesting.
RSEG NEAR_ID:CONST:SORT:NOROOT(1)
`?<Initializer for usCriticalNesting>`:
DW 10