Revert Portable/WizC Formatting (#888)

* Revert formatting on WizC ports

* Fix spelling mistakes

---------

Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
This commit is contained in:
Soren Ptak 2023-11-23 04:04:07 -08:00 committed by GitHub
parent b3febb7416
commit cb196ddbb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 396 additions and 401 deletions

View file

@ -27,22 +27,22 @@
*/ */
/* /*
* Changes from V3.0.0 Changes from V3.0.0
+ ISRcode is pulled inline and portTICKisr() is therefore + ISRcode is pulled inline and portTICKisr() is therefore
+ deleted from this file. deleted from this file.
+
+ Prescaler logic for Timer1 added to allow for a wider + Prescaler logic for Timer1 added to allow for a wider
+ range of TickRates. range of TickRates.
+
+ Changes from V3.0.1 Changes from V3.0.1
*/ */
#include <FreeRTOS.h> #include <FreeRTOS.h>
#include <task.h> #include <task.h>
/* IO port constants. */ /* IO port constants. */
#define portBIT_SET ( 1 ) #define portBIT_SET (1)
#define portBIT_CLEAR ( 0 ) #define portBIT_CLEAR (0)
/* /*
* Hardware setup for the tick. * Hardware setup for the tick.
@ -50,27 +50,27 @@
* and requested tickrate, a prescaled value with a matching * and requested tickrate, a prescaled value with a matching
* prescaler are determined. * prescaler are determined.
*/ */
#define portTIMER_COMPARE_BASE ( ( APROCFREQ / 4 ) / configTICK_RATE_HZ ) #define portTIMER_COMPARE_BASE ((APROCFREQ/4)/configTICK_RATE_HZ)
#if portTIMER_COMPARE_BASE < 0x10000 #if portTIMER_COMPARE_BASE < 0x10000
#define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE ) #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE)
#define portTIMER_COMPARE_PS1 ( portBIT_CLEAR ) #define portTIMER_COMPARE_PS1 (portBIT_CLEAR)
#define portTIMER_COMPARE_PS0 ( portBIT_CLEAR ) #define portTIMER_COMPARE_PS0 (portBIT_CLEAR)
#elif portTIMER_COMPARE_BASE < 0x20000 #elif portTIMER_COMPARE_BASE < 0x20000
#define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE / 2 ) #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 2)
#define portTIMER_COMPARE_PS1 ( portBIT_CLEAR ) #define portTIMER_COMPARE_PS1 (portBIT_CLEAR)
#define portTIMER_COMPARE_PS0 ( portBIT_SET ) #define portTIMER_COMPARE_PS0 (portBIT_SET)
#elif portTIMER_COMPARE_BASE < 0x40000 #elif portTIMER_COMPARE_BASE < 0x40000
#define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE / 4 ) #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 4)
#define portTIMER_COMPARE_PS1 ( portBIT_SET ) #define portTIMER_COMPARE_PS1 (portBIT_SET)
#define portTIMER_COMPARE_PS0 ( portBIT_CLEAR ) #define portTIMER_COMPARE_PS0 (portBIT_CLEAR)
#elif portTIMER_COMPARE_BASE < 0x80000 #elif portTIMER_COMPARE_BASE < 0x80000
#define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE / 8 ) #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 8)
#define portTIMER_COMPARE_PS1 ( portBIT_SET ) #define portTIMER_COMPARE_PS1 (portBIT_SET)
#define portTIMER_COMPARE_PS0 ( portBIT_SET ) #define portTIMER_COMPARE_PS0 (portBIT_SET)
#else /* if portTIMER_COMPARE_BASE < 0x10000 */ #else
#error "TickRate out of range" #error "TickRate out of range"
#endif /* if portTIMER_COMPARE_BASE < 0x10000 */ #endif
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -92,27 +92,27 @@ void portSetupTick( void )
* Set the compare match value. * Set the compare match value.
*/ */
CCPR1H = ( uint8_t ) ( ( portTIMER_COMPARE_VALUE >> 8 ) & 0xff ); CCPR1H = ( uint8_t ) ( ( portTIMER_COMPARE_VALUE >> 8 ) & 0xff );
CCPR1L = ( uint8_t ) ( portTIMER_COMPARE_VALUE & 0xff ); CCPR1L = ( uint8_t ) ( portTIMER_COMPARE_VALUE & 0xff );
/* /*
* Set Compare Special Event Trigger Mode * Set Compare Special Event Trigger Mode
*/ */
bCCP1M3 = portBIT_SET; bCCP1M3 = portBIT_SET;
bCCP1M2 = portBIT_CLEAR; bCCP1M2 = portBIT_CLEAR;
bCCP1M1 = portBIT_SET; bCCP1M1 = portBIT_SET;
bCCP1M0 = portBIT_SET; bCCP1M0 = portBIT_SET;
/* /*
* Enable CCP1 interrupt * Enable CCP1 interrupt
*/ */
bCCP1IE = portBIT_SET; bCCP1IE = portBIT_SET;
/* /*
* We are only going to use the global interrupt bit, so disable * We are only going to use the global interrupt bit, so disable
* interruptpriorities and enable peripheral interrupts. * interruptpriorities and enable peripheral interrupts.
*/ */
bIPEN = portBIT_CLEAR; bIPEN = portBIT_CLEAR;
bPEIE = portBIT_SET; bPEIE = portBIT_SET;
/* /*
* Set up timer1 * Set up timer1
@ -128,12 +128,12 @@ void portSetupTick( void )
/* /*
* Setup the timer * Setup the timer
*/ */
bRD16 = portBIT_SET; /* 16-bit */ bRD16 = portBIT_SET; // 16-bit
bT1CKPS1 = portTIMER_COMPARE_PS1; /* prescaler */ bT1CKPS1 = portTIMER_COMPARE_PS1; // prescaler
bT1CKPS0 = portTIMER_COMPARE_PS0; /* prescaler */ bT1CKPS0 = portTIMER_COMPARE_PS0; // prescaler
bT1OSCEN = portBIT_SET; /* Oscillator enable */ bT1OSCEN = portBIT_SET; // Oscillator enable
bT1SYNC = portBIT_SET; /* No external clock sync */ bT1SYNC = portBIT_SET; // No external clock sync
bTMR1CS = portBIT_CLEAR; /* Internal clock */ bTMR1CS = portBIT_CLEAR; // Internal clock
bTMR1ON = portBIT_SET; /* Start timer1 */ bTMR1ON = portBIT_SET; // Start timer1
} }

