code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /* When switching out a task, if the task tag contains a buffer address then save the flop context into the buffer. */ #define traceTASK_SWITCHED_OUT() \ if( pxCurrentTCB->pxTaskTag != NULL ) \ { \ extern void vPortSaveFPURegisters( void * ); \ vPortSaveFPURegisters( ( void * ) ( pxCurrentTCB->pxTaskTag ) ); \ } /* When switching in a task, if the task tag contains a buffer address then load the flop context from the buffer. */ #define traceTASK_SWITCHED_IN() \ if( pxCurrentTCB->pxTaskTag != NULL ) \ { \ extern void vPortRestoreFPURegisters( void * ); \ vPortRestoreFPURegisters( ( void * ) ( pxCurrentTCB->pxTaskTag ) ); \ }
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/PPC440_Xilinx/FPU_Macros.h
C
oos
3,714
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef PORTMACRO_H #define PORTMACRO_H #include "xexception_l.h" #ifdef __cplusplus extern "C" { #endif /*----------------------------------------------------------- * Port specific definitions. * * The settings in this file configure FreeRTOS correctly for the * given hardware and compiler. * * These settings should not be altered. *----------------------------------------------------------- */ /* Type definitions. */ #define portCHAR char #define portFLOAT float #define portDOUBLE double #define portLONG long #define portSHORT short #define portSTACK_TYPE unsigned portLONG #define portBASE_TYPE portLONG #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff #else typedef unsigned portLONG portTickType; #define portMAX_DELAY ( portTickType ) 0xffffffff #endif /*-----------------------------------------------------------*/ /* This port uses the critical nesting count from the TCB rather than maintaining a separate value and then saving this value in the task stack. */ #define portCRITICAL_NESTING_IN_TCB 1 /* Interrupt control macros. */ #define portDISABLE_INTERRUPTS() XExc_mDisableExceptions( XEXC_NON_CRITICAL ); #define portENABLE_INTERRUPTS() XExc_mEnableExceptions( XEXC_NON_CRITICAL ); /*-----------------------------------------------------------*/ /* Critical section macros. */ void vTaskEnterCritical( void ); void vTaskExitCritical( void ); #define portENTER_CRITICAL() vTaskEnterCritical() #define portEXIT_CRITICAL() vTaskExitCritical() /*-----------------------------------------------------------*/ /* Task utilities. */ void vPortYield( void ); #define portYIELD() asm volatile ( "SC \n\t NOP" ) #define portYIELD_FROM_ISR() vTaskSwitchContext() /*-----------------------------------------------------------*/ /* Hardware specifics. */ #define portBYTE_ALIGNMENT 8 #define portSTACK_GROWTH ( -1 ) #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) #define portNOP() asm volatile ( "NOP" ) /* There are 32 * 32bit floating point regieters, plus the FPSCR to save. */ #define portNO_FLOP_REGISTERS_TO_SAVE ( 32 + 1 ) /*-----------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. */ #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) /* Port specific interrupt handling functions. */ void vPortSetupInterruptController( void ); portBASE_TYPE xPortInstallInterruptHandler( unsigned portCHAR ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef ); #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/PPC440_Xilinx/portmacro.h
C
oos
5,849
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #include "FreeRTOSConfig.h" .extern pxCurrentTCB .extern vTaskSwitchContext .extern vTaskIncrementTick .extern vPortISRHandler .global vPortStartFirstTask .global vPortYield .global vPortTickISR .global vPortISRWrapper .global vPortSaveFPURegisters .global vPortRestoreFPURegisters .set BChainField, 0 .set NextLRField, BChainField + 4 .set MSRField, NextLRField + 4 .set PCField, MSRField + 4 .set LRField, PCField + 4 .set CTRField, LRField + 4 .set XERField, CTRField + 4 .set CRField, XERField + 4 .set USPRG0Field, CRField + 4 .set r0Field, USPRG0Field + 4 .set r2Field, r0Field + 4 .set r3r31Field, r2Field + 4 .set IFrameSize, r3r31Field + ( ( 31 - 3 ) + 1 ) * 4 .macro portSAVE_STACK_POINTER_AND_LR /* Get the address of the TCB. */ xor R0, R0, R0 addis R2, R0, pxCurrentTCB@ha lwz R2, pxCurrentTCB@l( R2 ) /* Store the stack pointer into the TCB */ stw SP, 0( R2 ) /* Save the link register */ stwu R1, -24( R1 ) mflr R0 stw R31, 20( R1 ) stw R0, 28( R1 ) mr R31, r1 .endm .macro portRESTORE_STACK_POINTER_AND_LR /* Restore the link register */ lwz R11, 0( R1 ) lwz R0, 4( R11 ) mtlr R0 lwz R31, -4( R11 ) mr R1, R11 /* Get the address of the TCB. */ xor R0, R0, R0 addis SP, R0, pxCurrentTCB@ha lwz SP, pxCurrentTCB@l( R1 ) /* Get the task stack pointer from the TCB. */ lwz SP, 0( SP ) .endm vPortStartFirstTask: /* Get the address of the TCB. */ xor R0, R0, R0 addis SP, R0, pxCurrentTCB@ha lwz SP, pxCurrentTCB@l( SP ) /* Get the task stack pointer from the TCB. */ lwz SP, 0( SP ) /* Restore MSR register to SRR1. */ lwz R0, MSRField(R1) mtsrr1 R0 /* Restore current PC location to SRR0. */ lwz R0, PCField(R1) mtsrr0 R0 /* Save USPRG0 register */ lwz R0, USPRG0Field(R1) mtspr 0x100,R0 /* Restore Condition register */ lwz R0, CRField(R1) mtcr R0 /* Restore Fixed Point Exception register */ lwz R0, XERField(R1) mtxer R0 /* Restore Counter register */ lwz R0, CTRField(R1) mtctr R0 /* Restore Link register */ lwz R0, LRField(R1) mtlr R0 /* Restore remaining GPR registers. */ lmw R3,r3r31Field(R1) /* Restore r0 and r2. */ lwz R0, r0Field(R1) lwz R2, r2Field(R1) /* Remove frame from stack */ addi R1,R1,IFrameSize /* Return into the first task */ rfi vPortYield: portSAVE_STACK_POINTER_AND_LR bl vTaskSwitchContext portRESTORE_STACK_POINTER_AND_LR blr vPortTickISR: portSAVE_STACK_POINTER_AND_LR bl vTaskIncrementTick #if configUSE_PREEMPTION == 1 bl vTaskSwitchContext #endif /* Clear the interrupt */ lis R0, 2048 mttsr R0 portRESTORE_STACK_POINTER_AND_LR blr vPortISRWrapper: portSAVE_STACK_POINTER_AND_LR bl vPortISRHandler portRESTORE_STACK_POINTER_AND_LR blr #if configUSE_FPU == 1 vPortSaveFPURegisters: /* Enable APU and mark FPU as present. */ mfmsr r0 xor r30, r30, r30 oris r30, r30, 512 ori r30, r30, 8192 or r0, r0, r30 mtmsr r0 #ifdef USE_DP_FPU /* Buffer address is in r3. Save each flop register into an offset from this buffer address. */ stfd f0, 0(r3) stfd f1, 8(r3) stfd f2, 16(r3) stfd f3, 24(r3) stfd f4, 32(r3) stfd f5, 40(r3) stfd f6, 48(r3) stfd f7, 56(r3) stfd f8, 64(r3) stfd f9, 72(r3) stfd f10, 80(r3) stfd f11, 88(r3) stfd f12, 96(r3) stfd f13, 104(r3) stfd f14, 112(r3) stfd f15, 120(r3) stfd f16, 128(r3) stfd f17, 136(r3) stfd f18, 144(r3) stfd f19, 152(r3) stfd f20, 160(r3) stfd f21, 168(r3) stfd f22, 176(r3) stfd f23, 184(r3) stfd f24, 192(r3) stfd f25, 200(r3) stfd f26, 208(r3) stfd f27, 216(r3) stfd f28, 224(r3) stfd f29, 232(r3) stfd f30, 240(r3) stfd f31, 248(r3) /* Also save the FPSCR. */ mffs f31 stfs f31, 256(r3) #else /* Buffer address is in r3. Save each flop register into an offset from this buffer address. */ stfs f0, 0(r3) stfs f1, 4(r3) stfs f2, 8(r3) stfs f3, 12(r3) stfs f4, 16(r3) stfs f5, 20(r3) stfs f6, 24(r3) stfs f7, 28(r3) stfs f8, 32(r3) stfs f9, 36(r3) stfs f10, 40(r3) stfs f11, 44(r3) stfs f12, 48(r3) stfs f13, 52(r3) stfs f14, 56(r3) stfs f15, 60(r3) stfs f16, 64(r3) stfs f17, 68(r3) stfs f18, 72(r3) stfs f19, 76(r3) stfs f20, 80(r3) stfs f21, 84(r3) stfs f22, 88(r3) stfs f23, 92(r3) stfs f24, 96(r3) stfs f25, 100(r3) stfs f26, 104(r3) stfs f27, 108(r3) stfs f28, 112(r3) stfs f29, 116(r3) stfs f30, 120(r3) stfs f31, 124(r3) /* Also save the FPSCR. */ mffs f31 stfs f31, 128(r3) #endif blr #endif /* configUSE_FPU. */ #if configUSE_FPU == 1 vPortRestoreFPURegisters: /* Enable APU and mark FPU as present. */ mfmsr r0 xor r30, r30, r30 oris r30, r30, 512 ori r30, r30, 8192 or r0, r0, r30 mtmsr r0 #ifdef USE_DP_FPU /* Buffer address is in r3. Restore each flop register from an offset into this buffer. First the FPSCR. */ lfs f31, 256(r3) mtfsf f31, 7 lfd f0, 0(r3) lfd f1, 8(r3) lfd f2, 16(r3) lfd f3, 24(r3) lfd f4, 32(r3) lfd f5, 40(r3) lfd f6, 48(r3) lfd f7, 56(r3) lfd f8, 64(r3) lfd f9, 72(r3) lfd f10, 80(r3) lfd f11, 88(r3) lfd f12, 96(r3) lfd f13, 104(r3) lfd f14, 112(r3) lfd f15, 120(r3) lfd f16, 128(r3) lfd f17, 136(r3) lfd f18, 144(r3) lfd f19, 152(r3) lfd f20, 160(r3) lfd f21, 168(r3) lfd f22, 176(r3) lfd f23, 184(r3) lfd f24, 192(r3) lfd f25, 200(r3) lfd f26, 208(r3) lfd f27, 216(r3) lfd f28, 224(r3) lfd f29, 232(r3) lfd f30, 240(r3) lfd f31, 248(r3) #else /* Buffer address is in r3. Restore each flop register from an offset into this buffer. First the FPSCR. */ lfs f31, 128(r3) mtfsf f31, 7 lfs f0, 0(r3) lfs f1, 4(r3) lfs f2, 8(r3) lfs f3, 12(r3) lfs f4, 16(r3) lfs f5, 20(r3) lfs f6, 24(r3) lfs f7, 28(r3) lfs f8, 32(r3) lfs f9, 36(r3) lfs f10, 40(r3) lfs f11, 44(r3) lfs f12, 48(r3) lfs f13, 52(r3) lfs f14, 56(r3) lfs f15, 60(r3) lfs f16, 64(r3) lfs f17, 68(r3) lfs f18, 72(r3) lfs f19, 76(r3) lfs f20, 80(r3) lfs f21, 84(r3) lfs f22, 88(r3) lfs f23, 92(r3) lfs f24, 96(r3) lfs f25, 100(r3) lfs f26, 104(r3) lfs f27, 108(r3) lfs f28, 112(r3) lfs f29, 116(r3) lfs f30, 120(r3) lfs f31, 124(r3) #endif blr #endif /* configUSE_FPU. */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/PPC440_Xilinx/portasm.S
Unix Assembly
oos
9,595
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /*----------------------------------------------------------- * Implementation of functions defined in portable.h for the PPC440 port. *----------------------------------------------------------*/ /* Scheduler includes. */ #include "FreeRTOS.h" #include "task.h" /* Library includes. */ #include "xtime_l.h" #include "xintc.h" #include "xintc_i.h" /*-----------------------------------------------------------*/ /* Definitions to set the initial MSR of each task. */ #define portCRITICAL_INTERRUPT_ENABLE ( 1UL << 17UL ) #define portEXTERNAL_INTERRUPT_ENABLE ( 1UL << 15UL ) #define portMACHINE_CHECK_ENABLE ( 1UL << 12UL ) #if configUSE_FPU == 1 #define portAPU_PRESENT ( 1UL << 25UL ) #define portFCM_FPU_PRESENT ( 1UL << 13UL ) #else #define portAPU_PRESENT ( 0UL ) #define portFCM_FPU_PRESENT ( 0UL ) #endif #define portINITIAL_MSR ( portCRITICAL_INTERRUPT_ENABLE | portEXTERNAL_INTERRUPT_ENABLE | portMACHINE_CHECK_ENABLE | portAPU_PRESENT | portFCM_FPU_PRESENT ) extern const unsigned _SDA_BASE_; extern const unsigned _SDA2_BASE_; /*-----------------------------------------------------------*/ /* * Setup the system timer to generate the tick interrupt. */ static void prvSetupTimerInterrupt( void ); /* * The handler for the tick interrupt - defined in portasm.s. */ extern void vPortTickISR( void ); /* * The handler for the yield function - defined in portasm.s. */ extern void vPortYield( void ); /* * Function to start the scheduler running by starting the highest * priority task that has thus far been created. */ extern void vPortStartFirstTask( void ); /*-----------------------------------------------------------*/ /* Structure used to hold the state of the interrupt controller. */ static XIntc xInterruptController; /*-----------------------------------------------------------*/ /* * Initialise the stack of a task to look exactly as if the task had been * interrupted. * * See the header file portable.h. */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { /* Place a known value at the bottom of the stack for debugging. */ *pxTopOfStack = 0xDEADBEEF; pxTopOfStack--; /* EABI stack frame. */ pxTopOfStack -= 20; /* Previous backchain and LR, R31 to R4 inclusive. */ /* Parameters in R13. */ *pxTopOfStack = ( portSTACK_TYPE ) &_SDA_BASE_; /* address of the first small data area */ pxTopOfStack -= 10; /* Parameters in R3. */ *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; pxTopOfStack--; /* Parameters in R2. */ *pxTopOfStack = ( portSTACK_TYPE ) &_SDA2_BASE_; /* address of the second small data area */ pxTopOfStack--; /* R1 is the stack pointer so is omitted. */ *pxTopOfStack = 0x10000001UL;; /* R0. */ pxTopOfStack--; *pxTopOfStack = 0x00000000UL; /* USPRG0. */ pxTopOfStack--; *pxTopOfStack = 0x00000000UL; /* CR. */ pxTopOfStack--; *pxTopOfStack = 0x00000000UL; /* XER. */ pxTopOfStack--; *pxTopOfStack = 0x00000000UL; /* CTR. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) vPortEndScheduler; /* LR. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* SRR0. */ pxTopOfStack--; *pxTopOfStack = portINITIAL_MSR;/* SRR1. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) vPortEndScheduler;/* Next LR. */ pxTopOfStack--; *pxTopOfStack = 0x00000000UL;/* Backchain. */ return pxTopOfStack; } /*-----------------------------------------------------------*/ portBASE_TYPE xPortStartScheduler( void ) { prvSetupTimerInterrupt(); XExc_RegisterHandler( XEXC_ID_SYSTEM_CALL, ( XExceptionHandler ) vPortYield, ( void * ) 0 ); vPortStartFirstTask(); /* Should not get here as the tasks are now running! */ return pdFALSE; } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { /* Not implemented. */ for( ;; ); } /*-----------------------------------------------------------*/ /* * Hardware initialisation to generate the RTOS tick. */ static void prvSetupTimerInterrupt( void ) { const unsigned long ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL ); XTime_DECClearInterrupt(); XTime_FITClearInterrupt(); XTime_WDTClearInterrupt(); XTime_WDTDisableInterrupt(); XTime_FITDisableInterrupt(); XExc_RegisterHandler( XEXC_ID_DEC_INT, ( XExceptionHandler ) vPortTickISR, ( void * ) 0 ); XTime_DECEnableAutoReload(); XTime_DECSetInterval( ulInterval ); XTime_DECEnableInterrupt(); } /*-----------------------------------------------------------*/ void vPortISRHandler( void *pvNullDoNotUse ) { unsigned long ulInterruptStatus, ulInterruptMask = 1UL; portBASE_TYPE xInterruptNumber; XIntc_Config *pxInterruptController; XIntc_VectorTableEntry *pxTable; /* Just to remove compiler warning. */ ( void ) pvNullDoNotUse; /* Get the configuration by using the device ID - in this case it is assumed that only one interrupt controller is being used. */ pxInterruptController = &XIntc_ConfigTable[ XPAR_XPS_INTC_0_DEVICE_ID ]; /* Which interrupts are pending? */ ulInterruptStatus = XIntc_mGetIntrStatus( pxInterruptController->BaseAddress ); for( xInterruptNumber = 0; xInterruptNumber < XPAR_INTC_MAX_NUM_INTR_INPUTS; xInterruptNumber++ ) { if( ulInterruptStatus & 0x01UL ) { /* Clear the pending interrupt. */ XIntc_mAckIntr( pxInterruptController->BaseAddress, ulInterruptMask ); /* Call the registered handler. */ pxTable = &( pxInterruptController->HandlerTable[ xInterruptNumber ] ); pxTable->Handler( pxTable->CallBackRef ); } /* Check the next interrupt. */ ulInterruptMask <<= 0x01UL; ulInterruptStatus >>= 0x01UL; /* Have we serviced all interrupts? */ if( ulInterruptStatus == 0UL ) { break; } } } /*-----------------------------------------------------------*/ void vPortSetupInterruptController( void ) { extern void vPortISRWrapper( void ); /* Perform all library calls necessary to initialise the exception table and interrupt controller. This assumes only one interrupt controller is in use. */ XExc_mDisableExceptions( XEXC_NON_CRITICAL ); XExc_Init(); /* The library functions save the context - we then jump to a wrapper to save the stack into the TCB. The wrapper then calls the handler defined above. */ XExc_RegisterHandler( XEXC_ID_NON_CRITICAL_INT, ( XExceptionHandler ) vPortISRWrapper, NULL ); XIntc_Initialize( &xInterruptController, XPAR_XPS_INTC_0_DEVICE_ID ); XIntc_Start( &xInterruptController, XIN_REAL_MODE ); } /*-----------------------------------------------------------*/ portBASE_TYPE xPortInstallInterruptHandler( unsigned char ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef ) { portBASE_TYPE xReturn = pdFAIL; /* This function is defined here so the scope of xInterruptController can remain within this file. */ if( XST_SUCCESS == XIntc_Connect( &xInterruptController, ucInterruptID, pxHandler, pvCallBackRef ) ) { XIntc_Enable( &xInterruptController, ucInterruptID ); xReturn = pdPASS; } return xReturn; }
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/PPC440_Xilinx/port.c
C
oos
10,222
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /* Scheduler includes. */ #include "FreeRTOS.h" #include "task.h" /* Hardware includes. */ #include <microblaze_exceptions_i.h> #include <microblaze_exceptions_g.h> /* The Xilinx library defined exception entry point stacks a number of registers. These definitions are offsets from the stack pointer to the various stacked register values. */ #define portexR3_STACK_OFFSET 4 #define portexR4_STACK_OFFSET 5 #define portexR5_STACK_OFFSET 6 #define portexR6_STACK_OFFSET 7 #define portexR7_STACK_OFFSET 8 #define portexR8_STACK_OFFSET 9 #define portexR9_STACK_OFFSET 10 #define portexR10_STACK_OFFSET 11 #define portexR11_STACK_OFFSET 12 #define portexR12_STACK_OFFSET 13 #define portexR15_STACK_OFFSET 16 #define portexR18_STACK_OFFSET 19 #define portexMSR_STACK_OFFSET 20 #define portexR19_STACK_OFFSET -1 /* This is defined to equal the size, in bytes, of the stack frame generated by the Xilinx standard library exception entry point. It is required to determine the stack pointer value prior to the exception being entered. */ #define portexASM_HANDLER_STACK_FRAME_SIZE 84UL /* The number of bytes a MicroBlaze instruction consumes. */ #define portexINSTRUCTION_SIZE 4 /* Exclude this entire file if the MicroBlaze is not configured to handle exceptions, or the application defined configuration constant configINSTALL_EXCEPTION_HANDLERS is not set to 1. */ #if ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 ) /* This variable is set in the exception entry code, before vPortExceptionHandler is called. */ unsigned long *pulStackPointerOnFunctionEntry = NULL; /* This is the structure that is filled with the MicroBlaze context as it existed immediately prior to the exception occurrence. A pointer to this structure is passed into the vApplicationExceptionRegisterDump() callback function, if one is defined. */ static xPortRegisterDump xRegisterDump; /* This is the FreeRTOS exception handler that is installed for all exception types. It is called from vPortExceptionHanlderEntry() - which is itself defined in portasm.S. */ void vPortExceptionHandler( void *pvExceptionID ); extern void vPortExceptionHandlerEntry( void *pvExceptionID ); /*-----------------------------------------------------------*/ /* vApplicationExceptionRegisterDump() is a callback function that the application can optionally define to receive a populated xPortRegisterDump structure. If the application chooses not to define a version of vApplicationExceptionRegisterDump() then this weekly defined default implementation will be called instead. */ extern void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump ) __attribute__((weak)); void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump ) { ( void ) xRegisterDump; for( ;; ) { portNOP(); } } /*-----------------------------------------------------------*/ void vPortExceptionHandler( void *pvExceptionID ) { extern void *pxCurrentTCB; /* Fill an xPortRegisterDump structure with the MicroBlaze context as it was immediately before the exception occurrence. */ /* First fill in the name and handle of the task that was in the Running state when the exception occurred. */ xRegisterDump.xCurrentTaskHandle = pxCurrentTCB; xRegisterDump.pcCurrentTaskName = pcTaskGetTaskName( NULL ); configASSERT( pulStackPointerOnFunctionEntry ); /* Obtain the values of registers that were stacked prior to this function being called, and may have changed since they were stacked. */ xRegisterDump.ulR3 = pulStackPointerOnFunctionEntry[ portexR3_STACK_OFFSET ]; xRegisterDump.ulR4 = pulStackPointerOnFunctionEntry[ portexR4_STACK_OFFSET ]; xRegisterDump.ulR5 = pulStackPointerOnFunctionEntry[ portexR5_STACK_OFFSET ]; xRegisterDump.ulR6 = pulStackPointerOnFunctionEntry[ portexR6_STACK_OFFSET ]; xRegisterDump.ulR7 = pulStackPointerOnFunctionEntry[ portexR7_STACK_OFFSET ]; xRegisterDump.ulR8 = pulStackPointerOnFunctionEntry[ portexR8_STACK_OFFSET ]; xRegisterDump.ulR9 = pulStackPointerOnFunctionEntry[ portexR9_STACK_OFFSET ]; xRegisterDump.ulR10 = pulStackPointerOnFunctionEntry[ portexR10_STACK_OFFSET ]; xRegisterDump.ulR11 = pulStackPointerOnFunctionEntry[ portexR11_STACK_OFFSET ]; xRegisterDump.ulR12 = pulStackPointerOnFunctionEntry[ portexR12_STACK_OFFSET ]; xRegisterDump.ulR15_return_address_from_subroutine = pulStackPointerOnFunctionEntry[ portexR15_STACK_OFFSET ]; xRegisterDump.ulR18 = pulStackPointerOnFunctionEntry[ portexR18_STACK_OFFSET ]; xRegisterDump.ulR19 = pulStackPointerOnFunctionEntry[ portexR19_STACK_OFFSET ]; xRegisterDump.ulMSR = pulStackPointerOnFunctionEntry[ portexMSR_STACK_OFFSET ]; /* Obtain the value of all other registers. */ xRegisterDump.ulR2_small_data_area = mfgpr( R2 ); xRegisterDump.ulR13_read_write_small_data_area = mfgpr( R13 ); xRegisterDump.ulR14_return_address_from_interrupt = mfgpr( R14 ); xRegisterDump.ulR16_return_address_from_trap = mfgpr( R16 ); xRegisterDump.ulR17_return_address_from_exceptions = mfgpr( R17 ); xRegisterDump.ulR20 = mfgpr( R20 ); xRegisterDump.ulR21 = mfgpr( R21 ); xRegisterDump.ulR22 = mfgpr( R22 ); xRegisterDump.ulR23 = mfgpr( R23 ); xRegisterDump.ulR24 = mfgpr( R24 ); xRegisterDump.ulR25 = mfgpr( R25 ); xRegisterDump.ulR26 = mfgpr( R26 ); xRegisterDump.ulR27 = mfgpr( R27 ); xRegisterDump.ulR28 = mfgpr( R28 ); xRegisterDump.ulR29 = mfgpr( R29 ); xRegisterDump.ulR30 = mfgpr( R30 ); xRegisterDump.ulR31 = mfgpr( R31 ); xRegisterDump.ulR1_SP = ( ( unsigned long ) pulStackPointerOnFunctionEntry ) + portexASM_HANDLER_STACK_FRAME_SIZE; xRegisterDump.ulEAR = mfear(); xRegisterDump.ulESR = mfesr(); xRegisterDump.ulEDR = mfedr(); /* Move the saved program counter back to the instruction that was executed when the exception occurred. This is only valid for certain types of exception. */ xRegisterDump.ulPC = xRegisterDump.ulR17_return_address_from_exceptions - portexINSTRUCTION_SIZE; #if XPAR_MICROBLAZE_0_USE_FPU == 1 { xRegisterDump.ulFSR = mffsr(); } #else { xRegisterDump.ulFSR = 0UL; } #endif /* Also fill in a string that describes what type of exception this is. The string uses the same ID names as defined in the MicroBlaze standard library exception header files. */ switch( ( unsigned long ) pvExceptionID ) { case XEXC_ID_FSL : xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_FSL"; break; case XEXC_ID_UNALIGNED_ACCESS : xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_UNALIGNED_ACCESS"; break; case XEXC_ID_ILLEGAL_OPCODE : xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_ILLEGAL_OPCODE"; break; case XEXC_ID_M_AXI_I_EXCEPTION : xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_M_AXI_I_EXCEPTION or XEXC_ID_IPLB_EXCEPTION"; break; case XEXC_ID_M_AXI_D_EXCEPTION : xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_M_AXI_D_EXCEPTION or XEXC_ID_DPLB_EXCEPTION"; break; case XEXC_ID_DIV_BY_ZERO : xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_DIV_BY_ZERO"; break; case XEXC_ID_STACK_VIOLATION : xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_STACK_VIOLATION or XEXC_ID_MMU"; break; #if XPAR_MICROBLAZE_0_USE_FPU == 1 case XEXC_ID_FPU : xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_FPU see ulFSR value"; break; #endif /* XPAR_MICROBLAZE_0_USE_FPU */ } /* vApplicationExceptionRegisterDump() is a callback function that the application can optionally define to receive the populated xPortRegisterDump structure. If the application chooses not to define a version of vApplicationExceptionRegisterDump() then the weekly defined default implementation within this file will be called instead. */ vApplicationExceptionRegisterDump( &xRegisterDump ); /* Must not attempt to leave this function! */ for( ;; ) { portNOP(); } } /*-----------------------------------------------------------*/ void vPortExceptionsInstallHandlers( void ) { static unsigned long ulHandlersAlreadyInstalled = pdFALSE; if( ulHandlersAlreadyInstalled == pdFALSE ) { ulHandlersAlreadyInstalled = pdTRUE; #if XPAR_MICROBLAZE_0_UNALIGNED_EXCEPTIONS == 1 microblaze_register_exception_handler( XEXC_ID_UNALIGNED_ACCESS, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_UNALIGNED_ACCESS ); #endif /* XPAR_MICROBLAZE_0_UNALIGNED_EXCEPTIONS*/ #if XPAR_MICROBLAZE_0_ILL_OPCODE_EXCEPTION == 1 microblaze_register_exception_handler( XEXC_ID_ILLEGAL_OPCODE, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_ILLEGAL_OPCODE ); #endif /* XPAR_MICROBLAZE_0_ILL_OPCODE_EXCEPTION*/ #if XPAR_MICROBLAZE_0_M_AXI_I_BUS_EXCEPTION == 1 microblaze_register_exception_handler( XEXC_ID_M_AXI_I_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_M_AXI_I_EXCEPTION ); #endif /* XPAR_MICROBLAZE_0_M_AXI_I_BUS_EXCEPTION*/ #if XPAR_MICROBLAZE_0_M_AXI_D_BUS_EXCEPTION == 1 microblaze_register_exception_handler( XEXC_ID_M_AXI_D_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_M_AXI_D_EXCEPTION ); #endif /* XPAR_MICROBLAZE_0_M_AXI_D_BUS_EXCEPTION*/ #if XPAR_MICROBLAZE_0_IPLB_BUS_EXCEPTION == 1 microblaze_register_exception_handler( XEXC_ID_IPLB_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_IPLB_EXCEPTION ); #endif /* XPAR_MICROBLAZE_0_IPLB_BUS_EXCEPTION*/ #if XPAR_MICROBLAZE_0_DPLB_BUS_EXCEPTION == 1 microblaze_register_exception_handler( XEXC_ID_DPLB_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_DPLB_EXCEPTION ); #endif /* XPAR_MICROBLAZE_0_DPLB_BUS_EXCEPTION*/ #if XPAR_MICROBLAZE_0_DIV_ZERO_EXCEPTION == 1 microblaze_register_exception_handler( XEXC_ID_DIV_BY_ZERO, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_DIV_BY_ZERO ); #endif /* XPAR_MICROBLAZE_0_DIV_ZERO_EXCEPTION*/ #if XPAR_MICROBLAZE_0_FPU_EXCEPTION == 1 microblaze_register_exception_handler( XEXC_ID_FPU, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_FPU ); #endif /* XPAR_MICROBLAZE_0_FPU_EXCEPTION*/ #if XPAR_MICROBLAZE_0_FSL_EXCEPTION == 1 microblaze_register_exception_handler( XEXC_ID_FSL, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_FSL ); #endif /* XPAR_MICROBLAZE_0_FSL_EXCEPTION*/ } } /* Exclude the entire file if the MicroBlaze is not configured to handle exceptions, or the application defined configuration item configINSTALL_EXCEPTION_HANDLERS is not set to 1. */ #endif /* ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 ) */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/MicroBlazeV8/port_exceptions.c
C
oos
13,791
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef PORTMACRO_H #define PORTMACRO_H #ifdef __cplusplus extern "C" { #endif /* BSP includes. */ #include <mb_interface.h> #include <xparameters.h> /*----------------------------------------------------------- * Port specific definitions. * * The settings in this file configure FreeRTOS correctly for the * given hardware and compiler. * * These settings should not be altered. *----------------------------------------------------------- */ /* 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 #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff #else typedef unsigned portLONG portTickType; #define portMAX_DELAY ( portTickType ) 0xffffffff #endif /*-----------------------------------------------------------*/ /* Interrupt control macros and functions. */ void microblaze_disable_interrupts( void ); void microblaze_enable_interrupts( void ); #define portDISABLE_INTERRUPTS() microblaze_disable_interrupts() #define portENABLE_INTERRUPTS() microblaze_enable_interrupts() /*-----------------------------------------------------------*/ /* Critical section macros. */ void vPortEnterCritical( void ); void vPortExitCritical( void ); #define portENTER_CRITICAL() { \ extern volatile unsigned portBASE_TYPE uxCriticalNesting; \ microblaze_disable_interrupts(); \ uxCriticalNesting++; \ } #define portEXIT_CRITICAL() { \ extern volatile unsigned portBASE_TYPE uxCriticalNesting; \ /* Interrupts are disabled, so we can */ \ /* access the variable directly. */ \ uxCriticalNesting--; \ if( uxCriticalNesting == 0 ) \ { \ /* The nesting has unwound and we \ can enable interrupts again. */ \ portENABLE_INTERRUPTS(); \ } \ } /*-----------------------------------------------------------*/ /* The yield macro maps directly to the vPortYield() function. */ void vPortYield( void ); #define portYIELD() vPortYield() /* portYIELD_FROM_ISR() does not directly call vTaskSwitchContext(), but instead sets a flag to say that a yield has been requested. The interrupt exit code then checks this flag, and calls vTaskSwitchContext() before restoring a task context, if the flag is not false. This is done to prevent multiple calls to vTaskSwitchContext() being made from a single interrupt, as a single interrupt can result in multiple peripherals being serviced. */ extern volatile unsigned long ulTaskSwitchRequested; #define portYIELD_FROM_ISR( x ) if( x != pdFALSE ) ulTaskSwitchRequested = 1 /*-----------------------------------------------------------*/ /* Hardware specifics. */ #define portBYTE_ALIGNMENT 4 #define portSTACK_GROWTH ( -1 ) #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) #define portNOP() asm volatile ( "NOP" ) /*-----------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. */ #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) /*-----------------------------------------------------------*/ /* The following structure is used by the FreeRTOS exception handler. It is filled with the MicroBlaze context as it was at the time the exception occurred. This is done as an aid to debugging exception occurrences. */ typedef struct PORT_REGISTER_DUMP { /* The following structure members hold the values of the MicroBlaze registers at the time the exception was raised. */ unsigned long ulR1_SP; unsigned long ulR2_small_data_area; unsigned long ulR3; unsigned long ulR4; unsigned long ulR5; unsigned long ulR6; unsigned long ulR7; unsigned long ulR8; unsigned long ulR9; unsigned long ulR10; unsigned long ulR11; unsigned long ulR12; unsigned long ulR13_read_write_small_data_area; unsigned long ulR14_return_address_from_interrupt; unsigned long ulR15_return_address_from_subroutine; unsigned long ulR16_return_address_from_trap; unsigned long ulR17_return_address_from_exceptions; /* The exception entry code will copy the BTR into R17 if the exception occurred in the delay slot of a branch instruction. */ unsigned long ulR18; unsigned long ulR19; unsigned long ulR20; unsigned long ulR21; unsigned long ulR22; unsigned long ulR23; unsigned long ulR24; unsigned long ulR25; unsigned long ulR26; unsigned long ulR27; unsigned long ulR28; unsigned long ulR29; unsigned long ulR30; unsigned long ulR31; unsigned long ulPC; unsigned long ulESR; unsigned long ulMSR; unsigned long ulEAR; unsigned long ulFSR; unsigned long ulEDR; /* A human readable description of the exception cause. The strings used are the same as the #define constant names found in the microblaze_exceptions_i.h header file */ signed char *pcExceptionCause; /* The human readable name of the task that was running at the time the exception occurred. This is the name that was given to the task when the task was created using the FreeRTOS xTaskCreate() API function. */ signed char *pcCurrentTaskName; /* The handle of the task that was running a the time the exception occurred. */ void * xCurrentTaskHandle; } xPortRegisterDump; /* * Installs pxHandler as the interrupt handler for the peripheral specified by * the ucInterruptID parameter. * * ucInterruptID: * * The ID of the peripheral that will have pxHandler assigned as its interrupt * handler. Peripheral IDs are defined in the xparameters.h header file, which * is itself part of the BSP project. For example, in the official demo * application for this port, xparameters.h defines the following IDs for the * four possible interrupt sources: * * XPAR_INTC_0_UARTLITE_1_VEC_ID - for the UARTlite peripheral. * XPAR_INTC_0_TMRCTR_0_VEC_ID - for the AXI Timer 0 peripheral. * XPAR_INTC_0_EMACLITE_0_VEC_ID - for the Ethernet lite peripheral. * XPAR_INTC_0_GPIO_1_VEC_ID - for the button inputs. * * * pxHandler: * * A pointer to the interrupt handler function itself. This must be a void * function that takes a (void *) parameter. * * * pvCallBackRef: * * The parameter passed into the handler function. In many cases this will not * be used and can be NULL. Some times it is used to pass in a reference to * the peripheral instance variable, so it can be accessed from inside the * handler function. * * * pdPASS is returned if the function executes successfully. Any other value * being returned indicates that the function did not execute correctly. */ portBASE_TYPE xPortInstallInterruptHandler( unsigned char ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef ); /* * Enables the interrupt, within the interrupt controller, for the peripheral * specified by the ucInterruptID parameter. * * ucInterruptID: * * The ID of the peripheral that will have its interrupt enabled in the * interrupt controller. Peripheral IDs are defined in the xparameters.h header * file, which is itself part of the BSP project. For example, in the official * demo application for this port, xparameters.h defines the following IDs for * the four possible interrupt sources: * * XPAR_INTC_0_UARTLITE_1_VEC_ID - for the UARTlite peripheral. * XPAR_INTC_0_TMRCTR_0_VEC_ID - for the AXI Timer 0 peripheral. * XPAR_INTC_0_EMACLITE_0_VEC_ID - for the Ethernet lite peripheral. * XPAR_INTC_0_GPIO_1_VEC_ID - for the button inputs. * */ void vPortEnableInterrupt( unsigned char ucInterruptID ); /* * Disables the interrupt, within the interrupt controller, for the peripheral * specified by the ucInterruptID parameter. * * ucInterruptID: * * The ID of the peripheral that will have its interrupt disabled in the * interrupt controller. Peripheral IDs are defined in the xparameters.h header * file, which is itself part of the BSP project. For example, in the official * demo application for this port, xparameters.h defines the following IDs for * the four possible interrupt sources: * * XPAR_INTC_0_UARTLITE_1_VEC_ID - for the UARTlite peripheral. * XPAR_INTC_0_TMRCTR_0_VEC_ID - for the AXI Timer 0 peripheral. * XPAR_INTC_0_EMACLITE_0_VEC_ID - for the Ethernet lite peripheral. * XPAR_INTC_0_GPIO_1_VEC_ID - for the button inputs. * */ void vPortDisableInterrupt( unsigned char ucInterruptID ); /* * This is an application defined callback function used to install the tick * interrupt handler. It is provided as an application callback because the * kernel will run on lots of different MicroBlaze and FPGA configurations - not * all of which will have the same timer peripherals defined or available. This * example uses the AXI Timer 0. If that is available on your hardware platform * then this example callback implementation should not require modification. * The name of the interrupt handler that should be installed is vPortTickISR(), * which the function below declares as an extern. */ void vApplicationSetupTimerInterrupt( void ); /* * This is an application defined callback function used to clear whichever * interrupt was installed by the the vApplicationSetupTimerInterrupt() callback * function - in this case the interrupt generated by the AXI timer. It is * provided as an application callback because the kernel will run on lots of * different MicroBlaze and FPGA configurations - not all of which will have the * same timer peripherals defined or available. This example uses the AXI Timer 0. * If that is available on your hardware platform then this example callback * implementation should not require modification provided the example definition * of vApplicationSetupTimerInterrupt() is also not modified. */ void vApplicationClearTimerInterrupt( void ); /* * vPortExceptionsInstallHandlers() is only available when the MicroBlaze * is configured to include exception functionality, and * configINSTALL_EXCEPTION_HANDLERS is set to 1 in FreeRTOSConfig.h. * * vPortExceptionsInstallHandlers() installs the FreeRTOS exception handler * for every possible exception cause. * * vPortExceptionsInstallHandlers() can be called explicitly from application * code. After that is done, the default FreeRTOS exception handler that will * have been installed can be replaced for any specific exception cause by using * the standard Xilinx library function microblaze_register_exception_handler(). * * If vPortExceptionsInstallHandlers() is not called explicitly by the * application, it will be called automatically by the kernel the first time * xPortInstallInterruptHandler() is called. At that time, any exception * handlers that may have already been installed will be replaced. * * See the description of vApplicationExceptionRegisterDump() for information * on the processing performed by the FreeRTOS exception handler. */ void vPortExceptionsInstallHandlers( void ); /* * The FreeRTOS exception handler fills an xPortRegisterDump structure (defined * in portmacro.h) with the MicroBlaze context, as it was at the time the * exception occurred. The exception handler then calls * vApplicationExceptionRegisterDump(), passing in the completed * xPortRegisterDump structure as its parameter. * * The FreeRTOS kernel provides its own implementation of * vApplicationExceptionRegisterDump(), but the kernel provided implementation * is declared as being 'weak'. The weak definition allows the application * writer to provide their own implementation, should they wish to use the * register dump information. For example, an implementation could be provided * that wrote the register dump data to a display, or a UART port. */ void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump ); #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/MicroBlazeV8/portmacro.h
C
oos
15,552
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /* FreeRTOS includes. */ #include "FreeRTOSConfig.h" /* Xilinx library includes. */ #include "microblaze_exceptions_g.h" #include "xparameters.h" /* The context is oversized to allow functions called from the ISR to write back into the caller stack. */ #if XPAR_MICROBLAZE_0_USE_FPU == 1 #define portCONTEXT_SIZE 136 #define portMINUS_CONTEXT_SIZE -136 #else #define portCONTEXT_SIZE 132 #define portMINUS_CONTEXT_SIZE -132 #endif /* Offsets from the stack pointer at which saved registers are placed. */ #define portR31_OFFSET 4 #define portR30_OFFSET 8 #define portR29_OFFSET 12 #define portR28_OFFSET 16 #define portR27_OFFSET 20 #define portR26_OFFSET 24 #define portR25_OFFSET 28 #define portR24_OFFSET 32 #define portR23_OFFSET 36 #define portR22_OFFSET 40 #define portR21_OFFSET 44 #define portR20_OFFSET 48 #define portR19_OFFSET 52 #define portR18_OFFSET 56 #define portR17_OFFSET 60 #define portR16_OFFSET 64 #define portR15_OFFSET 68 #define portR14_OFFSET 72 #define portR13_OFFSET 76 #define portR12_OFFSET 80 #define portR11_OFFSET 84 #define portR10_OFFSET 88 #define portR9_OFFSET 92 #define portR8_OFFSET 96 #define portR7_OFFSET 100 #define portR6_OFFSET 104 #define portR5_OFFSET 108 #define portR4_OFFSET 112 #define portR3_OFFSET 116 #define portR2_OFFSET 120 #define portCRITICAL_NESTING_OFFSET 124 #define portMSR_OFFSET 128 #define portFSR_OFFSET 132 .extern pxCurrentTCB .extern XIntc_DeviceInterruptHandler .extern vTaskSwitchContext .extern uxCriticalNesting .extern pulISRStack .extern ulTaskSwitchRequested .extern vPortExceptionHandler .extern pulStackPointerOnFunctionEntry .global _interrupt_handler .global VPortYieldASM .global vPortStartFirstTask .global vPortExceptionHandlerEntry .macro portSAVE_CONTEXT /* Make room for the context on the stack. */ addik r1, r1, portMINUS_CONTEXT_SIZE /* Stack general registers. */ swi r31, r1, portR31_OFFSET swi r30, r1, portR30_OFFSET swi r29, r1, portR29_OFFSET swi r28, r1, portR28_OFFSET swi r27, r1, portR27_OFFSET swi r26, r1, portR26_OFFSET swi r25, r1, portR25_OFFSET swi r24, r1, portR24_OFFSET swi r23, r1, portR23_OFFSET swi r22, r1, portR22_OFFSET swi r21, r1, portR21_OFFSET swi r20, r1, portR20_OFFSET swi r19, r1, portR19_OFFSET swi r18, r1, portR18_OFFSET swi r17, r1, portR17_OFFSET swi r16, r1, portR16_OFFSET swi r15, r1, portR15_OFFSET /* R14 is saved later as it needs adjustment if a yield is performed. */ swi r13, r1, portR13_OFFSET swi r12, r1, portR12_OFFSET swi r11, r1, portR11_OFFSET swi r10, r1, portR10_OFFSET swi r9, r1, portR9_OFFSET swi r8, r1, portR8_OFFSET swi r7, r1, portR7_OFFSET swi r6, r1, portR6_OFFSET swi r5, r1, portR5_OFFSET swi r4, r1, portR4_OFFSET swi r3, r1, portR3_OFFSET swi r2, r1, portR2_OFFSET /* Stack the critical section nesting value. */ lwi r18, r0, uxCriticalNesting swi r18, r1, portCRITICAL_NESTING_OFFSET /* Stack MSR. */ mfs r18, rmsr swi r18, r1, portMSR_OFFSET #if XPAR_MICROBLAZE_0_USE_FPU == 1 /* Stack FSR. */ mfs r18, rfsr swi r18, r1, portFSR_OFFSET #endif /* Save the top of stack value to the TCB. */ lwi r3, r0, pxCurrentTCB sw r1, r0, r3 .endm .macro portRESTORE_CONTEXT /* Load the top of stack value from the TCB. */ lwi r18, r0, pxCurrentTCB lw r1, r0, r18 /* Restore the general registers. */ lwi r31, r1, portR31_OFFSET lwi r30, r1, portR30_OFFSET lwi r29, r1, portR29_OFFSET lwi r28, r1, portR28_OFFSET lwi r27, r1, portR27_OFFSET lwi r26, r1, portR26_OFFSET lwi r25, r1, portR25_OFFSET lwi r24, r1, portR24_OFFSET lwi r23, r1, portR23_OFFSET lwi r22, r1, portR22_OFFSET lwi r21, r1, portR21_OFFSET lwi r20, r1, portR20_OFFSET lwi r19, r1, portR19_OFFSET lwi r17, r1, portR17_OFFSET lwi r16, r1, portR16_OFFSET lwi r15, r1, portR15_OFFSET lwi r14, r1, portR14_OFFSET lwi r13, r1, portR13_OFFSET lwi r12, r1, portR12_OFFSET lwi r11, r1, portR11_OFFSET lwi r10, r1, portR10_OFFSET lwi r9, r1, portR9_OFFSET lwi r8, r1, portR8_OFFSET lwi r7, r1, portR7_OFFSET lwi r6, r1, portR6_OFFSET lwi r5, r1, portR5_OFFSET lwi r4, r1, portR4_OFFSET lwi r3, r1, portR3_OFFSET lwi r2, r1, portR2_OFFSET /* Reload the rmsr from the stack. */ lwi r18, r1, portMSR_OFFSET mts rmsr, r18 #if XPAR_MICROBLAZE_0_USE_FPU == 1 /* Reload the FSR from the stack. */ lwi r18, r1, portFSR_OFFSET mts rfsr, r18 #endif /* Load the critical nesting value. */ lwi r18, r1, portCRITICAL_NESTING_OFFSET swi r18, r0, uxCriticalNesting /* Test the critical nesting value. If it is non zero then the task last exited the running state using a yield. If it is zero, then the task last exited the running state through an interrupt. */ xori r18, r18, 0 bnei r18, exit_from_yield /* r18 was being used as a temporary. Now restore its true value from the stack. */ lwi r18, r1, portR18_OFFSET /* Remove the stack frame. */ addik r1, r1, portCONTEXT_SIZE /* Return using rtid so interrupts are re-enabled as this function is exited. */ rtid r14, 0 or r0, r0, r0 .endm /* This function is used to exit portRESTORE_CONTEXT() if the task being returned to last left the Running state by calling taskYIELD() (rather than being preempted by an interrupt). */ .text .align 2 exit_from_yield: /* r18 was being used as a temporary. Now restore its true value from the stack. */ lwi r18, r1, portR18_OFFSET /* Remove the stack frame. */ addik r1, r1, portCONTEXT_SIZE /* Return to the task. */ rtsd r14, 0 or r0, r0, r0 .text .align 2 _interrupt_handler: portSAVE_CONTEXT /* Stack the return address. */ swi r14, r1, portR14_OFFSET /* Switch to the ISR stack. */ lwi r1, r0, pulISRStack /* The parameter to the interrupt handler. */ ori r5, r0, configINTERRUPT_CONTROLLER_TO_USE /* Execute any pending interrupts. */ bralid r15, XIntc_DeviceInterruptHandler or r0, r0, r0 /* See if a new task should be selected to execute. */ lwi r18, r0, ulTaskSwitchRequested or r18, r18, r0 /* If ulTaskSwitchRequested is already zero, then jump straight to restoring the task that is already in the Running state. */ beqi r18, task_switch_not_requested /* Set ulTaskSwitchRequested back to zero as a task switch is about to be performed. */ swi r0, r0, ulTaskSwitchRequested /* ulTaskSwitchRequested was not 0 when tested. Select the next task to execute. */ bralid r15, vTaskSwitchContext or r0, r0, r0 task_switch_not_requested: /* Restore the context of the next task scheduled to execute. */ portRESTORE_CONTEXT .text .align 2 VPortYieldASM: portSAVE_CONTEXT /* Modify the return address so a return is done to the instruction after the call to VPortYieldASM. */ addi r14, r14, 8 swi r14, r1, portR14_OFFSET /* Switch to use the ISR stack. */ lwi r1, r0, pulISRStack /* Select the next task to execute. */ bralid r15, vTaskSwitchContext or r0, r0, r0 /* Restore the context of the next task scheduled to execute. */ portRESTORE_CONTEXT .text .align 2 vPortStartFirstTask: portRESTORE_CONTEXT #if MICROBLAZE_EXCEPTIONS_ENABLED == 1 .text .align 2 vPortExceptionHandlerEntry: /* Take a copy of the stack pointer before vPortExecptionHandler is called, storing its value prior to the function stack frame being created. */ swi r1, r0, pulStackPointerOnFunctionEntry bralid r15, vPortExceptionHandler or r0, r0, r0 #endif /* MICROBLAZE_EXCEPTIONS_ENABLED */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/MicroBlazeV8/portasm.S
Unix Assembly
oos
10,680
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /*----------------------------------------------------------- * Implementation of functions defined in portable.h for the MicroBlaze port. *----------------------------------------------------------*/ /* Scheduler includes. */ #include "FreeRTOS.h" #include "task.h" /* Standard includes. */ #include <string.h> /* Hardware includes. */ #include <xintc_i.h> #include <xil_exception.h> #include <microblaze_exceptions_g.h> /* Tasks are started with a critical section nesting of 0 - however, prior to the scheduler being commenced interrupts should not be enabled, so the critical nesting variable is initialised to a non-zero value. */ #define portINITIAL_NESTING_VALUE ( 0xff ) /* The bit within the MSR register that enabled/disables interrupts. */ #define portMSR_IE ( 0x02U ) /* If the floating point unit is included in the MicroBlaze build, then the FSR register is saved as part of the task context. portINITIAL_FSR is the value given to the FSR register when the initial context is set up for a task being created. */ #define portINITIAL_FSR ( 0U ) /*-----------------------------------------------------------*/ /* * Initialise the interrupt controller instance. */ static long prvInitialiseInterruptController( void ); /* Ensure the interrupt controller instance variable is initialised before it is * used, and that the initialisation only happens once. */ static long prvEnsureInterruptControllerIsInitialised( void ); /*-----------------------------------------------------------*/ /* Counts the nesting depth of calls to portENTER_CRITICAL(). Each task maintains its own count, so this variable is saved as part of the task context. */ volatile unsigned portBASE_TYPE uxCriticalNesting = portINITIAL_NESTING_VALUE; /* This port uses a separate stack for interrupts. This prevents the stack of every task needing to be large enough to hold an entire interrupt stack on top of the task stack. */ unsigned long *pulISRStack; /* If an interrupt requests a context switch, then ulTaskSwitchRequested will get set to 1. ulTaskSwitchRequested is inspected just before the main interrupt handler exits. If, at that time, ulTaskSwitchRequested is set to 1, the kernel will call vTaskSwitchContext() to ensure the task that runs immediately after the interrupt exists is the highest priority task that is able to run. This is an unusual mechanism, but is used for this port because a single interrupt can cause the servicing of multiple peripherals - and it is inefficient to call vTaskSwitchContext() multiple times as each peripheral is serviced. */ volatile unsigned long ulTaskSwitchRequested = 0UL; /* The instance of the interrupt controller used by this port. This is required by the Xilinx library API functions. */ static XIntc xInterruptControllerInstance; /*-----------------------------------------------------------*/ /* * Initialise the stack of a task to look exactly as if a call to * portSAVE_CONTEXT had been made. * * See the portable.h header file. */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { extern void *_SDA2_BASE_, *_SDA_BASE_; const unsigned long ulR2 = ( unsigned long ) &_SDA2_BASE_; const unsigned long ulR13 = ( unsigned long ) &_SDA_BASE_; /* Place a few bytes of known values on the bottom of the stack. This is essential for the Microblaze port and these lines must not be omitted. */ *pxTopOfStack = ( portSTACK_TYPE ) 0x00000000; pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x00000000; pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x00000000; pxTopOfStack--; #if XPAR_MICROBLAZE_0_USE_FPU == 1 /* The FSR value placed in the initial task context is just 0. */ *pxTopOfStack = portINITIAL_FSR; pxTopOfStack--; #endif /* The MSR value placed in the initial task context should have interrupts disabled. Each task will enable interrupts automatically when it enters the running state for the first time. */ *pxTopOfStack = mfmsr() & ~portMSR_IE; pxTopOfStack--; /* First stack an initial value for the critical section nesting. This is initialised to zero. */ *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* R0 is always zero. */ /* R1 is the SP. */ /* Place an initial value for all the general purpose registers. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) ulR2; /* R2 - read only small data area. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x03; /* R3 - return values and temporaries. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x04; /* R4 - return values and temporaries. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;/* R5 contains the function call parameters. */ #ifdef portPRE_LOAD_STACK_FOR_DEBUGGING pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x06; /* R6 - other parameters and temporaries. Used as the return address from vPortTaskEntryPoint. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x07; /* R7 - other parameters and temporaries. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x08; /* R8 - other parameters and temporaries. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x09; /* R9 - other parameters and temporaries. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x0a; /* R10 - other parameters and temporaries. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x0b; /* R11 - temporaries. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x0c; /* R12 - temporaries. */ pxTopOfStack--; #else pxTopOfStack-= 8; #endif *pxTopOfStack = ( portSTACK_TYPE ) ulR13; /* R13 - read/write small data area. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* R14 - return address for interrupt. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) NULL; /* R15 - return address for subroutine. */ #ifdef portPRE_LOAD_STACK_FOR_DEBUGGING pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x10; /* R16 - return address for trap (debugger). */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x11; /* R17 - return address for exceptions, if configured. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x12; /* R18 - reserved for assembler and compiler temporaries. */ pxTopOfStack--; #else pxTopOfStack -= 4; #endif *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* R19 - must be saved across function calls. Callee-save. Seems to be interpreted as the frame pointer. */ #ifdef portPRE_LOAD_STACK_FOR_DEBUGGING pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x14; /* R20 - reserved for storing a pointer to the Global Offset Table (GOT) in Position Independent Code (PIC). Non-volatile in non-PIC code. Must be saved across function calls. Callee-save. Not used by FreeRTOS. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x15; /* R21 - must be saved across function calls. Callee-save. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x16; /* R22 - must be saved across function calls. Callee-save. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x17; /* R23 - must be saved across function calls. Callee-save. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x18; /* R24 - must be saved across function calls. Callee-save. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x19; /* R25 - must be saved across function calls. Callee-save. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1a; /* R26 - must be saved across function calls. Callee-save. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1b; /* R27 - must be saved across function calls. Callee-save. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1c; /* R28 - must be saved across function calls. Callee-save. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1d; /* R29 - must be saved across function calls. Callee-save. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1e; /* R30 - must be saved across function calls. Callee-save. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1f; /* R31 - must be saved across function calls. Callee-save. */ pxTopOfStack--; #else pxTopOfStack -= 13; #endif /* Return a pointer to the top of the stack that has been generated so this can be stored in the task control block for the task. */ return pxTopOfStack; } /*-----------------------------------------------------------*/ portBASE_TYPE xPortStartScheduler( void ) { extern void ( vPortStartFirstTask )( void ); extern unsigned long _stack[]; /* Setup the hardware to generate the tick. Interrupts are disabled when this function is called. This port uses an application defined callback function to install the tick interrupt handler because the kernel will run on lots of different MicroBlaze and FPGA configurations - not all of which will have the same timer peripherals defined or available. An example definition of vApplicationSetupTimerInterrupt() is provided in the official demo application that accompanies this port. */ vApplicationSetupTimerInterrupt(); /* Reuse the stack from main() as the stack for the interrupts/exceptions. */ pulISRStack = ( unsigned long * ) _stack; /* Ensure there is enough space for the functions called from the interrupt service routines to write back into the stack frame of the caller. */ pulISRStack -= 2; /* Restore the context of the first task that is going to run. From here on, the created tasks will be executing. */ vPortStartFirstTask(); /* Should not get here as the tasks are now running! */ return pdFALSE; } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { /* Not implemented. */ } /*-----------------------------------------------------------*/ /* * Manual context switch called by portYIELD or taskYIELD. */ void vPortYield( void ) { extern void VPortYieldASM( void ); /* Perform the context switch in a critical section to assure it is not interrupted by the tick ISR. It is not a problem to do this as each task maintains its own interrupt status. */ portENTER_CRITICAL(); { /* Jump directly to the yield function to ensure there is no compiler generated prologue code. */ asm volatile ( "bralid r14, VPortYieldASM \n\t" \ "or r0, r0, r0 \n\t" ); } portEXIT_CRITICAL(); } /*-----------------------------------------------------------*/ void vPortEnableInterrupt( unsigned char ucInterruptID ) { long lReturn; /* An API function is provided to enable an interrupt in the interrupt controller because the interrupt controller instance variable is private to this file. */ lReturn = prvEnsureInterruptControllerIsInitialised(); if( lReturn == pdPASS ) { XIntc_Enable( &xInterruptControllerInstance, ucInterruptID ); } configASSERT( lReturn ); } /*-----------------------------------------------------------*/ void vPortDisableInterrupt( unsigned char ucInterruptID ) { long lReturn; /* An API function is provided to disable an interrupt in the interrupt controller because the interrupt controller instance variable is private to this file. */ lReturn = prvEnsureInterruptControllerIsInitialised(); if( lReturn == pdPASS ) { XIntc_Disable( &xInterruptControllerInstance, ucInterruptID ); } configASSERT( lReturn ); } /*-----------------------------------------------------------*/ portBASE_TYPE xPortInstallInterruptHandler( unsigned char ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef ) { long lReturn; /* An API function is provided to install an interrupt handler because the interrupt controller instance variable is private to this file. */ lReturn = prvEnsureInterruptControllerIsInitialised(); if( lReturn == pdPASS ) { lReturn = XIntc_Connect( &xInterruptControllerInstance, ucInterruptID, pxHandler, pvCallBackRef ); } if( lReturn == XST_SUCCESS ) { lReturn = pdPASS; } configASSERT( lReturn == pdPASS ); return lReturn; } /*-----------------------------------------------------------*/ static long prvEnsureInterruptControllerIsInitialised( void ) { static long lInterruptControllerInitialised = pdFALSE; long lReturn; /* Ensure the interrupt controller instance variable is initialised before it is used, and that the initialisation only happens once. */ if( lInterruptControllerInitialised != pdTRUE ) { lReturn = prvInitialiseInterruptController(); if( lReturn == pdPASS ) { lInterruptControllerInitialised = pdTRUE; } } else { lReturn = pdPASS; } return lReturn; } /*-----------------------------------------------------------*/ /* * Handler for the timer interrupt. This is the handler that the application * defined callback function vApplicationSetupTimerInterrupt() should install. */ void vPortTickISR( void *pvUnused ) { extern void vApplicationClearTimerInterrupt( void ); /* Ensure the unused parameter does not generate a compiler warning. */ ( void ) pvUnused; /* This port uses an application defined callback function to clear the tick interrupt because the kernel will run on lots of different MicroBlaze and FPGA configurations - not all of which will have the same timer peripherals defined or available. An example definition of vApplicationClearTimerInterrupt() is provided in the official demo application that accompanies this port. */ vApplicationClearTimerInterrupt(); /* Increment the RTOS tick - this might cause a task to unblock. */ vTaskIncrementTick(); /* If the preemptive scheduler is being used then a context switch should be requested in case incrementing the tick unblocked a task, or a time slice should cause another task to enter the Running state. */ #if configUSE_PREEMPTION == 1 /* Force vTaskSwitchContext() to be called as the interrupt exits. */ ulTaskSwitchRequested = 1; #endif } /*-----------------------------------------------------------*/ static long prvInitialiseInterruptController( void ) { long lStatus; lStatus = XIntc_Initialize( &xInterruptControllerInstance, configINTERRUPT_CONTROLLER_TO_USE ); if( lStatus == XST_SUCCESS ) { /* Initialise the exception table. */ Xil_ExceptionInit(); /* Service all pending interrupts each time the handler is entered. */ XIntc_SetIntrSvcOption( xInterruptControllerInstance.BaseAddress, XIN_SVC_ALL_ISRS_OPTION ); /* Install exception handlers if the MicroBlaze is configured to handle exceptions, and the application defined constant configINSTALL_EXCEPTION_HANDLERS is set to 1. */ #if ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 ) { vPortExceptionsInstallHandlers(); } #endif /* MICROBLAZE_EXCEPTIONS_ENABLED */ /* Start the interrupt controller. Interrupts are enabled when the scheduler starts. */ lStatus = XIntc_Start( &xInterruptControllerInstance, XIN_REAL_MODE ); if( lStatus == XST_SUCCESS ) { lStatus = pdPASS; } else { lStatus = pdFAIL; } } configASSERT( lStatus == pdPASS ); return lStatus; } /*-----------------------------------------------------------*/
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/MicroBlazeV8/port.c
C
oos
18,506
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef PORTMACRO_H #define PORTMACRO_H #ifdef __cplusplus extern "C" { #endif #include <machine/ic.h> /*----------------------------------------------------------- * Port specific definitions. * * The settings in this file configure FreeRTOS correctly for the * given hardware and compiler. * * These settings should not be altered. *----------------------------------------------------------- */ /* Type definitions. */ #define portCHAR char #define portFLOAT float #define portDOUBLE double #define portLONG long #define portSHORT short #define portSTACK_TYPE unsigned portLONG #define portBASE_TYPE portLONG #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff #else typedef unsigned portLONG portTickType; #define portMAX_DELAY ( portTickType ) 0xffffffff #endif /*-----------------------------------------------------------*/ /* Architecture specifics. */ #define portSTACK_GROWTH ( -1 ) #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) #define portBYTE_ALIGNMENT 4 #define portNOP() __asm__ volatile ( "mov r0, r0" ) #define portCRITICAL_NESTING_IN_TCB 1 #define portIRQ_TRAP_YIELD 31 #define portKERNEL_INTERRUPT_PRIORITY_LEVEL 0 #define portSYSTEM_INTERRUPT_PRIORITY_LEVEL 0 /*-----------------------------------------------------------*/ /* Task utilities. */ extern void vPortYield( void ); /*---------------------------------------------------------------------------*/ #define portYIELD() asm __volatile__( " trap #%0 "::"i"(portIRQ_TRAP_YIELD):"memory") /*---------------------------------------------------------------------------*/ extern void vTaskEnterCritical( void ); extern void vTaskExitCritical( void ); #define portENTER_CRITICAL() vTaskEnterCritical() #define portEXIT_CRITICAL() vTaskExitCritical() /*---------------------------------------------------------------------------*/ /* Critical section management. */ #define portDISABLE_INTERRUPTS() ic->cpl = ( portSYSTEM_INTERRUPT_PRIORITY_LEVEL + 1 ) #define portENABLE_INTERRUPTS() ic->cpl = portKERNEL_INTERRUPT_PRIORITY_LEVEL /*---------------------------------------------------------------------------*/ #define portYIELD_FROM_ISR( xHigherPriorityTaskWoken ) if( xHigherPriorityTaskWoken != pdFALSE ) vTaskSwitchContext() /*---------------------------------------------------------------------------*/ #define portSAVE_CONTEXT() \ asm __volatile__ \ ( \ "sub r1, #68 \n" /* Make space on the stack for the context. */ \ "std r2, [r1] + 0 \n" \ "stq r4, [r1] + 8 \n" \ "stq r8, [r1] + 24 \n" \ "stq r12, [r1] + 40 \n" \ "mov r6, rtt \n" \ "mov r7, psr \n" \ "std r6, [r1] + 56 \n" \ "movhi r2, #16384 \n" /* Set the pointer to the IC. */ \ "ldub r3, [r2] + 2 \n" /* Load the current interrupt mask. */ \ "st r3, [r1]+ 64 \n" /* Store the interrupt mask on the stack. */ \ "ld r2, [r0]+short(pxCurrentTCB) \n" /* Load the pointer to the TCB. */ \ "st r1, [r2] \n" /* Save the stack pointer into the TCB. */ \ "mov r14, r1 \n" /* Compiler expects r14 to be set to the function stack. */ \ ); /*---------------------------------------------------------------------------*/ #define portRESTORE_CONTEXT() \ asm __volatile__( \ "ld r2, [r0]+short(pxCurrentTCB) \n" /* Load the TCB to find the stack pointer and context. */ \ "ld r1, [r2] \n" \ "movhi r2, #16384 \n" /* Set the pointer to the IC. */ \ "ld r3, [r1] + 64 \n" /* Load the previous interrupt mask. */ \ "stb r3, [r2] + 2 \n" /* Set the current interrupt mask to be the previous. */ \ "ldd r6, [r1] + 56 \n" /* Restore context. */ \ "mov rtt, r6 \n" \ "mov psr, r7 \n" \ "ldd r2, [r1] + 0 \n" \ "ldq r4, [r1] + 8 \n" \ "ldq r8, [r1] + 24 \n" \ "ldq r12, [r1] + 40 \n" \ "add r1, #68 \n" \ "rti \n" \ ); /*---------------------------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. */ #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) /*---------------------------------------------------------------------------*/ #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/CORTUS_APS3/portmacro.h
C
oos
7,981
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /* Standard includes. */ #include <stdlib.h> /* Kernel includes. */ #include "FreeRTOS.h" #include "task.h" /* Machine includes */ #include <machine/counter.h> #include <machine/ic.h> /*-----------------------------------------------------------*/ /* The initial PSR has the Previous Interrupt Enabled (PIEN) flag set. */ #define portINITIAL_PSR ( 0x00020000 ) /*-----------------------------------------------------------*/ /* * Perform any hardware configuration necessary to generate the tick interrupt. */ static void prvSetupTimerInterrupt( void ); /*-----------------------------------------------------------*/ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { /* Make space on the stack for the context - this leaves a couple of spaces empty. */ pxTopOfStack -= 20; /* Fill the registers with known values to assist debugging. */ pxTopOfStack[ 16 ] = portKERNEL_INTERRUPT_PRIORITY_LEVEL; pxTopOfStack[ 15 ] = portINITIAL_PSR; pxTopOfStack[ 14 ] = ( unsigned long ) pxCode; pxTopOfStack[ 13 ] = 0x00000000UL; /* R15. */ pxTopOfStack[ 12 ] = 0x00000000UL; /* R14. */ pxTopOfStack[ 11 ] = 0x0d0d0d0dUL; pxTopOfStack[ 10 ] = 0x0c0c0c0cUL; pxTopOfStack[ 9 ] = 0x0b0b0b0bUL; pxTopOfStack[ 8 ] = 0x0a0a0a0aUL; pxTopOfStack[ 7 ] = 0x09090909UL; pxTopOfStack[ 6 ] = 0x08080808UL; pxTopOfStack[ 5 ] = 0x07070707UL; pxTopOfStack[ 4 ] = 0x06060606UL; pxTopOfStack[ 3 ] = 0x05050505UL; pxTopOfStack[ 2 ] = 0x04040404UL; pxTopOfStack[ 1 ] = 0x03030303UL; pxTopOfStack[ 0 ] = ( unsigned long ) pvParameters; return pxTopOfStack; } /*-----------------------------------------------------------*/ portBASE_TYPE xPortStartScheduler( void ) { /* Set-up the timer interrupt. */ prvSetupTimerInterrupt(); /* Enable the TRAP yield. */ irq[ portIRQ_TRAP_YIELD ].ien = 1; irq[ portIRQ_TRAP_YIELD ].ipl = portKERNEL_INTERRUPT_PRIORITY_LEVEL; /* Integrated Interrupt Controller: Enable all interrupts. */ ic->ien = 1; /* Restore callee saved registers. */ portRESTORE_CONTEXT(); /* Should not get here. */ return 0; } /*-----------------------------------------------------------*/ static void prvSetupTimerInterrupt( void ) { /* Enable timer interrupts */ counter1->reload = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1; counter1->value = counter1->reload; counter1->mask = 1; /* Set the IRQ Handler priority and enable it. */ irq[ IRQ_COUNTER1 ].ien = 1; irq[ IRQ_COUNTER1 ].ipl = portKERNEL_INTERRUPT_PRIORITY_LEVEL; } /*-----------------------------------------------------------*/ /* Trap 31 handler. */ void interrupt31_handler( void ) __attribute__((naked)); void interrupt31_handler( void ) { portSAVE_CONTEXT(); __asm volatile ( "call vTaskSwitchContext" ); portRESTORE_CONTEXT(); } /*-----------------------------------------------------------*/ static void prvProcessTick( void ) __attribute__((noinline)); static void prvProcessTick( void ) { vTaskIncrementTick(); #if configUSE_PREEMPTION == 1 vTaskSwitchContext(); #endif /* Clear the Tick Interrupt. */ counter1->expired = 0; } /*-----------------------------------------------------------*/ /* Timer 1 interrupt handler, used for tick interrupt. */ void interrupt7_handler( void ) __attribute__((naked)); void interrupt7_handler( void ) { portSAVE_CONTEXT(); prvProcessTick(); portRESTORE_CONTEXT(); } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { /* Nothing to do. Unlikely to want to end. */ } /*-----------------------------------------------------------*/
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/CORTUS_APS3/port.c
C
oos
6,696
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef PORTMACRO_H #define PORTMACRO_H #ifdef __cplusplus extern "C" { #endif /*----------------------------------------------------------- * Port specific definitions. * * The settings in this file configure FreeRTOS correctly for the * given hardware and compiler. * * These settings should not be altered. *----------------------------------------------------------- */ /* Type definitions. */ #define portCHAR char #define portFLOAT float #define portDOUBLE double #define portLONG long #define portSHORT short #define portSTACK_TYPE unsigned portLONG #define portBASE_TYPE long #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff #else typedef unsigned portLONG portTickType; #define portMAX_DELAY ( portTickType ) 0xffffffff #endif /*-----------------------------------------------------------*/ /* Architecture specifics. */ #define portSTACK_GROWTH ( -1 ) #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) #define portBYTE_ALIGNMENT 8 /*-----------------------------------------------------------*/ /* Scheduler utilities. */ extern void vPortYieldFromISR( void ); #define portYIELD() vPortYieldFromISR() #define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) vPortYieldFromISR() /*-----------------------------------------------------------*/ /* Critical section management. */ /* * Set basepri to portMAX_SYSCALL_INTERRUPT_PRIORITY without effecting other * registers. r0 is clobbered. */ #define portSET_INTERRUPT_MASK() \ __asm volatile \ ( \ " mov r0, %0 \n" \ " msr basepri, r0 \n" \ ::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY):"r0" \ ) /* * Set basepri back to 0 without effective other registers. * r0 is clobbered. */ #define portCLEAR_INTERRUPT_MASK() \ __asm volatile \ ( \ " mov r0, #0 \n" \ " msr basepri, r0 \n" \ :::"r0" \ ) #define portSET_INTERRUPT_MASK_FROM_ISR() 0;portSET_INTERRUPT_MASK() #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) portCLEAR_INTERRUPT_MASK();(void)x extern void vPortEnterCritical( void ); extern void vPortExitCritical( void ); #define portDISABLE_INTERRUPTS() portSET_INTERRUPT_MASK() #define portENABLE_INTERRUPTS() portCLEAR_INTERRUPT_MASK() #define portENTER_CRITICAL() vPortEnterCritical() #define portEXIT_CRITICAL() vPortExitCritical() /*-----------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. */ #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) #define portNOP() #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/ARM_CM3/portmacro.h
C
oos
5,920
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /*----------------------------------------------------------- * Implementation of functions defined in portable.h for the ARM CM3 port. *----------------------------------------------------------*/ /* Scheduler includes. */ #include "FreeRTOS.h" #include "task.h" /* For backward compatibility, ensure configKERNEL_INTERRUPT_PRIORITY is defined. The value should also ensure backward compatibility. FreeRTOS.org versions prior to V4.4.0 did not include this definition. */ #ifndef configKERNEL_INTERRUPT_PRIORITY #define configKERNEL_INTERRUPT_PRIORITY 255 #endif /* Constants required to manipulate the NVIC. */ #define portNVIC_SYSTICK_CTRL ( ( volatile unsigned long *) 0xe000e010 ) #define portNVIC_SYSTICK_LOAD ( ( volatile unsigned long *) 0xe000e014 ) #define portNVIC_INT_CTRL ( ( volatile unsigned long *) 0xe000ed04 ) #define portNVIC_SYSPRI2 ( ( volatile unsigned long *) 0xe000ed20 ) #define portNVIC_SYSTICK_CLK 0x00000004 #define portNVIC_SYSTICK_INT 0x00000002 #define portNVIC_SYSTICK_ENABLE 0x00000001 #define portNVIC_PENDSVSET 0x10000000 #define portNVIC_PENDSV_PRI ( ( ( unsigned long ) configKERNEL_INTERRUPT_PRIORITY ) << 16 ) #define portNVIC_SYSTICK_PRI ( ( ( unsigned long ) configKERNEL_INTERRUPT_PRIORITY ) << 24 ) /* Constants required to set up the initial stack. */ #define portINITIAL_XPSR ( 0x01000000 ) /* The priority used by the kernel is assigned to a variable to make access from inline assembler easier. */ const unsigned long ulKernelPriority = configKERNEL_INTERRUPT_PRIORITY; /* Each task maintains its own interrupt status in the critical nesting variable. */ static unsigned portBASE_TYPE uxCriticalNesting = 0xaaaaaaaa; /* * Setup the timer to generate the tick interrupts. */ static void prvSetupTimerInterrupt( void ); /* * Exception handlers. */ void xPortPendSVHandler( void ) __attribute__ (( naked )); void xPortSysTickHandler( void ); void vPortSVCHandler( void ) __attribute__ (( naked )); /* * Start first task is a separate function so it can be tested in isolation. */ void vPortStartFirstTask( void ) __attribute__ (( naked )); /*-----------------------------------------------------------*/ /* * See header file for description. */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { /* Simulate the stack frame as it would be created by a context switch interrupt. */ pxTopOfStack--; /* Offset added to account for the way the MCU uses the stack on entry/exit of interrupts. */ *pxTopOfStack = portINITIAL_XPSR; /* xPSR */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* PC */ pxTopOfStack--; *pxTopOfStack = 0; /* LR */ pxTopOfStack -= 5; /* R12, R3, R2 and R1. */ *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R0 */ pxTopOfStack -= 8; /* R11, R10, R9, R8, R7, R6, R5 and R4. */ return pxTopOfStack; } /*-----------------------------------------------------------*/ void vPortSVCHandler( void ) { __asm volatile ( " ldr r3, pxCurrentTCBConst2 \n" /* Restore the context. */ " ldr r1, [r3] \n" /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */ " ldr r0, [r1] \n" /* The first item in pxCurrentTCB is the task top of stack. */ " ldmia r0!, {r4-r11} \n" /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */ " msr psp, r0 \n" /* Restore the task stack pointer. */ " mov r0, #0 \n" " msr basepri, r0 \n" " orr r14, #0xd \n" " bx r14 \n" " \n" " .align 2 \n" "pxCurrentTCBConst2: .word pxCurrentTCB \n" ); } /*-----------------------------------------------------------*/ void vPortStartFirstTask( void ) { __asm volatile( " ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */ " ldr r0, [r0] \n" " ldr r0, [r0] \n" " msr msp, r0 \n" /* Set the msp back to the start of the stack. */ " cpsie i \n" /* Globally enable interrupts. */ " svc 0 \n" /* System call to start first task. */ " nop \n" ); } /*-----------------------------------------------------------*/ /* * See header file for description. */ portBASE_TYPE xPortStartScheduler( void ) { /* Make PendSV, CallSV and SysTick the same priroity as the kernel. */ *(portNVIC_SYSPRI2) |= portNVIC_PENDSV_PRI; *(portNVIC_SYSPRI2) |= portNVIC_SYSTICK_PRI; /* Start the timer that generates the tick ISR. Interrupts are disabled here already. */ prvSetupTimerInterrupt(); /* Initialise the critical nesting count ready for the first task. */ uxCriticalNesting = 0; /* Start the first task. */ vPortStartFirstTask(); /* Should not get here! */ return 0; } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { /* It is unlikely that the CM3 port will require this function as there is nothing to return to. */ } /*-----------------------------------------------------------*/ void vPortYieldFromISR( void ) { /* Set a PendSV to request a context switch. */ *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET; } /*-----------------------------------------------------------*/ void vPortEnterCritical( void ) { portDISABLE_INTERRUPTS(); uxCriticalNesting++; } /*-----------------------------------------------------------*/ void vPortExitCritical( void ) { uxCriticalNesting--; if( uxCriticalNesting == 0 ) { portENABLE_INTERRUPTS(); } } /*-----------------------------------------------------------*/ void xPortPendSVHandler( void ) { /* This is a naked function. */ __asm volatile ( " mrs r0, psp \n" " \n" " ldr r3, pxCurrentTCBConst \n" /* Get the location of the current TCB. */ " ldr r2, [r3] \n" " \n" " stmdb r0!, {r4-r11} \n" /* Save the remaining registers. */ " str r0, [r2] \n" /* Save the new top of stack into the first member of the TCB. */ " \n" " stmdb sp!, {r3, r14} \n" " mov r0, %0 \n" " msr basepri, r0 \n" " bl vTaskSwitchContext \n" " mov r0, #0 \n" " msr basepri, r0 \n" " ldmia sp!, {r3, r14} \n" " \n" /* Restore the context, including the critical nesting count. */ " ldr r1, [r3] \n" " ldr r0, [r1] \n" /* The first item in pxCurrentTCB is the task top of stack. */ " ldmia r0!, {r4-r11} \n" /* Pop the registers. */ " msr psp, r0 \n" " bx r14 \n" " \n" " .align 2 \n" "pxCurrentTCBConst: .word pxCurrentTCB \n" ::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY) ); } /*-----------------------------------------------------------*/ void xPortSysTickHandler( void ) { unsigned long ulDummy; /* If using preemption, also force a context switch. */ #if configUSE_PREEMPTION == 1 *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET; #endif ulDummy = portSET_INTERRUPT_MASK_FROM_ISR(); { vTaskIncrementTick(); } portCLEAR_INTERRUPT_MASK_FROM_ISR( ulDummy ); } /*-----------------------------------------------------------*/ /* * Setup the systick timer to generate the tick interrupts at the required * frequency. */ void prvSetupTimerInterrupt( void ) { /* Configure SysTick to interrupt at the requested rate. */ *(portNVIC_SYSTICK_LOAD) = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL; *(portNVIC_SYSTICK_CTRL) = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE; } /*-----------------------------------------------------------*/
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/ARM_CM3/port.c
C
oos
10,720
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef PORTMACRO_H #define PORTMACRO_H #ifdef __cplusplus extern "C" { #endif /*----------------------------------------------------------- * Port specific definitions. * * The settings in this file configure FreeRTOS correctly for the * given hardware and compiler. * * These settings should not be altered. *----------------------------------------------------------- */ /* 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 #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff #else typedef unsigned portLONG portTickType; #define portMAX_DELAY ( portTickType ) 0xffffffff #endif /*-----------------------------------------------------------*/ /* Hardware specifics. */ #define portBYTE_ALIGNMENT 4 #define portSTACK_GROWTH -1 #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) /*-----------------------------------------------------------*/ unsigned portLONG ulPortSetIPL( unsigned portLONG ); #define portDISABLE_INTERRUPTS() ulPortSetIPL( configMAX_SYSCALL_INTERRUPT_PRIORITY ) #define portENABLE_INTERRUPTS() ulPortSetIPL( 0 ) extern void vPortEnterCritical( void ); extern void vPortExitCritical( void ); #define portENTER_CRITICAL() vPortEnterCritical() #define portEXIT_CRITICAL() vPortExitCritical() extern unsigned portBASE_TYPE uxPortSetInterruptMaskFromISR( void ); extern void vPortClearInterruptMaskFromISR( unsigned portBASE_TYPE ); #define portSET_INTERRUPT_MASK_FROM_ISR() ulPortSetIPL( configMAX_SYSCALL_INTERRUPT_PRIORITY ) #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusRegister ) ulPortSetIPL( uxSavedStatusRegister ) /*-----------------------------------------------------------*/ /* Task utilities. */ #define portNOP() asm volatile ( "nop" ) /* Note this will overwrite all other bits in the force register, it is done this way for speed. */ #define portYIELD() MCF_INTC0_INTFRCL = ( 1UL << configYIELD_INTERRUPT_VECTOR ); portNOP(); portNOP() /*-----------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. */ #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__((noreturn)) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) /*-----------------------------------------------------------*/ #define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) \ { \ portYIELD(); \ } #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/ColdFire_V2/portmacro.h
C
oos
5,841
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /* * Purpose: Lowest level routines for all ColdFire processors. * * Notes: * * ulPortSetIPL() and mcf5xxx_wr_cacr() copied with permission from FreeScale * supplied source files. */ .global ulPortSetIPL .global mcf5xxx_wr_cacr .global __cs3_isr_interrupt_80 .global vPortStartFirstTask .text .macro portSAVE_CONTEXT lea.l (-60, %sp), %sp movem.l %d0-%fp, (%sp) move.l pxCurrentTCB, %a0 move.l %sp, (%a0) .endm .macro portRESTORE_CONTEXT move.l pxCurrentTCB, %a0 move.l (%a0), %sp movem.l (%sp), %d0-%fp lea.l %sp@(60), %sp rte .endm /********************************************************************/ /* * This routines changes the IPL to the value passed into the routine. * It also returns the old IPL value back. * Calling convention from C: * old_ipl = asm_set_ipl(new_ipl); * For the Diab Data C compiler, it passes return value thru D0. * Note that only the least significant three bits of the passed * value are used. */ ulPortSetIPL: link A6,#-8 movem.l D6-D7,(SP) move.w SR,D7 /* current sr */ move.l D7,D0 /* prepare return value */ andi.l #0x0700,D0 /* mask out IPL */ lsr.l #8,D0 /* IPL */ move.l 8(A6),D6 /* get argument */ andi.l #0x07,D6 /* least significant three bits */ lsl.l #8,D6 /* move over to make mask */ andi.l #0x0000F8FF,D7 /* zero out current IPL */ or.l D6,D7 /* place new IPL in sr */ move.w D7,SR movem.l (SP),D6-D7 lea 8(SP),SP unlk A6 rts /********************************************************************/ mcf5xxx_wr_cacr: move.l 4(sp),d0 .long 0x4e7b0002 /* movec d0,cacr */ nop rts /********************************************************************/ /* Yield interrupt. */ __cs3_isr_interrupt_80: portSAVE_CONTEXT jsr vPortYieldHandler portRESTORE_CONTEXT /********************************************************************/ vPortStartFirstTask: portRESTORE_CONTEXT .end
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/ColdFire_V2/portasm.S
Motorola 68K Assembly
oos
5,135
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /* Kernel includes. */ #include "FreeRTOS.h" #include "task.h" #define portINITIAL_FORMAT_VECTOR ( ( portSTACK_TYPE ) 0x4000 ) /* Supervisor mode set. */ #define portINITIAL_STATUS_REGISTER ( ( portSTACK_TYPE ) 0x2000) /* Used to keep track of the number of nested calls to taskENTER_CRITICAL(). This will be set to 0 prior to the first task being started. */ static unsigned long ulCriticalNesting = 0x9999UL; /*-----------------------------------------------------------*/ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; pxTopOfStack--; *pxTopOfStack = (portSTACK_TYPE) 0xDEADBEEF; pxTopOfStack--; /* Exception stack frame starts with the return address. */ *pxTopOfStack = ( portSTACK_TYPE ) pxCode; pxTopOfStack--; *pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) | ( portINITIAL_STATUS_REGISTER ); pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x0; /*FP*/ pxTopOfStack -= 14; /* A5 to D0. */ return pxTopOfStack; } /*-----------------------------------------------------------*/ portBASE_TYPE xPortStartScheduler( void ) { extern void vPortStartFirstTask( void ); ulCriticalNesting = 0UL; /* Configure the interrupts used by this port. */ vApplicationSetupInterrupts(); /* Start the first task executing. */ vPortStartFirstTask(); return pdFALSE; } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { /* Not implemented as there is nothing to return to. */ } /*-----------------------------------------------------------*/ void vPortEnterCritical( void ) { if( ulCriticalNesting == 0UL ) { /* Guard against context switches being pended simultaneously with a critical section being entered. */ do { portDISABLE_INTERRUPTS(); if( MCF_INTC0_INTFRCL == 0UL ) { break; } portENABLE_INTERRUPTS(); } while( 1 ); } ulCriticalNesting++; } /*-----------------------------------------------------------*/ void vPortExitCritical( void ) { ulCriticalNesting--; if( ulCriticalNesting == 0 ) { portENABLE_INTERRUPTS(); } } /*-----------------------------------------------------------*/ void vPortYieldHandler( void ) { unsigned long ulSavedInterruptMask; ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR(); /* Note this will clear all forced interrupts - this is done for speed. */ MCF_INTC0_INTFRCL = 0; vTaskSwitchContext(); portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask ); }
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/ColdFire_V2/port.c
C
oos
5,629
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /*----------------------------------------------------------- * Components that can be compiled to either ARM or THUMB mode are * contained in port.c The ISR routines, which can only be compiled * to ARM mode, are contained in this file. *----------------------------------------------------------*/ /* Scheduler includes. */ #include "FreeRTOS.h" #include "task.h" /* Constants required to handle interrupts. */ #define portTIMER_MATCH_ISR_BIT ( ( unsigned portCHAR ) 0x01 ) #define portCLEAR_VIC_INTERRUPT ( ( unsigned portLONG ) 0 ) /* Constants required to handle critical sections. */ #define portNO_CRITICAL_NESTING ( ( unsigned portLONG ) 0 ) volatile unsigned portLONG ulCriticalNesting = 9999UL; /*-----------------------------------------------------------*/ /* ISR to handle manual context switches (from a call to taskYIELD()). */ void vPortYieldProcessor( void ) __attribute__((interrupt("SWI"), naked)); /* * The scheduler can only be started from ARM mode, hence the inclusion of this * function here. */ void vPortISRStartFirstTask( void ); /*-----------------------------------------------------------*/ void vPortISRStartFirstTask( void ) { /* Simply start the scheduler. This is included here as it can only be called from ARM mode. */ portRESTORE_CONTEXT(); } /*-----------------------------------------------------------*/ /* * Called by portYIELD() or taskYIELD() to manually force a context switch. * * When a context switch is performed from the task level the saved task * context is made to look as if it occurred from within the tick ISR. This * way the same restore context function can be used when restoring the context * saved from the ISR or that saved from a call to vPortYieldProcessor. */ void vPortYieldProcessor( void ) { /* Within an IRQ ISR the link register has an offset from the true return address, but an SWI ISR does not. Add the offset manually so the same ISR return code can be used in both cases. */ __asm volatile ( "ADD LR, LR, #4" ); /* Perform the context switch. First save the context of the current task. */ portSAVE_CONTEXT(); /* Find the highest priority task that is ready to run. */ __asm volatile( "bl vTaskSwitchContext" ); /* Restore the context of the new task. */ portRESTORE_CONTEXT(); } /*-----------------------------------------------------------*/ /* * The ISR used for the scheduler tick depends on whether the cooperative or * the preemptive scheduler is being used. */ #if configUSE_PREEMPTION == 0 /* The cooperative scheduler requires a normal IRQ service routine to simply increment the system tick. */ void vNonPreemptiveTick( void ) __attribute__ ((interrupt ("IRQ"))); void vNonPreemptiveTick( void ) { vTaskIncrementTick(); T0IR = 2; VICVectAddr = portCLEAR_VIC_INTERRUPT; } #else /* The preemptive scheduler is defined as "naked" as the full context is saved on entry as part of the context switch. */ void vPreemptiveTick( void ) __attribute__((naked)); void vPreemptiveTick( void ) { /* Save the context of the interrupted task. */ portSAVE_CONTEXT(); /* Increment the RTOS tick count, then look for the highest priority task that is ready to run. */ __asm volatile( "bl vTaskIncrementTick" ); __asm volatile( "bl vTaskSwitchContext" ); /* Ready for the next interrupt. */ T0IR = 2; VICVectAddr = portCLEAR_VIC_INTERRUPT; /* Restore the context of the new task. */ portRESTORE_CONTEXT(); } #endif /*-----------------------------------------------------------*/ /* * The interrupt management utilities can only be called from ARM mode. When * THUMB_INTERWORK is defined the utilities are defined as functions here to * ensure a switch to ARM mode. When THUMB_INTERWORK is not defined then * the utilities are defined as macros in portmacro.h - as per other ports. */ #ifdef THUMB_INTERWORK void vPortDisableInterruptsFromThumb( void ) __attribute__ ((naked)); void vPortEnableInterruptsFromThumb( void ) __attribute__ ((naked)); void vPortDisableInterruptsFromThumb( void ) { __asm volatile ( "STMDB SP!, {R0} \n\t" /* Push R0. */ "MRS R0, CPSR \n\t" /* Get CPSR. */ "ORR R0, R0, #0xC0 \n\t" /* Disable IRQ, FIQ. */ "MSR CPSR, R0 \n\t" /* Write back modified value. */ "LDMIA SP!, {R0} \n\t" /* Pop R0. */ "BX R14" ); /* Return back to thumb. */ } void vPortEnableInterruptsFromThumb( void ) { __asm volatile ( "STMDB SP!, {R0} \n\t" /* Push R0. */ "MRS R0, CPSR \n\t" /* Get CPSR. */ "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */ "MSR CPSR, R0 \n\t" /* Write back modified value. */ "LDMIA SP!, {R0} \n\t" /* Pop R0. */ "BX R14" ); /* Return back to thumb. */ } #endif /* THUMB_INTERWORK */ /* The code generated by the GCC compiler uses the stack in different ways at different optimisation levels. The interrupt flags can therefore not always be saved to the stack. Instead the critical section nesting level is stored in a variable, which is then saved as part of the stack context. */ void vPortEnterCritical( void ) { /* Disable interrupts as per portDISABLE_INTERRUPTS(); */ __asm volatile ( "STMDB SP!, {R0} \n\t" /* Push R0. */ "MRS R0, CPSR \n\t" /* Get CPSR. */ "ORR R0, R0, #0xC0 \n\t" /* Disable IRQ, FIQ. */ "MSR CPSR, R0 \n\t" /* Write back modified value. */ "LDMIA SP!, {R0}" ); /* Pop R0. */ /* Now interrupts are disabled ulCriticalNesting can be accessed directly. Increment ulCriticalNesting to keep a count of how many times portENTER_CRITICAL() has been called. */ ulCriticalNesting++; } void vPortExitCritical( void ) { if( ulCriticalNesting > portNO_CRITICAL_NESTING ) { /* Decrement the nesting count as we are leaving a critical section. */ ulCriticalNesting--; /* If the nesting level has reached zero then interrupts should be re-enabled. */ if( ulCriticalNesting == portNO_CRITICAL_NESTING ) { /* Enable interrupts as per portEXIT_CRITICAL(). */ __asm volatile ( "STMDB SP!, {R0} \n\t" /* Push R0. */ "MRS R0, CPSR \n\t" /* Get CPSR. */ "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */ "MSR CPSR, R0 \n\t" /* Write back modified value. */ "LDMIA SP!, {R0}" ); /* Pop R0. */ } } }
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/ARM7_LPC23xx/portISR.c
C
oos
9,560
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /* Changes from V3.2.3 + Modified portENTER_SWITCHING_ISR() to allow use with GCC V4.0.1. Changes from V3.2.4 + Removed the use of the %0 parameter within the assembler macros and replaced them with hard coded registers. This will ensure the assembler does not select the link register as the temp register as was occasionally happening previously. + The assembler statements are now included in a single asm block rather than each line having its own asm block. Changes from V4.5.0 + Removed the portENTER_SWITCHING_ISR() and portEXIT_SWITCHING_ISR() macros and replaced them with portYIELD_FROM_ISR() macro. Application code should now make use of the portSAVE_CONTEXT() and portRESTORE_CONTEXT() macros as per the V4.5.1 demo code. */ #ifndef PORTMACRO_H #define PORTMACRO_H #ifdef __cplusplus extern "C" { #endif /*----------------------------------------------------------- * Port specific definitions. * * The settings in this file configure FreeRTOS correctly for the * given hardware and compiler. * * These settings should not be altered. *----------------------------------------------------------- */ /* Type definitions. */ #define portCHAR char #define portFLOAT float #define portDOUBLE double #define portLONG long #define portSHORT short #define portSTACK_TYPE unsigned portLONG #define portBASE_TYPE portLONG #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff #else typedef unsigned portLONG portTickType; #define portMAX_DELAY ( portTickType ) 0xffffffff #endif /*-----------------------------------------------------------*/ /* Architecture specifics. */ #define portSTACK_GROWTH ( -1 ) #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) #define portBYTE_ALIGNMENT 8 #define portNOP() __asm volatile ( "NOP" ); /*-----------------------------------------------------------*/ /* Scheduler utilities. */ /* * portRESTORE_CONTEXT, portRESTORE_CONTEXT, portENTER_SWITCHING_ISR * and portEXIT_SWITCHING_ISR can only be called from ARM mode, but * are included here for efficiency. An attempt to call one from * THUMB mode code will result in a compile time error. */ #define portRESTORE_CONTEXT() \ { \ extern volatile void * volatile pxCurrentTCB; \ extern volatile unsigned portLONG ulCriticalNesting; \ \ /* Set the LR to the task stack. */ \ __asm volatile ( \ "LDR R0, =pxCurrentTCB \n\t" \ "LDR R0, [R0] \n\t" \ "LDR LR, [R0] \n\t" \ \ /* The critical nesting depth is the first item on the stack. */ \ /* Load it into the ulCriticalNesting variable. */ \ "LDR R0, =ulCriticalNesting \n\t" \ "LDMFD LR!, {R1} \n\t" \ "STR R1, [R0] \n\t" \ \ /* Get the SPSR from the stack. */ \ "LDMFD LR!, {R0} \n\t" \ "MSR SPSR, R0 \n\t" \ \ /* Restore all system mode registers for the task. */ \ "LDMFD LR, {R0-R14}^ \n\t" \ "NOP \n\t" \ \ /* Restore the return address. */ \ "LDR LR, [LR, #+60] \n\t" \ \ /* And return - correcting the offset in the LR to obtain the */ \ /* correct address. */ \ "SUBS PC, LR, #4 \n\t" \ ); \ ( void ) ulCriticalNesting; \ ( void ) pxCurrentTCB; \ } /*-----------------------------------------------------------*/ #define portSAVE_CONTEXT() \ { \ extern volatile void * volatile pxCurrentTCB; \ extern volatile unsigned portLONG ulCriticalNesting; \ \ /* Push R0 as we are going to use the register. */ \ __asm volatile ( \ "STMDB SP!, {R0} \n\t" \ \ /* Set R0 to point to the task stack pointer. */ \ "STMDB SP,{SP}^ \n\t" \ "NOP \n\t" \ "SUB SP, SP, #4 \n\t" \ "LDMIA SP!,{R0} \n\t" \ \ /* Push the return address onto the stack. */ \ "STMDB R0!, {LR} \n\t" \ \ /* Now we have saved LR we can use it instead of R0. */ \ "MOV LR, R0 \n\t" \ \ /* Pop R0 so we can save it onto the system mode stack. */ \ "LDMIA SP!, {R0} \n\t" \ \ /* Push all the system mode registers onto the task stack. */ \ "STMDB LR,{R0-LR}^ \n\t" \ "NOP \n\t" \ "SUB LR, LR, #60 \n\t" \ \ /* Push the SPSR onto the task stack. */ \ "MRS R0, SPSR \n\t" \ "STMDB LR!, {R0} \n\t" \ \ "LDR R0, =ulCriticalNesting \n\t" \ "LDR R0, [R0] \n\t" \ "STMDB LR!, {R0} \n\t" \ \ /* Store the new top of stack for the task. */ \ "LDR R0, =pxCurrentTCB \n\t" \ "LDR R0, [R0] \n\t" \ "STR LR, [R0] \n\t" \ ); \ ( void ) ulCriticalNesting; \ ( void ) pxCurrentTCB; \ } #define portYIELD_FROM_ISR() vTaskSwitchContext() #define portYIELD() __asm volatile ( "SWI 0" ) /*-----------------------------------------------------------*/ /* Critical section management. */ /* * The interrupt management utilities can only be called from ARM mode. When * THUMB_INTERWORK is defined the utilities are defined as functions in * portISR.c to ensure a switch to ARM mode. When THUMB_INTERWORK is not * defined then the utilities are defined as macros here - as per other ports. */ #ifdef THUMB_INTERWORK extern void vPortDisableInterruptsFromThumb( void ) __attribute__ ((naked)); extern void vPortEnableInterruptsFromThumb( void ) __attribute__ ((naked)); #define portDISABLE_INTERRUPTS() vPortDisableInterruptsFromThumb() #define portENABLE_INTERRUPTS() vPortEnableInterruptsFromThumb() #else #define portDISABLE_INTERRUPTS() \ __asm volatile ( \ "STMDB SP!, {R0} \n\t" /* Push R0. */ \ "MRS R0, CPSR \n\t" /* Get CPSR. */ \ "ORR R0, R0, #0xC0 \n\t" /* Disable IRQ, FIQ. */ \ "MSR CPSR, R0 \n\t" /* Write back modified value. */ \ "LDMIA SP!, {R0} " ) /* Pop R0. */ #define portENABLE_INTERRUPTS() \ __asm volatile ( \ "STMDB SP!, {R0} \n\t" /* Push R0. */ \ "MRS R0, CPSR \n\t" /* Get CPSR. */ \ "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */ \ "MSR CPSR, R0 \n\t" /* Write back modified value. */ \ "LDMIA SP!, {R0} " ) /* Pop R0. */ #endif /* THUMB_INTERWORK */ extern void vPortEnterCritical( void ); extern void vPortExitCritical( void ); #define portENTER_CRITICAL() vPortEnterCritical(); #define portEXIT_CRITICAL() vPortExitCritical(); /*-----------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. */ #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/ARM7_LPC23xx/portmacro.h
C
oos
10,522
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /*----------------------------------------------------------- * Implementation of functions defined in portable.h for the ARM7 port. * * Components that can be compiled to either ARM or THUMB mode are * contained in this file. The ISR routines, which can only be compiled * to ARM mode are contained in portISR.c. *----------------------------------------------------------*/ /* Standard includes. */ #include <stdlib.h> /* Scheduler includes. */ #include "FreeRTOS.h" #include "task.h" /* Constants required to setup the task context. */ #define portINITIAL_SPSR ( ( portSTACK_TYPE ) 0x1f ) /* System mode, ARM mode, interrupts enabled. */ #define portTHUMB_MODE_BIT ( ( portSTACK_TYPE ) 0x20 ) #define portINSTRUCTION_SIZE ( ( portSTACK_TYPE ) 4 ) #define portNO_CRITICAL_SECTION_NESTING ( ( portSTACK_TYPE ) 0 ) /* Constants required to setup the tick ISR. */ #define portENABLE_TIMER ( ( unsigned portCHAR ) 0x01 ) #define portPRESCALE_VALUE 0x00 #define portINTERRUPT_ON_MATCH ( ( unsigned portLONG ) 0x01 ) #define portRESET_COUNT_ON_MATCH ( ( unsigned portLONG ) 0x02 ) /* Constants required to setup the VIC for the tick ISR. */ #define portTIMER_VIC_CHANNEL ( ( unsigned portLONG ) 0x0004 ) #define portTIMER_VIC_CHANNEL_BIT ( ( unsigned portLONG ) 0x0010 ) #define portTIMER_VIC_ENABLE ( ( unsigned portLONG ) 0x0020 ) /*-----------------------------------------------------------*/ /* Setup the timer to generate the tick interrupts. */ static void prvSetupTimerInterrupt( void ); /* * The scheduler can only be started from ARM mode, so * vPortISRStartFirstSTask() is defined in portISR.c. */ extern void vPortISRStartFirstTask( void ); /*-----------------------------------------------------------*/ /* * Initialise the stack of a task to look exactly as if a call to * portSAVE_CONTEXT had been called. * * See header file for description. */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { portSTACK_TYPE *pxOriginalTOS; pxOriginalTOS = pxTopOfStack; /* To ensure asserts in tasks.c don't fail, although in this case the assert is not really required. */ pxTopOfStack--; /* Setup the initial stack of the task. The stack is set exactly as expected by the portRESTORE_CONTEXT() macro. */ /* First on the stack is the return address - which in this case is the start of the task. The offset is added to make the return address appear as it would within an IRQ ISR. */ *pxTopOfStack = ( portSTACK_TYPE ) pxCode + portINSTRUCTION_SIZE; pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x00000000; /* R14 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) pxOriginalTOS; /* Stack used when task starts goes in R13. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x12121212; /* R12 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x11111111; /* R11 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x10101010; /* R10 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x09090909; /* R9 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x08080808; /* R8 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x07070707; /* R7 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x06060606; /* R6 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x05050505; /* R5 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x04040404; /* R4 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x03030303; /* R3 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x02020202; /* R2 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x01010101; /* R1 */ pxTopOfStack--; /* When the task starts is will expect to find the function parameter in R0. */ *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R0 */ pxTopOfStack--; /* The last thing onto the stack is the status register, which is set for system mode, with interrupts enabled. */ *pxTopOfStack = ( portSTACK_TYPE ) portINITIAL_SPSR; if( ( ( unsigned long ) pxCode & 0x01UL ) != 0x00 ) { /* We want the task to start in thumb mode. */ *pxTopOfStack |= portTHUMB_MODE_BIT; } pxTopOfStack--; /* Some optimisation levels use the stack differently to others. This means the interrupt flags cannot always be stored on the stack and will instead be stored in a variable, which is then saved as part of the tasks context. */ *pxTopOfStack = portNO_CRITICAL_SECTION_NESTING; return pxTopOfStack; } /*-----------------------------------------------------------*/ portBASE_TYPE xPortStartScheduler( void ) { /* Start the timer that generates the tick ISR. Interrupts are disabled here already. */ prvSetupTimerInterrupt(); /* Start the first task. */ vPortISRStartFirstTask(); /* Should not get here! */ return 0; } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { /* It is unlikely that the ARM port will require this function as there is nothing to return to. */ } /*-----------------------------------------------------------*/ /* * Setup the timer 0 to generate the tick interrupts at the required frequency. */ static void prvSetupTimerInterrupt( void ) { unsigned portLONG ulCompareMatch; PCLKSEL0 = (PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2); T0TCR = 2; /* Stop and reset the timer */ T0CTCR = 0; /* Timer mode */ /* A 1ms tick does not require the use of the timer prescale. This is defaulted to zero but can be used if necessary. */ T0PR = portPRESCALE_VALUE; /* Calculate the match value required for our wanted tick rate. */ ulCompareMatch = configCPU_CLOCK_HZ / configTICK_RATE_HZ; /* Protect against divide by zero. Using an if() statement still results in a warning - hence the #if. */ #if portPRESCALE_VALUE != 0 { ulCompareMatch /= ( portPRESCALE_VALUE + 1 ); } #endif T0MR1 = ulCompareMatch; /* Generate tick with timer 0 compare match. */ T0MCR = (3 << 3); /* Reset timer on match and generate interrupt */ /* Setup the VIC for the timer. */ VICIntEnable = 0x00000010; /* The ISR installed depends on whether the preemptive or cooperative scheduler is being used. */ #if configUSE_PREEMPTION == 1 { extern void ( vPreemptiveTick )( void ); VICVectAddr4 = ( portLONG ) vPreemptiveTick; } #else { extern void ( vNonPreemptiveTick )( void ); VICVectAddr4 = ( portLONG ) vNonPreemptiveTick; } #endif VICVectCntl4 = 1; /* Start the timer - interrupts are disabled when this function is called so it is okay to do this here. */ T0TCR = portENABLE_TIMER; } /*-----------------------------------------------------------*/
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/ARM7_LPC23xx/port.c
C
oos
9,921
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /* Changes from V1.2.3 + portCPU_CLOSK_HZ definition changed to 8MHz base 10, previously it base 16. */ #ifndef PORTMACRO_H #define PORTMACRO_H #ifdef __cplusplus extern "C" { #endif /*----------------------------------------------------------- * Port specific definitions. * * The settings in this file configure FreeRTOS correctly for the * given hardware and compiler. * * These settings should not be altered. *----------------------------------------------------------- */ /* Type definitions. */ #define portCHAR char #define portFLOAT float #define portDOUBLE double #define portLONG long #define portSHORT int #define portSTACK_TYPE unsigned portCHAR #define portBASE_TYPE char #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff #else typedef unsigned portLONG portTickType; #define portMAX_DELAY ( portTickType ) 0xffffffff #endif /*-----------------------------------------------------------*/ /* Critical section management. */ #define portENTER_CRITICAL() asm volatile ( "in __tmp_reg__, __SREG__" :: ); \ asm volatile ( "cli" :: ); \ asm volatile ( "push __tmp_reg__" :: ) #define portEXIT_CRITICAL() asm volatile ( "pop __tmp_reg__" :: ); \ asm volatile ( "out __SREG__, __tmp_reg__" :: ) #define portDISABLE_INTERRUPTS() asm volatile ( "cli" :: ); #define portENABLE_INTERRUPTS() asm volatile ( "sei" :: ); /*-----------------------------------------------------------*/ /* Architecture specifics. */ #define portSTACK_GROWTH ( -1 ) #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) #define portBYTE_ALIGNMENT 1 #define portNOP() asm volatile ( "nop" ); /*-----------------------------------------------------------*/ /* Kernel utilities. */ extern void vPortYield( void ) __attribute__ ( ( naked ) ); #define portYIELD() vPortYield() /*-----------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. */ #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/ATMega323/portmacro.h
C
oos
5,359
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /* Changes from V2.6.0 + AVR port - Replaced the inb() and outb() functions with direct memory access. This allows the port to be built with the 20050414 build of WinAVR. */ #include <stdlib.h> #include <avr/interrupt.h> #include "FreeRTOS.h" #include "task.h" /*----------------------------------------------------------- * Implementation of functions defined in portable.h for the AVR port. *----------------------------------------------------------*/ /* Start tasks with interrupts enables. */ #define portFLAGS_INT_ENABLED ( ( portSTACK_TYPE ) 0x80 ) /* Hardware constants for timer 1. */ #define portCLEAR_COUNTER_ON_MATCH ( ( unsigned char ) 0x08 ) #define portPRESCALE_64 ( ( unsigned char ) 0x03 ) #define portCLOCK_PRESCALER ( ( unsigned long ) 64 ) #define portCOMPARE_MATCH_A_INTERRUPT_ENABLE ( ( unsigned char ) 0x10 ) /*-----------------------------------------------------------*/ /* We require the address of the pxCurrentTCB variable, but don't want to know any details of its type. */ typedef void tskTCB; extern volatile tskTCB * volatile pxCurrentTCB; /*-----------------------------------------------------------*/ /* * Macro to save all the general purpose registers, the save the stack pointer * into the TCB. * * The first thing we do is save the flags then disable interrupts. This is to * guard our stack against having a context switch interrupt after we have already * pushed the registers onto the stack - causing the 32 registers to be on the * stack twice. * * r1 is set to zero as the compiler expects it to be thus, however some * of the math routines make use of R1. * * The interrupts will have been disabled during the call to portSAVE_CONTEXT() * so we need not worry about reading/writing to the stack pointer. */ #define portSAVE_CONTEXT() \ asm volatile ( "push r0 \n\t" \ "in r0, __SREG__ \n\t" \ "cli \n\t" \ "push r0 \n\t" \ "push r1 \n\t" \ "clr r1 \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 r0, 0x3d \n\t" \ "st x+, r0 \n\t" \ "in r0, 0x3e \n\t" \ "st x+, r0 \n\t" \ ); /* * Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during * the context save so we can write to the stack pointer. */ #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 r1 \n\t" \ "pop r0 \n\t" \ "out __SREG__, r0 \n\t" \ "pop r0 \n\t" \ ); /*-----------------------------------------------------------*/ /* * Perform hardware setup to enable ticks from timer 1, compare match A. */ static void prvSetupTimerInterrupt( void ); /*-----------------------------------------------------------*/ /* * See header file for description. */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { unsigned short usAddress; /* Place a few bytes of known values on the bottom of the stack. This is just useful for debugging. */ *pxTopOfStack = 0x11; pxTopOfStack--; *pxTopOfStack = 0x22; pxTopOfStack--; *pxTopOfStack = 0x33; pxTopOfStack--; /* Simulate how the stack would look after a call to vPortYield() generated by the compiler. */ /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */ /* The start of the task code will be popped off the stack last, so place it on first. */ usAddress = ( unsigned short ) pxCode; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff ); pxTopOfStack--; usAddress >>= 8; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff ); pxTopOfStack--; /* 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 = ( portSTACK_TYPE ) 0x00; /* R0 */ pxTopOfStack--; *pxTopOfStack = portFLAGS_INT_ENABLED; pxTopOfStack--; /* Now the remaining registers. The compiler expects R1 to be 0. */ *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* R1 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x02; /* R2 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x03; /* R3 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x04; /* R4 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x05; /* R5 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x06; /* R6 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x07; /* R7 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x08; /* R8 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x09; /* R9 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x10; /* R10 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x11; /* R11 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x12; /* R12 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x13; /* R13 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x14; /* R14 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x15; /* R15 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x16; /* R16 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x17; /* R17 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x18; /* R18 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x19; /* R19 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x20; /* R20 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x21; /* R21 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x22; /* R22 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x23; /* R23 */ pxTopOfStack--; /* Place the parameter on the stack in the expected location. */ usAddress = ( unsigned short ) pvParameters; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff ); pxTopOfStack--; usAddress >>= 8; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff ); pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x26; /* R26 X */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x27; /* R27 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x28; /* R28 Y */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x29; /* R29 */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x30; /* R30 Z */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x031; /* R31 */ pxTopOfStack--; /*lint +e950 +e611 +e923 */ return pxTopOfStack; } /*-----------------------------------------------------------*/ portBASE_TYPE xPortStartScheduler( void ) { /* Setup the hardware to generate the tick. */ prvSetupTimerInterrupt(); /* Restore the context of the first task that is going to run. */ 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. */ asm volatile ( "ret" ); /* Should not get here. */ return pdTRUE; } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { /* It is unlikely that the AVR port will get stopped. If required simply disable the tick interrupt here. */ } /*-----------------------------------------------------------*/ /* * Manual context switch. The first thing we do is save the registers so we * can use a naked attribute. */ void vPortYield( void ) __attribute__ ( ( naked ) ); void vPortYield( void ) { portSAVE_CONTEXT(); vTaskSwitchContext(); portRESTORE_CONTEXT(); asm volatile ( "ret" ); } /*-----------------------------------------------------------*/ /* * Context switch function used by the tick. This must be identical to * vPortYield() from the call to vTaskSwitchContext() onwards. The only * difference from vPortYield() is the tick count is incremented as the * call comes from the tick ISR. */ void vPortYieldFromTick( void ) __attribute__ ( ( naked ) ); void vPortYieldFromTick( void ) { portSAVE_CONTEXT(); vTaskIncrementTick(); vTaskSwitchContext(); portRESTORE_CONTEXT(); asm volatile ( "ret" ); } /*-----------------------------------------------------------*/ /* * Setup timer 1 compare match A to generate a tick interrupt. */ static void prvSetupTimerInterrupt( void ) { unsigned long ulCompareMatch; unsigned char ucHighByte, ucLowByte; /* Using 16bit timer 1 to generate the tick. Correct fuses must be selected for the configCPU_CLOCK_HZ clock. */ ulCompareMatch = configCPU_CLOCK_HZ / configTICK_RATE_HZ; /* We only have 16 bits so have to scale to get our required tick rate. */ ulCompareMatch /= portCLOCK_PRESCALER; /* Adjust for correct value. */ ulCompareMatch -= ( unsigned long ) 1; /* Setup compare match value for compare match A. Interrupts are disabled before this is called so we need not worry here. */ ucLowByte = ( unsigned char ) ( ulCompareMatch & ( unsigned long ) 0xff ); ulCompareMatch >>= 8; ucHighByte = ( unsigned char ) ( ulCompareMatch & ( unsigned long ) 0xff ); OCR1AH = ucHighByte; OCR1AL = ucLowByte; /* Setup clock source and compare match behaviour. */ ucLowByte = portCLEAR_COUNTER_ON_MATCH | portPRESCALE_64; TCCR1B = ucLowByte; /* Enable the interrupt - this is okay as interrupt are currently globally disabled. */ ucLowByte = TIMSK; ucLowByte |= portCOMPARE_MATCH_A_INTERRUPT_ENABLE; TIMSK = ucLowByte; } /*-----------------------------------------------------------*/ #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. */ void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) ); void SIG_OUTPUT_COMPARE1A( void ) { vPortYieldFromTick(); asm volatile ( "reti" ); } #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(); */ void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal ) ); void SIG_OUTPUT_COMPARE1A( void ) { vTaskIncrementTick(); } #endif
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/ATMega323/port.c
C
oos
15,518
/*This file has been prepared for Doxygen automatic documentation generation.*/ /*! \file ********************************************************************* * * \brief FreeRTOS port source for AVR32 UC3. * * - Compiler: GNU GCC for AVR32 * - Supported devices: All AVR32 devices can be used. * - AppNote: * * \author Atmel Corporation: http://www.atmel.com \n * Support and FAQ: http://support.atmel.no/ * *****************************************************************************/ /* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef PORTMACRO_H #define PORTMACRO_H /*----------------------------------------------------------- * Port specific definitions. * * The settings in this file configure FreeRTOS correctly for the * given hardware and compiler. * * These settings should not be altered. *----------------------------------------------------------- */ #include <avr32/io.h> #include "intc.h" #include "compiler.h" #ifdef __cplusplus extern "C" { #endif /* Type definitions. */ #define portCHAR char #define portFLOAT float #define portDOUBLE double #define portLONG long #define portSHORT short #define portSTACK_TYPE unsigned portLONG #define portBASE_TYPE portLONG #define TASK_DELAY_MS(x) ( (x) /portTICK_RATE_MS ) #define TASK_DELAY_S(x) ( (x)*1000 /portTICK_RATE_MS ) #define TASK_DELAY_MIN(x) ( (x)*60*1000/portTICK_RATE_MS ) #define configTICK_TC_IRQ ATPASTE2(AVR32_TC_IRQ, configTICK_TC_CHANNEL) #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff #else typedef unsigned portLONG portTickType; #define portMAX_DELAY ( portTickType ) 0xffffffff #endif /*-----------------------------------------------------------*/ /* Architecture specifics. */ #define portSTACK_GROWTH ( -1 ) #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) #define portBYTE_ALIGNMENT 4 #define portNOP() {__asm__ __volatile__ ("nop");} /*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/ /* INTC-specific. */ #define DISABLE_ALL_EXCEPTIONS() Disable_global_exception() #define ENABLE_ALL_EXCEPTIONS() Enable_global_exception() #define DISABLE_ALL_INTERRUPTS() Disable_global_interrupt() #define ENABLE_ALL_INTERRUPTS() Enable_global_interrupt() #define DISABLE_INT_LEVEL(int_lev) Disable_interrupt_level(int_lev) #define ENABLE_INT_LEVEL(int_lev) Enable_interrupt_level(int_lev) /* * Debug trace. * Activated if and only if configDBG is nonzero. * Prints a formatted string to stdout. * The current source file name and line number are output with a colon before * the formatted string. * A carriage return and a linefeed are appended to the output. * stdout is redirected to the USART configured by configDBG_USART. * The parameters are the same as for the standard printf function. * There is no return value. * SHALL NOT BE CALLED FROM WITHIN AN INTERRUPT as fputs and printf use malloc, * which is interrupt-unsafe with the current __malloc_lock and __malloc_unlock. */ #if configDBG #define portDBG_TRACE(...) \ {\ fputs(__FILE__ ":" ASTRINGZ(__LINE__) ": ", stdout);\ printf(__VA_ARGS__);\ fputs("\r\n", stdout);\ } #else #define portDBG_TRACE(...) #endif /* Critical section management. */ #define portDISABLE_INTERRUPTS() DISABLE_ALL_INTERRUPTS() #define portENABLE_INTERRUPTS() ENABLE_ALL_INTERRUPTS() extern void vPortEnterCritical( void ); extern void vPortExitCritical( void ); #define portENTER_CRITICAL() vPortEnterCritical(); #define portEXIT_CRITICAL() vPortExitCritical(); /* Added as there is no such function in FreeRTOS. */ extern void *pvPortRealloc( void *pv, size_t xSize ); /*-----------------------------------------------------------*/ /*=============================================================================================*/ /* * Restore Context for cases other than INTi. */ #define portRESTORE_CONTEXT() \ { \ extern volatile unsigned portLONG ulCriticalNesting; \ extern volatile void *volatile pxCurrentTCB; \ \ __asm__ __volatile__ ( \ /* Set SP to point to new stack */ \ "mov r8, LO(%[pxCurrentTCB]) \n\t"\ "orh r8, HI(%[pxCurrentTCB]) \n\t"\ "ld.w r0, r8[0] \n\t"\ "ld.w sp, r0[0] \n\t"\ \ /* Restore ulCriticalNesting variable */ \ "ld.w r0, sp++ \n\t"\ "mov r8, LO(%[ulCriticalNesting]) \n\t"\ "orh r8, HI(%[ulCriticalNesting]) \n\t"\ "st.w r8[0], r0 \n\t"\ \ /* Restore R0..R7 */ \ "ldm sp++, r0-r7 \n\t"\ /* R0-R7 should not be used below this line */ \ /* Skip PC and SR (will do it at the end) */ \ "sub sp, -2*4 \n\t"\ /* Restore R8..R12 and LR */ \ "ldm sp++, r8-r12, lr \n\t"\ /* Restore SR */ \ "ld.w r0, sp[-8*4]\n\t" /* R0 is modified, is restored later. */ \ "mtsr %[SR], r0 \n\t"\ /* Restore r0 */ \ "ld.w r0, sp[-9*4] \n\t"\ /* Restore PC */ \ "ld.w pc, sp[-7*4]" /* Get PC from stack - PC is the 7th register saved */ \ : \ : [ulCriticalNesting] "i" (&ulCriticalNesting), \ [pxCurrentTCB] "i" (&pxCurrentTCB), \ [SR] "i" (AVR32_SR) \ ); \ } /* * portSAVE_CONTEXT_INT() and portRESTORE_CONTEXT_INT(): for INT0..3 exceptions. * portSAVE_CONTEXT_SCALL() and portRESTORE_CONTEXT_SCALL(): for the scall exception. * * Had to make different versions because registers saved on the system stack * are not the same between INT0..3 exceptions and the scall exception. */ // Task context stack layout: // R8 (*) // R9 (*) // R10 (*) // R11 (*) // R12 (*) // R14/LR (*) // R15/PC (*) // SR (*) // R0 // R1 // R2 // R3 // R4 // R5 // R6 // R7 // ulCriticalNesting // (*) automatically done for INT0..INT3, but not for SCALL /* * The ISR used for the scheduler tick depends on whether the cooperative or * the preemptive scheduler is being used. */ #if configUSE_PREEMPTION == 0 /* * portSAVE_CONTEXT_OS_INT() for OS Tick exception. */ #define portSAVE_CONTEXT_OS_INT() \ { \ /* Save R0..R7 */ \ __asm__ __volatile__ ("stm --sp, r0-r7"); \ \ /* With the cooperative scheduler, as there is no context switch by interrupt, */ \ /* there is also no context save. */ \ } /* * portRESTORE_CONTEXT_OS_INT() for Tick exception. */ #define portRESTORE_CONTEXT_OS_INT() \ { \ __asm__ __volatile__ ( \ /* Restore R0..R7 */ \ "ldm sp++, r0-r7\n\t" \ \ /* With the cooperative scheduler, as there is no context switch by interrupt, */ \ /* there is also no context restore. */ \ "rete" \ ); \ } #else /* * portSAVE_CONTEXT_OS_INT() for OS Tick exception. */ #define portSAVE_CONTEXT_OS_INT() \ { \ extern volatile unsigned portLONG ulCriticalNesting; \ extern volatile void *volatile pxCurrentTCB; \ \ /* When we come here */ \ /* Registers R8..R12, LR, PC and SR had already been pushed to system stack */ \ \ __asm__ __volatile__ ( \ /* Save R0..R7 */ \ "stm --sp, r0-r7 \n\t"\ \ /* Save ulCriticalNesting variable - R0 is overwritten */ \ "mov r8, LO(%[ulCriticalNesting])\n\t" \ "orh r8, HI(%[ulCriticalNesting])\n\t" \ "ld.w r0, r8[0] \n\t"\ "st.w --sp, r0 \n\t"\ \ /* Check if INT0 or higher were being handled (case where the OS tick interrupted another */ \ /* interrupt handler (which was of a higher priority level but decided to lower its priority */ \ /* level and allow other lower interrupt level to occur). */ \ /* In this case we don't want to do a task switch because we don't know what the stack */ \ /* currently looks like (we don't know what the interrupted interrupt handler was doing). */ \ /* Saving SP in pxCurrentTCB and then later restoring it (thinking restoring the task) */ \ /* will just be restoring the interrupt handler, no way!!! */ \ /* So, since we won't do a vTaskSwitchContext(), it's of no use to save SP. */ \ "ld.w r0, sp[9*4]\n\t" /* Read SR in stack */ \ "bfextu r0, r0, 22, 3\n\t" /* Extract the mode bits to R0. */ \ "cp.w r0, 1\n\t" /* Compare the mode bits with supervisor mode(b'001) */ \ "brhi LABEL_INT_SKIP_SAVE_CONTEXT_%[LINE] \n\t"\ \ /* Store SP in the first member of the structure pointed to by pxCurrentTCB */ \ /* NOTE: we don't enter a critical section here because all interrupt handlers */ \ /* MUST perform a SAVE_CONTEXT/RESTORE_CONTEXT in the same way as */ \ /* portSAVE_CONTEXT_OS_INT/port_RESTORE_CONTEXT_OS_INT if they call OS functions. */ \ /* => all interrupt handlers must use portENTER_SWITCHING_ISR/portEXIT_SWITCHING_ISR. */ \ "mov r8, LO(%[pxCurrentTCB])\n\t" \ "orh r8, HI(%[pxCurrentTCB])\n\t" \ "ld.w r0, r8[0]\n\t" \ "st.w r0[0], sp\n" \ \ "LABEL_INT_SKIP_SAVE_CONTEXT_%[LINE]:" \ : \ : [ulCriticalNesting] "i" (&ulCriticalNesting), \ [pxCurrentTCB] "i" (&pxCurrentTCB), \ [LINE] "i" (__LINE__) \ ); \ } /* * portRESTORE_CONTEXT_OS_INT() for Tick exception. */ #define portRESTORE_CONTEXT_OS_INT() \ { \ extern volatile unsigned portLONG ulCriticalNesting; \ extern volatile void *volatile pxCurrentTCB; \ \ /* Check if INT0 or higher were being handled (case where the OS tick interrupted another */ \ /* interrupt handler (which was of a higher priority level but decided to lower its priority */ \ /* level and allow other lower interrupt level to occur). */ \ /* In this case we don't want to do a task switch because we don't know what the stack */ \ /* currently looks like (we don't know what the interrupted interrupt handler was doing). */ \ /* Saving SP in pxCurrentTCB and then later restoring it (thinking restoring the task) */ \ /* will just be restoring the interrupt handler, no way!!! */ \ __asm__ __volatile__ ( \ "ld.w r0, sp[9*4]\n\t" /* Read SR in stack */ \ "bfextu r0, r0, 22, 3\n\t" /* Extract the mode bits to R0. */ \ "cp.w r0, 1\n\t" /* Compare the mode bits with supervisor mode(b'001) */ \ "brhi LABEL_INT_SKIP_RESTORE_CONTEXT_%[LINE]" \ : \ : [LINE] "i" (__LINE__) \ ); \ \ /* Else */ \ /* because it is here safe, always call vTaskSwitchContext() since an OS tick occurred. */ \ /* A critical section has to be used here because vTaskSwitchContext handles FreeRTOS linked lists. */\ portENTER_CRITICAL(); \ vTaskSwitchContext(); \ portEXIT_CRITICAL(); \ \ /* Restore all registers */ \ \ __asm__ __volatile__ ( \ /* Set SP to point to new stack */ \ "mov r8, LO(%[pxCurrentTCB]) \n\t"\ "orh r8, HI(%[pxCurrentTCB]) \n\t"\ "ld.w r0, r8[0] \n\t"\ "ld.w sp, r0[0] \n"\ \ "LABEL_INT_SKIP_RESTORE_CONTEXT_%[LINE]: \n\t"\ \ /* Restore ulCriticalNesting variable */ \ "ld.w r0, sp++ \n\t" \ "mov r8, LO(%[ulCriticalNesting]) \n\t"\ "orh r8, HI(%[ulCriticalNesting]) \n\t"\ "st.w r8[0], r0 \n\t"\ \ /* Restore R0..R7 */ \ "ldm sp++, r0-r7 \n\t"\ \ /* Now, the stack should be R8..R12, LR, PC and SR */ \ "rete" \ : \ : [ulCriticalNesting] "i" (&ulCriticalNesting), \ [pxCurrentTCB] "i" (&pxCurrentTCB), \ [LINE] "i" (__LINE__) \ ); \ } #endif /* * portSAVE_CONTEXT_SCALL() for SupervisorCALL exception. * * NOTE: taskYIELD()(== SCALL) MUST NOT be called in a mode > supervisor mode. * */ #define portSAVE_CONTEXT_SCALL() \ { \ extern volatile unsigned portLONG ulCriticalNesting; \ extern volatile void *volatile pxCurrentTCB; \ \ /* Warning: the stack layout after SCALL doesn't match the one after an interrupt. */ \ /* If SR[M2:M0] == 001 */ \ /* PC and SR are on the stack. */ \ /* Else (other modes) */ \ /* Nothing on the stack. */ \ \ /* WARNING NOTE: the else case cannot happen as it is strictly forbidden to call */ \ /* vTaskDelay() and vTaskDelayUntil() OS functions (that result in a taskYield()) */ \ /* in an interrupt|exception handler. */ \ \ __asm__ __volatile__ ( \ /* in order to save R0-R7 */ \ "sub sp, 6*4 \n\t"\ /* Save R0..R7 */ \ "stm --sp, r0-r7 \n\t"\ \ /* in order to save R8-R12 and LR */ \ /* do not use SP if interrupts occurs, SP must be left at bottom of stack */ \ "sub r7, sp,-16*4 \n\t"\ /* Copy PC and SR in other places in the stack. */ \ "ld.w r0, r7[-2*4] \n\t" /* Read SR */\ "st.w r7[-8*4], r0 \n\t" /* Copy SR */\ "ld.w r0, r7[-1*4] \n\t" /* Read PC */\ "st.w r7[-7*4], r0 \n\t" /* Copy PC */\ \ /* Save R8..R12 and LR on the stack. */ \ "stm --r7, r8-r12, lr \n\t"\ \ /* Arriving here we have the following stack organizations: */ \ /* R8..R12, LR, PC, SR, R0..R7. */ \ \ /* Now we can finalize the save. */ \ \ /* Save ulCriticalNesting variable - R0 is overwritten */ \ "mov r8, LO(%[ulCriticalNesting]) \n\t"\ "orh r8, HI(%[ulCriticalNesting]) \n\t"\ "ld.w r0, r8[0] \n\t"\ "st.w --sp, r0" \ : \ : [ulCriticalNesting] "i" (&ulCriticalNesting) \ ); \ \ /* Disable the its which may cause a context switch (i.e. cause a change of */ \ /* pxCurrentTCB). */ \ /* Basically, all accesses to the pxCurrentTCB structure should be put in a */ \ /* critical section because it is a global structure. */ \ portENTER_CRITICAL(); \ \ /* Store SP in the first member of the structure pointed to by pxCurrentTCB */ \ __asm__ __volatile__ ( \ "mov r8, LO(%[pxCurrentTCB]) \n\t"\ "orh r8, HI(%[pxCurrentTCB]) \n\t"\ "ld.w r0, r8[0] \n\t"\ "st.w r0[0], sp" \ : \ : [pxCurrentTCB] "i" (&pxCurrentTCB) \ ); \ } /* * portRESTORE_CONTEXT() for SupervisorCALL exception. */ #define portRESTORE_CONTEXT_SCALL() \ { \ extern volatile unsigned portLONG ulCriticalNesting; \ extern volatile void *volatile pxCurrentTCB; \ \ /* Restore all registers */ \ \ /* Set SP to point to new stack */ \ __asm__ __volatile__ ( \ "mov r8, LO(%[pxCurrentTCB]) \n\t"\ "orh r8, HI(%[pxCurrentTCB]) \n\t"\ "ld.w r0, r8[0] \n\t"\ "ld.w sp, r0[0]" \ : \ : [pxCurrentTCB] "i" (&pxCurrentTCB) \ ); \ \ /* Leave pxCurrentTCB variable access critical section */ \ portEXIT_CRITICAL(); \ \ __asm__ __volatile__ ( \ /* Restore ulCriticalNesting variable */ \ "ld.w r0, sp++ \n\t"\ "mov r8, LO(%[ulCriticalNesting]) \n\t"\ "orh r8, HI(%[ulCriticalNesting]) \n\t"\ "st.w r8[0], r0 \n\t"\ \ /* skip PC and SR */ \ /* do not use SP if interrupts occurs, SP must be left at bottom of stack */ \ "sub r7, sp, -10*4 \n\t"\ /* Restore r8-r12 and LR */ \ "ldm r7++, r8-r12, lr \n\t"\ \ /* RETS will take care of the extra PC and SR restore. */ \ /* So, we have to prepare the stack for this. */ \ "ld.w r0, r7[-8*4] \n\t" /* Read SR */\ "st.w r7[-2*4], r0 \n\t" /* Copy SR */\ "ld.w r0, r7[-7*4] \n\t" /* Read PC */\ "st.w r7[-1*4], r0 \n\t" /* Copy PC */\ \ /* Restore R0..R7 */ \ "ldm sp++, r0-r7 \n\t"\ \ "sub sp, -6*4 \n\t"\ \ "rets" \ : \ : [ulCriticalNesting] "i" (&ulCriticalNesting) \ ); \ } /* * The ISR used depends on whether the cooperative or * the preemptive scheduler is being used. */ #if configUSE_PREEMPTION == 0 /* * ISR entry and exit macros. These are only required if a task switch * is required from the ISR. */ #define portENTER_SWITCHING_ISR() \ { \ /* Save R0..R7 */ \ __asm__ __volatile__ ("stm --sp, r0-r7"); \ \ /* With the cooperative scheduler, as there is no context switch by interrupt, */ \ /* there is also no context save. */ \ } /* * Input parameter: in R12, boolean. Perform a vTaskSwitchContext() if 1 */ #define portEXIT_SWITCHING_ISR() \ { \ __asm__ __volatile__ ( \ /* Restore R0..R7 */ \ "ldm sp++, r0-r7 \n\t"\ \ /* With the cooperative scheduler, as there is no context switch by interrupt, */ \ /* there is also no context restore. */ \ "rete" \ ); \ } #else /* * ISR entry and exit macros. These are only required if a task switch * is required from the ISR. */ #define portENTER_SWITCHING_ISR() \ { \ extern volatile unsigned portLONG ulCriticalNesting; \ extern volatile void *volatile pxCurrentTCB; \ \ /* When we come here */ \ /* Registers R8..R12, LR, PC and SR had already been pushed to system stack */ \ \ __asm__ __volatile__ ( \ /* Save R0..R7 */ \ "stm --sp, r0-r7 \n\t"\ \ /* Save ulCriticalNesting variable - R0 is overwritten */ \ "mov r8, LO(%[ulCriticalNesting]) \n\t"\ "orh r8, HI(%[ulCriticalNesting]) \n\t"\ "ld.w r0, r8[0] \n\t"\ "st.w --sp, r0 \n\t"\ \ /* Check if INT0 or higher were being handled (case where the OS tick interrupted another */ \ /* interrupt handler (which was of a higher priority level but decided to lower its priority */ \ /* level and allow other lower interrupt level to occur). */ \ /* In this case we don't want to do a task switch because we don't know what the stack */ \ /* currently looks like (we don't know what the interrupted interrupt handler was doing). */ \ /* Saving SP in pxCurrentTCB and then later restoring it (thinking restoring the task) */ \ /* will just be restoring the interrupt handler, no way!!! */ \ /* So, since we won't do a vTaskSwitchContext(), it's of no use to save SP. */ \ "ld.w r0, sp[9*4] \n\t" /* Read SR in stack */\ "bfextu r0, r0, 22, 3 \n\t" /* Extract the mode bits to R0. */\ "cp.w r0, 1 \n\t" /* Compare the mode bits with supervisor mode(b'001) */\ "brhi LABEL_ISR_SKIP_SAVE_CONTEXT_%[LINE] \n\t"\ \ /* Store SP in the first member of the structure pointed to by pxCurrentTCB */ \ "mov r8, LO(%[pxCurrentTCB]) \n\t"\ "orh r8, HI(%[pxCurrentTCB]) \n\t"\ "ld.w r0, r8[0] \n\t"\ "st.w r0[0], sp \n"\ \ "LABEL_ISR_SKIP_SAVE_CONTEXT_%[LINE]:" \ : \ : [ulCriticalNesting] "i" (&ulCriticalNesting), \ [pxCurrentTCB] "i" (&pxCurrentTCB), \ [LINE] "i" (__LINE__) \ ); \ } /* * Input parameter: in R12, boolean. Perform a vTaskSwitchContext() if 1 */ #define portEXIT_SWITCHING_ISR() \ { \ extern volatile unsigned portLONG ulCriticalNesting; \ extern volatile void *volatile pxCurrentTCB; \ \ __asm__ __volatile__ ( \ /* Check if INT0 or higher were being handled (case where the OS tick interrupted another */ \ /* interrupt handler (which was of a higher priority level but decided to lower its priority */ \ /* level and allow other lower interrupt level to occur). */ \ /* In this case it's of no use to switch context and restore a new SP because we purposedly */ \ /* did not previously save SP in its TCB. */ \ "ld.w r0, sp[9*4] \n\t" /* Read SR in stack */\ "bfextu r0, r0, 22, 3 \n\t" /* Extract the mode bits to R0. */\ "cp.w r0, 1 \n\t" /* Compare the mode bits with supervisor mode(b'001) */\ "brhi LABEL_ISR_SKIP_RESTORE_CONTEXT_%[LINE] \n\t"\ \ /* If a switch is required then we just need to call */ \ /* vTaskSwitchContext() as the context has already been */ \ /* saved. */ \ "cp.w r12, 1 \n\t" /* Check if Switch context is required. */\ "brne LABEL_ISR_RESTORE_CONTEXT_%[LINE]" \ : \ : [LINE] "i" (__LINE__) \ ); \ \ /* A critical section has to be used here because vTaskSwitchContext handles FreeRTOS linked lists. */ \ portENTER_CRITICAL(); \ vTaskSwitchContext(); \ portEXIT_CRITICAL(); \ \ __asm__ __volatile__ ( \ "LABEL_ISR_RESTORE_CONTEXT_%[LINE]: \n\t"\ /* Restore the context of which ever task is now the highest */ \ /* priority that is ready to run. */ \ \ /* Restore all registers */ \ \ /* Set SP to point to new stack */ \ "mov r8, LO(%[pxCurrentTCB]) \n\t"\ "orh r8, HI(%[pxCurrentTCB]) \n\t"\ "ld.w r0, r8[0] \n\t"\ "ld.w sp, r0[0] \n"\ \ "LABEL_ISR_SKIP_RESTORE_CONTEXT_%[LINE]: \n\t"\ \ /* Restore ulCriticalNesting variable */ \ "ld.w r0, sp++ \n\t"\ "mov r8, LO(%[ulCriticalNesting]) \n\t"\ "orh r8, HI(%[ulCriticalNesting]) \n\t"\ "st.w r8[0], r0 \n\t"\ \ /* Restore R0..R7 */ \ "ldm sp++, r0-r7 \n\t"\ \ /* Now, the stack should be R8..R12, LR, PC and SR */ \ "rete" \ : \ : [ulCriticalNesting] "i" (&ulCriticalNesting), \ [pxCurrentTCB] "i" (&pxCurrentTCB), \ [LINE] "i" (__LINE__) \ ); \ } #endif #define portYIELD() {__asm__ __volatile__ ("scall");} /* Task function macros as described on the FreeRTOS.org WEB site. */ #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/AVR32_UC3/portmacro.h
C
oos
30,359
/*This file is prepared for Doxygen automatic documentation generation.*/ /*! \file ********************************************************************* * * \brief Exception and interrupt vectors. * * This file maps all events supported by an AVR32UC. * * - Compiler: GNU GCC for AVR32 * - Supported devices: All AVR32UC devices with an INTC module can be used. * - AppNote: * * \author Atmel Corporation: http://www.atmel.com \n * Support and FAQ: http://support.atmel.no/ * ******************************************************************************/ /* Copyright (c) 2007, Atmel Corporation All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The name of ATMEL may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <avr32/io.h> #include "intc.h" //! @{ //! \verbatim .section .exception, "ax", @progbits // Start of Exception Vector Table. // EVBA must be aligned with a power of two strictly greater than the EVBA- // relative offset of the last vector. .balign 0x200 // Export symbol. .global _evba .type _evba, @function _evba: .org 0x000 // Unrecoverable Exception. _handle_Unrecoverable_Exception: rjmp $ .org 0x004 // TLB Multiple Hit: UNUSED IN AVR32UC. _handle_TLB_Multiple_Hit: rjmp $ .org 0x008 // Bus Error Data Fetch. _handle_Bus_Error_Data_Fetch: rjmp $ .org 0x00C // Bus Error Instruction Fetch. _handle_Bus_Error_Instruction_Fetch: rjmp $ .org 0x010 // NMI. _handle_NMI: rjmp $ .org 0x014 // Instruction Address. _handle_Instruction_Address: rjmp $ .org 0x018 // ITLB Protection. _handle_ITLB_Protection: rjmp $ .org 0x01C // Breakpoint. _handle_Breakpoint: rjmp $ .org 0x020 // Illegal Opcode. _handle_Illegal_Opcode: rjmp $ .org 0x024 // Unimplemented Instruction. _handle_Unimplemented_Instruction: rjmp $ .org 0x028 // Privilege Violation. _handle_Privilege_Violation: rjmp $ .org 0x02C // Floating-Point: UNUSED IN AVR32UC. _handle_Floating_Point: rjmp $ .org 0x030 // Coprocessor Absent: UNUSED IN AVR32UC. _handle_Coprocessor_Absent: rjmp $ .org 0x034 // Data Address (Read). _handle_Data_Address_Read: rjmp $ .org 0x038 // Data Address (Write). _handle_Data_Address_Write: rjmp $ .org 0x03C // DTLB Protection (Read). _handle_DTLB_Protection_Read: rjmp $ .org 0x040 // DTLB Protection (Write). _handle_DTLB_Protection_Write: rjmp $ .org 0x044 // DTLB Modified: UNUSED IN AVR32UC. _handle_DTLB_Modified: rjmp $ .org 0x050 // ITLB Miss: UNUSED IN AVR32UC. _handle_ITLB_Miss: rjmp $ .org 0x060 // DTLB Miss (Read): UNUSED IN AVR32UC. _handle_DTLB_Miss_Read: rjmp $ .org 0x070 // DTLB Miss (Write): UNUSED IN AVR32UC. _handle_DTLB_Miss_Write: rjmp $ .org 0x100 // Supervisor Call. _handle_Supervisor_Call: lda.w pc, SCALLYield // Interrupt support. // The interrupt controller must provide the offset address relative to EVBA. // Important note: // All interrupts call a C function named _get_interrupt_handler. // This function will read group and interrupt line number to then return in // R12 a pointer to a user-provided interrupt handler. .balign 4 _int0: // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the // CPU upon interrupt entry. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected. mfsr r12, AVR32_SR bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE cp.w r12, 0b110 brlo _int0_normal lddsp r12, sp[0 * 4] stdsp sp[6 * 4], r12 lddsp r12, sp[1 * 4] stdsp sp[7 * 4], r12 lddsp r12, sp[3 * 4] sub sp, -6 * 4 rete _int0_normal: #endif mov r12, 0 // Pass the int_lev parameter to the _get_interrupt_handler function. call _get_interrupt_handler cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler. rete // If this was a spurious interrupt (R12 == NULL), return from event handler. _int1: // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the // CPU upon interrupt entry. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected. mfsr r12, AVR32_SR bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE cp.w r12, 0b110 brlo _int1_normal lddsp r12, sp[0 * 4] stdsp sp[6 * 4], r12 lddsp r12, sp[1 * 4] stdsp sp[7 * 4], r12 lddsp r12, sp[3 * 4] sub sp, -6 * 4 rete _int1_normal: #endif mov r12, 1 // Pass the int_lev parameter to the _get_interrupt_handler function. call _get_interrupt_handler cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler. rete // If this was a spurious interrupt (R12 == NULL), return from event handler. _int2: // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the // CPU upon interrupt entry. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected. mfsr r12, AVR32_SR bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE cp.w r12, 0b110 brlo _int2_normal lddsp r12, sp[0 * 4] stdsp sp[6 * 4], r12 lddsp r12, sp[1 * 4] stdsp sp[7 * 4], r12 lddsp r12, sp[3 * 4] sub sp, -6 * 4 rete _int2_normal: #endif mov r12, 2 // Pass the int_lev parameter to the _get_interrupt_handler function. call _get_interrupt_handler cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler. rete // If this was a spurious interrupt (R12 == NULL), return from event handler. _int3: // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the // CPU upon interrupt entry. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected. mfsr r12, AVR32_SR bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE cp.w r12, 0b110 brlo _int3_normal lddsp r12, sp[0 * 4] stdsp sp[6 * 4], r12 lddsp r12, sp[1 * 4] stdsp sp[7 * 4], r12 lddsp r12, sp[3 * 4] sub sp, -6 * 4 rete _int3_normal: #endif mov r12, 3 // Pass the int_lev parameter to the _get_interrupt_handler function. call _get_interrupt_handler cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler. rete // If this was a spurious interrupt (R12 == NULL), return from event handler. // Constant data area. .balign 4 // Values to store in the interrupt priority registers for the various interrupt priority levels. // The interrupt priority registers contain the interrupt priority level and // the EVBA-relative interrupt vector offset. .global ipr_val .type ipr_val, @object ipr_val: .word (INT0 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int0 - _evba),\ (INT1 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int1 - _evba),\ (INT2 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int2 - _evba),\ (INT3 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int3 - _evba) //! \endverbatim //! @}
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/AVR32_UC3/exception.S
Unix Assembly
oos
9,645
/*This file has been prepared for Doxygen automatic documentation generation.*/ /*! \file ********************************************************************* * * \brief FreeRTOS port source for AVR32 UC3. * * - Compiler: GNU GCC for AVR32 * - Supported devices: All AVR32 devices can be used. * - AppNote: * * \author Atmel Corporation: http://www.atmel.com \n * Support and FAQ: http://support.atmel.no/ * *****************************************************************************/ /* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /* Standard includes. */ #include <sys/cpu.h> #include <sys/usart.h> #include <malloc.h> /* Scheduler includes. */ #include "FreeRTOS.h" #include "task.h" /* AVR32 UC3 includes. */ #include <avr32/io.h> #include "gpio.h" #if( configTICK_USE_TC==1 ) #include "tc.h" #endif /* Constants required to setup the task context. */ #define portINITIAL_SR ( ( portSTACK_TYPE ) 0x00400000 ) /* AVR32 : [M2:M0]=001 I1M=0 I0M=0, GM=0 */ #define portINSTRUCTION_SIZE ( ( portSTACK_TYPE ) 0 ) /* Each task maintains its own critical nesting variable. */ #define portNO_CRITICAL_NESTING ( ( unsigned long ) 0 ) volatile unsigned long ulCriticalNesting = 9999UL; #if( configTICK_USE_TC==0 ) static void prvScheduleNextTick( void ); #else static void prvClearTcInt( void ); #endif /* Setup the timer to generate the tick interrupts. */ static void prvSetupTimerInterrupt( void ); /*-----------------------------------------------------------*/ /* * Low-level initialization routine called during startup, before the main * function. * This version comes in replacement to the default one provided by Newlib. * Newlib's _init_startup only calls init_exceptions, but Newlib's exception * vectors are not compatible with the SCALL management in the current FreeRTOS * port. More low-level initializations are besides added here. */ void _init_startup(void) { /* Import the Exception Vector Base Address. */ extern void _evba; #if configHEAP_INIT extern void __heap_start__; extern void __heap_end__; portBASE_TYPE *pxMem; #endif /* Load the Exception Vector Base Address in the corresponding system register. */ Set_system_register( AVR32_EVBA, ( int ) &_evba ); /* Enable exceptions. */ ENABLE_ALL_EXCEPTIONS(); /* Initialize interrupt handling. */ INTC_init_interrupts(); #if configHEAP_INIT /* Initialize the heap used by malloc. */ for( pxMem = &__heap_start__; pxMem < ( portBASE_TYPE * )&__heap_end__; ) { *pxMem++ = 0xA5A5A5A5; } #endif /* Give the used CPU clock frequency to Newlib, so it can work properly. */ set_cpu_hz( configCPU_CLOCK_HZ ); /* Code section present if and only if the debug trace is activated. */ #if configDBG { static const gpio_map_t DBG_USART_GPIO_MAP = { { configDBG_USART_RX_PIN, configDBG_USART_RX_FUNCTION }, { configDBG_USART_TX_PIN, configDBG_USART_TX_FUNCTION } }; /* Initialize the USART used for the debug trace with the configured parameters. */ set_usart_base( ( void * ) configDBG_USART ); gpio_enable_module( DBG_USART_GPIO_MAP, sizeof( DBG_USART_GPIO_MAP ) / sizeof( DBG_USART_GPIO_MAP[0] ) ); usart_init( configDBG_USART_BAUDRATE ); } #endif } /*-----------------------------------------------------------*/ /* * malloc, realloc and free are meant to be called through respectively * pvPortMalloc, pvPortRealloc and vPortFree. * The latter functions call the former ones from within sections where tasks * are suspended, so the latter functions are task-safe. __malloc_lock and * __malloc_unlock use the same mechanism to also keep the former functions * task-safe as they may be called directly from Newlib's functions. * However, all these functions are interrupt-unsafe and SHALL THEREFORE NOT BE * CALLED FROM WITHIN AN INTERRUPT, because __malloc_lock and __malloc_unlock do * not call portENTER_CRITICAL and portEXIT_CRITICAL in order not to disable * interrupts during memory allocation management as this may be a very time- * consuming process. */ /* * Lock routine called by Newlib on malloc / realloc / free entry to guarantee a * safe section as memory allocation management uses global data. * See the aforementioned details. */ void __malloc_lock(struct _reent *ptr) { vTaskSuspendAll(); } /* * Unlock routine called by Newlib on malloc / realloc / free exit to guarantee * a safe section as memory allocation management uses global data. * See the aforementioned details. */ void __malloc_unlock(struct _reent *ptr) { xTaskResumeAll(); } /*-----------------------------------------------------------*/ /* Added as there is no such function in FreeRTOS. */ void *pvPortRealloc( void *pv, size_t xWantedSize ) { void *pvReturn; vTaskSuspendAll(); { pvReturn = realloc( pv, xWantedSize ); } xTaskResumeAll(); return pvReturn; } /*-----------------------------------------------------------*/ /* The cooperative scheduler requires a normal IRQ service routine to simply increment the system tick. */ /* The preemptive scheduler is defined as "naked" as the full context is saved on entry as part of the context switch. */ __attribute__((__naked__)) static void vTick( void ) { /* Save the context of the interrupted task. */ portSAVE_CONTEXT_OS_INT(); #if( configTICK_USE_TC==1 ) /* Clear the interrupt flag. */ prvClearTcInt(); #else /* Schedule the COUNT&COMPARE match interrupt in (configCPU_CLOCK_HZ/configTICK_RATE_HZ) clock cycles from now. */ prvScheduleNextTick(); #endif /* Because FreeRTOS is not supposed to run with nested interrupts, put all OS calls in a critical section . */ portENTER_CRITICAL(); vTaskIncrementTick(); portEXIT_CRITICAL(); /* Restore the context of the "elected task". */ portRESTORE_CONTEXT_OS_INT(); } /*-----------------------------------------------------------*/ __attribute__((__naked__)) void SCALLYield( void ) { /* Save the context of the interrupted task. */ portSAVE_CONTEXT_SCALL(); vTaskSwitchContext(); portRESTORE_CONTEXT_SCALL(); } /*-----------------------------------------------------------*/ /* The code generated by the GCC compiler uses the stack in different ways at different optimisation levels. The interrupt flags can therefore not always be saved to the stack. Instead the critical section nesting level is stored in a variable, which is then saved as part of the stack context. */ __attribute__((__noinline__)) void vPortEnterCritical( void ) { /* Disable interrupts */ portDISABLE_INTERRUPTS(); /* Now interrupts are disabled ulCriticalNesting can be accessed directly. Increment ulCriticalNesting to keep a count of how many times portENTER_CRITICAL() has been called. */ ulCriticalNesting++; } /*-----------------------------------------------------------*/ __attribute__((__noinline__)) void vPortExitCritical( void ) { if(ulCriticalNesting > portNO_CRITICAL_NESTING) { ulCriticalNesting--; if( ulCriticalNesting == portNO_CRITICAL_NESTING ) { /* Enable all interrupt/exception. */ portENABLE_INTERRUPTS(); } } } /*-----------------------------------------------------------*/ /* * Initialise the stack of a task to look exactly as if a call to * portSAVE_CONTEXT had been called. * * See header file for description. */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { /* Setup the initial stack of the task. The stack is set exactly as expected by the portRESTORE_CONTEXT() macro. */ /* When the task starts, it will expect to find the function parameter in R12. */ pxTopOfStack--; *pxTopOfStack-- = ( portSTACK_TYPE ) 0x08080808; /* R8 */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0x09090909; /* R9 */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0x0A0A0A0A; /* R10 */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0x0B0B0B0B; /* R11 */ *pxTopOfStack-- = ( portSTACK_TYPE ) pvParameters; /* R12 */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0xDEADBEEF; /* R14/LR */ *pxTopOfStack-- = ( portSTACK_TYPE ) pxCode + portINSTRUCTION_SIZE; /* R15/PC */ *pxTopOfStack-- = ( portSTACK_TYPE ) portINITIAL_SR; /* SR */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0xFF0000FF; /* R0 */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0x01010101; /* R1 */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0x02020202; /* R2 */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0x03030303; /* R3 */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0x04040404; /* R4 */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0x05050505; /* R5 */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0x06060606; /* R6 */ *pxTopOfStack-- = ( portSTACK_TYPE ) 0x07070707; /* R7 */ *pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_NESTING; /* ulCriticalNesting */ return pxTopOfStack; } /*-----------------------------------------------------------*/ portBASE_TYPE xPortStartScheduler( void ) { /* Start the timer that generates the tick ISR. Interrupts are disabled here already. */ prvSetupTimerInterrupt(); /* Start the first task. */ portRESTORE_CONTEXT(); /* Should not get here! */ return 0; } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { /* It is unlikely that the AVR32 port will require this function as there is nothing to return to. */ } /*-----------------------------------------------------------*/ /* Schedule the COUNT&COMPARE match interrupt in (configCPU_CLOCK_HZ/configTICK_RATE_HZ) clock cycles from now. */ #if( configTICK_USE_TC==0 ) static void prvScheduleFirstTick(void) { unsigned long lCycles; lCycles = Get_system_register(AVR32_COUNT); lCycles += (configCPU_CLOCK_HZ/configTICK_RATE_HZ); // If lCycles ends up to be 0, make it 1 so that the COMPARE and exception // generation feature does not get disabled. if(0 == lCycles) { lCycles++; } Set_system_register(AVR32_COMPARE, lCycles); } __attribute__((__noinline__)) static void prvScheduleNextTick(void) { unsigned long lCycles, lCount; lCycles = Get_system_register(AVR32_COMPARE); lCycles += (configCPU_CLOCK_HZ/configTICK_RATE_HZ); // If lCycles ends up to be 0, make it 1 so that the COMPARE and exception // generation feature does not get disabled. if(0 == lCycles) { lCycles++; } lCount = Get_system_register(AVR32_COUNT); if( lCycles < lCount ) { // We missed a tick, recover for the next. lCycles += (configCPU_CLOCK_HZ/configTICK_RATE_HZ); } Set_system_register(AVR32_COMPARE, lCycles); } #else __attribute__((__noinline__)) static void prvClearTcInt(void) { AVR32_TC.channel[configTICK_TC_CHANNEL].sr; } #endif /*-----------------------------------------------------------*/ /* Setup the timer to generate the tick interrupts. */ static void prvSetupTimerInterrupt(void) { #if( configTICK_USE_TC==1 ) volatile avr32_tc_t *tc = &AVR32_TC; // Options for waveform genration. tc_waveform_opt_t waveform_opt = { .channel = configTICK_TC_CHANNEL, /* Channel selection. */ .bswtrg = TC_EVT_EFFECT_NOOP, /* Software trigger effect on TIOB. */ .beevt = TC_EVT_EFFECT_NOOP, /* External event effect on TIOB. */ .bcpc = TC_EVT_EFFECT_NOOP, /* RC compare effect on TIOB. */ .bcpb = TC_EVT_EFFECT_NOOP, /* RB compare effect on TIOB. */ .aswtrg = TC_EVT_EFFECT_NOOP, /* Software trigger effect on TIOA. */ .aeevt = TC_EVT_EFFECT_NOOP, /* External event effect on TIOA. */ .acpc = TC_EVT_EFFECT_NOOP, /* RC compare effect on TIOA: toggle. */ .acpa = TC_EVT_EFFECT_NOOP, /* RA compare effect on TIOA: toggle (other possibilities are none, set and clear). */ .wavsel = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,/* Waveform selection: Up mode without automatic trigger on RC compare. */ .enetrg = FALSE, /* External event trigger enable. */ .eevt = 0, /* External event selection. */ .eevtedg = TC_SEL_NO_EDGE, /* External event edge selection. */ .cpcdis = FALSE, /* Counter disable when RC compare. */ .cpcstop = FALSE, /* Counter clock stopped with RC compare. */ .burst = FALSE, /* Burst signal selection. */ .clki = FALSE, /* Clock inversion. */ .tcclks = TC_CLOCK_SOURCE_TC2 /* Internal source clock 2. */ }; tc_interrupt_t tc_interrupt = { .etrgs=0, .ldrbs=0, .ldras=0, .cpcs =1, .cpbs =0, .cpas =0, .lovrs=0, .covfs=0, }; #endif /* Disable all interrupt/exception. */ portDISABLE_INTERRUPTS(); /* Register the compare interrupt handler to the interrupt controller and enable the compare interrupt. */ #if( configTICK_USE_TC==1 ) { INTC_register_interrupt(&vTick, configTICK_TC_IRQ, INT0); /* Initialize the timer/counter. */ tc_init_waveform(tc, &waveform_opt); /* Set the compare triggers. Remember TC counter is 16-bits, so counting second is not possible! That's why we configure it to count ms. */ tc_write_rc( tc, configTICK_TC_CHANNEL, ( configPBA_CLOCK_HZ / 4) / configTICK_RATE_HZ ); tc_configure_interrupts( tc, configTICK_TC_CHANNEL, &tc_interrupt ); /* Start the timer/counter. */ tc_start(tc, configTICK_TC_CHANNEL); } #else { INTC_register_interrupt(&vTick, AVR32_CORE_COMPARE_IRQ, INT0); prvScheduleFirstTick(); } #endif }
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/AVR32_UC3/port.c
C
oos
16,901
.extern pxCurrentTCB .extern vTaskISRHandler .extern vTaskSwitchContext .extern uxCriticalNesting .extern pulISRStack .global __FreeRTOS_interrupt_handler .global VPortYieldASM .global vStartFirstTask .macro portSAVE_CONTEXT /* Make room for the context on the stack. */ addik r1, r1, -132 /* Save r31 so it can then be used. */ swi r31, r1, 4 /* Copy the msr into r31 - this is stacked later. */ mfs r31, rmsr /* Stack general registers. */ swi r30, r1, 12 swi r29, r1, 16 swi r28, r1, 20 swi r27, r1, 24 swi r26, r1, 28 swi r25, r1, 32 swi r24, r1, 36 swi r23, r1, 40 swi r22, r1, 44 swi r21, r1, 48 swi r20, r1, 52 swi r19, r1, 56 swi r18, r1, 60 swi r17, r1, 64 swi r16, r1, 68 swi r15, r1, 72 swi r13, r1, 80 swi r12, r1, 84 swi r11, r1, 88 swi r10, r1, 92 swi r9, r1, 96 swi r8, r1, 100 swi r7, r1, 104 swi r6, r1, 108 swi r5, r1, 112 swi r4, r1, 116 swi r3, r1, 120 swi r2, r1, 124 /* Stack the critical section nesting value. */ lwi r3, r0, uxCriticalNesting swi r3, r1, 128 /* Save the top of stack value to the TCB. */ lwi r3, r0, pxCurrentTCB sw r1, r0, r3 .endm .macro portRESTORE_CONTEXT /* Load the top of stack value from the TCB. */ lwi r3, r0, pxCurrentTCB lw r1, r0, r3 /* Restore the general registers. */ lwi r31, r1, 4 lwi r30, r1, 12 lwi r29, r1, 16 lwi r28, r1, 20 lwi r27, r1, 24 lwi r26, r1, 28 lwi r25, r1, 32 lwi r24, r1, 36 lwi r23, r1, 40 lwi r22, r1, 44 lwi r21, r1, 48 lwi r20, r1, 52 lwi r19, r1, 56 lwi r18, r1, 60 lwi r17, r1, 64 lwi r16, r1, 68 lwi r15, r1, 72 lwi r14, r1, 76 lwi r13, r1, 80 lwi r12, r1, 84 lwi r11, r1, 88 lwi r10, r1, 92 lwi r9, r1, 96 lwi r8, r1, 100 lwi r7, r1, 104 lwi r6, r1, 108 lwi r5, r1, 112 lwi r4, r1, 116 lwi r2, r1, 124 /* Load the critical nesting value. */ lwi r3, r1, 128 swi r3, r0, uxCriticalNesting /* Obtain the MSR value from the stack. */ lwi r3, r1, 8 /* Are interrupts enabled in the MSR? If so return using an return from interrupt instruction to ensure interrupts are enabled only once the task is running again. */ andi r3, r3, 2 beqid r3, 36 or r0, r0, r0 /* Reload the rmsr from the stack, clear the enable interrupt bit in the value before saving back to rmsr register, then return enabling interrupts as we return. */ lwi r3, r1, 8 andi r3, r3, ~2 mts rmsr, r3 lwi r3, r1, 120 addik r1, r1, 132 rtid r14, 0 or r0, r0, r0 /* Reload the rmsr from the stack, place it in the rmsr register, and return without enabling interrupts. */ lwi r3, r1, 8 mts rmsr, r3 lwi r3, r1, 120 addik r1, r1, 132 rtsd r14, 0 or r0, r0, r0 .endm .text .align 2 __FreeRTOS_interrupt_handler: portSAVE_CONTEXT /* Entered via an interrupt so interrupts must be enabled in msr. */ ori r31, r31, 2 /* Stack msr. */ swi r31, r1, 8 /* Stack the return address. As we entered via an interrupt we do not need to modify the return address prior to stacking. */ swi r14, r1, 76 /* Now switch to use the ISR stack. */ lwi r3, r0, pulISRStack add r1, r3, r0 bralid r15, vTaskISRHandler or r0, r0, r0 portRESTORE_CONTEXT VPortYieldASM: portSAVE_CONTEXT /* Stack msr. */ swi r31, r1, 8 /* Modify the return address so we return to the instruction after the exception. */ addi r14, r14, 8 swi r14, r1, 76 /* Now switch to use the ISR stack. */ lwi r3, r0, pulISRStack add r1, r3, r0 bralid r15, vTaskSwitchContext or r0, r0, r0 portRESTORE_CONTEXT vStartFirstTask: portRESTORE_CONTEXT
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/MicroBlaze/portasm.s
Unix Assembly
oos
3,702
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef PORTMACRO_H #define PORTMACRO_H #ifdef __cplusplus extern "C" { #endif /*----------------------------------------------------------- * Port specific definitions. * * The settings in this file configure FreeRTOS correctly for the * given hardware and compiler. * * These settings should not be altered. *----------------------------------------------------------- */ /* Type definitions. */ #define portCHAR char #define portFLOAT float #define portDOUBLE double #define portLONG long #define portSHORT short #define portSTACK_TYPE unsigned portLONG #define portBASE_TYPE portLONG #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff #else typedef unsigned portLONG portTickType; #define portMAX_DELAY ( portTickType ) 0xffffffff #endif /*-----------------------------------------------------------*/ /* Interrupt control macros. */ void microblaze_disable_interrupts( void ); void microblaze_enable_interrupts( void ); #define portDISABLE_INTERRUPTS() microblaze_disable_interrupts() #define portENABLE_INTERRUPTS() microblaze_enable_interrupts() /*-----------------------------------------------------------*/ /* Critical section macros. */ void vPortEnterCritical( void ); void vPortExitCritical( void ); #define portENTER_CRITICAL() { \ extern unsigned portBASE_TYPE uxCriticalNesting; \ microblaze_disable_interrupts(); \ uxCriticalNesting++; \ } #define portEXIT_CRITICAL() { \ extern unsigned portBASE_TYPE uxCriticalNesting; \ /* Interrupts are disabled, so we can */ \ /* access the variable directly. */ \ uxCriticalNesting--; \ if( uxCriticalNesting == 0 ) \ { \ /* The nesting has unwound and we \ can enable interrupts again. */ \ portENABLE_INTERRUPTS(); \ } \ } /*-----------------------------------------------------------*/ /* Task utilities. */ void vPortYield( void ); #define portYIELD() vPortYield() void vTaskSwitchContext(); #define portYIELD_FROM_ISR() vTaskSwitchContext() /*-----------------------------------------------------------*/ /* Hardware specifics. */ #define portBYTE_ALIGNMENT 4 #define portSTACK_GROWTH ( -1 ) #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) #define portNOP() asm volatile ( "NOP" ) /*-----------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. */ #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/MicroBlaze/portmacro.h
C
oos
5,969
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /*----------------------------------------------------------- * Implementation of functions defined in portable.h for the MicroBlaze port. *----------------------------------------------------------*/ /* Scheduler includes. */ #include "FreeRTOS.h" #include "task.h" /* Standard includes. */ #include <string.h> /* Hardware includes. */ #include <xintc.h> #include <xintc_i.h> #include <xtmrctr.h> /* Tasks are started with interrupts enabled. */ #define portINITIAL_MSR_STATE ( ( portSTACK_TYPE ) 0x02 ) /* Tasks are started with a critical section nesting of 0 - however prior to the scheduler being commenced we don't want the critical nesting level to reach zero, so it is initialised to a high value. */ #define portINITIAL_NESTING_VALUE ( 0xff ) /* Our hardware setup only uses one counter. */ #define portCOUNTER_0 0 /* The stack used by the ISR is filled with a known value to assist in debugging. */ #define portISR_STACK_FILL_VALUE 0x55555555 /* Counts the nesting depth of calls to portENTER_CRITICAL(). Each task maintains it's own count, so this variable is saved as part of the task context. */ volatile unsigned portBASE_TYPE uxCriticalNesting = portINITIAL_NESTING_VALUE; /* To limit the amount of stack required by each task, this port uses a separate stack for interrupts. */ unsigned long *pulISRStack; /*-----------------------------------------------------------*/ /* * Sets up the periodic ISR used for the RTOS tick. This uses timer 0, but * could have alternatively used the watchdog timer or timer 1. */ static void prvSetupTimerInterrupt( void ); /*-----------------------------------------------------------*/ /* * Initialise the stack of a task to look exactly as if a call to * portSAVE_CONTEXT had been made. * * See the header file portable.h. */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { extern void *_SDA2_BASE_, *_SDA_BASE_; const unsigned long ulR2 = ( unsigned long ) &_SDA2_BASE_; const unsigned long ulR13 = ( unsigned long ) &_SDA_BASE_; /* Place a few bytes of known values on the bottom of the stack. This is essential for the Microblaze port and these lines must not be omitted. The parameter value will overwrite the 0x22222222 value during the function prologue. */ *pxTopOfStack = ( portSTACK_TYPE ) 0x11111111; pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x22222222; pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x33333333; pxTopOfStack--; /* First stack an initial value for the critical section nesting. This is initialised to zero as tasks are started with interrupts enabled. */ *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* R0. */ /* Place an initial value for all the general purpose registers. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) ulR2; /* R2 - small data area. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x03; /* R3. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x04; /* R4. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;/* R5 contains the function call parameters. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x06; /* R6. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x07; /* R7. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x08; /* R8. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x09; /* R9. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x0a; /* R10. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x0b; /* R11. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x0c; /* R12. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) ulR13; /* R13 - small data read write area. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* R14. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x0f; /* R15. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x10; /* R16. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x11; /* R17. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x12; /* R18. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x13; /* R19. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x14; /* R20. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x15; /* R21. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x16; /* R22. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x17; /* R23. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x18; /* R24. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x19; /* R25. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1a; /* R26. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1b; /* R27. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1c; /* R28. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1d; /* R29. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1e; /* R30. */ pxTopOfStack--; /* The MSR is stacked between R30 and R31. */ *pxTopOfStack = portINITIAL_MSR_STATE; pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x1f; /* R31. */ pxTopOfStack--; /* Return a pointer to the top of the stack we have generated so this can be stored in the task control block for the task. */ return pxTopOfStack; } /*-----------------------------------------------------------*/ portBASE_TYPE xPortStartScheduler( void ) { extern void ( __FreeRTOS_interrupt_Handler )( void ); extern void ( vStartFirstTask )( void ); /* Setup the FreeRTOS interrupt handler. Code copied from crt0.s. */ asm volatile ( "la r6, r0, __FreeRTOS_interrupt_handler \n\t" \ "sw r6, r1, r0 \n\t" \ "lhu r7, r1, r0 \n\t" \ "shi r7, r0, 0x12 \n\t" \ "shi r6, r0, 0x16 " ); /* Setup the hardware to generate the tick. Interrupts are disabled when this function is called. */ prvSetupTimerInterrupt(); /* Allocate the stack to be used by the interrupt handler. */ pulISRStack = ( unsigned long * ) pvPortMalloc( configMINIMAL_STACK_SIZE * sizeof( portSTACK_TYPE ) ); /* Restore the context of the first task that is going to run. */ if( pulISRStack != NULL ) { /* Fill the ISR stack with a known value to facilitate debugging. */ memset( pulISRStack, portISR_STACK_FILL_VALUE, configMINIMAL_STACK_SIZE * sizeof( portSTACK_TYPE ) ); pulISRStack += ( configMINIMAL_STACK_SIZE - 1 ); /* Kick off the first task. */ vStartFirstTask(); } /* Should not get here as the tasks are now running! */ return pdFALSE; } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { /* Not implemented. */ } /*-----------------------------------------------------------*/ /* * Manual context switch called by portYIELD or taskYIELD. */ void vPortYield( void ) { extern void VPortYieldASM( void ); /* Perform the context switch in a critical section to assure it is not interrupted by the tick ISR. It is not a problem to do this as each task maintains it's own interrupt status. */ portENTER_CRITICAL(); /* Jump directly to the yield function to ensure there is no compiler generated prologue code. */ asm volatile ( "bralid r14, VPortYieldASM \n\t" \ "or r0, r0, r0 \n\t" ); portEXIT_CRITICAL(); } /*-----------------------------------------------------------*/ /* * Hardware initialisation to generate the RTOS tick. */ static void prvSetupTimerInterrupt( void ) { XTmrCtr xTimer; const unsigned long ulCounterValue = configCPU_CLOCK_HZ / configTICK_RATE_HZ; unsigned portBASE_TYPE uxMask; /* The OPB timer1 is used to generate the tick. Use the provided library functions to enable the timer and set the tick frequency. */ XTmrCtr_mDisable( XPAR_OPB_TIMER_1_BASEADDR, XPAR_OPB_TIMER_1_DEVICE_ID ); XTmrCtr_Initialize( &xTimer, XPAR_OPB_TIMER_1_DEVICE_ID ); XTmrCtr_mSetLoadReg( XPAR_OPB_TIMER_1_BASEADDR, portCOUNTER_0, ulCounterValue ); XTmrCtr_mSetControlStatusReg( XPAR_OPB_TIMER_1_BASEADDR, portCOUNTER_0, XTC_CSR_LOAD_MASK | XTC_CSR_INT_OCCURED_MASK ); /* Set the timer interrupt enable bit while maintaining the other bit states. */ uxMask = XIntc_In32( ( XPAR_OPB_INTC_0_BASEADDR + XIN_IER_OFFSET ) ); uxMask |= XPAR_OPB_TIMER_1_INTERRUPT_MASK; XIntc_Out32( ( XPAR_OPB_INTC_0_BASEADDR + XIN_IER_OFFSET ), ( uxMask ) ); XTmrCtr_Start( &xTimer, XPAR_OPB_TIMER_1_DEVICE_ID ); XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_1_BASEADDR, portCOUNTER_0, XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK | XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK | XTC_CSR_INT_OCCURED_MASK ); XIntc_mAckIntr( XPAR_INTC_SINGLE_BASEADDR, 1 ); } /*-----------------------------------------------------------*/ /* * The interrupt handler placed in the interrupt vector when the scheduler is * started. The task context has already been saved when this is called. * This handler determines the interrupt source and calls the relevant * peripheral handler. */ void vTaskISRHandler( void ) { static unsigned long ulPending; /* Which interrupts are pending? */ ulPending = XIntc_In32( ( XPAR_INTC_SINGLE_BASEADDR + XIN_IVR_OFFSET ) ); if( ulPending < XPAR_INTC_MAX_NUM_INTR_INPUTS ) { static XIntc_VectorTableEntry *pxTablePtr; static XIntc_Config *pxConfig; static unsigned long ulInterruptMask; ulInterruptMask = ( unsigned long ) 1 << ulPending; /* Get the configuration data using the device ID */ pxConfig = &XIntc_ConfigTable[ ( unsigned long ) XPAR_INTC_SINGLE_DEVICE_ID ]; pxTablePtr = &( pxConfig->HandlerTable[ ulPending ] ); if( pxConfig->AckBeforeService & ( ulInterruptMask ) ) { XIntc_mAckIntr( pxConfig->BaseAddress, ulInterruptMask ); pxTablePtr->Handler( pxTablePtr->CallBackRef ); } else { pxTablePtr->Handler( pxTablePtr->CallBackRef ); XIntc_mAckIntr( pxConfig->BaseAddress, ulInterruptMask ); } } } /*-----------------------------------------------------------*/ /* * Handler for the timer interrupt. */ void vTickISR( void *pvBaseAddress ) { unsigned long ulCSR; /* Increment the RTOS tick - this might cause a task to unblock. */ vTaskIncrementTick(); /* Clear the timer interrupt */ ulCSR = XTmrCtr_mGetControlStatusReg(XPAR_OPB_TIMER_1_BASEADDR, 0); XTmrCtr_mSetControlStatusReg( XPAR_OPB_TIMER_1_BASEADDR, portCOUNTER_0, ulCSR ); /* If we are using the preemptive scheduler then we also need to determine if this tick should cause a context switch. */ #if configUSE_PREEMPTION == 1 vTaskSwitchContext(); #endif } /*-----------------------------------------------------------*/
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/GCC/MicroBlaze/port.c
C
oos
13,814
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef PORTMACRO_H #define PORTMACRO_H #ifdef __cplusplus extern "C" { #endif /*----------------------------------------------------------- * Port specific definitions. * * The settings in this file configure FreeRTOS correctly for the * given hardware and compiler. * * These settings should not be altered. *----------------------------------------------------------- */ /* Type definitions. */ #define portCHAR char #define portFLOAT float #define portDOUBLE long #define portLONG long #define portSHORT int #define portSTACK_TYPE unsigned portSHORT #define portBASE_TYPE portSHORT #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff #else typedef unsigned portLONG portTickType; #define portMAX_DELAY ( portTickType ) 0xffffffff #endif /*-----------------------------------------------------------*/ /* Critical section handling. */ #define portENTER_CRITICAL() __asm{ pushf } \ __asm{ cli } \ #define portEXIT_CRITICAL() __asm{ popf } #define portDISABLE_INTERRUPTS() __asm{ cli } #define portENABLE_INTERRUPTS() __asm{ sti } /*-----------------------------------------------------------*/ /* Hardware specifics. */ #define portNOP() __asm{ nop } #define portSTACK_GROWTH ( -1 ) #define portSWITCH_INT_NUMBER 0x80 #define portYIELD() __asm{ int portSWITCH_INT_NUMBER } #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) #define portBYTE_ALIGNMENT 2 #define portINITIAL_SW ( ( portSTACK_TYPE ) 0x0202 ) /* Start the tasks with interrupts enabled. */ /*-----------------------------------------------------------*/ /* Compiler specifics. */ #define portINPUT_BYTE( xAddr ) inp( xAddr ) #define portOUTPUT_BYTE( xAddr, ucValue ) outp( xAddr, ucValue ) #define portINPUT_WORD( xAddr ) inpw( xAddr ) #define portOUTPUT_WORD( xAddr, usValue ) outpw( xAddr, usValue ) /*-----------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. */ #define portTASK_FUNCTION_PROTO( vTaskFunction, vParameters ) void vTaskFunction( void *pvParameters ) #define portTASK_FUNCTION( vTaskFunction, vParameters ) void vTaskFunction( void *pvParameters ) #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/Paradigm/Tern_EE/large_untested/portmacro.h
C
oos
5,376
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ typedef void tskTCB; extern volatile tskTCB * volatile pxCurrentTCB; extern void vTaskSwitchContext( void ); /* * Saves the stack pointer for one task into its TCB, calls * vTaskSwitchContext() to update the TCB being used, then restores the stack * from the new TCB read to run the task. */ void portSWITCH_CONTEXT( void ); /* * Load the stack pointer from the TCB of the task which is going to be first * to execute. Then force an IRET so the registers and IP are popped off the * stack. */ void portFIRST_CONTEXT( void ); #define portSWITCH_CONTEXT() \ asm { mov ax, seg pxCurrentTCB } \ asm { mov ds, ax } \ asm { les bx, pxCurrentTCB } /* Save the stack pointer into the TCB. */ \ asm { mov es:0x2[ bx ], ss } \ asm { mov es:[ bx ], sp } \ asm { call far ptr vTaskSwitchContext } /* Perform the switch. */ \ asm { mov ax, seg pxCurrentTCB } /* Restore the stack pointer from the TCB. */ \ asm { mov ds, ax } \ asm { les bx, dword ptr pxCurrentTCB } \ asm { mov ss, es:[ bx + 2 ] } \ asm { mov sp, es:[ bx ] } #define portFIRST_CONTEXT() \ asm { mov ax, seg pxCurrentTCB } \ asm { mov ds, ax } \ asm { les bx, dword ptr pxCurrentTCB } \ asm { mov ss, es:[ bx + 2 ] } \ asm { mov sp, es:[ bx ] } \ asm { pop bp } \ asm { pop di } \ asm { pop si } \ asm { pop ds } \ asm { pop es } \ asm { pop dx } \ asm { pop cx } \ asm { pop bx } \ asm { pop ax } \ asm { iret }
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/Paradigm/Tern_EE/large_untested/portasm.h
C
oos
4,717
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /*----------------------------------------------------------- * Implementation of functions defined in portable.h for the Tern EE 186 * port. *----------------------------------------------------------*/ /* Library includes. */ #include <embedded.h> #include <ae.h> /* Scheduler includes. */ #include "FreeRTOS.h" #include "task.h" #include "portasm.h" /* The timer increments every four clocks, hence the divide by 4. */ #define portTIMER_COMPARE ( unsigned short ) ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) / ( unsigned long ) 4 ) /* From the RDC data sheet. */ #define portENABLE_TIMER_AND_INTERRUPT ( unsigned short ) 0xe001 /* Interrupt control. */ #define portEIO_REGISTER 0xff22 #define portCLEAR_INTERRUPT 0x0008 /* Setup the hardware to generate the required tick frequency. */ static void prvSetupTimerInterrupt( void ); /* The ISR used depends on whether the preemptive or cooperative scheduler is being used. */ #if( configUSE_PREEMPTION == 1 ) /* Tick service routine used by the scheduler when preemptive scheduling is being used. */ static void __interrupt __far prvPreemptiveTick( void ); #else /* Tick service routine used by the scheduler when cooperative scheduling is being used. */ static void __interrupt __far prvNonPreemptiveTick( void ); #endif /* Trap routine used by taskYIELD() to manually cause a context switch. */ static void __interrupt __far prvYieldProcessor( void ); /* The timer initialisation functions leave interrupts enabled, which is not what we want. This ISR is installed temporarily in case the timer fires before we get a change to disable interrupts again. */ static void __interrupt __far prvDummyISR( void ); /*-----------------------------------------------------------*/ /* See header file for description. */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { portSTACK_TYPE DS_Reg = 0; /* Place a few bytes of known values on the bottom of the stack. This is just useful for debugging. */ *pxTopOfStack = 0x1111; pxTopOfStack--; *pxTopOfStack = 0x2222; pxTopOfStack--; *pxTopOfStack = 0x3333; pxTopOfStack--; /* We are going to start the scheduler using a return from interrupt instruction to load the program counter, so first there would be the function call with parameters preamble. */ *pxTopOfStack = FP_SEG( pvParameters ); pxTopOfStack--; *pxTopOfStack = FP_OFF( pvParameters ); pxTopOfStack--; *pxTopOfStack = FP_SEG( pxCode ); pxTopOfStack--; *pxTopOfStack = FP_OFF( pxCode ); pxTopOfStack--; /* Next the status register and interrupt return address. */ *pxTopOfStack = portINITIAL_SW; pxTopOfStack--; *pxTopOfStack = FP_SEG( pxCode ); pxTopOfStack--; *pxTopOfStack = FP_OFF( pxCode ); pxTopOfStack--; /* The remaining registers would be pushed on the stack by our context switch function. These are loaded with values simply to make debugging easier. */ *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA; /* AX */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB; /* BX */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC; /* CX */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD; /* DX */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE; /* ES */ pxTopOfStack--; /* We need the true data segment. */ __asm{ MOV DS_Reg, DS }; *pxTopOfStack = DS_Reg; /* DS */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x0123; /* SI */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD; /* DI */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB; /* BP */ return pxTopOfStack; } /*-----------------------------------------------------------*/ portBASE_TYPE xPortStartScheduler( void ) { /* This is called with interrupts already disabled. */ /* Put our manual switch (yield) function on a known vector. */ setvect( portSWITCH_INT_NUMBER, prvYieldProcessor ); /* Setup the tick interrupt. */ prvSetupTimerInterrupt(); /* Kick off the scheduler by setting up the context of the first task. */ portFIRST_CONTEXT(); /* Should not get here! */ return pdFALSE; } /*-----------------------------------------------------------*/ static void __interrupt __far prvDummyISR( void ) { /* The timer initialisation functions leave interrupts enabled, which is not what we want. This ISR is installed temporarily in case the timer fires before we get a change to disable interrupts again. */ outport( portEIO_REGISTER, portCLEAR_INTERRUPT ); } /*-----------------------------------------------------------*/ /* The ISR used depends on whether the preemptive or cooperative scheduler is being used. */ #if( configUSE_PREEMPTION == 1 ) static void __interrupt __far prvPreemptiveTick( void ) { /* Get the scheduler to update the task states following the tick. */ vTaskIncrementTick(); /* Switch in the context of the next task to be run. */ portSWITCH_CONTEXT(); /* Reset interrupt. */ outport( portEIO_REGISTER, portCLEAR_INTERRUPT ); } #else static void __interrupt __far prvNonPreemptiveTick( void ) { /* Same as preemptive tick, but the cooperative scheduler is being used so we don't have to switch in the context of the next task. */ vTaskIncrementTick(); /* Reset interrupt. */ outport( portEIO_REGISTER, portCLEAR_INTERRUPT ); } #endif /*-----------------------------------------------------------*/ static void __interrupt __far prvYieldProcessor( void ) { /* Switch in the context of the next task to be run. */ portSWITCH_CONTEXT(); } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { /* Not implemented. */ } /*-----------------------------------------------------------*/ static void prvSetupTimerInterrupt( void ) { const unsigned short usTimerACompare = portTIMER_COMPARE, usTimerAMode = portENABLE_TIMER_AND_INTERRUPT; const unsigned short usT2_IRQ = 0x13; /* Configure the timer, the dummy handler is used here as the init function leaves interrupts enabled. */ t2_init( usTimerAMode, usTimerACompare, prvDummyISR ); /* Disable interrupts again before installing the real handlers. */ portDISABLE_INTERRUPTS(); #if( configUSE_PREEMPTION == 1 ) /* Tick service routine used by the scheduler when preemptive scheduling is being used. */ setvect( usT2_IRQ, prvPreemptiveTick ); #else /* Tick service routine used by the scheduler when cooperative scheduling is being used. */ setvect( usT2_IRQ, prvNonPreemptiveTick ); #endif }
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/Paradigm/Tern_EE/large_untested/port.c
C
oos
9,688
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef PORTMACRO_H #define PORTMACRO_H #ifdef __cplusplus extern "C" { #endif /*----------------------------------------------------------- * Port specific definitions. * * The settings in this file configure FreeRTOS correctly for the * given hardware and compiler. * * These settings should not be altered. *----------------------------------------------------------- */ /* Type definitions. */ #define portCHAR char #define portFLOAT float #define portDOUBLE long #define portLONG long #define portSHORT int #define portSTACK_TYPE unsigned portSHORT #define portBASE_TYPE portSHORT typedef void ( __interrupt __far *pxISR )(); #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff #else typedef unsigned portLONG portTickType; #define portMAX_DELAY ( portTickType ) 0xffffffff #endif /*-----------------------------------------------------------*/ /* Critical section handling. */ #define portENTER_CRITICAL() __asm{ pushf } \ __asm{ cli } \ #define portEXIT_CRITICAL() __asm{ popf } #define portDISABLE_INTERRUPTS() __asm{ cli } #define portENABLE_INTERRUPTS() __asm{ sti } /*-----------------------------------------------------------*/ /* Hardware specifics. */ #define portNOP() __asm{ nop } #define portSTACK_GROWTH ( -1 ) #define portSWITCH_INT_NUMBER 0x80 #define portYIELD() __asm{ int portSWITCH_INT_NUMBER } #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) #define portBYTE_ALIGNMENT 2 #define portINITIAL_SW ( ( portSTACK_TYPE ) 0x0202 ) /* Start the tasks with interrupts enabled. */ /*-----------------------------------------------------------*/ /* Compiler specifics. */ #define portINPUT_BYTE( xAddr ) inp( xAddr ) #define portOUTPUT_BYTE( xAddr, ucValue ) outp( xAddr, ucValue ) #define portINPUT_WORD( xAddr ) inpw( xAddr ) #define portOUTPUT_WORD( xAddr, usValue ) outpw( xAddr, usValue ) /*-----------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. */ #define portTASK_FUNCTION_PROTO( vTaskFunction, vParameters ) void vTaskFunction( void *pvParameters ) #define portTASK_FUNCTION( vTaskFunction, vParameters ) void vTaskFunction( void *pvParameters ) #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/Paradigm/Tern_EE/small/portmacro.h
C
oos
5,422
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef PORT_ASM_H #define PORT_ASM_H typedef void tskTCB; extern volatile tskTCB * volatile pxCurrentTCB; extern void vTaskSwitchContext( void ); /* * Saves the stack pointer for one task into its TCB, calls * vTaskSwitchContext() to update the TCB being used, then restores the stack * from the new TCB read to run the task. */ void portEND_SWITCHING_ISR( void ); /* * Load the stack pointer from the TCB of the task which is going to be first * to execute. Then force an IRET so the registers and IP are popped off the * stack. */ void portFIRST_CONTEXT( void ); #define portEND_SWITCHING_ISR() \ asm { mov bx, [pxCurrentTCB] } \ asm { mov word ptr [bx], sp } \ asm { call far ptr vTaskSwitchContext } \ asm { mov bx, [pxCurrentTCB] } \ asm { mov sp, [bx] } #define portFIRST_CONTEXT() \ asm { mov bx, [pxCurrentTCB] } \ asm { mov sp, [bx] } \ asm { pop bp } \ asm { pop di } \ asm { pop si } \ asm { pop ds } \ asm { pop es } \ asm { pop dx } \ asm { pop cx } \ asm { pop bx } \ asm { pop ax } \ asm { iret } #endif
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/Paradigm/Tern_EE/small/portasm.h
C
oos
4,295
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /*----------------------------------------------------------- * Implementation of functions defined in portable.h for the Tern EE 186 * port. *----------------------------------------------------------*/ /* Library includes. */ #include <embedded.h> #include <ae.h> /* Scheduler includes. */ #include "FreeRTOS.h" #include "task.h" #include "portasm.h" /* The timer increments every four clocks, hence the divide by 4. */ #define portPRESCALE_VALUE ( 16 ) #define portTIMER_COMPARE ( configCPU_CLOCK_HZ / ( configTICK_RATE_HZ * 4UL ) ) /* From the RDC data sheet. */ #define portENABLE_TIMER_AND_INTERRUPT ( unsigned short ) 0xe00b #define portENABLE_TIMER ( unsigned short ) 0xC001 /* Interrupt control. */ #define portEIO_REGISTER 0xff22 #define portCLEAR_INTERRUPT 0x0008 /* Setup the hardware to generate the required tick frequency. */ static void prvSetupTimerInterrupt( void ); /* The ISR used depends on whether the preemptive or cooperative scheduler is being used. */ #if( configUSE_PREEMPTION == 1 ) /* Tick service routine used by the scheduler when preemptive scheduling is being used. */ static void __interrupt __far prvPreemptiveTick( void ); #else /* Tick service routine used by the scheduler when cooperative scheduling is being used. */ static void __interrupt __far prvNonPreemptiveTick( void ); #endif /* Trap routine used by taskYIELD() to manually cause a context switch. */ static void __interrupt __far prvYieldProcessor( void ); /*-----------------------------------------------------------*/ /* See header file for description. */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { portSTACK_TYPE DS_Reg = 0; /* We need the true data segment. */ __asm{ MOV DS_Reg, DS }; /* Place a few bytes of known values on the bottom of the stack. This is just useful for debugging. */ *pxTopOfStack = 0x1111; pxTopOfStack--; *pxTopOfStack = 0x2222; pxTopOfStack--; *pxTopOfStack = 0x3333; pxTopOfStack--; /* We are going to start the scheduler using a return from interrupt instruction to load the program counter, so first there would be the function call with parameters preamble. */ *pxTopOfStack = FP_OFF( pvParameters ); pxTopOfStack--; *pxTopOfStack = FP_OFF( pxCode ); pxTopOfStack--; /* Next the status register and interrupt return address. */ *pxTopOfStack = portINITIAL_SW; pxTopOfStack--; *pxTopOfStack = FP_SEG( pxCode ); pxTopOfStack--; *pxTopOfStack = FP_OFF( pxCode ); pxTopOfStack--; /* The remaining registers would be pushed on the stack by our context switch function. These are loaded with values simply to make debugging easier. */ *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA; /* AX */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB; /* BX */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC; /* CX */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD; /* DX */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE; /* ES */ pxTopOfStack--; *pxTopOfStack = DS_Reg; /* DS */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x0123; /* SI */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD; /* DI */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB; /* BP */ return pxTopOfStack; } /*-----------------------------------------------------------*/ portBASE_TYPE xPortStartScheduler( void ) { /* This is called with interrupts already disabled. */ /* Put our manual switch (yield) function on a known vector. */ setvect( portSWITCH_INT_NUMBER, prvYieldProcessor ); /* Setup the tick interrupt. */ prvSetupTimerInterrupt(); /* Kick off the scheduler by setting up the context of the first task. */ portFIRST_CONTEXT(); /* Should not get here! */ return pdFALSE; } /*-----------------------------------------------------------*/ /* The ISR used depends on whether the preemptive or cooperative scheduler is being used. */ #if( configUSE_PREEMPTION == 1 ) static void __interrupt __far prvPreemptiveTick( void ) { /* Get the scheduler to update the task states following the tick. */ vTaskIncrementTick(); /* Switch in the context of the next task to be run. */ portEND_SWITCHING_ISR(); /* Reset interrupt. */ outport( portEIO_REGISTER, portCLEAR_INTERRUPT ); } #else static void __interrupt __far prvNonPreemptiveTick( void ) { /* Same as preemptive tick, but the cooperative scheduler is being used so we don't have to switch in the context of the next task. */ vTaskIncrementTick(); /* Reset interrupt. */ outport( portEIO_REGISTER, portCLEAR_INTERRUPT ); } #endif /*-----------------------------------------------------------*/ static void __interrupt __far prvYieldProcessor( void ) { /* Switch in the context of the next task to be run. */ portEND_SWITCHING_ISR(); } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { /* Not implemented. */ } /*-----------------------------------------------------------*/ static void prvSetupTimerInterrupt( void ) { const unsigned long ulCompareValue = portTIMER_COMPARE; unsigned short usTimerCompare; usTimerCompare = ( unsigned short ) ( ulCompareValue >> 4 ); t2_init( portENABLE_TIMER, portPRESCALE_VALUE, NULL ); #if( configUSE_PREEMPTION == 1 ) /* Tick service routine used by the scheduler when preemptive scheduling is being used. */ t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvPreemptiveTick ); #else /* Tick service routine used by the scheduler when cooperative scheduling is being used. */ t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvNonPreemptiveTick ); #endif }
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/portable/Paradigm/Tern_EE/small/port.c
C
oos
8,896
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #include "FreeRTOS.h" #include "task.h" #include "croutine.h" /* * Some kernel aware debuggers require data to be viewed to be global, rather * than file scope. */ #ifdef portREMOVE_STATIC_QUALIFIER #define static #endif /* Lists for ready and blocked co-routines. --------------------*/ static xList pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */ static xList xDelayedCoRoutineList1; /*< Delayed co-routines. */ static xList xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */ static xList * pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */ static xList * pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */ static xList xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */ /* Other file private variables. --------------------------------*/ corCRCB * pxCurrentCoRoutine = NULL; static unsigned portBASE_TYPE uxTopCoRoutineReadyPriority = 0; static portTickType xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0; /* The initial state of the co-routine when it is created. */ #define corINITIAL_STATE ( 0 ) /* * Place the co-routine represented by pxCRCB into the appropriate ready queue * for the priority. It is inserted at the end of the list. * * This macro accesses the co-routine ready lists and therefore must not be * used from within an ISR. */ #define prvAddCoRoutineToReadyQueue( pxCRCB ) \ { \ if( pxCRCB->uxPriority > uxTopCoRoutineReadyPriority ) \ { \ uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \ } \ vListInsertEnd( ( xList * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \ } /* * Utility to ready all the lists used by the scheduler. This is called * automatically upon the creation of the first co-routine. */ static void prvInitialiseCoRoutineLists( void ); /* * Co-routines that are readied by an interrupt cannot be placed directly into * the ready lists (there is no mutual exclusion). Instead they are placed in * in the pending ready list in order that they can later be moved to the ready * list by the co-routine scheduler. */ static void prvCheckPendingReadyList( void ); /* * Macro that looks at the list of co-routines that are currently delayed to * see if any require waking. * * Co-routines are stored in the queue in the order of their wake time - * meaning once one co-routine has been found whose timer has not expired * we need not look any further down the list. */ static void prvCheckDelayedList( void ); /*-----------------------------------------------------------*/ signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex ) { signed portBASE_TYPE xReturn; corCRCB *pxCoRoutine; /* Allocate the memory that will store the co-routine control block. */ pxCoRoutine = ( corCRCB * ) pvPortMalloc( sizeof( corCRCB ) ); if( pxCoRoutine ) { /* If pxCurrentCoRoutine is NULL then this is the first co-routine to be created and the co-routine data structures need initialising. */ if( pxCurrentCoRoutine == NULL ) { pxCurrentCoRoutine = pxCoRoutine; prvInitialiseCoRoutineLists(); } /* Check the priority is within limits. */ if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES ) { uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1; } /* Fill out the co-routine control block from the function parameters. */ pxCoRoutine->uxState = corINITIAL_STATE; pxCoRoutine->uxPriority = uxPriority; pxCoRoutine->uxIndex = uxIndex; pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode; /* Initialise all the other co-routine control block parameters. */ vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) ); vListInitialiseItem( &( pxCoRoutine->xEventListItem ) ); /* Set the co-routine control block as a link back from the xListItem. This is so we can get back to the containing CRCB from a generic item in a list. */ listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine ); listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine ); /* Event lists are always in priority order. */ listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority ); /* Now the co-routine has been initialised it can be added to the ready list at the correct priority. */ prvAddCoRoutineToReadyQueue( pxCoRoutine ); xReturn = pdPASS; } else { xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; } return xReturn; } /*-----------------------------------------------------------*/ void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList ) { portTickType xTimeToWake; /* Calculate the time to wake - this may overflow but this is not a problem. */ xTimeToWake = xCoRoutineTickCount + xTicksToDelay; /* We must remove ourselves from the ready list before adding ourselves to the blocked list as the same list item is used for both lists. */ vListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) ); /* The list item will be inserted in wake time order. */ listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake ); if( xTimeToWake < xCoRoutineTickCount ) { /* Wake time has overflowed. Place this item in the overflow list. */ vListInsert( ( xList * ) pxOverflowDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) ); } else { /* The wake time has not overflowed, so we can use the current block list. */ vListInsert( ( xList * ) pxDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) ); } if( pxEventList ) { /* Also add the co-routine to an event list. If this is done then the function must be called with interrupts disabled. */ vListInsert( pxEventList, &( pxCurrentCoRoutine->xEventListItem ) ); } } /*-----------------------------------------------------------*/ static void prvCheckPendingReadyList( void ) { /* Are there any co-routines waiting to get moved to the ready list? These are co-routines that have been readied by an ISR. The ISR cannot access the ready lists itself. */ while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE ) { corCRCB *pxUnblockedCRCB; /* The pending ready list can be accessed by an ISR. */ portDISABLE_INTERRUPTS(); { pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) ); vListRemove( &( pxUnblockedCRCB->xEventListItem ) ); } portENABLE_INTERRUPTS(); vListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); } } /*-----------------------------------------------------------*/ static void prvCheckDelayedList( void ) { corCRCB *pxCRCB; xPassedTicks = xTaskGetTickCount() - xLastTickCount; while( xPassedTicks ) { xCoRoutineTickCount++; xPassedTicks--; /* If the tick count has overflowed we need to swap the ready lists. */ if( xCoRoutineTickCount == 0 ) { xList * pxTemp; /* Tick count has overflowed so we need to swap the delay lists. If there are any items in pxDelayedCoRoutineList here then there is an error! */ pxTemp = pxDelayedCoRoutineList; pxDelayedCoRoutineList = pxOverflowDelayedCoRoutineList; pxOverflowDelayedCoRoutineList = pxTemp; } /* See if this tick has made a timeout expire. */ while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE ) { pxCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList ); if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) ) { /* Timeout not yet expired. */ break; } portDISABLE_INTERRUPTS(); { /* The event could have occurred just before this critical section. If this is the case then the generic list item will have been moved to the pending ready list and the following line is still valid. Also the pvContainer parameter will have been set to NULL so the following lines are also valid. */ vListRemove( &( pxCRCB->xGenericListItem ) ); /* Is the co-routine waiting on an event also? */ if( pxCRCB->xEventListItem.pvContainer ) { vListRemove( &( pxCRCB->xEventListItem ) ); } } portENABLE_INTERRUPTS(); prvAddCoRoutineToReadyQueue( pxCRCB ); } } xLastTickCount = xCoRoutineTickCount; } /*-----------------------------------------------------------*/ void vCoRoutineSchedule( void ) { /* See if any co-routines readied by events need moving to the ready lists. */ prvCheckPendingReadyList(); /* See if any delayed co-routines have timed out. */ prvCheckDelayedList(); /* Find the highest priority queue that contains ready co-routines. */ while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) ) { if( uxTopCoRoutineReadyPriority == 0 ) { /* No more co-routines to check. */ return; } --uxTopCoRoutineReadyPriority; } /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines of the same priority get an equal share of the processor time. */ listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ); /* Call the co-routine. */ ( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex ); return; } /*-----------------------------------------------------------*/ static void prvInitialiseCoRoutineLists( void ) { unsigned portBASE_TYPE uxPriority; for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ ) { vListInitialise( ( xList * ) &( pxReadyCoRoutineLists[ uxPriority ] ) ); } vListInitialise( ( xList * ) &xDelayedCoRoutineList1 ); vListInitialise( ( xList * ) &xDelayedCoRoutineList2 ); vListInitialise( ( xList * ) &xPendingReadyCoRoutineList ); /* Start with pxDelayedCoRoutineList using list1 and the pxOverflowDelayedCoRoutineList using list2. */ pxDelayedCoRoutineList = &xDelayedCoRoutineList1; pxOverflowDelayedCoRoutineList = &xDelayedCoRoutineList2; } /*-----------------------------------------------------------*/ signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList ) { corCRCB *pxUnblockedCRCB; signed portBASE_TYPE xReturn; /* This function is called from within an interrupt. It can only access event lists and the pending ready list. This function assumes that a check has already been made to ensure pxEventList is not empty. */ pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); vListRemove( &( pxUnblockedCRCB->xEventListItem ) ); vListInsertEnd( ( xList * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) ); if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority ) { xReturn = pdTRUE; } else { xReturn = pdFALSE; } return xReturn; }
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/croutine.c
C
oos
14,871
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /* * This is the list implementation used by the scheduler. While it is tailored * heavily for the schedulers needs, it is also available for use by * application code. * * xLists can only store pointers to xListItems. Each xListItem contains a * numeric value (xItemValue). Most of the time the lists are sorted in * descending item value order. * * Lists are created already containing one list item. The value of this * item is the maximum possible that can be stored, it is therefore always at * the end of the list and acts as a marker. The list member pxHead always * points to this marker - even though it is at the tail of the list. This * is because the tail contains a wrap back pointer to the true head of * the list. * * In addition to it's value, each list item contains a pointer to the next * item in the list (pxNext), a pointer to the list it is in (pxContainer) * and a pointer to back to the object that contains it. These later two * pointers are included for efficiency of list manipulation. There is * effectively a two way link between the object containing the list item and * the list item itself. * * * \page ListIntroduction List Implementation * \ingroup FreeRTOSIntro */ #ifndef LIST_H #define LIST_H #ifdef __cplusplus extern "C" { #endif /* * Definition of the only type of object that a list can contain. */ struct xLIST_ITEM { portTickType xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */ volatile struct xLIST_ITEM * pxNext; /*< Pointer to the next xListItem in the list. */ volatile struct xLIST_ITEM * pxPrevious;/*< Pointer to the previous xListItem in the list. */ void * pvOwner; /*< Pointer to the object (normally a TCB) that contains the list item. There is therefore a two way link between the object containing the list item and the list item itself. */ void * pvContainer; /*< Pointer to the list in which this list item is placed (if any). */ }; typedef struct xLIST_ITEM xListItem; /* For some reason lint wants this as two separate definitions. */ struct xMINI_LIST_ITEM { portTickType xItemValue; volatile struct xLIST_ITEM *pxNext; volatile struct xLIST_ITEM *pxPrevious; }; typedef struct xMINI_LIST_ITEM xMiniListItem; /* * Definition of the type of queue used by the scheduler. */ typedef struct xLIST { volatile unsigned portBASE_TYPE uxNumberOfItems; volatile xListItem * pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to pvListGetOwnerOfNextEntry (). */ volatile xMiniListItem xListEnd; /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */ } xList; /* * Access macro to set the owner of a list item. The owner of a list item * is the object (usually a TCB) that contains the list item. * * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER * \ingroup LinkedList */ #define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) /* * Access macro to set the value of the list item. In most cases the value is * used to sort the list in descending order. * * \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE * \ingroup LinkedList */ #define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( pxListItem )->xItemValue = ( xValue ) /* * Access macro the retrieve the value of the list item. The value can * represent anything - for example a the priority of a task, or the time at * which a task should be unblocked. * * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE * \ingroup LinkedList */ #define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue ) /* * Access macro the retrieve the value of the list item at the head of a given * list. * * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE * \ingroup LinkedList */ #define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList ) ( (&( ( pxList )->xListEnd ))->pxNext->xItemValue ) /* * Access macro to determine if a list contains any items. The macro will * only have the value true if the list is empty. * * \page listLIST_IS_EMPTY listLIST_IS_EMPTY * \ingroup LinkedList */ #define listLIST_IS_EMPTY( pxList ) ( ( pxList )->uxNumberOfItems == ( unsigned portBASE_TYPE ) 0 ) /* * Access macro to return the number of items in the list. */ #define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems ) /* * Access function to obtain the owner of the next entry in a list. * * The list member pxIndex is used to walk through a list. Calling * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list * and returns that entries pxOwner parameter. Using multiple calls to this * function it is therefore possible to move through every item contained in * a list. * * The pxOwner parameter of a list item is a pointer to the object that owns * the list item. In the scheduler this is normally a task control block. * The pxOwner parameter effectively creates a two way link between the list * item and its owner. * * @param pxList The list from which the next item owner is to be returned. * * \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY * \ingroup LinkedList */ #define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \ { \ xList * const pxConstList = ( pxList ); \ /* Increment the index to the next item and return the item, ensuring */ \ /* we don't return the marker used at the end of the list. */ \ ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ if( ( pxConstList )->pxIndex == ( xListItem * ) &( ( pxConstList )->xListEnd ) ) \ { \ ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ } \ ( pxTCB ) = ( pxConstList )->pxIndex->pvOwner; \ } /* * Access function to obtain the owner of the first entry in a list. Lists * are normally sorted in ascending item value order. * * This function returns the pxOwner member of the first item in the list. * The pxOwner parameter of a list item is a pointer to the object that owns * the list item. In the scheduler this is normally a task control block. * The pxOwner parameter effectively creates a two way link between the list * item and its owner. * * @param pxList The list from which the owner of the head item is to be * returned. * * \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY * \ingroup LinkedList */ #define listGET_OWNER_OF_HEAD_ENTRY( pxList ) ( (&( ( pxList )->xListEnd ))->pxNext->pvOwner ) /* * Check to see if a list item is within a list. The list item maintains a * "container" pointer that points to the list it is in. All this macro does * is check to see if the container and the list match. * * @param pxList The list we want to know if the list item is within. * @param pxListItem The list item we want to know if is in the list. * @return pdTRUE is the list item is in the list, otherwise pdFALSE. * pointer against */ #define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) ) /* * Must be called before a list is used! This initialises all the members * of the list structure and inserts the xListEnd item into the list as a * marker to the back of the list. * * @param pxList Pointer to the list being initialised. * * \page vListInitialise vListInitialise * \ingroup LinkedList */ void vListInitialise( xList *pxList ); /* * Must be called before a list item is used. This sets the list container to * null so the item does not think that it is already contained in a list. * * @param pxItem Pointer to the list item being initialised. * * \page vListInitialiseItem vListInitialiseItem * \ingroup LinkedList */ void vListInitialiseItem( xListItem *pxItem ); /* * Insert a list item into a list. The item will be inserted into the list in * a position determined by its item value (descending item value order). * * @param pxList The list into which the item is to be inserted. * * @param pxNewListItem The item to that is to be placed in the list. * * \page vListInsert vListInsert * \ingroup LinkedList */ void vListInsert( xList *pxList, xListItem *pxNewListItem ); /* * Insert a list item into a list. The item will be inserted in a position * such that it will be the last item within the list returned by multiple * calls to listGET_OWNER_OF_NEXT_ENTRY. * * The list member pvIndex is used to walk through a list. Calling * listGET_OWNER_OF_NEXT_ENTRY increments pvIndex to the next item in the list. * Placing an item in a list using vListInsertEnd effectively places the item * in the list position pointed to by pvIndex. This means that every other * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before * the pvIndex parameter again points to the item being inserted. * * @param pxList The list into which the item is to be inserted. * * @param pxNewListItem The list item to be inserted into the list. * * \page vListInsertEnd vListInsertEnd * \ingroup LinkedList */ void vListInsertEnd( xList *pxList, xListItem *pxNewListItem ); /* * Remove an item from a list. The list item has a pointer to the list that * it is in, so only the list item need be passed into the function. * * @param vListRemove The item to be removed. The item will remove itself from * the list pointed to by it's pxContainer parameter. * * \page vListRemove vListRemove * \ingroup LinkedList */ void vListRemove( xListItem *pxItemToRemove ); #ifdef __cplusplus } #endif #endif
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/include/list.h
C
oos
12,949
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef TASK_H #define TASK_H #ifndef INC_FREERTOS_H #error "include FreeRTOS.h must appear in source files before include task.h" #endif #include "portable.h" #include "list.h" #ifdef __cplusplus extern "C" { #endif /*----------------------------------------------------------- * MACROS AND DEFINITIONS *----------------------------------------------------------*/ #define tskKERNEL_VERSION_NUMBER "V7.0.1" /** * task. h * * Type by which tasks are referenced. For example, a call to xTaskCreate * returns (via a pointer parameter) an xTaskHandle variable that can then * be used as a parameter to vTaskDelete to delete the task. * * \page xTaskHandle xTaskHandle * \ingroup Tasks */ typedef void * xTaskHandle; /* * Used internally only. */ typedef struct xTIME_OUT { portBASE_TYPE xOverflowCount; portTickType xTimeOnEntering; } xTimeOutType; /* * Defines the memory ranges allocated to the task when an MPU is used. */ typedef struct xMEMORY_REGION { void *pvBaseAddress; unsigned long ulLengthInBytes; unsigned long ulParameters; } xMemoryRegion; /* * Parameters required to create an MPU protected task. */ typedef struct xTASK_PARAMTERS { pdTASK_CODE pvTaskCode; const signed char * const pcName; unsigned short usStackDepth; void *pvParameters; unsigned portBASE_TYPE uxPriority; portSTACK_TYPE *puxStackBuffer; xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ]; } xTaskParameters; /* * Defines the priority used by the idle task. This must not be modified. * * \ingroup TaskUtils */ #define tskIDLE_PRIORITY ( ( unsigned portBASE_TYPE ) 0U ) /** * task. h * * Macro for forcing a context switch. * * \page taskYIELD taskYIELD * \ingroup SchedulerControl */ #define taskYIELD() portYIELD() /** * task. h * * Macro to mark the start of a critical code region. Preemptive context * switches cannot occur when in a critical region. * * NOTE: This may alter the stack (depending on the portable implementation) * so must be used with care! * * \page taskENTER_CRITICAL taskENTER_CRITICAL * \ingroup SchedulerControl */ #define taskENTER_CRITICAL() portENTER_CRITICAL() /** * task. h * * Macro to mark the end of a critical code region. Preemptive context * switches cannot occur when in a critical region. * * NOTE: This may alter the stack (depending on the portable implementation) * so must be used with care! * * \page taskEXIT_CRITICAL taskEXIT_CRITICAL * \ingroup SchedulerControl */ #define taskEXIT_CRITICAL() portEXIT_CRITICAL() /** * task. h * * Macro to disable all maskable interrupts. * * \page taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS * \ingroup SchedulerControl */ #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS() /** * task. h * * Macro to enable microcontroller interrupts. * * \page taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS * \ingroup SchedulerControl */ #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS() /* Definitions returned by xTaskGetSchedulerState(). */ #define taskSCHEDULER_NOT_STARTED 0 #define taskSCHEDULER_RUNNING 1 #define taskSCHEDULER_SUSPENDED 2 /*----------------------------------------------------------- * TASK CREATION API *----------------------------------------------------------*/ /** * task. h *<pre> portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const char * const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pvCreatedTask );</pre> * * Create a new task and add it to the list of tasks that are ready to run. * * xTaskCreate() can only be used to create a task that has unrestricted * access to the entire microcontroller memory map. Systems that include MPU * support can alternatively create an MPU constrained task using * xTaskCreateRestricted(). * * @param pvTaskCode Pointer to the task entry function. Tasks * must be implemented to never return (i.e. continuous loop). * * @param pcName A descriptive name for the task. This is mainly used to * facilitate debugging. Max length defined by tskMAX_TASK_NAME_LEN - default * is 16. * * @param usStackDepth The size of the task stack specified as the number of * variables the stack can hold - not the number of bytes. For example, if * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes * will be allocated for stack storage. * * @param pvParameters Pointer that will be used as the parameter for the task * being created. * * @param uxPriority The priority at which the task should run. Systems that * include MPU support can optionally create tasks in a privileged (system) * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For * example, to create a privileged task at priority 2 the uxPriority parameter * should be set to ( 2 | portPRIVILEGE_BIT ). * * @param pvCreatedTask Used to pass back a handle by which the created task * can be referenced. * * @return pdPASS if the task was successfully created and added to a ready * list, otherwise an error code defined in the file errors. h * * Example usage: <pre> // Task to be created. void vTaskCode( void * pvParameters ) { for( ;; ) { // Task code goes here. } } // Function that creates a task. void vOtherFunction( void ) { static unsigned char ucParameterToPass; xTaskHandle xHandle; // Create the task, storing the handle. Note that the passed parameter ucParameterToPass // must exist for the lifetime of the task, so in this case is declared static. If it was just an // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time // the new task attempts to access it. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle ); // Use the handle to delete the task. vTaskDelete( xHandle ); } </pre> * \defgroup xTaskCreate xTaskCreate * \ingroup Tasks */ #define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) ) /** * task. h *<pre> portBASE_TYPE xTaskCreateRestricted( xTaskParameters *pxTaskDefinition, xTaskHandle *pxCreatedTask );</pre> * * xTaskCreateRestricted() should only be used in systems that include an MPU * implementation. * * Create a new task and add it to the list of tasks that are ready to run. * The function parameters define the memory regions and associated access * permissions allocated to the task. * * @param pxTaskDefinition Pointer to a structure that contains a member * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API * documentation) plus an optional stack buffer and the memory region * definitions. * * @param pxCreatedTask Used to pass back a handle by which the created task * can be referenced. * * @return pdPASS if the task was successfully created and added to a ready * list, otherwise an error code defined in the file errors. h * * Example usage: <pre> // Create an xTaskParameters structure that defines the task to be created. static const xTaskParameters xCheckTaskParameters = { vATask, // pvTaskCode - the function that implements the task. "ATask", // pcName - just a text name for the task to assist debugging. 100, // usStackDepth - the stack size DEFINED IN WORDS. NULL, // pvParameters - passed into the task function as the function parameters. ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state. cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack. // xRegions - Allocate up to three separate memory regions for access by // the task, with appropriate access permissions. Different processors have // different memory alignment requirements - refer to the FreeRTOS documentation // for full information. { // Base address Length Parameters { cReadWriteArray, 32, portMPU_REGION_READ_WRITE }, { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY }, { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE } } }; int main( void ) { xTaskHandle xHandle; // Create a task from the const structure defined above. The task handle // is requested (the second parameter is not NULL) but in this case just for // demonstration purposes as its not actually used. xTaskCreateRestricted( &xRegTest1Parameters, &xHandle ); // Start the scheduler. vTaskStartScheduler(); // Will only get here if there was insufficient memory to create the idle // task. for( ;; ); } </pre> * \defgroup xTaskCreateRestricted xTaskCreateRestricted * \ingroup Tasks */ #define xTaskCreateRestricted( x, pxCreatedTask ) xTaskGenericCreate( ((x)->pvTaskCode), ((x)->pcName), ((x)->usStackDepth), ((x)->pvParameters), ((x)->uxPriority), (pxCreatedTask), ((x)->puxStackBuffer), ((x)->xRegions) ) /** * task. h *<pre> void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions );</pre> * * Memory regions are assigned to a restricted task when the task is created by * a call to xTaskCreateRestricted(). These regions can be redefined using * vTaskAllocateMPURegions(). * * @param xTask The handle of the task being updated. * * @param xRegions A pointer to an xMemoryRegion structure that contains the * new memory region definitions. * * Example usage: <pre> // Define an array of xMemoryRegion structures that configures an MPU region // allowing read/write access for 1024 bytes starting at the beginning of the // ucOneKByte array. The other two of the maximum 3 definable regions are // unused so set to zero. static const xMemoryRegion xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] = { // Base address Length Parameters { ucOneKByte, 1024, portMPU_REGION_READ_WRITE }, { 0, 0, 0 }, { 0, 0, 0 } }; void vATask( void *pvParameters ) { // This task was created such that it has access to certain regions of // memory as defined by the MPU configuration. At some point it is // desired that these MPU regions are replaced with that defined in the // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions() // for this purpose. NULL is used as the task handle to indicate that this // function should modify the MPU regions of the calling task. vTaskAllocateMPURegions( NULL, xAltRegions ); // Now the task can continue its function, but from this point on can only // access its stack and the ucOneKByte array (unless any other statically // defined or shared regions have been declared elsewhere). } </pre> * \defgroup xTaskCreateRestricted xTaskCreateRestricted * \ingroup Tasks */ void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions ) PRIVILEGED_FUNCTION; /** * task. h * <pre>void vTaskDelete( xTaskHandle pxTask );</pre> * * INCLUDE_vTaskDelete must be defined as 1 for this function to be available. * See the configuration section for more information. * * Remove a task from the RTOS real time kernels management. The task being * deleted will be removed from all ready, blocked, suspended and event lists. * * NOTE: The idle task is responsible for freeing the kernel allocated * memory from tasks that have been deleted. It is therefore important that * the idle task is not starved of microcontroller processing time if your * application makes any calls to vTaskDelete (). Memory allocated by the * task code is not automatically freed, and should be freed before the task * is deleted. * * See the demo application file death.c for sample code that utilises * vTaskDelete (). * * @param pxTask The handle of the task to be deleted. Passing NULL will * cause the calling task to be deleted. * * Example usage: <pre> void vOtherFunction( void ) { xTaskHandle xHandle; // Create the task, storing the handle. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); // Use the handle to delete the task. vTaskDelete( xHandle ); } </pre> * \defgroup vTaskDelete vTaskDelete * \ingroup Tasks */ void vTaskDelete( xTaskHandle pxTaskToDelete ) PRIVILEGED_FUNCTION; /*----------------------------------------------------------- * TASK CONTROL API *----------------------------------------------------------*/ /** * task. h * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre> * * Delay a task for a given number of ticks. The actual time that the * task remains blocked depends on the tick rate. The constant * portTICK_RATE_MS can be used to calculate real time from the tick * rate - with the resolution of one tick period. * * INCLUDE_vTaskDelay must be defined as 1 for this function to be available. * See the configuration section for more information. * * * vTaskDelay() specifies a time at which the task wishes to unblock relative to * the time at which vTaskDelay() is called. For example, specifying a block * period of 100 ticks will cause the task to unblock 100 ticks after * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method * of controlling the frequency of a cyclical task as the path taken through the * code, as well as other task and interrupt activity, will effect the frequency * at which vTaskDelay() gets called and therefore the time at which the task * next executes. See vTaskDelayUntil() for an alternative API function designed * to facilitate fixed frequency execution. It does this by specifying an * absolute time (rather than a relative time) at which the calling task should * unblock. * * @param xTicksToDelay The amount of time, in tick periods, that * the calling task should block. * * Example usage: void vTaskFunction( void * pvParameters ) { void vTaskFunction( void * pvParameters ) { // Block for 500ms. const portTickType xDelay = 500 / portTICK_RATE_MS; for( ;; ) { // Simply toggle the LED every 500ms, blocking between each toggle. vToggleLED(); vTaskDelay( xDelay ); } } * \defgroup vTaskDelay vTaskDelay * \ingroup TaskCtrl */ void vTaskDelay( portTickType xTicksToDelay ) PRIVILEGED_FUNCTION; /** * task. h * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre> * * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available. * See the configuration section for more information. * * Delay a task until a specified time. This function can be used by cyclical * tasks to ensure a constant execution frequency. * * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will * cause a task to block for the specified number of ticks from the time vTaskDelay () is * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed * execution frequency as the time between a task starting to execute and that task * calling vTaskDelay () may not be fixed [the task may take a different path though the * code between calls, or may get interrupted or preempted a different number of times * each time it executes]. * * Whereas vTaskDelay () specifies a wake time relative to the time at which the function * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to * unblock. * * The constant portTICK_RATE_MS can be used to calculate real time from the tick * rate - with the resolution of one tick period. * * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the * task was last unblocked. The variable must be initialised with the current time * prior to its first use (see the example below). Following this the variable is * automatically updated within vTaskDelayUntil (). * * @param xTimeIncrement The cycle time period. The task will be unblocked at * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the * same xTimeIncrement parameter value will cause the task to execute with * a fixed interface period. * * Example usage: <pre> // Perform an action every 10 ticks. void vTaskFunction( void * pvParameters ) { portTickType xLastWakeTime; const portTickType xFrequency = 10; // Initialise the xLastWakeTime variable with the current time. xLastWakeTime = xTaskGetTickCount (); for( ;; ) { // Wait for the next cycle. vTaskDelayUntil( &xLastWakeTime, xFrequency ); // Perform action here. } } </pre> * \defgroup vTaskDelayUntil vTaskDelayUntil * \ingroup TaskCtrl */ void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement ) PRIVILEGED_FUNCTION; /** * task. h * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );</pre> * * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available. * See the configuration section for more information. * * Obtain the priority of any task. * * @param pxTask Handle of the task to be queried. Passing a NULL * handle results in the priority of the calling task being returned. * * @return The priority of pxTask. * * Example usage: <pre> void vAFunction( void ) { xTaskHandle xHandle; // Create a task, storing the handle. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); // ... // Use the handle to obtain the priority of the created task. // It was created with tskIDLE_PRIORITY, but may have changed // it itself. if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY ) { // The task has changed it's priority. } // ... // Is our priority higher than the created task? if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) ) { // Our priority (obtained using NULL handle) is higher. } } </pre> * \defgroup uxTaskPriorityGet uxTaskPriorityGet * \ingroup TaskCtrl */ unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION; /** * task. h * <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre> * * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available. * See the configuration section for more information. * * Set the priority of any task. * * A context switch will occur before the function returns if the priority * being set is higher than the currently executing task. * * @param pxTask Handle to the task for which the priority is being set. * Passing a NULL handle results in the priority of the calling task being set. * * @param uxNewPriority The priority to which the task will be set. * * Example usage: <pre> void vAFunction( void ) { xTaskHandle xHandle; // Create a task, storing the handle. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); // ... // Use the handle to raise the priority of the created task. vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 ); // ... // Use a NULL handle to raise our priority to the same value. vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 ); } </pre> * \defgroup vTaskPrioritySet vTaskPrioritySet * \ingroup TaskCtrl */ void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority ) PRIVILEGED_FUNCTION; /** * task. h * <pre>void vTaskSuspend( xTaskHandle pxTaskToSuspend );</pre> * * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. * See the configuration section for more information. * * Suspend any task. When suspended a task will never get any microcontroller * processing time, no matter what its priority. * * Calls to vTaskSuspend are not accumulative - * i.e. calling vTaskSuspend () twice on the same task still only requires one * call to vTaskResume () to ready the suspended task. * * @param pxTaskToSuspend Handle to the task being suspended. Passing a NULL * handle will cause the calling task to be suspended. * * Example usage: <pre> void vAFunction( void ) { xTaskHandle xHandle; // Create a task, storing the handle. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); // ... // Use the handle to suspend the created task. vTaskSuspend( xHandle ); // ... // The created task will not run during this period, unless // another task calls vTaskResume( xHandle ). //... // Suspend ourselves. vTaskSuspend( NULL ); // We cannot get here unless another task calls vTaskResume // with our handle as the parameter. } </pre> * \defgroup vTaskSuspend vTaskSuspend * \ingroup TaskCtrl */ void vTaskSuspend( xTaskHandle pxTaskToSuspend ) PRIVILEGED_FUNCTION; /** * task. h * <pre>void vTaskResume( xTaskHandle pxTaskToResume );</pre> * * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. * See the configuration section for more information. * * Resumes a suspended task. * * A task that has been suspended by one of more calls to vTaskSuspend () * will be made available for running again by a single call to * vTaskResume (). * * @param pxTaskToResume Handle to the task being readied. * * Example usage: <pre> void vAFunction( void ) { xTaskHandle xHandle; // Create a task, storing the handle. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); // ... // Use the handle to suspend the created task. vTaskSuspend( xHandle ); // ... // The created task will not run during this period, unless // another task calls vTaskResume( xHandle ). //... // Resume the suspended task ourselves. vTaskResume( xHandle ); // The created task will once again get microcontroller processing // time in accordance with it priority within the system. } </pre> * \defgroup vTaskResume vTaskResume * \ingroup TaskCtrl */ void vTaskResume( xTaskHandle pxTaskToResume ) PRIVILEGED_FUNCTION; /** * task. h * <pre>void xTaskResumeFromISR( xTaskHandle pxTaskToResume );</pre> * * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be * available. See the configuration section for more information. * * An implementation of vTaskResume() that can be called from within an ISR. * * A task that has been suspended by one of more calls to vTaskSuspend () * will be made available for running again by a single call to * xTaskResumeFromISR (). * * @param pxTaskToResume Handle to the task being readied. * * \defgroup vTaskResumeFromISR vTaskResumeFromISR * \ingroup TaskCtrl */ portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume ) PRIVILEGED_FUNCTION; /*----------------------------------------------------------- * SCHEDULER CONTROL *----------------------------------------------------------*/ /** * task. h * <pre>void vTaskStartScheduler( void );</pre> * * Starts the real time kernel tick processing. After calling the kernel * has control over which tasks are executed and when. This function * does not return until an executing task calls vTaskEndScheduler (). * * At least one task should be created via a call to xTaskCreate () * before calling vTaskStartScheduler (). The idle task is created * automatically when the first application task is created. * * See the demo application file main.c for an example of creating * tasks and starting the kernel. * * Example usage: <pre> void vAFunction( void ) { // Create at least one task before starting the kernel. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); // Start the real time kernel with preemption. vTaskStartScheduler (); // Will not get here unless a task calls vTaskEndScheduler () } </pre> * * \defgroup vTaskStartScheduler vTaskStartScheduler * \ingroup SchedulerControl */ void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION; /** * task. h * <pre>void vTaskEndScheduler( void );</pre> * * Stops the real time kernel tick. All created tasks will be automatically * deleted and multitasking (either preemptive or cooperative) will * stop. Execution then resumes from the point where vTaskStartScheduler () * was called, as if vTaskStartScheduler () had just returned. * * See the demo application file main. c in the demo/PC directory for an * example that uses vTaskEndScheduler (). * * vTaskEndScheduler () requires an exit function to be defined within the * portable layer (see vPortEndScheduler () in port. c for the PC port). This * performs hardware specific operations such as stopping the kernel tick. * * vTaskEndScheduler () will cause all of the resources allocated by the * kernel to be freed - but will not free resources allocated by application * tasks. * * Example usage: <pre> void vTaskCode( void * pvParameters ) { for( ;; ) { // Task code goes here. // At some point we want to end the real time kernel processing // so call ... vTaskEndScheduler (); } } void vAFunction( void ) { // Create at least one task before starting the kernel. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); // Start the real time kernel with preemption. vTaskStartScheduler (); // Will only get here when the vTaskCode () task has called // vTaskEndScheduler (). When we get here we are back to single task // execution. } </pre> * * \defgroup vTaskEndScheduler vTaskEndScheduler * \ingroup SchedulerControl */ void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION; /** * task. h * <pre>void vTaskSuspendAll( void );</pre> * * Suspends all real time kernel activity while keeping interrupts (including the * kernel tick) enabled. * * After calling vTaskSuspendAll () the calling task will continue to execute * without risk of being swapped out until a call to xTaskResumeAll () has been * made. * * API functions that have the potential to cause a context switch (for example, * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler * is suspended. * * Example usage: <pre> void vTask1( void * pvParameters ) { for( ;; ) { // Task code goes here. // ... // At some point the task wants to perform a long operation during // which it does not want to get swapped out. It cannot use // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the // operation may cause interrupts to be missed - including the // ticks. // Prevent the real time kernel swapping out the task. vTaskSuspendAll (); // Perform the operation here. There is no need to use critical // sections as we have all the microcontroller processing time. // During this time interrupts will still operate and the kernel // tick count will be maintained. // ... // The operation is complete. Restart the kernel. xTaskResumeAll (); } } </pre> * \defgroup vTaskSuspendAll vTaskSuspendAll * \ingroup SchedulerControl */ void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION; /** * task. h * <pre>char xTaskResumeAll( void );</pre> * * Resumes real time kernel activity following a call to vTaskSuspendAll (). * After a call to vTaskSuspendAll () the kernel will take control of which * task is executing at any time. * * @return If resuming the scheduler caused a context switch then pdTRUE is * returned, otherwise pdFALSE is returned. * * Example usage: <pre> void vTask1( void * pvParameters ) { for( ;; ) { // Task code goes here. // ... // At some point the task wants to perform a long operation during // which it does not want to get swapped out. It cannot use // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the // operation may cause interrupts to be missed - including the // ticks. // Prevent the real time kernel swapping out the task. vTaskSuspendAll (); // Perform the operation here. There is no need to use critical // sections as we have all the microcontroller processing time. // During this time interrupts will still operate and the real // time kernel tick count will be maintained. // ... // The operation is complete. Restart the kernel. We want to force // a context switch - but there is no point if resuming the scheduler // caused a context switch already. if( !xTaskResumeAll () ) { taskYIELD (); } } } </pre> * \defgroup xTaskResumeAll xTaskResumeAll * \ingroup SchedulerControl */ signed portBASE_TYPE xTaskResumeAll( void ) PRIVILEGED_FUNCTION; /** * task. h * <pre>signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );</pre> * * Utility task that simply returns pdTRUE if the task referenced by xTask is * currently in the Suspended state, or pdFALSE if the task referenced by xTask * is in any other state. * */ signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask ) PRIVILEGED_FUNCTION; /*----------------------------------------------------------- * TASK UTILITIES *----------------------------------------------------------*/ /** * task. h * <PRE>portTickType xTaskGetTickCount( void );</PRE> * * @return The count of ticks since vTaskStartScheduler was called. * * \page xTaskGetTickCount xTaskGetTickCount * \ingroup TaskUtils */ portTickType xTaskGetTickCount( void ) PRIVILEGED_FUNCTION; /** * task. h * <PRE>portTickType xTaskGetTickCountFromISR( void );</PRE> * * @return The count of ticks since vTaskStartScheduler was called. * * This is a version of xTaskGetTickCount() that is safe to be called from an * ISR - provided that portTickType is the natural word size of the * microcontroller being used or interrupt nesting is either not supported or * not being used. * * \page xTaskGetTickCount xTaskGetTickCount * \ingroup TaskUtils */ portTickType xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION; /** * task. h * <PRE>unsigned short uxTaskGetNumberOfTasks( void );</PRE> * * @return The number of tasks that the real time kernel is currently managing. * This includes all ready, blocked and suspended tasks. A task that * has been deleted but not yet freed by the idle task will also be * included in the count. * * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks * \ingroup TaskUtils */ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION; /** * task. h * <PRE>signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery );</PRE> * * @return The text (human readable) name of the task referenced by the handle * xTaskToQueury. A task can query its own name by either passing in its own * handle, or by setting xTaskToQuery to NULL. INCLUDE_pcTaskGetTaskName must be * set to 1 in FreeRTOSConfig.h for pcTaskGetTaskName() to be available. * * \page pcTaskGetTaskName pcTaskGetTaskName * \ingroup TaskUtils */ signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery ); /** * task. h * <PRE>void vTaskList( char *pcWriteBuffer );</PRE> * * configUSE_TRACE_FACILITY must be defined as 1 for this function to be * available. See the configuration section for more information. * * NOTE: This function will disable interrupts for its duration. It is * not intended for normal application runtime use but as a debug aid. * * Lists all the current tasks, along with their current state and stack * usage high water mark. * * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or * suspended ('S'). * * @param pcWriteBuffer A buffer into which the above mentioned details * will be written, in ascii form. This buffer is assumed to be large * enough to contain the generated report. Approximately 40 bytes per * task should be sufficient. * * \page vTaskList vTaskList * \ingroup TaskUtils */ void vTaskList( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /** * task. h * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE> * * configGENERATE_RUN_TIME_STATS must be defined as 1 for this function * to be available. The application must also then provide definitions * for portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and * portGET_RUN_TIME_COUNTER_VALUE to configure a peripheral timer/counter * and return the timers current count value respectively. The counter * should be at least 10 times the frequency of the tick count. * * NOTE: This function will disable interrupts for its duration. It is * not intended for normal application runtime use but as a debug aid. * * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total * accumulated execution time being stored for each task. The resolution * of the accumulated time value depends on the frequency of the timer * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro. * Calling vTaskGetRunTimeStats() writes the total execution time of each * task into a buffer, both as an absolute count value and as a percentage * of the total system execution time. * * @param pcWriteBuffer A buffer into which the execution times will be * written, in ascii form. This buffer is assumed to be large enough to * contain the generated report. Approximately 40 bytes per task should * be sufficient. * * \page vTaskGetRunTimeStats vTaskGetRunTimeStats * \ingroup TaskUtils */ void vTaskGetRunTimeStats( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /** * task. h * <PRE>void vTaskStartTrace( char * pcBuffer, unsigned portBASE_TYPE uxBufferSize );</PRE> * * Starts a real time kernel activity trace. The trace logs the identity of * which task is running when. * * The trace file is stored in binary format. A separate DOS utility called * convtrce.exe is used to convert this into a tab delimited text file which * can be viewed and plotted in a spread sheet. * * @param pcBuffer The buffer into which the trace will be written. * * @param ulBufferSize The size of pcBuffer in bytes. The trace will continue * until either the buffer in full, or ulTaskEndTrace () is called. * * \page vTaskStartTrace vTaskStartTrace * \ingroup TaskUtils */ void vTaskStartTrace( signed char * pcBuffer, unsigned long ulBufferSize ) PRIVILEGED_FUNCTION; /** * task. h * <PRE>unsigned long ulTaskEndTrace( void );</PRE> * * Stops a kernel activity trace. See vTaskStartTrace (). * * @return The number of bytes that have been written into the trace buffer. * * \page usTaskEndTrace usTaskEndTrace * \ingroup TaskUtils */ unsigned long ulTaskEndTrace( void ) PRIVILEGED_FUNCTION; /** * task.h * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE> * * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for * this function to be available. * * Returns the high water mark of the stack associated with xTask. That is, * the minimum free stack space there has been (in words, so on a 32 bit machine * a value of 1 means 4 bytes) since the task started. The smaller the returned * number the closer the task has come to overflowing its stack. * * @param xTask Handle of the task associated with the stack to be checked. * Set xTask to NULL to check the stack of the calling task. * * @return The smallest amount of free stack space there has been (in bytes) * since the task referenced by xTask was created. */ unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask ) PRIVILEGED_FUNCTION; /* When using trace macros it is sometimes necessary to include tasks.h before FreeRTOS.h. When this is done pdTASK_HOOK_CODE will not yet have been defined, so the following two prototypes will cause a compilation error. This can be fixed by simply guarding against the inclusion of these two prototypes unless they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration constant. */ #ifdef configUSE_APPLICATION_TASK_TAG #if configUSE_APPLICATION_TASK_TAG == 1 /** * task.h * <pre>void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre> * * Sets pxHookFunction to be the task hook function used by the task xTask. * Passing xTask as NULL has the effect of setting the calling tasks hook * function. */ void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction ) PRIVILEGED_FUNCTION; /** * task.h * <pre>void xTaskGetApplicationTaskTag( xTaskHandle xTask );</pre> * * Returns the pxHookFunction value assigned to the task xTask. */ pdTASK_HOOK_CODE xTaskGetApplicationTaskTag( xTaskHandle xTask ) PRIVILEGED_FUNCTION; #endif /* configUSE_APPLICATION_TASK_TAG ==1 */ #endif /* ifdef configUSE_APPLICATION_TASK_TAG */ /** * task.h * <pre>portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre> * * Calls the hook function associated with xTask. Passing xTask as NULL has * the effect of calling the Running tasks (the calling task) hook function. * * pvParameter is passed to the hook function for the task to interpret as it * wants. */ portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter ) PRIVILEGED_FUNCTION; /** * xTaskGetIdleTaskHandle() is only available if * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h. * * Simply returns the handle of the idle task. It is not valid to call * xTaskGetIdleTaskHandle() before the scheduler has been started. */ xTaskHandle xTaskGetIdleTaskHandle( void ); /*----------------------------------------------------------- * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES *----------------------------------------------------------*/ /* * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. * * Called from the real time kernel tick (either preemptive or cooperative), * this increments the tick count and checks if any tasks that are blocked * for a finite period required removing from a blocked list and placing on * a ready list. */ void vTaskIncrementTick( void ) PRIVILEGED_FUNCTION; /* * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. * * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. * * Removes the calling task from the ready list and places it both * on the list of tasks waiting for a particular event, and the * list of delayed tasks. The task will be removed from both lists * and replaced on the ready list should either the event occur (and * there be no higher priority tasks waiting on the same event) or * the delay period expires. * * @param pxEventList The list containing tasks that are blocked waiting * for the event to occur. * * @param xTicksToWait The maximum amount of time that the task should wait * for the event to occur. This is specified in kernel ticks,the constant * portTICK_RATE_MS can be used to convert kernel ticks into a real time * period. */ void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait ) PRIVILEGED_FUNCTION; /* * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. * * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. * * This function performs nearly the same function as vTaskPlaceOnEventList(). * The difference being that this function does not permit tasks to block * indefinitely, whereas vTaskPlaceOnEventList() does. * * @return pdTRUE if the task being removed has a higher priority than the task * making the call, otherwise pdFALSE. */ void vTaskPlaceOnEventListRestricted( const xList * const pxEventList, portTickType xTicksToWait ) PRIVILEGED_FUNCTION; /* * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. * * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. * * Removes a task from both the specified event list and the list of blocked * tasks, and places it on a ready queue. * * xTaskRemoveFromEventList () will be called if either an event occurs to * unblock a task, or the block timeout period expires. * * @return pdTRUE if the task being removed has a higher priority than the task * making the call, otherwise pdFALSE. */ signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList ) PRIVILEGED_FUNCTION; /* * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. * * Sets the pointer to the current TCB to the TCB of the highest priority task * that is ready to run. */ void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION; /* * Return the handle of the calling task. */ xTaskHandle xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION; /* * Capture the current time status for future reference. */ void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut ) PRIVILEGED_FUNCTION; /* * Compare the time status now with that previously captured to see if the * timeout has expired. */ portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait ) PRIVILEGED_FUNCTION; /* * Shortcut used by the queue implementation to prevent unnecessary call to * taskYIELD(); */ void vTaskMissedYield( void ) PRIVILEGED_FUNCTION; /* * Returns the scheduler state as taskSCHEDULER_RUNNING, * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED. */ portBASE_TYPE xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION; /* * Raises the priority of the mutex holder to that of the calling task should * the mutex holder have a priority less than the calling task. */ void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder ) PRIVILEGED_FUNCTION; /* * Set the priority of a task back to its proper priority in the case that it * inherited a higher priority while it was holding a semaphore. */ void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder ) PRIVILEGED_FUNCTION; /* * Generic version of the task creation function which is in turn called by the * xTaskCreate() and xTaskCreateRestricted() macros. */ signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pxTaskCode, const signed char * const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask, portSTACK_TYPE *puxStackBuffer, const xMemoryRegion * const xRegions ) PRIVILEGED_FUNCTION; #ifdef __cplusplus } #endif #endif /* TASK_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/include/task.h
C
oos
46,909
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ /*----------------------------------------------------------- * Portable layer API. Each function must be defined for each port. *----------------------------------------------------------*/ #ifndef PORTABLE_H #define PORTABLE_H /* Include the macro file relevant to the port being used. */ #ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT #include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h" typedef void ( __interrupt __far *pxISR )(); #endif #ifdef OPEN_WATCOM_FLASH_LITE_186_PORT #include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h" typedef void ( __interrupt __far *pxISR )(); #endif #ifdef GCC_MEGA_AVR #include "../portable/GCC/ATMega323/portmacro.h" #endif #ifdef IAR_MEGA_AVR #include "../portable/IAR/ATMega323/portmacro.h" #endif #ifdef MPLAB_PIC24_PORT #include "..\..\Source\portable\MPLAB\PIC24_dsPIC\portmacro.h" #endif #ifdef MPLAB_DSPIC_PORT #include "..\..\Source\portable\MPLAB\PIC24_dsPIC\portmacro.h" #endif #ifdef MPLAB_PIC18F_PORT #include "..\..\Source\portable\MPLAB\PIC18F\portmacro.h" #endif #ifdef MPLAB_PIC32MX_PORT #include "..\..\Source\portable\MPLAB\PIC32MX\portmacro.h" #endif #ifdef _FEDPICC #include "libFreeRTOS/Include/portmacro.h" #endif #ifdef SDCC_CYGNAL #include "../../Source/portable/SDCC/Cygnal/portmacro.h" #endif #ifdef GCC_ARM7 #include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h" #endif #ifdef GCC_ARM7_ECLIPSE #include "portmacro.h" #endif #ifdef ROWLEY_LPC23xx #include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h" #endif #ifdef IAR_MSP430 #include "..\..\Source\portable\IAR\MSP430\portmacro.h" #endif #ifdef GCC_MSP430 #include "../../Source/portable/GCC/MSP430F449/portmacro.h" #endif #ifdef ROWLEY_MSP430 #include "../../Source/portable/Rowley/MSP430F449/portmacro.h" #endif #ifdef ARM7_LPC21xx_KEIL_RVDS #include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h" #endif #ifdef SAM7_GCC #include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h" #endif #ifdef SAM7_IAR #include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h" #endif #ifdef SAM9XE_IAR #include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h" #endif #ifdef LPC2000_IAR #include "..\..\Source\portable\IAR\LPC2000\portmacro.h" #endif #ifdef STR71X_IAR #include "..\..\Source\portable\IAR\STR71x\portmacro.h" #endif #ifdef STR75X_IAR #include "..\..\Source\portable\IAR\STR75x\portmacro.h" #endif #ifdef STR75X_GCC #include "..\..\Source\portable\GCC\STR75x\portmacro.h" #endif #ifdef STR91X_IAR #include "..\..\Source\portable\IAR\STR91x\portmacro.h" #endif #ifdef GCC_H8S #include "../../Source/portable/GCC/H8S2329/portmacro.h" #endif #ifdef GCC_AT91FR40008 #include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h" #endif #ifdef RVDS_ARMCM3_LM3S102 #include "../../Source/portable/RVDS/ARM_CM3/portmacro.h" #endif #ifdef GCC_ARMCM3_LM3S102 #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" #endif #ifdef GCC_ARMCM3 #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" #endif #ifdef IAR_ARM_CM3 #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" #endif #ifdef IAR_ARMCM3_LM #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" #endif #ifdef HCS12_CODE_WARRIOR #include "../../Source/portable/CodeWarrior/HCS12/portmacro.h" #endif #ifdef MICROBLAZE_GCC #include "../../Source/portable/GCC/MicroBlaze/portmacro.h" #endif #ifdef TERN_EE #include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h" #endif #ifdef GCC_HCS12 #include "../../Source/portable/GCC/HCS12/portmacro.h" #endif #ifdef GCC_MCF5235 #include "../../Source/portable/GCC/MCF5235/portmacro.h" #endif #ifdef COLDFIRE_V2_GCC #include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h" #endif #ifdef COLDFIRE_V2_CODEWARRIOR #include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h" #endif #ifdef GCC_PPC405 #include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h" #endif #ifdef GCC_PPC440 #include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h" #endif #ifdef _16FX_SOFTUNE #include "..\..\Source\portable\Softune\MB96340\portmacro.h" #endif #ifdef BCC_INDUSTRIAL_PC_PORT /* A short file name has to be used in place of the normal FreeRTOSConfig.h when using the Borland compiler. */ #include "frconfig.h" #include "..\portable\BCC\16BitDOS\PC\prtmacro.h" typedef void ( __interrupt __far *pxISR )(); #endif #ifdef BCC_FLASH_LITE_186_PORT /* A short file name has to be used in place of the normal FreeRTOSConfig.h when using the Borland compiler. */ #include "frconfig.h" #include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h" typedef void ( __interrupt __far *pxISR )(); #endif #ifdef __GNUC__ #ifdef __AVR32_AVR32A__ #include "portmacro.h" #endif #endif #ifdef __ICCAVR32__ #ifdef __CORE__ #if __CORE__ == __AVR32A__ #include "portmacro.h" #endif #endif #endif #ifdef __91467D #include "portmacro.h" #endif #ifdef __96340 #include "portmacro.h" #endif #ifdef __IAR_V850ES_Fx3__ #include "../../Source/portable/IAR/V850ES/portmacro.h" #endif #ifdef __IAR_V850ES_Jx3__ #include "../../Source/portable/IAR/V850ES/portmacro.h" #endif #ifdef __IAR_V850ES_Jx3_L__ #include "../../Source/portable/IAR/V850ES/portmacro.h" #endif #ifdef __IAR_V850ES_Jx2__ #include "../../Source/portable/IAR/V850ES/portmacro.h" #endif #ifdef __IAR_V850ES_Hx2__ #include "../../Source/portable/IAR/V850ES/portmacro.h" #endif #ifdef __IAR_78K0R_Kx3__ #include "../../Source/portable/IAR/78K0R/portmacro.h" #endif #ifdef __IAR_78K0R_Kx3L__ #include "../../Source/portable/IAR/78K0R/portmacro.h" #endif /* Catch all to ensure portmacro.h is included in the build. Newer demos have the path as part of the project options, rather than as relative from the project location. If portENTER_CRITICAL() has not been defined then portmacro.h has not yet been included - as every portmacro.h provides a portENTER_CRITICAL() definition. Check the demo application for your demo to find the path to the correct portmacro.h file. */ #ifndef portENTER_CRITICAL #include "portmacro.h" #endif #if portBYTE_ALIGNMENT == 8 #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) #endif #if portBYTE_ALIGNMENT == 4 #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) #endif #if portBYTE_ALIGNMENT == 2 #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) #endif #if portBYTE_ALIGNMENT == 1 #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) #endif #ifndef portBYTE_ALIGNMENT_MASK #error "Invalid portBYTE_ALIGNMENT definition" #endif #ifndef portNUM_CONFIGURABLE_REGIONS #define portNUM_CONFIGURABLE_REGIONS 1 #endif #ifdef __cplusplus extern "C" { #endif #include "mpu_wrappers.h" /* * Setup the stack of a new task so it is ready to be placed under the * scheduler control. The registers have to be placed on the stack in * the order that the port expects to find them. * */ #if( portUSING_MPU_WRAPPERS == 1 ) portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters, portBASE_TYPE xRunPrivileged ) PRIVILEGED_FUNCTION; #else portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ); #endif /* * Map to the memory management routines required for the port. */ void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION; void vPortFree( void *pv ) PRIVILEGED_FUNCTION; void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION; size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION; /* * Setup the hardware ready for the scheduler to take control. This generally * sets up a tick interrupt and sets timers for the correct tick frequency. */ portBASE_TYPE xPortStartScheduler( void ) PRIVILEGED_FUNCTION; /* * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so * the hardware is left in its original condition after the scheduler stops * executing. */ void vPortEndScheduler( void ) PRIVILEGED_FUNCTION; /* * The structures and methods of manipulating the MPU are contained within the * port layer. * * Fills the xMPUSettings structure with the memory region information * contained in xRegions. */ #if( portUSING_MPU_WRAPPERS == 1 ) struct xMEMORY_REGION; void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, portSTACK_TYPE *pxBottomOfStack, unsigned short usStackDepth ) PRIVILEGED_FUNCTION; #endif #ifdef __cplusplus } #endif #endif /* PORTABLE_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/include/portable.h
C
oos
11,780
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef INC_FREERTOS_H #define INC_FREERTOS_H /* * Include the generic headers required for the FreeRTOS port being used. */ #include <stddef.h> /* Basic FreeRTOS definitions. */ #include "projdefs.h" /* Application specific configuration options. */ #include "FreeRTOSConfig.h" /* Definitions specific to the port being used. */ #include "portable.h" /* Defines the prototype to which the application task hook function must conform. */ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); /* * Check all the required application specific macros have been defined. * These macros are application specific and (as downloaded) are defined * within FreeRTOSConfig.h. */ #ifndef configUSE_PREEMPTION #error Missing definition: configUSE_PREEMPTION should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif #ifndef configUSE_IDLE_HOOK #error Missing definition: configUSE_IDLE_HOOK should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif #ifndef configUSE_TICK_HOOK #error Missing definition: configUSE_TICK_HOOK should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif #ifndef configUSE_CO_ROUTINES #error Missing definition: configUSE_CO_ROUTINES should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif #ifndef INCLUDE_vTaskPrioritySet #error Missing definition: INCLUDE_vTaskPrioritySet should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif #ifndef INCLUDE_uxTaskPriorityGet #error Missing definition: INCLUDE_uxTaskPriorityGet should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif #ifndef INCLUDE_vTaskDelete #error Missing definition: INCLUDE_vTaskDelete should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif #ifndef INCLUDE_vTaskSuspend #error Missing definition: INCLUDE_vTaskSuspend should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif #ifndef INCLUDE_vTaskDelayUntil #error Missing definition: INCLUDE_vTaskDelayUntil should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif #ifndef INCLUDE_vTaskDelay #error Missing definition: INCLUDE_vTaskDelay should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif #ifndef configUSE_16_BIT_TICKS #error Missing definition: configUSE_16_BIT_TICKS should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif #ifndef INCLUDE_xTaskGetIdleTaskHandle #define INCLUDE_xTaskGetIdleTaskHandle 0 #endif #ifndef INCLUDE_xTimerGetTimerDaemonTaskHandle #define INCLUDE_xTimerGetTimerDaemonTaskHandle 0 #endif #ifndef INCLUDE_pcTaskGetTaskName #define INCLUDE_pcTaskGetTaskName 0 #endif #ifndef configUSE_APPLICATION_TASK_TAG #define configUSE_APPLICATION_TASK_TAG 0 #endif #ifndef INCLUDE_uxTaskGetStackHighWaterMark #define INCLUDE_uxTaskGetStackHighWaterMark 0 #endif #ifndef configUSE_RECURSIVE_MUTEXES #define configUSE_RECURSIVE_MUTEXES 0 #endif #ifndef configUSE_MUTEXES #define configUSE_MUTEXES 0 #endif #ifndef configUSE_TIMERS #define configUSE_TIMERS 0 #endif #ifndef configUSE_COUNTING_SEMAPHORES #define configUSE_COUNTING_SEMAPHORES 0 #endif #ifndef configUSE_ALTERNATIVE_API #define configUSE_ALTERNATIVE_API 0 #endif #ifndef portCRITICAL_NESTING_IN_TCB #define portCRITICAL_NESTING_IN_TCB 0 #endif #ifndef configMAX_TASK_NAME_LEN #define configMAX_TASK_NAME_LEN 16 #endif #ifndef configIDLE_SHOULD_YIELD #define configIDLE_SHOULD_YIELD 1 #endif #if configMAX_TASK_NAME_LEN < 1 #error configMAX_TASK_NAME_LEN must be set to a minimum of 1 in FreeRTOSConfig.h #endif #ifndef INCLUDE_xTaskResumeFromISR #define INCLUDE_xTaskResumeFromISR 1 #endif #ifndef configASSERT #define configASSERT( x ) #endif /* The timers module relies on xTaskGetSchedulerState(). */ #if configUSE_TIMERS == 1 #ifndef configTIMER_TASK_PRIORITY #error If configUSE_TIMERS is set to 1 then configTIMER_TASK_PRIORITY must also be defined. #endif /* configTIMER_TASK_PRIORITY */ #ifndef configTIMER_QUEUE_LENGTH #error If configUSE_TIMERS is set to 1 then configTIMER_QUEUE_LENGTH must also be defined. #endif /* configTIMER_QUEUE_LENGTH */ #ifndef configTIMER_TASK_STACK_DEPTH #error If configUSE_TIMERS is set to 1 then configTIMER_TASK_STACK_DEPTH must also be defined. #endif /* configTIMER_TASK_STACK_DEPTH */ #endif /* configUSE_TIMERS */ #ifndef INCLUDE_xTaskGetSchedulerState #define INCLUDE_xTaskGetSchedulerState 0 #endif #ifndef INCLUDE_xTaskGetCurrentTaskHandle #define INCLUDE_xTaskGetCurrentTaskHandle 0 #endif #ifndef portSET_INTERRUPT_MASK_FROM_ISR #define portSET_INTERRUPT_MASK_FROM_ISR() 0 #endif #ifndef portCLEAR_INTERRUPT_MASK_FROM_ISR #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue #endif #ifndef configQUEUE_REGISTRY_SIZE #define configQUEUE_REGISTRY_SIZE 0U #endif #if ( configQUEUE_REGISTRY_SIZE < 1 ) #define vQueueAddToRegistry( xQueue, pcName ) #define vQueueUnregisterQueue( xQueue ) #endif #ifndef portPOINTER_SIZE_TYPE #define portPOINTER_SIZE_TYPE unsigned long #endif /* Remove any unused trace macros. */ #ifndef traceSTART /* Used to perform any necessary initialisation - for example, open a file into which trace is to be written. */ #define traceSTART() #endif #ifndef traceEND /* Use to close a trace, for example close a file into which trace has been written. */ #define traceEND() #endif #ifndef traceTASK_SWITCHED_IN /* Called after a task has been selected to run. pxCurrentTCB holds a pointer to the task control block of the selected task. */ #define traceTASK_SWITCHED_IN() #endif #ifndef traceTASK_SWITCHED_OUT /* Called before a task has been selected to run. pxCurrentTCB holds a pointer to the task control block of the task being switched out. */ #define traceTASK_SWITCHED_OUT() #endif #ifndef traceBLOCKING_ON_QUEUE_RECEIVE /* Task is about to block because it cannot read from a queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore upon which the read was attempted. pxCurrentTCB points to the TCB of the task that attempted the read. */ #define traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ) #endif #ifndef traceBLOCKING_ON_QUEUE_SEND /* Task is about to block because it cannot write to a queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore upon which the write was attempted. pxCurrentTCB points to the TCB of the task that attempted the write. */ #define traceBLOCKING_ON_QUEUE_SEND( pxQueue ) #endif #ifndef configCHECK_FOR_STACK_OVERFLOW #define configCHECK_FOR_STACK_OVERFLOW 0 #endif /* The following event macros are embedded in the kernel API calls. */ #ifndef traceQUEUE_CREATE #define traceQUEUE_CREATE( pxNewQueue ) #endif #ifndef traceQUEUE_CREATE_FAILED #define traceQUEUE_CREATE_FAILED() #endif #ifndef traceCREATE_MUTEX #define traceCREATE_MUTEX( pxNewQueue ) #endif #ifndef traceCREATE_MUTEX_FAILED #define traceCREATE_MUTEX_FAILED() #endif #ifndef traceGIVE_MUTEX_RECURSIVE #define traceGIVE_MUTEX_RECURSIVE( pxMutex ) #endif #ifndef traceGIVE_MUTEX_RECURSIVE_FAILED #define traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex ) #endif #ifndef traceTAKE_MUTEX_RECURSIVE #define traceTAKE_MUTEX_RECURSIVE( pxMutex ) #endif #ifndef traceTAKE_MUTEX_RECURSIVE_FAILED #define traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex ) #endif #ifndef traceCREATE_COUNTING_SEMAPHORE #define traceCREATE_COUNTING_SEMAPHORE() #endif #ifndef traceCREATE_COUNTING_SEMAPHORE_FAILED #define traceCREATE_COUNTING_SEMAPHORE_FAILED() #endif #ifndef traceQUEUE_SEND #define traceQUEUE_SEND( pxQueue ) #endif #ifndef traceQUEUE_SEND_FAILED #define traceQUEUE_SEND_FAILED( pxQueue ) #endif #ifndef traceQUEUE_RECEIVE #define traceQUEUE_RECEIVE( pxQueue ) #endif #ifndef traceQUEUE_PEEK #define traceQUEUE_PEEK( pxQueue ) #endif #ifndef traceQUEUE_RECEIVE_FAILED #define traceQUEUE_RECEIVE_FAILED( pxQueue ) #endif #ifndef traceQUEUE_SEND_FROM_ISR #define traceQUEUE_SEND_FROM_ISR( pxQueue ) #endif #ifndef traceQUEUE_SEND_FROM_ISR_FAILED #define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) #endif #ifndef traceQUEUE_RECEIVE_FROM_ISR #define traceQUEUE_RECEIVE_FROM_ISR( pxQueue ) #endif #ifndef traceQUEUE_RECEIVE_FROM_ISR_FAILED #define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ) #endif #ifndef traceQUEUE_DELETE #define traceQUEUE_DELETE( pxQueue ) #endif #ifndef traceTASK_CREATE #define traceTASK_CREATE( pxNewTCB ) #endif #ifndef traceTASK_CREATE_FAILED #define traceTASK_CREATE_FAILED() #endif #ifndef traceTASK_DELETE #define traceTASK_DELETE( pxTaskToDelete ) #endif #ifndef traceTASK_DELAY_UNTIL #define traceTASK_DELAY_UNTIL() #endif #ifndef traceTASK_DELAY #define traceTASK_DELAY() #endif #ifndef traceTASK_PRIORITY_SET #define traceTASK_PRIORITY_SET( pxTask, uxNewPriority ) #endif #ifndef traceTASK_SUSPEND #define traceTASK_SUSPEND( pxTaskToSuspend ) #endif #ifndef traceTASK_RESUME #define traceTASK_RESUME( pxTaskToResume ) #endif #ifndef traceTASK_RESUME_FROM_ISR #define traceTASK_RESUME_FROM_ISR( pxTaskToResume ) #endif #ifndef traceTASK_INCREMENT_TICK #define traceTASK_INCREMENT_TICK( xTickCount ) #endif #ifndef traceTIMER_CREATE #define traceTIMER_CREATE( pxNewTimer ) #endif #ifndef traceTIMER_CREATE_FAILED #define traceTIMER_CREATE_FAILED() #endif #ifndef traceTIMER_COMMAND_SEND #define traceTIMER_COMMAND_SEND( xTimer, xMessageID, xMessageValueValue, xReturn ) #endif #ifndef traceTIMER_EXPIRED #define traceTIMER_EXPIRED( pxTimer ) #endif #ifndef traceTIMER_COMMAND_RECEIVED #define traceTIMER_COMMAND_RECEIVED( pxTimer, xMessageID, xMessageValue ) #endif #ifndef configGENERATE_RUN_TIME_STATS #define configGENERATE_RUN_TIME_STATS 0 #endif #if ( configGENERATE_RUN_TIME_STATS == 1 ) #ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS #error If configGENERATE_RUN_TIME_STATS is defined then portCONFIGURE_TIMER_FOR_RUN_TIME_STATS must also be defined. portCONFIGURE_TIMER_FOR_RUN_TIME_STATS should call a port layer function to setup a peripheral timer/counter that can then be used as the run time counter time base. #endif /* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS */ #ifndef portGET_RUN_TIME_COUNTER_VALUE #ifndef portALT_GET_RUN_TIME_COUNTER_VALUE #error If configGENERATE_RUN_TIME_STATS is defined then either portGET_RUN_TIME_COUNTER_VALUE or portALT_GET_RUN_TIME_COUNTER_VALUE must also be defined. See the examples provided and the FreeRTOS web site for more information. #endif /* portALT_GET_RUN_TIME_COUNTER_VALUE */ #endif /* portGET_RUN_TIME_COUNTER_VALUE */ #endif /* configGENERATE_RUN_TIME_STATS */ #ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() #endif #ifndef configUSE_MALLOC_FAILED_HOOK #define configUSE_MALLOC_FAILED_HOOK 0 #endif #ifndef portPRIVILEGE_BIT #define portPRIVILEGE_BIT ( ( unsigned portBASE_TYPE ) 0x00 ) #endif #ifndef portYIELD_WITHIN_API #define portYIELD_WITHIN_API portYIELD #endif #ifndef pvPortMallocAligned #define pvPortMallocAligned( x, puxStackBuffer ) ( ( ( puxStackBuffer ) == NULL ) ? ( pvPortMalloc( ( x ) ) ) : ( puxStackBuffer ) ) #endif #ifndef vPortFreeAligned #define vPortFreeAligned( pvBlockToFree ) vPortFree( pvBlockToFree ) #endif #endif /* INC_FREERTOS_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/include/FreeRTOS.h
C
oos
15,417
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef STACK_MACROS_H #define STACK_MACROS_H /* * Call the stack overflow hook function if the stack of the task being swapped * out is currently overflowed, or looks like it might have overflowed in the * past. * * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check * the current stack state only - comparing the current top of stack value to * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 * will also cause the last few stack bytes to be checked to ensure the value * to which the bytes were set when the task was created have not been * overwritten. Note this second test does not guarantee that an overflowed * stack will always be recognised. */ /*-----------------------------------------------------------*/ #if( configCHECK_FOR_STACK_OVERFLOW == 0 ) /* FreeRTOSConfig.h is not set to check for stack overflows. */ #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */ /*-----------------------------------------------------------*/ #if( configCHECK_FOR_STACK_OVERFLOW == 1 ) /* FreeRTOSConfig.h is only set to use the first method of overflow checking. */ #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() #endif /*-----------------------------------------------------------*/ #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) ) /* Only the current stack state is to be checked. */ #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ { \ /* Is the currently saved stack pointer within the stack limit? */ \ if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ { \ vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ } \ } #endif /* configCHECK_FOR_STACK_OVERFLOW > 0 */ /*-----------------------------------------------------------*/ #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) ) /* Only the current stack state is to be checked. */ #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ { \ \ /* Is the currently saved stack pointer within the stack limit? */ \ if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ { \ vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ } \ } #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ /*-----------------------------------------------------------*/ #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ { \ static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ \ \ /* Has the extremity of the task stack ever been written over? */ \ if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ { \ vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ } \ } #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ /*-----------------------------------------------------------*/ #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ { \ char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack; \ static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ \ \ pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ \ /* Has the extremity of the task stack ever been written over? */ \ if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ { \ vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ } \ } #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ /*-----------------------------------------------------------*/ #endif /* STACK_MACROS_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/include/StackMacros.h
C
oos
8,580
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef SEMAPHORE_H #define SEMAPHORE_H #ifndef INC_FREERTOS_H #error "#include FreeRTOS.h" must appear in source files before "#include semphr.h" #endif #include "queue.h" typedef xQueueHandle xSemaphoreHandle; #define semBINARY_SEMAPHORE_QUEUE_LENGTH ( ( unsigned char ) 1U ) #define semSEMAPHORE_QUEUE_ITEM_LENGTH ( ( unsigned char ) 0U ) #define semGIVE_BLOCK_TIME ( ( portTickType ) 0U ) /** * semphr. h * <pre>vSemaphoreCreateBinary( xSemaphoreHandle xSemaphore )</pre> * * <i>Macro</i> that implements a semaphore by using the existing queue mechanism. * The queue length is 1 as this is a binary semaphore. The data size is 0 * as we don't want to actually store any data - we just want to know if the * queue is empty or full. * * This type of semaphore can be used for pure synchronisation between tasks or * between an interrupt and a task. The semaphore need not be given back once * obtained, so one task/interrupt can continuously 'give' the semaphore while * another continuously 'takes' the semaphore. For this reason this type of * semaphore does not use a priority inheritance mechanism. For an alternative * that does use priority inheritance see xSemaphoreCreateMutex(). * * @param xSemaphore Handle to the created semaphore. Should be of type xSemaphoreHandle. * * Example usage: <pre> xSemaphoreHandle xSemaphore; void vATask( void * pvParameters ) { // Semaphore cannot be used before a call to vSemaphoreCreateBinary (). // This is a macro so pass the variable in directly. vSemaphoreCreateBinary( xSemaphore ); if( xSemaphore != NULL ) { // The semaphore was created successfully. // The semaphore can now be used. } } </pre> * \defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary * \ingroup Semaphores */ #define vSemaphoreCreateBinary( xSemaphore ) { \ ( xSemaphore ) = xQueueCreate( ( unsigned portBASE_TYPE ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH ); \ if( ( xSemaphore ) != NULL ) \ { \ xSemaphoreGive( ( xSemaphore ) ); \ } \ } /** * semphr. h * <pre>xSemaphoreTake( * xSemaphoreHandle xSemaphore, * portTickType xBlockTime * )</pre> * * <i>Macro</i> to obtain a semaphore. The semaphore must have previously been * created with a call to vSemaphoreCreateBinary(), xSemaphoreCreateMutex() or * xSemaphoreCreateCounting(). * * @param xSemaphore A handle to the semaphore being taken - obtained when * the semaphore was created. * * @param xBlockTime The time in ticks to wait for the semaphore to become * available. The macro portTICK_RATE_MS can be used to convert this to a * real time. A block time of zero can be used to poll the semaphore. A block * time of portMAX_DELAY can be used to block indefinitely (provided * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h). * * @return pdTRUE if the semaphore was obtained. pdFALSE * if xBlockTime expired without the semaphore becoming available. * * Example usage: <pre> xSemaphoreHandle xSemaphore = NULL; // A task that creates a semaphore. void vATask( void * pvParameters ) { // Create the semaphore to guard a shared resource. vSemaphoreCreateBinary( xSemaphore ); } // A task that uses the semaphore. void vAnotherTask( void * pvParameters ) { // ... Do other things. if( xSemaphore != NULL ) { // See if we can obtain the semaphore. If the semaphore is not available // wait 10 ticks to see if it becomes free. if( xSemaphoreTake( xSemaphore, ( portTickType ) 10 ) == pdTRUE ) { // We were able to obtain the semaphore and can now access the // shared resource. // ... // We have finished accessing the shared resource. Release the // semaphore. xSemaphoreGive( xSemaphore ); } else { // We could not obtain the semaphore and can therefore not access // the shared resource safely. } } } </pre> * \defgroup xSemaphoreTake xSemaphoreTake * \ingroup Semaphores */ #define xSemaphoreTake( xSemaphore, xBlockTime ) xQueueGenericReceive( ( xQueueHandle ) ( xSemaphore ), NULL, ( xBlockTime ), pdFALSE ) /** * semphr. h * xSemaphoreTakeRecursive( * xSemaphoreHandle xMutex, * portTickType xBlockTime * ) * * <i>Macro</i> to recursively obtain, or 'take', a mutex type semaphore. * The mutex must have previously been created using a call to * xSemaphoreCreateRecursiveMutex(); * * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this * macro to be available. * * This macro must not be used on mutexes created using xSemaphoreCreateMutex(). * * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex * doesn't become available again until the owner has called * xSemaphoreGiveRecursive() for each successful 'take' request. For example, * if a task successfully 'takes' the same mutex 5 times then the mutex will * not be available to any other task until it has also 'given' the mutex back * exactly five times. * * @param xMutex A handle to the mutex being obtained. This is the * handle returned by xSemaphoreCreateRecursiveMutex(); * * @param xBlockTime The time in ticks to wait for the semaphore to become * available. The macro portTICK_RATE_MS can be used to convert this to a * real time. A block time of zero can be used to poll the semaphore. If * the task already owns the semaphore then xSemaphoreTakeRecursive() will * return immediately no matter what the value of xBlockTime. * * @return pdTRUE if the semaphore was obtained. pdFALSE if xBlockTime * expired without the semaphore becoming available. * * Example usage: <pre> xSemaphoreHandle xMutex = NULL; // A task that creates a mutex. void vATask( void * pvParameters ) { // Create the mutex to guard a shared resource. xMutex = xSemaphoreCreateRecursiveMutex(); } // A task that uses the mutex. void vAnotherTask( void * pvParameters ) { // ... Do other things. if( xMutex != NULL ) { // See if we can obtain the mutex. If the mutex is not available // wait 10 ticks to see if it becomes free. if( xSemaphoreTakeRecursive( xSemaphore, ( portTickType ) 10 ) == pdTRUE ) { // We were able to obtain the mutex and can now access the // shared resource. // ... // For some reason due to the nature of the code further calls to // xSemaphoreTakeRecursive() are made on the same mutex. In real // code these would not be just sequential calls as this would make // no sense. Instead the calls are likely to be buried inside // a more complex call structure. xSemaphoreTakeRecursive( xMutex, ( portTickType ) 10 ); xSemaphoreTakeRecursive( xMutex, ( portTickType ) 10 ); // The mutex has now been 'taken' three times, so will not be // available to another task until it has also been given back // three times. Again it is unlikely that real code would have // these calls sequentially, but instead buried in a more complex // call structure. This is just for illustrative purposes. xSemaphoreGiveRecursive( xMutex ); xSemaphoreGiveRecursive( xMutex ); xSemaphoreGiveRecursive( xMutex ); // Now the mutex can be taken by other tasks. } else { // We could not obtain the mutex and can therefore not access // the shared resource safely. } } } </pre> * \defgroup xSemaphoreTakeRecursive xSemaphoreTakeRecursive * \ingroup Semaphores */ #define xSemaphoreTakeRecursive( xMutex, xBlockTime ) xQueueTakeMutexRecursive( ( xMutex ), ( xBlockTime ) ) /* * xSemaphoreAltTake() is an alternative version of xSemaphoreTake(). * * The source code that implements the alternative (Alt) API is much * simpler because it executes everything from within a critical section. * This is the approach taken by many other RTOSes, but FreeRTOS.org has the * preferred fully featured API too. The fully featured API has more * complex code that takes longer to execute, but makes much less use of * critical sections. Therefore the alternative API sacrifices interrupt * responsiveness to gain execution speed, whereas the fully featured API * sacrifices execution speed to ensure better interrupt responsiveness. */ #define xSemaphoreAltTake( xSemaphore, xBlockTime ) xQueueAltGenericReceive( ( xQueueHandle ) ( xSemaphore ), NULL, ( xBlockTime ), pdFALSE ) /** * semphr. h * <pre>xSemaphoreGive( xSemaphoreHandle xSemaphore )</pre> * * <i>Macro</i> to release a semaphore. The semaphore must have previously been * created with a call to vSemaphoreCreateBinary(), xSemaphoreCreateMutex() or * xSemaphoreCreateCounting(). and obtained using sSemaphoreTake(). * * This macro must not be used from an ISR. See xSemaphoreGiveFromISR () for * an alternative which can be used from an ISR. * * This macro must also not be used on semaphores created using * xSemaphoreCreateRecursiveMutex(). * * @param xSemaphore A handle to the semaphore being released. This is the * handle returned when the semaphore was created. * * @return pdTRUE if the semaphore was released. pdFALSE if an error occurred. * Semaphores are implemented using queues. An error can occur if there is * no space on the queue to post a message - indicating that the * semaphore was not first obtained correctly. * * Example usage: <pre> xSemaphoreHandle xSemaphore = NULL; void vATask( void * pvParameters ) { // Create the semaphore to guard a shared resource. vSemaphoreCreateBinary( xSemaphore ); if( xSemaphore != NULL ) { if( xSemaphoreGive( xSemaphore ) != pdTRUE ) { // We would expect this call to fail because we cannot give // a semaphore without first "taking" it! } // Obtain the semaphore - don't block if the semaphore is not // immediately available. if( xSemaphoreTake( xSemaphore, ( portTickType ) 0 ) ) { // We now have the semaphore and can access the shared resource. // ... // We have finished accessing the shared resource so can free the // semaphore. if( xSemaphoreGive( xSemaphore ) != pdTRUE ) { // We would not expect this call to fail because we must have // obtained the semaphore to get here. } } } } </pre> * \defgroup xSemaphoreGive xSemaphoreGive * \ingroup Semaphores */ #define xSemaphoreGive( xSemaphore ) xQueueGenericSend( ( xQueueHandle ) ( xSemaphore ), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK ) /** * semphr. h * <pre>xSemaphoreGiveRecursive( xSemaphoreHandle xMutex )</pre> * * <i>Macro</i> to recursively release, or 'give', a mutex type semaphore. * The mutex must have previously been created using a call to * xSemaphoreCreateRecursiveMutex(); * * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this * macro to be available. * * This macro must not be used on mutexes created using xSemaphoreCreateMutex(). * * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex * doesn't become available again until the owner has called * xSemaphoreGiveRecursive() for each successful 'take' request. For example, * if a task successfully 'takes' the same mutex 5 times then the mutex will * not be available to any other task until it has also 'given' the mutex back * exactly five times. * * @param xMutex A handle to the mutex being released, or 'given'. This is the * handle returned by xSemaphoreCreateMutex(); * * @return pdTRUE if the semaphore was given. * * Example usage: <pre> xSemaphoreHandle xMutex = NULL; // A task that creates a mutex. void vATask( void * pvParameters ) { // Create the mutex to guard a shared resource. xMutex = xSemaphoreCreateRecursiveMutex(); } // A task that uses the mutex. void vAnotherTask( void * pvParameters ) { // ... Do other things. if( xMutex != NULL ) { // See if we can obtain the mutex. If the mutex is not available // wait 10 ticks to see if it becomes free. if( xSemaphoreTakeRecursive( xMutex, ( portTickType ) 10 ) == pdTRUE ) { // We were able to obtain the mutex and can now access the // shared resource. // ... // For some reason due to the nature of the code further calls to // xSemaphoreTakeRecursive() are made on the same mutex. In real // code these would not be just sequential calls as this would make // no sense. Instead the calls are likely to be buried inside // a more complex call structure. xSemaphoreTakeRecursive( xMutex, ( portTickType ) 10 ); xSemaphoreTakeRecursive( xMutex, ( portTickType ) 10 ); // The mutex has now been 'taken' three times, so will not be // available to another task until it has also been given back // three times. Again it is unlikely that real code would have // these calls sequentially, it would be more likely that the calls // to xSemaphoreGiveRecursive() would be called as a call stack // unwound. This is just for demonstrative purposes. xSemaphoreGiveRecursive( xMutex ); xSemaphoreGiveRecursive( xMutex ); xSemaphoreGiveRecursive( xMutex ); // Now the mutex can be taken by other tasks. } else { // We could not obtain the mutex and can therefore not access // the shared resource safely. } } } </pre> * \defgroup xSemaphoreGiveRecursive xSemaphoreGiveRecursive * \ingroup Semaphores */ #define xSemaphoreGiveRecursive( xMutex ) xQueueGiveMutexRecursive( ( xMutex ) ) /* * xSemaphoreAltGive() is an alternative version of xSemaphoreGive(). * * The source code that implements the alternative (Alt) API is much * simpler because it executes everything from within a critical section. * This is the approach taken by many other RTOSes, but FreeRTOS.org has the * preferred fully featured API too. The fully featured API has more * complex code that takes longer to execute, but makes much less use of * critical sections. Therefore the alternative API sacrifices interrupt * responsiveness to gain execution speed, whereas the fully featured API * sacrifices execution speed to ensure better interrupt responsiveness. */ #define xSemaphoreAltGive( xSemaphore ) xQueueAltGenericSend( ( xQueueHandle ) ( xSemaphore ), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK ) /** * semphr. h * <pre> xSemaphoreGiveFromISR( xSemaphoreHandle xSemaphore, signed portBASE_TYPE *pxHigherPriorityTaskWoken )</pre> * * <i>Macro</i> to release a semaphore. The semaphore must have previously been * created with a call to vSemaphoreCreateBinary() or xSemaphoreCreateCounting(). * * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex()) * must not be used with this macro. * * This macro can be used from an ISR. * * @param xSemaphore A handle to the semaphore being released. This is the * handle returned when the semaphore was created. * * @param pxHigherPriorityTaskWoken xSemaphoreGiveFromISR() will set * *pxHigherPriorityTaskWoken to pdTRUE if giving the semaphore caused a task * to unblock, and the unblocked task has a priority higher than the currently * running task. If xSemaphoreGiveFromISR() sets this value to pdTRUE then * a context switch should be requested before the interrupt is exited. * * @return pdTRUE if the semaphore was successfully given, otherwise errQUEUE_FULL. * * Example usage: <pre> \#define LONG_TIME 0xffff \#define TICKS_TO_WAIT 10 xSemaphoreHandle xSemaphore = NULL; // Repetitive task. void vATask( void * pvParameters ) { for( ;; ) { // We want this task to run every 10 ticks of a timer. The semaphore // was created before this task was started. // Block waiting for the semaphore to become available. if( xSemaphoreTake( xSemaphore, LONG_TIME ) == pdTRUE ) { // It is time to execute. // ... // We have finished our task. Return to the top of the loop where // we will block on the semaphore until it is time to execute // again. Note when using the semaphore for synchronisation with an // ISR in this manner there is no need to 'give' the semaphore back. } } } // Timer ISR void vTimerISR( void * pvParameters ) { static unsigned char ucLocalTickCount = 0; static signed portBASE_TYPE xHigherPriorityTaskWoken; // A timer tick has occurred. // ... Do other time functions. // Is it time for vATask () to run? xHigherPriorityTaskWoken = pdFALSE; ucLocalTickCount++; if( ucLocalTickCount >= TICKS_TO_WAIT ) { // Unblock the task by releasing the semaphore. xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken ); // Reset the count so we release the semaphore again in 10 ticks time. ucLocalTickCount = 0; } if( xHigherPriorityTaskWoken != pdFALSE ) { // We can force a context switch here. Context switching from an // ISR uses port specific syntax. Check the demo task for your port // to find the syntax required. } } </pre> * \defgroup xSemaphoreGiveFromISR xSemaphoreGiveFromISR * \ingroup Semaphores */ #define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueueHandle ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK ) /** * semphr. h * <pre>xSemaphoreHandle xSemaphoreCreateMutex( void )</pre> * * <i>Macro</i> that implements a mutex semaphore by using the existing queue * mechanism. * * Mutexes created using this macro can be accessed using the xSemaphoreTake() * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and * xSemaphoreGiveRecursive() macros should not be used. * * This type of semaphore uses a priority inheritance mechanism so a task * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the * semaphore it is no longer required. * * Mutex type semaphores cannot be used from within interrupt service routines. * * See vSemaphoreCreateBinary() for an alternative implementation that can be * used for pure synchronisation (where one task or interrupt always 'gives' the * semaphore and another always 'takes' the semaphore) and from within interrupt * service routines. * * @return xSemaphore Handle to the created mutex semaphore. Should be of type * xSemaphoreHandle. * * Example usage: <pre> xSemaphoreHandle xSemaphore; void vATask( void * pvParameters ) { // Semaphore cannot be used before a call to xSemaphoreCreateMutex(). // This is a macro so pass the variable in directly. xSemaphore = xSemaphoreCreateMutex(); if( xSemaphore != NULL ) { // The semaphore was created successfully. // The semaphore can now be used. } } </pre> * \defgroup vSemaphoreCreateMutex vSemaphoreCreateMutex * \ingroup Semaphores */ #define xSemaphoreCreateMutex() xQueueCreateMutex() /** * semphr. h * <pre>xSemaphoreHandle xSemaphoreCreateRecursiveMutex( void )</pre> * * <i>Macro</i> that implements a recursive mutex by using the existing queue * mechanism. * * Mutexes created using this macro can be accessed using the * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The * xSemaphoreTake() and xSemaphoreGive() macros should not be used. * * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex * doesn't become available again until the owner has called * xSemaphoreGiveRecursive() for each successful 'take' request. For example, * if a task successfully 'takes' the same mutex 5 times then the mutex will * not be available to any other task until it has also 'given' the mutex back * exactly five times. * * This type of semaphore uses a priority inheritance mechanism so a task * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the * semaphore it is no longer required. * * Mutex type semaphores cannot be used from within interrupt service routines. * * See vSemaphoreCreateBinary() for an alternative implementation that can be * used for pure synchronisation (where one task or interrupt always 'gives' the * semaphore and another always 'takes' the semaphore) and from within interrupt * service routines. * * @return xSemaphore Handle to the created mutex semaphore. Should be of type * xSemaphoreHandle. * * Example usage: <pre> xSemaphoreHandle xSemaphore; void vATask( void * pvParameters ) { // Semaphore cannot be used before a call to xSemaphoreCreateMutex(). // This is a macro so pass the variable in directly. xSemaphore = xSemaphoreCreateRecursiveMutex(); if( xSemaphore != NULL ) { // The semaphore was created successfully. // The semaphore can now be used. } } </pre> * \defgroup vSemaphoreCreateMutex vSemaphoreCreateMutex * \ingroup Semaphores */ #define xSemaphoreCreateRecursiveMutex() xQueueCreateMutex() /** * semphr. h * <pre>xSemaphoreHandle xSemaphoreCreateCounting( unsigned portBASE_TYPE uxMaxCount, unsigned portBASE_TYPE uxInitialCount )</pre> * * <i>Macro</i> that creates a counting semaphore by using the existing * queue mechanism. * * Counting semaphores are typically used for two things: * * 1) Counting events. * * In this usage scenario an event handler will 'give' a semaphore each time * an event occurs (incrementing the semaphore count value), and a handler * task will 'take' a semaphore each time it processes an event * (decrementing the semaphore count value). The count value is therefore * the difference between the number of events that have occurred and the * number that have been processed. In this case it is desirable for the * initial count value to be zero. * * 2) Resource management. * * In this usage scenario the count value indicates the number of resources * available. To obtain control of a resource a task must first obtain a * semaphore - decrementing the semaphore count value. When the count value * reaches zero there are no free resources. When a task finishes with the * resource it 'gives' the semaphore back - incrementing the semaphore count * value. In this case it is desirable for the initial count value to be * equal to the maximum count value, indicating that all resources are free. * * @param uxMaxCount The maximum count value that can be reached. When the * semaphore reaches this value it can no longer be 'given'. * * @param uxInitialCount The count value assigned to the semaphore when it is * created. * * @return Handle to the created semaphore. Null if the semaphore could not be * created. * * Example usage: <pre> xSemaphoreHandle xSemaphore; void vATask( void * pvParameters ) { xSemaphoreHandle xSemaphore = NULL; // Semaphore cannot be used before a call to xSemaphoreCreateCounting(). // The max value to which the semaphore can count should be 10, and the // initial value assigned to the count should be 0. xSemaphore = xSemaphoreCreateCounting( 10, 0 ); if( xSemaphore != NULL ) { // The semaphore was created successfully. // The semaphore can now be used. } } </pre> * \defgroup xSemaphoreCreateCounting xSemaphoreCreateCounting * \ingroup Semaphores */ #define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ) xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ) ) /** * semphr. h * <pre>void vSemaphoreDelete( xSemaphoreHandle xSemaphore );</pre> * * Delete a semaphore. This function must be used with care. For example, * do not delete a mutex type semaphore if the mutex is held by a task. * * @param xSemaphore A handle to the semaphore to be deleted. * * \page vSemaphoreDelete vSemaphoreDelete * \ingroup Semaphores */ #define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( xQueueHandle ) xSemaphore ) #endif /* SEMAPHORE_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/include/semphr.h
C
oos
28,498
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef TIMERS_H #define TIMERS_H #ifndef INC_FREERTOS_H #error "include FreeRTOS.h must appear in source files before include timers.h" #endif #include "portable.h" #include "list.h" #include "task.h" #ifdef __cplusplus extern "C" { #endif /* IDs for commands that can be sent/received on the timer queue. These are to be used solely through the macros that make up the public software timer API, as defined below. */ #define tmrCOMMAND_START 0 #define tmrCOMMAND_STOP 1 #define tmrCOMMAND_CHANGE_PERIOD 2 #define tmrCOMMAND_DELETE 3 /*----------------------------------------------------------- * MACROS AND DEFINITIONS *----------------------------------------------------------*/ /** * Type by which software timers are referenced. For example, a call to * xTimerCreate() returns an xTimerHandle variable that can then be used to * reference the subject timer in calls to other software timer API functions * (for example, xTimerStart(), xTimerReset(), etc.). */ typedef void * xTimerHandle; /* Define the prototype to which timer callback functions must conform. */ typedef void (*tmrTIMER_CALLBACK)( xTimerHandle xTimer ); /** * xTimerHandle xTimerCreate( const signed char *pcTimerName, * portTickType xTimerPeriod, * unsigned portBASE_TYPE uxAutoReload, * void * pvTimerID, * tmrTIMER_CALLBACK pxCallbackFunction ); * * Creates a new software timer instance. This allocates the storage required * by the new timer, initialises the new timers internal state, and returns a * handle by which the new timer can be referenced. * * Timers are created in the dormant state. The xTimerStart(), xTimerReset(), * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the * active state. * * @param pcTimerName A text name that is assigned to the timer. This is done * purely to assist debugging. The kernel itself only ever references a timer by * its handle, and never by its name. * * @param xTimerPeriod The timer period. The time is defined in tick periods so * the constant portTICK_RATE_MS can be used to convert a time that has been * specified in milliseconds. For example, if the timer must expire after 100 * ticks, then xTimerPeriod should be set to 100. Alternatively, if the timer * must expire after 500ms, then xPeriod can be set to ( 500 / portTICK_RATE_MS ) * provided configTICK_RATE_HZ is less than or equal to 1000. * * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will * expire repeatedly with a frequency set by the xTimerPeriod parameter. If * uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and * enter the dormant state after it expires. * * @param pvTimerID An identifier that is assigned to the timer being created. * Typically this would be used in the timer callback function to identify which * timer expired when the same callback function is assigned to more than one * timer. * * @param pxCallbackFunction The function to call when the timer expires. * Callback functions must have the prototype defined by tmrTIMER_CALLBACK, * which is "void vCallbackFunction( xTimerHandle xTimer );". * * @return If the timer is successfully create then a handle to the newly * created timer is returned. If the timer cannot be created (because either * there is insufficient FreeRTOS heap remaining to allocate the timer * structures, or the timer period was set to 0) then 0 is returned. * * Example usage: * * * #define NUM_TIMERS 5 * * // An array to hold handles to the created timers. * xTimerHandle xTimers[ NUM_TIMERS ]; * * // An array to hold a count of the number of times each timer expires. * long lExpireCounters[ NUM_TIMERS ] = { 0 }; * * // Define a callback function that will be used by multiple timer instances. * // The callback function does nothing but count the number of times the * // associated timer expires, and stop the timer once the timer has expired * // 10 times. * void vTimerCallback( xTimerHandle pxTimer ) * { * long lArrayIndex; * const long xMaxExpiryCountBeforeStopping = 10; * * // Optionally do something if the pxTimer parameter is NULL. * configASSERT( pxTimer ); * * // Which timer expired? * lArrayIndex = ( long ) pvTimerGetTimerID( pxTimer ); * * // Increment the number of times that pxTimer has expired. * lExpireCounters[ lArrayIndex ] += 1; * * // If the timer has expired 10 times then stop it from running. * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping ) * { * // Do not use a block time if calling a timer API function from a * // timer callback function, as doing so could cause a deadlock! * xTimerStop( pxTimer, 0 ); * } * } * * void main( void ) * { * long x; * * // Create then start some timers. Starting the timers before the scheduler * // has been started means the timers will start running immediately that * // the scheduler starts. * for( x = 0; x < NUM_TIMERS; x++ ) * { * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel. * ( 100 * x ), // The timer period in ticks. * pdTRUE, // The timers will auto-reload themselves when they expire. * ( void * ) x, // Assign each timer a unique id equal to its array index. * vTimerCallback // Each timer calls the same callback when it expires. * ); * * if( xTimers[ x ] == NULL ) * { * // The timer was not created. * } * else * { * // Start the timer. No block time is specified, and even if one was * // it would be ignored because the scheduler has not yet been * // started. * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS ) * { * // The timer could not be set into the Active state. * } * } * } * * // ... * // Create tasks here. * // ... * * // Starting the scheduler will start the timers running as they have already * // been set into the active state. * xTaskStartScheduler(); * * // Should not reach here. * for( ;; ); * } */ xTimerHandle xTimerCreate( const signed char *pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void * pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction ) PRIVILEGED_FUNCTION; /** * void *pvTimerGetTimerID( xTimerHandle xTimer ); * * Returns the ID assigned to the timer. * * IDs are assigned to timers using the pvTimerID parameter of the call to * xTimerCreated() that was used to create the timer. * * If the same callback function is assigned to multiple timers then the timer * ID can be used within the callback function to identify which timer actually * expired. * * @param xTimer The timer being queried. * * @return The ID assigned to the timer being queried. * * Example usage: * * See the xTimerCreate() API function example usage scenario. */ void *pvTimerGetTimerID( xTimerHandle xTimer ) PRIVILEGED_FUNCTION; /** * portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer ); * * Queries a timer to see if it is active or dormant. * * A timer will be dormant if: * 1) It has been created but not started, or * 2) It is an expired on-shot timer that has not been restarted. * * Timers are created in the dormant state. The xTimerStart(), xTimerReset(), * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the * active state. * * @param xTimer The timer being queried. * * @return pdFALSE will be returned if the timer is dormant. A value other than * pdFALSE will be returned if the timer is active. * * Example usage: * * // This function assumes xTimer has already been created. * void vAFunction( xTimerHandle xTimer ) * { * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )" * { * // xTimer is active, do something. * } * else * { * // xTimer is not active, do something else. * } * } */ portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer ) PRIVILEGED_FUNCTION; /** * xTimerGetTimerDaemonTaskHandle() is only available if * INCLUDE_xTimerGetTimerDaemonTaskHandle is set to 1 in FreeRTOSConfig.h. * * Simply returns the handle of the timer service/daemon task. It it not valid * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started. */ xTaskHandle xTimerGetTimerDaemonTaskHandle( void ); /** * portBASE_TYPE xTimerStart( xTimerHandle xTimer, portTickType xBlockTime ); * * Timer functionality is provided by a timer service/daemon task. Many of the * public FreeRTOS timer API functions send commands to the timer service task * though a queue called the timer command queue. The timer command queue is * private to the kernel itself and is not directly accessible to application * code. The length of the timer command queue is set by the * configTIMER_QUEUE_LENGTH configuration constant. * * xTimerStart() starts a timer that was previously created using the * xTimerCreate() API function. If the timer had already been started and was * already in the active state, then xTimerStart() has equivalent functionality * to the xTimerReset() API function. * * Starting a timer ensures the timer is in the active state. If the timer * is not stopped, deleted, or reset in the mean time, the callback function * associated with the timer will get called 'n' ticks after xTimerStart() was * called, where 'n' is the timers defined period. * * It is valid to call xTimerStart() before the scheduler has been started, but * when this is done the timer will not actually start until the scheduler is * started, and the timers expiry time will be relative to when the scheduler is * started, not relative to when xTimerStart() was called. * * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart() * to be available. * * @param xTimer The handle of the timer being started/restarted. * * @param xBlockTime Specifies the time, in ticks, that the calling task should * be held in the Blocked state to wait for the start command to be successfully * sent to the timer command queue, should the queue already be full when * xTimerStart() was called. xBlockTime is ignored if xTimerStart() is called * before the scheduler is started. * * @return pdFAIL will be returned if the start command could not be sent to * the timer command queue even after xBlockTime ticks had passed. pdPASS will * be returned if the command was successfully sent to the timer command queue. * When the command is actually processed will depend on the priority of the * timer service/daemon task relative to other tasks in the system, although the * timers expiry time is relative to when xTimerStart() is actually called. The * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY * configuration constant. * * Example usage: * * See the xTimerCreate() API function example usage scenario. * */ #define xTimerStart( xTimer, xBlockTime ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xBlockTime ) ) /** * portBASE_TYPE xTimerStop( xTimerHandle xTimer, portTickType xBlockTime ); * * Timer functionality is provided by a timer service/daemon task. Many of the * public FreeRTOS timer API functions send commands to the timer service task * though a queue called the timer command queue. The timer command queue is * private to the kernel itself and is not directly accessible to application * code. The length of the timer command queue is set by the * configTIMER_QUEUE_LENGTH configuration constant. * * xTimerStop() stops a timer that was previously started using either of the * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(), * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions. * * Stopping a timer ensures the timer is not in the active state. * * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop() * to be available. * * @param xTimer The handle of the timer being stopped. * * @param xBlockTime Specifies the time, in ticks, that the calling task should * be held in the Blocked state to wait for the stop command to be successfully * sent to the timer command queue, should the queue already be full when * xTimerStop() was called. xBlockTime is ignored if xTimerStop() is called * before the scheduler is started. * * @return pdFAIL will be returned if the stop command could not be sent to * the timer command queue even after xBlockTime ticks had passed. pdPASS will * be returned if the command was successfully sent to the timer command queue. * When the command is actually processed will depend on the priority of the * timer service/daemon task relative to other tasks in the system. The timer * service/daemon task priority is set by the configTIMER_TASK_PRIORITY * configuration constant. * * Example usage: * * See the xTimerCreate() API function example usage scenario. * */ #define xTimerStop( xTimer, xBlockTime ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xBlockTime ) ) /** * portBASE_TYPE xTimerChangePeriod( xTimerHandle xTimer, * portTickType xNewPeriod, * portTickType xBlockTime ); * * Timer functionality is provided by a timer service/daemon task. Many of the * public FreeRTOS timer API functions send commands to the timer service task * though a queue called the timer command queue. The timer command queue is * private to the kernel itself and is not directly accessible to application * code. The length of the timer command queue is set by the * configTIMER_QUEUE_LENGTH configuration constant. * * xTimerChangePeriod() changes the period of a timer that was previously * created using the xTimerCreate() API function. * * xTimerChangePeriod() can be called to change the period of an active or * dormant state timer. * * The configUSE_TIMERS configuration constant must be set to 1 for * xTimerChangePeriod() to be available. * * @param xTimer The handle of the timer that is having its period changed. * * @param xNewPeriod The new period for xTimer. Timer periods are specified in * tick periods, so the constant portTICK_RATE_MS can be used to convert a time * that has been specified in milliseconds. For example, if the timer must * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively, * if the timer must expire after 500ms, then xNewPeriod can be set to * ( 500 / portTICK_RATE_MS ) provided configTICK_RATE_HZ is less than * or equal to 1000. * * @param xBlockTime Specifies the time, in ticks, that the calling task should * be held in the Blocked state to wait for the change period command to be * successfully sent to the timer command queue, should the queue already be * full when xTimerChangePeriod() was called. xBlockTime is ignored if * xTimerChangePeriod() is called before the scheduler is started. * * @return pdFAIL will be returned if the change period command could not be * sent to the timer command queue even after xBlockTime ticks had passed. * pdPASS will be returned if the command was successfully sent to the timer * command queue. When the command is actually processed will depend on the * priority of the timer service/daemon task relative to other tasks in the * system. The timer service/daemon task priority is set by the * configTIMER_TASK_PRIORITY configuration constant. * * Example usage: * * // This function assumes xTimer has already been created. If the timer * // referenced by xTimer is already active when it is called, then the timer * // is deleted. If the timer referenced by xTimer is not active when it is * // called, then the period of the timer is set to 500ms and the timer is * // started. * void vAFunction( xTimerHandle xTimer ) * { * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )" * { * // xTimer is already active - delete it. * xTimerDelete( xTimer ); * } * else * { * // xTimer is not active, change its period to 500ms. This will also * // cause the timer to start. Block for a maximum of 100 ticks if the * // change period command cannot immediately be sent to the timer * // command queue. * if( xTimerChangePeriod( xTimer, 500 / portTICK_RATE_MS, 100 ) == pdPASS ) * { * // The command was successfully sent. * } * else * { * // The command could not be sent, even after waiting for 100 ticks * // to pass. Take appropriate action here. * } * } * } */ #define xTimerChangePeriod( xTimer, xNewPeriod, xBlockTime ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xBlockTime ) ) /** * portBASE_TYPE xTimerDelete( xTimerHandle xTimer, portTickType xBlockTime ); * * Timer functionality is provided by a timer service/daemon task. Many of the * public FreeRTOS timer API functions send commands to the timer service task * though a queue called the timer command queue. The timer command queue is * private to the kernel itself and is not directly accessible to application * code. The length of the timer command queue is set by the * configTIMER_QUEUE_LENGTH configuration constant. * * xTimerDelete() deletes a timer that was previously created using the * xTimerCreate() API function. * * The configUSE_TIMERS configuration constant must be set to 1 for * xTimerDelete() to be available. * * @param xTimer The handle of the timer being deleted. * * @param xBlockTime Specifies the time, in ticks, that the calling task should * be held in the Blocked state to wait for the delete command to be * successfully sent to the timer command queue, should the queue already be * full when xTimerDelete() was called. xBlockTime is ignored if xTimerDelete() * is called before the scheduler is started. * * @return pdFAIL will be returned if the delete command could not be sent to * the timer command queue even after xBlockTime ticks had passed. pdPASS will * be returned if the command was successfully sent to the timer command queue. * When the command is actually processed will depend on the priority of the * timer service/daemon task relative to other tasks in the system. The timer * service/daemon task priority is set by the configTIMER_TASK_PRIORITY * configuration constant. * * Example usage: * * See the xTimerChangePeriod() API function example usage scenario. */ #define xTimerDelete( xTimer, xBlockTime ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xBlockTime ) ) /** * portBASE_TYPE xTimerReset( xTimerHandle xTimer, portTickType xBlockTime ); * * Timer functionality is provided by a timer service/daemon task. Many of the * public FreeRTOS timer API functions send commands to the timer service task * though a queue called the timer command queue. The timer command queue is * private to the kernel itself and is not directly accessible to application * code. The length of the timer command queue is set by the * configTIMER_QUEUE_LENGTH configuration constant. * * xTimerReset() re-starts a timer that was previously created using the * xTimerCreate() API function. If the timer had already been started and was * already in the active state, then xTimerReset() will cause the timer to * re-evaluate its expiry time so that it is relative to when xTimerReset() was * called. If the timer was in the dormant state then xTimerReset() has * equivalent functionality to the xTimerStart() API function. * * Resetting a timer ensures the timer is in the active state. If the timer * is not stopped, deleted, or reset in the mean time, the callback function * associated with the timer will get called 'n' ticks after xTimerReset() was * called, where 'n' is the timers defined period. * * It is valid to call xTimerReset() before the scheduler has been started, but * when this is done the timer will not actually start until the scheduler is * started, and the timers expiry time will be relative to when the scheduler is * started, not relative to when xTimerReset() was called. * * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset() * to be available. * * @param xTimer The handle of the timer being reset/started/restarted. * * @param xBlockTime Specifies the time, in ticks, that the calling task should * be held in the Blocked state to wait for the reset command to be successfully * sent to the timer command queue, should the queue already be full when * xTimerReset() was called. xBlockTime is ignored if xTimerReset() is called * before the scheduler is started. * * @return pdFAIL will be returned if the reset command could not be sent to * the timer command queue even after xBlockTime ticks had passed. pdPASS will * be returned if the command was successfully sent to the timer command queue. * When the command is actually processed will depend on the priority of the * timer service/daemon task relative to other tasks in the system, although the * timers expiry time is relative to when xTimerStart() is actually called. The * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY * configuration constant. * * Example usage: * * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass * // without a key being pressed, then the LCD back-light is switched off. In * // this case, the timer is a one-shot timer. * * xTimerHandle xBacklightTimer = NULL; * * // The callback function assigned to the one-shot timer. In this case the * // parameter is not used. * void vBacklightTimerCallback( xTimerHandle pxTimer ) * { * // The timer expired, therefore 5 seconds must have passed since a key * // was pressed. Switch off the LCD back-light. * vSetBacklightState( BACKLIGHT_OFF ); * } * * // The key press event handler. * void vKeyPressEventHandler( char cKey ) * { * // Ensure the LCD back-light is on, then reset the timer that is * // responsible for turning the back-light off after 5 seconds of * // key inactivity. Wait 10 ticks for the command to be successfully sent * // if it cannot be sent immediately. * vSetBacklightState( BACKLIGHT_ON ); * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS ) * { * // The reset command was not executed successfully. Take appropriate * // action here. * } * * // Perform the rest of the key processing here. * } * * void main( void ) * { * long x; * * // Create then start the one-shot timer that is responsible for turning * // the back-light off if no keys are pressed within a 5 second period. * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel. * ( 5000 / portTICK_RATE_MS), // The timer period in ticks. * pdFALSE, // The timer is a one-shot timer. * 0, // The id is not used by the callback so can take any value. * vBacklightTimerCallback // The callback function that switches the LCD back-light off. * ); * * if( xBacklightTimer == NULL ) * { * // The timer was not created. * } * else * { * // Start the timer. No block time is specified, and even if one was * // it would be ignored because the scheduler has not yet been * // started. * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS ) * { * // The timer could not be set into the Active state. * } * } * * // ... * // Create tasks here. * // ... * * // Starting the scheduler will start the timer running as it has already * // been set into the active state. * xTaskStartScheduler(); * * // Should not reach here. * for( ;; ); * } */ #define xTimerReset( xTimer, xBlockTime ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xBlockTime ) ) /** * portBASE_TYPE xTimerStartFromISR( xTimerHandle xTimer, * portBASE_TYPE *pxHigherPriorityTaskWoken ); * * A version of xTimerStart() that can be called from an interrupt service * routine. * * @param xTimer The handle of the timer being started/restarted. * * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most * of its time in the Blocked state, waiting for messages to arrive on the timer * command queue. Calling xTimerStartFromISR() writes a message to the timer * command queue, so has the potential to transition the timer service/daemon * task out of the Blocked state. If calling xTimerStartFromISR() causes the * timer service/daemon task to leave the Blocked state, and the timer service/ * daemon task has a priority equal to or greater than the currently executing * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will * get set to pdTRUE internally within the xTimerStartFromISR() function. If * xTimerStartFromISR() sets this value to pdTRUE then a context switch should * be performed before the interrupt exits. * * @return pdFAIL will be returned if the start command could not be sent to * the timer command queue. pdPASS will be returned if the command was * successfully sent to the timer command queue. When the command is actually * processed will depend on the priority of the timer service/daemon task * relative to other tasks in the system, although the timers expiry time is * relative to when xTimerStartFromISR() is actually called. The timer service/daemon * task priority is set by the configTIMER_TASK_PRIORITY configuration constant. * * Example usage: * * // This scenario assumes xBacklightTimer has already been created. When a * // key is pressed, an LCD back-light is switched on. If 5 seconds pass * // without a key being pressed, then the LCD back-light is switched off. In * // this case, the timer is a one-shot timer, and unlike the example given for * // the xTimerReset() function, the key press event handler is an interrupt * // service routine. * * // The callback function assigned to the one-shot timer. In this case the * // parameter is not used. * void vBacklightTimerCallback( xTimerHandle pxTimer ) * { * // The timer expired, therefore 5 seconds must have passed since a key * // was pressed. Switch off the LCD back-light. * vSetBacklightState( BACKLIGHT_OFF ); * } * * // The key press interrupt service routine. * void vKeyPressEventInterruptHandler( void ) * { * portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; * * // Ensure the LCD back-light is on, then restart the timer that is * // responsible for turning the back-light off after 5 seconds of * // key inactivity. This is an interrupt service routine so can only * // call FreeRTOS API functions that end in "FromISR". * vSetBacklightState( BACKLIGHT_ON ); * * // xTimerStartFromISR() or xTimerResetFromISR() could be called here * // as both cause the timer to re-calculate its expiry time. * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was * // declared (in this function). * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS ) * { * // The start command was not executed successfully. Take appropriate * // action here. * } * * // Perform the rest of the key processing here. * * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch * // should be performed. The syntax required to perform a context switch * // from inside an ISR varies from port to port, and from compiler to * // compiler. Inspect the demos for the port you are using to find the * // actual syntax required. * if( xHigherPriorityTaskWoken != pdFALSE ) * { * // Call the interrupt safe yield function here (actual function * // depends on the FreeRTOS port being used. * } * } */ #define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U ) /** * portBASE_TYPE xTimerStopFromISR( xTimerHandle xTimer, * portBASE_TYPE *pxHigherPriorityTaskWoken ); * * A version of xTimerStop() that can be called from an interrupt service * routine. * * @param xTimer The handle of the timer being stopped. * * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most * of its time in the Blocked state, waiting for messages to arrive on the timer * command queue. Calling xTimerStopFromISR() writes a message to the timer * command queue, so has the potential to transition the timer service/daemon * task out of the Blocked state. If calling xTimerStopFromISR() causes the * timer service/daemon task to leave the Blocked state, and the timer service/ * daemon task has a priority equal to or greater than the currently executing * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will * get set to pdTRUE internally within the xTimerStopFromISR() function. If * xTimerStopFromISR() sets this value to pdTRUE then a context switch should * be performed before the interrupt exits. * * @return pdFAIL will be returned if the stop command could not be sent to * the timer command queue. pdPASS will be returned if the command was * successfully sent to the timer command queue. When the command is actually * processed will depend on the priority of the timer service/daemon task * relative to other tasks in the system. The timer service/daemon task * priority is set by the configTIMER_TASK_PRIORITY configuration constant. * * Example usage: * * // This scenario assumes xTimer has already been created and started. When * // an interrupt occurs, the timer should be simply stopped. * * // The interrupt service routine that stops the timer. * void vAnExampleInterruptServiceRoutine( void ) * { * portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; * * // The interrupt has occurred - simply stop the timer. * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined * // (within this function). As this is an interrupt service routine, only * // FreeRTOS API functions that end in "FromISR" can be used. * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS ) * { * // The stop command was not executed successfully. Take appropriate * // action here. * } * * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch * // should be performed. The syntax required to perform a context switch * // from inside an ISR varies from port to port, and from compiler to * // compiler. Inspect the demos for the port you are using to find the * // actual syntax required. * if( xHigherPriorityTaskWoken != pdFALSE ) * { * // Call the interrupt safe yield function here (actual function * // depends on the FreeRTOS port being used. * } * } */ #define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0, ( pxHigherPriorityTaskWoken ), 0U ) /** * portBASE_TYPE xTimerChangePeriodFromISR( xTimerHandle xTimer, * portTickType xNewPeriod, * portBASE_TYPE *pxHigherPriorityTaskWoken ); * * A version of xTimerChangePeriod() that can be called from an interrupt * service routine. * * @param xTimer The handle of the timer that is having its period changed. * * @param xNewPeriod The new period for xTimer. Timer periods are specified in * tick periods, so the constant portTICK_RATE_MS can be used to convert a time * that has been specified in milliseconds. For example, if the timer must * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively, * if the timer must expire after 500ms, then xNewPeriod can be set to * ( 500 / portTICK_RATE_MS ) provided configTICK_RATE_HZ is less than * or equal to 1000. * * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most * of its time in the Blocked state, waiting for messages to arrive on the timer * command queue. Calling xTimerChangePeriodFromISR() writes a message to the * timer command queue, so has the potential to transition the timer service/ * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR() * causes the timer service/daemon task to leave the Blocked state, and the * timer service/daemon task has a priority equal to or greater than the * currently executing task (the task that was interrupted), then * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets * this value to pdTRUE then a context switch should be performed before the * interrupt exits. * * @return pdFAIL will be returned if the command to change the timers period * could not be sent to the timer command queue. pdPASS will be returned if the * command was successfully sent to the timer command queue. When the command * is actually processed will depend on the priority of the timer service/daemon * task relative to other tasks in the system. The timer service/daemon task * priority is set by the configTIMER_TASK_PRIORITY configuration constant. * * Example usage: * * // This scenario assumes xTimer has already been created and started. When * // an interrupt occurs, the period of xTimer should be changed to 500ms. * * // The interrupt service routine that changes the period of xTimer. * void vAnExampleInterruptServiceRoutine( void ) * { * portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; * * // The interrupt has occurred - change the period of xTimer to 500ms. * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined * // (within this function). As this is an interrupt service routine, only * // FreeRTOS API functions that end in "FromISR" can be used. * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS ) * { * // The command to change the timers period was not executed * // successfully. Take appropriate action here. * } * * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch * // should be performed. The syntax required to perform a context switch * // from inside an ISR varies from port to port, and from compiler to * // compiler. Inspect the demos for the port you are using to find the * // actual syntax required. * if( xHigherPriorityTaskWoken != pdFALSE ) * { * // Call the interrupt safe yield function here (actual function * // depends on the FreeRTOS port being used. * } * } */ #define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U ) /** * portBASE_TYPE xTimerResetFromISR( xTimerHandle xTimer, * portBASE_TYPE *pxHigherPriorityTaskWoken ); * * A version of xTimerReset() that can be called from an interrupt service * routine. * * @param xTimer The handle of the timer that is to be started, reset, or * restarted. * * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most * of its time in the Blocked state, waiting for messages to arrive on the timer * command queue. Calling xTimerResetFromISR() writes a message to the timer * command queue, so has the potential to transition the timer service/daemon * task out of the Blocked state. If calling xTimerResetFromISR() causes the * timer service/daemon task to leave the Blocked state, and the timer service/ * daemon task has a priority equal to or greater than the currently executing * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will * get set to pdTRUE internally within the xTimerResetFromISR() function. If * xTimerResetFromISR() sets this value to pdTRUE then a context switch should * be performed before the interrupt exits. * * @return pdFAIL will be returned if the reset command could not be sent to * the timer command queue. pdPASS will be returned if the command was * successfully sent to the timer command queue. When the command is actually * processed will depend on the priority of the timer service/daemon task * relative to other tasks in the system, although the timers expiry time is * relative to when xTimerResetFromISR() is actually called. The timer service/daemon * task priority is set by the configTIMER_TASK_PRIORITY configuration constant. * * Example usage: * * // This scenario assumes xBacklightTimer has already been created. When a * // key is pressed, an LCD back-light is switched on. If 5 seconds pass * // without a key being pressed, then the LCD back-light is switched off. In * // this case, the timer is a one-shot timer, and unlike the example given for * // the xTimerReset() function, the key press event handler is an interrupt * // service routine. * * // The callback function assigned to the one-shot timer. In this case the * // parameter is not used. * void vBacklightTimerCallback( xTimerHandle pxTimer ) * { * // The timer expired, therefore 5 seconds must have passed since a key * // was pressed. Switch off the LCD back-light. * vSetBacklightState( BACKLIGHT_OFF ); * } * * // The key press interrupt service routine. * void vKeyPressEventInterruptHandler( void ) * { * portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; * * // Ensure the LCD back-light is on, then reset the timer that is * // responsible for turning the back-light off after 5 seconds of * // key inactivity. This is an interrupt service routine so can only * // call FreeRTOS API functions that end in "FromISR". * vSetBacklightState( BACKLIGHT_ON ); * * // xTimerStartFromISR() or xTimerResetFromISR() could be called here * // as both cause the timer to re-calculate its expiry time. * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was * // declared (in this function). * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS ) * { * // The reset command was not executed successfully. Take appropriate * // action here. * } * * // Perform the rest of the key processing here. * * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch * // should be performed. The syntax required to perform a context switch * // from inside an ISR varies from port to port, and from compiler to * // compiler. Inspect the demos for the port you are using to find the * // actual syntax required. * if( xHigherPriorityTaskWoken != pdFALSE ) * { * // Call the interrupt safe yield function here (actual function * // depends on the FreeRTOS port being used. * } * } */ #define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U ) /* * Functions beyond this part are not part of the public API and are intended * for use by the kernel only. */ portBASE_TYPE xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION; portBASE_TYPE xTimerGenericCommand( xTimerHandle xTimer, portBASE_TYPE xCommandID, portTickType xOptionalValue, portBASE_TYPE *pxHigherPriorityTaskWoken, portTickType xBlockTime ) PRIVILEGED_FUNCTION; #ifdef __cplusplus } #endif #endif /* TIMERS_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/include/timers.h
C
oos
44,681
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef MPU_WRAPPERS_H #define MPU_WRAPPERS_H /* This file redefines API functions to be called through a wrapper macro, but only for ports that are using the MPU. */ #ifdef portUSING_MPU_WRAPPERS /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE will be defined when this file is included from queue.c or task.c to prevent it from having an effect within those files. */ #ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE #define xTaskGenericCreate MPU_xTaskGenericCreate #define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions #define vTaskDelete MPU_vTaskDelete #define vTaskDelayUntil MPU_vTaskDelayUntil #define vTaskDelay MPU_vTaskDelay #define uxTaskPriorityGet MPU_uxTaskPriorityGet #define vTaskPrioritySet MPU_vTaskPrioritySet #define vTaskSuspend MPU_vTaskSuspend #define xTaskIsTaskSuspended MPU_xTaskIsTaskSuspended #define vTaskResume MPU_vTaskResume #define vTaskSuspendAll MPU_vTaskSuspendAll #define xTaskResumeAll MPU_xTaskResumeAll #define xTaskGetTickCount MPU_xTaskGetTickCount #define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks #define vTaskList MPU_vTaskList #define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats #define vTaskStartTrace MPU_vTaskStartTrace #define ulTaskEndTrace MPU_ulTaskEndTrace #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState #define xQueueCreate MPU_xQueueCreate #define xQueueCreateMutex MPU_xQueueCreateMutex #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore #define xQueueGenericSend MPU_xQueueGenericSend #define xQueueAltGenericSend MPU_xQueueAltGenericSend #define xQueueAltGenericReceive MPU_xQueueAltGenericReceive #define xQueueGenericReceive MPU_xQueueGenericReceive #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting #define vQueueDelete MPU_vQueueDelete #define pvPortMalloc MPU_pvPortMalloc #define vPortFree MPU_vPortFree #define xPortGetFreeHeapSize MPU_xPortGetFreeHeapSize #define vPortInitialiseBlocks MPU_vPortInitialiseBlocks #if configQUEUE_REGISTRY_SIZE > 0 #define vQueueAddToRegistry MPU_vQueueAddToRegistry #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue #endif /* Remove the privileged function macro. */ #define PRIVILEGED_FUNCTION #else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ /* Ensure API functions go in the privileged execution section. */ #define PRIVILEGED_FUNCTION __attribute__((section("privileged_functions"))) #define PRIVILEGED_DATA __attribute__((section("privileged_data"))) //#define PRIVILEGED_DATA #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ #else /* portUSING_MPU_WRAPPERS */ #define PRIVILEGED_FUNCTION #define PRIVILEGED_DATA #define portUSING_MPU_WRAPPERS 0 #endif /* portUSING_MPU_WRAPPERS */ #endif /* MPU_WRAPPERS_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/include/mpu_wrappers.h
C
oos
6,412
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef PROJDEFS_H #define PROJDEFS_H /* Defines the prototype to which task functions must conform. */ typedef void (*pdTASK_CODE)( void * ); #define pdTRUE ( 1 ) #define pdFALSE ( 0 ) #define pdPASS ( 1 ) #define pdFAIL ( 0 ) #define errQUEUE_EMPTY ( 0 ) #define errQUEUE_FULL ( 0 ) /* Error definitions. */ #define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 ) #define errNO_TASK_TO_RUN ( -2 ) #define errQUEUE_BLOCKED ( -4 ) #define errQUEUE_YIELD ( -5 ) #endif /* PROJDEFS_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/include/projdefs.h
C
oos
3,526
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef QUEUE_H #define QUEUE_H #ifndef INC_FREERTOS_H #error "#include FreeRTOS.h" must appear in source files before "#include queue.h" #endif #ifdef __cplusplus extern "C" { #endif #include "mpu_wrappers.h" /** * Type by which queues are referenced. For example, a call to xQueueCreate * returns (via a pointer parameter) an xQueueHandle variable that can then * be used as a parameter to xQueueSend(), xQueueReceive(), etc. */ typedef void * xQueueHandle; /* For internal use only. */ #define queueSEND_TO_BACK ( 0 ) #define queueSEND_TO_FRONT ( 1 ) /** * queue. h * <pre> xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize ); * </pre> * * Creates a new queue instance. This allocates the storage required by the * new queue and returns a handle for the queue. * * @param uxQueueLength The maximum number of items that the queue can contain. * * @param uxItemSize The number of bytes each item in the queue will require. * Items are queued by copy, not by reference, so this is the number of bytes * that will be copied for each posted item. Each item on the queue must be * the same size. * * @return If the queue is successfully create then a handle to the newly * created queue is returned. If the queue cannot be created then 0 is * returned. * * Example usage: <pre> struct AMessage { char ucMessageID; char ucData[ 20 ]; }; void vATask( void *pvParameters ) { xQueueHandle xQueue1, xQueue2; // Create a queue capable of containing 10 unsigned long values. xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) ); if( xQueue1 == 0 ) { // Queue was not created and must not be used. } // Create a queue capable of containing 10 pointers to AMessage structures. // These should be passed by pointer as they contain a lot of data. xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) ); if( xQueue2 == 0 ) { // Queue was not created and must not be used. } // ... Rest of task code. } </pre> * \defgroup xQueueCreate xQueueCreate * \ingroup QueueManagement */ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize ); /** * queue. h * <pre> portBASE_TYPE xQueueSendToToFront( xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait ); * </pre> * * This is a macro that calls xQueueGenericSend(). * * Post an item to the front of a queue. The item is queued by copy, not by * reference. This function must not be called from an interrupt service * routine. See xQueueSendFromISR () for an alternative which may be used * in an ISR. * * @param xQueue The handle to the queue on which the item is to be posted. * * @param pvItemToQueue A pointer to the item that is to be placed on the * queue. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from pvItemToQueue * into the queue storage area. * * @param xTicksToWait The maximum amount of time the task should block * waiting for space to become available on the queue, should it already * be full. The call will return immediately if this is set to 0 and the * queue is full. The time is defined in tick periods so the constant * portTICK_RATE_MS should be used to convert to real time if this is required. * * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. * * Example usage: <pre> struct AMessage { char ucMessageID; char ucData[ 20 ]; } xMessage; unsigned long ulVar = 10UL; void vATask( void *pvParameters ) { xQueueHandle xQueue1, xQueue2; struct AMessage *pxMessage; // Create a queue capable of containing 10 unsigned long values. xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) ); // Create a queue capable of containing 10 pointers to AMessage structures. // These should be passed by pointer as they contain a lot of data. xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) ); // ... if( xQueue1 != 0 ) { // Send an unsigned long. Wait for 10 ticks for space to become // available if necessary. if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS ) { // Failed to post the message, even after 10 ticks. } } if( xQueue2 != 0 ) { // Send a pointer to a struct AMessage object. Don't block if the // queue is already full. pxMessage = & xMessage; xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 ); } // ... Rest of task code. } </pre> * \defgroup xQueueSend xQueueSend * \ingroup QueueManagement */ #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT ) /** * queue. h * <pre> portBASE_TYPE xQueueSendToBack( xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait ); * </pre> * * This is a macro that calls xQueueGenericSend(). * * Post an item to the back of a queue. The item is queued by copy, not by * reference. This function must not be called from an interrupt service * routine. See xQueueSendFromISR () for an alternative which may be used * in an ISR. * * @param xQueue The handle to the queue on which the item is to be posted. * * @param pvItemToQueue A pointer to the item that is to be placed on the * queue. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from pvItemToQueue * into the queue storage area. * * @param xTicksToWait The maximum amount of time the task should block * waiting for space to become available on the queue, should it already * be full. The call will return immediately if this is set to 0 and the queue * is full. The time is defined in tick periods so the constant * portTICK_RATE_MS should be used to convert to real time if this is required. * * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. * * Example usage: <pre> struct AMessage { char ucMessageID; char ucData[ 20 ]; } xMessage; unsigned long ulVar = 10UL; void vATask( void *pvParameters ) { xQueueHandle xQueue1, xQueue2; struct AMessage *pxMessage; // Create a queue capable of containing 10 unsigned long values. xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) ); // Create a queue capable of containing 10 pointers to AMessage structures. // These should be passed by pointer as they contain a lot of data. xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) ); // ... if( xQueue1 != 0 ) { // Send an unsigned long. Wait for 10 ticks for space to become // available if necessary. if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS ) { // Failed to post the message, even after 10 ticks. } } if( xQueue2 != 0 ) { // Send a pointer to a struct AMessage object. Don't block if the // queue is already full. pxMessage = & xMessage; xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 ); } // ... Rest of task code. } </pre> * \defgroup xQueueSend xQueueSend * \ingroup QueueManagement */ #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK ) /** * queue. h * <pre> portBASE_TYPE xQueueSend( xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait ); * </pre> * * This is a macro that calls xQueueGenericSend(). It is included for * backward compatibility with versions of FreeRTOS.org that did not * include the xQueueSendToFront() and xQueueSendToBack() macros. It is * equivalent to xQueueSendToBack(). * * Post an item on a queue. The item is queued by copy, not by reference. * This function must not be called from an interrupt service routine. * See xQueueSendFromISR () for an alternative which may be used in an ISR. * * @param xQueue The handle to the queue on which the item is to be posted. * * @param pvItemToQueue A pointer to the item that is to be placed on the * queue. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from pvItemToQueue * into the queue storage area. * * @param xTicksToWait The maximum amount of time the task should block * waiting for space to become available on the queue, should it already * be full. The call will return immediately if this is set to 0 and the * queue is full. The time is defined in tick periods so the constant * portTICK_RATE_MS should be used to convert to real time if this is required. * * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. * * Example usage: <pre> struct AMessage { char ucMessageID; char ucData[ 20 ]; } xMessage; unsigned long ulVar = 10UL; void vATask( void *pvParameters ) { xQueueHandle xQueue1, xQueue2; struct AMessage *pxMessage; // Create a queue capable of containing 10 unsigned long values. xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) ); // Create a queue capable of containing 10 pointers to AMessage structures. // These should be passed by pointer as they contain a lot of data. xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) ); // ... if( xQueue1 != 0 ) { // Send an unsigned long. Wait for 10 ticks for space to become // available if necessary. if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS ) { // Failed to post the message, even after 10 ticks. } } if( xQueue2 != 0 ) { // Send a pointer to a struct AMessage object. Don't block if the // queue is already full. pxMessage = & xMessage; xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 ); } // ... Rest of task code. } </pre> * \defgroup xQueueSend xQueueSend * \ingroup QueueManagement */ #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK ) /** * queue. h * <pre> portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait portBASE_TYPE xCopyPosition ); * </pre> * * It is preferred that the macros xQueueSend(), xQueueSendToFront() and * xQueueSendToBack() are used in place of calling this function directly. * * Post an item on a queue. The item is queued by copy, not by reference. * This function must not be called from an interrupt service routine. * See xQueueSendFromISR () for an alternative which may be used in an ISR. * * @param xQueue The handle to the queue on which the item is to be posted. * * @param pvItemToQueue A pointer to the item that is to be placed on the * queue. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from pvItemToQueue * into the queue storage area. * * @param xTicksToWait The maximum amount of time the task should block * waiting for space to become available on the queue, should it already * be full. The call will return immediately if this is set to 0 and the * queue is full. The time is defined in tick periods so the constant * portTICK_RATE_MS should be used to convert to real time if this is required. * * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the * item at the back of the queue, or queueSEND_TO_FRONT to place the item * at the front of the queue (for high priority messages). * * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. * * Example usage: <pre> struct AMessage { char ucMessageID; char ucData[ 20 ]; } xMessage; unsigned long ulVar = 10UL; void vATask( void *pvParameters ) { xQueueHandle xQueue1, xQueue2; struct AMessage *pxMessage; // Create a queue capable of containing 10 unsigned long values. xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) ); // Create a queue capable of containing 10 pointers to AMessage structures. // These should be passed by pointer as they contain a lot of data. xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) ); // ... if( xQueue1 != 0 ) { // Send an unsigned long. Wait for 10 ticks for space to become // available if necessary. if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS ) { // Failed to post the message, even after 10 ticks. } } if( xQueue2 != 0 ) { // Send a pointer to a struct AMessage object. Don't block if the // queue is already full. pxMessage = & xMessage; xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK ); } // ... Rest of task code. } </pre> * \defgroup xQueueSend xQueueSend * \ingroup QueueManagement */ signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ); /** * queue. h * <pre> portBASE_TYPE xQueuePeek( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait );</pre> * * This is a macro that calls the xQueueGenericReceive() function. * * Receive an item from a queue without removing the item from the queue. * The item is received by copy so a buffer of adequate size must be * provided. The number of bytes copied into the buffer was defined when * the queue was created. * * Successfully received items remain on the queue so will be returned again * by the next call, or a call to xQueueReceive(). * * This macro must not be used in an interrupt service routine. * * @param pxQueue The handle to the queue from which the item is to be * received. * * @param pvBuffer Pointer to the buffer into which the received item will * be copied. * * @param xTicksToWait The maximum amount of time the task should block * waiting for an item to receive should the queue be empty at the time * of the call. The time is defined in tick periods so the constant * portTICK_RATE_MS should be used to convert to real time if this is required. * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue * is empty. * * @return pdTRUE if an item was successfully received from the queue, * otherwise pdFALSE. * * Example usage: <pre> struct AMessage { char ucMessageID; char ucData[ 20 ]; } xMessage; xQueueHandle xQueue; // Task to create a queue and post a value. void vATask( void *pvParameters ) { struct AMessage *pxMessage; // Create a queue capable of containing 10 pointers to AMessage structures. // These should be passed by pointer as they contain a lot of data. xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) ); if( xQueue == 0 ) { // Failed to create the queue. } // ... // Send a pointer to a struct AMessage object. Don't block if the // queue is already full. pxMessage = & xMessage; xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 ); // ... Rest of task code. } // Task to peek the data from the queue. void vADifferentTask( void *pvParameters ) { struct AMessage *pxRxedMessage; if( xQueue != 0 ) { // Peek a message on the created queue. Block for 10 ticks if a // message is not immediately available. if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) ) { // pcRxedMessage now points to the struct AMessage variable posted // by vATask, but the item still remains on the queue. } } // ... Rest of task code. } </pre> * \defgroup xQueueReceive xQueueReceive * \ingroup QueueManagement */ #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE ) /** * queue. h * <pre> portBASE_TYPE xQueueReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait );</pre> * * This is a macro that calls the xQueueGenericReceive() function. * * Receive an item from a queue. The item is received by copy so a buffer of * adequate size must be provided. The number of bytes copied into the buffer * was defined when the queue was created. * * Successfully received items are removed from the queue. * * This function must not be used in an interrupt service routine. See * xQueueReceiveFromISR for an alternative that can. * * @param pxQueue The handle to the queue from which the item is to be * received. * * @param pvBuffer Pointer to the buffer into which the received item will * be copied. * * @param xTicksToWait The maximum amount of time the task should block * waiting for an item to receive should the queue be empty at the time * of the call. xQueueReceive() will return immediately if xTicksToWait * is zero and the queue is empty. The time is defined in tick periods so the * constant portTICK_RATE_MS should be used to convert to real time if this is * required. * * @return pdTRUE if an item was successfully received from the queue, * otherwise pdFALSE. * * Example usage: <pre> struct AMessage { char ucMessageID; char ucData[ 20 ]; } xMessage; xQueueHandle xQueue; // Task to create a queue and post a value. void vATask( void *pvParameters ) { struct AMessage *pxMessage; // Create a queue capable of containing 10 pointers to AMessage structures. // These should be passed by pointer as they contain a lot of data. xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) ); if( xQueue == 0 ) { // Failed to create the queue. } // ... // Send a pointer to a struct AMessage object. Don't block if the // queue is already full. pxMessage = & xMessage; xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 ); // ... Rest of task code. } // Task to receive from the queue. void vADifferentTask( void *pvParameters ) { struct AMessage *pxRxedMessage; if( xQueue != 0 ) { // Receive a message on the created queue. Block for 10 ticks if a // message is not immediately available. if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) ) { // pcRxedMessage now points to the struct AMessage variable posted // by vATask. } } // ... Rest of task code. } </pre> * \defgroup xQueueReceive xQueueReceive * \ingroup QueueManagement */ #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE ) /** * queue. h * <pre> portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait portBASE_TYPE xJustPeek );</pre> * * It is preferred that the macro xQueueReceive() be used rather than calling * this function directly. * * Receive an item from a queue. The item is received by copy so a buffer of * adequate size must be provided. The number of bytes copied into the buffer * was defined when the queue was created. * * This function must not be used in an interrupt service routine. See * xQueueReceiveFromISR for an alternative that can. * * @param pxQueue The handle to the queue from which the item is to be * received. * * @param pvBuffer Pointer to the buffer into which the received item will * be copied. * * @param xTicksToWait The maximum amount of time the task should block * waiting for an item to receive should the queue be empty at the time * of the call. The time is defined in tick periods so the constant * portTICK_RATE_MS should be used to convert to real time if this is required. * xQueueGenericReceive() will return immediately if the queue is empty and * xTicksToWait is 0. * * @param xJustPeek When set to true, the item received from the queue is not * actually removed from the queue - meaning a subsequent call to * xQueueReceive() will return the same item. When set to false, the item * being received from the queue is also removed from the queue. * * @return pdTRUE if an item was successfully received from the queue, * otherwise pdFALSE. * * Example usage: <pre> struct AMessage { char ucMessageID; char ucData[ 20 ]; } xMessage; xQueueHandle xQueue; // Task to create a queue and post a value. void vATask( void *pvParameters ) { struct AMessage *pxMessage; // Create a queue capable of containing 10 pointers to AMessage structures. // These should be passed by pointer as they contain a lot of data. xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) ); if( xQueue == 0 ) { // Failed to create the queue. } // ... // Send a pointer to a struct AMessage object. Don't block if the // queue is already full. pxMessage = & xMessage; xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 ); // ... Rest of task code. } // Task to receive from the queue. void vADifferentTask( void *pvParameters ) { struct AMessage *pxRxedMessage; if( xQueue != 0 ) { // Receive a message on the created queue. Block for 10 ticks if a // message is not immediately available. if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) ) { // pcRxedMessage now points to the struct AMessage variable posted // by vATask. } } // ... Rest of task code. } </pre> * \defgroup xQueueReceive xQueueReceive * \ingroup QueueManagement */ signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek ); /** * queue. h * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre> * * Return the number of messages stored in a queue. * * @param xQueue A handle to the queue being queried. * * @return The number of messages available in the queue. * * \page uxQueueMessagesWaiting uxQueueMessagesWaiting * \ingroup QueueManagement */ unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue ); /** * queue. h * <pre>void vQueueDelete( xQueueHandle xQueue );</pre> * * Delete a queue - freeing all the memory allocated for storing of items * placed on the queue. * * @param xQueue A handle to the queue to be deleted. * * \page vQueueDelete vQueueDelete * \ingroup QueueManagement */ void vQueueDelete( xQueueHandle pxQueue ); /** * queue. h * <pre> portBASE_TYPE xQueueSendToFrontFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, portBASE_TYPE *pxHigherPriorityTaskWoken ); </pre> * * This is a macro that calls xQueueGenericSendFromISR(). * * Post an item to the front of a queue. It is safe to use this macro from * within an interrupt service routine. * * Items are queued by copy not reference so it is preferable to only * queue small items, especially when called from an ISR. In most cases * it would be preferable to store a pointer to the item being queued. * * @param xQueue The handle to the queue on which the item is to be posted. * * @param pvItemToQueue A pointer to the item that is to be placed on the * queue. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from pvItemToQueue * into the queue storage area. * * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task * to unblock, and the unblocked task has a priority higher than the currently * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then * a context switch should be requested before the interrupt is exited. * * @return pdTRUE if the data was successfully sent to the queue, otherwise * errQUEUE_FULL. * * Example usage for buffered IO (where the ISR can obtain more than one value * per call): <pre> void vBufferISR( void ) { char cIn; portBASE_TYPE xHigherPrioritTaskWoken; // We have not woken a task at the start of the ISR. xHigherPriorityTaskWoken = pdFALSE; // Loop until the buffer is empty. do { // Obtain a byte from the buffer. cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS ); // Post the byte. xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken ); } while( portINPUT_BYTE( BUFFER_COUNT ) ); // Now the buffer is empty we can switch context if necessary. if( xHigherPriorityTaskWoken ) { taskYIELD (); } } </pre> * * \defgroup xQueueSendFromISR xQueueSendFromISR * \ingroup QueueManagement */ #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT ) /** * queue. h * <pre> portBASE_TYPE xQueueSendToBackFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, portBASE_TYPE *pxHigherPriorityTaskWoken ); </pre> * * This is a macro that calls xQueueGenericSendFromISR(). * * Post an item to the back of a queue. It is safe to use this macro from * within an interrupt service routine. * * Items are queued by copy not reference so it is preferable to only * queue small items, especially when called from an ISR. In most cases * it would be preferable to store a pointer to the item being queued. * * @param xQueue The handle to the queue on which the item is to be posted. * * @param pvItemToQueue A pointer to the item that is to be placed on the * queue. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from pvItemToQueue * into the queue storage area. * * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task * to unblock, and the unblocked task has a priority higher than the currently * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then * a context switch should be requested before the interrupt is exited. * * @return pdTRUE if the data was successfully sent to the queue, otherwise * errQUEUE_FULL. * * Example usage for buffered IO (where the ISR can obtain more than one value * per call): <pre> void vBufferISR( void ) { char cIn; portBASE_TYPE xHigherPriorityTaskWoken; // We have not woken a task at the start of the ISR. xHigherPriorityTaskWoken = pdFALSE; // Loop until the buffer is empty. do { // Obtain a byte from the buffer. cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS ); // Post the byte. xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken ); } while( portINPUT_BYTE( BUFFER_COUNT ) ); // Now the buffer is empty we can switch context if necessary. if( xHigherPriorityTaskWoken ) { taskYIELD (); } } </pre> * * \defgroup xQueueSendFromISR xQueueSendFromISR * \ingroup QueueManagement */ #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK ) /** * queue. h * <pre> portBASE_TYPE xQueueSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, portBASE_TYPE *pxHigherPriorityTaskWoken ); </pre> * * This is a macro that calls xQueueGenericSendFromISR(). It is included * for backward compatibility with versions of FreeRTOS.org that did not * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR() * macros. * * Post an item to the back of a queue. It is safe to use this function from * within an interrupt service routine. * * Items are queued by copy not reference so it is preferable to only * queue small items, especially when called from an ISR. In most cases * it would be preferable to store a pointer to the item being queued. * * @param xQueue The handle to the queue on which the item is to be posted. * * @param pvItemToQueue A pointer to the item that is to be placed on the * queue. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from pvItemToQueue * into the queue storage area. * * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task * to unblock, and the unblocked task has a priority higher than the currently * running task. If xQueueSendFromISR() sets this value to pdTRUE then * a context switch should be requested before the interrupt is exited. * * @return pdTRUE if the data was successfully sent to the queue, otherwise * errQUEUE_FULL. * * Example usage for buffered IO (where the ISR can obtain more than one value * per call): <pre> void vBufferISR( void ) { char cIn; portBASE_TYPE xHigherPriorityTaskWoken; // We have not woken a task at the start of the ISR. xHigherPriorityTaskWoken = pdFALSE; // Loop until the buffer is empty. do { // Obtain a byte from the buffer. cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS ); // Post the byte. xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken ); } while( portINPUT_BYTE( BUFFER_COUNT ) ); // Now the buffer is empty we can switch context if necessary. if( xHigherPriorityTaskWoken ) { // Actual macro used here is port specific. taskYIELD_FROM_ISR (); } } </pre> * * \defgroup xQueueSendFromISR xQueueSendFromISR * \ingroup QueueManagement */ #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK ) /** * queue. h * <pre> portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ); </pre> * * It is preferred that the macros xQueueSendFromISR(), * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place * of calling this function directly. * * Post an item on a queue. It is safe to use this function from within an * interrupt service routine. * * Items are queued by copy not reference so it is preferable to only * queue small items, especially when called from an ISR. In most cases * it would be preferable to store a pointer to the item being queued. * * @param xQueue The handle to the queue on which the item is to be posted. * * @param pvItemToQueue A pointer to the item that is to be placed on the * queue. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from pvItemToQueue * into the queue storage area. * * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task * to unblock, and the unblocked task has a priority higher than the currently * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then * a context switch should be requested before the interrupt is exited. * * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the * item at the back of the queue, or queueSEND_TO_FRONT to place the item * at the front of the queue (for high priority messages). * * @return pdTRUE if the data was successfully sent to the queue, otherwise * errQUEUE_FULL. * * Example usage for buffered IO (where the ISR can obtain more than one value * per call): <pre> void vBufferISR( void ) { char cIn; portBASE_TYPE xHigherPriorityTaskWokenByPost; // We have not woken a task at the start of the ISR. xHigherPriorityTaskWokenByPost = pdFALSE; // Loop until the buffer is empty. do { // Obtain a byte from the buffer. cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS ); // Post each byte. xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK ); } while( portINPUT_BYTE( BUFFER_COUNT ) ); // Now the buffer is empty we can switch context if necessary. Note that the // name of the yield function required is port specific. if( xHigherPriorityTaskWokenByPost ) { taskYIELD_YIELD_FROM_ISR(); } } </pre> * * \defgroup xQueueSendFromISR xQueueSendFromISR * \ingroup QueueManagement */ signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ); /** * queue. h * <pre> portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, portBASE_TYPE *pxTaskWoken ); * </pre> * * Receive an item from a queue. It is safe to use this function from within an * interrupt service routine. * * @param pxQueue The handle to the queue from which the item is to be * received. * * @param pvBuffer Pointer to the buffer into which the received item will * be copied. * * @param pxTaskWoken A task may be blocked waiting for space to become * available on the queue. If xQueueReceiveFromISR causes such a task to * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will * remain unchanged. * * @return pdTRUE if an item was successfully received from the queue, * otherwise pdFALSE. * * Example usage: <pre> xQueueHandle xQueue; // Function to create a queue and post some values. void vAFunction( void *pvParameters ) { char cValueToPost; const portTickType xBlockTime = ( portTickType )0xff; // Create a queue capable of containing 10 characters. xQueue = xQueueCreate( 10, sizeof( char ) ); if( xQueue == 0 ) { // Failed to create the queue. } // ... // Post some characters that will be used within an ISR. If the queue // is full then this task will block for xBlockTime ticks. cValueToPost = 'a'; xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime ); cValueToPost = 'b'; xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime ); // ... keep posting characters ... this task may block when the queue // becomes full. cValueToPost = 'c'; xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime ); } // ISR that outputs all the characters received on the queue. void vISR_Routine( void ) { portBASE_TYPE xTaskWokenByReceive = pdFALSE; char cRxedChar; while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) ) { // A character was received. Output the character now. vOutputCharacter( cRxedChar ); // If removing the character from the queue woke the task that was // posting onto the queue cTaskWokenByReceive will have been set to // pdTRUE. No matter how many times this loop iterates only one // task will be woken. } if( cTaskWokenByPost != ( char ) pdFALSE; { taskYIELD (); } } </pre> * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR * \ingroup QueueManagement */ signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken ); /* * Utilities to query queue that are safe to use from an ISR. These utilities * should be used only from witin an ISR, or within a critical section. */ signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue ); signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue ); unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue ); /* * xQueueAltGenericSend() is an alternative version of xQueueGenericSend(). * Likewise xQueueAltGenericReceive() is an alternative version of * xQueueGenericReceive(). * * The source code that implements the alternative (Alt) API is much * simpler because it executes everything from within a critical section. * This is the approach taken by many other RTOSes, but FreeRTOS.org has the * preferred fully featured API too. The fully featured API has more * complex code that takes longer to execute, but makes much less use of * critical sections. Therefore the alternative API sacrifices interrupt * responsiveness to gain execution speed, whereas the fully featured API * sacrifices execution speed to ensure better interrupt responsiveness. */ signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ); signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ); #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT ) #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK ) #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE ) #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE ) /* * The functions defined above are for passing data to and from tasks. The * functions below are the equivalents for passing data to and from * co-routines. * * These functions are called from the co-routine macro implementation and * should not be called directly from application code. Instead use the macro * wrappers defined within croutine.h. */ signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken ); signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken ); signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait ); signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait ); /* * For internal use only. Use xSemaphoreCreateMutex() or * xSemaphoreCreateCounting() instead of calling these functions directly. */ xQueueHandle xQueueCreateMutex( void ); xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount ); /* * For internal use only. Use xSemaphoreTakeMutexRecursive() or * xSemaphoreGiveMutexRecursive() instead of calling these functions directly. */ portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime ); portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex ); /* * The registry is provided as a means for kernel aware debuggers to * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add * a queue, semaphore or mutex handle to the registry if you want the handle * to be available to a kernel aware debugger. If you are not using a kernel * aware debugger then this function can be ignored. * * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0 * within FreeRTOSConfig.h for the registry to be available. Its value * does not effect the number of queues, semaphores and mutexes that can be * created - just the number that the registry can hold. * * @param xQueue The handle of the queue being added to the registry. This * is the handle returned by a call to xQueueCreate(). Semaphore and mutex * handles can also be passed in here. * * @param pcName The name to be associated with the handle. This is the * name that the kernel aware debugger will display. */ #if configQUEUE_REGISTRY_SIZE > 0U void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName ); #endif /* Not a public API function, hence the 'Restricted' in the name. */ void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait ); #ifdef __cplusplus } #endif #endif /* QUEUE_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/include/queue.h
C
oos
44,191
/* FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Richard Barry, contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! http://www.FreeRTOS.org - Documentation, latest information, license and contact details. http://www.SafeRTOS.com - A version that is certified for use in safety critical systems. http://www.OpenRTOS.com - Commercial support, development, porting, licensing and training services. */ #ifndef CO_ROUTINE_H #define CO_ROUTINE_H #ifndef INC_FREERTOS_H #error "include FreeRTOS.h must appear in source files before include croutine.h" #endif #include "list.h" #ifdef __cplusplus extern "C" { #endif /* Used to hide the implementation of the co-routine control block. The control block structure however has to be included in the header due to the macro implementation of the co-routine functionality. */ typedef void * xCoRoutineHandle; /* Defines the prototype to which co-routine functions must conform. */ typedef void (*crCOROUTINE_CODE)( xCoRoutineHandle, unsigned portBASE_TYPE ); typedef struct corCoRoutineControlBlock { crCOROUTINE_CODE pxCoRoutineFunction; xListItem xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */ xListItem xEventListItem; /*< List item used to place the CRCB in event lists. */ unsigned portBASE_TYPE uxPriority; /*< The priority of the co-routine in relation to other co-routines. */ unsigned portBASE_TYPE uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */ unsigned short uxState; /*< Used internally by the co-routine implementation. */ } corCRCB; /* Co-routine control block. Note must be identical in size down to uxPriority with tskTCB. */ /** * croutine. h *<pre> portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex );</pre> * * Create a new co-routine and add it to the list of co-routines that are * ready to run. * * @param pxCoRoutineCode Pointer to the co-routine function. Co-routine * functions require special syntax - see the co-routine section of the WEB * documentation for more information. * * @param uxPriority The priority with respect to other co-routines at which * the co-routine will run. * * @param uxIndex Used to distinguish between different co-routines that * execute the same function. See the example below and the co-routine section * of the WEB documentation for further information. * * @return pdPASS if the co-routine was successfully created and added to a ready * list, otherwise an error code defined with ProjDefs.h. * * Example usage: <pre> // Co-routine to be created. void vFlashCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { // Variables in co-routines must be declared static if they must maintain value across a blocking call. // This may not be necessary for const variables. static const char cLedToFlash[ 2 ] = { 5, 6 }; static const portTickType uxFlashRates[ 2 ] = { 200, 400 }; // Must start every co-routine with a call to crSTART(); crSTART( xHandle ); for( ;; ) { // This co-routine just delays for a fixed period, then toggles // an LED. Two co-routines are created using this function, so // the uxIndex parameter is used to tell the co-routine which // LED to flash and how long to delay. This assumes xQueue has // already been created. vParTestToggleLED( cLedToFlash[ uxIndex ] ); crDELAY( xHandle, uxFlashRates[ uxIndex ] ); } // Must end every co-routine with a call to crEND(); crEND(); } // Function that creates two co-routines. void vOtherFunction( void ) { unsigned char ucParameterToPass; xTaskHandle xHandle; // Create two co-routines at priority 0. The first is given index 0 // so (from the code above) toggles LED 5 every 200 ticks. The second // is given index 1 so toggles LED 6 every 400 ticks. for( uxIndex = 0; uxIndex < 2; uxIndex++ ) { xCoRoutineCreate( vFlashCoRoutine, 0, uxIndex ); } } </pre> * \defgroup xCoRoutineCreate xCoRoutineCreate * \ingroup Tasks */ signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex ); /** * croutine. h *<pre> void vCoRoutineSchedule( void );</pre> * * Run a co-routine. * * vCoRoutineSchedule() executes the highest priority co-routine that is able * to run. The co-routine will execute until it either blocks, yields or is * preempted by a task. Co-routines execute cooperatively so one * co-routine cannot be preempted by another, but can be preempted by a task. * * If an application comprises of both tasks and co-routines then * vCoRoutineSchedule should be called from the idle task (in an idle task * hook). * * Example usage: <pre> // This idle task hook will schedule a co-routine each time it is called. // The rest of the idle task will execute between co-routine calls. void vApplicationIdleHook( void ) { vCoRoutineSchedule(); } // Alternatively, if you do not require any other part of the idle task to // execute, the idle task hook can call vCoRoutineScheduler() within an // infinite loop. void vApplicationIdleHook( void ) { for( ;; ) { vCoRoutineSchedule(); } } </pre> * \defgroup vCoRoutineSchedule vCoRoutineSchedule * \ingroup Tasks */ void vCoRoutineSchedule( void ); /** * croutine. h * <pre> crSTART( xCoRoutineHandle xHandle );</pre> * * This macro MUST always be called at the start of a co-routine function. * * Example usage: <pre> // Co-routine to be created. void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { // Variables in co-routines must be declared static if they must maintain value across a blocking call. static long ulAVariable; // Must start every co-routine with a call to crSTART(); crSTART( xHandle ); for( ;; ) { // Co-routine functionality goes here. } // Must end every co-routine with a call to crEND(); crEND(); }</pre> * \defgroup crSTART crSTART * \ingroup Tasks */ #define crSTART( pxCRCB ) switch( ( ( corCRCB * )( pxCRCB ) )->uxState ) { case 0: /** * croutine. h * <pre> crEND();</pre> * * This macro MUST always be called at the end of a co-routine function. * * Example usage: <pre> // Co-routine to be created. void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { // Variables in co-routines must be declared static if they must maintain value across a blocking call. static long ulAVariable; // Must start every co-routine with a call to crSTART(); crSTART( xHandle ); for( ;; ) { // Co-routine functionality goes here. } // Must end every co-routine with a call to crEND(); crEND(); }</pre> * \defgroup crSTART crSTART * \ingroup Tasks */ #define crEND() } /* * These macros are intended for internal use by the co-routine implementation * only. The macros should not be used directly by application writers. */ #define crSET_STATE0( xHandle ) ( ( corCRCB * )( xHandle ) )->uxState = (__LINE__ * 2); return; case (__LINE__ * 2): #define crSET_STATE1( xHandle ) ( ( corCRCB * )( xHandle ) )->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1): /** * croutine. h *<pre> crDELAY( xCoRoutineHandle xHandle, portTickType xTicksToDelay );</pre> * * Delay a co-routine for a fixed period of time. * * crDELAY can only be called from the co-routine function itself - not * from within a function called by the co-routine function. This is because * co-routines do not maintain their own stack. * * @param xHandle The handle of the co-routine to delay. This is the xHandle * parameter of the co-routine function. * * @param xTickToDelay The number of ticks that the co-routine should delay * for. The actual amount of time this equates to is defined by * configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant portTICK_RATE_MS * can be used to convert ticks to milliseconds. * * Example usage: <pre> // Co-routine to be created. void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { // Variables in co-routines must be declared static if they must maintain value across a blocking call. // This may not be necessary for const variables. // We are to delay for 200ms. static const xTickType xDelayTime = 200 / portTICK_RATE_MS; // Must start every co-routine with a call to crSTART(); crSTART( xHandle ); for( ;; ) { // Delay for 200ms. crDELAY( xHandle, xDelayTime ); // Do something here. } // Must end every co-routine with a call to crEND(); crEND(); }</pre> * \defgroup crDELAY crDELAY * \ingroup Tasks */ #define crDELAY( xHandle, xTicksToDelay ) \ if( ( xTicksToDelay ) > 0 ) \ { \ vCoRoutineAddToDelayedList( ( xTicksToDelay ), NULL ); \ } \ crSET_STATE0( ( xHandle ) ); /** * <pre> crQUEUE_SEND( xCoRoutineHandle xHandle, xQueueHandle pxQueue, void *pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE *pxResult )</pre> * * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. * * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas * xQueueSend() and xQueueReceive() can only be used from tasks. * * crQUEUE_SEND can only be called from the co-routine function itself - not * from within a function called by the co-routine function. This is because * co-routines do not maintain their own stack. * * See the co-routine section of the WEB documentation for information on * passing data between tasks and co-routines and between ISR's and * co-routines. * * @param xHandle The handle of the calling co-routine. This is the xHandle * parameter of the co-routine function. * * @param pxQueue The handle of the queue on which the data will be posted. * The handle is obtained as the return value when the queue is created using * the xQueueCreate() API function. * * @param pvItemToQueue A pointer to the data being posted onto the queue. * The number of bytes of each queued item is specified when the queue is * created. This number of bytes is copied from pvItemToQueue into the queue * itself. * * @param xTickToDelay The number of ticks that the co-routine should block * to wait for space to become available on the queue, should space not be * available immediately. The actual amount of time this equates to is defined * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant * portTICK_RATE_MS can be used to convert ticks to milliseconds (see example * below). * * @param pxResult The variable pointed to by pxResult will be set to pdPASS if * data was successfully posted onto the queue, otherwise it will be set to an * error defined within ProjDefs.h. * * Example usage: <pre> // Co-routine function that blocks for a fixed period then posts a number onto // a queue. static void prvCoRoutineFlashTask( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { // Variables in co-routines must be declared static if they must maintain value across a blocking call. static portBASE_TYPE xNumberToPost = 0; static portBASE_TYPE xResult; // Co-routines must begin with a call to crSTART(). crSTART( xHandle ); for( ;; ) { // This assumes the queue has already been created. crQUEUE_SEND( xHandle, xCoRoutineQueue, &xNumberToPost, NO_DELAY, &xResult ); if( xResult != pdPASS ) { // The message was not posted! } // Increment the number to be posted onto the queue. xNumberToPost++; // Delay for 100 ticks. crDELAY( xHandle, 100 ); } // Co-routines must end with a call to crEND(). crEND(); }</pre> * \defgroup crQUEUE_SEND crQUEUE_SEND * \ingroup Tasks */ #define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \ { \ *( pxResult ) = xQueueCRSend( ( pxQueue) , ( pvItemToQueue) , ( xTicksToWait ) ); \ if( *( pxResult ) == errQUEUE_BLOCKED ) \ { \ crSET_STATE0( ( xHandle ) ); \ *pxResult = xQueueCRSend( ( pxQueue ), ( pvItemToQueue ), 0 ); \ } \ if( *pxResult == errQUEUE_YIELD ) \ { \ crSET_STATE1( ( xHandle ) ); \ *pxResult = pdPASS; \ } \ } /** * croutine. h * <pre> crQUEUE_RECEIVE( xCoRoutineHandle xHandle, xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait, portBASE_TYPE *pxResult )</pre> * * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. * * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas * xQueueSend() and xQueueReceive() can only be used from tasks. * * crQUEUE_RECEIVE can only be called from the co-routine function itself - not * from within a function called by the co-routine function. This is because * co-routines do not maintain their own stack. * * See the co-routine section of the WEB documentation for information on * passing data between tasks and co-routines and between ISR's and * co-routines. * * @param xHandle The handle of the calling co-routine. This is the xHandle * parameter of the co-routine function. * * @param pxQueue The handle of the queue from which the data will be received. * The handle is obtained as the return value when the queue is created using * the xQueueCreate() API function. * * @param pvBuffer The buffer into which the received item is to be copied. * The number of bytes of each queued item is specified when the queue is * created. This number of bytes is copied into pvBuffer. * * @param xTickToDelay The number of ticks that the co-routine should block * to wait for data to become available from the queue, should data not be * available immediately. The actual amount of time this equates to is defined * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant * portTICK_RATE_MS can be used to convert ticks to milliseconds (see the * crQUEUE_SEND example). * * @param pxResult The variable pointed to by pxResult will be set to pdPASS if * data was successfully retrieved from the queue, otherwise it will be set to * an error code as defined within ProjDefs.h. * * Example usage: <pre> // A co-routine receives the number of an LED to flash from a queue. It // blocks on the queue until the number is received. static void prvCoRoutineFlashWorkTask( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { // Variables in co-routines must be declared static if they must maintain value across a blocking call. static portBASE_TYPE xResult; static unsigned portBASE_TYPE uxLEDToFlash; // All co-routines must start with a call to crSTART(). crSTART( xHandle ); for( ;; ) { // Wait for data to become available on the queue. crQUEUE_RECEIVE( xHandle, xCoRoutineQueue, &uxLEDToFlash, portMAX_DELAY, &xResult ); if( xResult == pdPASS ) { // We received the LED to flash - flash it! vParTestToggleLED( uxLEDToFlash ); } } crEND(); }</pre> * \defgroup crQUEUE_RECEIVE crQUEUE_RECEIVE * \ingroup Tasks */ #define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \ { \ *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), ( xTicksToWait ) ); \ if( *( pxResult ) == errQUEUE_BLOCKED ) \ { \ crSET_STATE0( ( xHandle ) ); \ *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), 0 ); \ } \ if( *( pxResult ) == errQUEUE_YIELD ) \ { \ crSET_STATE1( ( xHandle ) ); \ *( pxResult ) = pdPASS; \ } \ } /** * croutine. h * <pre> crQUEUE_SEND_FROM_ISR( xQueueHandle pxQueue, void *pvItemToQueue, portBASE_TYPE xCoRoutinePreviouslyWoken )</pre> * * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() * functions used by tasks. * * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and * xQueueReceiveFromISR() can only be used to pass data between a task and and * ISR. * * crQUEUE_SEND_FROM_ISR can only be called from an ISR to send data to a queue * that is being used from within a co-routine. * * See the co-routine section of the WEB documentation for information on * passing data between tasks and co-routines and between ISR's and * co-routines. * * @param xQueue The handle to the queue on which the item is to be posted. * * @param pvItemToQueue A pointer to the item that is to be placed on the * queue. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from pvItemToQueue * into the queue storage area. * * @param xCoRoutinePreviouslyWoken This is included so an ISR can post onto * the same queue multiple times from a single interrupt. The first call * should always pass in pdFALSE. Subsequent calls should pass in * the value returned from the previous call. * * @return pdTRUE if a co-routine was woken by posting onto the queue. This is * used by the ISR to determine if a context switch may be required following * the ISR. * * Example usage: <pre> // A co-routine that blocks on a queue waiting for characters to be received. static void vReceivingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { char cRxedChar; portBASE_TYPE xResult; // All co-routines must start with a call to crSTART(). crSTART( xHandle ); for( ;; ) { // Wait for data to become available on the queue. This assumes the // queue xCommsRxQueue has already been created! crQUEUE_RECEIVE( xHandle, xCommsRxQueue, &uxLEDToFlash, portMAX_DELAY, &xResult ); // Was a character received? if( xResult == pdPASS ) { // Process the character here. } } // All co-routines must end with a call to crEND(). crEND(); } // An ISR that uses a queue to send characters received on a serial port to // a co-routine. void vUART_ISR( void ) { char cRxedChar; portBASE_TYPE xCRWokenByPost = pdFALSE; // We loop around reading characters until there are none left in the UART. while( UART_RX_REG_NOT_EMPTY() ) { // Obtain the character from the UART. cRxedChar = UART_RX_REG; // Post the character onto a queue. xCRWokenByPost will be pdFALSE // the first time around the loop. If the post causes a co-routine // to be woken (unblocked) then xCRWokenByPost will be set to pdTRUE. // In this manner we can ensure that if more than one co-routine is // blocked on the queue only one is woken by this ISR no matter how // many characters are posted to the queue. xCRWokenByPost = crQUEUE_SEND_FROM_ISR( xCommsRxQueue, &cRxedChar, xCRWokenByPost ); } }</pre> * \defgroup crQUEUE_SEND_FROM_ISR crQUEUE_SEND_FROM_ISR * \ingroup Tasks */ #define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) xQueueCRSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( xCoRoutinePreviouslyWoken ) ) /** * croutine. h * <pre> crQUEUE_SEND_FROM_ISR( xQueueHandle pxQueue, void *pvBuffer, portBASE_TYPE * pxCoRoutineWoken )</pre> * * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() * functions used by tasks. * * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and * xQueueReceiveFromISR() can only be used to pass data between a task and and * ISR. * * crQUEUE_RECEIVE_FROM_ISR can only be called from an ISR to receive data * from a queue that is being used from within a co-routine (a co-routine * posted to the queue). * * See the co-routine section of the WEB documentation for information on * passing data between tasks and co-routines and between ISR's and * co-routines. * * @param xQueue The handle to the queue on which the item is to be posted. * * @param pvBuffer A pointer to a buffer into which the received item will be * placed. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from the queue into * pvBuffer. * * @param pxCoRoutineWoken A co-routine may be blocked waiting for space to become * available on the queue. If crQUEUE_RECEIVE_FROM_ISR causes such a * co-routine to unblock *pxCoRoutineWoken will get set to pdTRUE, otherwise * *pxCoRoutineWoken will remain unchanged. * * @return pdTRUE an item was successfully received from the queue, otherwise * pdFALSE. * * Example usage: <pre> // A co-routine that posts a character to a queue then blocks for a fixed // period. The character is incremented each time. static void vSendingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { // cChar holds its value while this co-routine is blocked and must therefore // be declared static. static char cCharToTx = 'a'; portBASE_TYPE xResult; // All co-routines must start with a call to crSTART(). crSTART( xHandle ); for( ;; ) { // Send the next character to the queue. crQUEUE_SEND( xHandle, xCoRoutineQueue, &cCharToTx, NO_DELAY, &xResult ); if( xResult == pdPASS ) { // The character was successfully posted to the queue. } else { // Could not post the character to the queue. } // Enable the UART Tx interrupt to cause an interrupt in this // hypothetical UART. The interrupt will obtain the character // from the queue and send it. ENABLE_RX_INTERRUPT(); // Increment to the next character then block for a fixed period. // cCharToTx will maintain its value across the delay as it is // declared static. cCharToTx++; if( cCharToTx > 'x' ) { cCharToTx = 'a'; } crDELAY( 100 ); } // All co-routines must end with a call to crEND(). crEND(); } // An ISR that uses a queue to receive characters to send on a UART. void vUART_ISR( void ) { char cCharToTx; portBASE_TYPE xCRWokenByPost = pdFALSE; while( UART_TX_REG_EMPTY() ) { // Are there any characters in the queue waiting to be sent? // xCRWokenByPost will automatically be set to pdTRUE if a co-routine // is woken by the post - ensuring that only a single co-routine is // woken no matter how many times we go around this loop. if( crQUEUE_RECEIVE_FROM_ISR( pxQueue, &cCharToTx, &xCRWokenByPost ) ) { SEND_CHARACTER( cCharToTx ); } } }</pre> * \defgroup crQUEUE_RECEIVE_FROM_ISR crQUEUE_RECEIVE_FROM_ISR * \ingroup Tasks */ #define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) xQueueCRReceiveFromISR( ( pxQueue ), ( pvBuffer ), ( pxCoRoutineWoken ) ) /* * This function is intended for internal use by the co-routine macros only. * The macro nature of the co-routine implementation requires that the * prototype appears here. The function should not be used by application * writers. * * Removes the current co-routine from its ready list and places it in the * appropriate delayed list. */ void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList ); /* * This function is intended for internal use by the queue implementation only. * The function should not be used by application writers. * * Removes the highest priority co-routine from the event list and places it in * the pending ready list. */ signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList ); #ifdef __cplusplus } #endif #endif /* CO_ROUTINE_H */
zz314326255--adkping
iNEMO-accessory/firmware/FreeRTOSv7.0.2/Source/include/croutine.h
C
oos
28,423
/** Automatically generated file. DO NOT MODIFY */ package com.st.android.iNemoDemo; public final class BuildConfig { public final static boolean DEBUG = true; }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/gen/com/st/android/iNemoDemo/BuildConfig.java
Java
oos
166
package com.st.android.iNemoDemo; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import com.st.android.iNemoDemo.R; import com.st.android.iNemoDemo.iNemoInfo.INemoInfo; import com.st.android.iNemoDemo.iNemoInfo.Sensor; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class INemoDemoActivity extends ADKActivity { public int SETTINGS_ACTIVITY_REQUEST = 0; protected void setStatus(int status){ this.mStatus = status; if(status == ATTACHED_DEVICE){ TextView deviceLabel; Button connectButton; setContentView(R.layout.connect_device); deviceLabel = (TextView)findViewById(R.id.deviceLabel); connectButton = (Button)findViewById(R.id.connectButton); if(connectButton != null){ connectButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { CommunicationFrame cf = new CommunicationFrame(); cf.setConnectFrame(); sendCommand(cf); } }); connectButton.setEnabled(true); } if(deviceLabel != null) deviceLabel.setText("Detected Device: " + this.mAccessory.getManufacturer() + "\n"); } else if(status == NO_DEVICE){ setContentView(R.layout.no_device); } else if(status == CONNECTED_DEVICE){ CommunicationFrame cf = new CommunicationFrame(); Button disconnectButton, settingsButton, startAcquisitionButton; setContentView(R.layout.connected_dev); if(this.mINemoInfo == null){ this.mINemoInfo = new INemoInfo(); cf.setGetMCUIDFrame(); sendCommand(cf); cf.setGetFWVersionFrame(); sendCommand(cf); cf.setGetHWVersionFrame(); sendCommand(cf); cf.setGetOutputModeFrame(); sendCommand(cf); } else this.updateConnectedLayout(); disconnectButton = (Button)findViewById(R.id.disconnectButton); settingsButton = (Button)findViewById(R.id.settingsButton); startAcquisitionButton = (Button)findViewById(R.id.startAcquisitionButton); if(disconnectButton != null){ disconnectButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { CommunicationFrame cf = new CommunicationFrame(); cf.setDisconnectFrame(); sendCommand(cf); } }); } if(settingsButton != null){ settingsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startSettingsActivity(); } }); } if(startAcquisitionButton != null){ startAcquisitionButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { CommunicationFrame cf = new CommunicationFrame(); cf.setStartAcquisitionFrame(); sendCommand(cf); } }); } } else if(status == ACQUISITION){ Button stopAcquisitionButton; setContentView(R.layout.acquisition); stopAcquisitionButton = (Button)findViewById(R.id.stopAcquisitionButton); if(stopAcquisitionButton != null){ stopAcquisitionButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { CommunicationFrame cf = new CommunicationFrame(); cf.setStopAcquisitionFrame(); sendCommand(cf); } }); } } } protected void handleReceivedMsg(CommunicationFrame cf){ if(cf.isConnectACK()){ this.setStatus(CONNECTED_DEVICE); } else if(cf.isConnectNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in connecting device: " + cf.getErrorCode() + "\n"); } else if(cf.isDisconnectACK()){ this.mINemoInfo = null; this.setStatus(ATTACHED_DEVICE); } else if(cf.isDisconnectNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in disconnecting device: " + cf.getErrorCode() + "\n"); } else if(cf.isGetMCUIDACK()){ if(this.mINemoInfo != null){ this.mINemoInfo.setUID(cf.getStringPayload()); updateConnectedLayout(); } } else if(cf.isGetMCUIDNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in getting device UID: " + cf.getErrorCode() + "\n"); } else if(cf.isGetFWVersionACK()){ if(this.mINemoInfo != null){ this.mINemoInfo.setFW_v(cf.getStringPayload()); updateConnectedLayout(); } } else if(cf.isGetFWVersionNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in getting FW info: " + cf.getErrorCode() + "\n"); } else if(cf.isGetHWVersionACK()){ if(this.mINemoInfo != null){ this.mINemoInfo.setHW_v(cf.getStringPayload()); updateConnectedLayout(); } } else if(cf.isGetHWVersionNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in getting HW info: " + cf.getErrorCode() + "\n"); } else if(cf.isSetSensorParameterACK()){ updateConnectedLayout(); } else if(cf.isSetSensorParameterNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in setting parameter: " + cf.getErrorCode() + "\n"); } else if(cf.isGetSensorParameterACK()){ if(cf.updateParameter(this.mINemoInfo)) updateConnectedLayout(); else { TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in getting parameter value\n"); } } else if(cf.isGetSensorParameterNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in getting parameter value: " + cf.getErrorCode() + "\n"); } else if(cf.isRestoreDefaultParameterACK()){ if(cf.updateParameter(this.mINemoInfo)) updateConnectedLayout(); else { TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in restoring parameter value\n"); } } else if(cf.isRestoreDefaultParameterNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in restoring parameter value: " + cf.getErrorCode() + "\n"); } else if(cf.isSetOutputModeACK()){ updateConnectedLayout(); } else if(cf.isSetOutputModeNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in setting output mode: " + cf.getErrorCode() + "\n"); } else if(cf.isGetOutputModeACK()){ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); if(cf.updateOutputMode(mINemoInfo, sharedPrefs)){ updateConnectedLayout(); for(Byte b : mINemoInfo.getSensors().keySet()){ Sensor s = mINemoInfo.getSensors().get(b); if(s.isEnabled()){ for(Byte b2 : s.getParameters().keySet()){ CommunicationFrame newCf = new CommunicationFrame(); newCf.setGetSensorParameterFrame(b, b2); sendCommand(newCf); } } } } else { TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in updating output mode\n"); } } else if(cf.isGetOutputModeNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in getting output mode: " + cf.getErrorCode() + "\n"); } else if(cf.isStartAcquisitonACK()){ this.setStatus(ACQUISITION); } else if(cf.isStartAcquisitonNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in starting acquisition: " + cf.getErrorCode() + "\n"); } else if(cf.isStopAcquisitonACK()){ this.setStatus(CONNECTED_DEVICE); } else if(cf.isStopAcquisitonNACK()){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Error in stopping acquisition: " + cf.getErrorCode() + "\n"); } else if(cf.isAcquisitionData()){ if(this.mINemoInfo != null){ cf.updateAcquiredData(mINemoInfo); TextView dataLabel = (TextView)findViewById(R.id.dataLabel); if(dataLabel != null) dataLabel.setText(this.mINemoInfo.printAcquisitionData()); } } else{ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); if(debugLabel != null) debugLabel.append("Unknown message received\n"); } } private void updateConnectedLayout(){ TextView iNemoInfolabel = (TextView)findViewById(R.id.iNemoInfolabel); if(iNemoInfolabel != null && this.mINemoInfo != null) iNemoInfolabel.setText(this.mINemoInfo.toString()); } public void startSettingsActivity(){ Intent settingsActivity = new Intent(this, SettingsActivity.class); startActivity(settingsActivity); } public void onResume(){ super.onResume(); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); if(sharedPrefs != null && this.mINemoInfo != null && this.mStatus == CONNECTED_DEVICE){ try{ boolean b = false, changedOutMode = false; String s = ""; byte by = 0; byte[] by2; byte[] by3; ArrayList<CommunicationFrame> cfs = new ArrayList<CommunicationFrame>(); b = sharedPrefs.getBoolean("calibrated_data", Boolean.getBoolean(getString(R.string.def_calibrated_data))); if(this.mINemoInfo.isCalibratedData() != b){ this.mINemoInfo.setCalibratedData(b); changedOutMode = true; } s = sharedPrefs.getString("acquisition_rate", getString(R.string.def_acquisition_rate)); by = Byte.parseByte(s); if(this.mINemoInfo.getAcquisitionRate() != by){ this.mINemoInfo.setAcquisitionRate(by); changedOutMode = true; } b = sharedPrefs.getBoolean("ahrs_lib", Boolean.getBoolean(getString(R.string.def_ahrs_lib))); if(this.mINemoInfo.isAhrsLib() != b){ this.mINemoInfo.setAhrsLib(b); changedOutMode = true; } b = sharedPrefs.getBoolean("enable_acc", Boolean.getBoolean(getString(R.string.def_acc))); if(this.mINemoInfo.isSensorEnabled(CommunicationFrame.ACCELEROMETER) != b){ this.mINemoInfo.enableSensor(CommunicationFrame.ACCELEROMETER, b); changedOutMode = true; } b = sharedPrefs.getBoolean("enable_mag", Boolean.getBoolean(getString(R.string.def_mag))); if(this.mINemoInfo.isSensorEnabled(CommunicationFrame.MAGNETOMETER) != b){ this.mINemoInfo.enableSensor(CommunicationFrame.MAGNETOMETER, b); changedOutMode = true; } b = sharedPrefs.getBoolean("enable_gyro", Boolean.getBoolean(getString(R.string.def_gyro))); if(this.mINemoInfo.isSensorEnabled(CommunicationFrame.GYRO_1AXIS) != b){ this.mINemoInfo.enableSensor(CommunicationFrame.GYRO_1AXIS, b); this.mINemoInfo.enableSensor(CommunicationFrame.GYRO_2AXIS, b); changedOutMode = true; } b = sharedPrefs.getBoolean("enable_press", Boolean.getBoolean(getString(R.string.def_press))); if(this.mINemoInfo.isSensorEnabled(CommunicationFrame.PRESSURE) != b){ this.mINemoInfo.enableSensor(CommunicationFrame.PRESSURE, b); changedOutMode = true; } b = sharedPrefs.getBoolean("enable_temp", Boolean.getBoolean(getString(R.string.def_temp))); if(this.mINemoInfo.isSensorEnabled(CommunicationFrame.TEMPERATURE) != b){ this.mINemoInfo.enableSensor(CommunicationFrame.TEMPERATURE, b); changedOutMode = true; } if(changedOutMode){ CommunicationFrame cf = new CommunicationFrame(); cf.setSetOutputModeFrame(mINemoInfo.isSensorEnabled(CommunicationFrame.TEMPERATURE), mINemoInfo.isSensorEnabled(CommunicationFrame.PRESSURE), mINemoInfo.isSensorEnabled(CommunicationFrame.MAGNETOMETER), mINemoInfo.isSensorEnabled(CommunicationFrame.GYRO_1AXIS), mINemoInfo.isSensorEnabled(CommunicationFrame.ACCELEROMETER), mINemoInfo.isCalibratedData(), mINemoInfo.isAhrsLib(), mINemoInfo.getAcquisitionRate()); cfs.add(cf); } s = sharedPrefs.getString("acc_out_rate", getString(R.string.def_acc_out_rate)); by = Byte.parseByte(s); by2 = this.mINemoInfo.getSensorParameterValue(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OUT_RATE); if(by2[0] != by){ CommunicationFrame cf = new CommunicationFrame(); byte[] temp_b = new byte[1]; temp_b[0] = by; this.mINemoInfo.updateSensorParameter(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OUT_RATE, temp_b); cf.setSetSensorParameterFrame(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OUT_RATE, temp_b); cfs.add(cf); } s = sharedPrefs.getString("acc_full_scale", getString(R.string.def_acc_full_scale)); by = Byte.parseByte(s); by2 = this.mINemoInfo.getSensorParameterValue(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_FULL_SCALE); if(by2[0] != by){ CommunicationFrame cf = new CommunicationFrame(); byte[] temp_b = new byte[1]; temp_b[0] = by; this.mINemoInfo.updateSensorParameter(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_FULL_SCALE, temp_b); cf.setSetSensorParameterFrame(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_FULL_SCALE, temp_b); cfs.add(cf); } s = sharedPrefs.getString("acc_offset_x", getString(R.string.def_acc_off_x)); by3 = CommunicationFrame.convertShortInBytes(Short.parseShort(s)); by2 = this.mINemoInfo.getSensorParameterValue(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OFFSET_X); if(by2[0] != by3[0] || by2[1] != by3[1]){ CommunicationFrame cf = new CommunicationFrame(); this.mINemoInfo.updateSensorParameter(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OFFSET_X, by3); cf.setSetSensorParameterFrame(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OFFSET_X, by3); cfs.add(cf); } s = sharedPrefs.getString("acc_offset_y", getString(R.string.def_acc_off_y)); by3 = CommunicationFrame.convertShortInBytes(Short.parseShort(s)); by2 = this.mINemoInfo.getSensorParameterValue(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OFFSET_Y); if(by2[0] != by3[0] || by2[1] != by3[1]){ CommunicationFrame cf = new CommunicationFrame(); this.mINemoInfo.updateSensorParameter(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OFFSET_Y, by3); cf.setSetSensorParameterFrame(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OFFSET_Y, by3); cfs.add(cf); } s = sharedPrefs.getString("acc_offset_z", getString(R.string.def_acc_off_z)); by3 = CommunicationFrame.convertShortInBytes(Short.parseShort(s)); by2 = this.mINemoInfo.getSensorParameterValue(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OFFSET_Z); if(by2[0] != by3[0] || by2[1] != by3[1]){ CommunicationFrame cf = new CommunicationFrame(); this.mINemoInfo.updateSensorParameter(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OFFSET_Z, by3); cf.setSetSensorParameterFrame(CommunicationFrame.ACCELEROMETER, CommunicationFrame.ACC_OFFSET_Z, by3); cfs.add(cf); } s = sharedPrefs.getString("temp_offset", getString(R.string.def_temp_off)); by3 = CommunicationFrame.convertShortInBytes(Short.parseShort(s)); by2 = this.mINemoInfo.getSensorParameterValue(CommunicationFrame.TEMPERATURE, CommunicationFrame.TEMP_OFFSET); if(by2[0] != by3[0] || by2[1] != by3[1]){ CommunicationFrame cf = new CommunicationFrame(); this.mINemoInfo.updateSensorParameter(CommunicationFrame.TEMPERATURE, CommunicationFrame.TEMP_OFFSET, by3); cf.setSetSensorParameterFrame(CommunicationFrame.TEMPERATURE, CommunicationFrame.TEMP_OFFSET, by3); cfs.add(cf); } for(CommunicationFrame cf : cfs) this.sendCommand(cf); } catch(Exception e){ TextView debugLabel = (TextView)findViewById(R.id.debugLabel); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); debugLabel.append("error\n"); debugLabel.append(sw.toString()); } } } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/INemoDemoActivity.java
Java
oos
16,363
package com.st.android.iNemoDemo; import java.nio.ByteBuffer; import java.nio.ShortBuffer; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import com.st.android.iNemoDemo.iNemoInfo.INemoInfo; public class CommunicationFrame { static final String TAG = "CommunicationFrame"; private static final int FRAME_SIZE = 64; /* Frame Control */ private static final byte CTRL_type = 0x00; /* control frame */ private static final byte DATA_type = 0x40; /* data frame */ private static final byte ACK_type = (byte)0x80; /* Ack frame */ private static final byte NACK_type = (byte)0xC0; /* NACK frame */ private static final byte ACK_req = 0x20; /* Ack required */ private static final byte ACK_NOTreq = 0x00; /* NACK required */ private static final byte Last_Frag = 0x00; /* Last Fragment */ private static final byte More_Frag = 0x10; /* More Fragment */ private static final byte Version_1 = 0x00; /* Frame Version */ private static final byte QoS_Normal = 0x00; /* Data no Ack Last Fragment */ private static final byte Qos_Medium = 0x01; /* Data with Ack More Fragment */ private static final byte QoS_High = 0x02; /* Ack no payload */ /* Error codes */ private static final byte CmdUnsupported = 0x01; private static final byte ValueOutOfRange = 0x02; private static final byte NotExecutable = 0x03; private static final byte WrongSyntax = 0x04; private static final byte iNEMONotConnected = 0x05; /* Message IDs - Communication Control Frames */ private static final byte iNEMO_Connect = 0x00; private static final byte iNEMO_Disconnect = 0x01; private static final byte iNEMO_Reset_Board = 0x02; private static final byte iNEMO_Enter_DFU_Mode = 0x03; private static final byte iNEMO_Trace = 0x07; private static final byte iNEMO_Led = 0x08; /* Message IDs - Board Info Frames */ private static final byte iNEMO_Get_Device_Mode = 0x10; private static final byte iNEMO_Get_MCU_ID = 0x12; private static final byte iNEMO_Get_FW_Version = 0x13; private static final byte iNEMO_Get_HW_Version = 0x14; private static final byte iNEMO_Identify = 0x15; private static final byte iNEMO_Get_AHRS_Library = 0x17; private static final byte iNEMO_Get_Libraries = 0x18; /* Message IDs - Sensor Setting Frames */ private static final byte iNEMO_Set_Sensor_Parameter = 0x20; private static final byte iNEMO_Get_Sensor_Parameter = 0x21; private static final byte iNEMO_Restore_Default_Parameter = 0x22; /* Message IDs - Acquisition Sensor Data Frames */ private static final byte iNEMO_SetOutMode = 0x50; private static final byte iNEMO_GetOutMode = 0x51; private static final byte iNEMO_Start_Acquisition = 0x52; private static final byte iNEMO_Stop_Acquisition = 0x53; /* FREQUENCY ACQUISITION VALUES */ public static final byte LOW_FREQUENCY = 0x00; /* 1 HZ frequency acquisition */ public static final byte MEDIUM_FREQUENCY_1 = 0x08; /* 10 HZ frequency acquisition */ public static final byte MEDIUM_FREQUENCY_2 = 0x10; /* 25 HZ frequency acquisition */ public static final byte MEDIUM_FREQUENCY_3 = 0x20; /* 30 HZ frequency acquisition */ public static final byte HIGH_FREQUENCY_1 = 0x18; /* 50 HZ frequency acquisition */ public static final byte HIGH_FREQUENCY_2 = 0x28; /* 100 HZ frequency acquisition */ public static final byte HIGH_FREQUENCY_3 = 0x30; /* 400 HZ frequency acquisition */ /* Sensor Types */ public static final byte ACCELEROMETER = 0x00; public static final byte MAGNETOMETER = 0x01; public static final byte GYRO_2AXIS = 0x02; public static final byte GYRO_1AXIS = 0x03; public static final byte PRESSURE = 0x04; public static final byte TEMPERATURE = 0x05; /* Accelerometer Parameters */ public static final byte ACC_OUT_RATE = 0x00; public static final byte ACC_FULL_SCALE = 0x01; public static final byte ACC_HPF = 0x02; public static final byte ACC_OFFSET_X = 0x03; public static final byte ACC_OFFSET_Y = 0x04; public static final byte ACC_OFFSET_Z = 0x05; /* Accelerometer output data rate values */ public static final byte ACC_OUT_RATE_50HZ = 0x00; public static final byte ACC_OUT_RATE_100HZ = 0x01; public static final byte ACC_OUT_RATE_400HZ = 0x02; public static final byte ACC_OUT_RATE_1000HZ = 0x03; /* Accelerometer full scale values */ public static final byte ACC_FULL_SCALE_2G = 0x00; public static final byte ACC_FULL_SCALE_4G = 0x01; public static final byte ACC_FULL_SCALE_8G = 0x03; /* Accelerometer high-pass filter */ // TODO /* Magnetometer Parameters */ public static final byte MAG_OUT_RATE = 0x00; public static final byte MAG_FULL_SCALE = 0x01; public static final byte MAG_OP_MODE = 0x02; public static final byte MAG_OFFSET_X = 0x03; public static final byte MAG_OFFSET_Y = 0x04; public static final byte MAG_OFFSET_Z = 0x05; /* Magnetometer output data rate values */ public static final byte MAG_OUT_RATE_0_75HZ = 0x00; public static final byte MAG_OUT_RATE_1_5HZ = 0x01; public static final byte MAG_OUT_RATE_3HZ = 0x02; public static final byte MAG_OUT_RATE_7_5HZ = 0x03; public static final byte MAG_OUT_RATE_15HZ = 0x04; public static final byte MAG_OUT_RATE_30HZ = 0x05; public static final byte MAG_OUT_RATE_75HZ = 0x06; /* Magnetometer full scale values */ public static final byte MAG_FULL_SCALE_1_3G = 0x00; public static final byte MAG_FULL_SCALE_1_9G = 0x01; public static final byte MAG_FULL_SCALE_2_5G = 0x03; public static final byte MAG_FULL_SCALE_4_0G = 0x04; public static final byte MAG_FULL_SCALE_4_7G = 0x05; public static final byte MAG_FULL_SCALE_5_6G = 0x06; public static final byte MAG_FULL_SCALE_8_1G = 0x07; /* Magnetometer operating modes values */ public static final byte MAG_OP_MODE_NORMAL = 0x00; public static final byte MAG_OP_MODE_POS_BIAS = 0x01; public static final byte MAG_OP_MODE_NEG_BIAS = 0x02; public static final byte MAG_OP_MODE_FORBIDDEN = 0x03; /* 2-Axis Gyroscope Parameters */ public static final byte GYRO2_FULL_SCALE = 0x00; public static final byte GYRO2_OFFSET_X = 0x01; public static final byte GYRO2_OFFSET_Y = 0x02; /* 2-Axis Gyroscope full scale values */ public static final byte GYRO2_FULL_SCALE_300 = 0x04; public static final byte GYRO2_FULL_SCALE_1200 = 0x08; /* 1-Axis Gyroscope Parameters */ public static final byte GYRO1_FULL_SCALE = 0x00; public static final byte GYRO1_OFFSET_Z = 0x01; /* 1-Axis Gyroscope full scale values */ public static final byte GYRO1_FULL_SCALE_300 = 0x04; /* Pressure Parameters */ public static final byte PRESS_OUT_RATE = 0x00; public static final byte PRESS_OFFSET = 0x01; /* Pressure output data rate values */ public static final byte PRESS_OUT_RATE_7HZ = 0x01; public static final byte PRESS_OUT_RATE_12_5HZ = 0x03; /* Temperature Parameters */ public static final byte TEMP_OFFSET = 0x00; /* Frame message */ private byte[] msg; public CommunicationFrame(){ //this.msg = new byte[FRAME_SIZE + 1]; } public byte[] getMsg(){ return this.msg; } public void setMsg(byte[] message){ int len = message.length < FRAME_SIZE ? message.length : FRAME_SIZE; this.msg = new byte[len]; for(int i = 0; i < len; i++){ this.msg[i] = message[i]; } } public void setConnectFrame(){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; this.msg = new byte[3]; this.msg[0] = frame_ctrl; this.msg[1] = 0x01; this.msg[2] = iNEMO_Connect; } public void setDisconnectFrame(){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; this.msg = new byte[3]; this.msg[0] = frame_ctrl; this.msg[1] = 0x01; this.msg[2] = iNEMO_Disconnect; } public void setGetMCUIDFrame(){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; this.msg = new byte[3]; this.msg[0] = frame_ctrl; this.msg[1] = 0x01; this.msg[2] = iNEMO_Get_MCU_ID; } public void setGetFWVersionFrame(){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; this.msg = new byte[3]; this.msg[0] = frame_ctrl; this.msg[1] = 0x01; this.msg[2] = iNEMO_Get_FW_Version; } public void setGetHWVersionFrame(){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; this.msg = new byte[3]; this.msg[0] = frame_ctrl; this.msg[1] = 0x01; this.msg[2] = iNEMO_Get_HW_Version; } public void setSetSensorParameterFrame(byte sensor, byte parameter, byte[] value){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; int v_len = value.length; this.msg = new byte[5 + v_len]; this.msg[0] = frame_ctrl; this.msg[1] = (byte) (0x03 + v_len); this.msg[2] = iNEMO_Set_Sensor_Parameter; this.msg[3] = sensor; this.msg[4] = parameter; this.msg[5] = value[0]; if(v_len > 1) this.msg[6] = value[1]; } public void setGetSensorParameterFrame(byte sensor, byte parameter){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; this.msg = new byte[5]; this.msg[0] = frame_ctrl; this.msg[1] = 0x03; this.msg[2] = iNEMO_Get_Sensor_Parameter; this.msg[3] = sensor; this.msg[4] = parameter; } public void setRestoreDefaultParameterFrame(byte sensor, byte parameter){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; this.msg = new byte[5]; this.msg[0] = frame_ctrl; this.msg[1] = 0x03; this.msg[2] = iNEMO_Restore_Default_Parameter; this.msg[3] = sensor; this.msg[4] = parameter; } public void setSetOutputModeFrame(boolean tempEnabled, boolean pressEnabled, boolean magEnabled, boolean gyroEnabled, boolean accEnabled, boolean calibratedData, boolean ahrsEnabled, byte acquisitionRate){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; byte out1 = 0x00, out2 = 0x00; if(tempEnabled) out1 |= 0x01; if(pressEnabled) out1 |= 0x02; if(magEnabled) out1 |= 0x04; if(gyroEnabled) out1 |= 0x08; if(accEnabled) out1 |= 0x10; if(!calibratedData) out1 |= 0x20; if(ahrsEnabled) out1 |= 0x80; out2 |= acquisitionRate; this.msg = new byte[7]; this.msg[0] = frame_ctrl; this.msg[1] = 0x05; this.msg[2] = iNEMO_SetOutMode; this.msg[3] = out1; this.msg[4] = out2; this.msg[5] = 0x00; this.msg[6] = 0x00; } public void setGetOutputModeFrame(){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; this.msg = new byte[3]; this.msg[0] = frame_ctrl; this.msg[1] = 0x01; this.msg[2] = iNEMO_GetOutMode; } public void setStartAcquisitionFrame(){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; this.msg = new byte[3]; this.msg[0] = frame_ctrl; this.msg[1] = 0x01; this.msg[2] = iNEMO_Start_Acquisition; } public void setStopAcquisitionFrame(){ byte frame_ctrl = CTRL_type | ACK_req | Last_Frag | Version_1 | QoS_Normal; this.msg = new byte[3]; this.msg[0] = frame_ctrl; this.msg[1] = 0x01; this.msg[2] = iNEMO_Stop_Acquisition; } public boolean isConnectACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x01) return false; if(this.msg[2] != iNEMO_Connect) return false; return true; } public boolean isConnectNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_Connect) return false; return true; } public boolean isDisconnectACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x01) return false; if(this.msg[2] != iNEMO_Disconnect) return false; return true; } public boolean isDisconnectNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_Disconnect) return false; return true; } public boolean isGetMCUIDACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x0d) return false; if(this.msg[2] != iNEMO_Get_MCU_ID) return false; return true; } public boolean isGetMCUIDNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_Get_MCU_ID) return false; return true; } public boolean isGetFWVersionACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] < 0x02) return false; if(this.msg[2] != iNEMO_Get_FW_Version) return false; return true; } public boolean isGetFWVersionNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_Get_FW_Version) return false; return true; } public boolean isGetHWVersionACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] < 0x02) return false; if(this.msg[2] != iNEMO_Get_HW_Version) return false; return true; } public boolean isGetHWVersionNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_Get_HW_Version) return false; return true; } public boolean isSetSensorParameterACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x01) return false; if(this.msg[2] != iNEMO_Set_Sensor_Parameter) return false; return true; } public boolean isSetSensorParameterNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_Set_Sensor_Parameter) return false; return true; } public boolean isGetSensorParameterACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] < 0x02) return false; if(this.msg[2] != iNEMO_Get_Sensor_Parameter) return false; return true; } public boolean isGetSensorParameterNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_Get_Sensor_Parameter) return false; return true; } public boolean isRestoreDefaultParameterACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] < 0x02) return false; if(this.msg[2] != iNEMO_Restore_Default_Parameter) return false; return true; } public boolean isRestoreDefaultParameterNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_Restore_Default_Parameter) return false; return true; } public boolean isSetOutputModeACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x01) return false; if(this.msg[2] != iNEMO_SetOutMode) return false; return true; } public boolean isSetOutputModeNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_SetOutMode) return false; return true; } public boolean isGetOutputModeACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x05) return false; if(this.msg[2] != iNEMO_GetOutMode) return false; return true; } public boolean isGetOutputModeNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_GetOutMode) return false; return true; } public boolean isStartAcquisitonACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x01) return false; if(this.msg[2] != iNEMO_Start_Acquisition) return false; return true; } public boolean isStartAcquisitonNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_Start_Acquisition) return false; return true; } public boolean isStopAcquisitonACK(){ if(this.msg[0] != (ACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x01) return false; if(this.msg[2] != iNEMO_Stop_Acquisition) return false; return true; } public boolean isStopAcquisitonNACK(){ if(this.msg[0] != (NACK_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] != 0x02) return false; if(this.msg[2] != iNEMO_Stop_Acquisition) return false; return true; } public boolean isAcquisitionData(){ if(this.msg[0] != (DATA_type | ACK_NOTreq | Last_Frag | Version_1 | QoS_Normal)) return false; if(this.msg[1] < 0x03) return false; if(this.msg[2] != iNEMO_Start_Acquisition) return false; return true; } public static byte[] convertShortInBytes(short value){ ByteBuffer buffer = ByteBuffer.allocate(2); buffer.putShort(value); buffer.flip(); return buffer.array(); } public static short convertBytesInShort(byte[] values){ ByteBuffer buffer = ByteBuffer.wrap(values); ShortBuffer shorts = buffer.asShortBuffer( ); return shorts.get(0); } public String getErrorCode(){ if(this.msg[1] == 0x02){ if(this.msg[3] == CmdUnsupported) return "Command Not Supported"; else if(this.msg[3] == ValueOutOfRange) return "Value Out Of Range"; else if(this.msg[3] == NotExecutable) return "Not Executable"; else if(this.msg[3] == WrongSyntax) return "Wrong Syntax"; else if(this.msg[3] == iNEMONotConnected) return "iNEMO Not Connected"; } return "Error code undefined"; } public String getStringPayload(){ String payload = ""; int len = this.msg[1] - 1; for(int i = 0; i < len ; i++){ payload += (char)this.msg[3 + i]; } return payload; } public static String getSensorName(byte sensor){ String s; if(sensor == ACCELEROMETER) s = "Accelerometer"; else if(sensor == MAGNETOMETER) s = "Magnetometer"; else if(sensor == GYRO_2AXIS) s = "Gyro 2-axis"; else if(sensor == GYRO_1AXIS) s = "Gyro 1-axis"; else if(sensor == PRESSURE) s = "Pressure"; else if(sensor == TEMPERATURE) s = "Temperature"; else s = ""; return s; } public static String getParameterName(byte sensor, byte parameter){ String s; if(sensor == ACCELEROMETER){ if(parameter == ACC_OUT_RATE) s = "Output Data Rate"; else if(parameter == ACC_FULL_SCALE) s = "Full Scale"; else if(parameter == ACC_HPF) s = "HP filter"; else if(parameter == ACC_OFFSET_X) s = "Offset x"; else if(parameter == ACC_OFFSET_Y) s = "Offset y"; else if(parameter == ACC_OFFSET_Z) s = "Offset z"; else s = ""; } else if(sensor == MAGNETOMETER){ if(parameter == MAG_OUT_RATE) s = "Output Data Rate"; else if(parameter == MAG_FULL_SCALE) s = "Full Scale"; else if(parameter == MAG_OP_MODE) s = "Operating Mode"; else if(parameter == MAG_OFFSET_X) s = "Offset x"; else if(parameter == MAG_OFFSET_Y) s = "Offset y"; else if(parameter == MAG_OFFSET_Z) s = "Offset z"; else s = ""; } else if(sensor == GYRO_2AXIS){ if(parameter == GYRO2_FULL_SCALE) s = "Full Scale"; else if(parameter == GYRO2_OFFSET_X) s = "Offset x"; else if(parameter == GYRO2_OFFSET_Y) s = "Offset y"; else s = ""; } else if(sensor == GYRO_1AXIS){ if(parameter == GYRO1_FULL_SCALE) s = "Full Scale"; else if(parameter == GYRO1_OFFSET_Z) s = "Offset z"; else s = ""; } else if(sensor == PRESSURE){ if(parameter == PRESS_OUT_RATE) s = "Output Data Rate"; else if(parameter == PRESS_OFFSET) s = "Offset"; else s = ""; } else if(sensor == TEMPERATURE){ if(parameter == TEMP_OFFSET) s = "Offset"; else s = ""; } else s = ""; return s; } public static String getParameterValueName(byte sensor, byte parameter, byte[] value){ String s; if(sensor == ACCELEROMETER){ if(parameter == ACC_OUT_RATE){ if(value[0] == ACC_OUT_RATE_50HZ) s = "50Hz"; else if(value[0] == ACC_OUT_RATE_100HZ) s = "100Hz"; else if(value[0] == ACC_OUT_RATE_400HZ) s = "400Hz"; else if(value[0] == ACC_OUT_RATE_1000HZ) s = "1000Hz"; else s = ""; } else if(parameter == ACC_FULL_SCALE){ if(value[0] == ACC_FULL_SCALE_2G) s = "2g"; else if(value[0] == ACC_FULL_SCALE_4G) s = "4g"; else if(value[0] == ACC_FULL_SCALE_8G) s = "8g"; else s = ""; } else if(parameter == ACC_HPF){ // TODO s = ""; } else if(parameter == ACC_OFFSET_X){ short v = convertBytesInShort(value); s = "" + v; } else if(parameter == ACC_OFFSET_Y){ short v = convertBytesInShort(value); s = "" + v; } else if(parameter == ACC_OFFSET_Z){ short v = convertBytesInShort(value); s = "" + v; } else s = ""; } else if(sensor == MAGNETOMETER){ if(parameter == MAG_OUT_RATE){ if(value[0] == MAG_OUT_RATE_0_75HZ) s = "0.75Hz"; else if(value[0] == MAG_OUT_RATE_1_5HZ) s = "1.5Hz"; else if(value[0] == MAG_OUT_RATE_3HZ) s = "3Hz"; else if(value[0] == MAG_OUT_RATE_7_5HZ) s = "7.5Hz"; else if(value[0] == MAG_OUT_RATE_15HZ) s = "15Hz"; else if(value[0] == MAG_OUT_RATE_30HZ) s = "30Hz"; else if(value[0] == MAG_OUT_RATE_75HZ) s = "75Hz"; else s = ""; } else if(parameter == MAG_FULL_SCALE){ if(value[0] == MAG_FULL_SCALE_1_3G) s = "1.3g"; else if(value[0] == MAG_FULL_SCALE_1_9G) s = "1.9g"; else if(value[0] == MAG_FULL_SCALE_2_5G) s = "2.5g"; else if(value[0] == MAG_FULL_SCALE_4_0G) s = "4.0g"; else if(value[0] == MAG_FULL_SCALE_4_7G) s = "4.7g"; else if(value[0] == MAG_FULL_SCALE_5_6G) s = "5.6g"; else if(value[0] == MAG_FULL_SCALE_8_1G) s = "8.1g"; else s = ""; } else if(parameter == MAG_OP_MODE){ if(value[0] == MAG_OP_MODE_NORMAL) s = "Normal"; else if(value[0] == MAG_OP_MODE_POS_BIAS) s = "Positive Bias"; else if(value[0] == MAG_OP_MODE_NEG_BIAS) s = "Negative Bias"; else if(value[0] == MAG_OP_MODE_FORBIDDEN) s = "Forbidden"; else s = ""; } else if(parameter == MAG_OFFSET_X){ short v = convertBytesInShort(value); s = "" + v; } else if(parameter == MAG_OFFSET_Y){ short v = convertBytesInShort(value); s = "" + v; } else if(parameter == MAG_OFFSET_Z){ short v = convertBytesInShort(value); s = "" + v; } else s = ""; } else if(sensor == GYRO_2AXIS){ if(parameter == GYRO2_FULL_SCALE){ if(value[0] == GYRO2_FULL_SCALE_300) s = "300dps"; else if(value[0] == GYRO2_FULL_SCALE_1200) s = "1200dps"; else s = ""; } else if(parameter == GYRO2_OFFSET_X){ short v = convertBytesInShort(value); s = "" + v; } else if(parameter == GYRO2_OFFSET_Y){ short v = convertBytesInShort(value); s = "" + v; } else s = ""; } else if(sensor == GYRO_1AXIS){ if(parameter == GYRO1_FULL_SCALE){ if(value[0] == GYRO1_FULL_SCALE_300) s = "300dps"; else s = ""; } else if(parameter == GYRO1_OFFSET_Z){ short v = convertBytesInShort(value); s = "" + v; } else s = ""; } else if(sensor == PRESSURE){ if(parameter == PRESS_OUT_RATE) s = "Output Data Rate"; else if(parameter == PRESS_OFFSET){ short v = convertBytesInShort(value); s = "" + v; } else s = ""; } else if(sensor == TEMPERATURE){ if(parameter == TEMP_OFFSET){ short v = convertBytesInShort(value); s = "" + v; } else s = ""; } else s = ""; return s; } public boolean updateParameter(INemoInfo info){ if(info == null) return false; int len = (this.msg[1] - 3) <= 2 ? (this.msg[1] - 3) : 2; byte[] value = new byte[len]; for(int i = 0; i < len; i++) value[i] = this.msg[5 + i]; return info.updateSensorParameter(this.msg[3], this.msg[4], value); } public boolean updateOutputMode(INemoInfo info, SharedPreferences sharedPrefs){ if(info == null || sharedPrefs == null) return false; Editor e = sharedPrefs.edit(); if((this.msg[3] & 0x01) == 0x01){ info.enableSensor(TEMPERATURE, true); e.putBoolean("enable_temp", true); } else{ info.enableSensor(TEMPERATURE, false); e.putBoolean("enable_temp", false); } if((this.msg[3] & 0x02) == 0x02){ info.enableSensor(PRESSURE, true); e.putBoolean("enable_press", true); } else{ info.enableSensor(PRESSURE, false); e.putBoolean("enable_press", false); } if((this.msg[3] & 0x04) == 0x04){ info.enableSensor(MAGNETOMETER, true); e.putBoolean("enable_mag", true); } else{ info.enableSensor(MAGNETOMETER, false); e.putBoolean("enable_mag", false); } if((this.msg[3] & 0x08) == 0x08){ info.enableSensor(GYRO_2AXIS, true); info.enableSensor(GYRO_1AXIS, true); e.putBoolean("enable_gyro", true); } else{ info.enableSensor(GYRO_2AXIS, false); info.enableSensor(GYRO_1AXIS, false); e.putBoolean("enable_gyro", false); } if((this.msg[3] & 0x10) == 0x10){ info.enableSensor(ACCELEROMETER, true); e.putBoolean("enable_acc", true); } else { info.enableSensor(ACCELEROMETER, false); e.putBoolean("enable_acc", false); } if((this.msg[3] & 0x20) == 0x20) { info.setCalibratedData(false); e.putBoolean("calibrated_data", false); } else { info.setCalibratedData(true); e.putBoolean("calibrated_data", true); } info.setAcquisitionRate(this.msg[4]); e.putString("acquisition_rate", Byte.toString(this.msg[4])); e.commit(); return true; } public void updateAcquiredData(INemoInfo info){ if(info == null) return; int count = 5; if(info.isSensorEnabled(ACCELEROMETER)){ short[] values = new short[3]; byte[] tmp = new byte[2]; tmp[0] = this.msg[count]; tmp[1] = this.msg[count + 1]; values[0] = convertBytesInShort(tmp); tmp[0] = this.msg[count + 2]; tmp[1] = this.msg[count + 3]; values[1] = convertBytesInShort(tmp); tmp[0] = this.msg[count + 4]; tmp[1] = this.msg[count + 5]; values[2] = convertBytesInShort(tmp); info.updateAcquiredData(ACCELEROMETER, values); count += 6; } if(info.isSensorEnabled(GYRO_2AXIS)){ short[] values = new short[2]; byte[] tmp = new byte[2]; tmp[0] = this.msg[count]; tmp[1] = this.msg[count + 1]; values[0] = convertBytesInShort(tmp); tmp[0] = this.msg[count + 2]; tmp[1] = this.msg[count + 3]; values[1] = convertBytesInShort(tmp); info.updateAcquiredData(GYRO_2AXIS, values); count += 4; } if(info.isSensorEnabled(GYRO_1AXIS)){ short[] values = new short[1]; byte[] tmp = new byte[2]; tmp[0] = this.msg[count]; tmp[1] = this.msg[count + 1]; values[0] = convertBytesInShort(tmp); info.updateAcquiredData(GYRO_1AXIS, values); count += 2; } if(info.isSensorEnabled(MAGNETOMETER)){ short[] values = new short[3]; byte[] tmp = new byte[2]; tmp[0] = this.msg[count]; tmp[1] = this.msg[count + 1]; values[0] = convertBytesInShort(tmp); tmp[0] = this.msg[count + 2]; tmp[1] = this.msg[count + 3]; values[1] = convertBytesInShort(tmp); tmp[0] = this.msg[count + 4]; tmp[1] = this.msg[count + 5]; values[2] = convertBytesInShort(tmp); info.updateAcquiredData(MAGNETOMETER, values); count += 6; } if(info.isSensorEnabled(PRESSURE)){ short[] values = new short[1]; byte[] tmp = new byte[2]; tmp[0] = this.msg[count]; tmp[1] = this.msg[count + 1]; values[0] = convertBytesInShort(tmp); info.updateAcquiredData(PRESSURE, values); count += 2; } if(info.isSensorEnabled(TEMPERATURE)){ short[] values = new short[1]; byte[] tmp = new byte[2]; tmp[0] = this.msg[count]; tmp[1] = this.msg[count + 1]; values[0] = convertBytesInShort(tmp); info.updateAcquiredData(TEMPERATURE, values); count += 2; } } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/CommunicationFrame.java
Java
oos
28,982
package com.st.android.iNemoDemo.iNemoInfo; import java.util.HashMap; import com.st.android.iNemoDemo.CommunicationFrame; public class INemoInfo { private String UID; private String FW_v; private String HW_v; private HashMap<Byte, Sensor> sensors; private HashMap<Byte, short[]> tmpAcquiredData; boolean calibratedData; boolean ahrsLib; byte acquisitionRate; public INemoInfo(){ this.sensors = new HashMap<Byte, Sensor>(); this.tmpAcquiredData = new HashMap<Byte, short[]>(); this.sensors.put(CommunicationFrame.ACCELEROMETER, new Accelerometer()); this.tmpAcquiredData.put(CommunicationFrame.ACCELEROMETER, new short[3]); this.sensors.put(CommunicationFrame.MAGNETOMETER, new Magnetometer()); this.tmpAcquiredData.put(CommunicationFrame.MAGNETOMETER, new short[3]); this.sensors.put(CommunicationFrame.GYRO_2AXIS, new Gyro_2axis()); this.tmpAcquiredData.put(CommunicationFrame.GYRO_2AXIS, new short[2]); this.sensors.put(CommunicationFrame.GYRO_1AXIS, new Gyro_1axis()); this.tmpAcquiredData.put(CommunicationFrame.GYRO_1AXIS, new short[1]); this.sensors.put(CommunicationFrame.PRESSURE, new Pressure()); this.tmpAcquiredData.put(CommunicationFrame.PRESSURE, new short[1]); this.sensors.put(CommunicationFrame.TEMPERATURE, new Temperature()); this.tmpAcquiredData.put(CommunicationFrame.TEMPERATURE, new short[1]); this.reset(); } public void reset(){ this.UID = " "; this.FW_v = " "; this.HW_v = " "; this.calibratedData = true; this.ahrsLib = false; this.acquisitionRate = 0; for(Byte b : this.sensors.keySet()) this.sensors.get(b).resetParameters(); } public String getUID() { return UID; } public void setUID(String uID) { UID = uID; } public String getFW_v() { return FW_v; } public void setFW_v(String fW_v) { FW_v = fW_v; } public String getHW_v() { return HW_v; } public void setHW_v(String hW_v) { HW_v = hW_v; } public boolean isCalibratedData() { return calibratedData; } public void setCalibratedData(boolean calibratedData) { this.calibratedData = calibratedData; } public byte getAcquisitionRate() { return acquisitionRate; } public void setAcquisitionRate(byte acquisitionRate) { this.acquisitionRate = acquisitionRate; } public boolean isAhrsLib() { return ahrsLib; } public void setAhrsLib(boolean ahrsLib) { this.ahrsLib = ahrsLib; } public HashMap<Byte, short[]> getTmpAcquiredData() { return tmpAcquiredData; } public HashMap<Byte, Sensor> getSensors() { return sensors; } public boolean updateSensorParameter(byte sensor, byte parameter, byte[] value){ if(!this.sensors.containsKey(sensor)) return false; return this.sensors.get(sensor).updateParameter(parameter, value); } public byte[] getSensorParameterValue(byte sensor, byte parameter){ if(!this.sensors.containsKey(sensor)) return null; return this.sensors.get(sensor).getParamaterValue(parameter); } public void enableSensor(byte sensor, boolean enabled){ if(this.sensors.containsKey(sensor)) this.sensors.get(sensor).setEnabled(enabled); } public boolean isSensorEnabled(byte sensor){ if(this.sensors.containsKey(sensor)) return this.sensors.get(sensor).isEnabled(); return false; } public void updateAcquiredData(byte sensor, short[] values){ if(this.tmpAcquiredData.containsKey(sensor) && values.length == this.tmpAcquiredData.get(sensor).length){ for(int i = 0; i < values.length; i++) this.tmpAcquiredData.get(sensor)[i] = values[i]; } } public String toString(){ String s = "UID: " + this.UID + "\n"; s += "FW: " + this.FW_v + "\n"; s += "HW: " + this.HW_v + "\n"; if(this.calibratedData) s += "Data: Calibrated\n"; else s += "Data: Raw\n"; if(this.ahrsLib) s += "AHRS Library: enabled\n"; else s += "AHRS Library: disabled\n"; s += "Acquisition Rate: "; if(this.acquisitionRate == CommunicationFrame.LOW_FREQUENCY) s += "1Hz\n"; else if(this.acquisitionRate == CommunicationFrame.MEDIUM_FREQUENCY_1) s += "10Hz\n"; else if(this.acquisitionRate == CommunicationFrame.MEDIUM_FREQUENCY_2) s += "25Hz\n"; else if(this.acquisitionRate == CommunicationFrame.MEDIUM_FREQUENCY_3) s += "30Hz\n"; else if(this.acquisitionRate == CommunicationFrame.HIGH_FREQUENCY_1) s += "50Hz\n"; else if(this.acquisitionRate == CommunicationFrame.HIGH_FREQUENCY_2) s += "100Hz\n"; else if(this.acquisitionRate == CommunicationFrame.HIGH_FREQUENCY_3) s += "400Hz\n"; for(Byte b : this.sensors.keySet()){ if(this.sensors.get(b).isEnabled()){ s += CommunicationFrame.getSensorName(b) + ":\n"; for(Byte b2 : this.sensors.get(b).parameters.keySet()){ s += "\t- " + CommunicationFrame.getParameterName(b, b2) + ": " + CommunicationFrame.getParameterValueName(b, b2, this.sensors.get(b).parameters.get(b2)) + "\n"; } } } return s; } public String printAcquisitionData(){ String s = ""; for(Byte b : this.sensors.keySet()){ if(this.sensors.get(b).isEnabled()){ s += CommunicationFrame.getSensorName(b) + ":"; if(b == CommunicationFrame.ACCELEROMETER){ s+= "\n"; s+= "\tx: " + this.tmpAcquiredData.get(b)[0] + " mg\n"; s+= "\ty: " + this.tmpAcquiredData.get(b)[1] + " mg\n"; s+= "\tz: " + this.tmpAcquiredData.get(b)[2] + " mg\n"; } else if(b == CommunicationFrame.MAGNETOMETER){ s+= "\n"; s+= "\tx: " + this.tmpAcquiredData.get(b)[0] + " mG\n"; s+= "\ty: " + this.tmpAcquiredData.get(b)[1] + " mG\n"; s+= "\tz: " + this.tmpAcquiredData.get(b)[2] + " mG\n"; } else if(b == CommunicationFrame.GYRO_2AXIS){ s+= "\n"; s+= "\tx: " + this.tmpAcquiredData.get(b)[0] + " dps\n"; s+= "\ty: " + this.tmpAcquiredData.get(b)[1] + " dps\n"; } else if(b == CommunicationFrame.GYRO_1AXIS){ s+= "\n"; s+= "\tz: " + this.tmpAcquiredData.get(b)[0] + " dps\n"; } else if(b == CommunicationFrame.PRESSURE){ s+= "\t" + (float)(this.tmpAcquiredData.get(b)[0]/10.0f) + " mbar\n"; } else if(b == CommunicationFrame.TEMPERATURE){ s+= "\t" + (float)(this.tmpAcquiredData.get(b)[0]/10.0f) + " °C\n"; } } } return s; } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/iNemoInfo/INemoInfo.java
Java
oos
6,202
package com.st.android.iNemoDemo.iNemoInfo; import com.st.android.iNemoDemo.CommunicationFrame; public class Gyro_2axis extends Sensor{ public Gyro_2axis(){ super(); this.parameters.put(CommunicationFrame.GYRO2_FULL_SCALE, new byte[1]); this.parameters.put(CommunicationFrame.GYRO2_OFFSET_X, new byte[2]); this.parameters.put(CommunicationFrame.GYRO2_OFFSET_Y, new byte[2]); } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/iNemoInfo/Gyro_2axis.java
Java
oos
393
package com.st.android.iNemoDemo.iNemoInfo; import com.st.android.iNemoDemo.CommunicationFrame; public class Temperature extends Sensor{ public Temperature(){ super(); this.parameters.put(CommunicationFrame.TEMP_OFFSET, new byte[2]); } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/iNemoInfo/Temperature.java
Java
oos
250
package com.st.android.iNemoDemo.iNemoInfo; import com.st.android.iNemoDemo.CommunicationFrame; public class Accelerometer extends Sensor{ public Accelerometer(){ super(); this.parameters.put(CommunicationFrame.ACC_OUT_RATE, new byte[1]); this.parameters.put(CommunicationFrame.ACC_FULL_SCALE, new byte[1]); this.parameters.put(CommunicationFrame.ACC_HPF, new byte[2]); this.parameters.put(CommunicationFrame.ACC_OFFSET_X, new byte[2]); this.parameters.put(CommunicationFrame.ACC_OFFSET_Y, new byte[2]); this.parameters.put(CommunicationFrame.ACC_OFFSET_Z, new byte[2]); } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/iNemoInfo/Accelerometer.java
Java
oos
597
package com.st.android.iNemoDemo.iNemoInfo; import com.st.android.iNemoDemo.CommunicationFrame; public class Pressure extends Sensor{ public Pressure(){ super(); this.parameters.put(CommunicationFrame.PRESS_OUT_RATE, new byte[1]); this.parameters.put(CommunicationFrame.PRESS_OFFSET, new byte[2]); } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/iNemoInfo/Pressure.java
Java
oos
314
package com.st.android.iNemoDemo.iNemoInfo; import java.util.HashMap; public abstract class Sensor { private boolean enabled; protected HashMap<Byte, byte[]> parameters; public Sensor(){ super(); enabled = false; this.parameters = new HashMap<Byte, byte[]>(); } public boolean isEnabled() { return enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; } public HashMap<Byte, byte[]> getParameters() { return parameters; } public byte[] getParamaterValue(byte parameter){ if(!this.parameters.containsKey(parameter)) return null; return this.parameters.get(parameter); } public boolean updateParameter(byte parameter, byte[] value){ if(!this.parameters.containsKey(parameter)) return false; if(value.length != this.parameters.get(parameter).length) return false; for(int i = 0; i < value.length; i++) this.parameters.get(parameter)[i] = value[i]; return true; } public void resetParameters(){ for(Byte b : this.parameters.keySet()){ int len = this.parameters.get(b).length; for(int i = 0; i < len; i++) this.parameters.get(b)[i] = 0x00; } } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/iNemoInfo/Sensor.java
Java
oos
1,143
package com.st.android.iNemoDemo.iNemoInfo; import com.st.android.iNemoDemo.CommunicationFrame; public class Magnetometer extends Sensor{ public Magnetometer(){ super(); this.parameters.put(CommunicationFrame.MAG_OUT_RATE, new byte[1]); this.parameters.put(CommunicationFrame.MAG_FULL_SCALE, new byte[1]); this.parameters.put(CommunicationFrame.MAG_OP_MODE, new byte[1]); this.parameters.put(CommunicationFrame.MAG_OFFSET_X, new byte[2]); this.parameters.put(CommunicationFrame.MAG_OFFSET_Y, new byte[2]); this.parameters.put(CommunicationFrame.MAG_OFFSET_Z, new byte[2]); } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/iNemoInfo/Magnetometer.java
Java
oos
597
package com.st.android.iNemoDemo.iNemoInfo; import com.st.android.iNemoDemo.CommunicationFrame; public class Gyro_1axis extends Sensor{ public Gyro_1axis(){ super(); this.parameters.put(CommunicationFrame.GYRO1_FULL_SCALE, new byte[1]); this.parameters.put(CommunicationFrame.GYRO1_OFFSET_Z, new byte[2]); } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/iNemoInfo/Gyro_1axis.java
Java
oos
322
package com.st.android.iNemoDemo; import android.os.Bundle; import android.preference.PreferenceActivity; public class SettingsActivity extends PreferenceActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); setResult(RESULT_OK); } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/SettingsActivity.java
Java
oos
360
package com.st.android.iNemoDemo; import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Intent; import android.os.Bundle; import android.util.Log; /* This Activity does nothing but receive USB_DEVICE_ATTACHED events from the * USB service and springboards to the main Gallery activity */ public final class UsbAccessoryActivity extends Activity { static final String TAG = "UsbAccessoryActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(this, INemoDemoActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(intent); } catch (ActivityNotFoundException e) { Log.e(TAG, "unable to start DemoKit activity", e); } finish(); } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/UsbAccessoryActivity.java
Java
oos
855
package com.st.android.iNemoDemo; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.ParcelFileDescriptor; import android.util.Log; import com.android.future.usb.UsbAccessory; import com.android.future.usb.UsbManager; import com.st.android.iNemoDemo.iNemoInfo.INemoInfo; public class ADKActivity extends Activity implements Runnable{ static final String TAG = "ADK_Activity"; private static final String ACTION_USB_PERMISSION = "com.st.android.adkping.action.USB_PERMISSION"; protected static final int NO_DEVICE = 0; protected static final int ATTACHED_DEVICE = 1; protected static final int CONNECTED_DEVICE = 2; protected static final int ACQUISITION = 3; protected static final int SETTINGS = 4; private UsbManager mUsbManager; private PendingIntent mPermissionIntent; private boolean mPermissionRequestPending; UsbAccessory mAccessory; ParcelFileDescriptor mAccessoryFileDescriptor; FileInputStream mAccessoryInput; FileOutputStream mAccessoryOutput; protected INemoInfo mINemoInfo = null; protected int mStatus = 0; private final BroadcastReceiver mUsbBroadcastReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION_USB_PERMISSION.equals(action)){ synchronized (this){ UsbAccessory accessory = UsbManager.getAccessory(intent); if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { openAccessory(accessory); } else { Log.d(TAG, "permission denied for accessory " + accessory); } mPermissionRequestPending = false; } } else if (UsbManager.ACTION_USB_ACCESSORY_DETACHED.equals(action)){ UsbAccessory accessory = UsbManager.getAccessory(intent); if (accessory != null && accessory.equals(mAccessory)) { closeAccessory(); } } } }; Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { CommunicationFrame cf = (CommunicationFrame) msg.obj; handleReceivedMsg(cf); } }; protected void setStatus(int status) {} protected void handleReceivedMsg(CommunicationFrame cf) {} protected void resume(){ this.setStatus(mStatus); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mUsbManager = UsbManager.getInstance(this); /* Handle the Accessory stuff */ mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); registerReceiver(mUsbBroadcastReceiver, filter); final ActivityDataObject obj = (ActivityDataObject)getLastNonConfigurationInstance(); if (obj != null){ // TODO seguita la documentazione ma non funziona (???) this.mAccessory = obj.getmAccessory(); this.mINemoInfo = obj.getmINemoInfo(); if(this.mAccessory != null){ openAccessory(this.mAccessory); } } this.setStatus(mStatus); } @Override public Object onRetainNonConfigurationInstance() { final ActivityDataObject obj = new ActivityDataObject(); obj.setmAccessory(mAccessory); obj.setmINemoInfo(mINemoInfo); return obj; } @Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); mStatus = savedInstanceState.getInt("status"); } protected void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); savedInstanceState.putInt("status", mStatus); } @Override public void onResume() { super.onResume(); if(mAccessory == null) checkConnectedAccesory(); this.setStatus(mStatus); } @Override public void onPause() { super.onPause(); } @Override public void onDestroy() { closeAccessory(); unregisterReceiver(mUsbBroadcastReceiver); super.onDestroy(); } private void checkConnectedAccesory(){ UsbAccessory[] accessories = mUsbManager.getAccessoryList(); UsbAccessory accessory = (accessories == null ? null : accessories[0]); if (accessory != null) { if (mUsbManager.hasPermission(accessory)) { openAccessory(accessory); } else { synchronized (mUsbBroadcastReceiver) { if (!mPermissionRequestPending) { mUsbManager.requestPermission(accessory, mPermissionIntent); mPermissionRequestPending = true; } } } } else { Log.e(TAG, "mAccessory is null"); } } private void openAccessory(UsbAccessory accessory) { mAccessoryFileDescriptor = mUsbManager.openAccessory(accessory); if (mAccessoryFileDescriptor != null) { this.mAccessory = accessory; FileDescriptor fd = mAccessoryFileDescriptor.getFileDescriptor(); mAccessoryInput = new FileInputStream(fd); mAccessoryOutput = new FileOutputStream(fd); Thread thread = new Thread(null, this, "ADKThread"); thread.start(); setStatus(ATTACHED_DEVICE); Log.d(TAG, "accessory opened"); } else{ Log.d(TAG, "accessory open fail"); } } private void closeAccessory() { try{ if(mAccessoryFileDescriptor != null) mAccessoryFileDescriptor.close(); } catch (IOException e) {} finally{ mAccessoryFileDescriptor = null; mAccessory = null; setStatus(NO_DEVICE); } } public void run() { int ret = 0; byte[] buffer = new byte[16384]; while (ret >= 0) { try { ret = mAccessoryInput.read(buffer); } catch (IOException e) { break; } CommunicationFrame cf = new CommunicationFrame(); Message m = Message.obtain(); cf.setMsg(buffer); m.obj = cf; mHandler.sendMessage(m); } } public void sendCommand(CommunicationFrame cf) { if (mAccessoryOutput != null) { try { mAccessoryOutput.write(cf.getMsg()); } catch (IOException e) { Log.e(TAG, "write failed", e); } } } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/ADKActivity.java
Java
oos
6,237
package com.st.android.iNemoDemo; import com.android.future.usb.UsbAccessory; import com.st.android.iNemoDemo.iNemoInfo.INemoInfo; public class ActivityDataObject { private INemoInfo mINemoInfo; private UsbAccessory mAccessory; public ActivityDataObject(){ this.mINemoInfo = null; this.mAccessory = null; } public INemoInfo getmINemoInfo() { return mINemoInfo; } public void setmINemoInfo(INemoInfo mINemoInfo) { this.mINemoInfo = mINemoInfo; } public UsbAccessory getmAccessory() { return mAccessory; } public void setmAccessory(UsbAccessory mAccessory) { this.mAccessory = mAccessory; } }
zz314326255--adkping
iNEMO-accessory/app/iNemoDemo/src/com/st/android/iNemoDemo/ActivityDataObject.java
Java
oos
625
package com.tictactoe; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.Window; import android.view.View.OnClickListener; import android.widget.ImageView; public class Main extends Activity { /** Called when the activity is first created. */ boolean suono=true; @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); ImageView due_giocatori = (ImageView) findViewById(R.id.due_giocatori); final ImageView img_sound = (ImageView) findViewById(R.id.sound); Tris.partite_vinte_o=0; Tris.partite_vinte_x=0; due_giocatori.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent gioco = new Intent(Main.this,Gioco.class); startActivity(gioco); finish(); } }); img_sound.setOnClickListener(new OnClickListener() { public void onClick(View v) { if(suono){ img_sound.setImageResource(R.drawable.sound_on); Gioco.sound=true; suono=false; }else{ img_sound.setImageResource(R.drawable.sound_off); Gioco.sound=false; suono=true; } } }); } }
zygora52-lineup
src/com/tictactoe/Main.java
Java
gpl3
1,327
package com.tictactoe; public class Tris { /** * @author Vincenzo di Cicco * * */ final int X=1,O=2; int orizzontale,verticale,diagonale; static int partite_vinte_x=0,partite_vinte_o=0; int[][] tris = new int[3][3]; void aggiungi_mossa(int elemento,int x,int y){ if (elemento == X){ tris[x][y]=X; }else if(elemento == O){ tris[x][y]=O; } } int posizione(int x, int y){ return tris[x][y]; } int controlla_vittoria(Tris tris){ orizzontale=-1; verticale=-1; diagonale=-1; for(int i=0; i < 3; i++){ if((tris.posizione(0, i) == tris.X) & (tris.posizione(1, i) == tris.X)& (tris.posizione(2, i) == tris.X)){orizzontale=i; return tris.X;} if((tris.posizione(0, i) == tris.O) & (tris.posizione(1, i) == tris.O)& (tris.posizione(2, i) == tris.O)){orizzontale=i; return tris.O;} if((tris.posizione(i, 0) == tris.X) & (tris.posizione(i, 1) == tris.X)& (tris.posizione(i,2) == tris.X)){verticale=i; return tris.X;} if((tris.posizione(i, 0) == tris.O) & (tris.posizione(i, 1) == tris.O)& (tris.posizione(i,2) == tris.O)){verticale=i; return tris.O;} } if((tris.posizione(0, 0) == tris.O) & (tris.posizione(1, 1) == tris.O)& (tris.posizione(2,2) == tris.O)){diagonale=0; return tris.O;} if((tris.posizione(0, 0) == tris.X) & (tris.posizione(1, 1) == tris.X)& (tris.posizione(2,2) == tris.X)){diagonale=0; return tris.X;} if((tris.posizione(2, 0) == tris.O) & (tris.posizione(1, 1) == tris.O)& (tris.posizione(0,2) == tris.O)){diagonale=1; return tris.O;} if((tris.posizione(2, 0) == tris.X) & (tris.posizione(1, 1) == tris.X)& (tris.posizione(0,2) == tris.X)){diagonale=1; return tris.X;} return -1; } }
zygora52-lineup
src/com/tictactoe/Tris.java
Java
gpl3
1,699
<?php if(!defined('THINK_PATH')) exit(); return array( //系统配置文件 'WEB_NAME' =>'ZGCMS',//网站名称 'PAGESIZE' =>'20',//分页每页显示页数 'NAV_NUM' =>'6',//分页每页显示页数 'ROTATION_NUM' =>'3',//首页轮播器图片显示数目 'ROTATION_TIME' =>'3',//首页轮播器图片播放速度 'TEXT_ADVER_NUM' =>'3',//文字广告显示数目 'HEADER_ADVER_NUM' =>'3',//头部图片广告显示数目 'SIDERBAR_ADVER_NUM' =>'3',//侧边栏图片广告显示数目 ); ?>
zzgcms
ZGCMS/sys_config.php
PHP
art
515
<?php //开启调试模式 define('APP_DEBUG',true); //定义ThinkPHP核心文件夹路径 define('THINK_PATH','./ThinkPHP/'); //定义项目名称与项目路径 define('APP_NAME','Admin'); define('APP_PATH','./Admin/'); //定义网站根目录 define('ROOT_DIR',dirname(__FILE__)); //定义网站目录入口文件所在目录 //define('WEB_DIR','/ZGCMS'); //加载ThinkPHP框架入口文件 require(THINK_PATH."/ThinkPHP.php"); ?>
zzgcms
ZGCMS/admin.php
PHP
art
461
@CHARSET "UTF-8"; #feedback { width:690px; float:left; margin:0 0 10px 0; border:1px solid #ccc; } #feedback h2 { } #feedback h4 { font-size:18px; color:#333; width:96%; margin:10px auto; padding:10px 0; border-bottom:1px solid #ccc; } #feedback h2 a { color:#360; text-decoration:none; } #feedback h2 a:hover { color:#f60; } #feedback h3 { text-align:center; font-size:22px; color:#333; border-bottom:1px solid #ccc; margin:0 auto; width:96%; padding:20px 0; } #feedback p.info { font-size:16px; text-indent:25px; line-height:150%; border-bottom:1px solid #ccc; margin:0 auto; width:96%; padding:20px 0; margin-bottom:10px; } #feedback dl { width:670px; margin:10px 0; float:left; border-bottom:1px dashed #ccc; margin-left:8px; } #feedback dl dt { float:left; } #feedback dl dd { float:right; width:585px; padding:0 0 10px 10px; } #feedback dl dd span { color:#06f; } #feedback dl dd.info { font-size:16px; line-height:150%; } #feedback dl dd.bottom { text-align:right; } #feedback dl dd em { float:right; font-style:normal; } #sidebar { width:260px; float:right; margin:0 0 10px 0; border:1px solid #ccc; } #sidebar ul { padding:2px 10px 0 10px; } #sidebar ul li { line-height:160%; background:url(../Images/pointer.png) no-repeat left center; padding:5px 0 0 10px; border-bottom:1px dashed #ccc; } #sidebar ul li em { float:right; font-style:normal; font-family:Tahoma; } #sidebar ul li a { color:#666; text-decoration:none; } #sidebar ul li a:hover { text-decoration:underline; } div.d5 { width:674px; margin:10px 0; padding:8px; border:1px solid #ccc; clear:both; } div.d5 p { margin:10px 0; } div.d5 p textarea { width:650px; height:150px; background:#eee; border:1px dashed #999; } div.d5 p.red { color:red; } div.d5 p input.text { width:80px; height:20px; border:1px dashed #999; background:#eee; } div.d5 p input.submit { width:80px; height:25px; cursor:pointer; } div.d5 p img.code { width:78px; height:30px; position:relative; top:10px; cursor:pointer; }
zzgcms
ZGCMS/Public/Css/feedback.css
CSS
art
2,190
@CHARSET "UTF-8"; body,h1,h2,h3,p,form,ul,ol,li,dl,dt,dd { padding:0; margin:0; } body { background:#fff; font-size:12px; } ul,ol { list-style-type:none; } #top { background:url(../Images/admin_top_bg.gif); } #top h1 { width:150px; height:80px; font-size:12px; background:url(../Images/logosmall.png) no-repeat; text-indent:-9999px; float:left; } #top ul { float:left; padding:47px 0 0 10px; } #top ul li { padding:0 0 0 5px; float:left; } #top ul li a { width:58px; height:33px; line-height:33px; text-align:center; display:block; background:url(../Images/li_bg.png) no-repeat left bottom; font-size:14px; font-weight:bold; text-decoration:none; color:#fff; } #top ul li a.selected { background-position:right bottom; color:#3b6ea5; } #top p { float:right; padding:33px 20px 0 0; color:#fff; } #top p a { text-decoration:none; color:#fff; } #top p a:hover { text-decoration:underline; } #sidebar { background:#f7fbfc url(../Images/sidebar_right.png) repeat-y right; } #sidebar dl { padding:20px; text-indent:2px; } #sidebar dl dt { font-size:14px; color:#3b6ea5; font-weight:bold; border-bottom:1px solid #ccc; padding:5px 0 ; margin:5px 0; } #sidebar dl dd { height:22px; line-height:22px; } #sidebar dl dd a { color:#333; text-decoration:none; } #sidebar dl dd a:hover { text-decoration:underline; } #main { background:#fff; } #main div.map { padding:15px; color:#333; } #main div.map strong { color:green; } #main table { width:95%; margin-left:auto; margin-right:auto; text-align:center; } #main table table { width:100%; text-align:left; } #main table.cke_dialog { width:auto; } #main table.user { text-align:left; } #main table span.red { color:red; } #main table span.green { color:green; } #main table.user tr td select { width:220px; height:22px; border:1px solid #ccc; background:#fff; } #main table.user tr td img.face { margin:0 0 0 60px; } #main table.left { text-align:left; } #main table tr { background:#fff; } #main table tr:hover { background:#ffffcc; } #main table tr.ckeditor { background:none; } #main table tr.ckeditor tr { background:none; } #main table.cke_dialog tr { background:none; } #main table th, #main table td { height:30px; line-height:30px; color:#333; } #main table th { background:#eef3f7; border-bottom:1px solid #d5dfe8; font-weight:normal; } #main table td { border-bottom:1px solid #eee; } #main table.content td { text-align:left; padding-left:5px; } #main table.content td span.red { color:red; } #main table.content td input.text { width:440px; } #main table.content td input.small { width:100px; } #main table.content td select { border:1px solid #ccc; width:150px; height:22px; } #main table.content td select optgroup { font-style:normal; } #main table.content td select option { padding:0 0 0 20px; } #main table.content td textarea { margin:0; width:440px; height:80px; overflow:auto; } #main table.content td span.middle { vertical-align:30px; } #main a { color:#3b6ea5; text-decoration:none; } #main a:hover { text-decoration:underline; } #main p.center { text-align:center; padding:20px; } #main form input.text { width:220px; height:19px; background:#fff; border:1px solid #ccc; } #main form input.sort { width:30px; text-align:center; } #main form select { width:100px; height:19px; background:#fff; } #main form textarea { font-size:13px; width:220px; height:100px; background:#fff; border:1px solid #ccc; margin:0 0 0 0; } #main form input.submit { cursor:pointer; margin:0 0 0 60px; } #main ol { padding:0 0 0 26px; height:35px; /*float:left;*/ } #main ol li { float:left; padding:0 10px 0 0; } #main ol li a { padding:6px; display:block; } #main ol li a:hover { background:#eee; } #main ol li a.selected { background:#3b6ea5; color:#fff; } #adminLogin { width:350px; margin:100px auto; color:#666; font-size:14px; } #adminLogin fieldset { padding:20px; } #adminLogin legend { font-size:16px; font-weight:bold; } #adminLogin label { display:block; margin:5px; } #adminLogin label.t { color:#999; text-indent:56px; } #adminLogin label input.text { width:220px; height:27px; border:1px solid #666; background:#eee; } #adminLogin input.submit { margin: 0 0 0 60px; cursor:pointer; } #adminLogin label img { margin:0 0 0 56px; cursor:pointer; } #page { text-align:center; padding:10px; } #page a { border:1px solid #666; padding:2px 5px; margin:0 2px; } #page a:hover,#page span.me { color:#fff; border:1px solid #000; background:#000; text-decoration:none; } #page span.disabled { border:1px solid #ccc; padding:2px 5px; margin:0 2px; color:#ccc; } #page span.me { padding:2px 5px; margin:0 2px; } #page select.select { width:120px; background:#fff; border:1px solid #ccc; } #page select.select optgroup { font-style:normal; } #cat td select { border:1px solid #ccc; width:150px; height:22px; } #cat td select option { padding:0 0 0 20px; } /* #search{ padding:0 10px 0 0; float:right; height:35px; } #search select{ background:#fff; border:1px solid #ccc; margin:0 10px 0 10px; font-style:normal; } #search input{ height:50px; } #search .sent{ height:28px; margin:0 30px 0 0; } */
zzgcms
ZGCMS/Public/Css/admin.css
CSS
art
5,574
@CHARSET "UTF-8"; #friendlink { border:1px solid #ccc; margin:0 0 10px 0; padding:0 0 10px 0; } #friendlink h2 { text-align:center; } #friendlink h2 a { color:#360; text-decoration:none; } #reg h2 a:hover { color:#f60; } #friendlink h3 { padding:20px; } #friendlink div { padding:0 20px; } #friendlink div a { color:#666; text-decoration:none; margin-right:10px; } #friendlink div a:hover { text-decoration:underline; } #friendlink div img { border:none; } #friendlink form { padding:15px 0; } #friendlink form dl { padding-left:250px; } #friendlink form dl dd { padding:5px 0; } #friendlink form dl dd span.red { color:red; } #friendlink form dl dd input.text,#reg form dl dd select { width:220px; height:22px; border:1px solid #999; background:#eee; } #friendlink form dl dd img.face { margin:0 0 0 60px; } #friendlink form dl dd img.code { cursor:pointer; margin:0 0 0 60px; } #friendlink form dl dd input.submit{ cursor:pointer; margin:0 0 0 60px; }
zzgcms
ZGCMS/Public/Css/friendlink.css
CSS
art
1,045
@CHARSET "UTF-8"; #user { width:268px; height:398px; float:right; margin:0 0 10px 0; border:1px solid #ccc; overflow:hidden; } #user form { position:relative; top:2px; } #user form label { display:block; padding:6px 0 4px 12px; } #user form label input.text { width:180px; height:20px; border:1px solid #666; background:#eee; } #user form label input.code { width:100px; } #user form label.yzm { position:relative; top:-14px; } #user form img { width:78px; height:30px; position:relative; top:10px; cursor:pointer; } #user form p { padding:5px 0; text-align:center; position:relative; top:-5px; } #user form p input.submit { width:45px; height:20px; cursor:pointer; font-sizez:12px; } #user form p a { color:green; text-decoration:none; } #user form p a:hover { text-decoration:underline; } #user div.a { width:80%; margin:10px auto; border:1px solid #eee; background:#fffffc; height:22px; line-height:22px; text-align:center; border-right:none; border-left:none; } #user div.a strong { color:#ff6600; } #user div.b { width:70%; margin:0 auto; padding:15px 0 0 0; height:85px; } #user div.b img { display:block; float:left; } #user div.b a { display:block; float:right; width:80px; padding:8px 0 0 0; color:green; letter-spacing:2px; } #user h3 { font-size:12px; padding:8px 10px; clear:both; } #user h3 span { color:#ccc; } #user dl { width:72px; float:left; padding:0 0 0 12px; } #user dl dt img { display:block; } #user dl dd { padding:5px; text-align:center; } #news { width:378px; height:398px; border:1px solid #ccc; float:right; margin:0 10px 10px 0; padding:0 10px; } #news h3 { text-align:center; padding:10px; color:#333; font-size:16px; } #news h3 a { color:#333; text-decoration:none; } #news h3 a:hover { text-decoration:underline; } #news p { line-height:150%; } #news p a { color:#333; text-decoration:none; } #news p a:hover { text-decoration:underline; } #news p.link { color:green; padding:4px 0; border-bottom:1px dashed #999; } #news p.link a { color:green; display:inline-block; padding:0 0 5px 0; } #news ul { padding:5px 2px 0 2px; } #news ul li { height:24px; line-height:24px; background:url(../Images/pointer.png) no-repeat left center; padding:0 0 0 10px; } #news ul li em { float:right; font-style:normal; font-family:Tahoma; } #news ul li a { color:#666; text-decoration:none; } #news ul li a:hover { text-decoration:underline; } #pic { width:270px; height:195px; float:left; margin:0 0 10px 0; } #pic embed { display:block; border:1px solid #ccc; } #rec { width:268px; height:193px; float:left; margin:0 0 10px 0; border:1px solid #ccc; } #rec ul { padding:2px 10px 0 10px; } #rec ul li { height:23px; line-height:23px; background:url(../Images/pointer.png) no-repeat left center; padding:0 0 0 10px; } #rec ul li em { float:right; font-style:normal; font-family:Tahoma; } #rec ul li a { color:#666; text-decoration:none; } #rec ul li a:hover { text-decoration:underline; } #sidebar-right { width:270px; height:835px; float:right; margin:0 0 10px 0; } #sidebar-right div.adver { width:270px; height:200px; margin:0 0 10px 0; } #sidebar-right div.adver img { display:block; } #sidebar-right div.hot,#sidebar-right div.comm,#sidebar-right div.vote { border:1px solid #ccc; height:200px; margin:0 0 10px 0; } #sidebar-right div.vote { margin:0; } #sidebar-right div.vote h3 { padding:10px; text-align:center; font-size:14px; color:#369; border-bottom:1px dashed #ccc; width:80%; margin:5px auto; } #sidebar-right div.vote form label { display:block; padding:2px 0 2px 20px; } #sidebar-right div.vote form p { text-align:center; padding:5px; } #sidebar-right div.vote form p input { width:45px; height:20px; margin:0 3px; cursor:pointer; font-size:12px; } #sidebar-right ul { padding:3px 10px 0 10px; } #sidebar-right ul li { height:24px; line-height:24px; background:url(../Images/pointer.png) no-repeat left center; padding:0 0 0 10px; } #sidebar-right ul li em { float:right; font-style:normal; font-family:Tahoma; } #sidebar-right ul li a { color:#666; text-decoration:none; } #sidebar-right ul li a:hover { text-decoration:underline; } #picnews { width:678px; height:198px; border:1px solid #ccc; float:left; margin:0 0 10px 0; } #picnews dl { width:156px; float:left; padding:10px 0 0 11px; } #picnews dl dt { border:1px solid #999; padding:2px; } #picnews dl dt img { border:none; display:block; } #picnews dl dd { padding:5px; text-align:center; } #picnews dl dd a { color:#666; text-decoration:none; } #picnews dl dd a:hover { text-decoration:underline; } #newslist { width:680px; height:625px; float:left; margin:0 0 10px 0; } #newslist div.list { width:49%; height:306px; border:1px solid #ccc; float:left; } #newslist div.list h2 a { float:right; padding:0 10px 0 0; } #newslist div.list h2 a { color:green; text-decoration:none; } #newslist div.list h2 a:hover { text-decoration:underline; } #newslist ul { padding:8px 10px 0 10px; } #newslist ul li { height:24px; line-height:24px; background:url(../Images/arrow.png) no-repeat left center; padding:0 0 0 10px; } #newslist ul li em { float:right; font-style:normal; font-family:Tahoma; } #newslist ul li a { color:#666; text-decoration:none; } #newslist ul li a:hover { text-decoration:underline; } #newslist div.right { float:right; } #newslist div.bottom { margin:0 0 10px 0; }
zzgcms
ZGCMS/Public/Css/index.css
CSS
art
5,827
@CHARSET "UTF-8"; body,h1,h2,h3,p,form,ul,li,dl,dt,dd { padding:0; margin:0; } body { width:960px; margin:0 auto; background:#fff; font-size:12px; color:#666; } ul { list-style-type:none; } h2 { font-size:12px; height:26px; line-height:26px; text-indent:10px; color:#360; background:url(../Images/lbg.png); letter-spacing:1px; } #top { height:26px; background:url(../Images/top_bg.png); margin:0 0 10px 0; text-align:right; } #top a.adv { display:inline-block; padding:5px 10px 0 0; color:red; } #top a.user { display:inline-block; padding:5px 0 0 0; color:blue; } #header { height:80px; margin:0 0 10px 0; } #header h1 { width:250px; height:80px; background:url(../Images/logo.png) no-repeat; font-size:12px; float:left; } #header h1 a { height:80px; display:block; text-indent:-9999px; } #header div.adver { width:690px; height:80px; float:right; border:1px solid #ccc; } #header div.adver img { display:block; border:none; } #nav { height:35px; background:url(../Images/nav_bg.png); border:1px solid #ccc; border-bottom:none; } #nav ul { height:35px; line-height:35px; font-size:14px; font-weight:bold; padding:0 0 0 10px; } #nav ul li { display:inline; padding:0 10px; } #nav ul li a { color:#369; text-decoration:none; } #nav ul li a:hover { color:#f60; } #search { height:25px; margin:0 0 10px 0; border:1px solid #ccc; border-top:none; padding:5px 0 0 5px; } #search form { float:left; } #search form select { background:#fff; } #search form input.text { width:200px; height:16px; background:#fff; } #search form input.submit { width:45px; height:22px; font-size:12px; cursor:pointer; } #search strong { float:left; padding:5px 0 0 15px; } #search ul { float:left; padding:5px 0 0 0; } #search ul li { float:left; padding:0 8px 0 0; } #search ul li a { color:green; text-decoration:none; } #search ul li a:hover { color:#f60; } #link { width:958px; height:108px; border:1px solid #ccc; float:left; margin:0 0 10px 0; } #link span { float:right; font-weight:normal; padding:0 10px 0 0; } #link span a { color:#360; text-decoration:none; } #link span a:hover { color:#f60; } #link ul { padding:0 0 0 10px; height:30px; line-height:30px; border-bottom:1px dashed #999; width:98%; margin:0 auto; } #link ul li { display:inline; padding:5px 5px 0 5px; } #link ul li a { color:#666; text-decoration:none; } #link ul li a:hover { text-decoration:underline; } #link dl { padding:10px 0 0 8px; } #link dl dd { padding:0 8px; float:left; } #link dl dd img { border:none; display:block; } #footer { width:960px; height:40px; float:left; } #footer p { text-align:center; line-height:150%; font-family:Tahoma; color:#333; } #footer p span { color:#06f; } #page { text-align:center; padding:10px; clear:both; } #page a { border:1px solid #666; padding:2px 5px; margin:0 2px; color:#3b6ea5; text-decoration:none; } #page a:hover,#page span.me { color:#fff; border:1px solid #000; background:#000; text-decoration:none; } #page span.disabled { border:1px solid #ccc; padding:2px 5px; margin:0 2px; color:#ccc; } #page span.me { padding:2px 5px; margin:0 2px; }
zzgcms
ZGCMS/Public/Css/basic.css
CSS
art
3,407
@CHARSET "UTF-8"; #list { width:690px; min-height:600px; float:left; margin:0 0 10px 0; } #list h2 { border:1px solid #ccc; border-bottom:none; } #list h2 a { color:#360; text-decoration:none; } #list h2 a:hover { color:#f60; } #list dl { height:110px; margin:10px 0; border-bottom:1px dashed #ccc; } #list dl dt { width:150px; height:100px; float:left; } #list dl dt img { display:block; border:1px solid #ccc; } #list dl dd { width:528px; float:left; margin:0 0 0 10px; padding:0 0 5px 0; line-height:150%; } #list dl dd a { text-decoration:none; font-weight:bold; color:#369; font-size:14px; } #list dl dd a:hover { color:#f60; } #list span.red { color:red; } #list p.none{ padding:20px; text-align:center; border-bottom:1px dashed #ccc; } #sidebar { width:260px; min-height:600px; float:right; margin:0 0 10px 0; } #sidebar div.nav { border:1px solid #ccc; text-align:center; padding:0 0 5px 0; margin:0 0 10px 0; } #sidebar div.nav span { padding:5px 0 0 0; display:inline-block; } #sidebar div.nav strong { width:110px; height:25px; line-height:25px; border:1px solid #ccc; display:inline-block; margin:5px 0 0 0; } #sidebar div.nav strong a { font-weight:normal; text-decoration:none; color:#666; display:inline-block; width:110px; height:25px; background:#eef3f7; } #sidebar div.right { border:1px solid #ccc; margin:0 0 10px 0; } #sidebar div.right ul { padding:2px 10px 0 10px; } #sidebar div.right ul li { height:23px; line-height:23px; background:url(../Images/pointer.png) no-repeat left center; padding:0 0 0 10px; } #sidebar div.right ul li em { float:right; font-style:normal; font-family:Tahoma; } #sidebar div.right ul li a { color:#666; text-decoration:none; } #sidebar div.right ul li a:hover { text-decoration:underline; }
zzgcms
ZGCMS/Public/Css/list.css
CSS
art
1,935
@CHARSET "UTF-8"; #cast { margin:0 0 10px 0; border:1px solid #ccc; } #cast h2 { } #cast h2 a { color:#360; text-decoration:none; } #cast h2 a:hover { color:#f60; } #cast table { width:80%; margin:15px auto; background:#ccc; } #cast table caption { font-size:22px; color:#333; padding:0 0 10px 0; font-weight:bold; } #cast table th,#cast table td { padding:10px; background:#fff; text-align:center; }
zzgcms
ZGCMS/Public/Css/cast.css
CSS
art
446
@CHARSET "UTF-8"; #reg { width:100%; float:left; margin:0 0 10px 0; } #reg h2 { border:1px solid #ccc; border-bottom:none; text-align:center; } #reg h2 a { color:#360; text-decoration:none; } #reg h2 a:hover { color:#f60; } #reg form { border:1px solid #ccc; padding:15px 0; } #reg form dl { padding-left:250px; } #reg form dl dd { padding:5px 0; } #reg form dl dd span.red { color:red; } #reg form dl dd input.text,#reg form dl dd select { width:220px; height:22px; border:1px solid #999; background:#eee; } #reg form dl dd img.face { margin:0 0 0 60px; } #reg form dl dd img.code { cursor:pointer; margin:0 0 0 60px; } #reg form dl dd input.submit{ cursor:pointer; margin:0 0 0 60px; }
zzgcms
ZGCMS/Public/Css/reg.css
CSS
art
761
@CHARSET "UTF-8"; #details { width:690px; min-height:600px; float:left; margin:0 0 10px 0; } #details h2 { border:1px solid #ccc; border-bottom:none; } #details h2 a { color:#360; text-decoration:none; } #details h2 a:hover { color:#f60; } #details h3 { text-align:center; color:#333; padding:20px 0 0 0; font-size:22px; } #details div.d1 { text-align:center; padding:10px; } #details div.d2 { padding:10px; margin:10px; background:#ffffee; border:1px solid #ccc; line-height:150%; } #details div.d3 { padding:20px 10px; line-height:250%; } #details div.d4 { padding:8px; border:1px dashed #ccc; } #details div.d5 { margin:10px 0; padding:8px; border:1px solid #ccc; clear:both; } #details div.d5 p { margin:10px 0; } #details div.d5 p textarea { width:650px; height:150px; background:#eee; border:1px dashed #999; } #details div.d5 p.red { color:red; } #details div.d5 p input.text { width:80px; height:20px; border:1px dashed #999; background:#eee; } #details div.d5 p input.submit { width:80px; height:25px; cursor:pointer; } #details div.d5 p img.code { width:78px; height:30px; position:relative; top:10px; cursor:pointer; } #details div.d6 { width:688px; margin:10px 0; border:1px solid #ccc; float:left; } #details div.d6 h2 { border:none; } #details div.d6 h2 a { float:right; font-weight:normal; padding-right:10px; color:#666; } #details div.d6 h2 a span { color:red; } #details div.d6 dl { width:670px; margin:10px 0; float:left; border-bottom:1px dashed #ccc; margin-left:8px; } #details div.d6 dl dt { float:left; } #details div.d6 dl dd { float:right; width:585px; padding:0 0 10px 10px; } #details div.d6 dl dd span { color:#06f; } #details div.d6 dl dd.info { font-size:12px; line-height:150%; } #details div.d6 dl dd.bottom { text-align:right; } #details div.d6 dl dd em { float:right; font-style:normal; } #sidebar { width:260px; min-height:600px; float:right; margin:0 0 10px 0; } #sidebar div.nav { border:1px solid #ccc; text-align:center; padding:0 0 5px 0; margin:0 0 10px 0; } #sidebar div.nav span { padding:5px 0 0 0; display:inline-block; } #sidebar div.nav strong { width:110px; height:25px; line-height:25px; border:1px solid #ccc; display:inline-block; margin:5px 0 0 0; } #sidebar div.nav strong a { font-weight:normal; text-decoration:none; color:#666; display:inline-block; width:110px; height:25px; background:#eef3f7; } #sidebar div.right { border:1px solid #ccc; margin:0 0 10px 0; } #sidebar div.right ul { padding:2px 10px 0 10px; } #sidebar div.right ul li { height:23px; line-height:23px; background:url(../Images/pointer.png) no-repeat left center; padding:0 0 0 10px; } #sidebar div.right ul li em { float:right; font-style:normal; font-family:Tahoma; } #sidebar div.right ul li a { color:#666; text-decoration:none; } #sidebar div.right ul li a:hover { text-decoration:underline; }
zzgcms
ZGCMS/Public/Css/details.css
CSS
art
3,126
window.onload = function () { var title = document.getElementById('title'); var ol = document.getElementsByTagName('ol'); var a = ol[0].getElementsByTagName('a'); for (i=0;i<a.length;i++) { a[i].className = null; if (title.innerHTML == a[i].innerHTML) { a[i].className = 'selected'; } } }; //验证等级表单 function checkForm() { var fm = document.add; if (fm.level_name.value == '' || fm.level_name.value.length < 2 || fm.level_name.value.length > 20) { alert('警告:等级名称不得为空并且不得小于两位并且不得大于20位!'); fm.level_name.focus(); return false; } if (fm.level_info.value.length > 200) { alert('警告:等级描述不得大于200位!'); fm.level_info.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/admin_level.js
JavaScript
art
819
window.onload = function () { var title = document.getElementById('title'); var ol = document.getElementsByTagName('ol'); var a = ol[0].getElementsByTagName('a'); for (i=0;i<a.length;i++) { a[i].className = null; if (title.innerHTML == a[i].innerHTML) { a[i].className = 'selected'; } } }; //验证等级表单 function checkForm() { var fm = document.add; if (fm.name.value == '' || fm.name.value.length < 2 || fm.name.value.length > 100) { alert('警告:权限名称不得为空并且不得小于两位并且不得大于100位!'); fm.name.focus(); return false; } if (fm.info.value.length > 200) { alert('警告:权限描述不得大于200位!'); fm.info.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/admin_premission.js
JavaScript
art
785
//验证登录 function checkLogin() { var fm = document.login; if (fm.admin_user.value == '' || fm.admin_user.value.length < 2 || fm.admin_user.value.length > 20) { alert('警告:用户名不得为空并且不得小于两位并且不得大于20位!'); fm.admin_user.focus(); return false; } if (fm.admin_pass.value == '' || fm.admin_pass.value.length < 6 ) { alert('警告:密码不得为空并且不得小于六位!'); fm.admin_pass.focus(); return false; } if (fm.code.value.length != 4 ) { alert('警告:验证码必须为四位!'); fm.code.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/admin_login.js
JavaScript
art
641
$(document).ready(function(){ var permission = $("#allpermission").val(); var permissionArr = permission.split(','); for(i=0;i<permissionArr.length;i++) $(":checkbox").each(function(){ if(this.value == permissionArr[i]) $(this).attr('checked','true'); }); });
zzgcms
ZGCMS/Public/Js/admin_level_checkbox.js
JavaScript
art
290
function admin_top_nav(j) { for (i=1;i<5;i++) { document.getElementById('nav'+i).style.backgroundPosition = 'left bottom'; document.getElementById('nav'+i).style.color = '#fff'; } document.getElementById('nav'+j).style.backgroundPosition = 'right bottom'; document.getElementById('nav'+j).style.color = '#3b6ea5'; }
zzgcms
ZGCMS/Public/Js/admin_top_nav.js
JavaScript
art
330
var header = []; header[1] = { 'title' : '头部广告3', 'pic' : '/ZGCMS/Public/Uploads/header_132eaf42e52cbd0978e733fbd6c9a17a.png', 'link' : 'http://www.tmall.com' }; header[2] = { 'title' : '头部广告2', 'pic' : '/ZGCMS/Public/Uploads/header_0254b2e8abd160195738ef029d94e99f.png', 'link' : 'http://www.tmall.com' }; header[3] = { 'title' : '中国一箭双星成功发射', 'pic' : '/ZGCMS/Public/Uploads/header_b61557ad8a8bd7bd097014d16f4c91bd.png', 'link' : 'http://www.163.com' }; var i = Math.floor(Math.random()*3+1); document.write('<a href="'+header[i].link+'" target="_blank" title="'+header[i].title+'"><img src="'+header[i].pic+'"></a>');
zzgcms
ZGCMS/Public/Js/header_adver.js
JavaScript
art
681
$(document).ready(function(){ var level = $("#level").val(); var a = $("#sel_lev").find("[value="+ level + "]").attr("selected","selected"); });
zzgcms
ZGCMS/Public/Js/admin_manage_select.js
JavaScript
art
153
//验证评论列表 function checkComment() { var fm = document.comment; if (fm.content.value == '' || fm.content.value.length > 255) { alert('警告:评论内容不得为空并且不得大于255位!'); fm.content.focus(); return false; } if (fm.code.value.length != 4 ) { alert('警告:验证码必须为四位!'); fm.code.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/details.js
JavaScript
art
410
window.onload = function () { /* var level = document.getElementById('level'); var options = document.getElementsByTagName('option'); if (level) { for(i=0;i<options.length;i++) { if (options[i].value == level.value) { options[i].setAttribute('selected','selected'); } } } */ var title = document.getElementById('title'); var ol = document.getElementsByTagName('ol'); var a = ol[0].getElementsByTagName('a'); for (i=0;i<a.length;i++) { a[i].className = null; if (title.innerHTML == a[i].innerHTML) { a[i].className = 'selected'; } } }; //验证Manageupdate function checkUpdateForm() { var fm = document.update; if (fm.admin_pass.value != '') { if (fm.admin_pass.value.length < 6) { alert('警告:密码修改不得小于六位!'); fm.admin_pass.focus(); return false; } } return true; } //验证Manageadd function checkAddForm() { var fm = document.add; if (fm.admin_user.value == '' || fm.admin_user.value.length < 2 || fm.admin_user.length > 20) { alert('警告:用户名不得为空并且不得小于两位并且不得大于20位!'); fm.admin_user.focus(); return false; } if (fm.admin_pass.value == '' || fm.admin_pass.value.length < 6) { alert('警告:密码不得为空并且不得小于六位!'); fm.admin_pass.focus(); return false; } if (fm.admin_pass.value != fm.admin_notpass.value) { alert('警告:密码与密码提示不一致!'); fm.admin_notpass.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/admin_manage.js
JavaScript
art
1,565
window.onload = function () { var title = document.getElementById('title'); var ol = document.getElementsByTagName('ol'); var a = ol[0].getElementsByTagName('a'); for (i=0;i<a.length;i++) { a[i].className = null; if (title.innerHTML == a[i].innerHTML) { a[i].className = 'selected'; } } }; function checkForm() { var fm = document.add; if (fm.nav_name.value == '' || fm.nav_name.value.length < 2 || fm.nav_name.value.length > 20) { alert('警告:导航名称不得为空并且不得小于两位并且不得大于20位!'); fm.nav_name.focus(); return false; } if (fm.nav_info.value.length > 200) { alert('警告:导航描述不得大于200位!'); fm.nav_info.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/admin_nav.js
JavaScript
art
765
window.onload = function () { var title = document.getElementById('title'); var ol = document.getElementsByTagName('ol'); var a = ol[0].getElementsByTagName('a'); for (i=0;i<a.length;i++) { a[i].className = null; if (title.innerHTML == a[i].innerHTML) { a[i].className = 'selected'; } } //设置ckeditor CKEDITOR.replace('TextArea1',{ uiColor: '#AADC6E' }); }; function centerWindow(url, name, width, height) { var left = (screen.width - width) / 2; var top = (screen.height - height) / 2 - 50; window.open(url, name, 'width='+width+',height='+height+',top='+top+',left='+left); } //验证addContent function checkAddContent() { var fm = document.content; if (fm.title.value == '' || fm.title.value.length < 2 || fm.title.value.length > 50) { alert('警告:标题不得为空并且不得小于两位并且不得大于50位!'); fm.title.focus(); return false; } if (fm.nav.value == '') { alert('警告:必须选择一个栏目!'); fm.nav.focus(); return false; } if (fm.tag.value.length > 30) { alert('警告:tag标签不得大于30位!'); fm.tag.focus(); return false; } if (fm.keyword.value.length > 30) { alert('警告:关键字不得大于30位!'); fm.keyword.focus(); return false; } if (fm.source.value.length > 20) { alert('警告:文章来源不得大于20位!'); fm.source.focus(); return false; } if (fm.author.value.length > 10) { alert('警告:作者不得大于10位!'); fm.author.focus(); return false; } if (fm.info.value.length > 200) { alert('警告:内容摘要不得大于200位!'); fm.info.focus(); return false; } if (CKEDITOR.instances.TextArea1.getData() == '') { alert('警告:详细内容不得为空!'); CKEDITOR.instances.TextArea1.focus(); return false; } if (isNaN(fm.count.value)) { alert('警告:浏览次数必须是数字!'); fm.count.focus(); return false; } if (isNaN(fm.gold.value)) { alert('警告:消费金币必须是数字!'); fm.gold.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/admin_article.js
JavaScript
art
2,157
window.onload = function () { var title = document.getElementById('title'); var ol = document.getElementsByTagName('ol'); var a = ol[0].getElementsByTagName('a'); for (i=0;i<a.length;i++) { a[i].className = null; if (title.innerHTML == a[i].innerHTML) { a[i].className = 'selected'; } } }; function link(type) { var logo = document.getElementById('logo'); switch (type) { case 1 : logo.style.display = 'none'; break; case 2 : logo.style.display = 'block'; break; } } function checkLink() { var fm = document.friendlink; if (fm.webname.value == '' || fm.webname.value.length > 20) { alert('警告:网站名称不得为空并且不得大于20位!'); fm.webname.focus(); return false; } if (fm.weburl.value == '' || fm.weburl.value.length > 100) { alert('警告:网站地址不得为空并且不得大于100位!'); fm.weburl.focus(); return false; } if (fm.type[1].checked) { if (fm.logourl.value == '' || fm.logourl.value.length > 100) { alert('警告:Logo地址不得为空并且不得大于100位!'); fm.logourl.focus(); return false; } } if (fm.user.value.length > 20) { alert('警告:站长名不得大于20位!'); fm.user.focus(); return false; } if (fm.code.value.length != 4 ) { alert('警告:验证码必须为四位!'); fm.code.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/admin_link.js
JavaScript
art
1,460
window.onload = function () { var title = document.getElementById('title'); var ol = document.getElementsByTagName('ol'); var a = ol[0].getElementsByTagName('a'); for (i=0;i<a.length;i++) { a[i].className = null; if (title.innerHTML == a[i].innerHTML) { a[i].className = 'selected'; } } }; function centerWindow(url, name, width, height) { var left = (screen.width - width) / 2; var top = (screen.height - height) / 2 - 50; window.open(url, name, 'width='+width+',height='+height+',top='+top+',left='+left); } function adver(type) { var fm = document.content; if (fm.adv.value == type) return; var thumbnail = document.getElementById('thumbnail'); var up = document.getElementById('up'); fm.thumbnail.value = ''; fm.pic.src = ''; fm.pic.style.display = 'none'; switch (type) { case 1 : thumbnail.style.display = 'none'; up.innerHTML = ''; fm.adv.value = 1; break; case 2 : thumbnail.style.display = 'block'; up.innerHTML = "<input type=\"button\" value=\"上传头部广告690x80\" onclick=\"centerWindow('/ZGCMS/admin.php/Adver/showUploadFile/type/header','upfile','400','100')\" />"; fm.adv.value = 2; break; case 3 : thumbnail.style.display = 'block'; up.innerHTML = "<input type=\"button\" value=\"上传侧栏广告270x200\" onclick=\"centerWindow('/ZGCMS/admin.php/Adver/showUploadFile/type/siderbar','upfile','400','100')\" />"; fm.adv.value = 3; break; } } //checkAdver function checkAdver() { var fm = document.content; if (fm.title.value == '' || fm.title.value.length < 2 || fm.title.value.length > 50) { alert('警告:标题不得为空并且不得小于两位并且不得大于50位!'); fm.title.focus(); return false; } if (fm.link.value == '') { alert('警告:广告链接不得为空!'); fm.link.focus(); return false; } if (fm.type[1].checked || fm.type[2].checked) { if (fm.thumbnail.value == '') { alert('警告:广告图片不得为空!'); fm.thumbnail.focus(); return false; } } if (fm.info.value.length > 200 ) { alert('警告:描述不得大于200位!'); fm.info.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/admin_adver.js
JavaScript
art
2,264
window.onload = function () { var title = document.getElementById('title'); var ol = document.getElementsByTagName('ol'); var a = ol[0].getElementsByTagName('a'); for (i=0;i<a.length;i++) { a[i].className = null; if (title.innerHTML == a[i].innerHTML) { a[i].className = 'selected'; } } }; //验证等级表单 function checkForm() { var fm = document.add; if (fm.title.value == '' || fm.title.value.length < 2 || fm.title.value.length > 20) { alert('警告:标题不得为空并且不得小于两位并且不得大于20位!'); fm.title.focus(); return false; } if (fm.info.value.length > 200) { alert('警告:描述不得大于200位!'); fm.info.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/admin_vote.js
JavaScript
art
773
var siderbar = []; siderbar[1] = { 'title' : '侧边栏广告3', 'pic' : '/ZGCMS/Public/Uploads/siderbar_0dfc52057eb1ddacf97a86acaec26296.png', 'link' : 'http://www.163.com' }; siderbar[2] = { 'title' : '侧边栏广告2', 'pic' : '/ZGCMS/Public/Uploads/siderbar_8fb806dfbcf56095e6f442595b85ebbb.png', 'link' : 'http://www.tmall.com' }; siderbar[3] = { 'title' : '侧边栏广告', 'pic' : '/ZGCMS/Public/Uploads/siderbar_21e00120a509a8536155beaf549ca70c.png', 'link' : 'http://www.tmall.com' }; var i = Math.floor(Math.random()*3+1); document.write('<a href="'+siderbar[i].link+'" target="_blank" title="'+siderbar[i].title+'"><img src="'+siderbar[i].pic+'"></a>');
zzgcms
ZGCMS/Public/Js/siderbar_adver.js
JavaScript
art
692
window.onload = function () { var title = document.getElementById('title'); var ol = document.getElementsByTagName('ol'); var a = ol[0].getElementsByTagName('a'); for (i=0;i<a.length;i++) { a[i].className = null; if (title.innerHTML == a[i].innerHTML) { a[i].className = 'selected'; } } }; function centerWindow(url, name, width, height) { var left = (screen.width - width) / 2; var top = (screen.height - height) / 2 - 50; window.open(url, name, 'width='+width+',height='+height+',top='+top+',left='+left); } //验证addContent function checkAddRotatain() { var fm = document.content; if (fm.thumbnail.value == '') { alert('警告:轮播图不得为空!'); fm.thumbnail.focus(); return false; } if (fm.link.value == '') { alert('警告:链接不得为空!'); fm.link.focus(); return false; } if (fm.title.value.length > 20) { alert('警告:标题不得大于20位!'); fm.title.focus(); return false; } if (fm.info.value.length > 200) { alert('警告:简介不得大于200位!'); fm.info.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/admin_rotation.js
JavaScript
art
1,154
window.onload = function () { var title = document.getElementById('title'); var ol = document.getElementsByTagName('ol'); var a = ol[0].getElementsByTagName('a'); for (i=0;i<a.length;i++) { a[i].className = null; if (title.innerHTML == a[i].innerHTML) { a[i].className = 'selected'; } } }; //选择头像 function sface() { var fm = document.reg; var index = fm.face.selectedIndex; fm.faceimg.src = '/ZGCMS/Public/Images/'+fm.face.options[index].value; } //验证等级表单 function checkForm() { var fm = document.add; if (fm.level_name.value == '' || fm.level_name.value.length < 2 || fm.level_name.value.length > 20) { alert('警告:等级名称不得为空并且不得小于两位并且不得大于20位!'); fm.level_name.focus(); return false; } if (fm.level_info.value.length > 200) { alert('警告:等级描述不得大于200位!'); fm.level_info.focus(); return false; } return true; } //验证修改 function checkUpdate() { var fm = document.reg; if (fm.pass.value != '') { if (fm.pass.value.length < 6) { alert('警告:密码不得小于6位!'); fm.pass.focus(); return false; } } if (!/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/.test(fm.email.value)) { alert('邮件格式不正确'); fm.email.value = ''; //清空 fm.email.focus(); //将焦点以至表单字段 return false; } return true; } //验证登录 function checkReg() { var fm = document.reg; if (fm.user.value == '' || fm.user.value.length < 2 || fm.user.value.length > 20) { alert('警告:用户名不得为空并且不得小于两位并且不得大于20位!'); fm.user.focus(); return false; } if (fm.pass.value.length < 6) { alert('警告:密码不得小于6位!'); fm.pass.focus(); return false; } if (fm.pass.value != fm.notpass.value) { alert('警告:密码和密码确认不一致!'); fm.notpass.focus(); return false; } if (!/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/.test(fm.email.value)) { alert('邮件格式不正确'); fm.email.value = ''; //清空 fm.email.focus(); //将焦点以至表单字段 return false; } if (fm.code.value.length != 4 ) { alert('警告:验证码必须为四位!'); fm.code.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/admin_user.js
JavaScript
art
2,353
//选择头像 function sface() { var fm = document.reg; var index = fm.face.selectedIndex; fm.faceimg.src = '/ZGCMS/Public/Images/'+fm.face.options[index].value; } //验证登录 function checkReg() { var fm = document.reg; if (fm.user.value == '' || fm.user.value.length < 2 || fm.user.value.length > 20) { alert('警告:用户名不得为空并且不得小于两位并且不得大于20位!'); fm.user.focus(); return false; } if (fm.pass.value.length < 6) { alert('警告:密码不得小于6位!'); fm.pass.focus(); return false; } if (fm.pass.value != fm.notpass.value) { alert('警告:密码和密码确认不一致!'); fm.notpass.focus(); return false; } if (!/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/.test(fm.email.value)) { alert('邮件格式不正确'); fm.email.value = ''; //清空 fm.email.focus(); //将焦点以至表单字段 return false; } if (fm.code.value.length != 4 ) { alert('警告:验证码必须为四位!'); fm.code.focus(); return false; } return true; } function checkLogin() { var fm = document.login; if (fm.user.value == '' || fm.user.value.length < 2 || fm.user.value.length > 20) { alert('警告:用户名不得为空并且不得小于两位并且不得大于20位!'); fm.user.focus(); return false; } if (fm.pass.value.length < 6) { alert('警告:密码不得小于6位!'); fm.pass.focus(); return false; } if (fm.code.value.length != 4 ) { alert('警告:验证码必须为四位!'); fm.code.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/reg.js
JavaScript
art
1,626
var text = []; text[1] = { 'title' : '文字广告三', 'link' : 'http://www.tmall.com' }; text[2] = { 'title' : '文字广告2', 'link' : 'http://www.163.com' }; text[3] = { 'title' : '文字广告', 'link' : 'http://www.baidu.com' }; var i = Math.floor(Math.random()*3+1); document.write('<a href="'+text[i].link+'" class="adv" target="_blank">'+text[i].title+'</a>');
zzgcms
ZGCMS/Public/Js/text_adver.js
JavaScript
art
392
function link(type) { var logo = document.getElementById('logo'); switch (type) { case 1 : logo.style.display = 'none'; break; case 2 : logo.style.display = 'block'; break; } } function checkLink() { var fm = document.friendlink; if (fm.webname.value == '' || fm.webname.value.length > 20) { alert('警告:网站名称不得为空并且不得大于20位!'); fm.webname.focus(); return false; } if (fm.weburl.value == '' || fm.weburl.value.length > 100) { alert('警告:网站地址不得为空并且不得大于100位!'); fm.weburl.focus(); return false; } if (fm.type[1].checked) { if (fm.logourl.value == '' || fm.logourl.value.length > 100) { alert('警告:Logo地址不得为空并且不得大于100位!'); fm.logourl.focus(); return false; } } if (fm.user.value.length > 20) { alert('警告:站长名不得大于20位!'); fm.user.focus(); return false; } if (fm.code.value.length != 4 ) { alert('警告:验证码必须为四位!'); fm.code.focus(); return false; } return true; }
zzgcms
ZGCMS/Public/Js/link.js
JavaScript
art
1,123
/* Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ body { /* Font */ font-family: Arial, Verdana, sans-serif; font-size: 12px; /* Text color */ color: #222; /* Remove the background color to make it transparent */ background-color: #fff; } ol,ul,dl { /* IE7: reset rtl list margin. (#7334) */ *margin-right:0px; /* preserved spaces for list items with text direction other than the list. (#6249,#8049)*/ padding:0 40px; }
zzgcms
ZGCMS/Public/Ckeditor/contents.css
CSS
art
559
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!-- Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Installation Guide - CKEditor</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <style type="text/css"> h3 { border-bottom: 1px solid #AAAAAA; } pre { background-color: #F9F9F9; border: 1px dashed #2F6FAB; padding: 1em; line-height: 1.1em; } #footer hr { margin: 10px 0 15px 0; height: 1px; border: solid 1px gray; border-bottom: none; } #footer p { margin: 0 10px 10px 10px; float: left; } #footer #copy { float: right; } </style> </head> <body> <h1> CKEditor Installation Guide</h1> <h3> What&#39;s CKEditor?</h3> <p> CKEditor is a text editor to be used inside web pages. It&#39;s not a replacement for desktop text editors like Word or OpenOffice, but a component to be used as part of web applications and web sites.</p> <h3> Installation</h3> <p> Installing CKEditor is an easy task. Just follow these simple steps:</p> <ol> <li><strong>Download</strong> the latest version of the editor from our web site: <a href="http://ckeditor.com">http://ckeditor.com</a>. You should have already completed this step, but be sure you have the very latest version.</li> <li><strong>Extract</strong> (decompress) the downloaded file into the root of your web site.</li> </ol> <p> <strong>Note:</strong> CKEditor is by default installed in the &quot;ckeditor&quot; folder. You can place the files in whichever you want though.</p> <h3> Checking Your Installation </h3> <p> The editor comes with a few sample pages that can be used to verify that installation proceeded properly. Take a look at the <a href="_samples">_samples</a> directory.</p> <p> To test your installation, just call the following page at your web site:</p> <pre> http://&lt;your site&gt;/&lt;CKEditor installation path&gt;/_samples/index.html For example: http://www.example.com/ckeditor/_samples/index.html</pre> <h3> Documentation</h3> <p> The full editor documentation is available online at the following address:<br /> <a href="http://docs.cksource.com/ckeditor">http://docs.cksource.com/ckeditor</a></p> <div id="footer"> <hr /> <p> CKEditor - The text editor for Internet - <a href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2012, <a href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
zzgcms
ZGCMS/Public/Ckeditor/INSTALL.html
HTML
art
2,859
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <!-- Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license --> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript"> function gup( name ) { name = name.replace( /[\[]/, '\\\[' ).replace( /[\]]/, '\\\]' ) ; var regexS = '[\\?&]' + name + '=([^&#]*)' ; var regex = new RegExp( regexS ) ; var results = regex.exec( window.location.href ) ; if ( results ) return results[ 1 ] ; else return '' ; } var interval; function sendData2Master() { var destination = window.parent.parent ; try { if ( destination.XDTMaster ) { var t = destination.XDTMaster.read( [ gup( 'cmd' ), gup( 'data' ) ] ) ; window.clearInterval( interval ) ; } } catch (e) {} } function onLoad() { interval = window.setInterval( sendData2Master, 100 ); } </script> </head> <body onload="onLoad()"><p></p></body> </html>
zzgcms
ZGCMS/Public/Ckeditor/plugins/wsc/dialogs/ciframe.html
HTML
art
1,120
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <!-- Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license --> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript"> function doLoadScript( url ) { if ( !url ) return false ; var s = document.createElement( "script" ) ; s.type = "text/javascript" ; s.src = url ; document.getElementsByTagName( "head" )[ 0 ].appendChild( s ) ; return true ; } var opener; function tryLoad() { opener = window.parent; // get access to global parameters var oParams = window.opener.oldFramesetPageParams; // make frameset rows string prepare var sFramesetRows = ( parseInt( oParams.firstframeh, 10 ) || '30') + ",*," + ( parseInt( oParams.thirdframeh, 10 ) || '150' ) + ',0' ; document.getElementById( 'itFrameset' ).rows = sFramesetRows ; // dynamic including init frames and crossdomain transport code // from config sproxy_js_frameset url var addScriptUrl = oParams.sproxy_js_frameset ; doLoadScript( addScriptUrl ) ; } </script> </head> <frameset id="itFrameset" onload="tryLoad();" border="0" rows="30,*,*,0"> <frame scrolling="no" framespacing="0" frameborder="0" noresize="noresize" marginheight="0" marginwidth="2" src="" name="navbar"></frame> <frame scrolling="auto" framespacing="0" frameborder="0" noresize="noresize" marginheight="0" marginwidth="0" src="" name="mid"></frame> <frame scrolling="no" framespacing="0" frameborder="0" noresize="noresize" marginheight="1" marginwidth="1" src="" name="bot"></frame> <frame scrolling="no" framespacing="0" frameborder="0" noresize="noresize" marginheight="1" marginwidth="1" src="" name="spellsuggestall"></frame> </frameset> </html>
zzgcms
ZGCMS/Public/Ckeditor/plugins/wsc/dialogs/tmpFrameset.html
HTML
art
1,935
/* Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ CKEDITOR.plugins.setLang('placeholder','cy',{placeholder:{title:"Priodweddau'r Daliwr Geiriau",toolbar:'Creu Daliwr Geiriau',text:'Testun y Daliwr Geiriau',edit:"Golygu'r Dailwr Geiriau",textMissing:"Mae'n rhaid i'r daliwr geiriau gynnwys testun."}});
zzgcms
ZGCMS/Public/Ckeditor/plugins/placeholder/lang/cy.js
JavaScript
art
407
/* Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ CKEDITOR.plugins.setLang('placeholder','tr',{placeholder:{title:'Yer tutucu özellikleri',toolbar:'Yer tutucu oluşturun',text:'Yer tutucu metini',edit:'Yer tutucuyu düzenle',textMissing:'Yer tutucu metin içermelidir.'}});
zzgcms
ZGCMS/Public/Ckeditor/plugins/placeholder/lang/tr.js
JavaScript
art
380
/* Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ CKEDITOR.plugins.setLang('placeholder','nb',{placeholder:{title:'Egenskaper for plassholder',toolbar:'Opprett plassholder',text:'Tekst for plassholder',edit:'Rediger plassholder',textMissing:'Plassholderen må inneholde tekst.'}});
zzgcms
ZGCMS/Public/Ckeditor/plugins/placeholder/lang/nb.js
JavaScript
art
387
/* Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ CKEDITOR.plugins.setLang('placeholder','fr',{placeholder:{title:"Propriétés de l'Espace réservé",toolbar:"Créer l'Espace réservé",text:"Texte de l'Espace réservé",edit:"Modifier l'Espace réservé",textMissing:"L'Espace réservé doit contenir du texte."}});
zzgcms
ZGCMS/Public/Ckeditor/plugins/placeholder/lang/fr.js
JavaScript
art
423