diff --git a/portable/ThirdParty/GCC/ATmega/port.c b/portable/ThirdParty/GCC/ATmega/port.c index 9b504684e..e0bafd586 100644 --- a/portable/ThirdParty/GCC/ATmega/port.c +++ b/portable/ThirdParty/GCC/ATmega/port.c @@ -36,166 +36,165 @@ #include "task.h" /*----------------------------------------------------------- -* Implementation of functions defined in portable.h for the AVR port. -*----------------------------------------------------------*/ + * Implementation of functions defined in portable.h for the AVR port. + *----------------------------------------------------------*/ /* Start tasks with interrupts enabled. */ -#define portFLAGS_INT_ENABLED ( ( StackType_t ) 0x80 ) +#define portFLAGS_INT_ENABLED ( (StackType_t) 0x80 ) -#if defined( portUSE_WDTO ) +#if defined( portUSE_WDTO) #warning "Watchdog Timer used for scheduler." - #define portSCHEDULER_ISR WDT_vect + #define portSCHEDULER_ISR WDT_vect #elif defined( portUSE_TIMER0 ) /* Hardware constants for Timer0. */ #warning "Timer0 used for scheduler." - #define portSCHEDULER_ISR TIMER0_COMPA_vect - #define portCLEAR_COUNTER_ON_MATCH ( ( uint8_t ) _BV( WGM01 ) ) - #define portPRESCALE_1024 ( ( uint8_t ) ( _BV( CS02 ) | _BV( CS00 ) ) ) - #define portCLOCK_PRESCALER ( ( uint32_t ) 1024 ) - #define portCOMPARE_MATCH_A_INTERRUPT_ENABLE ( ( uint8_t ) _BV( OCIE0A ) ) - #define portOCRL OCR0A - #define portTCCRa TCCR0A - #define portTCCRb TCCR0B - #define portTIMSK TIMSK0 - #define portTIFR TIFR0 + #define portSCHEDULER_ISR TIMER0_COMPA_vect + #define portCLEAR_COUNTER_ON_MATCH ( (uint8_t) _BV(WGM01) ) + #define portPRESCALE_1024 ( (uint8_t) (_BV(CS02)|_BV(CS00)) ) + #define portCLOCK_PRESCALER ( (uint32_t) 1024 ) + #define portCOMPARE_MATCH_A_INTERRUPT_ENABLE ( (uint8_t) _BV(OCIE0A) ) + #define portOCRL OCR0A + #define portTCCRa TCCR0A + #define portTCCRb TCCR0B + #define portTIMSK TIMSK0 + #define portTIFR TIFR0 -#endif /* if defined( portUSE_WDTO ) */ +#endif /*-----------------------------------------------------------*/ /* We require the address of the pxCurrentTCB variable, but don't want to know - * any details of its type. */ +any details of its type. */ typedef void TCB_t; extern volatile TCB_t * volatile pxCurrentTCB; /*-----------------------------------------------------------*/ /** - * Enable the watchdog timer, configuring it for expire after - * (value) timeout (which is a combination of the WDP0 - * through WDP3 bits). - * - * This function is derived from but enables only - * the interrupt bit (WDIE), rather than the reset bit (WDE). - * - * Can't find it documented but the WDT, once enabled, - * rolls over and fires a new interrupt each time. - * - * See also the symbolic constants WDTO_15MS et al. - * - * Updated to match avr-libc 2.0.0 - */ + Enable the watchdog timer, configuring it for expire after + (value) timeout (which is a combination of the WDP0 + through WDP3 bits). -#if defined( portUSE_WDTO ) + This function is derived from but enables only + the interrupt bit (WDIE), rather than the reset bit (WDE). - static __inline__ - __attribute__( ( __always_inline__ ) ) - void wdt_interrupt_enable( const uint8_t value ) + Can't find it documented but the WDT, once enabled, + rolls over and fires a new interrupt each time. + + See also the symbolic constants WDTO_15MS et al. + + Updated to match avr-libc 2.0.0 +*/ + +#if defined( portUSE_WDTO) + +static __inline__ +__attribute__ ((__always_inline__)) +void wdt_interrupt_enable (const uint8_t value) +{ + if (_SFR_IO_REG_P (_WD_CONTROL_REG)) { - if( _SFR_IO_REG_P( _WD_CONTROL_REG ) ) - { - __asm__ __volatile__ ( + __asm__ __volatile__ ( "in __tmp_reg__,__SREG__" "\n\t" - "cli" "\n\t" - "wdr" "\n\t" - "out %0, %1" "\n\t" - "out __SREG__,__tmp_reg__" "\n\t" - "out %0, %2" "\n\t" + "cli" "\n\t" + "wdr" "\n\t" + "out %0, %1" "\n\t" + "out __SREG__,__tmp_reg__" "\n\t" + "out %0, %2" "\n\t" : /* no outputs */ - : "I" ( _SFR_IO_ADDR( _WD_CONTROL_REG ) ), - "r" ( ( uint8_t ) ( _BV( _WD_CHANGE_BIT ) | _BV( WDE ) ) ), - "r" ( ( uint8_t ) ( ( value & 0x08 ? _WD_PS3_MASK : 0x00 ) | - _BV( WDIF ) | _BV( WDIE ) | ( value & 0x07 ) ) ) + : "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)), + "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))), + "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | + _BV(WDIF) | _BV(WDIE) | (value & 0x07)) ) : "r0" - ); - } - else - { - __asm__ __volatile__ ( - "in __tmp_reg__,__SREG__" "\n\t" - "cli" "\n\t" - "wdr" "\n\t" - "sts %0, %1" "\n\t" - "out __SREG__,__tmp_reg__" "\n\t" - "sts %0, %2" "\n\t" - : /* no outputs */ - : "n" ( _SFR_MEM_ADDR( _WD_CONTROL_REG ) ), - "r" ( ( uint8_t ) ( _BV( _WD_CHANGE_BIT ) | _BV( WDE ) ) ), - "r" ( ( uint8_t ) ( ( value & 0x08 ? _WD_PS3_MASK : 0x00 ) | - _BV( WDIF ) | _BV( WDIE ) | ( value & 0x07 ) ) ) - : "r0" - ); - } + ); } -#endif /* if defined( portUSE_WDTO ) */ + else + { + __asm__ __volatile__ ( + "in __tmp_reg__,__SREG__" "\n\t" + "cli" "\n\t" + "wdr" "\n\t" + "sts %0, %1" "\n\t" + "out __SREG__,__tmp_reg__" "\n\t" + "sts %0, %2" "\n\t" + : /* no outputs */ + : "n" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), + "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))), + "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | + _BV(WDIF) | _BV(WDIE) | (value & 0x07)) ) + : "r0" + ); + } +} +#endif /*-----------------------------------------------------------*/ - /** - * Enable the watchdog timer, configuring it for expire after - * (value) timeout (which is a combination of the WDP0 - * through WDP3 bits). - * - * This function is derived from but enables both - * the reset bit (WDE), and the interrupt bit (WDIE). - * - * This will ensure that if the interrupt is not serviced - * before the second timeout, the AVR will reset. - * - * Servicing the interrupt automatically clears it, - * and ensures the AVR does not reset. - * - * Can't find it documented but the WDT, once enabled, - * rolls over and fires a new interrupt each time. - * - * See also the symbolic constants WDTO_15MS et al. - * - * Updated to match avr-libc 2.0.0 - */ + Enable the watchdog timer, configuring it for expire after + (value) timeout (which is a combination of the WDP0 + through WDP3 bits). -#if defined( portUSE_WDTO ) + This function is derived from but enables both + the reset bit (WDE), and the interrupt bit (WDIE). - static __inline__ - __attribute__( ( __always_inline__ ) ) - void wdt_interrupt_reset_enable( const uint8_t value ) + This will ensure that if the interrupt is not serviced + before the second timeout, the AVR will reset. + + Servicing the interrupt automatically clears it, + and ensures the AVR does not reset. + + Can't find it documented but the WDT, once enabled, + rolls over and fires a new interrupt each time. + + See also the symbolic constants WDTO_15MS et al. + + Updated to match avr-libc 2.0.0 +*/ + +#if defined( portUSE_WDTO) + +static __inline__ +__attribute__ ((__always_inline__)) +void wdt_interrupt_reset_enable (const uint8_t value) +{ + if (_SFR_IO_REG_P (_WD_CONTROL_REG)) { - if( _SFR_IO_REG_P( _WD_CONTROL_REG ) ) - { - __asm__ __volatile__ ( + __asm__ __volatile__ ( "in __tmp_reg__,__SREG__" "\n\t" - "cli" "\n\t" - "wdr" "\n\t" - "out %0, %1" "\n\t" - "out __SREG__,__tmp_reg__" "\n\t" - "out %0, %2" "\n\t" + "cli" "\n\t" + "wdr" "\n\t" + "out %0, %1" "\n\t" + "out __SREG__,__tmp_reg__" "\n\t" + "out %0, %2" "\n\t" : /* no outputs */ - : "I" ( _SFR_IO_ADDR( _WD_CONTROL_REG ) ), - "r" ( ( uint8_t ) ( _BV( _WD_CHANGE_BIT ) | _BV( WDE ) ) ), - "r" ( ( uint8_t ) ( ( value & 0x08 ? _WD_PS3_MASK : 0x00 ) | - _BV( WDIF ) | _BV( WDIE ) | _BV( WDE ) | ( value & 0x07 ) ) ) + : "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)), + "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))), + "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | + _BV(WDIF) | _BV(WDIE) | _BV(WDE) | (value & 0x07)) ) : "r0" - ); - } - else - { - __asm__ __volatile__ ( - "in __tmp_reg__,__SREG__" "\n\t" - "cli" "\n\t" - "wdr" "\n\t" - "sts %0, %1" "\n\t" - "out __SREG__,__tmp_reg__" "\n\t" - "sts %0, %2" "\n\t" - : /* no outputs */ - : "n" ( _SFR_MEM_ADDR( _WD_CONTROL_REG ) ), - "r" ( ( uint8_t ) ( _BV( _WD_CHANGE_BIT ) | _BV( WDE ) ) ), - "r" ( ( uint8_t ) ( ( value & 0x08 ? _WD_PS3_MASK : 0x00 ) | - _BV( WDIF ) | _BV( WDIE ) | _BV( WDE ) | ( value & 0x07 ) ) ) - : "r0" - ); - } + ); } -#endif /* if defined( portUSE_WDTO ) */ + else + { + __asm__ __volatile__ ( + "in __tmp_reg__,__SREG__" "\n\t" + "cli" "\n\t" + "wdr" "\n\t" + "sts %0, %1" "\n\t" + "out __SREG__,__tmp_reg__" "\n\t" + "sts %0, %2" "\n\t" + : /* no outputs */ + : "n" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), + "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))), + "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | + _BV(WDIF) | _BV(WDIE) | _BV(WDE) | (value & 0x07)) ) + : "r0" + ); + } +} +#endif /*-----------------------------------------------------------*/ @@ -224,295 +223,295 @@ extern volatile TCB_t * volatile pxCurrentTCB; * The interrupts will have been disabled during the call to portSAVE_CONTEXT() * so we need not worry about reading/writing to the stack pointer. */ -#if defined( __AVR_3_BYTE_PC__ ) && defined( __AVR_HAVE_RAMPZ__ ) +#if defined(__AVR_3_BYTE_PC__) && defined(__AVR_HAVE_RAMPZ__) /* 3-Byte PC Save with RAMPZ */ - #define portSAVE_CONTEXT() \ - __asm__ __volatile__ ( "push __tmp_reg__ \n\t" \ - "in __tmp_reg__, __SREG__ \n\t" \ - "cli \n\t" \ - "push __tmp_reg__ \n\t" \ - "in __tmp_reg__, 0x3B \n\t" \ - "push __tmp_reg__ \n\t" \ - "in __tmp_reg__, 0x3C \n\t" \ - "push __tmp_reg__ \n\t" \ - "push __zero_reg__ \n\t" \ - "clr __zero_reg__ \n\t" \ - "push r2 \n\t" \ - "push r3 \n\t" \ - "push r4 \n\t" \ - "push r5 \n\t" \ - "push r6 \n\t" \ - "push r7 \n\t" \ - "push r8 \n\t" \ - "push r9 \n\t" \ - "push r10 \n\t" \ - "push r11 \n\t" \ - "push r12 \n\t" \ - "push r13 \n\t" \ - "push r14 \n\t" \ - "push r15 \n\t" \ - "push r16 \n\t" \ - "push r17 \n\t" \ - "push r18 \n\t" \ - "push r19 \n\t" \ - "push r20 \n\t" \ - "push r21 \n\t" \ - "push r22 \n\t" \ - "push r23 \n\t" \ - "push r24 \n\t" \ - "push r25 \n\t" \ - "push r26 \n\t" \ - "push r27 \n\t" \ - "push r28 \n\t" \ - "push r29 \n\t" \ - "push r30 \n\t" \ - "push r31 \n\t" \ - "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "in __tmp_reg__, __SP_L__ \n\t" \ - "st x+, __tmp_reg__ \n\t" \ - "in __tmp_reg__, __SP_H__ \n\t" \ - "st x+, __tmp_reg__ \n\t" \ - ); -#elif defined( __AVR_HAVE_RAMPZ__ ) +#define portSAVE_CONTEXT() \ + __asm__ __volatile__ ( "push __tmp_reg__ \n\t" \ + "in __tmp_reg__, __SREG__ \n\t" \ + "cli \n\t" \ + "push __tmp_reg__ \n\t" \ + "in __tmp_reg__, 0x3B \n\t" \ + "push __tmp_reg__ \n\t" \ + "in __tmp_reg__, 0x3C \n\t" \ + "push __tmp_reg__ \n\t" \ + "push __zero_reg__ \n\t" \ + "clr __zero_reg__ \n\t" \ + "push r2 \n\t" \ + "push r3 \n\t" \ + "push r4 \n\t" \ + "push r5 \n\t" \ + "push r6 \n\t" \ + "push r7 \n\t" \ + "push r8 \n\t" \ + "push r9 \n\t" \ + "push r10 \n\t" \ + "push r11 \n\t" \ + "push r12 \n\t" \ + "push r13 \n\t" \ + "push r14 \n\t" \ + "push r15 \n\t" \ + "push r16 \n\t" \ + "push r17 \n\t" \ + "push r18 \n\t" \ + "push r19 \n\t" \ + "push r20 \n\t" \ + "push r21 \n\t" \ + "push r22 \n\t" \ + "push r23 \n\t" \ + "push r24 \n\t" \ + "push r25 \n\t" \ + "push r26 \n\t" \ + "push r27 \n\t" \ + "push r28 \n\t" \ + "push r29 \n\t" \ + "push r30 \n\t" \ + "push r31 \n\t" \ + "lds r26, pxCurrentTCB \n\t" \ + "lds r27, pxCurrentTCB + 1 \n\t" \ + "in __tmp_reg__, __SP_L__ \n\t" \ + "st x+, __tmp_reg__ \n\t" \ + "in __tmp_reg__, __SP_H__ \n\t" \ + "st x+, __tmp_reg__ \n\t" \ + ); +#elif defined(__AVR_HAVE_RAMPZ__) /* 2-Byte PC Save with RAMPZ */ - #define portSAVE_CONTEXT() \ - __asm__ __volatile__ ( "push __tmp_reg__ \n\t" \ - "in __tmp_reg__, __SREG__ \n\t" \ - "cli \n\t" \ - "push __tmp_reg__ \n\t" \ - "in __tmp_reg__, 0x3B \n\t" \ - "push __tmp_reg__ \n\t" \ - "push __zero_reg__ \n\t" \ - "clr __zero_reg__ \n\t" \ - "push r2 \n\t" \ - "push r3 \n\t" \ - "push r4 \n\t" \ - "push r5 \n\t" \ - "push r6 \n\t" \ - "push r7 \n\t" \ - "push r8 \n\t" \ - "push r9 \n\t" \ - "push r10 \n\t" \ - "push r11 \n\t" \ - "push r12 \n\t" \ - "push r13 \n\t" \ - "push r14 \n\t" \ - "push r15 \n\t" \ - "push r16 \n\t" \ - "push r17 \n\t" \ - "push r18 \n\t" \ - "push r19 \n\t" \ - "push r20 \n\t" \ - "push r21 \n\t" \ - "push r22 \n\t" \ - "push r23 \n\t" \ - "push r24 \n\t" \ - "push r25 \n\t" \ - "push r26 \n\t" \ - "push r27 \n\t" \ - "push r28 \n\t" \ - "push r29 \n\t" \ - "push r30 \n\t" \ - "push r31 \n\t" \ - "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "in __tmp_reg__, __SP_L__ \n\t" \ - "st x+, __tmp_reg__ \n\t" \ - "in __tmp_reg__, __SP_H__ \n\t" \ - "st x+, __tmp_reg__ \n\t" \ - ); -#else /* if defined( __AVR_3_BYTE_PC__ ) && defined( __AVR_HAVE_RAMPZ__ ) */ +#define portSAVE_CONTEXT() \ + __asm__ __volatile__ ( "push __tmp_reg__ \n\t" \ + "in __tmp_reg__, __SREG__ \n\t" \ + "cli \n\t" \ + "push __tmp_reg__ \n\t" \ + "in __tmp_reg__, 0x3B \n\t" \ + "push __tmp_reg__ \n\t" \ + "push __zero_reg__ \n\t" \ + "clr __zero_reg__ \n\t" \ + "push r2 \n\t" \ + "push r3 \n\t" \ + "push r4 \n\t" \ + "push r5 \n\t" \ + "push r6 \n\t" \ + "push r7 \n\t" \ + "push r8 \n\t" \ + "push r9 \n\t" \ + "push r10 \n\t" \ + "push r11 \n\t" \ + "push r12 \n\t" \ + "push r13 \n\t" \ + "push r14 \n\t" \ + "push r15 \n\t" \ + "push r16 \n\t" \ + "push r17 \n\t" \ + "push r18 \n\t" \ + "push r19 \n\t" \ + "push r20 \n\t" \ + "push r21 \n\t" \ + "push r22 \n\t" \ + "push r23 \n\t" \ + "push r24 \n\t" \ + "push r25 \n\t" \ + "push r26 \n\t" \ + "push r27 \n\t" \ + "push r28 \n\t" \ + "push r29 \n\t" \ + "push r30 \n\t" \ + "push r31 \n\t" \ + "lds r26, pxCurrentTCB \n\t" \ + "lds r27, pxCurrentTCB + 1 \n\t" \ + "in __tmp_reg__, __SP_L__ \n\t" \ + "st x+, __tmp_reg__ \n\t" \ + "in __tmp_reg__, __SP_H__ \n\t" \ + "st x+, __tmp_reg__ \n\t" \ + ); +#else /* 2-Byte PC Save */ - #define portSAVE_CONTEXT() \ - __asm__ __volatile__ ( "push __tmp_reg__ \n\t" \ - "in __tmp_reg__, __SREG__ \n\t" \ - "cli \n\t" \ - "push __tmp_reg__ \n\t" \ - "push __zero_reg__ \n\t" \ - "clr __zero_reg__ \n\t" \ - "push r2 \n\t" \ - "push r3 \n\t" \ - "push r4 \n\t" \ - "push r5 \n\t" \ - "push r6 \n\t" \ - "push r7 \n\t" \ - "push r8 \n\t" \ - "push r9 \n\t" \ - "push r10 \n\t" \ - "push r11 \n\t" \ - "push r12 \n\t" \ - "push r13 \n\t" \ - "push r14 \n\t" \ - "push r15 \n\t" \ - "push r16 \n\t" \ - "push r17 \n\t" \ - "push r18 \n\t" \ - "push r19 \n\t" \ - "push r20 \n\t" \ - "push r21 \n\t" \ - "push r22 \n\t" \ - "push r23 \n\t" \ - "push r24 \n\t" \ - "push r25 \n\t" \ - "push r26 \n\t" \ - "push r27 \n\t" \ - "push r28 \n\t" \ - "push r29 \n\t" \ - "push r30 \n\t" \ - "push r31 \n\t" \ - "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "in __tmp_reg__, __SP_L__ \n\t" \ - "st x+, __tmp_reg__ \n\t" \ - "in __tmp_reg__, __SP_H__ \n\t" \ - "st x+, __tmp_reg__ \n\t" \ - ); -#endif /* if defined( __AVR_3_BYTE_PC__ ) && defined( __AVR_HAVE_RAMPZ__ ) */ +#define portSAVE_CONTEXT() \ + __asm__ __volatile__ ( "push __tmp_reg__ \n\t" \ + "in __tmp_reg__, __SREG__ \n\t" \ + "cli \n\t" \ + "push __tmp_reg__ \n\t" \ + "push __zero_reg__ \n\t" \ + "clr __zero_reg__ \n\t" \ + "push r2 \n\t" \ + "push r3 \n\t" \ + "push r4 \n\t" \ + "push r5 \n\t" \ + "push r6 \n\t" \ + "push r7 \n\t" \ + "push r8 \n\t" \ + "push r9 \n\t" \ + "push r10 \n\t" \ + "push r11 \n\t" \ + "push r12 \n\t" \ + "push r13 \n\t" \ + "push r14 \n\t" \ + "push r15 \n\t" \ + "push r16 \n\t" \ + "push r17 \n\t" \ + "push r18 \n\t" \ + "push r19 \n\t" \ + "push r20 \n\t" \ + "push r21 \n\t" \ + "push r22 \n\t" \ + "push r23 \n\t" \ + "push r24 \n\t" \ + "push r25 \n\t" \ + "push r26 \n\t" \ + "push r27 \n\t" \ + "push r28 \n\t" \ + "push r29 \n\t" \ + "push r30 \n\t" \ + "push r31 \n\t" \ + "lds r26, pxCurrentTCB \n\t" \ + "lds r27, pxCurrentTCB + 1 \n\t" \ + "in __tmp_reg__, __SP_L__ \n\t" \ + "st x+, __tmp_reg__ \n\t" \ + "in __tmp_reg__, __SP_H__ \n\t" \ + "st x+, __tmp_reg__ \n\t" \ + ); +#endif /* * Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during * the context save so we can write to the stack pointer. */ -#if defined( __AVR_3_BYTE_PC__ ) && defined( __AVR_HAVE_RAMPZ__ ) +#if defined(__AVR_3_BYTE_PC__) && defined(__AVR_HAVE_RAMPZ__) /* 3-Byte PC Restore with RAMPZ */ - #define portRESTORE_CONTEXT() \ - __asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "ld r28, x+ \n\t" \ - "out __SP_L__, r28 \n\t" \ - "ld r29, x+ \n\t" \ - "out __SP_H__, r29 \n\t" \ - "pop r31 \n\t" \ - "pop r30 \n\t" \ - "pop r29 \n\t" \ - "pop r28 \n\t" \ - "pop r27 \n\t" \ - "pop r26 \n\t" \ - "pop r25 \n\t" \ - "pop r24 \n\t" \ - "pop r23 \n\t" \ - "pop r22 \n\t" \ - "pop r21 \n\t" \ - "pop r20 \n\t" \ - "pop r19 \n\t" \ - "pop r18 \n\t" \ - "pop r17 \n\t" \ - "pop r16 \n\t" \ - "pop r15 \n\t" \ - "pop r14 \n\t" \ - "pop r13 \n\t" \ - "pop r12 \n\t" \ - "pop r11 \n\t" \ - "pop r10 \n\t" \ - "pop r9 \n\t" \ - "pop r8 \n\t" \ - "pop r7 \n\t" \ - "pop r6 \n\t" \ - "pop r5 \n\t" \ - "pop r4 \n\t" \ - "pop r3 \n\t" \ - "pop r2 \n\t" \ - "pop __zero_reg__ \n\t" \ - "pop __tmp_reg__ \n\t" \ - "out 0x3C, __tmp_reg__ \n\t" \ - "pop __tmp_reg__ \n\t" \ - "out 0x3B, __tmp_reg__ \n\t" \ - "pop __tmp_reg__ \n\t" \ - "out __SREG__, __tmp_reg__ \n\t" \ - "pop __tmp_reg__ \n\t" \ - ); -#elif defined( __AVR_HAVE_RAMPZ__ ) +#define portRESTORE_CONTEXT() \ + __asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \ + "lds r27, pxCurrentTCB + 1 \n\t" \ + "ld r28, x+ \n\t" \ + "out __SP_L__, r28 \n\t" \ + "ld r29, x+ \n\t" \ + "out __SP_H__, r29 \n\t" \ + "pop r31 \n\t" \ + "pop r30 \n\t" \ + "pop r29 \n\t" \ + "pop r28 \n\t" \ + "pop r27 \n\t" \ + "pop r26 \n\t" \ + "pop r25 \n\t" \ + "pop r24 \n\t" \ + "pop r23 \n\t" \ + "pop r22 \n\t" \ + "pop r21 \n\t" \ + "pop r20 \n\t" \ + "pop r19 \n\t" \ + "pop r18 \n\t" \ + "pop r17 \n\t" \ + "pop r16 \n\t" \ + "pop r15 \n\t" \ + "pop r14 \n\t" \ + "pop r13 \n\t" \ + "pop r12 \n\t" \ + "pop r11 \n\t" \ + "pop r10 \n\t" \ + "pop r9 \n\t" \ + "pop r8 \n\t" \ + "pop r7 \n\t" \ + "pop r6 \n\t" \ + "pop r5 \n\t" \ + "pop r4 \n\t" \ + "pop r3 \n\t" \ + "pop r2 \n\t" \ + "pop __zero_reg__ \n\t" \ + "pop __tmp_reg__ \n\t" \ + "out 0x3C, __tmp_reg__ \n\t" \ + "pop __tmp_reg__ \n\t" \ + "out 0x3B, __tmp_reg__ \n\t" \ + "pop __tmp_reg__ \n\t" \ + "out __SREG__, __tmp_reg__ \n\t" \ + "pop __tmp_reg__ \n\t" \ + ); +#elif defined(__AVR_HAVE_RAMPZ__) /* 2-Byte PC Restore with RAMPZ */ - #define portRESTORE_CONTEXT() \ - __asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "ld r28, x+ \n\t" \ - "out __SP_L__, r28 \n\t" \ - "ld r29, x+ \n\t" \ - "out __SP_H__, r29 \n\t" \ - "pop r31 \n\t" \ - "pop r30 \n\t" \ - "pop r29 \n\t" \ - "pop r28 \n\t" \ - "pop r27 \n\t" \ - "pop r26 \n\t" \ - "pop r25 \n\t" \ - "pop r24 \n\t" \ - "pop r23 \n\t" \ - "pop r22 \n\t" \ - "pop r21 \n\t" \ - "pop r20 \n\t" \ - "pop r19 \n\t" \ - "pop r18 \n\t" \ - "pop r17 \n\t" \ - "pop r16 \n\t" \ - "pop r15 \n\t" \ - "pop r14 \n\t" \ - "pop r13 \n\t" \ - "pop r12 \n\t" \ - "pop r11 \n\t" \ - "pop r10 \n\t" \ - "pop r9 \n\t" \ - "pop r8 \n\t" \ - "pop r7 \n\t" \ - "pop r6 \n\t" \ - "pop r5 \n\t" \ - "pop r4 \n\t" \ - "pop r3 \n\t" \ - "pop r2 \n\t" \ - "pop __zero_reg__ \n\t" \ - "pop __tmp_reg__ \n\t" \ - "out 0x3B, __tmp_reg__ \n\t" \ - "pop __tmp_reg__ \n\t" \ - "out __SREG__, __tmp_reg__ \n\t" \ - "pop __tmp_reg__ \n\t" \ - ); -#else /* if defined( __AVR_3_BYTE_PC__ ) && defined( __AVR_HAVE_RAMPZ__ ) */ +#define portRESTORE_CONTEXT() \ + __asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \ + "lds r27, pxCurrentTCB + 1 \n\t" \ + "ld r28, x+ \n\t" \ + "out __SP_L__, r28 \n\t" \ + "ld r29, x+ \n\t" \ + "out __SP_H__, r29 \n\t" \ + "pop r31 \n\t" \ + "pop r30 \n\t" \ + "pop r29 \n\t" \ + "pop r28 \n\t" \ + "pop r27 \n\t" \ + "pop r26 \n\t" \ + "pop r25 \n\t" \ + "pop r24 \n\t" \ + "pop r23 \n\t" \ + "pop r22 \n\t" \ + "pop r21 \n\t" \ + "pop r20 \n\t" \ + "pop r19 \n\t" \ + "pop r18 \n\t" \ + "pop r17 \n\t" \ + "pop r16 \n\t" \ + "pop r15 \n\t" \ + "pop r14 \n\t" \ + "pop r13 \n\t" \ + "pop r12 \n\t" \ + "pop r11 \n\t" \ + "pop r10 \n\t" \ + "pop r9 \n\t" \ + "pop r8 \n\t" \ + "pop r7 \n\t" \ + "pop r6 \n\t" \ + "pop r5 \n\t" \ + "pop r4 \n\t" \ + "pop r3 \n\t" \ + "pop r2 \n\t" \ + "pop __zero_reg__ \n\t" \ + "pop __tmp_reg__ \n\t" \ + "out 0x3B, __tmp_reg__ \n\t" \ + "pop __tmp_reg__ \n\t" \ + "out __SREG__, __tmp_reg__ \n\t" \ + "pop __tmp_reg__ \n\t" \ + ); +#else /* 2-Byte PC Restore */ - #define portRESTORE_CONTEXT() \ - __asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "ld r28, x+ \n\t" \ - "out __SP_L__, r28 \n\t" \ - "ld r29, x+ \n\t" \ - "out __SP_H__, r29 \n\t" \ - "pop r31 \n\t" \ - "pop r30 \n\t" \ - "pop r29 \n\t" \ - "pop r28 \n\t" \ - "pop r27 \n\t" \ - "pop r26 \n\t" \ - "pop r25 \n\t" \ - "pop r24 \n\t" \ - "pop r23 \n\t" \ - "pop r22 \n\t" \ - "pop r21 \n\t" \ - "pop r20 \n\t" \ - "pop r19 \n\t" \ - "pop r18 \n\t" \ - "pop r17 \n\t" \ - "pop r16 \n\t" \ - "pop r15 \n\t" \ - "pop r14 \n\t" \ - "pop r13 \n\t" \ - "pop r12 \n\t" \ - "pop r11 \n\t" \ - "pop r10 \n\t" \ - "pop r9 \n\t" \ - "pop r8 \n\t" \ - "pop r7 \n\t" \ - "pop r6 \n\t" \ - "pop r5 \n\t" \ - "pop r4 \n\t" \ - "pop r3 \n\t" \ - "pop r2 \n\t" \ - "pop __zero_reg__ \n\t" \ - "pop __tmp_reg__ \n\t" \ - "out __SREG__, __tmp_reg__ \n\t" \ - "pop __tmp_reg__ \n\t" \ - ); -#endif /* if defined( __AVR_3_BYTE_PC__ ) && defined( __AVR_HAVE_RAMPZ__ ) */ +#define portRESTORE_CONTEXT() \ + __asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \ + "lds r27, pxCurrentTCB + 1 \n\t" \ + "ld r28, x+ \n\t" \ + "out __SP_L__, r28 \n\t" \ + "ld r29, x+ \n\t" \ + "out __SP_H__, r29 \n\t" \ + "pop r31 \n\t" \ + "pop r30 \n\t" \ + "pop r29 \n\t" \ + "pop r28 \n\t" \ + "pop r27 \n\t" \ + "pop r26 \n\t" \ + "pop r25 \n\t" \ + "pop r24 \n\t" \ + "pop r23 \n\t" \ + "pop r22 \n\t" \ + "pop r21 \n\t" \ + "pop r20 \n\t" \ + "pop r19 \n\t" \ + "pop r18 \n\t" \ + "pop r17 \n\t" \ + "pop r16 \n\t" \ + "pop r15 \n\t" \ + "pop r14 \n\t" \ + "pop r13 \n\t" \ + "pop r12 \n\t" \ + "pop r11 \n\t" \ + "pop r10 \n\t" \ + "pop r9 \n\t" \ + "pop r8 \n\t" \ + "pop r7 \n\t" \ + "pop r6 \n\t" \ + "pop r5 \n\t" \ + "pop r4 \n\t" \ + "pop r3 \n\t" \ + "pop r2 \n\t" \ + "pop __zero_reg__ \n\t" \ + "pop __tmp_reg__ \n\t" \ + "out __SREG__, __tmp_reg__ \n\t" \ + "pop __tmp_reg__ \n\t" \ + ); +#endif /*-----------------------------------------------------------*/ /* @@ -524,17 +523,14 @@ static void prvSetupTimerInterrupt( void ); /* * See header file for description. */ -StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, - TaskFunction_t pxCode, - void * pvParameters ) +StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) { - uint16_t usAddress; - +uint16_t usAddress; /* Simulate how the stack would look after a call to vPortYield() generated by - * the compiler. */ + the compiler. */ /* The start of the task code will be popped off the stack last, so place - * it on first. */ + it on first. */ usAddress = ( uint16_t ) pxCode; *pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff ); pxTopOfStack--; @@ -543,51 +539,48 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, *pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff ); pxTopOfStack--; - #if defined( __AVR_3_BYTE_PC__ ) - - /* The AVR ATmega2560/ATmega2561 have 256KBytes of program memory and a 17-bit - * program counter. When a code address is stored on the stack, it takes 3 bytes - * instead of 2 for the other ATmega* chips. - * - * Store 0 as the top byte since we force all task routines to the bottom 128K - * of flash. We do this by using the .lowtext label in the linker script. - * - * In order to do this properly, we would need to get a full 3-byte pointer to - * pxCode. That requires a change to GCC. Not likely to happen any time soon. - */ - *pxTopOfStack = 0; - pxTopOfStack--; - #endif +#if defined(__AVR_3_BYTE_PC__) + /* The AVR ATmega2560/ATmega2561 have 256KBytes of program memory and a 17-bit + * program counter. When a code address is stored on the stack, it takes 3 bytes + * instead of 2 for the other ATmega* chips. + * + * Store 0 as the top byte since we force all task routines to the bottom 128K + * of flash. We do this by using the .lowtext label in the linker script. + * + * In order to do this properly, we would need to get a full 3-byte pointer to + * pxCode. That requires a change to GCC. Not likely to happen any time soon. + */ + *pxTopOfStack = 0; + pxTopOfStack--; +#endif /* Next simulate the stack as if after a call to portSAVE_CONTEXT(). - * portSAVE_CONTEXT places the flags on the stack immediately after r0 - * to ensure the interrupts get disabled as soon as possible, and so ensuring - * the stack use is minimal should a context switch interrupt occur. */ - *pxTopOfStack = ( StackType_t ) 0x00; /* R0 */ + portSAVE_CONTEXT places the flags on the stack immediately after r0 + to ensure the interrupts get disabled as soon as possible, and so ensuring + the stack use is minimal should a context switch interrupt occur. */ + *pxTopOfStack = ( StackType_t ) 0x00; /* R0 */ pxTopOfStack--; *pxTopOfStack = portFLAGS_INT_ENABLED; pxTopOfStack--; - #if defined( __AVR_3_BYTE_PC__ ) +#if defined(__AVR_3_BYTE_PC__) + /* If we have an ATmega256x, we are also saving the EIND register. + * We should default to 0. + */ + *pxTopOfStack = ( StackType_t ) 0x00; /* EIND */ + pxTopOfStack--; +#endif - /* If we have an ATmega256x, we are also saving the EIND register. - * We should default to 0. - */ - *pxTopOfStack = ( StackType_t ) 0x00; /* EIND */ - pxTopOfStack--; - #endif - - #if defined( __AVR_HAVE_RAMPZ__ ) - - /* We are saving the RAMPZ register. - * We should default to 0. - */ - *pxTopOfStack = ( StackType_t ) 0x00; /* RAMPZ */ - pxTopOfStack--; - #endif +#if defined(__AVR_HAVE_RAMPZ__) + /* We are saving the RAMPZ register. + * We should default to 0. + */ + *pxTopOfStack = ( StackType_t ) 0x00; /* RAMPZ */ + pxTopOfStack--; +#endif /* Now the remaining registers. The compiler expects R1 to be 0. */ - *pxTopOfStack = ( StackType_t ) 0x00; /* R1 */ + *pxTopOfStack = ( StackType_t ) 0x00; /* R1 */ /* Leave R2 - R23 untouched */ pxTopOfStack -= 23; @@ -616,7 +609,7 @@ BaseType_t xPortStartScheduler( void ) portRESTORE_CONTEXT(); /* Simulate a function call end as generated by the compiler. We will now - * jump to the start of the task the context of which we have just restored. */ + jump to the start of the task the context of which we have just restored. */ __asm__ __volatile__ ( "ret" ); /* Should not get here. */ @@ -626,7 +619,7 @@ BaseType_t xPortStartScheduler( void ) void vPortEndScheduler( void ) { - /* It is unlikely that the ATmega port will get stopped. */ + /* It is unlikely that the ATmega port will get stopped. */ } /*-----------------------------------------------------------*/ @@ -634,7 +627,7 @@ void vPortEndScheduler( void ) * Manual context switch. The first thing we do is save the registers so we * can use a naked attribute. */ -void vPortYield( void ) __attribute__( ( hot, flatten, naked ) ); +void vPortYield( void ) __attribute__ ( ( hot, flatten, naked ) ); void vPortYield( void ) { portSAVE_CONTEXT(); @@ -649,8 +642,8 @@ void vPortYield( void ) * Manual context switch callable from ISRs. The first thing we do is save * the registers so we can use a naked attribute. */ -void vPortYieldFromISR( void ) __attribute__( ( hot, flatten, naked ) ); -void vPortYieldFromISR( void ) +void vPortYieldFromISR(void) __attribute__ ( ( hot, flatten, naked ) ); +void vPortYieldFromISR(void) { portSAVE_CONTEXT(); vTaskSwitchContext(); @@ -666,111 +659,107 @@ void vPortYieldFromISR( void ) * difference from vPortYield() is the tick count is incremented as the * call comes from the tick ISR. */ -void vPortYieldFromTick( void ) __attribute__( ( hot, flatten, naked ) ); +void vPortYieldFromTick( void ) __attribute__ ( ( hot, flatten, naked ) ); void vPortYieldFromTick( void ) { portSAVE_CONTEXT(); - if( xTaskIncrementTick() != pdFALSE ) { vTaskSwitchContext(); } - portRESTORE_CONTEXT(); __asm__ __volatile__ ( "ret" ); } /*-----------------------------------------------------------*/ -#if defined( portUSE_WDTO ) - +#if defined(portUSE_WDTO) /* * Setup WDT to generate a tick interrupt. */ - void prvSetupTimerInterrupt( void ) - { - /* reset watchdog */ - wdt_reset(); +void prvSetupTimerInterrupt( void ) +{ + /* reset watchdog */ + wdt_reset(); - /* set up WDT Interrupt (rather than the WDT Reset). */ - wdt_interrupt_enable( portUSE_WDTO ); - } - -#elif defined( portUSE_TIMER0 ) + /* set up WDT Interrupt (rather than the WDT Reset). */ + wdt_interrupt_enable( portUSE_WDTO ); +} +#elif defined (portUSE_TIMER0) /* * Setup Timer0 compare match A to generate a tick interrupt. */ - static void prvSetupTimerInterrupt( void ) - { - uint32_t ulCompareMatch; - uint8_t ucLowByte; +static void prvSetupTimerInterrupt( void ) +{ +uint32_t ulCompareMatch; +uint8_t ucLowByte; - /* Using 8bit Timer0 to generate the tick. Correct fuses must be - * selected for the configCPU_CLOCK_HZ clock.*/ + /* Using 8bit Timer0 to generate the tick. Correct fuses must be + selected for the configCPU_CLOCK_HZ clock.*/ - ulCompareMatch = configCPU_CLOCK_HZ / configTICK_RATE_HZ; + ulCompareMatch = configCPU_CLOCK_HZ / configTICK_RATE_HZ; - /* We only have 8 bits so have to scale 1024 to get our required tick rate. */ - ulCompareMatch /= portCLOCK_PRESCALER; + /* We only have 8 bits so have to scale 1024 to get our required tick rate. */ + ulCompareMatch /= portCLOCK_PRESCALER; - /* Adjust for correct value. */ - ulCompareMatch -= ( uint32_t ) 1; + /* Adjust for correct value. */ + ulCompareMatch -= ( uint32_t ) 1; - /* Setup compare match value for compare match A. Interrupts are disabled - * before this is called so we need not worry here. */ - ucLowByte = ( uint8_t ) ( ulCompareMatch & ( uint32_t ) 0xff ); - portOCRL = ucLowByte; + /* Setup compare match value for compare match A. Interrupts are disabled + before this is called so we need not worry here. */ + ucLowByte = ( uint8_t ) ( ulCompareMatch & ( uint32_t ) 0xff ); + portOCRL = ucLowByte; - /* Setup clock source and compare match behaviour. */ - portTCCRa = portCLEAR_COUNTER_ON_MATCH; - portTCCRb = portPRESCALE_1024; + /* Setup clock source and compare match behaviour. */ + portTCCRa = portCLEAR_COUNTER_ON_MATCH; + portTCCRb = portPRESCALE_1024; - /* Enable the interrupt - this is okay as interrupt are currently globally disabled. */ - ucLowByte = portTIMSK; - ucLowByte |= portCOMPARE_MATCH_A_INTERRUPT_ENABLE; - portTIMSK = ucLowByte; - } + /* Enable the interrupt - this is okay as interrupt are currently globally disabled. */ + ucLowByte = portTIMSK; + ucLowByte |= portCOMPARE_MATCH_A_INTERRUPT_ENABLE; + portTIMSK = ucLowByte; +} -#endif /* if defined( portUSE_WDTO ) */ +#endif /*-----------------------------------------------------------*/ #if configUSE_PREEMPTION == 1 -/* - * Tick ISR for preemptive scheduler. We can use a naked attribute as - * the context is saved at the start of vPortYieldFromTick(). The tick - * count is incremented after the context is saved. - * - * use ISR_NOBLOCK where there is an important timer running, that should preempt the scheduler. - * - */ - ISR( portSCHEDULER_ISR, ISR_NAKED ) __attribute__( ( hot, flatten ) ); - + /* + * Tick ISR for preemptive scheduler. We can use a naked attribute as + * the context is saved at the start of vPortYieldFromTick(). The tick + * count is incremented after the context is saved. + * + * use ISR_NOBLOCK where there is an important timer running, that should preempt the scheduler. + * + */ + ISR(portSCHEDULER_ISR, ISR_NAKED) __attribute__ ((hot, flatten)); /* ISR(portSCHEDULER_ISR, ISR_NAKED ISR_NOBLOCK) __attribute__ ((hot, flatten)); */ - ISR( portSCHEDULER_ISR ) + ISR(portSCHEDULER_ISR) { vPortYieldFromTick(); __asm__ __volatile__ ( "reti" ); } -#else /* if configUSE_PREEMPTION == 1 */ - -/* - * Tick ISR for the cooperative scheduler. All this does is increment the - * tick count. We don't need to switch context, this can only be done by - * manual calls to taskYIELD(); - * - * use ISR_NOBLOCK where there is an important timer running, that should preempt the scheduler. - */ - ISR( portSCHEDULER_ISR ) __attribute__( ( hot, flatten ) ); +#else + /* + * Tick ISR for the cooperative scheduler. All this does is increment the + * tick count. We don't need to switch context, this can only be done by + * manual calls to taskYIELD(); + * + * use ISR_NOBLOCK where there is an important timer running, that should preempt the scheduler. + */ + ISR(portSCHEDULER_ISR) __attribute__ ((hot, flatten)); /* ISR(portSCHEDULER_ISR, ISR_NOBLOCK) __attribute__ ((hot, flatten)); */ - ISR( portSCHEDULER_ISR ) + ISR(portSCHEDULER_ISR) { xTaskIncrementTick(); } -#endif /* if configUSE_PREEMPTION == 1 */ +#endif + + diff --git a/portable/ThirdParty/GCC/ATmega/portmacro.h b/portable/ThirdParty/GCC/ATmega/portmacro.h index ab3dc1f6c..b6b512874 100644 --- a/portable/ThirdParty/GCC/ATmega/portmacro.h +++ b/portable/ThirdParty/GCC/ATmega/portmacro.h @@ -23,14 +23,14 @@ * http://aws.amazon.com/freertos * * 1 tab == 4 spaces! - */ +*/ #ifndef PORTMACRO_H - #define PORTMACRO_H +#define PORTMACRO_H - #ifdef __cplusplus - extern "C" { - #endif +#ifdef __cplusplus +extern "C" { +#endif /*----------------------------------------------------------- * Port specific definitions. @@ -42,49 +42,47 @@ *----------------------------------------------------------- */ - #include +#include /* Type definitions. */ - #define portCHAR char - #define portFLOAT float - #define portDOUBLE double - #define portLONG long - #define portSHORT int +#define portCHAR char +#define portFLOAT float +#define portDOUBLE double +#define portLONG long +#define portSHORT int - typedef uint8_t StackType_t; - typedef int8_t BaseType_t; - typedef uint8_t UBaseType_t; +typedef uint8_t StackType_t; +typedef int8_t BaseType_t; +typedef uint8_t UBaseType_t; - #if configUSE_16_BIT_TICKS == 1 - typedef uint16_t TickType_t; - #define portMAX_DELAY ( TickType_t ) 0xffff - #else - typedef uint32_t TickType_t; - #define portMAX_DELAY ( TickType_t ) 0xffffffffUL - #endif +#if configUSE_16_BIT_TICKS == 1 + typedef uint16_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffff +#else + typedef uint32_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffffffffUL +#endif /*-----------------------------------------------------------*/ /* Critical section management. */ - #define portENTER_CRITICAL() \ - __asm__ __volatile__ ( \ - "in __tmp_reg__, __SREG__" "\n\t" \ - "cli" "\n\t" \ - "push __tmp_reg__" "\n\t" \ - ::: "memory" \ - ) +#define portENTER_CRITICAL() __asm__ __volatile__ ( \ + "in __tmp_reg__, __SREG__" "\n\t" \ + "cli" "\n\t" \ + "push __tmp_reg__" "\n\t" \ + ::: "memory" \ + ) - #define portEXIT_CRITICAL() \ - __asm__ __volatile__ ( \ - "pop __tmp_reg__" "\n\t" \ - "out __SREG__, __tmp_reg__" "\n\t" \ - ::: "memory" \ - ) +#define portEXIT_CRITICAL() __asm__ __volatile__ ( \ + "pop __tmp_reg__" "\n\t" \ + "out __SREG__, __tmp_reg__" "\n\t" \ + ::: "memory" \ + ) - #define portDISABLE_INTERRUPTS() __asm__ __volatile__ ( "cli" ::: "memory" ) - #define portENABLE_INTERRUPTS() __asm__ __volatile__ ( "sei" ::: "memory" ) +#define portDISABLE_INTERRUPTS() __asm__ __volatile__ ( "cli" ::: "memory") +#define portENABLE_INTERRUPTS() __asm__ __volatile__ ( "sei" ::: "memory") /*-----------------------------------------------------------*/ /* Architecture specifics. */ @@ -93,66 +91,66 @@ * Prefer to use the enhanced Watchdog Timer, but also Timer0 is ok. */ - #if defined( WDIE ) && defined( WDIF ) /* If Enhanced WDT with interrupt capability is available */ +#if defined(WDIE) && defined(WDIF) /* If Enhanced WDT with interrupt capability is available */ - #define portUSE_WDTO WDTO_15MS /* use the Watchdog Timer for xTaskIncrementTick */ +#define portUSE_WDTO WDTO_15MS /* use the Watchdog Timer for xTaskIncrementTick */ /* Watchdog period options: WDTO_15MS - * WDTO_30MS - * WDTO_60MS - * WDTO_120MS - * WDTO_250MS - * WDTO_500MS - * WDTO_1S - * WDTO_2S - */ + WDTO_30MS + WDTO_60MS + WDTO_120MS + WDTO_250MS + WDTO_500MS + WDTO_1S + WDTO_2S +*/ - #else +#else - #define portUSE_TIMER0 /* use the 8-bit Timer0 for xTaskIncrementTick */ +#define portUSE_TIMER0 /* use the 8-bit Timer0 for xTaskIncrementTick */ - #endif +#endif - #define portSTACK_GROWTH ( -1 ) +#define portSTACK_GROWTH ( -1 ) /* Timing for the scheduler. * Watchdog Timer is 128kHz nominal, * but 120 kHz at 5V DC and 25 degrees is actually more accurate, * from data sheet. */ - #if defined( portUSE_WDTO ) - #define portTICK_PERIOD_MS ( ( TickType_t ) _BV( portUSE_WDTO + 4 ) ) - #else - #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) - #endif +#if defined( portUSE_WDTO ) +#define portTICK_PERIOD_MS ( (TickType_t) _BV( portUSE_WDTO + 4 ) ) +#else +#define portTICK_PERIOD_MS ( (TickType_t) 1000 / configTICK_RATE_HZ ) +#endif - #define portBYTE_ALIGNMENT 1 - #define portNOP() __asm__ __volatile__ ( "nop" ); +#define portBYTE_ALIGNMENT 1 +#define portNOP() __asm__ __volatile__ ( "nop" ); /*-----------------------------------------------------------*/ /* Kernel utilities. */ - extern void vPortYield( void ) __attribute__( ( naked ) ); - #define portYIELD() vPortYield() +extern void vPortYield( void ) __attribute__ ( ( naked ) ); +#define portYIELD() vPortYield() - extern void vPortYieldFromISR( void ) __attribute__( ( naked ) ); - #define portYIELD_FROM_ISR() vPortYieldFromISR() +extern void vPortYieldFromISR( void ) __attribute__ ( ( naked ) ); +#define portYIELD_FROM_ISR() vPortYieldFromISR() /*-----------------------------------------------------------*/ - #if defined( __AVR_3_BYTE_PC__ ) +#if defined(__AVR_3_BYTE_PC__) /* Task function macros as described on the FreeRTOS.org WEB site. */ /* Add .lowtext tag from the avr linker script avr6.x for ATmega2560 and ATmega2561 * to make sure functions are loaded in low memory. */ - #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) __attribute__( ( section( ".lowtext" ) ) ) - #else - #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) - #endif +#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__ ((section (".lowtext"))) +#else +#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) +#endif - #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) +#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) - #ifdef __cplusplus - } - #endif +#ifdef __cplusplus +} +#endif #endif /* PORTMACRO_H */ diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index a63ef7e8d..a00ab172c 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -26,31 +26,31 @@ */ /*----------------------------------------------------------- -* Implementation of functions defined in portable.h for the Posix port. -* -* Each task has a pthread which eases use of standard debuggers -* (allowing backtraces of tasks etc). Threads for tasks that are not -* running are blocked in sigwait(). -* -* Task switch is done by resuming the thread for the next task by -* sending it the resume signal (SIGUSR1) and then suspending the -* current thread. -* -* The timer interrupt uses SIGALRM and care is taken to ensure that -* the signal handler runs only on the thread for the current task. -* -* Use of part of the standard C library requires care as some -* functions can take pthread mutexes internally which can result in -* deadlocks as the FreeRTOS kernel can switch tasks while they're -* holding a pthread mutex. -* -* Replacement malloc(), free(), calloc(), and realloc() are provided -* for glibc (see below for more information). -* -* stdio (printf() and friends) should be called from a single task -* only or serialized with a FreeRTOS primitive such as a binary -* semaphore or mutex. -*----------------------------------------------------------*/ + * Implementation of functions defined in portable.h for the Posix port. + * + * Each task has a pthread which eases use of standard debuggers + * (allowing backtraces of tasks etc). Threads for tasks that are not + * running are blocked in sigwait(). + * + * Task switch is done by resuming the thread for the next task by + * sending it the resume signal (SIGUSR1) and then suspending the + * current thread. + * + * The timer interrupt uses SIGALRM and care is taken to ensure that + * the signal handler runs only on the thread for the current task. + * + * Use of part of the standard C library requires care as some + * functions can take pthread mutexes internally which can result in + * deadlocks as the FreeRTOS kernel can switch tasks while they're + * holding a pthread mutex. + * + * Replacement malloc(), free(), calloc(), and realloc() are provided + * for glibc (see below for more information). + * + * stdio (printf() and friends) should be called from a single task + * only or serialized with a FreeRTOS primitive such as a binary + * semaphore or mutex. + *----------------------------------------------------------*/ #include #include @@ -67,25 +67,25 @@ #include "task.h" /*-----------------------------------------------------------*/ -#define SIG_RESUME SIGUSR1 +#define SIG_RESUME SIGUSR1 typedef struct THREAD { - pthread_t pthread; - pdTASK_CODE pxCode; - void * pvParams; - BaseType_t xDying; + pthread_t pthread; + pdTASK_CODE pxCode; + void *pvParams; + BaseType_t xDying; } Thread_t; /* * The additional per-thread data is stored at the beginning of the * task's stack. */ -static inline Thread_t * prvGetThreadFromTask( TaskHandle_t xTask ) +static inline Thread_t *prvGetThreadFromTask(TaskHandle_t xTask) { - StackType_t * pxTopOfStack = *( StackType_t ** ) xTask; +StackType_t *pxTopOfStack = *(StackType_t **)xTask; - return ( Thread_t * ) ( pxTopOfStack + 1 ); + return (Thread_t *)(pxTopOfStack + 1); } /*-----------------------------------------------------------*/ @@ -94,7 +94,7 @@ static pthread_once_t hSigSetupThread = PTHREAD_ONCE_INIT; static sigset_t xResumeSignals; static sigset_t xAllSignals; static sigset_t xSchedulerOriginalSignalMask; -static pthread_t hMainThread = ( pthread_t ) NULL; +static pthread_t hMainThread = ( pthread_t )NULL; static volatile portBASE_TYPE uxCriticalNesting; /*-----------------------------------------------------------*/ @@ -103,9 +103,8 @@ static portBASE_TYPE xSchedulerEnd = pdFALSE; static void prvSetupSignalsAndSchedulerPolicy( void ); static void prvSetupTimerInterrupt( void ); -static void * prvWaitForStart( void * pvParams ); -static void prvSwitchThread( Thread_t * xThreadToResume, - Thread_t * xThreadToSuspend ); +static void *prvWaitForStart( void * pvParams ); +static void prvSwitchThread( Thread_t *xThreadToResume, Thread_t *xThreadToSuspend ); static void prvSuspendSelf( void ); static void prvResumeThread( pthread_t xThreadId ); static void vPortSystemTickHandler( int sig ); @@ -132,117 +131,110 @@ static void vPortStartFirstTask( void ); * timer (SIGALRM) and other signals. */ -extern void * __libc_malloc( size_t ); -extern void __libc_free( void * ); -extern void * __libc_calloc( size_t, - size_t ); -extern void * __libc_realloc( void * ptr, - size_t ); +extern void *__libc_malloc(size_t); +extern void __libc_free(void *); +extern void *__libc_calloc(size_t, size_t); +extern void *__libc_realloc(void *ptr, size_t); -void * malloc( size_t size ) +void *malloc(size_t size) { - sigset_t xSavedSignals; - void * ptr; +sigset_t xSavedSignals; +void *ptr; - pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); - ptr = __libc_malloc( size ); - pthread_sigmask( SIG_SETMASK, &xSavedSignals, NULL ); + pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); + ptr = __libc_malloc( size ); + pthread_sigmask( SIG_SETMASK, &xSavedSignals, NULL ); - return ptr; + return ptr; } -void free( void * ptr ) +void free(void *ptr) { - sigset_t xSavedSignals; +sigset_t xSavedSignals; - pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); - __libc_free( ptr ); - pthread_sigmask( SIG_SETMASK, &xSavedSignals, NULL ); + pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); + __libc_free( ptr ); + pthread_sigmask( SIG_SETMASK, &xSavedSignals, NULL ); } -void * calloc( size_t nmemb, - size_t size ) +void *calloc(size_t nmemb, size_t size) { - sigset_t xSavedSignals; - void * ptr; +sigset_t xSavedSignals; +void *ptr; - pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); - ptr = __libc_calloc( nmemb, size ); - pthread_sigmask( SIG_SETMASK, &xSavedSignals, NULL ); + pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); + ptr = __libc_calloc( nmemb, size ); + pthread_sigmask( SIG_SETMASK, &xSavedSignals, NULL ); - return ptr; + return ptr; } -void * realloc( void * ptr, - size_t size ) +void *realloc(void *ptr, size_t size) { - sigset_t xSavedSignals; +sigset_t xSavedSignals; - pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); - ptr = __libc_realloc( ptr, size ); - pthread_sigmask( SIG_SETMASK, &xSavedSignals, NULL ); + pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); + ptr = __libc_realloc( ptr, size ); + pthread_sigmask( SIG_SETMASK, &xSavedSignals, NULL ); - return ptr; + return ptr; } -static void prvFatalError( const char * pcCall, - int iErrno ) +static void prvFatalError( const char *pcCall, int iErrno ) { - fprintf( stderr, "%s: %s\n", pcCall, strerror( iErrno ) ); - abort(); + fprintf( stderr, "%s: %s\n", pcCall, strerror( iErrno ) ); + abort(); } /* * See header file for description. */ -portSTACK_TYPE * pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, - portSTACK_TYPE * pxEndOfStack, - pdTASK_CODE pxCode, - void * pvParameters ) +portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, + portSTACK_TYPE *pxEndOfStack, + pdTASK_CODE pxCode, void *pvParameters ) { - Thread_t * thread; - pthread_attr_t xThreadAttributes; - size_t ulStackSize; - int iRet; +Thread_t *thread; +pthread_attr_t xThreadAttributes; +size_t ulStackSize; +int iRet; - ( void ) pthread_once( &hSigSetupThread, prvSetupSignalsAndSchedulerPolicy ); + (void)pthread_once( &hSigSetupThread, prvSetupSignalsAndSchedulerPolicy ); - /* - * Store the additional thread data at the start of the stack. - */ - thread = ( Thread_t * ) ( pxTopOfStack + 1 ) - 1; - pxTopOfStack = ( portSTACK_TYPE * ) thread - 1; - ulStackSize = ( pxTopOfStack + 1 - pxEndOfStack ) * sizeof( *pxTopOfStack ); + /* + * Store the additional thread data at the start of the stack. + */ + thread = (Thread_t *)(pxTopOfStack + 1) - 1; + pxTopOfStack = (portSTACK_TYPE *)thread - 1; + ulStackSize = (pxTopOfStack + 1 - pxEndOfStack) * sizeof(*pxTopOfStack); - thread->pxCode = pxCode; - thread->pvParams = pvParameters; - thread->xDying = pdFALSE; + thread->pxCode = pxCode; + thread->pvParams = pvParameters; + thread->xDying = pdFALSE; - pthread_attr_init( &xThreadAttributes ); - pthread_attr_setstack( &xThreadAttributes, pxEndOfStack, ulStackSize ); + pthread_attr_init( &xThreadAttributes ); + pthread_attr_setstack( &xThreadAttributes, pxEndOfStack, ulStackSize ); - vPortEnterCritical(); + vPortEnterCritical(); - iRet = pthread_create( &thread->pthread, &xThreadAttributes, - prvWaitForStart, thread ); + iRet = pthread_create( &thread->pthread, &xThreadAttributes, + prvWaitForStart, thread ); + if ( iRet ) + { + prvFatalError( "pthread_create", iRet ); + } - if( iRet ) - { - prvFatalError( "pthread_create", iRet ); - } + vPortExitCritical(); - vPortExitCritical(); - - return pxTopOfStack; + return pxTopOfStack; } /*-----------------------------------------------------------*/ void vPortStartFirstTask( void ) { - Thread_t * pxFirstThread = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); +Thread_t *pxFirstThread = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); - /* Start the first task. */ - prvResumeThread( pxFirstThread->pthread ); + /* Start the first task. */ + prvResumeThread( pxFirstThread->pthread ); } /*-----------------------------------------------------------*/ @@ -251,126 +243,125 @@ void vPortStartFirstTask( void ) */ portBASE_TYPE xPortStartScheduler( void ) { - int iSignal; - sigset_t xSignals; +int iSignal; +sigset_t xSignals; - hMainThread = pthread_self(); + hMainThread = pthread_self(); - /* Start the timer that generates the tick ISR. Interrupts are disabled - * here already. */ - prvSetupTimerInterrupt(); + /* Start the timer that generates the tick ISR. Interrupts are disabled + here already. */ + prvSetupTimerInterrupt(); - /* Start the first task. */ - vPortStartFirstTask(); + /* Start the first task. */ + vPortStartFirstTask(); - /* Wait until signaled by vPortEndScheduler(). */ - sigemptyset( &xSignals ); - sigaddset( &xSignals, SIG_RESUME ); + /* Wait until signaled by vPortEndScheduler(). */ + sigemptyset( &xSignals ); + sigaddset( &xSignals, SIG_RESUME ); - while( !xSchedulerEnd ) - { - sigwait( &xSignals, &iSignal ); - } + while ( !xSchedulerEnd ) + { + sigwait( &xSignals, &iSignal ); + } - /* Restore original signal mask. */ - ( void ) pthread_sigmask( SIG_SETMASK, &xSchedulerOriginalSignalMask, NULL ); + /* Restore original signal mask. */ + (void)pthread_sigmask( SIG_SETMASK, &xSchedulerOriginalSignalMask, NULL ); - return 0; + return 0; } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { - struct itimerval itimer; - struct sigaction sigtick; +struct itimerval itimer; +struct sigaction sigtick; - /* Stop the timer and ignore any pending SIGALRMs that would end - * up running on the main thread when it is resumed. */ - itimer.it_value.tv_sec = 0; - itimer.it_value.tv_usec = 0; + /* Stop the timer and ignore any pending SIGALRMs that would end + * up running on the main thread when it is resumed. */ + itimer.it_value.tv_sec = 0; + itimer.it_value.tv_usec = 0; - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = 0; - ( void ) setitimer( ITIMER_REAL, &itimer, NULL ); + itimer.it_interval.tv_sec = 0; + itimer.it_interval.tv_usec = 0; + (void)setitimer( ITIMER_REAL, &itimer, NULL ); - sigtick.sa_flags = 0; - sigtick.sa_handler = SIG_IGN; - sigemptyset( &sigtick.sa_mask ); - sigaction( SIGALRM, &sigtick, NULL ); + sigtick.sa_flags = 0; + sigtick.sa_handler = SIG_IGN; + sigemptyset( &sigtick.sa_mask ); + sigaction( SIGALRM, &sigtick, NULL ); - /* Signal the scheduler to exit its loop. */ - xSchedulerEnd = pdTRUE; - ( void ) pthread_kill( hMainThread, SIG_RESUME ); + /* Signal the scheduler to exit its loop. */ + xSchedulerEnd = pdTRUE; + (void)pthread_kill( hMainThread, SIG_RESUME ); - prvSuspendSelf(); + prvSuspendSelf(); } /*-----------------------------------------------------------*/ void vPortEnterCritical( void ) { - if( uxCriticalNesting == 0 ) - { - vPortDisableInterrupts(); - } - - uxCriticalNesting++; + if ( uxCriticalNesting == 0 ) + { + vPortDisableInterrupts(); + } + uxCriticalNesting++; } /*-----------------------------------------------------------*/ void vPortExitCritical( void ) { - uxCriticalNesting--; + uxCriticalNesting--; - /* If we have reached 0 then re-enable the interrupts. */ - if( uxCriticalNesting == 0 ) - { - vPortEnableInterrupts(); - } + /* If we have reached 0 then re-enable the interrupts. */ + if( uxCriticalNesting == 0 ) + { + vPortEnableInterrupts(); + } } /*-----------------------------------------------------------*/ void vPortYieldFromISR( void ) { - Thread_t * xThreadToSuspend; - Thread_t * xThreadToResume; +Thread_t *xThreadToSuspend; +Thread_t *xThreadToResume; - xThreadToSuspend = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); + xThreadToSuspend = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); - vTaskSwitchContext(); + vTaskSwitchContext(); - xThreadToResume = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); + xThreadToResume = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); - prvSwitchThread( xThreadToResume, xThreadToSuspend ); + prvSwitchThread( xThreadToResume, xThreadToSuspend ); } /*-----------------------------------------------------------*/ void vPortYield( void ) { - vPortEnterCritical(); + vPortEnterCritical(); - vPortYieldFromISR(); + vPortYieldFromISR(); - vPortExitCritical(); + vPortExitCritical(); } /*-----------------------------------------------------------*/ void vPortDisableInterrupts( void ) { - pthread_sigmask( SIG_BLOCK, &xAllSignals, NULL ); + pthread_sigmask( SIG_BLOCK, &xAllSignals, NULL ); } /*-----------------------------------------------------------*/ void vPortEnableInterrupts( void ) { - pthread_sigmask( SIG_UNBLOCK, &xAllSignals, NULL ); + pthread_sigmask( SIG_UNBLOCK, &xAllSignals, NULL ); } /*-----------------------------------------------------------*/ portBASE_TYPE xPortSetInterruptMask( void ) { - /* Interrupts are always disabled inside ISRs (signals - * handlers). */ - return pdTRUE; + /* Interrupts are always disabled inside ISRs (signals + handlers). */ + return pdTRUE; } /*-----------------------------------------------------------*/ @@ -379,13 +370,13 @@ void vPortClearInterruptMask( portBASE_TYPE xMask ) } /*-----------------------------------------------------------*/ -static uint64_t prvGetTimeNs( void ) +static uint64_t prvGetTimeNs(void) { - struct timespec t; +struct timespec t; - clock_gettime( CLOCK_MONOTONIC, &t ); + clock_gettime(CLOCK_MONOTONIC, &t); - return t.tv_sec * 1000000000ull + t.tv_nsec; + return t.tv_sec * 1000000000ull + t.tv_nsec; } static uint64_t prvStartTimeNs; @@ -397,228 +388,218 @@ static uint64_t prvTickCount; */ void prvSetupTimerInterrupt( void ) { - struct itimerval itimer; - int iRet; +struct itimerval itimer; +int iRet; - /* Initialise the structure with the current timer information. */ - iRet = getitimer( ITIMER_REAL, &itimer ); + /* Initialise the structure with the current timer information. */ + iRet = getitimer( ITIMER_REAL, &itimer ); + if ( iRet ) + { + prvFatalError( "getitimer", errno ); + } - if( iRet ) - { - prvFatalError( "getitimer", errno ); - } + /* Set the interval between timer events. */ + itimer.it_interval.tv_sec = 0; + itimer.it_interval.tv_usec = portTICK_RATE_MICROSECONDS; - /* Set the interval between timer events. */ - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = portTICK_RATE_MICROSECONDS; + /* Set the current count-down. */ + itimer.it_value.tv_sec = 0; + itimer.it_value.tv_usec = portTICK_RATE_MICROSECONDS; - /* Set the current count-down. */ - itimer.it_value.tv_sec = 0; - itimer.it_value.tv_usec = portTICK_RATE_MICROSECONDS; + /* Set-up the timer interrupt. */ + iRet = setitimer( ITIMER_REAL, &itimer, NULL ); + if ( iRet ) + { + prvFatalError( "setitimer", errno ); + } - /* Set-up the timer interrupt. */ - iRet = setitimer( ITIMER_REAL, &itimer, NULL ); - - if( iRet ) - { - prvFatalError( "setitimer", errno ); - } - - prvStartTimeNs = prvGetTimeNs(); + prvStartTimeNs = prvGetTimeNs(); } /*-----------------------------------------------------------*/ static void vPortSystemTickHandler( int sig ) { - Thread_t * pxThreadToSuspend; - Thread_t * pxThreadToResume; - uint64_t xExpectedTicks; +Thread_t *pxThreadToSuspend; +Thread_t *pxThreadToResume; +uint64_t xExpectedTicks; - uxCriticalNesting++; /* Signals are blocked in this signal handler. */ + uxCriticalNesting++; /* Signals are blocked in this signal handler. */ - pxThreadToSuspend = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); + pxThreadToSuspend = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); - /* Tick Increment, accounting for any lost signals or drift in - * the timer. */ - xExpectedTicks = ( prvGetTimeNs() - prvStartTimeNs ) - / ( portTICK_RATE_MICROSECONDS * 1000 ); + /* Tick Increment, accounting for any lost signals or drift in + * the timer. */ + xExpectedTicks = (prvGetTimeNs() - prvStartTimeNs) + / (portTICK_RATE_MICROSECONDS * 1000); + do { + xTaskIncrementTick(); + prvTickCount++; + } while (prvTickCount < xExpectedTicks); - do - { - xTaskIncrementTick(); - prvTickCount++; - } while( prvTickCount < xExpectedTicks ); +#if ( configUSE_PREEMPTION == 1 ) + /* Select Next Task. */ + vTaskSwitchContext(); - #if ( configUSE_PREEMPTION == 1 ) - /* Select Next Task. */ - vTaskSwitchContext(); + pxThreadToResume = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); - pxThreadToResume = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); + prvSwitchThread(pxThreadToResume, pxThreadToSuspend); +#endif - prvSwitchThread( pxThreadToResume, pxThreadToSuspend ); - #endif - - uxCriticalNesting--; + uxCriticalNesting--; } /*-----------------------------------------------------------*/ -void vPortThreadDying( void * pxTaskToDelete, - volatile BaseType_t * pxPendYield ) +void vPortThreadDying( void *pxTaskToDelete, volatile BaseType_t *pxPendYield ) { - Thread_t * pxThread = prvGetThreadFromTask( pxTaskToDelete ); +Thread_t *pxThread = prvGetThreadFromTask( pxTaskToDelete ); - pxThread->xDying = pdTRUE; + pxThread->xDying = pdTRUE; } -void vPortCancelThread( void * pxTaskToDelete ) +void vPortCancelThread( void *pxTaskToDelete ) { - Thread_t * pxThreadToCancel = prvGetThreadFromTask( pxTaskToDelete ); +Thread_t *pxThreadToCancel = prvGetThreadFromTask( pxTaskToDelete ); - /* - * The thread has already been suspended so it can be safely - * cancelled. - */ - pthread_cancel( pxThreadToCancel->pthread ); - pthread_join( pxThreadToCancel->pthread, NULL ); + /* + * The thread has already been suspended so it can be safely + * cancelled. + */ + pthread_cancel( pxThreadToCancel->pthread ); + pthread_join( pxThreadToCancel->pthread, NULL ); } /*-----------------------------------------------------------*/ -static void * prvWaitForStart( void * pvParams ) +static void *prvWaitForStart( void * pvParams ) { - Thread_t * pxThread = pvParams; +Thread_t *pxThread = pvParams; - prvSuspendSelf(); + prvSuspendSelf(); - /* Resumed for the first time, unblocks all signals. */ - uxCriticalNesting = 0; - vPortEnableInterrupts(); + /* Resumed for the first time, unblocks all signals. */ + uxCriticalNesting = 0; + vPortEnableInterrupts(); - /* Call the task's entry point. */ - pxThread->pxCode( pxThread->pvParams ); + /* Call the task's entry point. */ + pxThread->pxCode( pxThread->pvParams ); - return NULL; + return NULL; } /*-----------------------------------------------------------*/ -static void prvSwitchThread( Thread_t * pxThreadToResume, - Thread_t * pxThreadToSuspend ) +static void prvSwitchThread( Thread_t *pxThreadToResume, + Thread_t *pxThreadToSuspend ) { - BaseType_t uxSavedCriticalNesting; +BaseType_t uxSavedCriticalNesting; - if( pxThreadToSuspend != pxThreadToResume ) - { - /* - * Switch tasks. - * - * The critical section nesting is per-task, so save it on the - * stack of the current (suspending thread), restoring it when - * we switch back to this task. - */ - uxSavedCriticalNesting = uxCriticalNesting; + if ( pxThreadToSuspend != pxThreadToResume ) + { + /* + * Switch tasks. + * + * The critical section nesting is per-task, so save it on the + * stack of the current (suspending thread), restoring it when + * we switch back to this task. + */ + uxSavedCriticalNesting = uxCriticalNesting; - prvResumeThread( pxThreadToResume->pthread ); + prvResumeThread( pxThreadToResume->pthread ); + if ( pxThreadToSuspend->xDying ) + { + pthread_exit( NULL ); + } + prvSuspendSelf(); - if( pxThreadToSuspend->xDying ) - { - pthread_exit( NULL ); - } - - prvSuspendSelf(); - - uxCriticalNesting = uxSavedCriticalNesting; - } + uxCriticalNesting = uxSavedCriticalNesting; + } } /*-----------------------------------------------------------*/ static void prvSuspendSelf( void ) { - int iSig; +int iSig; - /* - * Suspend this thread by waiting for a SIG_RESUME signal. - * - * A suspended thread must not handle signals (interrupts) so - * all signals must be blocked by calling this from: - * - * - Inside a critical section (vPortEnterCritical() / - * vPortExitCritical()). - * - * - From a signal handler that has all signals masked. - * - * - A thread with all signals blocked with pthread_sigmask(). - */ - sigwait( &xResumeSignals, &iSig ); + /* + * Suspend this thread by waiting for a SIG_RESUME signal. + * + * A suspended thread must not handle signals (interrupts) so + * all signals must be blocked by calling this from: + * + * - Inside a critical section (vPortEnterCritical() / + * vPortExitCritical()). + * + * - From a signal handler that has all signals masked. + * + * - A thread with all signals blocked with pthread_sigmask(). + */ + sigwait( &xResumeSignals, &iSig ); } /*-----------------------------------------------------------*/ static void prvResumeThread( pthread_t xThreadId ) { - if( pthread_self() != xThreadId ) - { - pthread_kill( xThreadId, SIG_RESUME ); - } + if ( pthread_self() != xThreadId ) + { + pthread_kill( xThreadId, SIG_RESUME ); + } } /*-----------------------------------------------------------*/ static void prvSetupSignalsAndSchedulerPolicy( void ) { - struct sigaction sigresume, sigtick; - int iRet; +struct sigaction sigresume, sigtick; +int iRet; - hMainThread = pthread_self(); + hMainThread = pthread_self(); - /* Initialise common signal masks. */ - sigemptyset( &xResumeSignals ); - sigaddset( &xResumeSignals, SIG_RESUME ); - sigfillset( &xAllSignals ); + /* Initialise common signal masks. */ + sigemptyset( &xResumeSignals ); + sigaddset( &xResumeSignals, SIG_RESUME ); + sigfillset( &xAllSignals ); + /* Don't block SIGINT so this can be used to break into GDB while + * in a critical section. */ + sigdelset( &xAllSignals, SIGINT ); - /* Don't block SIGINT so this can be used to break into GDB while - * in a critical section. */ - sigdelset( &xAllSignals, SIGINT ); + /* + * Block all signals in this thread so all new threads + * inherits this mask. + * + * When a thread is resumed for the first time, all signals + * will be unblocked. + */ + (void)pthread_sigmask( SIG_SETMASK, &xAllSignals, + &xSchedulerOriginalSignalMask ); - /* - * Block all signals in this thread so all new threads - * inherits this mask. - * - * When a thread is resumed for the first time, all signals - * will be unblocked. - */ - ( void ) pthread_sigmask( SIG_SETMASK, &xAllSignals, - &xSchedulerOriginalSignalMask ); + /* SIG_RESUME is only used with sigwait() so doesn't need a + handler. */ + sigresume.sa_flags = 0; + sigresume.sa_handler = SIG_IGN; + sigfillset( &sigresume.sa_mask ); - /* SIG_RESUME is only used with sigwait() so doesn't need a - * handler. */ - sigresume.sa_flags = 0; - sigresume.sa_handler = SIG_IGN; - sigfillset( &sigresume.sa_mask ); + sigtick.sa_flags = 0; + sigtick.sa_handler = vPortSystemTickHandler; + sigfillset( &sigtick.sa_mask ); - sigtick.sa_flags = 0; - sigtick.sa_handler = vPortSystemTickHandler; - sigfillset( &sigtick.sa_mask ); + iRet = sigaction( SIG_RESUME, &sigresume, NULL ); + if ( iRet ) + { + prvFatalError( "sigaction", errno ); + } - iRet = sigaction( SIG_RESUME, &sigresume, NULL ); - - if( iRet ) - { - prvFatalError( "sigaction", errno ); - } - - iRet = sigaction( SIGALRM, &sigtick, NULL ); - - if( iRet ) - { - prvFatalError( "sigaction", errno ); - } + iRet = sigaction( SIGALRM, &sigtick, NULL ); + if ( iRet ) + { + prvFatalError( "sigaction", errno ); + } } /*-----------------------------------------------------------*/ unsigned long ulPortGetRunTime( void ) { - struct tms xTimes; +struct tms xTimes; - times( &xTimes ); + times( &xTimes ); - return ( unsigned long ) xTimes.tms_utime; + return ( unsigned long ) xTimes.tms_utime; } /*-----------------------------------------------------------*/ diff --git a/portable/ThirdParty/GCC/Posix/portmacro.h b/portable/ThirdParty/GCC/Posix/portmacro.h index 91d44fe96..8046cbc8f 100644 --- a/portable/ThirdParty/GCC/Posix/portmacro.h +++ b/portable/ThirdParty/GCC/Posix/portmacro.h @@ -27,13 +27,13 @@ #ifndef PORTMACRO_H - #define PORTMACRO_H +#define PORTMACRO_H - #ifdef __cplusplus - extern "C" { - #endif +#ifdef __cplusplus +extern "C" { +#endif - #include +#include /*----------------------------------------------------------- * Port specific definitions. @@ -46,72 +46,71 @@ */ /* Type definitions. */ - #define portCHAR char - #define portFLOAT float - #define portDOUBLE double - #define portLONG long - #define portSHORT short - #define portSTACK_TYPE unsigned long - #define portBASE_TYPE long - #define portPOINTER_SIZE_TYPE intptr_t +#define portCHAR char +#define portFLOAT float +#define portDOUBLE double +#define portLONG long +#define portSHORT short +#define portSTACK_TYPE unsigned long +#define portBASE_TYPE long +#define portPOINTER_SIZE_TYPE intptr_t - typedef portSTACK_TYPE StackType_t; - typedef long BaseType_t; - typedef unsigned long UBaseType_t; +typedef portSTACK_TYPE StackType_t; +typedef long BaseType_t; +typedef unsigned long UBaseType_t; - typedef unsigned long TickType_t; - #define portMAX_DELAY ( TickType_t ) ULONG_MAX +typedef unsigned long TickType_t; +#define portMAX_DELAY ( TickType_t ) ULONG_MAX - #define portTICK_TYPE_IS_ATOMIC 1 +#define portTICK_TYPE_IS_ATOMIC 1 /*-----------------------------------------------------------*/ /* Architecture specifics. */ - #define portSTACK_GROWTH ( -1 ) - #define portHAS_STACK_OVERFLOW_CHECKING ( 1 ) - #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) - #define portTICK_RATE_MICROSECONDS ( ( portTickType ) 1000000 / configTICK_RATE_HZ ) - #define portBYTE_ALIGNMENT 8 +#define portSTACK_GROWTH ( -1 ) +#define portHAS_STACK_OVERFLOW_CHECKING ( 1 ) +#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) +#define portTICK_RATE_MICROSECONDS ( ( portTickType ) 1000000 / configTICK_RATE_HZ ) +#define portBYTE_ALIGNMENT 8 /*-----------------------------------------------------------*/ /* Scheduler utilities. */ - extern void vPortYield( void ); +extern void vPortYield( void ); - #define portYIELD() vPortYield() +#define portYIELD() vPortYield() - #define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) vPortYield() - #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) +#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) vPortYield() +#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) /*-----------------------------------------------------------*/ /* Critical section management. */ - extern void vPortDisableInterrupts( void ); - extern void vPortEnableInterrupts( void ); - #define portSET_INTERRUPT_MASK() ( vPortDisableInterrupts() ) - #define portCLEAR_INTERRUPT_MASK() ( vPortEnableInterrupts() ) +extern void vPortDisableInterrupts( void ); +extern void vPortEnableInterrupts( void ); +#define portSET_INTERRUPT_MASK() ( vPortDisableInterrupts() ) +#define portCLEAR_INTERRUPT_MASK() ( vPortEnableInterrupts() ) - extern portBASE_TYPE xPortSetInterruptMask( void ); - extern void vPortClearInterruptMask( portBASE_TYPE xMask ); +extern portBASE_TYPE xPortSetInterruptMask( void ); +extern void vPortClearInterruptMask( portBASE_TYPE xMask ); - extern void vPortEnterCritical( void ); - extern void vPortExitCritical( void ); - #define portSET_INTERRUPT_MASK_FROM_ISR() xPortSetInterruptMask() - #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vPortClearInterruptMask( x ) - #define portDISABLE_INTERRUPTS() portSET_INTERRUPT_MASK() - #define portENABLE_INTERRUPTS() portCLEAR_INTERRUPT_MASK() - #define portENTER_CRITICAL() vPortEnterCritical() - #define portEXIT_CRITICAL() vPortExitCritical() +extern void vPortEnterCritical( void ); +extern void vPortExitCritical( void ); +#define portSET_INTERRUPT_MASK_FROM_ISR() xPortSetInterruptMask() +#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vPortClearInterruptMask(x) +#define portDISABLE_INTERRUPTS() portSET_INTERRUPT_MASK() +#define portENABLE_INTERRUPTS() portCLEAR_INTERRUPT_MASK() +#define portENTER_CRITICAL() vPortEnterCritical() +#define portEXIT_CRITICAL() vPortExitCritical() /*-----------------------------------------------------------*/ - extern void vPortThreadDying( void * pxTaskToDelete, - volatile BaseType_t * pxPendYield ); - extern void vPortCancelThread( void * pxTaskToDelete ); - #define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortThreadDying( ( pvTaskToDelete ), ( pxPendYield ) ) - #define portCLEAN_UP_TCB( pxTCB ) vPortCancelThread( pxTCB ) +extern void vPortThreadDying( void *pxTaskToDelete, volatile BaseType_t *pxPendYield ); +extern void vPortCancelThread( void *pxTaskToDelete ); +#define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortThreadDying( ( pvTaskToDelete ), ( pxPendYield ) ) +#define portCLEAN_UP_TCB( pxTCB ) vPortCancelThread( pxTCB ) /*-----------------------------------------------------------*/ - #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) - #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) +#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) +#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) /*-----------------------------------------------------------*/ /* @@ -122,14 +121,14 @@ * Thus, only a compilier barrier is needed to prevent the compiler * reordering. */ - #define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" ) +#define portMEMORY_BARRIER() __asm volatile( "" ::: "memory" ) - extern unsigned long ulPortGetRunTime( void ); - #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() /* no-op */ - #define portGET_RUN_TIME_COUNTER_VALUE() ulPortGetRunTime() +extern unsigned long ulPortGetRunTime( void ); +#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() /* no-op */ +#define portGET_RUN_TIME_COUNTER_VALUE() ulPortGetRunTime() - #ifdef __cplusplus - } - #endif +#ifdef __cplusplus +} +#endif #endif /* PORTMACRO_H */