View file

@ -27,17 +27,17 @@
*/ */
/* /*
* Changes from V3.0.0 Changes from V3.0.0
+ ISRcode pulled inline to reduce stack-usage. + ISRcode pulled inline to reduce stack-usage.
+
+ Added functionality to only call vTaskSwitchContext() once + Added functionality to only call vTaskSwitchContext() once
+ when handling multiple interruptsources in a single interruptcall. when handling multiple interruptsources in a single interruptcall.
+
+ Filename changed to a .c extension to allow stepping through code + Filename changed to a .c extension to allow stepping through code
+ using F7. using F7.
+
+ Changes from V3.0.1 Changes from V3.0.1
*/ */
/* /*
* ISR for the tick. * ISR for the tick.
@ -76,4 +76,4 @@
#pragma wizcpp uselib "$__PATHNAME__/Tick.c" #pragma wizcpp uselib "$__PATHNAME__/Tick.c"
#endif /* _FREERTOS_DRIVERS_TICK_ISRTICK_C */ #endif /* _FREERTOS_DRIVERS_TICK_ISRTICK_C */

View file

@ -27,13 +27,13 @@
*/ */
/* /*
* Changes from V3.0.0 Changes from V3.0.0
*
* Changes from V3.0.1 Changes from V3.0.1
*
* Changes from V4.0.1 Changes from V4.0.1
* Uselib pragma added for Croutine.c Uselib pragma added for Croutine.c
*/ */
/* /*
* The installation script will automatically prepend this file to the default FreeRTOS.h. * The installation script will automatically prepend this file to the default FreeRTOS.h.
@ -51,4 +51,4 @@
#pragma wizcpp uselib "$__PATHNAME__/libFreeRTOS/Modules/List.c" #pragma wizcpp uselib "$__PATHNAME__/libFreeRTOS/Modules/List.c"
#pragma wizcpp uselib "$__PATHNAME__/libFreeRTOS/Modules/Port.c" #pragma wizcpp uselib "$__PATHNAME__/libFreeRTOS/Modules/Port.c"
#endif /* WIZC_FREERTOS_H */ #endif /* WIZC_FREERTOS_H */

View file

