42
42
*----------------------------------------------------------*/
43
43
44
44
/* Start tasks with interrupts enabled. */
45
- #define portFLAGS_INT_ENABLED ( (StackType_t) 0x80 )
45
+ #define portFLAGS_INT_ENABLED ( ( StackType_t ) 0x80 )
46
46
47
47
#if defined( portUSE_WDTO )
48
- #define portSCHEDULER_ISR WDT_vect
48
+ #define portSCHEDULER_ISR WDT_vect
49
49
50
50
#else
51
51
#warning "The user must define a Timer to be used for the Scheduler."
54
54
/*-----------------------------------------------------------*/
55
55
56
56
/* We require the address of the pxCurrentTCB variable, but don't want to know
57
- any details of its type. */
57
+ * any details of its type. */
58
58
typedef void TCB_t ;
59
59
extern volatile TCB_t * volatile pxCurrentTCB ;
60
60
61
61
/*-----------------------------------------------------------*/
62
62
63
63
/**
64
- Enable the watchdog timer, configuring it for expire after
65
- (value) timeout (which is a combination of the WDP0
66
- through WDP3 bits).
67
-
68
- This function is derived from <avr/wdt.h> but enables only
69
- the interrupt bit (WDIE), rather than the reset bit (WDE).
70
-
71
- Can't find it documented but the WDT, once enabled,
72
- rolls over and fires a new interrupt each time.
73
-
74
- See also the symbolic constants WDTO_15MS et al.
75
-
76
- Updated to match avr-libc 2.0.0
77
- */
64
+ * Enable the watchdog timer, configuring it for expire after
65
+ * (value) timeout (which is a combination of the WDP0
66
+ * through WDP3 bits).
67
+ *
68
+ * This function is derived from <avr/wdt.h> but enables only
69
+ * the interrupt bit (WDIE), rather than the reset bit (WDE).
70
+ *
71
+ * Can't find it documented but the WDT, once enabled,
72
+ * rolls over and fires a new interrupt each time.
73
+ *
74
+ * See also the symbolic constants WDTO_15MS et al.
75
+ *
76
+ * Updated to match avr-libc 2.0.0
77
+ */
78
78
79
79
#if defined( portUSE_WDTO )
80
80
@@ -121,26 +121,26 @@ void wdt_interrupt_enable (const uint8_t value)
121
121
122
122
/*-----------------------------------------------------------*/
123
123
/**
124
- Enable the watchdog timer, configuring it for expire after
125
- (value) timeout (which is a combination of the WDP0
126
- through WDP3 bits).
127
-
128
- This function is derived from <avr/wdt.h> but enables both
129
- the reset bit (WDE), and the interrupt bit (WDIE).
130
-
131
- This will ensure that if the interrupt is not serviced
132
- before the second timeout, the AVR will reset.
133
-
134
- Servicing the interrupt automatically clears it,
135
- and ensures the AVR does not reset.
136
-
137
- Can't find it documented but the WDT, once enabled,
138
- rolls over and fires a new interrupt each time.
139
-
140
- See also the symbolic constants WDTO_15MS et al.
141
-
142
- Updated to match avr-libc 2.0.0
143
- */
124
+ * Enable the watchdog timer, configuring it for expire after
125
+ * (value) timeout (which is a combination of the WDP0
126
+ * through WDP3 bits).
127
+ *
128
+ * This function is derived from <avr/wdt.h> but enables both
129
+ * the reset bit (WDE), and the interrupt bit (WDIE).
130
+ *
131
+ * This will ensure that if the interrupt is not serviced
132
+ * before the second timeout, the AVR will reset.
133
+ *
134
+ * Servicing the interrupt automatically clears it,
135
+ * and ensures the AVR does not reset.
136
+ *
137
+ * Can't find it documented but the WDT, once enabled,
138
+ * rolls over and fires a new interrupt each time.
139
+ *
140
+ * See also the symbolic constants WDTO_15MS et al.
141
+ *
142
+ * Updated to match avr-libc 2.0.0
143
+ */
144
144
145
145
#if defined( portUSE_WDTO )
146
146
@@ -551,10 +551,11 @@ uint16_t usAddress;
551
551
#endif
552
552
553
553
/* Next simulate the stack as if after a call to portSAVE_CONTEXT().
554
- portSAVE_CONTEXT places the flags on the stack immediately after r0
555
- to ensure the interrupts get disabled as soon as possible, and so ensuring
556
- the stack use is minimal should a context switch interrupt occur. */
557
- * pxTopOfStack = ( StackType_t ) 0x00 ; /* R0 */
554
+ * portSAVE_CONTEXT places the flags on the stack immediately after r0
555
+ * to ensure the interrupts get disabled as soon as possible, and so ensuring
556
+ * the stack use is minimal should a context switch interrupt occur.
557
+ */
558
+ * pxTopOfStack = ( StackType_t ) 0x00 ; /* R0 */
558
559
pxTopOfStack -- ;
559
560
* pxTopOfStack = portFLAGS_INT_ENABLED ;
560
561
pxTopOfStack -- ;
@@ -605,7 +606,7 @@ BaseType_t xPortStartScheduler( void )
605
606
portRESTORE_CONTEXT ();
606
607
607
608
/* Simulate a function call end as generated by the compiler. We will now
608
- jump to the start of the task the context of which we have just restored. */
609
+ * jump to the start of the task the context of which we have just restored. */
609
610
__asm__ __volatile__ ( "ret" );
610
611
611
612
/* Should not get here. */
@@ -622,15 +623,15 @@ void vPortEndScheduler( void )
622
623
}
623
624
/*-----------------------------------------------------------*/
624
625
625
- /*
626
- * Choose which delay function to use.
627
- * Arduino delay() is a millisecond granularity busy wait, that
628
- * that breaks FreeRTOS. So its use is limited to less than one
629
- * System Tick (portTICK_PERIOD_MS milliseconds).
630
- * FreeRTOS vTaskDelay() is relies on the System Tick which here
631
- * has a granularity of portTICK_PERIOD_MS milliseconds (15ms),
632
- * with the remainder implemented as an Arduino delay().
633
- */
626
+ /*
627
+ * Choose which delay function to use.
628
+ * Arduino delay() is a millisecond granularity busy wait, that
629
+ * that breaks FreeRTOS. So its use is limited to less than one
630
+ * System Tick (portTICK_PERIOD_MS milliseconds).
631
+ * FreeRTOS vTaskDelay() is relies on the System Tick which here
632
+ * has a granularity of portTICK_PERIOD_MS milliseconds (15ms),
633
+ * with the remainder implemented as an Arduino delay().
634
+ */
634
635
635
636
#ifdef delay
636
637
#undef delay
@@ -639,7 +640,7 @@ void vPortEndScheduler( void )
639
640
extern void delay ( unsigned long ms );
640
641
641
642
#if defined( portUSE_WDTO )
642
- void vPortDelay ( const uint32_t ms ) __attribute__ (( hot , flatten ) );
643
+ void vPortDelay ( const uint32_t ms ) __attribute__ ( ( hot , flatten ) );
643
644
void vPortDelay ( const uint32_t ms )
644
645
{
645
646
if ( ms < portTICK_PERIOD_MS )
@@ -655,15 +656,15 @@ void vPortDelay( const uint32_t ms )
655
656
#else
656
657
#warning "The user is responsible to provide function `vPortDelay()`"
657
658
#warning "Arduino uses all AVR MCU Timers, so breakage may occur"
658
- extern void vPortDelay ( const uint32_t ms ) __attribute__ (( hot , flatten ) );
659
+ extern void vPortDelay ( const uint32_t ms ) __attribute__ ( ( hot , flatten ) );
659
660
#endif
660
661
/*-----------------------------------------------------------*/
661
662
662
663
/*
663
664
* Manual context switch. The first thing we do is save the registers so we
664
665
* can use a naked attribute.
665
666
*/
666
- void vPortYield ( void ) __attribute__ (( hot , flatten , naked ) );
667
+ void vPortYield ( void ) __attribute__( ( hot , flatten , naked ) );
667
668
void vPortYield ( void )
668
669
{
669
670
portSAVE_CONTEXT ();
@@ -678,7 +679,7 @@ void vPortYield( void )
678
679
* Manual context switch callable from ISRs. The first thing we do is save
679
680
* the registers so we can use a naked attribute.
680
681
*/
681
- void vPortYieldFromISR ( void ) __attribute__ (( hot , flatten , naked ) );
682
+ void vPortYieldFromISR ( void ) __attribute__( ( hot , flatten , naked ) );
682
683
void vPortYieldFromISR ( void )
683
684
{
684
685
portSAVE_CONTEXT ();
@@ -695,7 +696,7 @@ void vPortYieldFromISR( void )
695
696
* difference from vPortYield() is the tick count is incremented as the
696
697
* call comes from the tick ISR.
697
698
*/
698
- void vPortYieldFromTick ( void ) __attribute__ (( hot , flatten , naked ) );
699
+ void vPortYieldFromTick ( void ) __attribute__( ( hot , flatten , naked ) );
699
700
void vPortYieldFromTick ( void )
700
701
{
701
702
portSAVE_CONTEXT ();
@@ -704,28 +705,30 @@ void vPortYieldFromTick( void )
704
705
{
705
706
vTaskSwitchContext ();
706
707
}
708
+
707
709
portRESTORE_CONTEXT ();
708
710
709
711
__asm__ __volatile__ ( "ret" );
710
712
}
711
713
/*-----------------------------------------------------------*/
712
714
713
715
#if defined( portUSE_WDTO )
714
- /*
715
- * Setup WDT to generate a tick interrupt.
716
- */
717
- void prvSetupTimerInterrupt ( void )
718
- {
719
- /* reset watchdog */
720
- wdt_reset ();
721
716
722
- /* set up WDT Interrupt (rather than the WDT Reset). */
723
- wdt_interrupt_enable ( portUSE_WDTO );
724
- }
717
+ /*
718
+ * Setup WDT to generate a tick interrupt.
719
+ */
720
+ void prvSetupTimerInterrupt ( void )
721
+ {
722
+ /* reset watchdog */
723
+ wdt_reset ();
724
+
725
+ /* set up WDT Interrupt (rather than the WDT Reset). */
726
+ wdt_interrupt_enable ( portUSE_WDTO );
727
+ }
725
728
726
729
#else
727
- #warning "The user is responsible to provide function `prvSetupTimerInterrupt()`"
728
- extern void prvSetupTimerInterrupt ( void );
730
+ #warning "The user is responsible to provide function `prvSetupTimerInterrupt()`"
731
+ extern void prvSetupTimerInterrupt ( void );
729
732
#endif
730
733
731
734
/*-----------------------------------------------------------*/
@@ -740,15 +743,16 @@ extern void prvSetupTimerInterrupt( void );
740
743
* use ISR_NOBLOCK where there is an important timer running, that should preempt the scheduler.
741
744
*
742
745
*/
743
- ISR (portSCHEDULER_ISR , ISR_NAKED ) __attribute__ ((hot , flatten ));
744
- /* ISR(portSCHEDULER_ISR, ISR_NAKED ISR_NOBLOCK) __attribute__ ((hot, flatten));
745
- */
746
- ISR (portSCHEDULER_ISR )
746
+ ISR ( portSCHEDULER_ISR , ISR_NAKED ) __attribute__( ( hot , flatten ) );
747
+
748
+ /* ISR(portSCHEDULER_ISR, ISR_NAKED ISR_NOBLOCK) __attribute__ ((hot, flatten));
749
+ */
750
+ ISR ( portSCHEDULER_ISR )
747
751
{
748
752
vPortYieldFromTick ();
749
753
__asm__ __volatile__ ( "reti" );
750
754
}
751
- #else
755
+ #else /* if configUSE_PREEMPTION == 1 */
752
756
753
757
/*
754
758
* Tick ISR for the cooperative scheduler. All this does is increment the
@@ -757,11 +761,12 @@ extern void prvSetupTimerInterrupt( void );
757
761
*
758
762
* use ISR_NOBLOCK where there is an important timer running, that should preempt the scheduler.
759
763
*/
760
- ISR (portSCHEDULER_ISR ) __attribute__ ((hot , flatten ));
761
- /* ISR(portSCHEDULER_ISR, ISR_NOBLOCK) __attribute__ ((hot, flatten));
762
- */
763
- ISR (portSCHEDULER_ISR )
764
+ ISR ( portSCHEDULER_ISR ) __attribute__( ( hot , flatten ) ) ;
765
+
766
+ /* ISR(portSCHEDULER_ISR, ISR_NOBLOCK) __attribute__ ((hot, flatten));
767
+ */
768
+ ISR ( portSCHEDULER_ISR )
764
769
{
765
770
xTaskIncrementTick ();
766
771
}
767
- #endif
772
+ #endif /* if configUSE_PREEMPTION == 1 */
0 commit comments