Style: revert more uncrustify files

This commit is contained in:
Alfred Gedeon 2020-08-11 21:46:34 -07:00 committed by alfred gedeon
parent fe9e37ca2b
commit c272a13203
4 changed files with 927 additions and 960 deletions

View file

@ -36,13 +36,13 @@
#include "task.h" #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. */ /* 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." #warning "Watchdog Timer used for scheduler."
#define portSCHEDULER_ISR WDT_vect #define portSCHEDULER_ISR WDT_vect
@ -50,50 +50,50 @@
/* Hardware constants for Timer0. */ /* Hardware constants for Timer0. */
#warning "Timer0 used for scheduler." #warning "Timer0 used for scheduler."
#define portSCHEDULER_ISR TIMER0_COMPA_vect #define portSCHEDULER_ISR TIMER0_COMPA_vect
#define portCLEAR_COUNTER_ON_MATCH ( ( uint8_t ) _BV( WGM01 ) ) #define portCLEAR_COUNTER_ON_MATCH ( (uint8_t) _BV(WGM01) )
#define portPRESCALE_1024 ( ( uint8_t ) ( _BV( CS02 ) | _BV( CS00 ) ) ) #define portPRESCALE_1024 ( (uint8_t) (_BV(CS02)|_BV(CS00)) )
#define portCLOCK_PRESCALER ( ( uint32_t ) 1024 ) #define portCLOCK_PRESCALER ( (uint32_t) 1024 )
#define portCOMPARE_MATCH_A_INTERRUPT_ENABLE ( ( uint8_t ) _BV( OCIE0A ) ) #define portCOMPARE_MATCH_A_INTERRUPT_ENABLE ( (uint8_t) _BV(OCIE0A) )
#define portOCRL OCR0A #define portOCRL OCR0A
#define portTCCRa TCCR0A #define portTCCRa TCCR0A
#define portTCCRb TCCR0B #define portTCCRb TCCR0B
#define portTIMSK TIMSK0 #define portTIMSK TIMSK0
#define portTIFR TIFR0 #define portTIFR TIFR0
#endif /* if defined( portUSE_WDTO ) */ #endif
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* We require the address of the pxCurrentTCB variable, but don't want to know /* 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; typedef void TCB_t;
extern volatile TCB_t * volatile pxCurrentTCB; extern volatile TCB_t * volatile pxCurrentTCB;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/** /**
* Enable the watchdog timer, configuring it for expire after Enable the watchdog timer, configuring it for expire after
* (value) timeout (which is a combination of the WDP0 (value) timeout (which is a combination of the WDP0
* through WDP3 bits). through WDP3 bits).
*
* This function is derived from <avr/wdt.h> 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
*/
#if defined( portUSE_WDTO ) This function is derived from <avr/wdt.h> but enables only
the interrupt bit (WDIE), rather than the reset bit (WDE).
static __inline__ Can't find it documented but the WDT, once enabled,
__attribute__( ( __always_inline__ ) ) rolls over and fires a new interrupt each time.
void wdt_interrupt_enable( const uint8_t value )
{ See also the symbolic constants WDTO_15MS et al.
if( _SFR_IO_REG_P( _WD_CONTROL_REG ) )
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))
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"in __tmp_reg__,__SREG__" "\n\t" "in __tmp_reg__,__SREG__" "\n\t"
@ -103,10 +103,10 @@ extern volatile TCB_t * volatile pxCurrentTCB;
"out __SREG__,__tmp_reg__" "\n\t" "out __SREG__,__tmp_reg__" "\n\t"
"out %0, %2" "\n\t" "out %0, %2" "\n\t"
: /* no outputs */ : /* no outputs */
: "I" ( _SFR_IO_ADDR( _WD_CONTROL_REG ) ), : "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)),
"r" ( ( uint8_t ) ( _BV( _WD_CHANGE_BIT ) | _BV( WDE ) ) ), "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),
"r" ( ( uint8_t ) ( ( value & 0x08 ? _WD_PS3_MASK : 0x00 ) | "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) |
_BV( WDIF ) | _BV( WDIE ) | ( value & 0x07 ) ) ) _BV(WDIF) | _BV(WDIE) | (value & 0x07)) )
: "r0" : "r0"
); );
} }
@ -120,47 +120,46 @@ extern volatile TCB_t * volatile pxCurrentTCB;
"out __SREG__,__tmp_reg__" "\n\t" "out __SREG__,__tmp_reg__" "\n\t"
"sts %0, %2" "\n\t" "sts %0, %2" "\n\t"
: /* no outputs */ : /* no outputs */
: "n" ( _SFR_MEM_ADDR( _WD_CONTROL_REG ) ), : "n" (_SFR_MEM_ADDR(_WD_CONTROL_REG)),
"r" ( ( uint8_t ) ( _BV( _WD_CHANGE_BIT ) | _BV( WDE ) ) ), "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),
"r" ( ( uint8_t ) ( ( value & 0x08 ? _WD_PS3_MASK : 0x00 ) | "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) |
_BV( WDIF ) | _BV( WDIE ) | ( value & 0x07 ) ) ) _BV(WDIF) | _BV(WDIE) | (value & 0x07)) )
: "r0" : "r0"
); );
} }
} }
#endif /* if defined( portUSE_WDTO ) */ #endif
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/** /**
* Enable the watchdog timer, configuring it for expire after Enable the watchdog timer, configuring it for expire after
* (value) timeout (which is a combination of the WDP0 (value) timeout (which is a combination of the WDP0
* through WDP3 bits). through WDP3 bits).
*
* This function is derived from <avr/wdt.h> 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
*/
#if defined( portUSE_WDTO ) This function is derived from <avr/wdt.h> but enables both
the reset bit (WDE), and the interrupt bit (WDIE).
static __inline__ This will ensure that if the interrupt is not serviced
__attribute__( ( __always_inline__ ) ) before the second timeout, the AVR will reset.
void wdt_interrupt_reset_enable( const uint8_t value )
{ Servicing the interrupt automatically clears it,
if( _SFR_IO_REG_P( _WD_CONTROL_REG ) ) 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))
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"in __tmp_reg__,__SREG__" "\n\t" "in __tmp_reg__,__SREG__" "\n\t"
@ -170,10 +169,10 @@ extern volatile TCB_t * volatile pxCurrentTCB;
"out __SREG__,__tmp_reg__" "\n\t" "out __SREG__,__tmp_reg__" "\n\t"
"out %0, %2" "\n\t" "out %0, %2" "\n\t"
: /* no outputs */ : /* no outputs */
: "I" ( _SFR_IO_ADDR( _WD_CONTROL_REG ) ), : "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)),
"r" ( ( uint8_t ) ( _BV( _WD_CHANGE_BIT ) | _BV( WDE ) ) ), "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),
"r" ( ( uint8_t ) ( ( value & 0x08 ? _WD_PS3_MASK : 0x00 ) | "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) |
_BV( WDIF ) | _BV( WDIE ) | _BV( WDE ) | ( value & 0x07 ) ) ) _BV(WDIF) | _BV(WDIE) | _BV(WDE) | (value & 0x07)) )
: "r0" : "r0"
); );
} }
@ -187,15 +186,15 @@ extern volatile TCB_t * volatile pxCurrentTCB;
"out __SREG__,__tmp_reg__" "\n\t" "out __SREG__,__tmp_reg__" "\n\t"
"sts %0, %2" "\n\t" "sts %0, %2" "\n\t"
: /* no outputs */ : /* no outputs */
: "n" ( _SFR_MEM_ADDR( _WD_CONTROL_REG ) ), : "n" (_SFR_MEM_ADDR(_WD_CONTROL_REG)),
"r" ( ( uint8_t ) ( _BV( _WD_CHANGE_BIT ) | _BV( WDE ) ) ), "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),
"r" ( ( uint8_t ) ( ( value & 0x08 ? _WD_PS3_MASK : 0x00 ) | "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) |
_BV( WDIF ) | _BV( WDIE ) | _BV( WDE ) | ( value & 0x07 ) ) ) _BV(WDIF) | _BV(WDIE) | _BV(WDE) | (value & 0x07)) )
: "r0" : "r0"
); );
} }
} }
#endif /* if defined( portUSE_WDTO ) */ #endif
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -224,9 +223,9 @@ extern volatile TCB_t * volatile pxCurrentTCB;
* The interrupts will have been disabled during the call to portSAVE_CONTEXT() * The interrupts will have been disabled during the call to portSAVE_CONTEXT()
* so we need not worry about reading/writing to the stack pointer. * 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 */ /* 3-Byte PC Save with RAMPZ */
#define portSAVE_CONTEXT() \ #define portSAVE_CONTEXT() \
__asm__ __volatile__ ( "push __tmp_reg__ \n\t" \ __asm__ __volatile__ ( "push __tmp_reg__ \n\t" \
"in __tmp_reg__, __SREG__ \n\t" \ "in __tmp_reg__, __SREG__ \n\t" \
"cli \n\t" \ "cli \n\t" \
@ -274,9 +273,9 @@ extern volatile TCB_t * volatile pxCurrentTCB;
"in __tmp_reg__, __SP_H__ \n\t" \ "in __tmp_reg__, __SP_H__ \n\t" \
"st x+, __tmp_reg__ \n\t" \ "st x+, __tmp_reg__ \n\t" \
); );
#elif defined( __AVR_HAVE_RAMPZ__ ) #elif defined(__AVR_HAVE_RAMPZ__)
/* 2-Byte PC Save with RAMPZ */ /* 2-Byte PC Save with RAMPZ */
#define portSAVE_CONTEXT() \ #define portSAVE_CONTEXT() \
__asm__ __volatile__ ( "push __tmp_reg__ \n\t" \ __asm__ __volatile__ ( "push __tmp_reg__ \n\t" \
"in __tmp_reg__, __SREG__ \n\t" \ "in __tmp_reg__, __SREG__ \n\t" \
"cli \n\t" \ "cli \n\t" \
@ -322,9 +321,9 @@ extern volatile TCB_t * volatile pxCurrentTCB;
"in __tmp_reg__, __SP_H__ \n\t" \ "in __tmp_reg__, __SP_H__ \n\t" \
"st x+, __tmp_reg__ \n\t" \ "st x+, __tmp_reg__ \n\t" \
); );
#else /* if defined( __AVR_3_BYTE_PC__ ) && defined( __AVR_HAVE_RAMPZ__ ) */ #else
/* 2-Byte PC Save */ /* 2-Byte PC Save */
#define portSAVE_CONTEXT() \ #define portSAVE_CONTEXT() \
__asm__ __volatile__ ( "push __tmp_reg__ \n\t" \ __asm__ __volatile__ ( "push __tmp_reg__ \n\t" \
"in __tmp_reg__, __SREG__ \n\t" \ "in __tmp_reg__, __SREG__ \n\t" \
"cli \n\t" \ "cli \n\t" \
@ -368,15 +367,15 @@ extern volatile TCB_t * volatile pxCurrentTCB;
"in __tmp_reg__, __SP_H__ \n\t" \ "in __tmp_reg__, __SP_H__ \n\t" \
"st x+, __tmp_reg__ \n\t" \ "st x+, __tmp_reg__ \n\t" \
); );
#endif /* if defined( __AVR_3_BYTE_PC__ ) && defined( __AVR_HAVE_RAMPZ__ ) */ #endif
/* /*
* Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during * Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during
* the context save so we can write to the stack pointer. * 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 */ /* 3-Byte PC Restore with RAMPZ */
#define portRESTORE_CONTEXT() \ #define portRESTORE_CONTEXT() \
__asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \ __asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \
"lds r27, pxCurrentTCB + 1 \n\t" \ "lds r27, pxCurrentTCB + 1 \n\t" \
"ld r28, x+ \n\t" \ "ld r28, x+ \n\t" \
@ -422,9 +421,9 @@ extern volatile TCB_t * volatile pxCurrentTCB;
"out __SREG__, __tmp_reg__ \n\t" \ "out __SREG__, __tmp_reg__ \n\t" \
"pop __tmp_reg__ \n\t" \ "pop __tmp_reg__ \n\t" \
); );
#elif defined( __AVR_HAVE_RAMPZ__ ) #elif defined(__AVR_HAVE_RAMPZ__)
/* 2-Byte PC Restore with RAMPZ */ /* 2-Byte PC Restore with RAMPZ */
#define portRESTORE_CONTEXT() \ #define portRESTORE_CONTEXT() \
__asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \ __asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \
"lds r27, pxCurrentTCB + 1 \n\t" \ "lds r27, pxCurrentTCB + 1 \n\t" \
"ld r28, x+ \n\t" \ "ld r28, x+ \n\t" \
@ -468,9 +467,9 @@ extern volatile TCB_t * volatile pxCurrentTCB;
"out __SREG__, __tmp_reg__ \n\t" \ "out __SREG__, __tmp_reg__ \n\t" \
"pop __tmp_reg__ \n\t" \ "pop __tmp_reg__ \n\t" \
); );
#else /* if defined( __AVR_3_BYTE_PC__ ) && defined( __AVR_HAVE_RAMPZ__ ) */ #else
/* 2-Byte PC Restore */ /* 2-Byte PC Restore */
#define portRESTORE_CONTEXT() \ #define portRESTORE_CONTEXT() \
__asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \ __asm__ __volatile__ ( "lds r26, pxCurrentTCB \n\t" \
"lds r27, pxCurrentTCB + 1 \n\t" \ "lds r27, pxCurrentTCB + 1 \n\t" \
"ld r28, x+ \n\t" \ "ld r28, x+ \n\t" \
@ -512,7 +511,7 @@ extern volatile TCB_t * volatile pxCurrentTCB;
"out __SREG__, __tmp_reg__ \n\t" \ "out __SREG__, __tmp_reg__ \n\t" \
"pop __tmp_reg__ \n\t" \ "pop __tmp_reg__ \n\t" \
); );
#endif /* if defined( __AVR_3_BYTE_PC__ ) && defined( __AVR_HAVE_RAMPZ__ ) */ #endif
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* /*
@ -524,17 +523,14 @@ static void prvSetupTimerInterrupt( void );
/* /*
* See header file for description. * See header file for description.
*/ */
StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
TaskFunction_t pxCode,
void * pvParameters )
{ {
uint16_t usAddress; uint16_t usAddress;
/* Simulate how the stack would look after a call to vPortYield() generated by /* 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 /* 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; usAddress = ( uint16_t ) pxCode;
*pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff ); *pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
pxTopOfStack--; pxTopOfStack--;
@ -543,8 +539,7 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
*pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff ); *pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
pxTopOfStack--; pxTopOfStack--;
#if defined( __AVR_3_BYTE_PC__ ) #if defined(__AVR_3_BYTE_PC__)
/* The AVR ATmega2560/ATmega2561 have 256KBytes of program memory and a 17-bit /* 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 * program counter. When a code address is stored on the stack, it takes 3 bytes
* instead of 2 for the other ATmega* chips. * instead of 2 for the other ATmega* chips.
@ -557,34 +552,32 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
*/ */
*pxTopOfStack = 0; *pxTopOfStack = 0;
pxTopOfStack--; pxTopOfStack--;
#endif #endif
/* Next simulate the stack as if after a call to portSAVE_CONTEXT(). /* Next simulate the stack as if after a call to portSAVE_CONTEXT().
* portSAVE_CONTEXT places the flags on the stack immediately after 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 to ensure the interrupts get disabled as soon as possible, and so ensuring
* the stack use is minimal should a context switch interrupt occur. */ the stack use is minimal should a context switch interrupt occur. */
*pxTopOfStack = ( StackType_t ) 0x00; /* R0 */ *pxTopOfStack = ( StackType_t ) 0x00; /* R0 */
pxTopOfStack--; pxTopOfStack--;
*pxTopOfStack = portFLAGS_INT_ENABLED; *pxTopOfStack = portFLAGS_INT_ENABLED;
pxTopOfStack--; 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. /* If we have an ATmega256x, we are also saving the EIND register.
* We should default to 0. * We should default to 0.
*/ */
*pxTopOfStack = ( StackType_t ) 0x00; /* EIND */ *pxTopOfStack = ( StackType_t ) 0x00; /* EIND */
pxTopOfStack--; pxTopOfStack--;
#endif #endif
#if defined( __AVR_HAVE_RAMPZ__ )
#if defined(__AVR_HAVE_RAMPZ__)
/* We are saving the RAMPZ register. /* We are saving the RAMPZ register.
* We should default to 0. * We should default to 0.
*/ */
*pxTopOfStack = ( StackType_t ) 0x00; /* RAMPZ */ *pxTopOfStack = ( StackType_t ) 0x00; /* RAMPZ */
pxTopOfStack--; pxTopOfStack--;
#endif #endif
/* Now the remaining registers. The compiler expects R1 to be 0. */ /* Now the remaining registers. The compiler expects R1 to be 0. */
*pxTopOfStack = ( StackType_t ) 0x00; /* R1 */ *pxTopOfStack = ( StackType_t ) 0x00; /* R1 */
@ -616,7 +609,7 @@ BaseType_t xPortStartScheduler( void )
portRESTORE_CONTEXT(); portRESTORE_CONTEXT();
/* Simulate a function call end as generated by the compiler. We will now /* 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" ); __asm__ __volatile__ ( "ret" );
/* Should not get here. */ /* Should not get here. */
@ -634,7 +627,7 @@ void vPortEndScheduler( void )
* Manual context switch. The first thing we do is save the registers so we * Manual context switch. The first thing we do is save the registers so we
* can use a naked attribute. * can use a naked attribute.
*/ */
void vPortYield( void ) __attribute__( ( hot, flatten, naked ) ); void vPortYield( void ) __attribute__ ( ( hot, flatten, naked ) );
void vPortYield( void ) void vPortYield( void )
{ {
portSAVE_CONTEXT(); portSAVE_CONTEXT();
@ -649,8 +642,8 @@ void vPortYield( void )
* Manual context switch callable from ISRs. The first thing we do is save * Manual context switch callable from ISRs. The first thing we do is save
* the registers so we can use a naked attribute. * the registers so we can use a naked attribute.
*/ */
void vPortYieldFromISR( void ) __attribute__( ( hot, flatten, naked ) ); void vPortYieldFromISR(void) __attribute__ ( ( hot, flatten, naked ) );
void vPortYieldFromISR( void ) void vPortYieldFromISR(void)
{ {
portSAVE_CONTEXT(); portSAVE_CONTEXT();
vTaskSwitchContext(); vTaskSwitchContext();
@ -666,48 +659,44 @@ void vPortYieldFromISR( void )
* difference from vPortYield() is the tick count is incremented as the * difference from vPortYield() is the tick count is incremented as the
* call comes from the tick ISR. * call comes from the tick ISR.
*/ */
void vPortYieldFromTick( void ) __attribute__( ( hot, flatten, naked ) ); void vPortYieldFromTick( void ) __attribute__ ( ( hot, flatten, naked ) );
void vPortYieldFromTick( void ) void vPortYieldFromTick( void )
{ {
portSAVE_CONTEXT(); portSAVE_CONTEXT();
if( xTaskIncrementTick() != pdFALSE ) if( xTaskIncrementTick() != pdFALSE )
{ {
vTaskSwitchContext(); vTaskSwitchContext();
} }
portRESTORE_CONTEXT(); portRESTORE_CONTEXT();
__asm__ __volatile__ ( "ret" ); __asm__ __volatile__ ( "ret" );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if defined( portUSE_WDTO ) #if defined(portUSE_WDTO)
/* /*
* Setup WDT to generate a tick interrupt. * Setup WDT to generate a tick interrupt.
*/ */
void prvSetupTimerInterrupt( void ) void prvSetupTimerInterrupt( void )
{ {
/* reset watchdog */ /* reset watchdog */
wdt_reset(); wdt_reset();
/* set up WDT Interrupt (rather than the WDT Reset). */ /* set up WDT Interrupt (rather than the WDT Reset). */
wdt_interrupt_enable( portUSE_WDTO ); wdt_interrupt_enable( portUSE_WDTO );
} }
#elif defined( portUSE_TIMER0 )
#elif defined (portUSE_TIMER0)
/* /*
* Setup Timer0 compare match A to generate a tick interrupt. * Setup Timer0 compare match A to generate a tick interrupt.
*/ */
static void prvSetupTimerInterrupt( void ) static void prvSetupTimerInterrupt( void )
{ {
uint32_t ulCompareMatch; uint32_t ulCompareMatch;
uint8_t ucLowByte; uint8_t ucLowByte;
/* Using 8bit Timer0 to generate the tick. Correct fuses must be /* Using 8bit Timer0 to generate the tick. Correct fuses must be
* selected for the configCPU_CLOCK_HZ clock.*/ selected for the configCPU_CLOCK_HZ clock.*/
ulCompareMatch = configCPU_CLOCK_HZ / configTICK_RATE_HZ; ulCompareMatch = configCPU_CLOCK_HZ / configTICK_RATE_HZ;
@ -718,7 +707,7 @@ void vPortYieldFromTick( void )
ulCompareMatch -= ( uint32_t ) 1; ulCompareMatch -= ( uint32_t ) 1;
/* Setup compare match value for compare match A. Interrupts are disabled /* Setup compare match value for compare match A. Interrupts are disabled
* before this is called so we need not worry here. */ before this is called so we need not worry here. */
ucLowByte = ( uint8_t ) ( ulCompareMatch & ( uint32_t ) 0xff ); ucLowByte = ( uint8_t ) ( ulCompareMatch & ( uint32_t ) 0xff );
portOCRL = ucLowByte; portOCRL = ucLowByte;
@ -731,15 +720,15 @@ void vPortYieldFromTick( void )
ucLowByte = portTIMSK; ucLowByte = portTIMSK;
ucLowByte |= portCOMPARE_MATCH_A_INTERRUPT_ENABLE; ucLowByte |= portCOMPARE_MATCH_A_INTERRUPT_ENABLE;
portTIMSK = ucLowByte; portTIMSK = ucLowByte;
} }
#endif /* if defined( portUSE_WDTO ) */ #endif
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if configUSE_PREEMPTION == 1 #if configUSE_PREEMPTION == 1
/* /*
* Tick ISR for preemptive scheduler. We can use a naked attribute as * Tick ISR for preemptive scheduler. We can use a naked attribute as
* the context is saved at the start of vPortYieldFromTick(). The tick * the context is saved at the start of vPortYieldFromTick(). The tick
* count is incremented after the context is saved. * count is incremented after the context is saved.
@ -747,30 +736,30 @@ void vPortYieldFromTick( void )
* use ISR_NOBLOCK where there is an important timer running, that should preempt the scheduler. * 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) __attribute__ ((hot, flatten));
/* ISR(portSCHEDULER_ISR, ISR_NAKED ISR_NOBLOCK) __attribute__ ((hot, flatten)); /* ISR(portSCHEDULER_ISR, ISR_NAKED ISR_NOBLOCK) __attribute__ ((hot, flatten));
*/ */
ISR( portSCHEDULER_ISR ) ISR(portSCHEDULER_ISR)
{ {
vPortYieldFromTick(); vPortYieldFromTick();
__asm__ __volatile__ ( "reti" ); __asm__ __volatile__ ( "reti" );
} }
#else /* if configUSE_PREEMPTION == 1 */ #else
/* /*
* Tick ISR for the cooperative scheduler. All this does is increment the * 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 * tick count. We don't need to switch context, this can only be done by
* manual calls to taskYIELD(); * manual calls to taskYIELD();
* *
* use ISR_NOBLOCK where there is an important timer running, that should preempt the scheduler. * use ISR_NOBLOCK where there is an important timer running, that should preempt the scheduler.
*/ */
ISR( portSCHEDULER_ISR ) __attribute__( ( hot, flatten ) ); ISR(portSCHEDULER_ISR) __attribute__ ((hot, flatten));
/* ISR(portSCHEDULER_ISR, ISR_NOBLOCK) __attribute__ ((hot, flatten)); /* ISR(portSCHEDULER_ISR, ISR_NOBLOCK) __attribute__ ((hot, flatten));
*/ */
ISR( portSCHEDULER_ISR ) ISR(portSCHEDULER_ISR)
{ {
xTaskIncrementTick(); xTaskIncrementTick();
} }
#endif /* if configUSE_PREEMPTION == 1 */ #endif

View file

@ -23,14 +23,14 @@
* http://aws.amazon.com/freertos * http://aws.amazon.com/freertos
* *
* 1 tab == 4 spaces! * 1 tab == 4 spaces!
*/ */
#ifndef PORTMACRO_H #ifndef PORTMACRO_H
#define PORTMACRO_H #define PORTMACRO_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/*----------------------------------------------------------- /*-----------------------------------------------------------
* Port specific definitions. * Port specific definitions.
@ -42,32 +42,31 @@
*----------------------------------------------------------- *-----------------------------------------------------------
*/ */
#include <avr/wdt.h> #include <avr/wdt.h>
/* Type definitions. */ /* Type definitions. */
#define portCHAR char #define portCHAR char
#define portFLOAT float #define portFLOAT float
#define portDOUBLE double #define portDOUBLE double
#define portLONG long #define portLONG long
#define portSHORT int #define portSHORT int
typedef uint8_t StackType_t; typedef uint8_t StackType_t;
typedef int8_t BaseType_t; typedef int8_t BaseType_t;
typedef uint8_t UBaseType_t; typedef uint8_t UBaseType_t;
#if configUSE_16_BIT_TICKS == 1 #if configUSE_16_BIT_TICKS == 1
typedef uint16_t TickType_t; typedef uint16_t TickType_t;
#define portMAX_DELAY ( TickType_t ) 0xffff #define portMAX_DELAY ( TickType_t ) 0xffff
#else #else
typedef uint32_t TickType_t; typedef uint32_t TickType_t;
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
#endif #endif
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Critical section management. */ /* Critical section management. */
#define portENTER_CRITICAL() \ #define portENTER_CRITICAL() __asm__ __volatile__ ( \
__asm__ __volatile__ ( \
"in __tmp_reg__, __SREG__" "\n\t" \ "in __tmp_reg__, __SREG__" "\n\t" \
"cli" "\n\t" \ "cli" "\n\t" \
"push __tmp_reg__" "\n\t" \ "push __tmp_reg__" "\n\t" \
@ -75,16 +74,15 @@
) )
#define portEXIT_CRITICAL() \ #define portEXIT_CRITICAL() __asm__ __volatile__ ( \
__asm__ __volatile__ ( \
"pop __tmp_reg__" "\n\t" \ "pop __tmp_reg__" "\n\t" \
"out __SREG__, __tmp_reg__" "\n\t" \ "out __SREG__, __tmp_reg__" "\n\t" \
::: "memory" \ ::: "memory" \
) )
#define portDISABLE_INTERRUPTS() __asm__ __volatile__ ( "cli" ::: "memory" ) #define portDISABLE_INTERRUPTS() __asm__ __volatile__ ( "cli" ::: "memory")
#define portENABLE_INTERRUPTS() __asm__ __volatile__ ( "sei" ::: "memory" ) #define portENABLE_INTERRUPTS() __asm__ __volatile__ ( "sei" ::: "memory")
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Architecture specifics. */ /* Architecture specifics. */
@ -93,66 +91,66 @@
* Prefer to use the enhanced Watchdog Timer, but also Timer0 is ok. * 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 /* Watchdog period options: WDTO_15MS
* WDTO_30MS WDTO_30MS
* WDTO_60MS WDTO_60MS
* WDTO_120MS WDTO_120MS
* WDTO_250MS WDTO_250MS
* WDTO_500MS WDTO_500MS
* WDTO_1S WDTO_1S
* WDTO_2S 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. /* Timing for the scheduler.
* Watchdog Timer is 128kHz nominal, * Watchdog Timer is 128kHz nominal,
* but 120 kHz at 5V DC and 25 degrees is actually more accurate, * but 120 kHz at 5V DC and 25 degrees is actually more accurate,
* from data sheet. * from data sheet.
*/ */
#if defined( portUSE_WDTO ) #if defined( portUSE_WDTO )
#define portTICK_PERIOD_MS ( ( TickType_t ) _BV( portUSE_WDTO + 4 ) ) #define portTICK_PERIOD_MS ( (TickType_t) _BV( portUSE_WDTO + 4 ) )
#else #else
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) #define portTICK_PERIOD_MS ( (TickType_t) 1000 / configTICK_RATE_HZ )
#endif #endif
#define portBYTE_ALIGNMENT 1 #define portBYTE_ALIGNMENT 1
#define portNOP() __asm__ __volatile__ ( "nop" ); #define portNOP() __asm__ __volatile__ ( "nop" );
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Kernel utilities. */ /* Kernel utilities. */
extern void vPortYield( void ) __attribute__( ( naked ) ); extern void vPortYield( void ) __attribute__ ( ( naked ) );
#define portYIELD() vPortYield() #define portYIELD() vPortYield()
extern void vPortYieldFromISR( void ) __attribute__( ( naked ) ); extern void vPortYieldFromISR( void ) __attribute__ ( ( naked ) );
#define portYIELD_FROM_ISR() vPortYieldFromISR() #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. */ /* 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 /* Add .lowtext tag from the avr linker script avr6.x for ATmega2560 and ATmega2561
* to make sure functions are loaded in low memory. * to make sure functions are loaded in low memory.
*/ */
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) __attribute__( ( section( ".lowtext" ) ) ) #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__ ((section (".lowtext")))
#else #else
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
#endif #endif
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* PORTMACRO_H */ #endif /* PORTMACRO_H */

View file

@ -26,31 +26,31 @@
*/ */
/*----------------------------------------------------------- /*-----------------------------------------------------------
* Implementation of functions defined in portable.h for the Posix port. * Implementation of functions defined in portable.h for the Posix port.
* *
* Each task has a pthread which eases use of standard debuggers * Each task has a pthread which eases use of standard debuggers
* (allowing backtraces of tasks etc). Threads for tasks that are not * (allowing backtraces of tasks etc). Threads for tasks that are not
* running are blocked in sigwait(). * running are blocked in sigwait().
* *
* Task switch is done by resuming the thread for the next task by * Task switch is done by resuming the thread for the next task by
* sending it the resume signal (SIGUSR1) and then suspending the * sending it the resume signal (SIGUSR1) and then suspending the
* current thread. * current thread.
* *
* The timer interrupt uses SIGALRM and care is taken to ensure that * The timer interrupt uses SIGALRM and care is taken to ensure that
* the signal handler runs only on the thread for the current task. * the signal handler runs only on the thread for the current task.
* *
* Use of part of the standard C library requires care as some * Use of part of the standard C library requires care as some
* functions can take pthread mutexes internally which can result in * functions can take pthread mutexes internally which can result in
* deadlocks as the FreeRTOS kernel can switch tasks while they're * deadlocks as the FreeRTOS kernel can switch tasks while they're
* holding a pthread mutex. * holding a pthread mutex.
* *
* Replacement malloc(), free(), calloc(), and realloc() are provided * Replacement malloc(), free(), calloc(), and realloc() are provided
* for glibc (see below for more information). * for glibc (see below for more information).
* *
* stdio (printf() and friends) should be called from a single task * stdio (printf() and friends) should be called from a single task
* only or serialized with a FreeRTOS primitive such as a binary * only or serialized with a FreeRTOS primitive such as a binary
* semaphore or mutex. * semaphore or mutex.
*----------------------------------------------------------*/ *----------------------------------------------------------*/
#include <errno.h> #include <errno.h>
#include <pthread.h> #include <pthread.h>
@ -73,7 +73,7 @@ typedef struct THREAD
{ {
pthread_t pthread; pthread_t pthread;
pdTASK_CODE pxCode; pdTASK_CODE pxCode;
void * pvParams; void *pvParams;
BaseType_t xDying; BaseType_t xDying;
} Thread_t; } Thread_t;
@ -81,11 +81,11 @@ typedef struct THREAD
* The additional per-thread data is stored at the beginning of the * The additional per-thread data is stored at the beginning of the
* task's stack. * 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 xResumeSignals;
static sigset_t xAllSignals; static sigset_t xAllSignals;
static sigset_t xSchedulerOriginalSignalMask; static sigset_t xSchedulerOriginalSignalMask;
static pthread_t hMainThread = ( pthread_t ) NULL; static pthread_t hMainThread = ( pthread_t )NULL;
static volatile portBASE_TYPE uxCriticalNesting; static volatile portBASE_TYPE uxCriticalNesting;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -103,9 +103,8 @@ static portBASE_TYPE xSchedulerEnd = pdFALSE;
static void prvSetupSignalsAndSchedulerPolicy( void ); static void prvSetupSignalsAndSchedulerPolicy( void );
static void prvSetupTimerInterrupt( void ); static void prvSetupTimerInterrupt( void );
static void * prvWaitForStart( void * pvParams ); static void *prvWaitForStart( void * pvParams );
static void prvSwitchThread( Thread_t * xThreadToResume, static void prvSwitchThread( Thread_t *xThreadToResume, Thread_t *xThreadToSuspend );
Thread_t * xThreadToSuspend );
static void prvSuspendSelf( void ); static void prvSuspendSelf( void );
static void prvResumeThread( pthread_t xThreadId ); static void prvResumeThread( pthread_t xThreadId );
static void vPortSystemTickHandler( int sig ); static void vPortSystemTickHandler( int sig );
@ -132,17 +131,15 @@ static void vPortStartFirstTask( void );
* timer (SIGALRM) and other signals. * timer (SIGALRM) and other signals.
*/ */
extern void * __libc_malloc( size_t ); extern void *__libc_malloc(size_t);
extern void __libc_free( void * ); extern void __libc_free(void *);
extern void * __libc_calloc( size_t, extern void *__libc_calloc(size_t, size_t);
size_t ); extern void *__libc_realloc(void *ptr, size_t);
extern void * __libc_realloc( void * ptr,
size_t );
void * malloc( size_t size ) void *malloc(size_t size)
{ {
sigset_t xSavedSignals; sigset_t xSavedSignals;
void * ptr; void *ptr;
pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals );
ptr = __libc_malloc( size ); ptr = __libc_malloc( size );
@ -151,20 +148,19 @@ void * malloc( size_t size )
return ptr; return ptr;
} }
void free( void * ptr ) void free(void *ptr)
{ {
sigset_t xSavedSignals; sigset_t xSavedSignals;
pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals );
__libc_free( ptr ); __libc_free( ptr );
pthread_sigmask( SIG_SETMASK, &xSavedSignals, NULL ); pthread_sigmask( SIG_SETMASK, &xSavedSignals, NULL );
} }
void * calloc( size_t nmemb, void *calloc(size_t nmemb, size_t size)
size_t size )
{ {
sigset_t xSavedSignals; sigset_t xSavedSignals;
void * ptr; void *ptr;
pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals );
ptr = __libc_calloc( nmemb, size ); ptr = __libc_calloc( nmemb, size );
@ -173,10 +169,9 @@ void * calloc( size_t nmemb,
return ptr; return ptr;
} }
void * realloc( void * ptr, void *realloc(void *ptr, size_t size)
size_t size )
{ {
sigset_t xSavedSignals; sigset_t xSavedSignals;
pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals ); pthread_sigmask( SIG_BLOCK, &xAllSignals, &xSavedSignals );
ptr = __libc_realloc( ptr, size ); ptr = __libc_realloc( ptr, size );
@ -185,8 +180,7 @@ void * realloc( void * ptr,
return ptr; return ptr;
} }
static void prvFatalError( const char * pcCall, static void prvFatalError( const char *pcCall, int iErrno )
int iErrno )
{ {
fprintf( stderr, "%s: %s\n", pcCall, strerror( iErrno ) ); fprintf( stderr, "%s: %s\n", pcCall, strerror( iErrno ) );
abort(); abort();
@ -195,24 +189,23 @@ static void prvFatalError( const char * pcCall,
/* /*
* See header file for description. * See header file for description.
*/ */
portSTACK_TYPE * pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack,
portSTACK_TYPE * pxEndOfStack, portSTACK_TYPE *pxEndOfStack,
pdTASK_CODE pxCode, pdTASK_CODE pxCode, void *pvParameters )
void * pvParameters )
{ {
Thread_t * thread; Thread_t *thread;
pthread_attr_t xThreadAttributes; pthread_attr_t xThreadAttributes;
size_t ulStackSize; size_t ulStackSize;
int iRet; int iRet;
( void ) pthread_once( &hSigSetupThread, prvSetupSignalsAndSchedulerPolicy ); (void)pthread_once( &hSigSetupThread, prvSetupSignalsAndSchedulerPolicy );
/* /*
* Store the additional thread data at the start of the stack. * Store the additional thread data at the start of the stack.
*/ */
thread = ( Thread_t * ) ( pxTopOfStack + 1 ) - 1; thread = (Thread_t *)(pxTopOfStack + 1) - 1;
pxTopOfStack = ( portSTACK_TYPE * ) thread - 1; pxTopOfStack = (portSTACK_TYPE *)thread - 1;
ulStackSize = ( pxTopOfStack + 1 - pxEndOfStack ) * sizeof( *pxTopOfStack ); ulStackSize = (pxTopOfStack + 1 - pxEndOfStack) * sizeof(*pxTopOfStack);
thread->pxCode = pxCode; thread->pxCode = pxCode;
thread->pvParams = pvParameters; thread->pvParams = pvParameters;
@ -225,8 +218,7 @@ portSTACK_TYPE * pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack,
iRet = pthread_create( &thread->pthread, &xThreadAttributes, iRet = pthread_create( &thread->pthread, &xThreadAttributes,
prvWaitForStart, thread ); prvWaitForStart, thread );
if ( iRet )
if( iRet )
{ {
prvFatalError( "pthread_create", iRet ); prvFatalError( "pthread_create", iRet );
} }
@ -239,7 +231,7 @@ portSTACK_TYPE * pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack,
void vPortStartFirstTask( void ) void vPortStartFirstTask( void )
{ {
Thread_t * pxFirstThread = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); Thread_t *pxFirstThread = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() );
/* Start the first task. */ /* Start the first task. */
prvResumeThread( pxFirstThread->pthread ); prvResumeThread( pxFirstThread->pthread );
@ -251,13 +243,13 @@ void vPortStartFirstTask( void )
*/ */
portBASE_TYPE xPortStartScheduler( void ) portBASE_TYPE xPortStartScheduler( void )
{ {
int iSignal; int iSignal;
sigset_t xSignals; sigset_t xSignals;
hMainThread = pthread_self(); hMainThread = pthread_self();
/* Start the timer that generates the tick ISR. Interrupts are disabled /* Start the timer that generates the tick ISR. Interrupts are disabled
* here already. */ here already. */
prvSetupTimerInterrupt(); prvSetupTimerInterrupt();
/* Start the first task. */ /* Start the first task. */
@ -267,13 +259,13 @@ portBASE_TYPE xPortStartScheduler( void )
sigemptyset( &xSignals ); sigemptyset( &xSignals );
sigaddset( &xSignals, SIG_RESUME ); sigaddset( &xSignals, SIG_RESUME );
while( !xSchedulerEnd ) while ( !xSchedulerEnd )
{ {
sigwait( &xSignals, &iSignal ); sigwait( &xSignals, &iSignal );
} }
/* Restore original signal mask. */ /* Restore original signal mask. */
( void ) pthread_sigmask( SIG_SETMASK, &xSchedulerOriginalSignalMask, NULL ); (void)pthread_sigmask( SIG_SETMASK, &xSchedulerOriginalSignalMask, NULL );
return 0; return 0;
} }
@ -281,8 +273,8 @@ portBASE_TYPE xPortStartScheduler( void )
void vPortEndScheduler( void ) void vPortEndScheduler( void )
{ {
struct itimerval itimer; struct itimerval itimer;
struct sigaction sigtick; struct sigaction sigtick;
/* Stop the timer and ignore any pending SIGALRMs that would end /* Stop the timer and ignore any pending SIGALRMs that would end
* up running on the main thread when it is resumed. */ * up running on the main thread when it is resumed. */
@ -291,7 +283,7 @@ void vPortEndScheduler( void )
itimer.it_interval.tv_sec = 0; itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 0; itimer.it_interval.tv_usec = 0;
( void ) setitimer( ITIMER_REAL, &itimer, NULL ); (void)setitimer( ITIMER_REAL, &itimer, NULL );
sigtick.sa_flags = 0; sigtick.sa_flags = 0;
sigtick.sa_handler = SIG_IGN; sigtick.sa_handler = SIG_IGN;
@ -300,7 +292,7 @@ void vPortEndScheduler( void )
/* Signal the scheduler to exit its loop. */ /* Signal the scheduler to exit its loop. */
xSchedulerEnd = pdTRUE; xSchedulerEnd = pdTRUE;
( void ) pthread_kill( hMainThread, SIG_RESUME ); (void)pthread_kill( hMainThread, SIG_RESUME );
prvSuspendSelf(); prvSuspendSelf();
} }
@ -308,11 +300,10 @@ void vPortEndScheduler( void )
void vPortEnterCritical( void ) void vPortEnterCritical( void )
{ {
if( uxCriticalNesting == 0 ) if ( uxCriticalNesting == 0 )
{ {
vPortDisableInterrupts(); vPortDisableInterrupts();
} }
uxCriticalNesting++; uxCriticalNesting++;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -331,8 +322,8 @@ void vPortExitCritical( void )
void vPortYieldFromISR( void ) void vPortYieldFromISR( void )
{ {
Thread_t * xThreadToSuspend; Thread_t *xThreadToSuspend;
Thread_t * xThreadToResume; Thread_t *xThreadToResume;
xThreadToSuspend = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); xThreadToSuspend = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() );
@ -369,7 +360,7 @@ void vPortEnableInterrupts( void )
portBASE_TYPE xPortSetInterruptMask( void ) portBASE_TYPE xPortSetInterruptMask( void )
{ {
/* Interrupts are always disabled inside ISRs (signals /* Interrupts are always disabled inside ISRs (signals
* handlers). */ handlers). */
return pdTRUE; return pdTRUE;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -379,11 +370,11 @@ 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;
} }
@ -397,13 +388,12 @@ static uint64_t prvTickCount;
*/ */
void prvSetupTimerInterrupt( void ) void prvSetupTimerInterrupt( void )
{ {
struct itimerval itimer; struct itimerval itimer;
int iRet; int iRet;
/* Initialise the structure with the current timer information. */ /* Initialise the structure with the current timer information. */
iRet = getitimer( ITIMER_REAL, &itimer ); iRet = getitimer( ITIMER_REAL, &itimer );
if ( iRet )
if( iRet )
{ {
prvFatalError( "getitimer", errno ); prvFatalError( "getitimer", errno );
} }
@ -418,8 +408,7 @@ void prvSetupTimerInterrupt( void )
/* Set-up the timer interrupt. */ /* Set-up the timer interrupt. */
iRet = setitimer( ITIMER_REAL, &itimer, NULL ); iRet = setitimer( ITIMER_REAL, &itimer, NULL );
if ( iRet )
if( iRet )
{ {
prvFatalError( "setitimer", errno ); prvFatalError( "setitimer", errno );
} }
@ -430,9 +419,9 @@ void prvSetupTimerInterrupt( void )
static void vPortSystemTickHandler( int sig ) static void vPortSystemTickHandler( int sig )
{ {
Thread_t * pxThreadToSuspend; Thread_t *pxThreadToSuspend;
Thread_t * pxThreadToResume; Thread_t *pxThreadToResume;
uint64_t xExpectedTicks; uint64_t xExpectedTicks;
uxCriticalNesting++; /* Signals are blocked in this signal handler. */ uxCriticalNesting++; /* Signals are blocked in this signal handler. */
@ -440,39 +429,36 @@ static void vPortSystemTickHandler( int sig )
/* Tick Increment, accounting for any lost signals or drift in /* Tick Increment, accounting for any lost signals or drift in
* the timer. */ * the timer. */
xExpectedTicks = ( prvGetTimeNs() - prvStartTimeNs ) xExpectedTicks = (prvGetTimeNs() - prvStartTimeNs)
/ ( portTICK_RATE_MICROSECONDS * 1000 ); / (portTICK_RATE_MICROSECONDS * 1000);
do {
do
{
xTaskIncrementTick(); xTaskIncrementTick();
prvTickCount++; prvTickCount++;
} while( prvTickCount < xExpectedTicks ); } while (prvTickCount < xExpectedTicks);
#if ( configUSE_PREEMPTION == 1 ) #if ( configUSE_PREEMPTION == 1 )
/* Select Next Task. */ /* Select Next Task. */
vTaskSwitchContext(); vTaskSwitchContext();
pxThreadToResume = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); pxThreadToResume = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() );
prvSwitchThread( pxThreadToResume, pxThreadToSuspend ); prvSwitchThread(pxThreadToResume, pxThreadToSuspend);
#endif #endif
uxCriticalNesting--; uxCriticalNesting--;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vPortThreadDying( void * pxTaskToDelete, void vPortThreadDying( void *pxTaskToDelete, volatile BaseType_t *pxPendYield )
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 * The thread has already been suspended so it can be safely
@ -483,9 +469,9 @@ void vPortCancelThread( void * pxTaskToDelete )
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void * prvWaitForStart( void * pvParams ) static void *prvWaitForStart( void * pvParams )
{ {
Thread_t * pxThread = pvParams; Thread_t *pxThread = pvParams;
prvSuspendSelf(); prvSuspendSelf();
@ -500,12 +486,12 @@ static void * prvWaitForStart( void * pvParams )
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvSwitchThread( Thread_t * pxThreadToResume, static void prvSwitchThread( Thread_t *pxThreadToResume,
Thread_t * pxThreadToSuspend ) Thread_t *pxThreadToSuspend )
{ {
BaseType_t uxSavedCriticalNesting; BaseType_t uxSavedCriticalNesting;
if( pxThreadToSuspend != pxThreadToResume ) if ( pxThreadToSuspend != pxThreadToResume )
{ {
/* /*
* Switch tasks. * Switch tasks.
@ -517,12 +503,10 @@ static void prvSwitchThread( Thread_t * pxThreadToResume,
uxSavedCriticalNesting = uxCriticalNesting; uxSavedCriticalNesting = uxCriticalNesting;
prvResumeThread( pxThreadToResume->pthread ); prvResumeThread( pxThreadToResume->pthread );
if ( pxThreadToSuspend->xDying )
if( pxThreadToSuspend->xDying )
{ {
pthread_exit( NULL ); pthread_exit( NULL );
} }
prvSuspendSelf(); prvSuspendSelf();
uxCriticalNesting = uxSavedCriticalNesting; uxCriticalNesting = uxSavedCriticalNesting;
@ -532,7 +516,7 @@ static void prvSwitchThread( Thread_t * pxThreadToResume,
static void prvSuspendSelf( void ) static void prvSuspendSelf( void )
{ {
int iSig; int iSig;
/* /*
* Suspend this thread by waiting for a SIG_RESUME signal. * Suspend this thread by waiting for a SIG_RESUME signal.
@ -554,7 +538,7 @@ static void prvSuspendSelf( void )
static void prvResumeThread( pthread_t xThreadId ) static void prvResumeThread( pthread_t xThreadId )
{ {
if( pthread_self() != xThreadId ) if ( pthread_self() != xThreadId )
{ {
pthread_kill( xThreadId, SIG_RESUME ); pthread_kill( xThreadId, SIG_RESUME );
} }
@ -563,8 +547,8 @@ static void prvResumeThread( pthread_t xThreadId )
static void prvSetupSignalsAndSchedulerPolicy( void ) static void prvSetupSignalsAndSchedulerPolicy( void )
{ {
struct sigaction sigresume, sigtick; struct sigaction sigresume, sigtick;
int iRet; int iRet;
hMainThread = pthread_self(); hMainThread = pthread_self();
@ -572,7 +556,6 @@ static void prvSetupSignalsAndSchedulerPolicy( void )
sigemptyset( &xResumeSignals ); sigemptyset( &xResumeSignals );
sigaddset( &xResumeSignals, SIG_RESUME ); sigaddset( &xResumeSignals, SIG_RESUME );
sigfillset( &xAllSignals ); sigfillset( &xAllSignals );
/* Don't block SIGINT so this can be used to break into GDB while /* Don't block SIGINT so this can be used to break into GDB while
* in a critical section. */ * in a critical section. */
sigdelset( &xAllSignals, SIGINT ); sigdelset( &xAllSignals, SIGINT );
@ -584,11 +567,11 @@ static void prvSetupSignalsAndSchedulerPolicy( void )
* When a thread is resumed for the first time, all signals * When a thread is resumed for the first time, all signals
* will be unblocked. * will be unblocked.
*/ */
( void ) pthread_sigmask( SIG_SETMASK, &xAllSignals, (void)pthread_sigmask( SIG_SETMASK, &xAllSignals,
&xSchedulerOriginalSignalMask ); &xSchedulerOriginalSignalMask );
/* SIG_RESUME is only used with sigwait() so doesn't need a /* SIG_RESUME is only used with sigwait() so doesn't need a
* handler. */ handler. */
sigresume.sa_flags = 0; sigresume.sa_flags = 0;
sigresume.sa_handler = SIG_IGN; sigresume.sa_handler = SIG_IGN;
sigfillset( &sigresume.sa_mask ); sigfillset( &sigresume.sa_mask );
@ -598,15 +581,13 @@ static void prvSetupSignalsAndSchedulerPolicy( void )
sigfillset( &sigtick.sa_mask ); sigfillset( &sigtick.sa_mask );
iRet = sigaction( SIG_RESUME, &sigresume, NULL ); iRet = sigaction( SIG_RESUME, &sigresume, NULL );
if ( iRet )
if( iRet )
{ {
prvFatalError( "sigaction", errno ); prvFatalError( "sigaction", errno );
} }
iRet = sigaction( SIGALRM, &sigtick, NULL ); iRet = sigaction( SIGALRM, &sigtick, NULL );
if ( iRet )
if( iRet )
{ {
prvFatalError( "sigaction", errno ); prvFatalError( "sigaction", errno );
} }
@ -615,7 +596,7 @@ static void prvSetupSignalsAndSchedulerPolicy( void )
unsigned long ulPortGetRunTime( void ) unsigned long ulPortGetRunTime( void )
{ {
struct tms xTimes; struct tms xTimes;
times( &xTimes ); times( &xTimes );

View file

@ -27,13 +27,13 @@
#ifndef PORTMACRO_H #ifndef PORTMACRO_H
#define PORTMACRO_H #define PORTMACRO_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <limits.h> #include <limits.h>
/*----------------------------------------------------------- /*-----------------------------------------------------------
* Port specific definitions. * Port specific definitions.
@ -46,72 +46,71 @@
*/ */
/* Type definitions. */ /* Type definitions. */
#define portCHAR char #define portCHAR char
#define portFLOAT float #define portFLOAT float
#define portDOUBLE double #define portDOUBLE double
#define portLONG long #define portLONG long
#define portSHORT short #define portSHORT short
#define portSTACK_TYPE unsigned long #define portSTACK_TYPE unsigned long
#define portBASE_TYPE long #define portBASE_TYPE long
#define portPOINTER_SIZE_TYPE intptr_t #define portPOINTER_SIZE_TYPE intptr_t
typedef portSTACK_TYPE StackType_t; typedef portSTACK_TYPE StackType_t;
typedef long BaseType_t; typedef long BaseType_t;
typedef unsigned long UBaseType_t; typedef unsigned long UBaseType_t;
typedef unsigned long TickType_t; typedef unsigned long TickType_t;
#define portMAX_DELAY ( TickType_t ) ULONG_MAX #define portMAX_DELAY ( TickType_t ) ULONG_MAX
#define portTICK_TYPE_IS_ATOMIC 1 #define portTICK_TYPE_IS_ATOMIC 1
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Architecture specifics. */ /* Architecture specifics. */
#define portSTACK_GROWTH ( -1 ) #define portSTACK_GROWTH ( -1 )
#define portHAS_STACK_OVERFLOW_CHECKING ( 1 ) #define portHAS_STACK_OVERFLOW_CHECKING ( 1 )
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
#define portTICK_RATE_MICROSECONDS ( ( portTickType ) 1000000 / configTICK_RATE_HZ ) #define portTICK_RATE_MICROSECONDS ( ( portTickType ) 1000000 / configTICK_RATE_HZ )
#define portBYTE_ALIGNMENT 8 #define portBYTE_ALIGNMENT 8
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Scheduler utilities. */ /* 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 portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) vPortYield()
#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Critical section management. */ /* Critical section management. */
extern void vPortDisableInterrupts( void ); extern void vPortDisableInterrupts( void );
extern void vPortEnableInterrupts( void ); extern void vPortEnableInterrupts( void );
#define portSET_INTERRUPT_MASK() ( vPortDisableInterrupts() ) #define portSET_INTERRUPT_MASK() ( vPortDisableInterrupts() )
#define portCLEAR_INTERRUPT_MASK() ( vPortEnableInterrupts() ) #define portCLEAR_INTERRUPT_MASK() ( vPortEnableInterrupts() )
extern portBASE_TYPE xPortSetInterruptMask( void ); extern portBASE_TYPE xPortSetInterruptMask( void );
extern void vPortClearInterruptMask( portBASE_TYPE xMask ); extern void vPortClearInterruptMask( portBASE_TYPE xMask );
extern void vPortEnterCritical( void ); extern void vPortEnterCritical( void );
extern void vPortExitCritical( void ); extern void vPortExitCritical( void );
#define portSET_INTERRUPT_MASK_FROM_ISR() xPortSetInterruptMask() #define portSET_INTERRUPT_MASK_FROM_ISR() xPortSetInterruptMask()
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vPortClearInterruptMask( x ) #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vPortClearInterruptMask(x)
#define portDISABLE_INTERRUPTS() portSET_INTERRUPT_MASK() #define portDISABLE_INTERRUPTS() portSET_INTERRUPT_MASK()
#define portENABLE_INTERRUPTS() portCLEAR_INTERRUPT_MASK() #define portENABLE_INTERRUPTS() portCLEAR_INTERRUPT_MASK()
#define portENTER_CRITICAL() vPortEnterCritical() #define portENTER_CRITICAL() vPortEnterCritical()
#define portEXIT_CRITICAL() vPortExitCritical() #define portEXIT_CRITICAL() vPortExitCritical()
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
extern void vPortThreadDying( void * pxTaskToDelete, extern void vPortThreadDying( void *pxTaskToDelete, volatile BaseType_t *pxPendYield );
volatile BaseType_t * pxPendYield ); extern void vPortCancelThread( void *pxTaskToDelete );
extern void vPortCancelThread( void * pxTaskToDelete ); #define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortThreadDying( ( pvTaskToDelete ), ( pxPendYield ) )
#define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortThreadDying( ( pvTaskToDelete ), ( pxPendYield ) ) #define portCLEAN_UP_TCB( pxTCB ) vPortCancelThread( pxTCB )
#define portCLEAN_UP_TCB( pxTCB ) vPortCancelThread( pxTCB )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#define portTASK_FUNCTION_PROTO( 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 ) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* /*
@ -122,14 +121,14 @@
* Thus, only a compilier barrier is needed to prevent the compiler * Thus, only a compilier barrier is needed to prevent the compiler
* reordering. * reordering.
*/ */
#define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" ) #define portMEMORY_BARRIER() __asm volatile( "" ::: "memory" )
extern unsigned long ulPortGetRunTime( void ); extern unsigned long ulPortGetRunTime( void );
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() /* no-op */ #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() /* no-op */
#define portGET_RUN_TIME_COUNTER_VALUE() ulPortGetRunTime() #define portGET_RUN_TIME_COUNTER_VALUE() ulPortGetRunTime()
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* PORTMACRO_H */ #endif /* PORTMACRO_H */