@@ -50,12 +50,6 @@ any details of its type. */
5050typedef void TCB_t ;
5151extern volatile TCB_t * volatile pxCurrentTCB ;
5252
53- /*-----------------------------------------------------------*/
54- /*
55- * Perform hardware setup to enable ticks from Watchdog Timer.
56- */
57- static void prvSetupTimerInterrupt ( void );
58-
5953/*-----------------------------------------------------------*/
6054
6155/*
@@ -374,6 +368,11 @@ static void prvSetupTimerInterrupt( void );
374368#endif
375369/*-----------------------------------------------------------*/
376370
371+ /*
372+ * Perform hardware setup to enable ticks from Watchdog Timer.
373+ */
374+ static void prvSetupTimerInterrupt ( void );
375+ /*-----------------------------------------------------------*/
377376
378377/*
379378 * See header file for description.
@@ -397,36 +396,28 @@ uint16_t usAddress;
397396
398397 /* The start of the task code will be popped off the stack last, so place
399398 it on first. */
399+ usAddress = ( uint16_t ) pxCode ;
400+ * pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
401+ pxTopOfStack -- ;
402+
403+ usAddress >>= 8 ;
404+ * pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
405+ pxTopOfStack -- ;
400406
401407#if defined(__AVR_3_BYTE_PC__ )
402408 /* The AVR ATmega2560/ATmega2561 have 256KBytes of program memory and a 17-bit
403- * program counter. When a code address is stored on the stack, it takes 3 bytes
409+ * program counter. When a code address is stored on the stack, it takes 3 bytes
404410 * instead of 2 for the other ATmega* chips.
405411 *
406412 * Store 0 as the top byte since we force all task routines to the bottom 128K
407413 * of flash. We do this by using the .lowtext label in the linker script.
408414 *
409415 * In order to do this properly, we would need to get a full 3-byte pointer to
410- * pxCode. That requires a change to GCC. Not likely to happen any time soon.
416+ * pxCode. That requires a change to GCC. Not likely to happen any time soon.
411417 */
412- usAddress = ( uint16_t ) pxCode ;
413- * pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
414- pxTopOfStack -- ;
415-
416- usAddress >>= 8 ;
417- * pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
418- pxTopOfStack -- ;
419418
420419 * pxTopOfStack = 0 ;
421420 pxTopOfStack -- ;
422- #else
423- usAddress = ( uint16_t ) pxCode ;
424- * pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
425- pxTopOfStack -- ;
426-
427- usAddress >>= 8 ;
428- * pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
429- pxTopOfStack -- ;
430421#endif
431422
432423 /* Next simulate the stack as if after a call to portSAVE_CONTEXT().
@@ -454,7 +445,7 @@ uint16_t usAddress;
454445 pxTopOfStack -- ;
455446#endif
456447
457- /* Now the remaining registers. The compiler expects R1 to be 0. */
448+ /* Now the remaining registers. The compiler expects R1 to be 0. */
458449 * pxTopOfStack = ( StackType_t ) 0x00 ; /* R1 */
459450 pxTopOfStack -- ;
460451 * pxTopOfStack = ( StackType_t ) 0x02 ; /* R2 */
@@ -521,7 +512,7 @@ uint16_t usAddress;
521512 pxTopOfStack -- ;
522513 * pxTopOfStack = ( StackType_t ) 0x30 ; /* R30 Z */
523514 pxTopOfStack -- ;
524- * pxTopOfStack = ( StackType_t ) 0x031 ; /* R31 */
515+ * pxTopOfStack = ( StackType_t ) 0x031 ; /* R31 */
525516 pxTopOfStack -- ;
526517
527518 return pxTopOfStack ;
@@ -536,7 +527,7 @@ BaseType_t xPortStartScheduler( void )
536527 /* Restore the context of the first task that is going to run. */
537528 portRESTORE_CONTEXT ();
538529
539- /* Simulate a function call end as generated by the compiler. We will now
530+ /* Simulate a function call end as generated by the compiler. We will now
540531 jump to the start of the task the context of which we have just restored. */
541532 __asm__ __volatile__ ( "ret" );
542533
@@ -550,12 +541,12 @@ void vPortEndScheduler( void )
550541 /* It is unlikely that the AVR port will get stopped. If required simply
551542 disable the tick interrupt here. */
552543
553- wdt_disable (); // disable Watchdog Timer
544+ wdt_disable (); /* disable Watchdog Timer */
554545}
555546/*-----------------------------------------------------------*/
556547
557548/*
558- * Manual context switch. The first thing we do is save the registers so we
549+ * Manual context switch. The first thing we do is save the registers so we
559550 * can use a naked attribute.
560551 */
561552void vPortYield ( void ) __attribute__ ( ( hot , flatten , naked ) );
@@ -570,23 +561,20 @@ void vPortYield( void )
570561/*-----------------------------------------------------------*/
571562
572563/*
573- * Context switch function used by the tick. This must be identical to
574- * vPortYield() from the call to vTaskSwitchContext() onwards. The only
564+ * Context switch function used by the tick. This must be identical to
565+ * vPortYield() from the call to vTaskSwitchContext() onwards. The only
575566 * difference from vPortYield() is the tick count is incremented as the
576567 * call comes from the tick ISR.
577568 */
578569void vPortYieldFromTick ( void ) __attribute__ ( ( hot , flatten , naked ) );
579570void vPortYieldFromTick ( void )
580571{
581572 portSAVE_CONTEXT ();
582-
583- sleep_reset (); // reset the sleep_mode() faster than sleep_disable();
584-
573+ sleep_reset (); /* reset the sleep_mode() faster than sleep_disable(); */
585574 if ( xTaskIncrementTick () != pdFALSE )
586575 {
587576 vTaskSwitchContext ();
588577 }
589-
590578 portRESTORE_CONTEXT ();
591579
592580 __asm__ __volatile__ ( "ret" );
@@ -604,14 +592,13 @@ void prvSetupTimerInterrupt( void )
604592 /* set up WDT Interrupt (rather than the WDT Reset). */
605593 wdt_interrupt_enable ( portUSE_WDTO );
606594}
607-
608595/*-----------------------------------------------------------*/
609596
610597#if configUSE_PREEMPTION == 1
611598
612599 /*
613- * Tick ISR for preemptive scheduler. We can use a naked attribute as
614- * the context is saved at the start of vPortYieldFromTick(). The tick
600+ * Tick ISR for preemptive scheduler. We can use a naked attribute as
601+ * the context is saved at the start of vPortYieldFromTick(). The tick
615602 * count is incremented after the context is saved.
616603 *
617604 * use ISR_NOBLOCK where there is an important timer running, that should preempt the scheduler.
@@ -628,8 +615,8 @@ void prvSetupTimerInterrupt( void )
628615#else
629616
630617 /*
631- * Tick ISR for the cooperative scheduler. All this does is increment the
632- * tick count. We don't need to switch context, this can only be done by
618+ * Tick ISR for the cooperative scheduler. All this does is increment the
619+ * tick count. We don't need to switch context, this can only be done by
633620 * manual calls to taskYIELD();
634621 *
635622 * use ISR_NOBLOCK where there is an important timer running, that should preempt the scheduler.
0 commit comments