📄 tc.lst
字号:
76 {
77 pTc->TC_CCR = AT91C_TC_CLKDIS;
\ TC_Stop:
\ 00000000 0210A0E3 MOV R1,#+2
\ 00000004 001080E5 STR R1,[R0, #+0]
78 }
\ 00000008 1EFF2FE1 BX LR ;; return
79
80 //------------------------------------------------------------------------------
81 /// Finds the best MCK divisor given the timer frequency and MCK. The result
82 /// is guaranteed to satisfy the following equation:
83 /// \pre
84 /// (MCK / (DIV * 65536)) <= freq <= (MCK / DIV)
85 /// \endpre
86 /// with DIV being the highest possible value.
87 /// \param freq Desired timer frequency.
88 /// \param mck Master clock frequency.
89 /// \param div Divisor value.
90 /// \param tcclks TCCLKS field value for divisor.
91 /// \return 1 if a proper divisor has been found; otherwise 0.
92 //------------------------------------------------------------------------------
\ In section .text, align 4, keep-with-next
93 unsigned char TC_FindMckDivisor(
94 unsigned int freq,
95 unsigned int mck,
96 unsigned int *div,
97 unsigned int *tcclks)
98 {
\ TC_FindMckDivisor:
\ 00000000 F0432DE9 PUSH {R4-R9,LR}
\ 00000004 14D04DE2 SUB SP,SP,#+20
\ 00000008 0040A0E1 MOV R4,R0
\ 0000000C 0150A0E1 MOV R5,R1
\ 00000010 0260A0E1 MOV R6,R2
\ 00000014 0370A0E1 MOV R7,R3
99 const unsigned int divisors[5] = {2, 8, 32, 128,
100 #if defined(at91sam9260) || defined(at91sam9261) || defined(at91sam9263) \
101 || defined(at91sam9xe) || defined(at91sam9rl64) || defined(at91cap9)
102 BOARD_MCK / 32768};
103 #else
104 1024};
\ 00000018 0D00A0E1 MOV R0,SP
\ 0000001C 7C109FE5 LDR R1,??TC_FindMckDivisor_0 ;; `?<Constant {2, 8, 32, 128, 1024}>`
\ 00000020 0C51B1E8 LDM R1!,{R2,R3,R8,R12,LR}
\ 00000024 0C51A0E8 STM R0!,{R2,R3,R8,R12,LR}
105 #endif
106 unsigned int index = 0;
\ 00000028 0080A0E3 MOV R8,#+0
\ 0000002C 0D90A0E1 MOV R9,SP
107
108 // Satisfy lower bound
109 while (freq < ((mck / divisors[index]) / 65536)) {
\ ??TC_FindMckDivisor_1:
\ 00000030 0500A0E1 MOV R0,R5
\ 00000034 041099E4 LDR R1,[R9], #+4
\ 00000038 ........ BL __aeabi_uidivmod
\ 0000003C 200854E1 CMP R4,R0, LSR #+16
\ 00000040 0500002A BCS ??TC_FindMckDivisor_2
110
111 index++;
\ 00000044 018088E2 ADD R8,R8,#+1
112
113 // If no divisor can be found, return 0
114 if (index == 5) {
\ 00000048 050058E3 CMP R8,#+5
\ 0000004C F7FFFF1A BNE ??TC_FindMckDivisor_1
115
116 return 0;
\ 00000050 0000A0E3 MOV R0,#+0
\ 00000054 0E0000EA B ??TC_FindMckDivisor_3
117 }
118 }
119
120 // Try to maximise DIV while satisfying upper bound
121 while (index < 4) {
122
123 if (freq > (mck / divisors[index + 1])) {
124
125 break;
126 }
127 index++;
\ ??TC_FindMckDivisor_4:
\ 00000058 018088E2 ADD R8,R8,#+1
\ ??TC_FindMckDivisor_2:
\ 0000005C 040058E3 CMP R8,#+4
\ 00000060 0500002A BCS ??TC_FindMckDivisor_5
\ 00000064 0500A0E1 MOV R0,R5
\ 00000068 08118DE0 ADD R1,SP,R8, LSL #+2
\ 0000006C 041091E5 LDR R1,[R1, #+4]
\ 00000070 ........ BL __aeabi_uidivmod
\ 00000074 040050E1 CMP R0,R4
\ 00000078 F6FFFF2A BCS ??TC_FindMckDivisor_4
128 }
129
130 // Store results
131 if (div) {
\ ??TC_FindMckDivisor_5:
\ 0000007C 000056E3 CMP R6,#+0
132
133 *div = divisors[index];
\ 00000080 08019D17 LDRNE R0,[SP, +R8, LSL #+2]
\ 00000084 00008615 STRNE R0,[R6, #+0]
134 }
135 if (tcclks) {
\ 00000088 000057E3 CMP R7,#+0
136
137 *tcclks = index;
\ 0000008C 00808715 STRNE R8,[R7, #+0]
138 }
139
140 return 1;
\ 00000090 0100A0E3 MOV R0,#+1
\ ??TC_FindMckDivisor_3:
\ 00000094 14D08DE2 ADD SP,SP,#+20 ;; stack cleaning
\ 00000098 F043BDE8 POP {R4-R9,LR}
\ 0000009C 1EFF2FE1 BX LR ;; return
\ ??TC_FindMckDivisor_0:
\ 000000A0 ........ DC32 `?<Constant {2, 8, 32, 128, 1024}>`
141 }
\ In section .rodata, align 4
\ `?<Constant {2, 8, 32, 128, 1024}>`:
\ 00000000 020000000800 DC32 2, 8, 32, 128, 1024
\ 000020000000
\ 800000000004
\ 0000
142
Maximum stack usage in bytes:
Function .cstack
-------- -------
TC_Configure 0
TC_FindMckDivisor 0
TC_Start 0
TC_Stop 0
Section sizes:
Function/Label Bytes
-------------- -----
TC_Configure 28
TC_Start 12
TC_Stop 12
TC_FindMckDivisor 164
?<Constant {2, 8, 32, 128, 1024}> 20
20 bytes in section .rodata
216 bytes in section .text
216 bytes of CODE memory
20 bytes of CONST memory
Errors: none
Warnings: none
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -