Skip to content

Instantly share code, notes, and snippets.

@marksat
Created September 20, 2022 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marksat/b1bfa1e44cd543801b71080e78fd2971 to your computer and use it in GitHub Desktop.
Save marksat/b1bfa1e44cd543801b71080e78fd2971 to your computer and use it in GitHub Desktop.
FreeRTOS v10.2.0, GCC 12.2.0 (with const)
40006156 <vPortSetupTimerInterrupt>:
40006156: 0200c6b7 lui a3,0x200c
4000615a: ffc68713 addi a4,a3,-4 # 200bffc <__ram_length+0x1ffec0c>
4000615e: ff868793 addi a5,a3,-8
40006162: 4310 lw a2,0(a4)
40006164: 439c lw a5,0(a5)
40006166: 4318 lw a4,0(a4)
40006168: fec719e3 bne a4,a2,4000615a <vPortSetupTimerInterrupt+0x4>
4000616c: 13278593 addi a1,a5,306
40006170: 00f5b533 sltu a0,a1,a5
40006174: 862e mv a2,a1
40006176: 020045b7 lui a1,0x2004
4000617a: c190 sw a2,0(a1)
4000617c: 26478613 addi a2,a5,612
40006180: 00e506b3 add a3,a0,a4
40006184: 00f637b3 sltu a5,a2,a5
40006188: c1d4 sw a3,4(a1)
4000618a: 97ba add a5,a5,a4
4000618c: 800006b7 lui a3,0x80000
40006190: 1ec6a823 sw a2,496(a3) # 800001f0 <__freertos_irq_stack_top+0xffff2df0>
40006194: 1ef6aa23 sw a5,500(a3)
40006198: 8082 ret
40004c5e <handle_asynchronous>:
40004c5e: 800002b7 lui t0,0x80000
40004c62: 00728313 addi t1,t0,7 # 80000007 <__freertos_irq_stack_top+0xffff2c07>
40004c66: 04651a63 bne a0,t1,40004cba <test_if_external_interrupt>
40004c6a: 3fffb297 auipc t0,0x3fffb
40004c6e: 48e2a283 lw t0,1166(t0) # 800000f8 <pullMachineTimerCompareRegister>
40004c72: 3fffb317 auipc t1,0x3fffb
40004c76: 4b632303 lw t1,1206(t1) # 80000128 <pullNextTime>
40004c7a: 00032383 lw t2,0(t1)
40004c7e: 00432e03 lw t3,4(t1)
40004c82: 0072a023 sw t2,0(t0)
40004c86: 01c2a223 sw t3,4(t0)
40004c8a: 3fffb297 auipc t0,0x3fffb
40004c8e: 49a2a283 lw t0,1178(t0) # 80000124 <ulTimerIncrementsForOneTick>
40004c92: 00728eb3 add t4,t0,t2
40004c96: 007ebf33 sltu t5,t4,t2
40004c9a: 01ee0fb3 add t6,t3,t5
40004c9e: 01d32023 sw t4,0(t1)
40004ca2: 01f32223 sw t6,4(t1)
40004ca6: 3fffb117 auipc sp,0x3fffb
40004caa: 48612103 lw sp,1158(sp) # 8000012c <xISRStackTop>
40004cae: 3c0000ef jal ra,4000506e <xTaskIncrementTick>
40004cb2: cd15 beqz a0,40004cee <processed_source>
40004cb4: 4f8000ef jal ra,400051ac <vTaskSwitchContext>
40004cb8: a81d j 40004cee <processed_source>
@marksat
Copy link
Author

marksat commented Sep 20, 2022

From port.c:
const uint32_t ulTimerIncrementsForOneTick = ( uint32_t ) ( configRTC_CLOCK_HZ / configTICK_RATE_HZ ); /* Assumes increment won't go over 32-bits. */

@marksat
Copy link
Author

marksat commented Sep 20, 2022

configRTC_CLOCK_HZ / configTICK_RATE_HZ = (122666666 / 100) / 4000 = 306

The compiler seems to have been smart enough to optimise this variable into a direct register access in vPortSetupTimerInterrupt():
4000616c: 13278593 addi a1,a5,306

However, vPortSetupTimerInterrupt() is only called when the FreeRTOS is started. The MTIMECMP register needs to be updated in portASM.S: lw t0,1178(t0) # 80000124 <ulTimerIncrementsForOneTick>. However, this memory address contains the value 0 which means the machine timer will generate an interrupt almost immediately.

@marksat
Copy link
Author

marksat commented Sep 20, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment