1 ;
********************************************************************************************************
5 ;
(c
) Copyright
2002, Jean J. Labrosse
, Weston
, FL
9 ; PAGED S12X Specific code
15 ; Notes
: THIS FILE
*MUST
* BE LINKED INTO NON_BANKED MEMORY
!
16 ;
********************************************************************************************************
20 ;
********************************************************************************************************
22 ;
********************************************************************************************************
24 PPAGE
: equ $
0015 ; Addres of PPAGE register
(assuming MC9S12XEP100 part
)
25 RPAGE
: equ $
0016 ; Addres of RPAGE register
(assuming MC9S12XEP100 part
)
26 EPAGE
: equ $
0017 ; Addres of EPAGE register
(assuming MC9S12XEP100 part
)
27 GPAGE
: equ $
0010 ; Addres of GPAGE register
(assuming MC9S12XEP100 part
)
29 CRGFLG
: equ $
0037 ; Address of CRGFLG
add by cha0s
30 PIFJ
: equ $
026f ; Address of CRGFLG
add by cha0s
32 ;
********************************************************************************************************
34 ;
********************************************************************************************************
37 xdef OS_CPU_SR_Restore
43 ;
********************************************************************************************************
44 ; EXTERNAL DECLARATIONS
45 ;
********************************************************************************************************
55 xref OSTickISR_Handler
58 ;
********************************************************************************************************
59 ; SAVE THE CCR
AND DISABLE INTERRUPTS
63 ; Description
: These function implements OS_CRITICAL_METHOD
#3
65 ; Arguments
: The function prototypes for the two functions are
:
66 ;
1) OS_CPU_SR OSCPUSaveSR
(void
)
67 ; where OS_CPU_SR is the contents of the CCR register prior to disabling
69 ;
2) void OSCPURestoreSR
(OS_CPU_SR os_cpu_sr
);
70 ;
'os_cpu_sr' the the value of the CCR to restore.
72 ; Note
(s
) : 1) It
's assumed that the compiler uses the D register to pass a single 16-bit argument
73 ; to and from an assembly language function.
74 ;********************************************************************************************************
77 tfr ccrw, d ; It's assumed that the
16-bit return value is in register D
78 sei ; Disable interrupts
79 rtc ; Return to caller with D containing the previous CCR
82 tfr d
,ccrw ; D contains the CCR word value to restore
, move to CCRW
85 ;
********************************************************************************************************
86 ; START HIGHEST PRIORITY TASK READY-TO-RUN
88 ; Description
: This function is called by OSStart
() to start the highest priority task that was created
89 ; by your application before calling OSStart
().
93 ; Note
(s
) : 1) The stack frame is assumed to look as follows
:
95 ; OSTCBHighRdy-
>OSTCBStkPtr
+ 0 --> gPAGE
109 ;
2) OSStartHighRdy
() MUST
:
110 ;
a) Call OSTaskSwHook
() then
,
111 ;
b) Set OSRunning to TRUE
,
112 ; c
) Switch to the highest priority task by loading the stack pointer of the
113 ; highest priority task into the SP register
and execute an RTI instruction.
114 ;
********************************************************************************************************
117 call OSTaskSwHook ; Invoke user defined context switch hook
119 ldab
#$01 ; Indicate that we are multitasking
122 ldx OSTCBHighRdy ; Point to TCB of highest priority task ready to run
123 lds
0,x ; Load SP into
68HC12
125 pula ; Get value of PPAGE register
126 staa PPAGE ; Store into CPU
's PPAGE register
128 pula ; Get value of RPAGE register
129 staa RPAGE ; Store into CPU's RPAGE register
131 pula ; Get value of EPAGE register
132 staa EPAGE ; Store into CPU
's EPAGE register
134 pula ; Get value of GPAGE register
135 staa GPAGE ; Store into CPU's GPAGE register
139 ;
********************************************************************************************************
140 ; TASK LEVEL CONTEXT SWITCH
142 ; Description
: This function is called when
a task makes
a higher priority task ready-to-run.
146 ; Note
(s
) : 1) Upon entry
,
147 ; OSTCBCur points to the OS_TCB of the task to suspend
148 ; OSTCBHighRdy points to the OS_TCB of the task to resume
150 ;
2) The stack frame of the task to suspend looks as follows
:
162 ;
3) The stack frame of the task to resume looks as follows
:
164 ; OSTCBHighRdy-
>OSTCBStkPtr
+ 0 --> gPAGE
177 ;
********************************************************************************************************
180 ldaa GPAGE ; Get current value of GPAGE register
181 psha ; Push GPAGE register onto current task
's stack
183 ldaa EPAGE ; Get current value of EPAGE register
184 psha ; Push EPAGE register onto current task's stack
186 ldaa RPAGE ; Get current value of RPAGE register
187 psha ; Push RPAGE register onto current task
's stack
189 ldaa PPAGE ; Get current value of PPAGE register
190 psha ; Push PPAGE register onto current task's stack
192 ldy OSTCBCur ; OSTCBCur-
>OSTCBStkPtr
= Stack Pointer
195 call OSTaskSwHook ; Call user task switch hook
197 ldx OSTCBHighRdy ; OSTCBCur
= OSTCBHighRdy
200 ldab OSPrioHighRdy ; OSPrioCur
= OSPrioHighRdy
203 lds
0,x ; Load SP into
68HC12
205 pula ; Get value of PPAGE register
206 staa PPAGE ; Store into CPU
's PPAGE register
208 pula ; Get value of RPAGE register
209 staa RPAGE ; Store into CPU's RPAGE register
211 pula ; Get value of EPAGE register
212 staa EPAGE ; Store into CPU
's EPAGE register
214 pula ; Get value of GPAGE register
215 staa GPAGE ; Store into CPU's GPAGE register
219 ;
********************************************************************************************************
220 ; INTERRUPT LEVEL CONTEXT SWITCH
222 ; Description
: This function is called by OSIntExit
() to perform
a context switch to
a task that has
223 ; been made ready-to-run by an ISR. The GPAGE
, EPAGE
, RPAGE
and PPAGE CPU registers of the
224 ; preempted task have already been stacked during the start of the ISR that is currently
228 ;
********************************************************************************************************
231 call OSTaskSwHook ; Call user task switch hook
233 ldx OSTCBHighRdy ; OSTCBCur
= OSTCBHighRdy
236 ldab OSPrioHighRdy ; OSPrioCur
= OSPrioHighRdy
239 lds
0,x ; Load the SP of the next task
241 pula ; Get value of PPAGE register
242 staa PPAGE ; Store into CPU
's PPAGE register
244 pula ; Get value of RPAGE register
245 staa RPAGE ; Store into CPU's RPAGE register
247 pula ; Get value of EPAGE register
248 staa EPAGE ; Store into CPU
's EPAGE register
250 pula ; Get value of GPAGE register
251 staa GPAGE ; Store into CPU's GPAGE register
255 ;
********************************************************************************************************
258 ; Description
: This function is the ISR used to notify uC
/OS-II that
a system tick has occurred. You
259 ; must setup the S12XE
's interrupt vector table so that an OUTPUT COMPARE interrupt
260 ; vectors to this function.
264 ; Notes : 1) The 'tick ISR
' assumes the we are using the Output Compare specified by OS_TICK_OC
265 ; (see APP_CFG.H and this file) to generate a tick that occurs every OS_TICK_OC_CNTS
266 ; (see APP_CFG.H) which corresponds to the number of FRT (Free Running Timer)
267 ; counts to the next interrupt.
269 ; 2) All USER interrupts should be modeled EXACTLY like this where the only
270 ; line to be modified is the call to your ISR_Handler and perhaps the call to
271 ; the label name OSTickISR1.
272 ;********************************************************************************************************
275 ldaa GPAGE ; Get current value of GPAGE register
276 psha ; Push GPAGE register onto current task's stack
278 ldaa EPAGE ; Get current value of EPAGE register
279 psha ; Push EPAGE register onto current task
's stack
281 ldaa RPAGE ; Get current value of RPAGE register
282 psha ; Push RPAGE register onto current task's stack
284 ldaa PPAGE ; Get current value of PPAGE register
285 psha ; Push PPAGE register onto current task
's stack
287 ;bset CRGFLG,#128 ;CRGFLG |= 0x80, Clean CRG model Flag add by cha0s
288 bset PIFJ,#64 ;PIFJ=#64, Clean PTJ model Flag add by cha0s
290 inc OSIntNesting ; Notify uC/OS-II about ISR
292 ldab OSIntNesting ; if (OSIntNesting == 1) {
296 ldy OSTCBCur ; OSTCBCur->OSTCBStkPtr = Stack Pointer
300 ; call OSTickISR_Handler
303 ; cli ; Optionally enable interrupts to allow interrupt nesting
305 call OSIntExit ; Notify uC/OS-II about end of ISR
307 pula ; Get value of PPAGE register
308 staa PPAGE ; Store into CPU's PPAGE register
310 pula ; Get value of RPAGE register
311 staa RPAGE ; Store into CPU
's RPAGE register
313 pula ; Get value of EPAGE register
314 staa EPAGE ; Store into CPU's EPAGE register
316 pula ; Get value of GPAGE register
317 staa GPAGE ; Store into CPU
's GPAGE register
319 rti ; Return from interrupt, no higher priority tasks ready.