@ -27,19 +27,19 @@
*/ */
/* /*
* Changes from V3.2.1 Changes from V3.2.1
+ CallReturn Depth increased from 8 to 10 levels to accommodate wizC/fedC V12. + CallReturn Depth increased from 8 to 10 levels to accommodate wizC/fedC V12.
+
+ Changes from V3.2.0 Changes from V3.2.0
+ TBLPTRU is now initialised to zero during the initial stack creation of a new task. This solves + TBLPTRU is now initialised to zero during the initial stack creation of a new task. This solves
+ an error on devices with more than 64kB ROM. an error on devices with more than 64kB ROM.
+
+ Changes from V3.0.0 Changes from V3.0.0
+ ucCriticalNesting is now initialised to 0x7F to prevent interrupts from being + ucCriticalNesting is now initialised to 0x7F to prevent interrupts from being
+ handled before the scheduler is started. handled before the scheduler is started.
+
+ Changes from V3.0.1 Changes from V3.0.1
*/ */
/* Scheduler include files. */ /* Scheduler include files. */
#include <FreeRTOS.h> #include <FreeRTOS.h>
@ -78,17 +78,17 @@ extern volatile TCB_t * volatile pxCurrentTCB;
* 16 bytes: Free space on stack * 16 bytes: Free space on stack
*/ */
#if _ROMSIZE > 0x8000 #if _ROMSIZE > 0x8000
#define portSTACK_FSR_BYTES ( 15 ) #define portSTACK_FSR_BYTES ( 15 )
#define portSTACK_CALLRETURN_ENTRY_SIZE ( 3 ) #define portSTACK_CALLRETURN_ENTRY_SIZE ( 3 )
#else #else
#define portSTACK_FSR_BYTES ( 13 ) #define portSTACK_FSR_BYTES ( 13 )
#define portSTACK_CALLRETURN_ENTRY_SIZE ( 2 ) #define portSTACK_CALLRETURN_ENTRY_SIZE ( 2 )
#endif #endif
#define portSTACK_MINIMAL_CALLRETURN_DEPTH ( 10 ) #define portSTACK_MINIMAL_CALLRETURN_DEPTH ( 10 )
#define portSTACK_OTHER_BYTES ( 20 ) #define portSTACK_OTHER_BYTES ( 20 )
uint16_t usCalcMinStackSize = 0; uint16_t usCalcMinStackSize = 0;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -106,20 +106,16 @@ register uint8_t ucCriticalNesting = 0x7F;
* Initialise the stack of a new task. * Initialise the stack of a new task.
* See portSAVE_CONTEXT macro for description. * See portSAVE_CONTEXT macro for description.
*/ */
StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
TaskFunction_t pxCode,
void * pvParameters )
{ {
uint8_t ucScratch; uint8_t ucScratch;
/* /*
* Get the size of the RAMarea in page 0 used by the compiler * Get the size of the RAMarea in page 0 used by the compiler
* We do this here already to avoid W-register conflicts. * We do this here already to avoid W-register conflicts.
*/ */
_Pragma("asm") _Pragma("asm")
movlw OVERHEADPAGE0 - LOCOPTSIZE + MAXLOCOPTSIZE movlw OVERHEADPAGE0-LOCOPTSIZE+MAXLOCOPTSIZE
movwf PRODL, ACCESS; movwf PRODL,ACCESS ; PRODL is used as temp register
PRODL is used as temp register
_Pragma("asmend") _Pragma("asmend")
ucScratch = PRODL; ucScratch = PRODL;
@ -127,9 +123,9 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
* Place a few bytes of known values on the bottom of the stack. * Place a few bytes of known values on the bottom of the stack.
* This is just useful for debugging. * This is just useful for debugging.
*/ */
/* *pxTopOfStack-- = 0x11; */ // *pxTopOfStack-- = 0x11;
/* *pxTopOfStack-- = 0x22; */ // *pxTopOfStack-- = 0x22;
/* *pxTopOfStack-- = 0x33; */ // *pxTopOfStack-- = 0x33;
/* /*
* Simulate how the stack would look after a call to vPortYield() * Simulate how the stack would look after a call to vPortYield()
@ -140,36 +136,36 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
* First store the function parameters. This is where the task expects * First store the function parameters. This is where the task expects
* to find them when it starts running. * to find them when it starts running.
*/ */
*pxTopOfStack-- = ( StackType_t ) ( ( ( uint16_t ) pvParameters >> 8 ) & 0x00ff ); *pxTopOfStack-- = ( StackType_t ) ( (( uint16_t ) pvParameters >> 8) & 0x00ff );
*pxTopOfStack-- = ( StackType_t ) ( ( uint16_t ) pvParameters & 0x00ff ); *pxTopOfStack-- = ( StackType_t ) ( ( uint16_t ) pvParameters & 0x00ff );
/* /*
* Next are all the registers that form part of the task context. * Next are all the registers that form part of the task context.
*/ */
*pxTopOfStack-- = ( StackType_t ) 0x11; /* STATUS. */ *pxTopOfStack-- = ( StackType_t ) 0x11; /* STATUS. */
*pxTopOfStack-- = ( StackType_t ) 0x22; /* WREG. */ *pxTopOfStack-- = ( StackType_t ) 0x22; /* WREG. */
*pxTopOfStack-- = ( StackType_t ) 0x33; /* BSR. */ *pxTopOfStack-- = ( StackType_t ) 0x33; /* BSR. */
*pxTopOfStack-- = ( StackType_t ) 0x44; /* PRODH. */ *pxTopOfStack-- = ( StackType_t ) 0x44; /* PRODH. */
*pxTopOfStack-- = ( StackType_t ) 0x55; /* PRODL. */ *pxTopOfStack-- = ( StackType_t ) 0x55; /* PRODL. */
*pxTopOfStack-- = ( StackType_t ) 0x66; /* FSR0H. */ *pxTopOfStack-- = ( StackType_t ) 0x66; /* FSR0H. */
*pxTopOfStack-- = ( StackType_t ) 0x77; /* FSR0L. */ *pxTopOfStack-- = ( StackType_t ) 0x77; /* FSR0L. */
*pxTopOfStack-- = ( StackType_t ) 0x88; /* FSR1H. */ *pxTopOfStack-- = ( StackType_t ) 0x88; /* FSR1H. */
*pxTopOfStack-- = ( StackType_t ) 0x99; /* FSR1L. */ *pxTopOfStack-- = ( StackType_t ) 0x99; /* FSR1L. */
*pxTopOfStack-- = ( StackType_t ) 0xAA; /* TABLAT. */ *pxTopOfStack-- = ( StackType_t ) 0xAA; /* TABLAT. */
#if _ROMSIZE > 0x8000 #if _ROMSIZE > 0x8000
*pxTopOfStack-- = ( StackType_t ) 0x00; /* TBLPTRU. */ *pxTopOfStack-- = ( StackType_t ) 0x00; /* TBLPTRU. */
#endif #endif
*pxTopOfStack-- = ( StackType_t ) 0xCC; /* TBLPTRH. */ *pxTopOfStack-- = ( StackType_t ) 0xCC; /* TBLPTRH. */
*pxTopOfStack-- = ( StackType_t ) 0xDD; /* TBLPTRL. */ *pxTopOfStack-- = ( StackType_t ) 0xDD; /* TBLPTRL. */
#if _ROMSIZE > 0x8000 #if _ROMSIZE > 0x8000
*pxTopOfStack-- = ( StackType_t ) 0xEE; /* PCLATU. */ *pxTopOfStack-- = ( StackType_t ) 0xEE; /* PCLATU. */
#endif #endif
*pxTopOfStack-- = ( StackType_t ) 0xFF; /* PCLATH. */ *pxTopOfStack-- = ( StackType_t ) 0xFF; /* PCLATH. */
/* /*
* Next the compiler's scratchspace. * Next the compiler's scratchspace.
*/ */
while( ucScratch-- > 0 ) while(ucScratch-- > 0)
{ {
*pxTopOfStack-- = ( StackType_t ) 0; *pxTopOfStack-- = ( StackType_t ) 0;
} }
@ -180,11 +176,11 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
* stack, too. TOSU is always written as zero here because wizC does not allow * stack, too. TOSU is always written as zero here because wizC does not allow
* functionpointers to point above 64kB in ROM. * functionpointers to point above 64kB in ROM.
*/ */
#if _ROMSIZE > 0x8000 #if _ROMSIZE > 0x8000
*pxTopOfStack-- = ( StackType_t ) 0; *pxTopOfStack-- = ( StackType_t ) 0;
#endif #endif
*pxTopOfStack-- = ( StackType_t ) ( ( ( uint16_t ) pxCode >> 8 ) & 0x00ff ); *pxTopOfStack-- = ( StackType_t ) ( ( ( uint16_t ) pxCode >> 8 ) & 0x00ff );
*pxTopOfStack-- = ( StackType_t ) ( ( uint16_t ) pxCode & 0x00ff ); *pxTopOfStack-- = ( StackType_t ) ( ( uint16_t ) pxCode & 0x00ff );
/* /*
* Store the number of return addresses on the hardware stack. * Store the number of return addresses on the hardware stack.
@ -211,19 +207,19 @@ uint16_t usPortCALCULATE_MINIMAL_STACK_SIZE( void )
* Fetch the size of compiler's scratchspace. * Fetch the size of compiler's scratchspace.
*/ */
_Pragma("asm") _Pragma("asm")
movlw OVERHEADPAGE0 - LOCOPTSIZE + MAXLOCOPTSIZE movlw OVERHEADPAGE0-LOCOPTSIZE+MAXLOCOPTSIZE
movlb usCalcMinStackSize >> 8 movlb usCalcMinStackSize>>8
movwf usCalcMinStackSize, BANKED movwf usCalcMinStackSize,BANKED
_Pragma("asmend") _Pragma("asmend")
/* /*
* Add minimum needed stackspace * Add minimum needed stackspace
*/ */
usCalcMinStackSize += ( portSTACK_FSR_BYTES ) usCalcMinStackSize += ( portSTACK_FSR_BYTES )
+ ( portSTACK_MINIMAL_CALLRETURN_DEPTH * portSTACK_CALLRETURN_ENTRY_SIZE ) + ( portSTACK_MINIMAL_CALLRETURN_DEPTH * portSTACK_CALLRETURN_ENTRY_SIZE )
+ ( portSTACK_OTHER_BYTES ); + ( portSTACK_OTHER_BYTES );
return( usCalcMinStackSize ); return(usCalcMinStackSize);
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -286,11 +282,11 @@ void vPortYield( void )
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
void * pvPortMalloc( uint16_t usWantedSize ) void *pvPortMalloc( uint16_t usWantedSize )
{ {
void * pvReturn; void *pvReturn;
vTaskSuspendAll(); vTaskSuspendAll();
{ {
@ -305,9 +301,9 @@ void vPortYield( void )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
void vPortFree( void * pv ) void vPortFree( void *pv )
{ {
if( pv ) if( pv )
{ {

View file

@ -27,48 +27,48 @@
*/ */
/* /*
* Changes from V3.0.0 Changes from V3.0.0
*
* Changes from V3.0.1 Changes from V3.0.1
*/ */
#ifndef PORTMACRO_H #ifndef PORTMACRO_H
#define PORTMACRO_H #define PORTMACRO_H
#if !defined( _SERIES ) || _SERIES != 18 #if !defined(_SERIES) || _SERIES != 18
#error "WizC supports FreeRTOS on the Microchip PIC18-series only" #error "WizC supports FreeRTOS on the Microchip PIC18-series only"
#endif #endif
#if !defined( QUICKCALL ) || QUICKCALL != 1 #if !defined(QUICKCALL) || QUICKCALL != 1
#error "QuickCall must be enabled (see ProjectOptions/Optimisations)" #error "QuickCall must be enabled (see ProjectOptions/Optimisations)"
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <pic.h> #include <pic.h>
#define portCHAR char #define portCHAR char
#define portFLOAT float #define portFLOAT float
#define portDOUBLE portFLOAT #define portDOUBLE portFLOAT
#define portLONG long #define portLONG long
#define portSHORT short #define portSHORT short
#define portSTACK_TYPE uint8_t #define portSTACK_TYPE uint8_t
#define portBASE_TYPE char #define portBASE_TYPE char
typedef portSTACK_TYPE StackType_t; typedef portSTACK_TYPE StackType_t;
typedef signed char BaseType_t; typedef signed char BaseType_t;
typedef unsigned char UBaseType_t; typedef unsigned char UBaseType_t;
#if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS ) #if( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS )
typedef uint16_t TickType_t; typedef uint16_t TickType_t;
#define portMAX_DELAY ( TickType_t ) ( 0xFFFF ) #define portMAX_DELAY ( TickType_t ) ( 0xFFFF )
#elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS ) #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS )
typedef uint32_t TickType_t; typedef uint32_t TickType_t;
#define portMAX_DELAY ( TickType_t ) ( 0xFFFFFFFFUL ) #define portMAX_DELAY ( TickType_t ) ( 0xFFFFFFFFUL )
#else #else
#error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width. #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
#endif #endif
#define portBYTE_ALIGNMENT 1 #define portBYTE_ALIGNMENT 1
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -76,33 +76,33 @@ typedef unsigned char UBaseType_t;
* Constant used for context switch macro when we require the interrupt * Constant used for context switch macro when we require the interrupt
* enable state to be forced when the interrupted task is switched back in. * enable state to be forced when the interrupted task is switched back in.
*/ */
#define portINTERRUPTS_FORCED ( 0x01 ) #define portINTERRUPTS_FORCED (0x01)
/* /*
* Constant used for context switch macro when we require the interrupt * Constant used for context switch macro when we require the interrupt
* enable state to be unchanged when the interrupted task is switched back in. * enable state to be unchanged when the interrupted task is switched back in.
*/ */
#define portINTERRUPTS_UNCHANGED ( 0x00 ) #define portINTERRUPTS_UNCHANGED (0x00)
/* Initial interrupt enable state for newly created tasks. This value is /* Initial interrupt enable state for newly created tasks. This value is
* used when a task switches in for the first time. * used when a task switches in for the first time.
*/ */
#define portINTERRUPTS_INITIAL_STATE ( portINTERRUPTS_FORCED ) #define portINTERRUPTS_INITIAL_STATE (portINTERRUPTS_FORCED)
/* /*
* Macros to modify the global interrupt enable bit in INTCON. * Macros to modify the global interrupt enable bit in INTCON.
*/ */
#define portDISABLE_INTERRUPTS() \ #define portDISABLE_INTERRUPTS() \
do \ do \
{ \ { \
bGIE = 0; \ bGIE=0; \
} while( bGIE ) /* MicroChip recommends this check! */ } while(bGIE) // MicroChip recommends this check!
#define portENABLE_INTERRUPTS() \ #define portENABLE_INTERRUPTS() \
do \ do \
{ \ { \
bGIE = 1; \ bGIE=1; \
} while( 0 ) } while(0)
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -111,43 +111,43 @@ typedef unsigned char UBaseType_t;
*/ */
extern uint8_t ucCriticalNesting; extern uint8_t ucCriticalNesting;
#define portNO_CRITICAL_SECTION_NESTING ( ( uint8_t ) 0 ) #define portNO_CRITICAL_SECTION_NESTING ( ( uint8_t ) 0 )
#define portENTER_CRITICAL() \ #define portENTER_CRITICAL() \
do \ do \
{ \ { \
portDISABLE_INTERRUPTS(); \ portDISABLE_INTERRUPTS(); \
\ \
/* \ /* \
* Now interrupts are disabled ucCriticalNesting \ * Now interrupts are disabled ucCriticalNesting \
* can be accessed directly. Increment \ * can be accessed directly. Increment \
* ucCriticalNesting to keep a count of how \ * ucCriticalNesting to keep a count of how \
* many times portENTER_CRITICAL() has been called. \ * many times portENTER_CRITICAL() has been called. \
*/ \ */ \
ucCriticalNesting++; \ ucCriticalNesting++; \
} while( 0 ) } while(0)
#define portEXIT_CRITICAL() \ #define portEXIT_CRITICAL() \
do \ do \
{ \ { \
if( ucCriticalNesting > portNO_CRITICAL_SECTION_NESTING ) \ if(ucCriticalNesting > portNO_CRITICAL_SECTION_NESTING) \
{ \ { \
/* \ /* \
* Decrement the nesting count as we are leaving a \ * Decrement the nesting count as we are leaving a \
* critical section. \ * critical section. \
*/ \ */ \
ucCriticalNesting--; \ ucCriticalNesting--; \
} \ } \
\ \
/* \ /* \
* If the nesting level has reached zero then \ * If the nesting level has reached zero then \
* interrupts should be re-enabled. \ * interrupts should be re-enabled. \
*/ \ */ \
if( ucCriticalNesting == portNO_CRITICAL_SECTION_NESTING ) \ if( ucCriticalNesting == portNO_CRITICAL_SECTION_NESTING ) \
{ \ { \
portENABLE_INTERRUPTS(); \ portENABLE_INTERRUPTS(); \
} \ } \
} while( 0 ) } while(0)
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -159,15 +159,15 @@ extern uint8_t ucCriticalNesting;
extern uint16_t usPortCALCULATE_MINIMAL_STACK_SIZE( void ); extern uint16_t usPortCALCULATE_MINIMAL_STACK_SIZE( void );
extern uint16_t usCalcMinStackSize; extern uint16_t usCalcMinStackSize;
#define portMINIMAL_STACK_SIZE \ #define portMINIMAL_STACK_SIZE \
( ( usCalcMinStackSize == 0 ) \ ((usCalcMinStackSize == 0) \
? usPortCALCULATE_MINIMAL_STACK_SIZE() \ ? usPortCALCULATE_MINIMAL_STACK_SIZE() \
: usCalcMinStackSize ) : usCalcMinStackSize )
/* /*
* WizC uses a downgrowing stack * WizC uses a downgrowing stack
*/ */
#define portSTACK_GROWTH ( -1 ) #define portSTACK_GROWTH ( -1 )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -203,220 +203,219 @@ extern uint16_t usCalcMinStackSize;
* assembler definitions. * assembler definitions.
*/ */
#define portSAVE_CONTEXT( ucInterruptForced ) \ #define portSAVE_CONTEXT( ucInterruptForced ) \
do \ do \
{ \ { \
portDISABLE_INTERRUPTS(); \ portDISABLE_INTERRUPTS(); \
\ \
_Pragma("asm") \ _Pragma("asm") \
; \ ; \
; Push the relevant SFR's onto the task's stack \ ; Push the relevant SFR's onto the task's stack \
; \ ; \
movff STATUS,POSTDEC2 \ movff STATUS,POSTDEC2 \
movff WREG,POSTDEC2 \ movff WREG,POSTDEC2 \
movff BSR,POSTDEC2 \ movff BSR,POSTDEC2 \
movff PRODH,POSTDEC2 \ movff PRODH,POSTDEC2 \
movff PRODL,POSTDEC2 \ movff PRODL,POSTDEC2 \
movff FSR0H,POSTDEC2 \ movff FSR0H,POSTDEC2 \
movff FSR0L,POSTDEC2 \ movff FSR0L,POSTDEC2 \
movff FSR1H,POSTDEC2 \ movff FSR1H,POSTDEC2 \
movff FSR1L,POSTDEC2 \ movff FSR1L,POSTDEC2 \
movff TABLAT,POSTDEC2 \ movff TABLAT,POSTDEC2 \
if __ROMSIZE > 0x8000 \ if __ROMSIZE > 0x8000 \
movff TBLPTRU,POSTDEC2 \ movff TBLPTRU,POSTDEC2 \
endif \ endif \
movff TBLPTRH,POSTDEC2 \ movff TBLPTRH,POSTDEC2 \
movff TBLPTRL,POSTDEC2 \ movff TBLPTRL,POSTDEC2 \
if __ROMSIZE > 0x8000 \ if __ROMSIZE > 0x8000 \
movff PCLATU,POSTDEC2 \ movff PCLATU,POSTDEC2 \
endif \ endif \
movff PCLATH,POSTDEC2 \ movff PCLATH,POSTDEC2 \
; \ ; \
; Store the compiler-scratch-area as described above. \ ; Store the compiler-scratch-area as described above. \
; \ ; \
movlw OVERHEADPAGE0-LOCOPTSIZE+MAXLOCOPTSIZE \ movlw OVERHEADPAGE0-LOCOPTSIZE+MAXLOCOPTSIZE \
clrf FSR0L,ACCESS \ clrf FSR0L,ACCESS \
clrf FSR0H,ACCESS \ clrf FSR0H,ACCESS \
_rtos_S1: \ _rtos_S1: \
movff POSTINC0,POSTDEC2 \ movff POSTINC0,POSTDEC2 \
decfsz WREG,W,ACCESS \ decfsz WREG,W,ACCESS \
SMARTJUMP _rtos_S1 \ SMARTJUMP _rtos_S1 \
; \ ; \
; Save the pic call/return-stack belonging to the \ ; Save the pic call/return-stack belonging to the \
; current task by copying it to the task's software- \ ; current task by copying it to the task's software- \
; stack. We save the hardware stack pointer (which \ ; stack. We save the hardware stack pointer (which \
; is the number of addresses on the stack) in the \ ; is the number of addresses on the stack) in the \
; W-register first because we need it later and it \ ; W-register first because we need it later and it \
; is modified in the save-loop by executing pop's. \ ; is modified in the save-loop by executing pop's. \
; After the loop the W-register is stored on the \ ; After the loop the W-register is stored on the \
; stack, too. \ ; stack, too. \
; \ ; \
movf STKPTR,W,ACCESS \ movf STKPTR,W,ACCESS \
bz _rtos_s3 \ bz _rtos_s3 \
_rtos_S2: \ _rtos_S2: \
if __ROMSIZE > 0x8000 \ if __ROMSIZE > 0x8000 \
movff TOSU,POSTDEC2 \ movff TOSU,POSTDEC2 \
endif \ endif \
movff TOSH,POSTDEC2 \ movff TOSH,POSTDEC2 \
movff TOSL,POSTDEC2 \ movff TOSL,POSTDEC2 \
pop \ pop \
tstfsz STKPTR,ACCESS \ tstfsz STKPTR,ACCESS \
SMARTJUMP _rtos_S2 \ SMARTJUMP _rtos_S2 \
_rtos_s3: \ _rtos_s3: \
movwf POSTDEC2,ACCESS \ movwf POSTDEC2,ACCESS \
; \ ; \
; Next the value for ucCriticalNesting used by the \ ; Next the value for ucCriticalNesting used by the \
; task is stored on the stack. When \ ; task is stored on the stack. When \
; (ucInterruptForced == portINTERRUPTS_FORCED), we save \ ; (ucInterruptForced == portINTERRUPTS_FORCED), we save \
; it as 0 (portNO_CRITICAL_SECTION_NESTING). \ ; it as 0 (portNO_CRITICAL_SECTION_NESTING). \
; \ ; \
if ucInterruptForced == portINTERRUPTS_FORCED \ if ucInterruptForced == portINTERRUPTS_FORCED \
clrf POSTDEC2,ACCESS \ clrf POSTDEC2,ACCESS \
else \ else \
movff ucCriticalNesting,POSTDEC2 \ movff ucCriticalNesting,POSTDEC2 \
endif \ endif \
; \ ; \
; Save the new top of the software stack in the TCB. \ ; Save the new top of the software stack in the TCB. \
; \ ; \
movff pxCurrentTCB,FSR0L \ movff pxCurrentTCB,FSR0L \
movff pxCurrentTCB+1,FSR0H \ movff pxCurrentTCB+1,FSR0H \
movff FSR2L,POSTINC0 \ movff FSR2L,POSTINC0 \
movff FSR2H,POSTINC0 \ movff FSR2H,POSTINC0 \
_Pragma("asmend") \ _Pragma("asmend") \
} while(0) } while(0)
/************************************************************/ /************************************************************/
/* /*
* This is the reverse of portSAVE_CONTEXT. * This is the reverse of portSAVE_CONTEXT.
*/ */
#define portRESTORE_CONTEXT() \ #define portRESTORE_CONTEXT() \
do \ do \
{ \ { \
_Pragma("asm") \ _Pragma("asm") \
; \ ; \
; Set FSR0 to point to pxCurrentTCB->pxTopOfStack. \ ; Set FSR0 to point to pxCurrentTCB->pxTopOfStack. \
; \ ; \
movff pxCurrentTCB,FSR0L \ movff pxCurrentTCB,FSR0L \
movff pxCurrentTCB+1,FSR0H \ movff pxCurrentTCB+1,FSR0H \
; \ ; \
; De-reference FSR0 to set the address it holds into \ ; De-reference FSR0 to set the address it holds into \
; FSR2 (i.e. *( pxCurrentTCB->pxTopOfStack ) ). FSR2 \ ; FSR2 (i.e. *( pxCurrentTCB->pxTopOfStack ) ). FSR2 \
; is used by wizC as stackpointer. \ ; is used by wizC as stackpointer. \
; \ ; \
movff POSTINC0,FSR2L \ movff POSTINC0,FSR2L \
movff POSTINC0,FSR2H \ movff POSTINC0,FSR2H \
; \ ; \
; Next, the value for ucCriticalNesting used by the \ ; Next, the value for ucCriticalNesting used by the \
; task is retrieved from the stack. \ ; task is retrieved from the stack. \
; \ ; \
movff PREINC2,ucCriticalNesting \ movff PREINC2,ucCriticalNesting \
; \ ; \
; Rebuild the pic call/return-stack. The number of \ ; Rebuild the pic call/return-stack. The number of \
; return addresses is the next item on the task stack. \ ; return addresses is the next item on the task stack. \
; Save this number in PRODL. Then fetch the addresses \ ; Save this number in PRODL. Then fetch the addresses \
; and store them on the hardwarestack. \ ; and store them on the hardwarestack. \
; The datasheets say we can't use movff here... \ ; The datasheets say we can't use movff here... \
; \ ; \
movff PREINC2,PRODL /* Use PRODL as tempregister */ \ movff PREINC2,PRODL // Use PRODL as tempregister \
clrf STKPTR,ACCESS \ clrf STKPTR,ACCESS \
_rtos_R1: \ _rtos_R1: \
push \ push \
movf PREINC2,W,ACCESS \ movf PREINC2,W,ACCESS \
movwf TOSL,ACCESS \ movwf TOSL,ACCESS \
movf PREINC2,W,ACCESS \ movf PREINC2,W,ACCESS \
movwf TOSH,ACCESS \ movwf TOSH,ACCESS \
if __ROMSIZE > 0x8000 \ if __ROMSIZE > 0x8000 \
movf PREINC2,W,ACCESS \ movf PREINC2,W,ACCESS \
movwf TOSU,ACCESS \ movwf TOSU,ACCESS \
else \ else \
clrf TOSU,ACCESS \ clrf TOSU,ACCESS \
endif \ endif \
decfsz PRODL,F,ACCESS \ decfsz PRODL,F,ACCESS \
SMARTJUMP _rtos_R1 \ SMARTJUMP _rtos_R1 \
; \ ; \
; Restore the compiler's working storage area to page 0 \ ; Restore the compiler's working storage area to page 0 \
; \ ; \
movlw OVERHEADPAGE0-LOCOPTSIZE+MAXLOCOPTSIZE \ movlw OVERHEADPAGE0-LOCOPTSIZE+MAXLOCOPTSIZE \
movwf FSR0L,ACCESS \ movwf FSR0L,ACCESS \
clrf FSR0H,ACCESS \ clrf FSR0H,ACCESS \
_rtos_R2: \ _rtos_R2: \
decf FSR0L,F,ACCESS \ decf FSR0L,F,ACCESS \
movff PREINC2,INDF0 \ movff PREINC2,INDF0 \
tstfsz FSR0L,ACCESS \ tstfsz FSR0L,ACCESS \
SMARTJUMP _rtos_R2 \ SMARTJUMP _rtos_R2 \
; \ ; \
; Restore the sfr's forming the tasks context. \ ; Restore the sfr's forming the tasks context. \
; We cannot yet restore bsr, w and status because \ ; We cannot yet restore bsr, w and status because \
; we need these registers for a final test. \ ; we need these registers for a final test. \
; \ ; \
movff PREINC2,PCLATH \ movff PREINC2,PCLATH \
if __ROMSIZE > 0x8000 \ if __ROMSIZE > 0x8000 \
movff PREINC2,PCLATU \ movff PREINC2,PCLATU \
else \ else \
clrf PCLATU,ACCESS \ clrf PCLATU,ACCESS \
endif \ endif \
movff PREINC2,TBLPTRL \ movff PREINC2,TBLPTRL \
movff PREINC2,TBLPTRH \ movff PREINC2,TBLPTRH \
if __ROMSIZE > 0x8000 \ if __ROMSIZE > 0x8000 \
movff PREINC2,TBLPTRU \ movff PREINC2,TBLPTRU \
else \ else \
clrf TBLPTRU,ACCESS \ clrf TBLPTRU,ACCESS \
endif \ endif \
movff PREINC2,TABLAT \ movff PREINC2,TABLAT \
movff PREINC2,FSR1L \ movff PREINC2,FSR1L \
movff PREINC2,FSR1H \ movff PREINC2,FSR1H \
movff PREINC2,FSR0L \ movff PREINC2,FSR0L \
movff PREINC2,FSR0H \ movff PREINC2,FSR0H \
movff PREINC2,PRODL \ movff PREINC2,PRODL \
movff PREINC2,PRODH \ movff PREINC2,PRODH \
; \ ; \
; The return from portRESTORE_CONTEXT() depends on \ ; The return from portRESTORE_CONTEXT() depends on \
; the value of ucCriticalNesting. When it is zero, \ ; the value of ucCriticalNesting. When it is zero, \
; interrupts need to be enabled. This is done via a \ ; interrupts need to be enabled. This is done via a \
; retfie instruction because we need the \ ; retfie instruction because we need the \
; interrupt-enabling and the return to the restored \ ; interrupt-enabling and the return to the restored \
; task to be uninterruptible. \ ; task to be uninterruptible. \
; Because bsr, status and W are affected by the test \ ; Because bsr, status and W are affected by the test \
; they are restored after the test. \ ; they are restored after the test. \
; \ ; \
movlb ucCriticalNesting>>8 \ movlb ucCriticalNesting>>8 \
tstfsz ucCriticalNesting,BANKED \ tstfsz ucCriticalNesting,BANKED \
SMARTJUMP _rtos_R4 \ SMARTJUMP _rtos_R4 \
_rtos_R3: \ _rtos_R3: \
movff PREINC2,BSR \ movff PREINC2,BSR \
movff PREINC2,WREG \ movff PREINC2,WREG \
movff PREINC2,STATUS \ movff PREINC2,STATUS \
retfie 0 ; Return enabling interrupts \ retfie 0 ; Return enabling interrupts \
_rtos_R4: \ _rtos_R4: \
movff PREINC2,BSR \ movff PREINC2,BSR \
movff PREINC2,WREG \ movff PREINC2,WREG \
movff PREINC2,STATUS \ movff PREINC2,STATUS \
return 0 ; Return without affecting interrupts \ return 0 ; Return without affecting interrupts \
_Pragma("asmend") \ _Pragma("asmend") \
} while(0) } while(0)
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
extern void vPortYield( void ); extern void vPortYield( void );
#define portYIELD() vPortYield() #define portYIELD() vPortYield()
#define portNOP() \ #define portNOP() _Pragma("asm") \
_Pragma("asm") \ nop \
nop \ _Pragma("asmend")
_Pragma("asmend")
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#define portTASK_FUNCTION( xFunction, pvParameters ) \ #define portTASK_FUNCTION( xFunction, pvParameters ) \
void pointed xFunction( void * pvParameters ) \ void pointed xFunction( void *pvParameters ) \
_Pragma(asmfunc xFunction) _Pragma(asmfunc xFunction)
#define portTASK_FUNCTION_PROTO portTASK_FUNCTION #define portTASK_FUNCTION_PROTO portTASK_FUNCTION
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/