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