1;/**************************************************************************/ 2;/* */ 3;/* Copyright (c) Microsoft Corporation. All rights reserved. */ 4;/* */ 5;/* This software is licensed under the Microsoft Software License */ 6;/* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7;/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8;/* and in the root directory of this software. */ 9;/* */ 10;/**************************************************************************/ 11; 12; 13;/**************************************************************************/ 14;/**************************************************************************/ 15;/** */ 16;/** ThreadX Component */ 17;/** */ 18;/** Thread */ 19;/** */ 20;/**************************************************************************/ 21;/**************************************************************************/ 22 23SWI0 EQU 0x872E0 24 25 extern __tx_timer_expiration_process 26 extern __tx_timer_system_clock 27 extern __tx_timer_expired_time_slice 28 extern __tx_timer_current_ptr 29 extern __tx_timer_expired 30 extern __tx_timer_list_start 31 extern __tx_timer_time_slice 32 extern __tx_timer_list_end 33 extern __tx_thread_time_slice 34 extern __tx_thread_preempt_disable 35 extern __tx_thread_execute_ptr 36 extern __tx_thread_current_ptr 37 38 section .text:CODE:ROOT 39 40;/**************************************************************************/ 41;/* */ 42;/* FUNCTION RELEASE */ 43;/* */ 44;/* _tx_timer_interrupt RXv1/IAR */ 45;/* 6.1.11 */ 46;/* AUTHOR */ 47;/* */ 48;/* William E. Lamie, Microsoft Corporation */ 49;/* */ 50;/* DESCRIPTION */ 51;/* */ 52;/* This function processes the hardware timer interrupt. This */ 53;/* processing includes incrementing the system clock and checking for */ 54;/* time slice and/or timer expiration. If either is found, the */ 55;/* interrupt context save/restore functions are called along with the */ 56;/* expiration functions. */ 57;/* */ 58;/* INPUT */ 59;/* */ 60;/* None */ 61;/* */ 62;/* OUTPUT */ 63;/* */ 64;/* None */ 65;/* */ 66;/* CALLS */ 67;/* */ 68;/* _tx_thread_context_save Save interrupted context */ 69;/* _tx_timer_expiration_process Timer expiration processing */ 70;/* _tx_thread_time_slice Time slice interrupted thread */ 71;/* _tx_thread_context_restore Restore interrupted context */ 72;/* */ 73;/* CALLED BY */ 74;/* */ 75;/* interrupt vector */ 76;/* */ 77;/* RELEASE HISTORY */ 78;/* */ 79;/* DATE NAME DESCRIPTION */ 80;/* */ 81;/* 08-02-2021 William E. Lamie Initial Version 6.1.8 */ 82;/* 10-15-2021 William E. Lamie Modified comment(s), */ 83;/* resulting in version 6.1.9 */ 84;/* 01-31-2022 William E. Lamie Modified comment(s), and */ 85;/* added missing thread */ 86;/* preemption logic, */ 87;/* resulting in version 6.1.10 */ 88;/* 04-25-2022 William E. Lamie Modified comment(s), */ 89;/* resulting in version 6.1.11 */ 90;/* */ 91;/**************************************************************************/ 92 93 public __tx_timer_interrupt 94__tx_timer_interrupt: 95; 96; /* Upon entry to this routine, it is assumed that all interrupts are locked 97; out and the stack looks like the following: 98; SP+4 -> Interrupted PC 99; SP+8-> Interrupted SR 100; */ 101; 102; /* Increment the system clock. */ 103; _tx_timer_system_clock++; 104; 105 PUSHM R14-R15 106 PUSHM R1-R5 107 108 MOV.L #__tx_timer_system_clock, R1 ; Pickup address of system clock 109 MOV.L [R1], R2 ; Pickup system clock 110 ADD #1, R2 ; Increment system clock 111 MOV.L R2,[R1] ; Store new system clock 112; 113; /* Test for time-slice expiration. */ 114; if (_tx_timer_time_slice) 115; { 116; 117 MOV.L #__tx_timer_time_slice, R1 ; Pickup address of time slice 118 MOV.L [R1], R2 ; Pickup the current time slice 119 CMP #0, R2 ; Is a time slice active? 120 BEQ __tx_timer_no_time_slice ; No, skip timer slice processing 121; 122; /* Decrement the time_slice. */ 123; _tx_timer_time_slice--; 124; 125 SUB #1, R2 ; Decrement the time-slice 126 MOV.L R2, [R1] ; Store time-slice 127; 128; /* Check for expiration. */ 129; if (__tx_timer_time_slice == 0) 130; 131 CMP #0, R2 ; Has it expired? 132 BNE __tx_timer_no_time_slice ; No, time-slice has not expired 133; 134; /* Set the time-slice expired flag. */ 135; _tx_timer_expired_time_slice = TX_TRUE; 136; 137 MOV.L #__tx_timer_expired_time_slice, R1 ; Pickup address of expired time-slice 138 MOV.L #1, R2 ; Build expired value 139 MOV.L R2, [R1] ; Set expired time slice variable 140; } 141; 142__tx_timer_no_time_slice: 143; 144; /* Test for timer expiration. */ 145; if (*_tx_timer_current_ptr) 146; { 147; 148 MOV.L #__tx_timer_current_ptr, R1 ; Pickup address of current timer ptr 149 MOV.L [R1], R2 ; Pickup current pointer 150 MOV.L [R2+], R1 ; pickup timer list entry, _tx_timer_current_ptr++ 151 CMP #0, R1 ; Is timer pointer NULL? 152 BEQ __tx_timer_no_timer ; Yes, no timer has expired 153 154; 155; /* Set expiration flag. */ 156; _tx_timer_expired = TX_TRUE; 157; 158 MOV.L #__tx_timer_expired,R2 ; Build address of expired flag 159 MOV.L #1, R1 ; Build expired value 160 MOV.L R1, [R2] 161 BRA __tx_timer_done ; Finished with timer processing 162; 163; } 164; else 165; { 166__tx_timer_no_timer: 167; 168; /* No timer expired, increment the timer pointer. */ 169; _tx_timer_current_ptr++; 170; 171; /* R2 already contains __tx_timer_current_ptr++ */ 172; 173; /* Check for wrap-around. */ 174; if (_tx_timer_current_ptr == _tx_timer_list_end) 175; 176 MOV.L #__tx_timer_list_end, R1 ; Pickup the timer list end ptr 177 MOV.L [R1], R1 ; Pickup actual timer list end 178 CMP R1, R2 ; Are we at list end? 179 BNE __tx_timer_skip_wrap ; No, don't move pointer to the 180 ; top of the list 181; 182; /* Wrap to beginning of list. */ 183; _tx_timer_current_ptr = _tx_timer_list_start; 184; 185 MOV.L #__tx_timer_list_start, R2 ; Pickup the timer list start ptr 186 MOV.L [R2], R2 ; Pickup the start of the list 187; } 188; 189__tx_timer_skip_wrap: 190 MOV.L #__tx_timer_current_ptr,R1 191 MOV.L R2, [R1] ; Store in updated pointer in _tx_timer_current_ptr 192 193__tx_timer_done: 194; 195; /* See if anything has expired. */ 196; if ((_tx_timer_expired_time_slice) || (_tx_timer_expired)) 197; { 198; 199 MOV.L #__tx_timer_expired_time_slice, R1 ; Pickup expired time slice addr 200 MOV.L [R1], R1 ; Pickup expired time slice 201 MOV.L #__tx_timer_expired, R2 ; Pickup expired timer flag address 202 MOV.L [R2], R2 ; Pickup actual flag 203 OR R1, R2 ; Or flags together 204 BEQ __tx_timer_nothing_expired ; If Z set, nothing has expired 205 206__tx_something_expired: 207; /* Did a timer expire? */ 208; if (_tx_timer_expired) 209; { 210 MOV.L #__tx_timer_expired,R1 ; Pickup expired flag address 211 MOV.L [R1], R1 ; Pickup expired flag 212 CMP #0,R1 ; Is the expired timer flag set? 213 BEQ __tx_timer_dont_activate ; No, skip timer activation 214; 215; /* Process timer expiration. */ 216; _tx_timer_expiration_process(); 217; 218 BSR __tx_timer_expiration_process ; Call the timer expiration handling routine 219; 220; } 221__tx_timer_dont_activate: 222; 223; /* Did time slice expire? */ 224; if (_tx_timer_expired_time_slice) 225; { 226; 227 MOV.L #__tx_timer_expired_time_slice, R1 ; Pickup time-slice expired flag addr 228 MOV.L [R1], R1 ; Pickup actual flag 229 CMP #0,R1 ; Has time-slice expired? 230 BEQ __tx_timer_not_ts_expiration ; No, skip time-slice expiration 231; 232; /* Time slice interrupted thread. */ 233; _tx_thread_time_slice(); 234 235 BSR __tx_thread_time_slice ; Call time-slice processing 236 237; /* Check if we must trigger a context switch. */ 238 MOV.L #__tx_thread_preempt_disable, R1 ; Load prempt disable flag. 239 MOV.L [R1], R1 240 CMP #0, R1 241 BNE __tx_timer_not_ts_expiration ; Skip if prempt disabled. 242 243 MOV.L #__tx_thread_execute_ptr, R1 244 MOV.L [R1], R1 245 MOV.L #__tx_thread_current_ptr, R2 246 MOV.L [R2], R2 247 CMP R1, R2 248 BEQ __tx_timer_not_ts_expiration 249 250 MOV.L #SWI0, R1 251 MOV.L #1, [R1] 252 253; } 254; 255__tx_timer_not_ts_expiration: 256 257__tx_timer_nothing_expired: 258 259 POPM R1-R5 260 POPM R14-R15 261; 262 RTS ; Return to point of interrupt 263; 264;} 265 END 266