comparison src/nucleus/tms470/tmt.s @ 0:4e78acac3d88

src/{condat,cs,gpf,nucleus}: import from Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:23:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4e78acac3d88
1 ;************************************************************************
2 ;*
3 ;* Copyright Mentor Graphics Corporation 2002
4 ;* All Rights Reserved.
5 ;*
6 ;* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS
7 ;* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS
8 ;* SUBJECT TO LICENSE TERMS.
9 ;*
10 ;************************************************************************
11 ;************************************************************************
12 ;*
13 ;* FILE NAME VERSION
14 ;*
15 ;* tmt.s Nucleus PLUS\ARM925\Code Composer 1.14.1
16 ;*
17 ;* COMPONENT
18 ;*
19 ;* TM - Timer Management
20 ;*
21 ;* DESCRIPTION
22 ;*
23 ;* This file contains the target dependent routines of the timer
24 ;* management component.
25 ;*
26 ;* FUNCTIONS
27 ;*
28 ;* TMT_Set_Clock Set system clock
29 ;* TMT_Retrieve_Clock Retrieve system clock
30 ;* TMT_Read_Timer Read count-down timer
31 ;* TMT_Enable_Timer Enable count-down timer
32 ;* TMT_Adjust_Timer Adjust count-down timer
33 ;* TMT_Disable_Timer Disable count-down timer
34 ;* TMT_Retrieve_TS_Task Retrieve time-sliced task ptr
35 ;* TMT_Timer_Interrupt Process timer interrupt
36 ;*
37 ;* DEPENDENCIES
38 ;*
39 ;* tc_extr.h Thread Control functions
40 ;* tm_extr.h Timer functions
41 ;*
42 ;* HISTORY
43 ;*
44 ;* NAME DATE REMARKS
45 ;*
46 ;* B. Ronquillo 08-28-2002 Released version 1.14.1
47 ;*
48 ;*
49 ;************************************************************************
50 ;#define NU_SOURCE_FILE
51 ;******************************
52 ;* INCLUDE ASSEMBLY CONSTANTS *
53 ;******************************
54 ; Define constants used in low-level initialization.
55 LOCKOUT .equ 00C0h ; Interrupt lockout value
56
57 .state32
58
59 ;**********************************
60 ;* EXTERNAL VARIABLE DECLARATIONS *
61 ;**********************************
62 ; Define external inner-component global data references.
63 ;extern VOID *TCD_Current_Thread;
64 ;extern UNSIGNED TMD_System_Clock;
65 ;extern UNSIGNED TMD_Timer;
66 ;extern INT TMD_Timer_State;
67 ;extern UNSIGNED TMD_Time_Slice;
68 ;extern TC_TCB *TMD_Time_Slice_Task;
69 ;extern INT TMD_Time_Slice_State;
70 ;extern TC_HCB TMD_HISR;
71
72 .ref _TCD_Current_Thread
73 .ref _TMD_System_Clock
74 .ref _TMD_Timer
75 .ref _TMD_Timer_State
76 .ref _TMD_Time_Slice
77 .ref _TMD_Time_Slice_Task
78 .ref _TMD_Time_Slice_State
79 .ref _TMD_HISR
80 .ref _TCD_Interrupt_Level
81
82 ; Define activate HISR function.
83 ;STATUS TCT_Activate_HISR(TC_HCB *hisr);
84
85 .ref _TCT_Activate_HISR
86
87 .text
88 ;**********************************
89 ;* LOCAL VARIABLE DECLARATIONS *
90 ;**********************************
91 ; Define various data structure pointers so their addresses
92 ; can be obtained in a PC-relative manner.
93
94 System_Clock
95 .word _TMD_System_Clock
96
97 Timer
98 .word _TMD_Timer
99
100 Timer_State
101 .word _TMD_Timer_State
102
103 Slice_State
104 .word _TMD_Time_Slice_State
105
106 Time_Slice
107 .word _TMD_Time_Slice
108
109 Current_Thread
110 .word _TCD_Current_Thread
111
112 Slice_Task
113 .word _TMD_Time_Slice_Task
114
115 HISR
116 .word _TMD_HISR
117
118 Int_Level
119 .word _TCD_Interrupt_Level
120
121 ;************************************************************************
122 ;*
123 ;* FUNCTION
124 ;*
125 ;* TMT_Set_Clock
126 ;*
127 ;* DESCRIPTION
128 ;*
129 ;* This function sets the system clock to the specified value.
130 ;*
131 ;* CALLED BY
132 ;*
133 ;* Application
134 ;*
135 ;* CALLS
136 ;*
137 ;* None
138 ;*
139 ;* INPUTS
140 ;*
141 ;* new_value New value for the clock
142 ;*
143 ;* OUTPUTS
144 ;*
145 ;* None
146 ;*
147 ;* HISTORY
148 ;*
149 ;* NAME DATE REMARKS
150 ;*
151 ;* W. Lamie 02-15-1994 Created initial version 1.0
152 ;* D. Lamie 02-15-1994 Verified version 1.0
153 ;*
154 ;************************************************************************
155 ;VOID TMT_Set_Clock(UNSIGNED new_value)
156 ;{
157 .def $TMT_Set_Clock
158 $TMT_Set_Clock ; Dual-state interworking veneer
159 .state16
160 BX r15
161 NOP
162 .state32
163 B _TMT_Set_Clock
164
165 .def _TMT_Set_Clock
166 _TMT_Set_Clock
167
168 ; Set the system clock to the specified value.
169 ; TMD_System_Clock = new_value;
170
171 LDR r1,System_Clock ; Build address of system clock
172 STR r0,[r1,#0] ; Store new system clock value
173
174 BX r14 ; Return to caller
175
176 ;}
177
178 ;************************************************************************
179 ;*
180 ;* FUNCTION
181 ;*
182 ;* TMT_Retrieve_Clock
183 ;*
184 ;* DESCRIPTION
185 ;*
186 ;* This function returns the current value of the system clock.
187 ;*
188 ;* CALLED BY
189 ;*
190 ;* Application
191 ;*
192 ;* CALLS
193 ;*
194 ;* None
195 ;*
196 ;* INPUTS
197 ;*
198 ;* None
199 ;*
200 ;* OUTPUTS
201 ;*
202 ;* TMD_System_Clock Value of system clock
203 ;*
204 ;* HISTORY
205 ;*
206 ;* NAME DATE REMARKS
207 ;*
208 ;* W. Lamie 02-15-1994 Created initial version 1.0
209 ;* D. Lamie 02-15-1994 Verified version 1.0
210 ;*
211 ;************************************************************************
212 ;UNSIGNED TMT_Retrieve_Clock(void)
213 ;{
214 .def $TMT_Retrieve_Clock
215 $TMT_Retrieve_Clock ; Dual-state interworking veneer
216 .state16
217 BX r15
218 NOP
219 .state32
220 B _TMT_Retrieve_Clock
221
222 .def _TMT_Retrieve_Clock
223 _TMT_Retrieve_Clock
224
225 ; Return the current value of the system clock.
226 ; return(TMD_System_Clock);
227
228 LDR r0,System_Clock ; Build address to system clock
229 LDR r0,[r0,#0] ; Pickup system clock contents
230
231 BX r14 ; Return to caller
232
233 ;}
234
235 ;************************************************************************
236 ;*
237 ;* FUNCTION
238 ;*
239 ;* TMT_Read_Timer
240 ;*
241 ;* DESCRIPTION
242 ;*
243 ;* This function returns the current value of the count-down timer.
244 ;*
245 ;* CALLED BY
246 ;*
247 ;* TMC_Start_Timer Start timer function
248 ;*
249 ;* CALLS
250 ;*
251 ;* None
252 ;*
253 ;* INPUTS
254 ;*
255 ;* None
256 ;*
257 ;* OUTPUTS
258 ;*
259 ;* TMD_Timer Value of count-down timer
260 ;*
261 ;* HISTORY
262 ;*
263 ;* NAME DATE REMARKS
264 ;*
265 ;* W. Lamie 02-15-1994 Created initial version 1.0
266 ;* D. Lamie 02-15-1994 Verified version 1.0
267 ;*
268 ;************************************************************************
269 ;UNSIGNED TMT_Read_Timer(void)
270 ;{
271 .def $TMT_Read_Timer
272 $TMT_Read_Timer ; Dual-state interworking veneer
273 .state16
274 BX r15
275 NOP
276 .state32
277 B _TMT_Read_Timer
278
279 .def _TMT_Read_Timer
280 _TMT_Read_Timer
281
282 ; Return the current value of the count-down timer.
283 ; return(TMD_Timer);
284
285 LDR r0,Timer ; Build address to timer
286 LDR r0,[r0,#0] ; Pickup timer contents
287
288 BX r14 ; Return to caller
289
290 ;}
291
292 ;************************************************************************
293 ;*
294 ;* FUNCTION
295 ;*
296 ;* TMT_Enable_Timer
297 ;*
298 ;* DESCRIPTION
299 ;*
300 ;* This function enables the count-down timer with the specified
301 ;* value.
302 ;*
303 ;* CALLED BY
304 ;*
305 ;* TMC_Start_Timer Start timer function
306 ;* TMC_Timer_Task Timer expiration task
307 ;*
308 ;* CALLS
309 ;*
310 ;* None
311 ;*
312 ;* INPUTS
313 ;*
314 ;* time New count-down time
315 ;*
316 ;* OUTPUTS
317 ;*
318 ;* None
319 ;*
320 ;* HISTORY
321 ;*
322 ;* NAME DATE REMARKS
323 ;*
324 ;* W. Lamie 02-15-1994 Created initial version 1.0
325 ;* D. Lamie 02-15-1994 Verified version 1.0
326 ;*
327 ;************************************************************************
328 ;VOID TMT_Enable_Timer(UNSIGNED time)
329 ;{
330 .def $TMT_Enable_Timer
331 $TMT_Enable_Timer ; Dual-state interworking veneer
332 .state16
333 BX r15
334 NOP
335 .state32
336 B _TMT_Enable_Timer
337
338 .def _TMT_Enable_Timer
339 _TMT_Enable_Timer
340
341 ; Place the new time value into the count-down timer.
342 ; TMD_Timer = time;
343
344 LDR r1,Timer ; Build address of timer
345 STR r0,[r1,#0] ; Store new timer value
346
347 ; Indicate that the timer is active.
348 ; TMD_Timer_State = TM_ACTIVE;
349
350 MOV r0,#0 ; Build TM_ACTIVE value
351 LDR r1,Timer_State ; Build address of timer state var
352 STR r0,[r1,#0] ; Change the state to active
353
354 BX r14 ; Return to caller
355
356 ;}
357
358 ;************************************************************************
359 ;*
360 ;* FUNCTION
361 ;*
362 ;* TMT_Adjust_Timer
363 ;*
364 ;* DESCRIPTION
365 ;*
366 ;* This function adjusts the count-down timer with the specified
367 ;* value, if the new value is less than the current.
368 ;*
369 ;* CALLED BY
370 ;*
371 ;* None
372 ;*
373 ;* CALLS
374 ;*
375 ;* None
376 ;*
377 ;* INPUTS
378 ;*
379 ;* time New count-down time.
380 ;*
381 ;* OUTPUTS
382 ;*
383 ;* None
384 ;*
385 ;* HISTORY
386 ;*
387 ;* NAME DATE REMARKS
388 ;*
389 ;* C. Meredith 03-01-1994 Created initial version 1.1
390 ;* D. Lamie 03-18-1994 Verified version 1.1
391 ;* C. Meredith 08-27-1994 Corrected bug in new timer
392 ;* adjust routine, resulting in
393 ;* version 1.1a
394 ;* W. Lamie 08-27-1994 Verified version 1.1a
395 ;*
396 ;************************************************************************
397 ;VOID TMT_Adjust_Timer(UNSIGNED time)
398 ;{
399 .def $TMT_Adjust_Timer
400 $TMT_Adjust_Timer ; Dual-state interworking veneer
401 .state16
402 BX r15
403 NOP
404 .state32
405 B _TMT_Adjust_Timer
406
407 .def _TMT_Adjust_Timer
408 _TMT_Adjust_Timer
409
410 ; Lockout all interrupts
411 ; TMD_Timer_State = TM_NOT_ACTIVE;
412
413 MRS r3,CPSR ; Pickup current CPSR
414 ORR r2,r3,#LOCKOUT ; Build lockout CPSR
415 MSR CPSR,r2 ; Setup new CPSR interrupt bits
416
417 ; Check for the new value is less than the current time value
418 ; if (time < TMD_Timer)
419
420 LDR r1,Timer ; Build address to timer var
421 LDR r2,[r1,#0] ; read value of the timer
422 CMP r2,r0 ; Do Timer - time > 0, means
423 BLT TMT_No_Adjust ; time < Timer.
424
425 ; Adjust the time
426 ; TMD_Timer = time;
427
428 STR r0,[r1,#0] ; load passed in timer value
429
430 ; Return to caller after restoring interrupts
431
432 TMT_No_Adjust:
433
434 MSR CPSR,r3 ; Setup new CPSR enable bits
435
436 BX r14 ; Return to caller
437 ;}
438
439 ;************************************************************************
440 ;*
441 ;* FUNCTION
442 ;*
443 ;* TMT_Disable_Timer
444 ;*
445 ;* DESCRIPTION
446 ;*
447 ;* This function disables the count-down timer.
448 ;*
449 ;* CALLED BY
450 ;*
451 ;* TMC_Start_Timer Start timer function
452 ;* TMC_Timer_Task Timer expiration task
453 ;*
454 ;* CALLS
455 ;*
456 ;* None
457 ;*
458 ;* INPUTS
459 ;*
460 ;* None
461 ;*
462 ;* OUTPUTS
463 ;*
464 ;* None
465 ;*
466 ;* HISTORY
467 ;*
468 ;* NAME DATE REMARKS
469 ;*
470 ;* W. Lamie 02-15-1994 Created initial version 1.0
471 ;* D. Lamie 02-15-1994 Verified version 1.0
472 ;*
473 ;************************************************************************
474 ;VOID TMT_Disable_Timer(void)
475 ;{
476 .def $TMT_Disable_Timer
477 $TMT_Disable_Timer ; Dual-state interworking veneer
478 .state16
479 BX r15
480 NOP
481 .state32
482 B _TMT_Disable_Timer
483
484 .def _TMT_Disable_Timer
485 _TMT_Disable_Timer
486
487 ; Disable the count-down timer.
488 ; TMD_Timer_State = TM_NOT_ACTIVE;
489
490 MOV r1,#1 ; Build TM_NOT_ACTIVE value
491 LDR r0,Timer_State ; Build address to timer state var
492 STR r1,[r0,#0] ; Change timer state to not active
493
494 BX r14 ; Return to caller
495 ;}
496
497 ;************************************************************************
498 ;*
499 ;* FUNCTION
500 ;*
501 ;* TMT_Retreive_TS_Timer
502 ;*
503 ;* DESCRIPTION
504 ;*
505 ;* This function returns the time-sliced task pointer.
506 ;*
507 ;* CALLED BY
508 ;*
509 ;* TMC_Timer_HISR Timer HISR
510 ;*
511 ;* CALLS
512 ;*
513 ;* None
514 ;*
515 ;* INPUTS
516 ;*
517 ;* None
518 ;*
519 ;* OUTPUTS
520 ;*
521 ;* TMD_Time_Slice_Task Time sliced task pointer
522 ;*
523 ;* HISTORY
524 ;*
525 ;* NAME DATE REMARKS
526 ;*
527 ;* C. Meredith 03-01-1994 Created initial version 1.1
528 ;* D. Lamie 03-18-1994 Verified version 1.1
529 ;*
530 ;************************************************************************
531 ;NU_TASK TMT_Retrieve_TS_Task (VOID)
532 ;{
533 .def $TMT_Retrieve_TS_Task
534 $TMT_Retrieve_TS_Task ; Dual-state interworking veneer
535 .state16
536 BX r15
537 NOP
538 .state32
539 B _TMT_Retrieve_TS_Task
540
541 .def _TMT_Retrieve_TS_Task
542 _TMT_Retrieve_TS_Task
543
544 ; Read the current TMD_Time_Slice_Task variable and load for
545 ; return to caller.
546
547 LDR r1,Slice_Task ; Build address to timer slice var
548 LDR r0,[r1,#0] ; Get task pointer to be returned
549
550 ; Return to caller time slice value back to caller
551
552 BX r14 ; Return to caller
553
554 ;}
555
556 ;************************************************************************
557 ;*
558 ;* FUNCTION
559 ;*
560 ;* TMT_Timer_Interrupt
561 ;*
562 ;* DESCRIPTION
563 ;*
564 ;* This function processes the actual hardware interrupt.
565 ;* Processing includes updating the system clock and the count-
566 ;* down timer and the time-slice timer. If one or both of the
567 ;* timers expire, the timer HISR is activated.
568 ;*
569 ;* CALLED BY
570 ;*
571 ;* Interrupt Vector
572 ;*
573 ;* CALLS
574 ;*
575 ;* TCT_Activate_HISR Activate timer HISR
576 ;* TCT_Interrupt_Context_Save Save interrupted context
577 ;* TCT_Interrupt_Context_Restore Restore interrupted context
578 ;*
579 ;* INPUTS
580 ;*
581 ;* None
582 ;*
583 ;* OUTPUTS
584 ;*
585 ;* None
586 ;*
587 ;* HISTORY
588 ;*
589 ;* NAME DATE REMARKS
590 ;*
591 ;* W. Lamie 02-15-1994 Created initial version 1.0
592 ;* D. Lamie 02-15-1994 Verified version 1.0
593 ;*
594 ;************************************************************************
595 ;VOID TMT_Timer_Interrupt(void)
596 ;{
597 .def _TMT_Timer_Interrupt
598 _TMT_Timer_Interrupt
599
600 MRS r1,CPSR ; Pickup current CPSR
601 ORR r1,r1,#LOCKOUT ; Set the interrupt lockout bits
602 MSR CPSR,r1 ; Lockout interrupts
603
604 ; Increment the system clock.
605 ; TMD_System_Clock++;
606
607 LDR r0,System_Clock ; Pickup system clock address
608 LDR r1,[r0,#0] ; Pickup system clock contents
609 ADD r1,r1,#1 ; Increment system clock
610 STR r1,[r0,#0] ; Store new system clock value
611
612 ; Determine if the count-down timer is active.
613 ; if (TMD_Timer_State == TM_ACTIVE)
614 ; {
615
616 LDR r1,Timer_State ; Build address to timer state flag
617 LDR r0,[r1,#0] ; Pickup timer state
618 MOV r3,#2 ; Build expired value
619 CMP r0,#0 ; Is there a timer active?
620 BNE TMT_No_Timer_Active ; No, skip timer processing
621
622 ; Decrement the count-down timer.
623 ; TMD_Timer--;
624
625 LDR r0,Timer ; Build timer address
626 LDR r2,[r0,#0] ; Pickup the current timer value
627
628 ; Test if the Timer is at 0 and if so skip the decrement
629 cmp r2,#1
630 beq EXPIRED
631
632 SUBS r2,r2,#1 ; Decrement the timer value
633 STR r2,[r0,#0] ; Store the new timer value
634
635 bne TMT_No_Timer_Active ; Skip over the Set Timer State
636
637 ; Determine if the timer has expired. If so, modify the state
638 ; to indicate that it has expired.
639 ; if (TMD_Timer == 0)
640
641 ; TMD_Timer_State = TM_EXPIRED;
642
643 EXPIRED:
644 STREQ r3,[r1,#0] ; Change the timer state to
645 ; expired
646
647 ; }
648 TMT_No_Timer_Active:
649
650 ; Determine if the time-slice timer is active. Note that the parameters
651 ; for the time-slice are controlled by the Thread Control (TC)
652 ; component.
653 ; if (TMD_Time_Slice_State == TM_ACTIVE)
654 ; {
655 LDR r0,Slice_State ; Build time slice state address
656 LDR r2,[r0,#0] ; Pickup time slice state
657 CMP r2,#0 ; Is there a time slice active?
658 BNE TMT_No_Time_Slice_Active ; No, skip time slice processing
659
660 ; Decrement the time slice counter.
661 ; TMD_Time_Slice--;
662
663 LDR r2,Time_Slice ; Build time slice address
664 LDR r3,[r2,#0] ; Pickup the time slice value
665 SUBS r3,r3,#1 ; Decrement the time slice
666 STR r3,[r2,#0] ; Store the new time slice value
667
668 ; Determine if the time-slice timer has expired. If so, modify the
669 ; time-slice state to indicate that it has.
670 ; if (TMD_Time_Slice == 0)
671 ; {
672
673 BNE TMT_No_Time_Slice_Active ; Has time slice expired?
674
675 ; TMD_Time_Slice_State = TM_EXPIRED;
676
677 MOV r3,#2 ; Build TM_EXPIRED value
678 STR r3,[r0,#0] ; Indicate time slice is expired
679
680 ; Copy the current thread into the time-slice task pointer.
681 ; TMD_Time_Slice_Task = TCD_Current_Thread;
682
683 LDR r2,Current_Thread ; Pickup current thread pointer adr
684 LDR r2,[r2,#0] ; Pickup current thread pointer
685 LDR r3,Slice_Task ; Pickup time slice task pointer ad
686 STR r2,[r3,#0] ; Store current thread pointer
687
688 ; ((TC_TCB *) TCD_Current_Thread) -> tc_cur_time_slice = 1;
689
690 MOV r3,#1 ; For safety, place a minimal time-
691 STR a4,[a3,#20h]! ; slice into the task's control
692 ; block
693
694 ; }
695 ; }
696 TMT_No_Time_Slice_Active:
697
698 ; Determine if either of the basic timers have expired. If so,
699 ; activate the timer HISR.
700 ; if ((TMD_Timer_State == TM_EXPIRED) ||
701 ; (TMD_Time_Slice_State == TM_EXPIRED))
702 ; {
703
704 LDR r1,[r1,#0] ; Pickup timer state
705 CMP r1,#2 ; Does it indicate expiration?
706 LDRNE r0,[r0,#0] ; Pickup time slice state
707 CMPNE r0,#2 ; Does it indicate expiration?
708
709 BXNE r14 ; Return if no expiration
710
711 ; Activate the HISR timer function.
712 ; TCT_Activate_HISR(&TMD_HISR);
713
714 STR r14,[r13, #-4]! ; Save r14 on the stack
715 LDR r0,HISR ; Build address of timer HISR
716 BL _TCT_Activate_HISR ; Activate timer HISR
717 LDR r14,[r13], #4 ; Recover return address
718 ; }
719
720 BX r14 ; Return to caller
721
722 ;}
723 .end
724
725