4242volatile uint64_t gl_loops_per_jiffy = 1 ;
4343volatile uint32_t gl_count = 1 ;
4444
45-
46-
47-
48-
4945/**
5046 * \brief check whether the specific timer present
5147 * \param[in] no timer number
@@ -54,6 +50,7 @@ volatile uint32_t gl_count = 1;
5450int32_t timer_present (const uint32_t no )
5551{
5652 uint32_t bcr = _arc_aux_read (AUX_BCR_TIMERS );
53+
5754 switch (no ) {
5855 case TIMER_0 :
5956 bcr = (bcr >> 8 ) & 1 ;
@@ -82,10 +79,6 @@ int32_t timer_present(const uint32_t no)
8279 */
8380int32_t timer_start (const uint32_t no , const uint32_t mode , const uint32_t val )
8481{
85- if (timer_present (no ) == 0 ) {
86- return -1 ;
87- }
88-
8982 switch (no ) {
9083 case TIMER_0 :
9184 _arc_aux_write (AUX_TIMER0_CTRL , 0 );
@@ -117,10 +110,6 @@ int32_t timer_start(const uint32_t no, const uint32_t mode, const uint32_t val)
117110 */
118111int32_t timer_stop (const uint32_t no )
119112{
120- if (timer_present (no ) == 0 ) {
121- return -1 ;
122- }
123-
124113 switch (no ) {
125114 case TIMER_0 :
126115 _arc_aux_write (AUX_TIMER0_CTRL , 0 );
@@ -151,10 +140,6 @@ int32_t timer_stop(const uint32_t no)
151140 */
152141int32_t timer_current (const uint32_t no , void * val )
153142{
154- if (timer_present (no ) == 0 ) {
155- return -1 ;
156- }
157-
158143 switch (no ) {
159144 case TIMER_0 :
160145 * ((uint32_t * )val ) = _arc_aux_read (AUX_TIMER0_CNT );
@@ -182,10 +167,6 @@ int32_t timer_int_clear(const uint32_t no)
182167{
183168 uint32_t val ;
184169
185- if (timer_present (no ) == 0 ) {
186- return -1 ;
187- }
188-
189170 switch (no ) {
190171 case TIMER_0 :
191172 val = _arc_aux_read (AUX_TIMER0_CTRL );
@@ -209,9 +190,17 @@ int32_t timer_int_clear(const uint32_t no)
209190 */
210191void timer_init (void )
211192{
212- timer_stop (TIMER_0 );
213- timer_stop (TIMER_1 );
214- timer_stop (TIMER_RTC );
193+ if (timer_present (TIMER_0 )) {
194+ timer_stop (TIMER_0 );
195+ }
196+
197+ if (timer_present (TIMER_1 )) {
198+ timer_stop (TIMER_1 );
199+ }
200+
201+ if (timer_present (TIMER_RTC )) {
202+ timer_stop (TIMER_RTC );
203+ }
215204}
216205
217206
@@ -224,6 +213,7 @@ void timer_init(void)
224213int32_t secure_timer_present (const uint32_t no )
225214{
226215 uint32_t bcr = _arc_aux_read (AUX_BCR_TIMERS );
216+
227217 switch (no ) {
228218 case SECURE_TIMER_0 :
229219 bcr = (bcr >> 11 ) & 1 ;
@@ -249,10 +239,6 @@ int32_t secure_timer_present(const uint32_t no)
249239 */
250240int32_t secure_timer_start (const uint32_t no , const uint32_t mode , const uint32_t val )
251241{
252- if (secure_timer_present (no ) == 0 ) {
253- return -1 ;
254- }
255-
256242 switch (no ) {
257243 case SECURE_TIMER_0 :
258244 _arc_aux_write (AUX_SECURE_TIMER0_CTRL , 0 );
@@ -281,10 +267,6 @@ int32_t secure_timer_start(const uint32_t no, const uint32_t mode, const uint32_
281267 */
282268int32_t secure_timer_stop (const uint32_t no )
283269{
284- if (secure_timer_present (no ) == 0 ) {
285- return -1 ;
286- }
287-
288270 switch (no ) {
289271 case SECURE_TIMER_0 :
290272 _arc_aux_write (AUX_SECURE_TIMER0_CTRL , 0 );
@@ -312,10 +294,6 @@ int32_t secure_timer_stop(const uint32_t no)
312294 */
313295int32_t secure_timer_current (const uint32_t no , void * val )
314296{
315- if (secure_timer_present (no ) == 0 ) {
316- return -1 ;
317- }
318-
319297 switch (no ) {
320298 case SECURE_TIMER_0 :
321299 * ((uint32_t * )val ) = _arc_aux_read (AUX_SECURE_TIMER0_CNT );
@@ -340,10 +318,6 @@ int32_t secure_timer_int_clear(const uint32_t no)
340318{
341319 uint32_t val ;
342320
343- if (secure_timer_present (no ) == 0 ) {
344- return -1 ;
345- }
346-
347321 switch (no ) {
348322 case SECURE_TIMER_0 :
349323 val = _arc_aux_read (AUX_SECURE_TIMER0_CTRL );
@@ -367,8 +341,13 @@ int32_t secure_timer_int_clear(const uint32_t no)
367341 */
368342void secure_timer_init (void )
369343{
370- secure_timer_stop (SECURE_TIMER_0 );
371- secure_timer_stop (SECURE_TIMER_1 );
344+ if (secure_timer_present (SECURE_TIMER_0 )) {
345+ secure_timer_stop (SECURE_TIMER_0 );
346+ }
347+
348+ if (secure_timer_present (SECURE_TIMER_1 )) {
349+ secure_timer_stop (SECURE_TIMER_1 );
350+ }
372351}
373352#endif /* ARC_FEATURE_SEC_TIMER1_PRESENT && ARC_FEATURE_SEC_TIMER0_PRESENT */
374353
@@ -382,18 +361,18 @@ void arc_delay_us(uint32_t usecs)
382361 __asm__ __volatile__(
383362
384363 " .extern gl_loops_per_jiffy \n"
385- " .extern gl_count \n"
386- " cmp %0, 0 \n"
387- " jeq 1f \n"
388- " ld %%r1, [gl_loops_per_jiffy] \n"
389- " mpy %%r1, %%r1, %0 \n"
364+ " .extern gl_count \n"
365+ " cmp %0, 0 \n"
366+ " jeq 1f \n"
367+ " ld %%r1, [gl_loops_per_jiffy] \n"
368+ " mpy %%r1, %%r1, %0 \n"
390369 " ld %%r2, [gl_count] \n"
391370 " divu %%r1, %%r1, %%r2 \n"
392- " .align 4 \n"
371+ " .align 4 \n"
393372 " mov %%lp_count, %%r1 \n"
394- " lp 1f \n"
395- " nop \n"
396- "1: \n"
373+ " lp 1f \n"
374+ " nop \n"
375+ "1: \n"
397376 :
398377 : "r" (usecs )
399378 : "lp_count" , "r1" , "r2" );
@@ -454,4 +433,3 @@ uint64_t timer_calibrate_delay(uint32_t cpu_clock)
454433
455434 return loops_per_jiffy ;
456435}
457-
0 commit comments