Merge pull request #2098 from opentx/bsongis/move_to_STM32F4

Bsongis/move to stm32 f4
This commit is contained in:
Andre Bernet
2015-02-21 12:20:00 +04:00
72 changed files with 8356 additions and 9993 deletions
@@ -23,6 +23,7 @@
#define PCBTARANIS #define PCBTARANIS
#define CPUARM #define CPUARM
#define CPUSTM32 #define CPUSTM32
#define STM32F40_41xxx
#define GUI #define GUI
#define HELI #define HELI
#define SPLASH #define SPLASH
@@ -1,16 +1,39 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsConfig.h * @file OsConfig.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief This file use by user to configuration CooCox CoOS. * @brief This file use by user to configuration CooCox CoOS.
* @note Ensure you have knew every item before modify this file. * @note Ensure you have knew every item before modify this file.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 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.
* *
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
******************************************************************************* *******************************************************************************
*/ */
@@ -37,7 +60,11 @@ Max number of tasks that can be running.
/*!< /*!<
Idle task stack size(word). Idle task stack size(word).
*/ */
#if CFG_CHIP_TYPE == 3
#define CFG_IDLE_STACK_SIZE (58)
#else
#define CFG_IDLE_STACK_SIZE (25) #define CFG_IDLE_STACK_SIZE (25)
#endif
/*!< /*!<
System frequency (Hz). System frequency (Hz).
+245 -222
View File
@@ -1,222 +1,245 @@
/** /**
******************************************************************************* *******************************************************************************
* @file CoOS.h * @file CoOS.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief API header file of CooCox CoOS. * @brief API header file of CooCox CoOS.
* @details This file including all API functions's declare of CooCox CoOS. * @details This file including all API functions's declare of CooCox CoOS.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
#ifndef _CCRTOS_H * * Redistributions in binary form must reproduce the above copyright
#define _CCRTOS_H * notice, this list of conditions and the following disclaimer in the
#include "OsConfig.h" * documentation and/or other materials provided with the distribution.
/*---------------------------- Type Define ----------------------------------*/ * * Neither the name of the <ORGANIZATION> nor the names of its
typedef signed char S8; * contributors may be used to endorse or promote products derived
typedef unsigned char U8; * from this software without specific prior written permission.
typedef short S16; *
typedef unsigned short U16; * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
typedef int S32; * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
typedef unsigned int U32; * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
typedef long long S64; * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
typedef unsigned long long U64; * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
typedef unsigned char BIT; * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
typedef unsigned char BOOL; * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
typedef unsigned int OS_STK; * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
typedef U8 OS_TID; * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
typedef U8 OS_TCID; * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
typedef U8 OS_MutexID; * THE POSSIBILITY OF SUCH DAMAGE.
typedef U8 OS_EventID; *
typedef U8 OS_FlagID; * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
typedef U8 OS_MMID; *******************************************************************************
typedef U8 StatusType; */
typedef U16 OS_VER;
typedef void (*FUNCPtr)(void*); #ifndef _CCRTOS_H
typedef void (*vFUNCPtr)(void); #define _CCRTOS_H
#include "../OsConfig.h"
/*---------------------------- Type Define ----------------------------------*/
/*---------------------------- Constant Define -------------------------------*/ typedef signed char S8;
#ifndef Co_NULL typedef unsigned char U8;
#define Co_NULL ((void *)0) typedef short S16;
#endif typedef unsigned short U16;
typedef int S32;
#ifndef Co_FALSE typedef unsigned int U32;
#define Co_FALSE (0) typedef long long S64;
#endif typedef unsigned long long U64;
typedef unsigned char BIT;
#ifndef Co_TRUE typedef unsigned char BOOL;
#define Co_TRUE (1) typedef unsigned int OS_STK;
#endif typedef U8 OS_TID;
typedef U8 OS_TCID;
typedef U8 OS_MutexID;
/*---------------------------- Error Codes ---------------------------------*/ typedef U8 OS_EventID;
#define E_CREATE_FAIL (StatusType)-1 typedef U8 OS_FlagID;
#define E_OK (StatusType)0 typedef U8 OS_MMID;
#define E_INVALID_ID (StatusType)1 typedef U8 StatusType;
#define E_INVALID_PARAMETER (StatusType)2 typedef U16 OS_VER;
#define E_CALL (StatusType)3 typedef void (*FUNCPtr)(void*);
#define E_TASK_WAITING (StatusType)4 typedef void (*vFUNCPtr)(void);
#define E_TIMEOUT (StatusType)5
#define E_SEM_FULL (StatusType)6
#define E_MBOX_FULL (StatusType)7 /*---------------------------- Constant Define -------------------------------*/
#define E_QUEUE_FULL (StatusType)8 #ifndef Co_NULL
#define E_SEM_EMPTY (StatusType)9 #define Co_NULL ((void *)0)
#define E_MBOX_EMPTY (StatusType)10 #endif
#define E_QUEUE_EMPTY (StatusType)11
#define E_FLAG_NOT_READY (StatusType)12 #ifndef Co_FALSE
#define E_ALREADY_IN_WAITING (StatusType)13 #define Co_FALSE (0)
#define E_TASK_NOT_WAITING (StatusType)14 #endif
#define E_TASK_WAIT_OTHER (StatusType)15
#define E_EXCEED_MAX_NUM (StatusType)16 #ifndef Co_TRUE
#define E_NOT_IN_DELAY_LIST (StatusType)17 #define Co_TRUE (1)
#define E_SEV_REQ_FULL (StatusType)18 #endif
#define E_NOT_FREE_ALL (StatusType)19
#define E_PROTECTED_TASK (StatusType)20
#define E_OS_IN_LOCK (StatusType)21 /*---------------------------- Error Codes ---------------------------------*/
#define E_CREATE_FAIL (StatusType)-1
#define E_OK (StatusType)0
/*---------------------------- Wait Opreation type --------------------------*/ #define E_INVALID_ID (StatusType)1
#define OPT_WAIT_ALL 0 /*!< Wait for all flags. */ #define E_INVALID_PARAMETER (StatusType)2
#define OPT_WAIT_ANY 1 /*!< Wait for any one of flags. */ #define E_CALL (StatusType)3
#define OPT_WAIT_ONE 2 /*!< Waot for one flag. */ #define E_TASK_WAITING (StatusType)4
#define E_TIMEOUT (StatusType)5
#define E_SEM_FULL (StatusType)6
/*---------------------------- Delete Opreation type ------------------------*/ #define E_MBOX_FULL (StatusType)7
#define OPT_DEL_NO_PEND 0 /*!< Delete when no task waitting for */ #define E_QUEUE_FULL (StatusType)8
#define OPT_DEL_ANYWAY 1 /*!< Delete always. */ #define E_SEM_EMPTY (StatusType)9
#define E_MBOX_EMPTY (StatusType)10
#define E_QUEUE_EMPTY (StatusType)11
/*---------------------------- Timer Types ----------------------------------*/ #define E_FLAG_NOT_READY (StatusType)12
#if CFG_TMR_EN >0 #define E_ALREADY_IN_WAITING (StatusType)13
#define TMR_TYPE_ONE_SHOT 0 /*!< Timer counter type: One-shot */ #define E_TASK_NOT_WAITING (StatusType)14
#define TMR_TYPE_PERIODIC 1 /*!< Timer counter type: Periodic */ #define E_TASK_WAIT_OTHER (StatusType)15
#endif #define E_EXCEED_MAX_NUM (StatusType)16
#define E_NOT_IN_DELAY_LIST (StatusType)17
#define E_SEV_REQ_FULL (StatusType)18
/*---------------------------- Event Control ---------------------------------*/ #define E_NOT_FREE_ALL (StatusType)19
#if CFG_EVENT_EN >0 #define E_PROTECTED_TASK (StatusType)20
#define EVENT_SORT_TYPE_FIFO (U8)0x01 /*!< Insert a event by FIFO */ #define E_OS_IN_LOCK (StatusType)21
#define EVENT_SORT_TYPE_PRIO (U8)0x02 /*!< Insert a event by prio */
#endif
/*---------------------------- Wait Opreation type --------------------------*/
#define OPT_WAIT_ALL 0 /*!< Wait for all flags. */
/*---------------------------- Function declare-------------------------------*/ #define OPT_WAIT_ANY 1 /*!< Wait for any one of flags. */
#define OPT_WAIT_ONE 2 /*!< Waot for one flag. */
/* Implement in file "core.c" */
extern void CoInitOS(void); /*!< Initialize OS */
extern void CoStartOS(void); /*!< Start multitask */ /*---------------------------- Delete Opreation type ------------------------*/
extern void CoEnterISR(void); /*!< Enter a ISR */ #define OPT_DEL_NO_PEND 0 /*!< Delete when no task waitting for */
extern void CoExitISR(void); /*!< Exit a ISR */ #define OPT_DEL_ANYWAY 1 /*!< Delete always. */
extern void CoSchedLock(void);
extern void CoSchedUnlock(void);
extern OS_VER CoGetOSVersion(void); /*!< Get OS version value */ /*---------------------------- Timer Types ----------------------------------*/
#if CFG_TMR_EN >0
#define TMR_TYPE_ONE_SHOT 0 /*!< Timer counter type: One-shot */
/* Implement in file "task.c" */ #define TMR_TYPE_PERIODIC 1 /*!< Timer counter type: Periodic */
#define CoCreateTask(task,argv,prio,stk,stkSz) \ #endif
CreateTask(task,argv,(prio)|(((stkSz)<<8) &0x000FFF00 ),stk)
/*---------------------------- Event Control ---------------------------------*/
#define CoCreateTaskEx(task,argv,prio,stk,stkSz,timeSlice,isWaitting) \ #if CFG_EVENT_EN >0
CreateTask(task,argv,(prio)|(((stkSz)<<8)&0x000FFF00)|(((timeSlice)<<20)&0x7FF00000)|((isWaitting<<31)&0x80000000),stk) #define EVENT_SORT_TYPE_FIFO (U8)0x01 /*!< Insert a event by FIFO */
#define EVENT_SORT_TYPE_PRIO (U8)0x02 /*!< Insert a event by prio */
extern void CoExitTask(void); #endif
extern OS_TID CoGetCurTaskID(void);
extern StatusType CoDelTask(OS_TID taskID);
extern StatusType CoActivateTask(OS_TID taskID,void *argv); /*---------------------------- Function declare-------------------------------*/
extern StatusType CoAwakeTask(OS_TID taskID);
extern StatusType CoSuspendTask(OS_TID taskID); /* Implement in file "core.c" */
extern StatusType CoSetPriority(OS_TID taskID,U8 priority); extern void CoInitOS(void); /*!< Initialize OS */
extern OS_TID CreateTask(FUNCPtr task,void *argv,U32 parameter,OS_STK *stk); extern void CoStartOS(void); /*!< Start multitask */
extern void CoEnterISR(void); /*!< Enter a ISR */
/* Implement in file "time.c" */ extern void CoExitISR(void); /*!< Exit a ISR */
extern U64 CoGetOSTime(void); extern void CoSchedLock(void);
extern StatusType CoTickDelay(U32 ticks); extern void CoSchedUnlock(void);
extern StatusType CoResetTaskDelayTick(OS_TID taskID,U32 ticks); extern OS_VER CoGetOSVersion(void); /*!< Get OS version value */
extern StatusType CoTimeDelay(U8 hour,U8 minute,U8 sec,U16 millsec);
/* Implement in file "task.c" */
/* Implement in file "timer.c" */ #define CoCreateTask(task,argv,prio,stk,stkSz) \
extern StatusType CoDelTmr(OS_TCID tmrID); CreateTask(task,argv,(prio)|(((stkSz)<<8) &0x000FFF00 ),stk)
extern StatusType CoStopTmr(OS_TCID tmrID);
extern StatusType CoStartTmr(OS_TCID tmrID);
extern U32 CoGetCurTmrCnt(OS_TCID tmrID,StatusType* perr); #define CoCreateTaskEx(task,argv,prio,stk,stkSz,timeSlice,isWaitting) \
extern StatusType CoSetTmrCnt(OS_TCID tmrID,U32 tmrCnt,U32 tmrReload); CreateTask(task,argv,(prio)|(((stkSz)<<8)&0x000FFF00)|(((timeSlice)<<20)&0x7FF00000)|((isWaitting<<31)&0x80000000),stk)
extern OS_TCID CoCreateTmr(U8 tmrType, U32 tmrCnt, U32 tmrReload, vFUNCPtr func);
extern void CoExitTask(void);
extern OS_TID CoGetCurTaskID(void);
/* Implement in file "kernelHeap.c"*/ extern StatusType CoDelTask(OS_TID taskID);
extern void* CoKmalloc(U32 size); extern StatusType CoActivateTask(OS_TID taskID,void *argv);
extern void CoKfree(void* memBuf); extern StatusType CoAwakeTask(OS_TID taskID);
extern StatusType CoSuspendTask(OS_TID taskID);
extern StatusType CoSetPriority(OS_TID taskID,U8 priority);
/* Implement in file "mm.c" */ extern OS_TID CreateTask(FUNCPtr task,void *argv,U32 parameter,OS_STK *stk);
extern void* CoGetMemoryBuffer(OS_MMID mmID);
extern StatusType CoDelMemoryPartition(OS_MMID mmID); /* Implement in file "time.c" */
extern StatusType CoFreeMemoryBuffer(OS_MMID mmID,void* buf); extern U64 CoGetOSTime(void);
extern U32 CoGetFreeBlockNum(OS_MMID mmID,StatusType* perr); extern StatusType CoTickDelay(U32 ticks);
extern OS_MMID CoCreateMemPartition(U8* memBuf,U32 blockSize,U32 blockNum); extern StatusType CoResetTaskDelayTick(OS_TID taskID,U32 ticks);
extern StatusType CoTimeDelay(U8 hour,U8 minute,U8 sec,U16 millsec);
/* Implement in file "mutex.c" */
extern OS_MutexID CoCreateMutex(void);
extern StatusType CoEnterMutexSection(OS_MutexID mutexID); /* Implement in file "timer.c" */
extern StatusType CoLeaveMutexSection(OS_MutexID mutexID); extern StatusType CoDelTmr(OS_TCID tmrID);
extern StatusType CoStopTmr(OS_TCID tmrID);
extern StatusType CoStartTmr(OS_TCID tmrID);
/* Implement in file "sem.c" */ extern U32 CoGetCurTmrCnt(OS_TCID tmrID,StatusType* perr);
extern StatusType CoPostSem(OS_EventID id); extern StatusType CoSetTmrCnt(OS_TCID tmrID,U32 tmrCnt,U32 tmrReload);
extern StatusType CoAcceptSem(OS_EventID id); extern OS_TCID CoCreateTmr(U8 tmrType, U32 tmrCnt, U32 tmrReload, vFUNCPtr func);
extern StatusType isr_PostSem(OS_EventID id);
extern StatusType CoDelSem(OS_EventID id,U8 opt);
extern StatusType CoPendSem(OS_EventID id,U32 timeout); /* Implement in file "kernelHeap.c"*/
extern OS_EventID CoCreateSem(U16 initCnt,U16 maxCnt,U8 sortType); extern void* CoKmalloc(U32 size);
extern void CoKfree(void* memBuf);
/* Implement in file "mbox.c" */
extern OS_EventID CoCreateMbox(U8 sortType); /* Implement in file "mm.c" */
extern StatusType CoDelMbox(OS_EventID id,U8 opt); extern void* CoGetMemoryBuffer(OS_MMID mmID);
extern StatusType CoPostMail(OS_EventID id,void* pmail); extern StatusType CoDelMemoryPartition(OS_MMID mmID);
extern StatusType isr_PostMail(OS_EventID id,void* pmail); extern StatusType CoFreeMemoryBuffer(OS_MMID mmID,void* buf);
extern void* CoAcceptMail(OS_EventID id,StatusType* perr); extern U32 CoGetFreeBlockNum(OS_MMID mmID,StatusType* perr);
extern void* CoPendMail(OS_EventID id,U32 timeout,StatusType* perr); extern OS_MMID CoCreateMemPartition(U8* memBuf,U32 blockSize,U32 blockNum);
/* Implement in file "mutex.c" */
/* Implement in file "queue.c" */ extern OS_MutexID CoCreateMutex(void);
extern StatusType CoDelQueue(OS_EventID id,U8 opt); extern StatusType CoEnterMutexSection(OS_MutexID mutexID);
extern StatusType CoPostQueueMail(OS_EventID id,void* pmail); extern StatusType CoLeaveMutexSection(OS_MutexID mutexID);
extern StatusType isr_PostQueueMail(OS_EventID id,void* pmail);
extern void* CoAcceptQueueMail(OS_EventID id,StatusType* perr);
extern OS_EventID CoCreateQueue(void **qStart, U16 size ,U8 sortType); /* Implement in file "sem.c" */
extern void* CoPendQueueMail(OS_EventID id,U32 timeout,StatusType* perr); extern StatusType CoPostSem(OS_EventID id);
extern StatusType CoAcceptSem(OS_EventID id);
extern StatusType isr_PostSem(OS_EventID id);
extern StatusType CoDelSem(OS_EventID id,U8 opt);
/* Implement in file "flag.c" */ extern StatusType CoPendSem(OS_EventID id,U32 timeout);
extern StatusType CoSetFlag (OS_FlagID id); extern OS_EventID CoCreateSem(U16 initCnt,U16 maxCnt,U8 sortType);
extern StatusType CoClearFlag (OS_FlagID id);
extern StatusType isr_SetFlag (OS_FlagID id);
extern StatusType CoDelFlag (OS_FlagID id,U8 opt); /* Implement in file "mbox.c" */
extern StatusType CoAcceptSingleFlag (OS_FlagID id); extern OS_EventID CoCreateMbox(U8 sortType);
extern StatusType CoWaitForSingleFlag (OS_FlagID id,U32 timeout); extern StatusType CoDelMbox(OS_EventID id,U8 opt);
extern OS_FlagID CoCreateFlag (BOOL bAutoReset,BOOL bInitialState); extern StatusType CoPostMail(OS_EventID id,void* pmail);
extern U32 CoAcceptMultipleFlags (U32 flags,U8 waitType,StatusType *perr); extern StatusType isr_PostMail(OS_EventID id,void* pmail);
extern U32 CoWaitForMultipleFlags (U32 flags,U8 waitType,U32 timeout,StatusType *perr); extern void* CoAcceptMail(OS_EventID id,StatusType* perr);
extern void* CoPendMail(OS_EventID id,U32 timeout,StatusType* perr);
/* Implement in file "utility.c" */
extern StatusType CoTimeToTick(U8 hour,U8 minute,U8 sec,U16 millsec,U32* ticks); /* Implement in file "queue.c" */
extern void CoTickToTime(U32 ticks,U8* hour,U8* minute,U8* sec,U16* millsec); extern StatusType CoDelQueue(OS_EventID id,U8 opt);
extern StatusType CoPostQueueMail(OS_EventID id,void* pmail);
extern StatusType isr_PostQueueMail(OS_EventID id,void* pmail);
/* Implement in file "hook.c" */ extern void* CoAcceptQueueMail(OS_EventID id,StatusType* perr);
extern void CoIdleTask(void* pdata); extern OS_EventID CoCreateQueue(void **qStart, U16 size ,U8 sortType);
extern void CoStkOverflowHook(OS_TID taskID); extern void* CoPendQueueMail(OS_EventID id,U32 timeout,StatusType* perr);
#endif
/* Implement in file "flag.c" */
extern StatusType CoSetFlag (OS_FlagID id);
extern StatusType CoClearFlag (OS_FlagID id);
extern StatusType isr_SetFlag (OS_FlagID id);
extern StatusType CoDelFlag (OS_FlagID id,U8 opt);
extern StatusType CoAcceptSingleFlag (OS_FlagID id);
extern StatusType CoWaitForSingleFlag (OS_FlagID id,U32 timeout);
extern OS_FlagID CoCreateFlag (BOOL bAutoReset,BOOL bInitialState);
extern U32 CoAcceptMultipleFlags (U32 flags,U8 waitType,StatusType *perr);
extern U32 CoWaitForMultipleFlags (U32 flags,U8 waitType,U32 timeout,StatusType *perr);
/* Implement in file "utility.c" */
extern StatusType CoTimeToTick(U8 hour,U8 minute,U8 sec,U16 millsec,U32* ticks);
extern void CoTickToTime(U32 ticks,U8* hour,U8* minute,U8* sec,U16* millsec);
/* Implement in file "hook.c" */
extern void CoIdleTask(void* pdata);
extern void CoStkOverflowHook(OS_TID taskID);
#endif
+50 -27
View File
@@ -1,27 +1,50 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsCore.h * @file OsCore.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Header file related to kernel * @brief Header file related to kernel
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _CORE_H * notice, this list of conditions and the following disclaimer in the
#define _CORE_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
#include <CoOS.h> * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
#define OsSchedLock() { OSSchedLock++; asm volatile ("" : : : "memory"); } /*!< Lock schedule */ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
extern void OsSchedUnlock(void); * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#endif * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 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.
*
* <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
*******************************************************************************
*/
#ifndef _CORE_H
#define _CORE_H
#include <CoOS.h>
#define OsSchedLock() { OSSchedLock++; asm volatile ("" : : : "memory"); } /*!< Lock schedule */
extern void OsSchedUnlock(void);
#endif
+107 -84
View File
@@ -1,84 +1,107 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsError.h * @file OsError.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief rror dispose header file * @brief rror dispose header file
* @details This file use to dispose error which from error configure for OS. * @details This file use to dispose error which from error configure for OS.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _ERROR_H * notice, this list of conditions and the following disclaimer in the
#define _ERROR_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
#if (CFG_SYSTICK_FREQ > 1000) ||(CFG_SYSTICK_FREQ < 1) * contributors may be used to endorse or promote products derived
#error " OsConfig.h System Tick time must between 1ms and 1s!" * from this software without specific prior written permission.
#endif *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#if CFG_MAX_USER_TASKS > 253 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#error " OsConfig.h, CFG_MAX_USER_TASKS must be <= 253! " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#endif * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#if CFG_LOWEST_PRIO > 254 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#error " OsConfig.h, CFG_LOWEST_PRIO must be <= 254! " * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#endif * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#if CFG_IDLE_STACK_SIZE <25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
#error " OsConfig.h, CFG_IDLE_STACK_SIZE must be >= 25! " * THE POSSIBILITY OF SUCH DAMAGE.
#endif *
* <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
*******************************************************************************
#if CFG_ROBIN_EN > 0 */
#if CFG_TIME_SLICE > 4095
#error " OsConfig.h, CFG_TIME_SLICE must be <= 4095! "
#endif #ifndef _ERROR_H
#endif #define _ERROR_H
#if CFG_TMR_EN > 0 #if (CFG_SYSTICK_FREQ > 1000) ||(CFG_SYSTICK_FREQ < 1)
#if CFG_MAX_TMR > 32 #error " OsConfig.h System Tick time must between 1ms and 1s!"
#error " OsConfig.h, CFG_MAX_TMR must be <= 32! " #endif
#endif
#endif #if CFG_MAX_USER_TASKS > 253
#error " OsConfig.h, CFG_MAX_USER_TASKS must be <= 253! "
#endif
#if CFG_MM_EN > 0
#if CFG_MAX_MM > 32 #if CFG_LOWEST_PRIO > 254
#error " config.h, CFG_MAX_MM must be <= 32! " #error " OsConfig.h, CFG_LOWEST_PRIO must be <= 254! "
#endif #endif
#endif
#if CFG_IDLE_STACK_SIZE <25
#error " OsConfig.h, CFG_IDLE_STACK_SIZE must be >= 25! "
#if CFG_KHEAP_EN > 0 #endif
#if KHEAP_SIZE < 0x20
#error " config.h, CFG_MAX_MM must be >= 0x20! "
#endif #if CFG_ROBIN_EN > 0
#endif #if CFG_TIME_SLICE > 4095
#error " OsConfig.h, CFG_TIME_SLICE must be <= 4095! "
#if CFG_MUTEX_EN > 0 #endif
#if CFG_MAX_MUTEX > 254 #endif
#error " config.h, CFG_MAX_MUTEX must be <= 254! "
#endif #if CFG_TMR_EN > 0
#endif #if CFG_MAX_TMR > 32
#error " OsConfig.h, CFG_MAX_TMR must be <= 32! "
#endif
#if CFG_EVENT_EN > 0 #endif
#if (CFG_MAX_EVENT > 254 || CFG_MAX_EVENT <= 0)
#error " config.h, CFG_MAX_EVENT must be <= 254 && > 0! "
#endif #if CFG_MM_EN > 0
#if CFG_MAX_MM > 32
#error " config.h, CFG_MAX_MM must be <= 32! "
#if CFG_QUEUE_EN > 0 #endif
#if CFG_MAX_QUEUE > CFG_MAX_EVENT #endif
#error " config.h, CFG_MAX_QUEUE must be <= CFG_MAX_EVENT! "
#endif
#endif #if CFG_KHEAP_EN > 0
#endif /* CFG_EVENT_EN */ #if KHEAP_SIZE < 0x20
#error " config.h, CFG_MAX_MM must be >= 0x20! "
#endif /* _ERROR_H */ #endif
#endif
#if CFG_MUTEX_EN > 0
#if CFG_MAX_MUTEX > 254
#error " config.h, CFG_MAX_MUTEX must be <= 254! "
#endif
#endif
#if CFG_EVENT_EN > 0
#if (CFG_MAX_EVENT > 254 || CFG_MAX_EVENT <= 0)
#error " config.h, CFG_MAX_EVENT must be <= 254 && > 0! "
#endif
#if CFG_QUEUE_EN > 0
#if CFG_MAX_QUEUE > CFG_MAX_EVENT
#error " config.h, CFG_MAX_QUEUE must be <= CFG_MAX_EVENT! "
#endif
#endif
#endif /* CFG_EVENT_EN */
#endif /* _ERROR_H */
+81 -58
View File
@@ -1,58 +1,81 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsEvent.h * @file OsEvent.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Event management header file * @brief Event management header file
* @details This file including some defines and declares related to event * @details This file including some defines and declares related to event
* (semaphore,mailbox,queque) management. * (semaphore,mailbox,queque) management.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _EVENT_H * notice, this list of conditions and the following disclaimer in the
#define _EVENT_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
#define EVENT_TYPE_SEM (U8)0x01 /*!< Event type:Semaphore. */ * contributors may be used to endorse or promote products derived
#define EVENT_TYPE_MBOX (U8)0x02 /*!< Event type:Mailbox. */ * from this software without specific prior written permission.
#define EVENT_TYPE_QUEUE (U8)0x03 /*!< Event type:Queue. */ *
#define EVENT_TYPE_INVALID (U8)0x04 /*!< Invalid event type. */ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* @struct EventCtrBlk event.h * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* @brief Event control block * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* @details This struct is use to manage event, * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* e.g. semaphore,mailbox,queue. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
*/ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
typedef struct EventCtrBlk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
{ * THE POSSIBILITY OF SUCH DAMAGE.
void* eventPtr; /*!< Point to mailbox or queue struct */ *
U8 id; /*!< ECB id */ * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
U8 eventType:4; /*!< Type of event */ *******************************************************************************
U8 eventSortType:4; /*!< 0:FIFO 1: Preemptive by prio */ */
U16 eventCounter; /*!< Counter of semaphore. */
U16 initialEventCounter; /*!< Initial counter of semaphore. */
P_OSTCB eventTCBList; /*!< Task waitting list. */ #ifndef _EVENT_H
}ECB,*P_ECB; #define _EVENT_H
/*---------------------------- Variable declare ------------------------------*/ #define EVENT_TYPE_SEM (U8)0x01 /*!< Event type:Semaphore. */
extern ECB EventTbl[CFG_MAX_EVENT]; /*!< Table use to save TCB. */ #define EVENT_TYPE_MBOX (U8)0x02 /*!< Event type:Mailbox. */
#define EVENT_TYPE_QUEUE (U8)0x03 /*!< Event type:Queue. */
/*---------------------------- Function declare ------------------------------*/ #define EVENT_TYPE_INVALID (U8)0x04 /*!< Invalid event type. */
/*!< Create a event */
extern P_ECB CreatEvent(U8 eventType,U8 eventSortType,void* eventPtr);
/**
/*!< Remove a task from wait list */ * @struct EventCtrBlk event.h
extern void EventTaskToWait(P_ECB pecb,P_OSTCB ptcb); * @brief Event control block
extern StatusType DeleteEvent(P_ECB pecb,U8 opt); /*!< Delete a event. */ * @details This struct is use to manage event,
extern void EventTaskToRdy(P_ECB pecb); /*!< Insert a task to ready list*/ * e.g. semaphore,mailbox,queue.
extern void CreateEventList(void); /*!< Create a event list. */ */
extern void RemoveEventWaittingList(P_OSTCB ptcb); typedef struct EventCtrBlk
#endif {
void* eventPtr; /*!< Point to mailbox or queue struct */
U8 id; /*!< ECB id */
U8 eventType:4; /*!< Type of event */
U8 eventSortType:4; /*!< 0:FIFO 1: Preemptive by prio */
U16 eventCounter; /*!< Counter of semaphore. */
U16 initialEventCounter; /*!< Initial counter of semaphore. */
P_OSTCB eventTCBList; /*!< Task waitting list. */
}ECB,*P_ECB;
/*---------------------------- Variable declare ------------------------------*/
extern ECB EventTbl[CFG_MAX_EVENT]; /*!< Table use to save TCB. */
/*---------------------------- Function declare ------------------------------*/
/*!< Create a event */
extern P_ECB CreatEvent(U8 eventType,U8 eventSortType,void* eventPtr);
/*!< Remove a task from wait list */
extern void EventTaskToWait(P_ECB pecb,P_OSTCB ptcb);
extern StatusType DeleteEvent(P_ECB pecb,U8 opt); /*!< Delete a event. */
extern void EventTaskToRdy(P_ECB pecb); /*!< Insert a task to ready list*/
extern void CreateEventList(void); /*!< Create a event list. */
extern void RemoveEventWaittingList(P_OSTCB ptcb);
#endif
+80 -57
View File
@@ -1,57 +1,80 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsFlag.h * @file OsFlag.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Evnet flag management header file * @brief Evnet flag management header file
* @details This file including some defines and declares about flag management. * @details This file including some defines and declares about flag management.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _FLAG_H * notice, this list of conditions and the following disclaimer in the
#define _FLAG_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
/** * contributors may be used to endorse or promote products derived
* @struct FlagNode flag.h * from this software without specific prior written permission.
* @brief Flag node struct *
* @details * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
*/ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
typedef struct FlagNode * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
{ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
struct FlagNode* nextNode; /*!< A pointer to next flag node */ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
struct FlagNode* prevNode; /*!< A pointer to prev flag node */ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
U32 waitFlags; /*!< Flag value */ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
P_OSTCB waitTask; /*!< A pointer to task waitting flag */ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
U8 waitType; /*!< Wait type */ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
}FLAG_NODE,*P_FLAG_NODE; * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
/** * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
* @struct Flag flag.h *******************************************************************************
* @brief Flag control block */
* @details This struct use to mange event flag.
*/
typedef struct Flag #ifndef _FLAG_H
{ #define _FLAG_H
U32 flagRdy; /*!< Ready flag */
U32 resetOpt; /*!< Reset option */ /**
U32 flagActive; /*!< Active flag */ * @struct FlagNode flag.h
P_FLAG_NODE headNode; /*!< Head node */ * @brief Flag node struct
P_FLAG_NODE tailNode; /*!< Tail node */ * @details
}FCB,*P_FCB; */
typedef struct FlagNode
{
/*---------------------------- Variable declare ------------------------------*/ struct FlagNode* nextNode; /*!< A pointer to next flag node */
extern FCB FlagCrl; struct FlagNode* prevNode; /*!< A pointer to prev flag node */
U32 waitFlags; /*!< Flag value */
/*---------------------------- Function declare ------------------------------*/ P_OSTCB waitTask; /*!< A pointer to task waitting flag */
extern void RemoveLinkNode(P_FLAG_NODE pnode); U8 waitType; /*!< Wait type */
#endif }FLAG_NODE,*P_FLAG_NODE;
/**
* @struct Flag flag.h
* @brief Flag control block
* @details This struct use to mange event flag.
*/
typedef struct Flag
{
U32 flagRdy; /*!< Ready flag */
U32 resetOpt; /*!< Reset option */
U32 flagActive; /*!< Active flag */
P_FLAG_NODE headNode; /*!< Head node */
P_FLAG_NODE tailNode; /*!< Tail node */
}FCB,*P_FCB;
/*---------------------------- Variable declare ------------------------------*/
extern FCB FlagCrl;
/*---------------------------- Function declare ------------------------------*/
extern void RemoveLinkNode(P_FLAG_NODE pnode);
#endif
+71 -48
View File
@@ -1,48 +1,71 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsKernelHeap.h * @file OsKernelHeap.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Header file related to memory management * @brief Header file related to memory management
* @details This file including some defines and function declare related to * @details This file including some defines and function declare related to
* kernel heap management. * kernel heap management.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _KERNELHEAP_H * notice, this list of conditions and the following disclaimer in the
#define _KERNELHEAP_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
typedef struct KennelHeap * from this software without specific prior written permission.
{ *
U32 startAddr; * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
U32 endAddr; * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
}KHeap,*P_KHeap; * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
typedef struct UsedMemBlk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
{ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
void* nextMB; * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
void* preMB; * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
}UMB,*P_UMB; * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
typedef struct FreeMemBlk * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
{ *******************************************************************************
struct FreeMemBlk* nextFMB; */
struct UsedMemBlk* nextUMB;
struct UsedMemBlk* preUMB;
}FMB,*P_FMB; #ifndef _KERNELHEAP_H
#define _KERNELHEAP_H
/*---------------------------- Function Declare ------------------------------*/
extern void CoCreateKheap(void);
typedef struct KennelHeap
#endif /* _KERNELHEAP_H */ {
U32 startAddr;
U32 endAddr;
}KHeap,*P_KHeap;
typedef struct UsedMemBlk
{
void* nextMB;
void* preMB;
}UMB,*P_UMB;
typedef struct FreeMemBlk
{
struct FreeMemBlk* nextFMB;
struct UsedMemBlk* nextUMB;
struct UsedMemBlk* preUMB;
}FMB,*P_FMB;
/*---------------------------- Function Declare ------------------------------*/
extern void CoCreateKheap(void);
#endif /* _KERNELHEAP_H */
+64 -41
View File
@@ -1,41 +1,64 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsMm.h * @file OsMm.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Header file related to memory management * @brief Header file related to memory management
* @details This file including some defines and function declare related to * @details This file including some defines and function declare related to
* memory management. * memory management.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _MM_H * notice, this list of conditions and the following disclaimer in the
#define _MM_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
typedef struct Memory * from this software without specific prior written permission.
{ *
U8* memAddr; * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
U8* freeBlock; * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
U32 blockSize; * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
U32 blockNum; * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
}MM,*P_MM; * 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
typedef struct MemoryBlock * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
{ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
struct MemoryBlock* nextBlock; * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
}MemBlk,*P_MemBlk; * THE POSSIBILITY OF SUCH DAMAGE.
*
* <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
extern U32 MemoryIDVessel; *******************************************************************************
*/
#endif /* _MM_H */
#ifndef _MM_H
#define _MM_H
typedef struct Memory
{
U8* memAddr;
U8* freeBlock;
U32 blockSize;
U32 blockNum;
}MM,*P_MM;
typedef struct MemoryBlock
{
struct MemoryBlock* nextBlock;
}MemBlk,*P_MemBlk;
extern U32 MemoryIDVessel;
#endif /* _MM_H */
+80 -57
View File
@@ -1,57 +1,80 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsMutex.h * @file OsMutex.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Mutex management header file * @brief Mutex management header file
* @details This file including some defines and declare related to mutex * @details This file including some defines and declare related to mutex
* management. * management.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _MUTEX_H * notice, this list of conditions and the following disclaimer in the
#define _MUTEX_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
#include <coocox.h> * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
#if CFG_MUTEX_EN > 0 *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
/*---------------------------- Resource status -------------------------------*/ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#define MUTEX_FREE 0 /*!< Mutex is free */ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#define MUTEX_OCCUPY 1 /*!< Mutex is occupy */ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
#define WAITING_MUTEX 0x80 * 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
* @struct Mutex mutex.h * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* @brief Mutex control block * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* @details This struct is use to mutex management. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
*/ * THE POSSIBILITY OF SUCH DAMAGE.
typedef struct Mutex *
{ * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
U8 originalPrio; /*!< Mutex priority. */ *******************************************************************************
U8 mutexFlag; /*!< Mutex flag. */ */
OS_TID taskID; /*!< Task ID. */
OS_TID hipriTaskID; /*!< Mutex ID. */
P_OSTCB waittingList; /*!< waitting the Mutex. */ #ifndef _MUTEX_H
}MUTEX,*P_MUTEX; #define _MUTEX_H
#include <coocox.h>
/*---------------------------- Variable declare ------------------------------*/
/*!< Table use to save mutex control block. */ #if CFG_MUTEX_EN > 0
extern MUTEX MutexTbl[CFG_MAX_MUTEX];
extern OS_MutexID MutexFreeID; /*!< A pointer to next vliad resource ID. */ /*---------------------------- Resource status -------------------------------*/
#define MUTEX_FREE 0 /*!< Mutex is free */
#define MUTEX_OCCUPY 1 /*!< Mutex is occupy */
/*---------------------------- Function declare ------------------------------*/ #define WAITING_MUTEX 0x80
extern void RemoveMutexList(P_OSTCB ptcb);
/**
#endif /* CFG_MUTEX_EN */ * @struct Mutex mutex.h
* @brief Mutex control block
#endif /* _MUTEX_H */ * @details This struct is use to mutex management.
*/
typedef struct Mutex
{
U8 originalPrio; /*!< Mutex priority. */
U8 mutexFlag; /*!< Mutex flag. */
OS_TID taskID; /*!< Task ID. */
OS_TID hipriTaskID; /*!< Mutex ID. */
P_OSTCB waittingList; /*!< waitting the Mutex. */
}MUTEX,*P_MUTEX;
/*---------------------------- Variable declare ------------------------------*/
/*!< Table use to save mutex control block. */
extern MUTEX MutexTbl[CFG_MAX_MUTEX];
extern OS_MutexID MutexFreeID; /*!< A pointer to next vliad resource ID. */
/*---------------------------- Function declare ------------------------------*/
extern void RemoveMutexList(P_OSTCB ptcb);
#endif /* CFG_MUTEX_EN */
#endif /* _MUTEX_H */
+62 -39
View File
@@ -1,39 +1,62 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsQueue.h * @file OsQueue.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Queue management header file * @brief Queue management header file
* @details This file including some defines and declares about queue management. * @details This file including some defines and declares about queue management.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _QUEUE_H * notice, this list of conditions and the following disclaimer in the
#define _QUEUE_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
/** * from this software without specific prior written permission.
* @struct Queue queue.h *
* @brief Queue struct * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* @details This struct use to manage queue. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*/ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
typedef struct Queue * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
{ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
void **qStart; /*!< */ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
U8 id; /*!< */ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
U16 head; /*!< The header of queue */ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
U16 tail; /*!< The end of queue */ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
U16 qMaxSize; /*!< The max size of queue */ * THE POSSIBILITY OF SUCH DAMAGE.
U16 qSize; /*!< Current size of queue */ *
}QCB,*P_QCB; * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
*******************************************************************************
*/
#endif
#ifndef _QUEUE_H
#define _QUEUE_H
/**
* @struct Queue queue.h
* @brief Queue struct
* @details This struct use to manage queue.
*
*/
typedef struct Queue
{
void **qStart; /*!< */
U8 id; /*!< */
U16 head; /*!< The header of queue */
U16 tail; /*!< The end of queue */
U16 qMaxSize; /*!< The max size of queue */
U16 qSize; /*!< Current size of queue */
}QCB,*P_QCB;
#endif
+76 -53
View File
@@ -1,53 +1,76 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsServiceReq.h * @file OsServiceReq.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Header file related to service request * @brief Header file related to service request
* @details This file including some defines and function declare related to * @details This file including some defines and function declare related to
* service request. * service request.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _SERVICEREQ_H * notice, this list of conditions and the following disclaimer in the
#define _SERVICEREQ_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
#if CFG_MAX_SERVICE_REQUEST > 0 * contributors may be used to endorse or promote products derived
#define SEM_REQ (U8)0x1 * from this software without specific prior written permission.
#define MBOX_REQ (U8)0x2 *
#define FLAG_REQ (U8)0x3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#define QUEUE_REQ (U8)0x4 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
typedef struct ServiceReqCell * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
{ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
U8 type; * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
U8 id; * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
void* arg; * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
}SQC,*P_SQC; * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
typedef struct ServiceReqQueue *
{ * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
U8 cnt; *******************************************************************************
U8 head; */
SQC cell[CFG_MAX_SERVICE_REQUEST];
}SRQ,*P_SRQ;
#ifndef _SERVICEREQ_H
#define _SERVICEREQ_H
extern SRQ ServiceReq;
extern BOOL InsertInSRQ(U8 type,U8 id,void* arg); #if CFG_MAX_SERVICE_REQUEST > 0
#endif #define SEM_REQ (U8)0x1
#define MBOX_REQ (U8)0x2
extern void RespondSRQ(void); #define FLAG_REQ (U8)0x3
extern BOOL TimeReq; #define QUEUE_REQ (U8)0x4
extern BOOL TimerReq;
extern BOOL IsrReq;
#endif typedef struct ServiceReqCell
{
U8 type;
U8 id;
void* arg;
}SQC,*P_SQC;
typedef struct ServiceReqQueue
{
U8 cnt;
U8 head;
SQC cell[CFG_MAX_SERVICE_REQUEST];
}SRQ,*P_SRQ;
extern SRQ ServiceReq;
extern BOOL InsertInSRQ(U8 type,U8 id,void* arg);
#endif
extern void RespondSRQ(void);
extern BOOL TimeReq;
extern BOOL TimerReq;
extern BOOL IsrReq;
#endif
+135 -112
View File
@@ -1,112 +1,135 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsTask.h * @file OsTask.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Header file related to task. * @brief Header file related to task.
* @details This file including some defines and function declare related to task. * @details This file including some defines and function declare related to task.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
#ifndef _TASK_H * * Redistributions in binary form must reproduce the above copyright
#define _TASK_H * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
#define SYS_TASK_NUM (1) /*!< System task number. */ * * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
/*---------------------------- Task Status -----------------------------------*/ * from this software without specific prior written permission.
#define TASK_READY 0 /*!< Ready status of task. */ *
#define TASK_RUNNING 1 /*!< Running status of task. */ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#define TASK_WAITING 2 /*!< Waitting status of task. */ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#define TASK_DORMANT 3 /*!< Dormant status of task. */ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#define INVALID_ID (U8)0xff * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#define INVALID_VALUE (U32)0xffffffff * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#define MAGIC_WORD (U32)0x5a5aa5a5 * 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.
* @struct TCB task.h *
* @brief Task control blcok. * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
* @details This struct use to manage task. *******************************************************************************
*/ */
typedef struct TCB
{ #ifndef _TASK_H
OS_STK *stkPtr; /*!< The current point of task. */ #define _TASK_H
U8 prio; /*!< Task priority. */
U8 state; /*!< TaSk status. */ #define SYS_TASK_NUM (1) /*!< System task number. */
OS_TID taskID; /*!< Task ID. */
/*---------------------------- Task Status -----------------------------------*/
#if CFG_MUTEX_EN > 0 #define TASK_READY 0 /*!< Ready status of task. */
OS_MutexID mutexID; /*!< Mutex ID. */ #define TASK_RUNNING 1 /*!< Running status of task. */
#endif #define TASK_WAITING 2 /*!< Waitting status of task. */
#define TASK_DORMANT 3 /*!< Dormant status of task. */
#if CFG_EVENT_EN > 0
OS_EventID eventID; /*!< Event ID. */
#endif #define INVALID_ID (U8)0xff
#define INVALID_VALUE (U32)0xffffffff
#if CFG_ROBIN_EN >0 #define MAGIC_WORD (U32)0x5a5aa5a5
U16 timeSlice; /*!< Task time slice */
#endif
/**
#if CFG_STK_CHECKOUT_EN >0 * @struct TCB task.h
OS_STK *stack; /*!< The top point of task. */ * @brief Task control blcok.
#endif * @details This struct use to manage task.
*/
#if CFG_EVENT_EN > 0 typedef struct TCB
void* pmail; /*!< Mail to task. */ {
struct TCB *waitNext; /*!< Point to next TCB in the Event waitting list.*/ OS_STK *stkPtr; /*!< The current point of task. */
struct TCB *waitPrev; /*!< Point to prev TCB in the Event waitting list.*/ U8 prio; /*!< Task priority. */
#endif U8 state; /*!< TaSk status. */
OS_TID taskID; /*!< Task ID. */
#if CFG_TASK_SCHEDULE_EN == 0
FUNCPtr taskFuc; #if CFG_MUTEX_EN > 0
OS_STK *taskStk; OS_MutexID mutexID; /*!< Mutex ID. */
#endif #endif
#if CFG_EVENT_EN > 0
#if CFG_FLAG_EN > 0 OS_EventID eventID; /*!< Event ID. */
void* pnode; /*!< Pointer to node of event flag. */ #endif
#endif
#if CFG_ROBIN_EN >0
#if CFG_TASK_WAITTING_EN >0 U16 timeSlice; /*!< Task time slice */
U32 delayTick; /*!< The number of ticks which delay. */ #endif
#endif
struct TCB *TCBnext; /*!< The pointer to next TCB. */ #if CFG_STK_CHECKOUT_EN >0
struct TCB *TCBprev; /*!< The pointer to prev TCB. */ OS_STK *stack; /*!< The top point of task. */
#endif
}OSTCB,*P_OSTCB;
#if CFG_EVENT_EN > 0
void* pmail; /*!< Mail to task. */
/*---------------------------- Variable declare ------------------------------*/ struct TCB *waitNext; /*!< Point to next TCB in the Event waitting list.*/
// save tcb ptr that created struct TCB *waitPrev; /*!< Point to prev TCB in the Event waitting list.*/
extern P_OSTCB FreeTCB; /*!< A pointer to free TCB. */ #endif
extern OSTCB TCBTbl[CFG_MAX_USER_TASKS+SYS_TASK_NUM];
extern P_OSTCB TCBRdy; /*!< A pointer to TCB that is ready status */ #if CFG_TASK_SCHEDULE_EN == 0
extern P_OSTCB TCBNext; /*!< A pointer to TCB next be scheduled. */ FUNCPtr taskFuc;
extern P_OSTCB TCBRunning; /*!< A pointer to TCB that is running. */ OS_STK *taskStk;
#endif
extern U64 OSCheckTime;
extern volatile U8 OSIntNesting; /*!< Use to indicate interrupt nesting level.*/
extern volatile U8 OSSchedLock; /*!< Schedule is lock(LOCK) or unlock(UN_LOCK).*/ #if CFG_FLAG_EN > 0
extern volatile BOOL TaskSchedReq; void* pnode; /*!< Pointer to node of event flag. */
extern OS_STK idle_stk[CFG_IDLE_STACK_SIZE]; #endif
#if CFG_TASK_WAITTING_EN >0
void Schedule(void); /*!< Schedule function */ U32 delayTick; /*!< The number of ticks which delay. */
void IdleTask(void* pdata); /*!< IDLE task code */ #endif
void InsertToTCBRdyList (P_OSTCB tcbInser); struct TCB *TCBnext; /*!< The pointer to next TCB. */
void RemoveFromTCBRdyList(P_OSTCB ptcb); struct TCB *TCBprev; /*!< The pointer to prev TCB. */
void CreateTCBList(void);
#if CFG_ORDER_LIST_SCHEDULE_EN ==0 }OSTCB,*P_OSTCB;
void ActiveTaskPri(U8 pri);
void DeleteTaskPri(U8 pri);
#endif /*---------------------------- Variable declare ------------------------------*/
// save tcb ptr that created
#endif extern P_OSTCB FreeTCB; /*!< A pointer to free TCB. */
extern OSTCB TCBTbl[CFG_MAX_USER_TASKS+SYS_TASK_NUM];
extern P_OSTCB TCBRdy; /*!< A pointer to TCB that is ready status */
extern P_OSTCB TCBNext; /*!< A pointer to TCB next be scheduled. */
extern P_OSTCB TCBRunning; /*!< A pointer to TCB that is running. */
extern U64 OSCheckTime;
extern volatile U8 OSIntNesting; /*!< Use to indicate interrupt nesting level.*/
extern volatile U8 OSSchedLock; /*!< Schedule is lock(LOCK) or unlock(UN_LOCK).*/
extern volatile BOOL TaskSchedReq;
extern OS_STK idle_stk[CFG_IDLE_STACK_SIZE];
void Schedule(void); /*!< Schedule function */
void IdleTask(void* pdata); /*!< IDLE task code */
void InsertToTCBRdyList (P_OSTCB tcbInser);
void RemoveFromTCBRdyList(P_OSTCB ptcb);
void CreateTCBList(void);
#if CFG_ORDER_LIST_SCHEDULE_EN ==0
void ActiveTaskPri(U8 pri);
void DeleteTaskPri(U8 pri);
#endif
#endif
+51 -28
View File
@@ -1,28 +1,51 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsTime.c * @file OsTime.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Header file related to time management * @brief Header file related to time management
* @details Thie file including some data declare related to time managment. * @details Thie file including some data declare related to time managment.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
#ifndef _TIME_H * * Redistributions in binary form must reproduce the above copyright
#define _TIME_H * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
/*---------------------------- Variable declare ------------------------------*/ * * Neither the name of the <ORGANIZATION> nor the names of its
extern P_OSTCB DlyList; /*!< A pointer to ther delay list. */ * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
/*---------------------------- Function declare ------------------------------*/ *
extern void TimeDispose(void); /*!< Time dispose function. */ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
extern void isr_TimeDispose(void); * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
extern void RemoveDelayList(P_OSTCB ptcb); * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
extern void InsertDelayList(P_OSTCB ptcb,U32 ticks); * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
#endif * 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.
*
* <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
*******************************************************************************
*/
#ifndef _TIME_H
#define _TIME_H
/*---------------------------- Variable declare ------------------------------*/
extern P_OSTCB DlyList; /*!< A pointer to ther delay list. */
/*---------------------------- Function declare ------------------------------*/
extern void TimeDispose(void); /*!< Time dispose function. */
extern void isr_TimeDispose(void);
extern void RemoveDelayList(P_OSTCB ptcb);
extern void InsertDelayList(P_OSTCB ptcb,U32 ticks);
#endif
+72 -49
View File
@@ -1,49 +1,72 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsTimer.h * @file OsTimer.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Timer manage header file * @brief Timer manage header file
* @details This file including some declares and defines related to timer * @details This file including some declares and defines related to timer
* management. * management.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
#ifndef _TIMER_H * * Redistributions in binary form must reproduce the above copyright
#define _TIMER_H * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
#define TMR_STATE_RUNNING 0 /*!< Timer State: Running */ * * Neither the name of the <ORGANIZATION> nor the names of its
#define TMR_STATE_STOPPED 1 /*!< Timer State: Stopped */ * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
/** *
* @struct tmrCtrl timer.h * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* @brief Timer control block * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* @details This struct is use to manage user timer. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
*/ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
typedef struct tmrCtrl /* Timer Control Block Define. */ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
{ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
OS_TCID tmrID; /*!< Timer ID. */ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
U8 tmrType; /*!< Timer Type. */ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
U8 tmrState; /*!< Timer State. */ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
U32 tmrCnt; /*!< Timer Counter. */ * THE POSSIBILITY OF SUCH DAMAGE.
U32 tmrReload; /*!< Timer Reload Counter Value. */ *
vFUNCPtr tmrCallBack; /*!< Call-back Function When Timer overrun. */ * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
struct tmrCtrl* tmrNext; /*!< Point to Next Timer Control Block. */ *******************************************************************************
struct tmrCtrl* tmrPrev; /*!< Point to Previous Timer Control Block*/ */
}TmrCtrl,*P_TmrCtrl; #ifndef _TIMER_H
#define _TIMER_H
/*---------------------------- Variable declare ------------------------------*/
extern P_TmrCtrl TmrList; /*!< A pointer to the timer list. */ #define TMR_STATE_RUNNING 0 /*!< Timer State: Running */
extern U32 TmrIDVessel; #define TMR_STATE_STOPPED 1 /*!< Timer State: Stopped */
/*---------------------------- Function declare ------------------------------*/
extern void TmrDispose(void); /*!< Timer counter function. */ /**
extern void isr_TmrDispose(void); * @struct tmrCtrl timer.h
#endif * @brief Timer control block
* @details This struct is use to manage user timer.
*
*/
typedef struct tmrCtrl /* Timer Control Block Define. */
{
OS_TCID tmrID; /*!< Timer ID. */
U8 tmrType; /*!< Timer Type. */
U8 tmrState; /*!< Timer State. */
U32 tmrCnt; /*!< Timer Counter. */
U32 tmrReload; /*!< Timer Reload Counter Value. */
vFUNCPtr tmrCallBack; /*!< Call-back Function When Timer overrun. */
struct tmrCtrl* tmrNext; /*!< Point to Next Timer Control Block. */
struct tmrCtrl* tmrPrev; /*!< Point to Previous Timer Control Block*/
}TmrCtrl,*P_TmrCtrl;
/*---------------------------- Variable declare ------------------------------*/
extern P_TmrCtrl TmrList; /*!< A pointer to the timer list. */
extern U32 TmrIDVessel;
/*---------------------------- Function declare ------------------------------*/
extern void TmrDispose(void); /*!< Timer counter function. */
extern void isr_TmrDispose(void);
#endif
+83 -60
View File
@@ -1,60 +1,83 @@
/** /**
******************************************************************************* *******************************************************************************
* @file coocox.h * @file coocox.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Gather for all header file of CooCox CoOS. * @brief Gather for all header file of CooCox CoOS.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _COOCOX_H * notice, this list of conditions and the following disclaimer in the
#define _COOCOX_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
#define OS_VERSION (U16)0x0113 /*!< OS version.(format: Vx.xx), * contributors may be used to endorse or promote products derived
e.g. value 0x0113 is version V1.13*/ * from this software without specific prior written permission.
/*---------------------------- Include ---------------------------------------*/ *
#include "CoOS.h" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#include "OsArch.h" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#include "OsCore.h" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#include "OsTask.h" * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
#include "OsServiceReq.h" * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#include "OsError.h" * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#include "OsTime.h" * 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)
#if CFG_TMR_EN > 0 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
#include "OsTimer.h" * THE POSSIBILITY OF SUCH DAMAGE.
#endif *
* <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
#if CFG_KHEAP_EN > 0 *******************************************************************************
#include "OsKernelHeap.h" */
#endif
#if CFG_MM_EN >0 #ifndef _COOCOX_H
#include "OsMM.h" #define _COOCOX_H
#endif
#define OS_VERSION (U16)0x0116 /*!< OS version.(format: Vx.xx),
#if CFG_EVENT_EN > 0 e.g. value 0x0114 is version V1.14*/
#include "OsEvent.h" /*---------------------------- Include ---------------------------------------*/
#endif #include "CoOS.h"
#include "OsArch.h"
#if CFG_MUTEX_EN > 0 #include "OsCore.h"
#include "OsMutex.h" #include "OsTask.h"
#endif #include "OsServiceReq.h"
#include "OsError.h"
#if CFG_QUEUE_EN > 0 #include "OsTime.h"
#include "OsQueue.h"
#endif
#if CFG_TMR_EN > 0
#if CFG_FLAG_EN > 0 #include "OsTimer.h"
#include "OsFlag.h" #endif
#endif
#if CFG_KHEAP_EN > 0
#endif /* _COOCOX_H */ #include "OsKernelHeap.h"
#endif
#if CFG_MM_EN >0
#include "OsMM.h"
#endif
#if CFG_EVENT_EN > 0
#include "OsEvent.h"
#endif
#if CFG_MUTEX_EN > 0
#include "OsMutex.h"
#endif
#if CFG_QUEUE_EN > 0
#include "OsQueue.h"
#endif
#if CFG_FLAG_EN > 0
#include "OsFlag.h"
#endif
#endif /* _COOCOX_H */
+261 -238
View File
@@ -1,238 +1,261 @@
/** /**
******************************************************************************* *******************************************************************************
* @file core.c * @file core.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Core implementation code of CooCox CoOS kernel. * @brief Core implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
/*---------------------------- Include ---------------------------------------*/ * * Redistributions in binary form must reproduce the above copyright
#include <coocox.h> * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
/*---------------------------- Variable Define -------------------------------*/ * * Neither the name of the <ORGANIZATION> nor the names of its
volatile U8 OSIntNesting = 0; /*!< Use to indicate interrupt nesting level*/ * contributors may be used to endorse or promote products derived
volatile U8 OSSchedLock = 0; /*!< Task Switch lock. */ * from this software without specific prior written permission.
volatile BOOL TaskSchedReq = Co_FALSE; *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* @brief Enter a ISR. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* @param[in] None * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* @param[out] None * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* @retval None * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* @par Description * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* @details This function is called to notify OS when enter to an ISR. * THE POSSIBILITY OF SUCH DAMAGE.
* *
* @note When you call API in ISR,you must call CoEnterISR() before your * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
* interrupt handler code,and call CoExitISR() after your handler *******************************************************************************
* code and before exiting from ISR. */
*******************************************************************************
*/ /*---------------------------- Include ---------------------------------------*/
void CoEnterISR(void) #include <coocox.h>
{
Inc8(&OSIntNesting); /* OSIntNesting increment */ /*---------------------------- Variable Define -------------------------------*/
} volatile U8 OSIntNesting = 0; /*!< Use to indicate interrupt nesting level*/
volatile U8 OSSchedLock = 0; /*!< Task Switch lock. */
volatile BOOL TaskSchedReq = Co_FALSE;
/**
*******************************************************************************
* @brief Exit a ISR. /**
* @param[in] None *******************************************************************************
* @param[out] None * @brief Enter a ISR.
* @retval None * @param[in] None
* * @param[out] None
* @par Description * @retval None
* @details This function is called when exit from a ISR. *
* * @par Description
* @note * @details This function is called to notify OS when enter to an ISR.
******************************************************************************* *
*/ * @note When you call API in ISR,you must call CoEnterISR() before your
void CoExitISR(void) * interrupt handler code,and call CoExitISR() after your handler
{ * code and before exiting from ISR.
Dec8(&OSIntNesting); /* OSIntNesting decrease */ *******************************************************************************
if( OSIntNesting == 0) /* Is OSIntNesting == 0? */ */
{ void CoEnterISR(void)
if(TaskSchedReq == Co_TRUE) {
{ Inc8(&OSIntNesting); /* OSIntNesting increment */
OSSchedLock++; }
Schedule(); /* Call task schedule */
OSSchedLock--;
} /**
} *******************************************************************************
} * @brief Exit a ISR.
* @param[in] None
* @param[out] None
* @retval None
/** *
******************************************************************************* * @par Description
* @brief Unlock schedule * @details This function is called when exit from a ISR.
* @param[in] None *
* @param[out] None * @note
* @retval None *******************************************************************************
* */
* @par Description void CoExitISR(void)
* @details This function is called to unlock schedule(i.e.enable schedule again) {
* Dec8(&OSIntNesting); /* OSIntNesting decrease */
* @note if( OSIntNesting == 0) /* Is OSIntNesting == 0? */
******************************************************************************* {
*/ if(TaskSchedReq == Co_TRUE)
void OsSchedUnlock(void) {
{ OSSchedLock++;
if(OSSchedLock == 1) /* Is OSSchedLock == 0? */ Schedule(); /* Call task schedule */
{ OSSchedLock--;
#if CFG_TASK_WAITTING_EN > 0 }
if(IsrReq == Co_TRUE) }
{ }
RespondSRQ(); /* Respond service request */
}
#endif
/* Judge task state change or higher PRI task coming in */ /**
if(TaskSchedReq == Co_TRUE) *******************************************************************************
{ * @brief Unlock schedule
Schedule(); /* Call task schedule */ * @param[in] None
} * @param[out] None
OSSchedLock = 0; * @retval None
} *
else * @par Description
{ * @details This function is called to unlock schedule(i.e.enable schedule again)
OSSchedLock--; *
} * @note
} *******************************************************************************
*/
void OsSchedUnlock(void)
/** {
******************************************************************************* if(OSSchedLock == 1) /* Is OSSchedLock == 0? */
* @brief Lock schedule {
* @param[in] None #if CFG_TASK_WAITTING_EN > 0
* @param[out] None if(IsrReq == Co_TRUE)
* @retval None {
* RespondSRQ(); /* Respond service request */
* @par Description }
* @details This function is called in application code to lock schedule. #endif
* /* Judge task state change or higher PRI task coming in */
* @note if(TaskSchedReq == Co_TRUE)
******************************************************************************* {
*/ Schedule(); /* Call task schedule */
void CoSchedLock(void) }
{ OSSchedLock = 0;
OsSchedLock(); /* Lock schedule */ }
} else
{
OSSchedLock--;
/** }
******************************************************************************* }
* @brief Unlock schedule
* @param[in] None
* @param[out] None /**
* @retval None *******************************************************************************
* * @brief Lock schedule
* @par Description * @param[in] None
* @details This function is called in APP to unlock schedule. * @param[out] None
* * @retval None
* @note *
******************************************************************************* * @par Description
*/ * @details This function is called in application code to lock schedule.
void CoSchedUnlock(void) *
{ * @note
OsSchedUnlock(); /* Unlock schedule */ *******************************************************************************
} */
void CoSchedLock(void)
{
/** OsSchedLock(); /* Lock schedule */
******************************************************************************* }
* @brief Initialize OS
* @param[in] None
* @param[out] None /**
* @retval None *******************************************************************************
* * @brief Unlock schedule
* @par Description * @param[in] None
* @details This function is called to initialize OS. * @param[out] None
* * @retval None
* @note You must call this function first,before any other OS API function *
* * @par Description
* @code There is a example for useage of this function,as follows: * @details This function is called in APP to unlock schedule.
* e.g. *
* ... // Your target initial code. * @note
* *******************************************************************************
* OsInit(); // Initial OS. */
* CreateTask(...); // Create tasks. void CoSchedUnlock(void)
* ... {
* OsStart(); // Start multitask. OsSchedUnlock(); /* Unlock schedule */
* @endcode }
*******************************************************************************
*/
void CoInitOS(void) /**
{ *******************************************************************************
InitSysTick(); /* Initialize system tick. */ * @brief Initialize OS
InitInt(); /* Initialize PendSV,SVC,SysTick interrupt */ * @param[in] None
CreateTCBList(); /* Create TCB list. */ * @param[out] None
#if CFG_EVENT_EN > 0 * @retval None
CreateEventList(); /* Create event control list. */ *
#endif * @par Description
#if CFG_KHEAP_EN > 0 * @details This function is called to initialize OS.
CoCreateKheap(); /* Create kernel heap within user define */ *
#endif * @note You must call this function first,before any other OS API function
OsSchedLock(); /* Lock Schedule */ *
/* Create first task -- IDLE task. */ * @code There is a example for useage of this function,as follows:
CoCreateTask( CoIdleTask, * e.g.
Co_NULL, * ... // Your target initial code.
CFG_LOWEST_PRIO, *
&idle_stk[CFG_IDLE_STACK_SIZE-1], * OsInit(); // Initial OS.
CFG_IDLE_STACK_SIZE * CreateTask(...); // Create tasks.
); * ...
/* Set PSP for CoIdleTask coming in */ * OsStart(); // Start multitask.
SetEnvironment(&idle_stk[CFG_IDLE_STACK_SIZE-1]); * @endcode
} *******************************************************************************
*/
void CoInitOS(void)
/** {
******************************************************************************* InitSysTick(); /* Initialize system tick. */
* @brief Start multitask InitInt(); /* Initialize PendSV,SVC,SysTick interrupt */
* @param[in] None CreateTCBList(); /* Create TCB list. */
* @param[out] None #if CFG_EVENT_EN > 0
* @retval None CreateEventList(); /* Create event control list. */
* #endif
* @par Description #if CFG_KHEAP_EN > 0
* @details This function is called to start multitask.After it is called, CoCreateKheap(); /* Create kernel heap within user define */
* OS start schedule task by priority or/and time slice. #endif
* @note This function must be called to start OS when you use CoOS,and must OsSchedLock(); /* Lock Schedule */
* call after CoOsInit(). /* Create first task -- IDLE task. */
******************************************************************************* CoCreateTask( CoIdleTask,
*/ Co_NULL,
void CoStartOS(void) CFG_LOWEST_PRIO,
{ &idle_stk[CFG_IDLE_STACK_SIZE-1],
TCBRunning = &TCBTbl[0]; /* Get running task */ CFG_IDLE_STACK_SIZE
TCBNext = TCBRunning; /* Set next scheduled task as running task */ );
TCBRunning->state = TASK_RUNNING; /* Set running task status to RUNNING */ /* Set PSP for CoIdleTask coming in */
RemoveFromTCBRdyList(TCBRunning); /* Remove running task from READY list */ SetEnvironment(&idle_stk[CFG_IDLE_STACK_SIZE-1]);
OsSchedUnlock(); /* Enable Schedule,call task schedule */ }
}
/**
/** *******************************************************************************
******************************************************************************* * @brief Start multitask
* @brief Get OS version * @param[in] None
* @param[in] None * @param[out] None
* @param[out] None * @retval None
* @retval The value is version of OS mutipled by 100. *
* * @par Description
* @par Description * @details This function is called to start multitask.After it is called,
* @details This function is used to return the version number of CooCox OS. * OS start schedule task by priority or/and time slice.
* the return value corresponds to CooCox's version number multiplied * @note This function must be called to start OS when you use CoOS,and must
* by 100. In other words, version 1.02 would be returned as 102. * call after CoOsInit().
******************************************************************************* *******************************************************************************
*/ */
OS_VER CoGetOSVersion(void) void CoStartOS(void)
{ {
return OS_VERSION; /* Get CooCox CoOS version */ TCBRunning = &TCBTbl[0]; /* Get running task */
} TCBNext = TCBRunning; /* Set next scheduled task as running task */
TCBRunning->state = TASK_RUNNING; /* Set running task status to RUNNING */
RemoveFromTCBRdyList(TCBRunning); /* Remove running task from READY list */
OsSchedUnlock(); /* Enable Schedule,call task schedule */
}
/**
*******************************************************************************
* @brief Get OS version
* @param[in] None
* @param[out] None
* @retval The value is version of OS mutipled by 100.
*
* @par Description
* @details This function is used to return the version number of CooCox OS.
* the return value corresponds to CooCox's version number multiplied
* by 100. In other words, version 1.02 would be returned as 102.
*******************************************************************************
*/
OS_VER CoGetOSVersion(void)
{
return OS_VERSION; /* Get CooCox CoOS version */
}
+435 -410
View File
@@ -1,410 +1,435 @@
/** /**
******************************************************************************* *******************************************************************************
* @file event.c * @file event.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief event management implementation code of CooCox CoOS kernel. * @brief event management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
/*---------------------------- Include ---------------------------------------*/ * notice, this list of conditions and the following disclaimer in the
#include <coocox.h> * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
/*---------------------------- Variable Define -------------------------------*/ * from this software without specific prior written permission.
#if CFG_EVENT_EN > 0 *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ECB EventTbl[CFG_MAX_EVENT]= {{0}};/*!< Table which save event control block.*/ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
P_ECB FreeEventList = Co_NULL; /*!< Pointer to free event control block. */ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 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
* @brief Create a empty list of event control block * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* @param[in] None * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* @param[out] None * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* @retval None * THE POSSIBILITY OF SUCH DAMAGE.
* *
* @par Description * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
* @details This function is called by OSInit() API to create a ECB list,supply *******************************************************************************
* a pointer to next event control block that not used. */
*******************************************************************************
*/
void CreateEventList(void) /*---------------------------- Include ---------------------------------------*/
{ #include <coocox.h>
U8 i;
P_ECB pecb1;
#if CFG_MAX_EVENT > 1 /*---------------------------- Variable Define -------------------------------*/
P_ECB pecb2; #if CFG_EVENT_EN > 0
#endif
i=0; ECB EventTbl[CFG_MAX_EVENT]= {{0}};/*!< Table which save event control block.*/
pecb1 = &EventTbl[0]; /* Get first item */ P_ECB FreeEventList = Co_NULL; /*!< Pointer to free event control block. */
#if CFG_MAX_EVENT == 1 /* Build event list for only one item */
pecb1->eventPtr = Co_NULL;
pecb1->id = i; /* Assign ID. */ /**
pecb1->eventType = EVENT_TYPE_INVALID; /* Sign that not to use. */ *******************************************************************************
#endif * @brief Create a empty list of event control block
* @param[in] None
#if CFG_MAX_EVENT > 1 /* Build event list for more than one item */ * @param[out] None
pecb2 = &EventTbl[1]; * @retval None
for(;i< (CFG_MAX_EVENT-1);i++ ) *
{ * @par Description
pecb1->eventPtr = (void*)pecb2; /* Set link for list */ * @details This function is called by OSInit() API to create a ECB list,supply
pecb1->id = i; /* Assign ID. */ * a pointer to next event control block that not used.
pecb1->eventType = EVENT_TYPE_INVALID;/* Sign that not to use. */ *******************************************************************************
pecb1++; /* Get next item */ */
pecb2++; void CreateEventList(void)
} {
pecb1->eventType = EVENT_TYPE_INVALID; /* Sign that not to use. */ U8 i;
pecb1->eventPtr = Co_NULL; /* Set link for last item */ P_ECB pecb1;
pecb1->id = i; #if CFG_MAX_EVENT > 1
#endif P_ECB pecb2;
#endif
FreeEventList = &EventTbl[0]; /* Set free event item */ i=0;
} pecb1 = &EventTbl[0]; /* Get first item */
#if CFG_MAX_EVENT == 1 /* Build event list for only one item */
pecb1->eventPtr = Co_NULL;
pecb1->id = i; /* Assign ID. */
/** pecb1->eventType = EVENT_TYPE_INVALID; /* Sign that not to use. */
******************************************************************************* #endif
* @brief Release a ECB
* @param[in] pecb A pointer to event control block which be released. #if CFG_MAX_EVENT > 1 /* Build event list for more than one item */
* @param[out] None pecb2 = &EventTbl[1];
* @retval None for(;i< (CFG_MAX_EVENT-1);i++ )
* {
* @par Description pecb1->eventPtr = (void*)pecb2; /* Set link for list */
* @details This function is called to release a event control block when a pecb1->id = i; /* Assign ID. */
* event be deleted. pecb1->eventType = EVENT_TYPE_INVALID;/* Sign that not to use. */
******************************************************************************* pecb1++; /* Get next item */
*/ pecb2++;
static void ReleaseECB(P_ECB pecb) }
{ pecb1->eventType = EVENT_TYPE_INVALID; /* Sign that not to use. */
pecb->eventType = EVENT_TYPE_INVALID; /* Sign that not to use. */ pecb1->eventPtr = Co_NULL; /* Set link for last item */
OsSchedLock(); /* Lock schedule */ pecb1->id = i;
pecb->eventPtr = FreeEventList; /* Release ECB that event hold */ #endif
FreeEventList = pecb; /* Reset free event item */
OsSchedUnlock(); /* Unlock schedule */ FreeEventList = &EventTbl[0]; /* Set free event item */
} }
/** /**
******************************************************************************* *******************************************************************************
* @brief Create a event * @brief Release a ECB
* @param[in] eventType The type of event which being created. * @param[in] pecb A pointer to event control block which be released.
* @param[in] eventSortType Event sort type. * @param[out] None
* @param[in] eventCounter Event counter,ONLY for EVENT_TYPE_SEM. * @retval None
* @param[in] eventPtr Event struct pointer,ONLY for Queue.Co_NULL for other *
* event type. * @par Description
* @param[out] None * @details This function is called to release a event control block when a
* @retval Co_NULL Invalid pointer,create event fail. * event be deleted.
* @retval others Pointer to event control block which had assigned right now. *******************************************************************************
* */
* @par Description static void ReleaseECB(P_ECB pecb)
* @details This function is called by CreateSem(),... {
* to get a event control block and initial the event content. pecb->eventType = EVENT_TYPE_INVALID; /* Sign that not to use. */
* OsSchedLock(); /* Lock schedule */
* @note This is a internal function of CooCox CoOS,User can't call. pecb->eventPtr = FreeEventList; /* Release ECB that event hold */
******************************************************************************* FreeEventList = pecb; /* Reset free event item */
*/ OsSchedUnlock(); /* Unlock schedule */
P_ECB CreatEvent(U8 eventType,U8 eventSortType,void* eventPtr) }
{
P_ECB pecb;
OsSchedLock(); /* Lock schedule */ /**
if(FreeEventList == Co_NULL) /* Is there no free evnet item */ *******************************************************************************
{ * @brief Create a event
OsSchedUnlock(); /* Yes,unlock schedule */ * @param[in] eventType The type of event which being created.
return Co_NULL; /* Return error */ * @param[in] eventSortType Event sort type.
} * @param[in] eventCounter Event counter,ONLY for EVENT_TYPE_SEM.
pecb = FreeEventList;/* Assign the free event item to this event */ * @param[in] eventPtr Event struct pointer,ONLY for Queue.Co_NULL for other
FreeEventList = FreeEventList->eventPtr; /* Reset free event item */ * event type.
OsSchedUnlock(); /* Unlock schedul */ * @param[out] None
* @retval Co_NULL Invalid pointer,create event fail.
pecb->eventType = eventType; /* Initialize event item as user set */ * @retval others Pointer to event control block which had assigned right now.
pecb->eventSortType = eventSortType; *
pecb->eventPtr = eventPtr; * @par Description
pecb->eventTCBList = Co_NULL; * @details This function is called by CreateSem(),...
return pecb; /* Return event item pointer */ * to get a event control block and initial the event content.
} *
* @note This is a internal function of CooCox CoOS,User can't call.
*******************************************************************************
/** */
******************************************************************************* P_ECB CreatEvent(U8 eventType,U8 eventSortType,void* eventPtr)
* @brief Delete a event {
* @param[in] pecb Pointer to event control block which will be deleted. P_ECB pecb;
* @param[in] opt Delete option.
* @arg == OPT_DEL_ANYWAY Delete event always OsSchedLock(); /* Lock schedule */
* @arg == OPT_DEL_NO_PEND Delete event only when no task pending on. if(FreeEventList == Co_NULL) /* Is there no free evnet item */
* @param[out] None {
* @retval E_INVALID_PARAMETER Parameter passed is invalid,deleted fail. OsSchedUnlock(); /* Yes,unlock schedule */
* @retval E_TASK_WAITTING These are one more tasks waitting event. return Co_NULL; /* Return error */
* @retval E_OK Delete event control block successful. }
* pecb = FreeEventList;/* Assign the free event item to this event */
* @par Description FreeEventList = FreeEventList->eventPtr; /* Reset free event item */
* @details This function is called to delete a event from the event wait list OsSchedUnlock(); /* Unlock schedul */
* use specify option.
* pecb->eventType = eventType; /* Initialize event item as user set */
* @note This is a internal function of Coocox CoOS,user can't call. pecb->eventSortType = eventSortType;
******************************************************************************* pecb->eventPtr = eventPtr;
*/ pecb->eventTCBList = Co_NULL;
StatusType DeleteEvent(P_ECB pecb,U8 opt) return pecb; /* Return event item pointer */
{ }
P_OSTCB ptcb;
if(opt == OPT_DEL_NO_PEND) /* Do delete event when no task pend? */
{ /**
if(pecb->eventTCBList != Co_NULL) /* Yes,is there task pend this event? */ *******************************************************************************
{ * @brief Delete a event
return E_TASK_WAITING; /* Yes,error return */ * @param[in] pecb Pointer to event control block which will be deleted.
} * @param[in] opt Delete option.
else * @arg == OPT_DEL_ANYWAY Delete event always
{ * @arg == OPT_DEL_NO_PEND Delete event only when no task pending on.
ReleaseECB(pecb); /* No,release resource that event hold*/ * @param[out] None
} * @retval E_INVALID_PARAMETER Parameter passed is invalid,deleted fail.
} * @retval E_TASK_WAITTING These are one more tasks waitting event.
else if(opt == OPT_DEL_ANYWAY) /* Do delete event anyway? */ * @retval E_OK Delete event control block successful.
{ *
OsSchedLock(); /* Lock schedule */ * @par Description
while(pecb->eventTCBList != Co_NULL) /* Is there task pend this event? */ * @details This function is called to delete a event from the event wait list
{ /* Yes,remove it */ * use specify option.
ptcb = pecb->eventTCBList;/* Get first task in event waiting list */ *
if(ptcb->delayTick != INVALID_VALUE) /* Is task in delay list? */ * @note This is a internal function of Coocox CoOS,user can't call.
{ *******************************************************************************
RemoveDelayList(ptcb); /* Yes,remove task from delay list */ */
} StatusType DeleteEvent(P_ECB pecb,U8 opt)
{
/* Set next item as event waiting list head */ P_OSTCB ptcb;
pecb->eventTCBList = ptcb->waitNext; if(opt == OPT_DEL_NO_PEND) /* Do delete event when no task pend? */
ptcb->waitNext = Co_NULL; /* Clear link for event waiting list */ {
ptcb->eventID = INVALID_ID; /* Sign that not to use. */ if(pecb->eventTCBList != Co_NULL) /* Yes,is there task pend this event? */
{
InsertToTCBRdyList(ptcb); /* Insert task into ready list */ return E_TASK_WAITING; /* Yes,error return */
} }
OsSchedUnlock(); /* Unlock schedule */ else
ReleaseECB(pecb); /* Release resource that event hold */ {
} ReleaseECB(pecb); /* No,release resource that event hold*/
return E_OK; /* Return OK */ }
} }
else if(opt == OPT_DEL_ANYWAY) /* Do delete event anyway? */
{
/** OsSchedLock(); /* Lock schedule */
******************************************************************************* while(pecb->eventTCBList != Co_NULL) /* Is there task pend this event? */
* @brief Insert a task to event wait list { /* Yes,remove it */
* @param[in] pecb Pointer to event control block corresponding to the event. ptcb = pecb->eventTCBList;/* Get first task in event waiting list */
* @param[in] ptcb Pointer to task that will be insert to event wait list. if(ptcb->delayTick != INVALID_VALUE) /* Is task in delay list? */
* @param[out] None {
* @retval None RemoveDelayList(ptcb); /* Yes,remove task from delay list */
* }
* @par Description
* @details This function is called to insert a task by fllowing manner: /* Set next item as event waiting list head */
* opt == EVENT_SORT_TYPE_FIFO By FIFO. pecb->eventTCBList = ptcb->waitNext;
* opt == EVENT_SORT_TYPE_PRIO By priority order,hghest priority ptcb->waitNext = Co_NULL; /* Clear link for event waiting list */
* as head,lowest priority as end. ptcb->eventID = INVALID_ID; /* Sign that not to use. */
* (Highest-->...-->Lowest-->Co_NULL)
******************************************************************************* InsertToTCBRdyList(ptcb); /* Insert task into ready list */
*/ }
void EventTaskToWait(P_ECB pecb,P_OSTCB ptcb) OsSchedUnlock(); /* Unlock schedule */
{ ReleaseECB(pecb); /* Release resource that event hold */
P_OSTCB ptcb1; }
#if (CFG_EVENT_SORT == 2) || (CFG_EVENT_SORT == 3) return E_OK; /* Return OK */
P_OSTCB ptcb2; }
#endif
OsSchedLock(); /* Lock schedule */ /**
ptcb1 = pecb->eventTCBList; /* Get first task in event waiting list */ *******************************************************************************
ptcb->eventID = pecb->id; /* Set event ID for task */ * @brief Insert a task to event wait list
* @param[in] pecb Pointer to event control block corresponding to the event.
#if CFG_EVENT_SORT == 3 /* Does event waiting list sort as FIFO? */ * @param[in] ptcb Pointer to task that will be insert to event wait list.
* @param[out] None
if(pecb->eventSortType == EVENT_SORT_TYPE_FIFO) * @retval None
#endif *
* @par Description
#if (CFG_EVENT_SORT == 1) || (CFG_EVENT_SORT == 3) * @details This function is called to insert a task by fllowing manner:
{ * opt == EVENT_SORT_TYPE_FIFO By FIFO.
if(ptcb1 == Co_NULL) /* Is no item in event waiting list?*/ * opt == EVENT_SORT_TYPE_PRIO By priority order,hghest priority
{ * as head,lowest priority as end.
pecb->eventTCBList = ptcb; /* Yes,set task as first item */ * (Highest-->...-->Lowest-->Co_NULL)
} *******************************************************************************
else */
{ void EventTaskToWait(P_ECB pecb,P_OSTCB ptcb)
while(ptcb1->waitNext != Co_NULL)/* No,insert task in last */ {
{ P_OSTCB ptcb1;
ptcb1 = ptcb1->waitNext; #if (CFG_EVENT_SORT == 2) || (CFG_EVENT_SORT == 3)
} P_OSTCB ptcb2;
ptcb1->waitNext = ptcb; /* Set link for list */ #endif
ptcb->waitPrev = ptcb1;
} OsSchedLock(); /* Lock schedule */
} ptcb1 = pecb->eventTCBList; /* Get first task in event waiting list */
#endif ptcb->eventID = pecb->id; /* Set event ID for task */
#if CFG_EVENT_SORT ==3 /* Does event waiting list sort as preemptive priority?*/ #if CFG_EVENT_SORT == 3 /* Does event waiting list sort as FIFO? */
else if(pecb->eventSortType == EVENT_SORT_TYPE_PRIO)
#endif if(pecb->eventSortType == EVENT_SORT_TYPE_FIFO)
#if (CFG_EVENT_SORT == 2) || (CFG_EVENT_SORT == 3) #endif
{
if(ptcb1 == Co_NULL) /* Is no item in event waiting list? */ #if (CFG_EVENT_SORT == 1) || (CFG_EVENT_SORT == 3)
{ {
pecb->eventTCBList = ptcb; /* Yes,set task as first item */ if(ptcb1 == Co_NULL) /* Is no item in event waiting list?*/
} {
/* Is PRI of task higher than list first item? */ pecb->eventTCBList = ptcb; /* Yes,set task as first item */
else if(ptcb1->prio > ptcb->prio) }
{ else
pecb->eventTCBList = ptcb; /* Reset task as first item */ {
ptcb->waitNext = ptcb1; /* Set link for list */ while(ptcb1->waitNext != Co_NULL)/* No,insert task in last */
ptcb1->waitPrev = ptcb; {
} ptcb1 = ptcb1->waitNext;
else /* No,find correct place to insert */ }
{ ptcb1->waitNext = ptcb; /* Set link for list */
ptcb2 = ptcb1->waitNext; ptcb->waitPrev = ptcb1;
while(ptcb2 != Co_NULL) /* Is last item? */ }
{ }
if(ptcb2->prio > ptcb->prio) /* No,is correct place? */ #endif
{
break; /* Yes,break Circulation */ #if CFG_EVENT_SORT ==3 /* Does event waiting list sort as preemptive priority?*/
} else if(pecb->eventSortType == EVENT_SORT_TYPE_PRIO)
ptcb1 = ptcb2; /* Save current item */ #endif
ptcb2 = ptcb2->waitNext; /* Get next item */ #if (CFG_EVENT_SORT == 2) || (CFG_EVENT_SORT == 3)
} {
ptcb1->waitNext = ptcb; /* Set link for list */ if(ptcb1 == Co_NULL) /* Is no item in event waiting list? */
ptcb->waitPrev = ptcb1; {
ptcb->waitNext = ptcb2; pecb->eventTCBList = ptcb; /* Yes,set task as first item */
if(ptcb2 != Co_NULL) }
{ /* Is PRI of task higher than list first item? */
ptcb2->waitPrev = ptcb; else if(ptcb1->prio > ptcb->prio)
} {
} pecb->eventTCBList = ptcb; /* Reset task as first item */
} ptcb->waitNext = ptcb1; /* Set link for list */
#endif ptcb1->waitPrev = ptcb;
ptcb->state = TASK_WAITING; /* Set task status to TASK_WAITING state */ }
TaskSchedReq = Co_TRUE; else /* No,find correct place to insert */
OsSchedUnlock(); /* Unlock schedule,and call task schedule */ {
} ptcb2 = ptcb1->waitNext;
while(ptcb2 != Co_NULL) /* Is last item? */
{
/** if(ptcb2->prio > ptcb->prio) /* No,is correct place? */
******************************************************************************* {
* @brief Move a task from event WAITING list to the DELAY list break; /* Yes,break Circulation */
* @param[in] pecb Pointer to event control block corresponding to the event. }
* @param[out] None ptcb1 = ptcb2; /* Save current item */
* @retval None ptcb2 = ptcb2->waitNext; /* Get next item */
* }
* @par Description ptcb1->waitNext = ptcb; /* Set link for list */
* @details This function is called to remove a task from event wait list,and ptcb->waitPrev = ptcb1;
* then insert it into the READY list. ptcb->waitNext = ptcb2;
******************************************************************************* if(ptcb2 != Co_NULL)
*/ {
void EventTaskToRdy(P_ECB pecb) ptcb2->waitPrev = ptcb;
{ }
P_OSTCB ptcb; }
#if CFG_QUEUE_EN >0 }
P_QCB pqcb; #endif
#endif ptcb->state = TASK_WAITING; /* Set task status to TASK_WAITING state */
ptcb = pecb->eventTCBList; TaskSchedReq = Co_TRUE;
if(ptcb == Co_NULL) OsSchedUnlock(); /* Unlock schedule,and call task schedule */
return; }
pecb->eventTCBList = ptcb->waitNext;/* Get first task in event waiting list*/
if(pecb->eventTCBList != Co_NULL) /* Is no item in event waiting list? */ /**
{ *******************************************************************************
pecb->eventTCBList->waitPrev = Co_NULL; /* No,clear link for first item */ * @brief Move a task from event WAITING list to the DELAY list
} * @param[in] pecb Pointer to event control block corresponding to the event.
* @param[out] None
ptcb->waitNext = Co_NULL; /* Clear event waiting link for task*/ * @retval None
ptcb->eventID = INVALID_ID; /* Sign that not to use. */ *
* @par Description
if(ptcb->delayTick != INVALID_VALUE) /* Is task in delay list? */ * @details This function is called to remove a task from event wait list,and
{ * then insert it into the READY list.
RemoveDelayList(ptcb); /* Yes,remove task from DELAY list */ *******************************************************************************
} */
if(pecb->eventType == EVENT_TYPE_MBOX)/* Is it a mailbox event? */ void EventTaskToRdy(P_ECB pecb)
{ {
ptcb->pmail = pecb->eventPtr; /* Yes,send mail to task */ P_OSTCB ptcb;
pecb->eventPtr = Co_NULL; /* Clear event sign */ #if CFG_QUEUE_EN >0
pecb->eventCounter--; P_QCB pqcb;
} #endif
#if CFG_QUEUE_EN >0 ptcb = pecb->eventTCBList;
else if(pecb->eventType == EVENT_TYPE_QUEUE) /* Is it a queue event? */ if(ptcb == Co_NULL)
{ return;
pqcb = (P_QCB)pecb->eventPtr; /* Yes,get queue pointer */
ptcb->pmail = *(pqcb->qStart + pqcb->head); /* Send mail to task */ pecb->eventTCBList = ptcb->waitNext;/* Get first task in event waiting list*/
pqcb->head++; /* Clear event sign */ if(pecb->eventTCBList != Co_NULL) /* Is no item in event waiting list? */
pqcb->qSize--; {
if(pqcb->head == pqcb->qMaxSize) pecb->eventTCBList->waitPrev = Co_NULL; /* No,clear link for first item */
{ }
pqcb->head = 0;
} ptcb->waitNext = Co_NULL; /* Clear event waiting link for task*/
} ptcb->eventID = INVALID_ID; /* Sign that not to use. */
#endif
if(ptcb->delayTick != INVALID_VALUE) /* Is task in delay list? */
#if CFG_MAILBOX_EN >0 {
else if(pecb->eventType == EVENT_TYPE_SEM)/* Is it a semaphore event? */ RemoveDelayList(ptcb); /* Yes,remove task from DELAY list */
{ }
pecb->eventCounter--; /* Yes,clear event sign */ #if CFG_MAILBOX_EN >0
ptcb->pmail = (void*)0xffffffff; /* Indicate task woke by event */ if(pecb->eventType == EVENT_TYPE_MBOX)/* Is it a mailbox event? */
} {
#endif ptcb->pmail = pecb->eventPtr; /* Yes,send mail to task */
if(ptcb == TCBRunning) pecb->eventPtr = Co_NULL; /* Clear event sign */
{ //pecb->eventCounter--;
ptcb->state = TASK_RUNNING; }
} #endif
else #if CFG_QUEUE_EN >0
{ else if(pecb->eventType == EVENT_TYPE_QUEUE) /* Is it a queue event? */
InsertToTCBRdyList(ptcb); /* Insert task into ready list */ {
} pqcb = (P_QCB)pecb->eventPtr; /* Yes,get queue pointer */
} ptcb->pmail = *(pqcb->qStart + pqcb->head); /* Send mail to task */
//pqcb->head++; /* Clear event sign */
//pqcb->qSize--;
//if(pqcb->head == pqcb->qMaxSize)
/** //{
******************************************************************************* // pqcb->head = 0;
* @brief Move a task from event wait list to the ready list //}
* @param[in] pecb Pointer to event control block corresponding to the event. }
* @param[out] None #endif
* @retval None
* #if CFG_SEM_EN >0
* @par Description else if(pecb->eventType == EVENT_TYPE_SEM)/* Is it a semaphore event? */
* @details This function is called to remove a task from event wait list,and {
* then insert it to the ready list. //pecb->eventCounter--; /* Yes,clear event sign */
******************************************************************************* ptcb->pmail = (void*)0xffffffff; /* Indicate task woke by event */
*/ }
void RemoveEventWaittingList(P_OSTCB ptcb) #endif
{ if(ptcb == TCBRunning)
P_ECB pecb; {
pecb = &EventTbl[ptcb->eventID]; /* Get event control block */ ptcb->state = TASK_RUNNING;
}
/* Is there only one item in event waiting list? */ else
if((ptcb->waitNext == Co_NULL) && (ptcb->waitPrev == Co_NULL)) {
{ InsertToTCBRdyList(ptcb); /* Insert task into ready list */
pecb->eventTCBList = Co_NULL; /* Yes,set event waiting list as Co_NULL */ }
} }
else if(ptcb->waitPrev == Co_NULL)/* Is the first item in event waiting list?*/
{
/* Yes,remove task from list,and reset event waiting list */
ptcb->waitNext->waitPrev = Co_NULL; /**
pecb->eventTCBList = ptcb->waitNext; *******************************************************************************
ptcb->waitNext = Co_NULL; * @brief Move a task from event wait list to the ready list
} * @param[in] pecb Pointer to event control block corresponding to the event.
else if(ptcb->waitNext == Co_NULL)/* Is the last item in event waiting list? */ * @param[out] None
{ * @retval None
ptcb->waitPrev->waitNext = Co_NULL; /* Yes,remove task form list */ *
ptcb->waitPrev = Co_NULL; * @par Description
} * @details This function is called to remove a task from event wait list,and
else /* No, remove task from list */ * then insert it to the ready list.
{ *******************************************************************************
ptcb->waitPrev->waitNext = ptcb->waitNext; */
ptcb->waitNext->waitPrev = ptcb->waitPrev; void RemoveEventWaittingList(P_OSTCB ptcb)
ptcb->waitPrev = Co_NULL; {
ptcb->waitNext = Co_NULL; P_ECB pecb;
} pecb = &EventTbl[ptcb->eventID]; /* Get event control block */
ptcb->eventID = INVALID_ID; /* Sign that not to use. */
} /* Is there only one item in event waiting list? */
if((ptcb->waitNext == Co_NULL) && (ptcb->waitPrev == Co_NULL))
#endif //CFG_EVENT_EN {
pecb->eventTCBList = Co_NULL; /* Yes,set event waiting list as Co_NULL */
}
else if(ptcb->waitPrev == Co_NULL)/* Is the first item in event waiting list?*/
{
/* Yes,remove task from list,and reset event waiting list */
ptcb->waitNext->waitPrev = Co_NULL;
pecb->eventTCBList = ptcb->waitNext;
ptcb->waitNext = Co_NULL;
}
else if(ptcb->waitNext == Co_NULL)/* Is the last item in event waiting list? */
{
ptcb->waitPrev->waitNext = Co_NULL; /* Yes,remove task form list */
ptcb->waitPrev = Co_NULL;
}
else /* No, remove task from list */
{
ptcb->waitPrev->waitNext = ptcb->waitNext;
ptcb->waitNext->waitPrev = ptcb->waitPrev;
ptcb->waitPrev = Co_NULL;
ptcb->waitNext = Co_NULL;
}
ptcb->eventID = INVALID_ID; /* Sign that not to use. */
}
#endif //CFG_EVENT_EN
File diff suppressed because it is too large Load Diff
+88 -65
View File
@@ -1,65 +1,88 @@
/** /**
******************************************************************************* *******************************************************************************
* @file hook.c * @file hook.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief hook management implementation code of CooCox CoOS kernel. * @brief hook management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
/*---------------------------- Inlcude --------------------------------------*/ * notice, this list of conditions and the following disclaimer in the
#include <coocox.h> * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
/** * contributors may be used to endorse or promote products derived
******************************************************************************* * from this software without specific prior written permission.
* @brief IDLE task of OS *
* @param[in] pdata The parameter passed to IDLE task. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* @param[out] None * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* @retval None * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* @par Description * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* @details This function is system IDLE task code. * 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
void CoIdleTask(void* pdata) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
{ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
/* Add your codes here */ * THE POSSIBILITY OF SUCH DAMAGE.
for(; ;) *
{ * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
/* Add your codes here */ *******************************************************************************
} */
}
/*---------------------------- Inlcude --------------------------------------*/
/** #include <coocox.h>
*******************************************************************************
* @brief Hook for stack overflow /**
* @param[in] taskID Piont to the task which lead to stack overflow. *******************************************************************************
* @param[out] None * @brief IDLE task of OS
* @retval None * @param[in] pdata The parameter passed to IDLE task.
* * @param[out] None
* @par Description * @retval None
* @details This function is a hook for stack overflow. *
******************************************************************************* * @par Description
*/ * @details This function is system IDLE task code.
void CoStkOverflowHook(OS_TID taskID) *******************************************************************************
{ */
/* Process stack overflow here */ void CoIdleTask(void* pdata)
for(; ;) {
{ /* Add your codes here */
for(; ;)
} {
} /* Add your codes here */
}
}
/**
*******************************************************************************
* @brief Hook for stack overflow
* @param[in] taskID Piont to the task which lead to stack overflow.
* @param[out] None
* @retval None
*
* @par Description
* @details This function is a hook for stack overflow.
*******************************************************************************
*/
void CoStkOverflowHook(OS_TID taskID)
{
/* Process stack overflow here */
for(; ;)
{
}
}
+432 -409
View File
@@ -1,409 +1,432 @@
/** /**
******************************************************************************* *******************************************************************************
* @file kernelHeap.c * @file kernelHeap.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief kernel heap management implementation code of CooCox CoOS kernel. * @brief kernel heap management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
/*---------------------------- Include ---------------------------------------*/ * notice, this list of conditions and the following disclaimer in the
#include <coocox.h> * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
#if CFG_KHEAP_EN >0 * from this software without specific prior written permission.
/*---------------------------- Variable Define -------------------------------*/ *
U32 KernelHeap[KHEAP_SIZE] = {0}; /*!< Kernel heap */ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
P_FMB FMBlist = Co_NULL; /*!< Free memory block list */ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
KHeap Kheap = {0}; /*!< Kernel heap control */ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
/*---------------------------- Function Declare ------------------------------*/ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
static P_FMB GetPreFMB(P_UMB usedMB); * 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)
* @brief Create kernel heap * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* @param[in] None * THE POSSIBILITY OF SUCH DAMAGE.
* @param[out] None *
* @retval None * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
* *******************************************************************************
* @par Description */
* @details This function is called to create kernel heap.
*******************************************************************************
*/ /*---------------------------- Include ---------------------------------------*/
void CoCreateKheap(void) #include <coocox.h>
{
Kheap.startAddr = (U32)(KernelHeap); /* Initialize kernel heap control */
Kheap.endAddr = (U32)(KernelHeap) + KHEAP_SIZE*4; #if CFG_KHEAP_EN >0
FMBlist = (P_FMB)KernelHeap; /* Initialize free memory block list*/ /*---------------------------- Variable Define -------------------------------*/
FMBlist->nextFMB = Co_NULL; U32 KernelHeap[KHEAP_SIZE] = {0}; /*!< Kernel heap */
FMBlist->nextUMB = Co_NULL; P_FMB FMBlist = Co_NULL; /*!< Free memory block list */
FMBlist->preUMB = Co_NULL; KHeap Kheap = {0}; /*!< Kernel heap control */
}
/*---------------------------- Function Declare ------------------------------*/
/** static P_FMB GetPreFMB(P_UMB usedMB);
******************************************************************************* /**
* @brief Allocation size bytes of memory block from kernel heap. *******************************************************************************
* @param[in] size Length of menory block. * @brief Create kernel heap
* @param[out] None * @param[in] None
* @retval Co_NULL Allocate fail. * @param[out] None
* @retval others Pointer to memory block. * @retval None
* *
* @par Description * @par Description
* @details This function is called to allocation size bytes of memory block. * @details This function is called to create kernel heap.
******************************************************************************* *******************************************************************************
*/ */
void* CoKmalloc(U32 size) void CoCreateKheap(void)
{ {
P_FMB freeMB,newFMB,preFMB; Kheap.startAddr = (U32)(KernelHeap); /* Initialize kernel heap control */
P_UMB usedMB,tmpUMB; Kheap.endAddr = (U32)(KernelHeap) + KHEAP_SIZE*4;
U8* memAddr; FMBlist = (P_FMB)KernelHeap; /* Initialize free memory block list*/
U32 freeSize; FMBlist->nextFMB = Co_NULL;
U32 kheapAddr; FMBlist->nextUMB = Co_NULL;
FMBlist->preUMB = Co_NULL;
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ }
if( size == 0 )
{
return Co_NULL; /**
} *******************************************************************************
#endif * @brief Allocation size bytes of memory block from kernel heap.
* @param[in] size Length of menory block.
/* Word alignment,and add used memory head size */ * @param[out] None
size = (((size+3)>>2)<<2) + 8; * @retval Co_NULL Allocate fail.
kheapAddr = Kheap.endAddr; /* Get the end address of kernel heap */ * @retval others Pointer to memory block.
OsSchedLock(); /* Lock schedule */ *
freeMB = FMBlist; /* Get first item of free memory list */ * @par Description
preFMB = Co_NULL; * @details This function is called to allocation size bytes of memory block.
while(freeMB != Co_NULL ) /* Is out of free memory list? */ *******************************************************************************
{ /* No */ */
if(freeMB->nextUMB == Co_NULL) /* Is last item of free memory list? */ void* CoKmalloc(U32 size)
{ /* Yes,get size for this free item */ {
freeSize = kheapAddr - (U32)(freeMB); P_FMB freeMB,newFMB,preFMB;
} P_UMB usedMB,tmpUMB;
else /* No,get size for this free item */ U8* memAddr;
{ U32 freeSize;
freeSize = (U32)(freeMB->nextUMB) -1 - (U32)(freeMB); U32 kheapAddr;
}
if(freeSize >= size) /* If the size equal or greater than need */ #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
{ /* Yes,assign in this free memory */ if( size == 0 )
usedMB=(P_UMB)freeMB;/* Get the address for used memory block head*/ {
return Co_NULL;
/* Get the address for used memory block */ }
memAddr = (U8*)((U32)(usedMB) + 8); #endif
/* Is left size of free memory smaller than 12? */ /* Word alignment,and add used memory head size */
if((freeSize-size) < 12) size = (((size+3)>>2)<<2) + 8;
{ kheapAddr = Kheap.endAddr; /* Get the end address of kernel heap */
/* Yes,malloc together(12 is the size of the header information OsSchedLock(); /* Lock schedule */
of free memory block ). */ freeMB = FMBlist; /* Get first item of free memory list */
if(preFMB != Co_NULL)/* Is first item of free memory block list? */ preFMB = Co_NULL;
{ /* No,set the link for list */ while(freeMB != Co_NULL ) /* Is out of free memory list? */
preFMB->nextFMB = freeMB->nextFMB; { /* No */
} if(freeMB->nextUMB == Co_NULL) /* Is last item of free memory list? */
else /* Yes,reset the first item */ { /* Yes,get size for this free item */
{ freeSize = kheapAddr - (U32)(freeMB);
FMBlist = freeMB->nextFMB; }
} else /* No,get size for this free item */
{
if(freeMB->nextUMB != Co_NULL) /* Is last item? */ freeSize = (U32)(freeMB->nextUMB) -1 - (U32)(freeMB);
{ /* No,set the link for list */ }
tmpUMB = (P_UMB)((U32)(freeMB->nextUMB)-1); if(freeSize >= size) /* If the size equal or greater than need */
tmpUMB->preMB = (void*)((U32)usedMB|0x1); { /* Yes,assign in this free memory */
} usedMB=(P_UMB)freeMB;/* Get the address for used memory block head*/
usedMB->nextMB = freeMB->nextUMB;/* Set used memory block link*/ /* Get the address for used memory block */
usedMB->preMB = freeMB->preUMB; memAddr = (U8*)((U32)(usedMB) + 8);
}
else /* No,the left size more than 12 */ /* Is left size of free memory smaller than 12? */
{ if((freeSize-size) < 12)
/* Get new free memory block address */ {
newFMB = (P_FMB)((U32)(freeMB) + size); /* Yes,malloc together(12 is the size of the header information
of free memory block ). */
if(preFMB != Co_NULL)/* Is first item of free memory block list? */ if(preFMB != Co_NULL)/* Is first item of free memory block list? */
{ { /* No,set the link for list */
preFMB->nextFMB = newFMB; /* No,set the link for list */ preFMB->nextFMB = freeMB->nextFMB;
} }
else else /* Yes,reset the first item */
{ {
FMBlist = newFMB; /* Yes,reset the first item */ FMBlist = freeMB->nextFMB;
} }
/* Set link for new free memory block */ if(freeMB->nextUMB != Co_NULL) /* Is last item? */
newFMB->preUMB = (P_UMB)((U32)usedMB|0x1); { /* No,set the link for list */
newFMB->nextUMB = freeMB->nextUMB; tmpUMB = (P_UMB)((U32)(freeMB->nextUMB)-1);
newFMB->nextFMB = freeMB->nextFMB; tmpUMB->preMB = (void*)((U32)usedMB|0x1);
}
if(freeMB->nextUMB != Co_NULL) /* Is last item? */
{ /* No,set the link for list */ usedMB->nextMB = freeMB->nextUMB;/* Set used memory block link*/
tmpUMB = (P_UMB)((U32)(freeMB->nextUMB)-1); usedMB->preMB = freeMB->preUMB;
tmpUMB->preMB = newFMB; }
} else /* No,the left size more than 12 */
{
usedMB->nextMB = newFMB; /* Set used memory block link */ /* Get new free memory block address */
usedMB->preMB = freeMB->preUMB; newFMB = (P_FMB)((U32)(freeMB) + size);
}
if(preFMB != Co_NULL)/* Is first item of free memory block list? */
if(freeMB->preUMB != Co_NULL) /* Is first item? */ {
{ /* No,set the link for list */ preFMB->nextFMB = newFMB; /* No,set the link for list */
tmpUMB = (P_UMB)((U32)(freeMB->preUMB)-1); }
tmpUMB->nextMB = (void*)((U32)usedMB|0x1); else
} {
FMBlist = newFMB; /* Yes,reset the first item */
OsSchedUnlock(); /* Unlock schedule */ }
return memAddr; /* Return used memory block address */
} /* Set link for new free memory block */
preFMB = freeMB; /* Save current free memory block as previous */ newFMB->preUMB = (P_UMB)((U32)usedMB|0x1);
freeMB = freeMB->nextFMB; /* Get the next item as current item*/ newFMB->nextUMB = freeMB->nextUMB;
} newFMB->nextFMB = freeMB->nextFMB;
OsSchedUnlock(); /* Unlock schedule */
return Co_NULL; /* Error return */ if(freeMB->nextUMB != Co_NULL) /* Is last item? */
} { /* No,set the link for list */
tmpUMB = (P_UMB)((U32)(freeMB->nextUMB)-1);
tmpUMB->preMB = newFMB;
/** }
*******************************************************************************
* @brief Release memory block to kernel heap. usedMB->nextMB = newFMB; /* Set used memory block link */
* @param[in] memBuf Pointer to memory block. usedMB->preMB = freeMB->preUMB;
* @param[out] None }
* @retval None
* if(freeMB->preUMB != Co_NULL) /* Is first item? */
* @par Description { /* No,set the link for list */
* @details This function is called to release memory block. tmpUMB = (P_UMB)((U32)(freeMB->preUMB)-1);
******************************************************************************* tmpUMB->nextMB = (void*)((U32)usedMB|0x1);
*/ }
void CoKfree(void* memBuf)
{ OsSchedUnlock(); /* Unlock schedule */
P_FMB curFMB,nextFMB,preFMB; return memAddr; /* Return used memory block address */
P_UMB usedMB,nextUMB,preUMB; }
preFMB = freeMB; /* Save current free memory block as previous */
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ freeMB = freeMB->nextFMB; /* Get the next item as current item*/
if(memBuf == Co_NULL) }
{ OsSchedUnlock(); /* Unlock schedule */
return; return Co_NULL; /* Error return */
} }
#endif
usedMB = (P_UMB)((U32)(memBuf)-8); /**
*******************************************************************************
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ * @brief Release memory block to kernel heap.
if((U32)(memBuf) < Kheap.startAddr) * @param[in] memBuf Pointer to memory block.
{ * @param[out] None
return; * @retval None
} *
if((U32)(memBuf) > Kheap.endAddr) * @par Description
{ * @details This function is called to release memory block.
return; *******************************************************************************
} */
#endif void CoKfree(void* memBuf)
{
P_FMB curFMB,nextFMB,preFMB;
OsSchedLock(); /* Lock schedule */ P_UMB usedMB,nextUMB,preUMB;
#if CFG_PAR_CHECKOUT_EN >0 /* Check UMB in list */ #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
if((U32)(usedMB) < (U32)(FMBlist)) if(memBuf == Co_NULL)
{ {
preUMB = (P_UMB)((U32)(FMBlist->preUMB)-1); return;
while(preUMB != usedMB) }
{ #endif
if(preUMB == Co_NULL)
{ usedMB = (P_UMB)((U32)(memBuf)-8);
OsSchedUnlock();
return; #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
} if((U32)(memBuf) < Kheap.startAddr)
preUMB = (P_UMB)((U32)(preUMB->preMB)-1); {
} return;
} }
else if((U32)(memBuf) > Kheap.endAddr)
{ {
if(FMBlist == Co_NULL) return;
{ }
nextUMB = (P_UMB)(Kheap.startAddr); #endif
}
else
{ OsSchedLock(); /* Lock schedule */
if(FMBlist->nextUMB != Co_NULL)
{ #if CFG_PAR_CHECKOUT_EN >0 /* Check UMB in list */
nextUMB = (P_UMB)((U32)(FMBlist->nextUMB)-1); if((U32)(usedMB) < (U32)(FMBlist))
} {
else preUMB = (P_UMB)((U32)(FMBlist->preUMB)-1);
{ while(preUMB != usedMB)
nextUMB = Co_NULL; {
} if(preUMB == Co_NULL)
} {
OsSchedUnlock();
while(nextUMB != usedMB) return;
{ }
if(nextUMB == Co_NULL) preUMB = (P_UMB)((U32)(preUMB->preMB)-1);
{ }
OsSchedUnlock(); }
return; else
} {
if(((U32)(nextUMB->nextMB)&0x1) == 0) if(FMBlist == Co_NULL)
{ {
nextFMB = (P_FMB)(nextUMB->nextMB); nextUMB = (P_UMB)(Kheap.startAddr);
nextUMB = (P_UMB)((U32)(nextFMB->nextUMB)-1); }
} else
else {
{ if(FMBlist->nextUMB != Co_NULL)
nextUMB = (P_UMB)((U32)(nextUMB->nextMB)-1); {
} nextUMB = (P_UMB)((U32)(FMBlist->nextUMB)-1);
} }
} else
#endif {
nextUMB = Co_NULL;
}
/* Is between two free memory block? */ }
if( (((U32)(usedMB->nextMB)&0x1) == 0) && (((U32)(usedMB->preMB)&0x1)==0) )
{ /* Yes,is the only one item in kernel heap? */ while(nextUMB != usedMB)
if((usedMB->nextMB == Co_NULL) && (usedMB->preMB == Co_NULL)) {
{ if(nextUMB == Co_NULL)
curFMB = (P_FMB)usedMB; /* Yes,release this item */ {
curFMB->nextFMB = Co_NULL; OsSchedUnlock();
curFMB->nextUMB = Co_NULL; return;
curFMB->preUMB = Co_NULL; }
FMBlist = curFMB; if(((U32)(nextUMB->nextMB)&0x1) == 0)
} {
else if(usedMB->preMB == Co_NULL) /* Is the first item in kernel heap */ nextFMB = (P_FMB)(nextUMB->nextMB);
{ nextUMB = (P_UMB)((U32)(nextFMB->nextUMB)-1);
/* Yes,release this item,and set link for list */ }
curFMB = (P_FMB)usedMB; else
nextFMB = (P_FMB)usedMB->nextMB; {
nextUMB = (P_UMB)((U32)(nextUMB->nextMB)-1);
curFMB->nextFMB = nextFMB->nextFMB; }
curFMB->nextUMB = nextFMB->nextUMB; }
curFMB->preUMB = Co_NULL; }
FMBlist = curFMB; #endif
}
else if(usedMB->nextMB == Co_NULL) /* Is the last item in kernel heap */
{ /* Yes,release this item,and set link for list */ /* Is between two free memory block? */
curFMB = (P_FMB)(usedMB->preMB); if( (((U32)(usedMB->nextMB)&0x1) == 0) && (((U32)(usedMB->preMB)&0x1)==0) )
curFMB->nextFMB = Co_NULL; { /* Yes,is the only one item in kernel heap? */
curFMB->nextUMB = Co_NULL; if((usedMB->nextMB == Co_NULL) && (usedMB->preMB == Co_NULL))
} {
else /* All no,show this item between two normal FMB */ curFMB = (P_FMB)usedMB; /* Yes,release this item */
{ curFMB->nextFMB = Co_NULL;
/* release this item,and set link for list */ curFMB->nextUMB = Co_NULL;
nextFMB = (P_FMB)usedMB->nextMB; curFMB->preUMB = Co_NULL;
curFMB = (P_FMB)(usedMB->preMB); FMBlist = curFMB;
}
curFMB->nextFMB = nextFMB->nextFMB; else if(usedMB->preMB == Co_NULL) /* Is the first item in kernel heap */
curFMB->nextUMB = nextFMB->nextUMB; {
} /* Yes,release this item,and set link for list */
} curFMB = (P_FMB)usedMB;
else if(((U32)(usedMB->preMB)&0x1) == 0) /* Is between FMB and UMB? */ nextFMB = (P_FMB)usedMB->nextMB;
{
if(usedMB->preMB == Co_NULL) /* Yes,is the first item in kernel heap? */ curFMB->nextFMB = nextFMB->nextFMB;
{ curFMB->nextUMB = nextFMB->nextUMB;
/* Yes,release this item,and set link for list */ curFMB->preUMB = Co_NULL;
curFMB = (P_FMB)usedMB; FMBlist = curFMB;
nextUMB = (P_UMB)usedMB->nextMB; }
curFMB->nextUMB = nextUMB; else if(usedMB->nextMB == Co_NULL) /* Is the last item in kernel heap */
curFMB->preUMB = Co_NULL; { /* Yes,release this item,and set link for list */
curFMB->nextFMB = FMBlist; curFMB = (P_FMB)(usedMB->preMB);
FMBlist = curFMB; curFMB->nextFMB = Co_NULL;
} curFMB->nextUMB = Co_NULL;
else /* No,release this item,and set link for list */ }
{ else /* All no,show this item between two normal FMB */
curFMB = (P_FMB)usedMB->preMB; {
nextUMB = (P_UMB)usedMB->nextMB; /* release this item,and set link for list */
curFMB->nextUMB = nextUMB; nextFMB = (P_FMB)usedMB->nextMB;
} curFMB = (P_FMB)(usedMB->preMB);
} curFMB->nextFMB = nextFMB->nextFMB;
else if(((U32)(usedMB->nextMB)&0x1) == 0) /* Is between UMB and FMB? */ curFMB->nextUMB = nextFMB->nextUMB;
{ /* Yes */ }
preUMB = (P_UMB)(usedMB->preMB); /* Get previous UMB */ }
curFMB = (P_FMB)(usedMB); /* new FMB */ else if(((U32)(usedMB->preMB)&0x1) == 0) /* Is between FMB and UMB? */
preFMB = GetPreFMB(usedMB); /* Get previous FMB */ {
if(preFMB == Co_NULL) /* Is previous FMB==Co_NULL? */ if(usedMB->preMB == Co_NULL) /* Yes,is the first item in kernel heap? */
{ {
nextFMB = FMBlist; /* Yes,get next FMB */ /* Yes,release this item,and set link for list */
FMBlist = curFMB; /* Reset new FMB as the first item of FMB list*/ curFMB = (P_FMB)usedMB;
} nextUMB = (P_UMB)usedMB->nextMB;
else curFMB->nextUMB = nextUMB;
{ curFMB->preUMB = Co_NULL;
nextFMB = preFMB->nextFMB; /* No,get next FMB */ curFMB->nextFMB = FMBlist;
preFMB->nextFMB = curFMB; /* Set link for FMB list */ FMBlist = curFMB;
} }
else /* No,release this item,and set link for list */
if(nextFMB == Co_NULL) /* Is new FMB as last item of FMB list? */ {
{ curFMB = (P_FMB)usedMB->preMB;
curFMB->preUMB = preUMB; /* Yes,set link for list */ nextUMB = (P_UMB)usedMB->nextMB;
curFMB->nextUMB = Co_NULL; curFMB->nextUMB = nextUMB;
curFMB->nextFMB = Co_NULL; }
}
else }
{ else if(((U32)(usedMB->nextMB)&0x1) == 0) /* Is between UMB and FMB? */
curFMB->preUMB = preUMB; /* No,set link for list */ { /* Yes */
curFMB->nextUMB = nextFMB->nextUMB; preUMB = (P_UMB)(usedMB->preMB); /* Get previous UMB */
curFMB->nextFMB = nextFMB->nextFMB; curFMB = (P_FMB)(usedMB); /* new FMB */
} preFMB = GetPreFMB(usedMB); /* Get previous FMB */
} if(preFMB == Co_NULL) /* Is previous FMB==Co_NULL? */
else /* All no,show UMB between two UMB*/ {
{ nextFMB = FMBlist; /* Yes,get next FMB */
curFMB = (P_FMB)(usedMB); /* new FMB */ FMBlist = curFMB; /* Reset new FMB as the first item of FMB list*/
preFMB = GetPreFMB(usedMB); /* Get previous FMB */ }
preUMB = (P_UMB)(usedMB->preMB); /* Get previous UMB */ else
nextUMB = (P_UMB)(usedMB->nextMB); /* Get next UMB */ {
nextFMB = preFMB->nextFMB; /* No,get next FMB */
if(preFMB == Co_NULL ) /* Is previous FMB==Co_NULL? */ preFMB->nextFMB = curFMB; /* Set link for FMB list */
{ }
nextFMB = FMBlist; /* Yes,get next FMB */
FMBlist = curFMB; /* Reset new FMB as the first item of FMB list */ if(nextFMB == Co_NULL) /* Is new FMB as last item of FMB list? */
} {
else curFMB->preUMB = preUMB; /* Yes,set link for list */
{ curFMB->nextUMB = Co_NULL;
nextFMB = preFMB->nextFMB; /* No,get next FMB */ curFMB->nextFMB = Co_NULL;
preFMB->nextFMB = curFMB; /* Set link for FMB list */ }
} else
{
curFMB->preUMB = preUMB; /* Set current FMB link for list */ curFMB->preUMB = preUMB; /* No,set link for list */
curFMB->nextUMB = nextUMB; curFMB->nextUMB = nextFMB->nextUMB;
curFMB->nextFMB = nextFMB; curFMB->nextFMB = nextFMB->nextFMB;
} }
}
if(curFMB->preUMB != Co_NULL)/* Is current FMB as first item in kernel heap? */ else /* All no,show UMB between two UMB*/
{ /* No,set link for list */ {
preUMB = (P_UMB)((U32)(curFMB->preUMB)-1); curFMB = (P_FMB)(usedMB); /* new FMB */
preUMB->nextMB = (void*)curFMB; preFMB = GetPreFMB(usedMB); /* Get previous FMB */
} preUMB = (P_UMB)(usedMB->preMB); /* Get previous UMB */
if(curFMB->nextUMB != Co_NULL)/* Is current FMB as last item in kernel heap? */ nextUMB = (P_UMB)(usedMB->nextMB); /* Get next UMB */
{ /* No,set link for list */
nextUMB = (P_UMB)((U32)(curFMB->nextUMB)-1); if(preFMB == Co_NULL ) /* Is previous FMB==Co_NULL? */
nextUMB->preMB = (void*)curFMB; {
} nextFMB = FMBlist; /* Yes,get next FMB */
OsSchedUnlock(); /* Unlock schedule */ FMBlist = curFMB; /* Reset new FMB as the first item of FMB list */
} }
else
{
/** nextFMB = preFMB->nextFMB; /* No,get next FMB */
******************************************************************************* preFMB->nextFMB = curFMB; /* Set link for FMB list */
* @brief Get previous free memory block pointer. }
* @param[in] usedMB Current used memory block.
* @param[out] None curFMB->preUMB = preUMB; /* Set current FMB link for list */
* @retval Previous free memory block pointer. curFMB->nextUMB = nextUMB;
* curFMB->nextFMB = nextFMB;
* @par Description }
* @details This function is called to get previous free memory block pointer.
******************************************************************************* if(curFMB->preUMB != Co_NULL)/* Is current FMB as first item in kernel heap? */
*/ { /* No,set link for list */
static P_FMB GetPreFMB(P_UMB usedMB) preUMB = (P_UMB)((U32)(curFMB->preUMB)-1);
{ preUMB->nextMB = (void*)curFMB;
P_UMB preUMB; }
preUMB = usedMB; if(curFMB->nextUMB != Co_NULL)/* Is current FMB as last item in kernel heap? */
while(((U32)(preUMB->preMB)&0x1)) /* Is previous MB as FMB? */ { /* No,set link for list */
{ /* No,get previous MB */ nextUMB = (P_UMB)((U32)(curFMB->nextUMB)-1);
preUMB = (P_UMB)((U32)(preUMB->preMB)-1); nextUMB->preMB = (void*)curFMB;
} }
return (P_FMB)(preUMB->preMB); /* Yes,return previous MB */ OsSchedUnlock(); /* Unlock schedule */
} }
#endif
/**
*******************************************************************************
* @brief Get previous free memory block pointer.
* @param[in] usedMB Current used memory block.
* @param[out] None
* @retval Previous free memory block pointer.
*
* @par Description
* @details This function is called to get previous free memory block pointer.
*******************************************************************************
*/
static P_FMB GetPreFMB(P_UMB usedMB)
{
P_UMB preUMB;
preUMB = usedMB;
while(((U32)(preUMB->preMB)&0x1)) /* Is previous MB as FMB? */
{ /* No,get previous MB */
preUMB = (P_UMB)((U32)(preUMB->preMB)-1);
}
return (P_FMB)(preUMB->preMB); /* Yes,return previous MB */
}
#endif
+356 -325
View File
@@ -1,325 +1,356 @@
/** /**
******************************************************************************* *******************************************************************************
* @file mbox.c * @file mbox.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Mailbox management implementation code of CooCox CoOS kernel. * @brief Mailbox management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
/*---------------------------- Include ---------------------------------------*/ * * Redistributions in binary form must reproduce the above copyright
#include <coocox.h> * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
#if CFG_MAILBOX_EN > 0 * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
/** * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
******************************************************************************* * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* @brief Create a mailbox * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* @param[in] sortType Mail box waiting list sort type. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* @param[out] None * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* @retval E_CREATE_FAIL Create mailbox fail. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* @retval others Create mailbox successful. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* @par Description * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* @details This function is called to create a mailbox. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* @note * THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************* *
*/ * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
OS_EventID CoCreateMbox(U8 sortType) *******************************************************************************
{ */
P_ECB pecb;
/*---------------------------- Include ---------------------------------------*/
/* Create a mailbox type event control block */ #include <coocox.h>
pecb = CreatEvent(EVENT_TYPE_MBOX,sortType,Co_NULL);
if(pecb == Co_NULL) /* If failed to create event block */
{ #if CFG_MAILBOX_EN > 0
return E_CREATE_FAIL;
}
pecb->eventCounter = 0; /**
return (pecb->id); /* Create a mailbox successfully, return event ID */ *******************************************************************************
} * @brief Create a mailbox
* @param[in] sortType Mail box waiting list sort type.
* @param[out] None
* @retval E_CREATE_FAIL Create mailbox fail.
/** * @retval others Create mailbox successful.
******************************************************************************* *
* @brief Delete a mailbox * @par Description
* @param[in] id Event ID. * @details This function is called to create a mailbox.
* @param[in] opt Delete option. * @note
* @param[out] None *******************************************************************************
* @retval E_INVALID_ID Invalid event ID. */
* @retval E_INVALID_PARAMETER Invalid parameter. OS_EventID CoCreateMbox(U8 sortType)
* @retval E_TASK_WAITTING Tasks waitting for the event,delete fail. {
* @retval E_OK Event deleted successful. P_ECB pecb;
*
* @par Description /* Create a mailbox type event control block */
* @details This function is called to delete a mailbox. pecb = CreatEvent(EVENT_TYPE_MBOX,sortType,Co_NULL);
* @note if(pecb == Co_NULL) /* If failed to create event block */
******************************************************************************* {
*/ return E_CREATE_FAIL;
StatusType CoDelMbox(OS_EventID id,U8 opt) }
{ pecb->eventCounter = 0;
P_ECB pecb; return (pecb->id); /* Create a mailbox successfully, return event ID */
}
#if CFG_PAR_CHECKOUT_EN >0
if(id >= CFG_MAX_EVENT) /* Judge id is valid or not? */
{
return E_INVALID_ID; /* Id is invalid ,return error */ /**
} *******************************************************************************
#endif * @brief Delete a mailbox
pecb = &EventTbl[id]; * @param[in] id Event ID.
#if CFG_PAR_CHECKOUT_EN >0 * @param[in] opt Delete option.
if(pecb->eventType != EVENT_TYPE_MBOX)/* Validate event control block type*/ * @param[out] None
{ * @retval E_INVALID_ID Invalid event ID.
return E_INVALID_ID; /* The event is not mailbox */ * @retval E_INVALID_PARAMETER Invalid parameter.
} * @retval E_TASK_WAITTING Tasks waitting for the event,delete fail.
#endif * @retval E_OK Event deleted successful.
return (DeleteEvent(pecb,opt)); /* Delete the mailbox event control block */ *
} * @par Description
* @details This function is called to delete a mailbox.
* @note
*******************************************************************************
/** */
******************************************************************************* StatusType CoDelMbox(OS_EventID id,U8 opt)
* @brief Accept a mailbox {
* @param[in] id Event ID. P_ECB pecb;
* @param[out] perr A pointer to error code.
* @retval Co_NULL #if CFG_PAR_CHECKOUT_EN >0
* @retval A pointer to mailbox accepted. if(id >= CFG_MAX_EVENT) /* Judge id is valid or not? */
* {
* @par Description return E_INVALID_ID; /* Id is invalid ,return error */
* @details This function is called to accept a mailbox. }
* @note #endif
******************************************************************************* pecb = &EventTbl[id];
*/ #if CFG_PAR_CHECKOUT_EN >0
void* CoAcceptMail(OS_EventID id,StatusType* perr) if(pecb->eventType != EVENT_TYPE_MBOX)/* Validate event control block type*/
{ {
P_ECB pecb; return E_INVALID_ID; /* The event is not mailbox */
void* pmail; }
#if CFG_PAR_CHECKOUT_EN >0 #endif
if(id >= CFG_MAX_EVENT) return (DeleteEvent(pecb,opt)); /* Delete the mailbox event control block */
{ }
*perr = E_INVALID_ID; /* Invalid 'id' */
return Co_NULL;
}
#endif /**
pecb = &EventTbl[id]; *******************************************************************************
* @brief Accept a mailbox
#if CFG_PAR_CHECKOUT_EN >0 * @param[in] id Event ID.
if(pecb->eventType != EVENT_TYPE_MBOX)/* Invalid event control block type */ * @param[out] perr A pointer to error code.
{ * @retval Co_NULL
*perr = E_INVALID_ID; * @retval A pointer to mailbox accepted.
return Co_NULL; *
} * @par Description
#endif * @details This function is called to accept a mailbox.
OsSchedLock(); * @note
if(pecb->eventCounter == 1) /* If there is already a message */ *******************************************************************************
{ */
*perr = E_OK; void* CoAcceptMail(OS_EventID id,StatusType* perr)
pmail = pecb->eventPtr; /* Get the message */ {
pecb->eventPtr = Co_NULL; /* Clear the mailbox */ P_ECB pecb;
pecb->eventCounter = 0; void* pmail;
OsSchedUnlock(); #if CFG_PAR_CHECKOUT_EN >0
return pmail; /* Return the message received */ if(id >= CFG_MAX_EVENT)
} {
else /* If the mailbox is empty */ *perr = E_INVALID_ID; /* Invalid 'id' */
{ return Co_NULL;
OsSchedUnlock(); }
*perr = E_MBOX_EMPTY; /* Mailbox is empty,return Co_NULL */ #endif
return Co_NULL; pecb = &EventTbl[id];
}
} #if CFG_PAR_CHECKOUT_EN >0
if(pecb->eventType != EVENT_TYPE_MBOX)/* Invalid event control block type */
{
*perr = E_INVALID_ID;
/** return Co_NULL;
******************************************************************************* }
* @brief Wait for a mailbox #endif
* @param[in] id Event ID. OsSchedLock();
* @param[in] timeout The longest time for writting mail. if(pecb->eventCounter == 1) /* If there is already a message */
* @param[out] perr A pointer to error code. {
* @retval Co_NULL *perr = E_OK;
* @retval A pointer to mailbox accept. pmail = pecb->eventPtr; /* Get the message */
* pecb->eventPtr = Co_NULL; /* Clear the mailbox */
* @par Description pecb->eventCounter = 0;
* @details This function is called to wait a mailbox. OsSchedUnlock();
* @note return pmail; /* Return the message received */
******************************************************************************* }
*/ else /* If the mailbox is empty */
void* CoPendMail(OS_EventID id,U32 timeout,StatusType* perr) {
{ OsSchedUnlock();
P_ECB pecb; *perr = E_MBOX_EMPTY; /* Mailbox is empty,return Co_NULL */
void* pmail; return Co_NULL;
P_OSTCB curTCB; }
}
if(OSIntNesting > 0) /* If the caller is ISR */
{
*perr = E_CALL;
return Co_NULL; /**
} *******************************************************************************
* @brief Wait for a mailbox
#if CFG_PAR_CHECKOUT_EN >0 * @param[in] id Event ID.
if(id >= CFG_MAX_EVENT) * @param[in] timeout The longest time for writting mail.
{ * @param[out] perr A pointer to error code.
*perr = E_INVALID_ID; /* Invalid 'id',retrun error */ * @retval Co_NULL
return Co_NULL; * @retval A pointer to mailbox accept.
} *
#endif * @par Description
* @details This function is called to wait a mailbox.
pecb = &EventTbl[id]; * @note
#if CFG_PAR_CHECKOUT_EN >0 *******************************************************************************
if(pecb->eventType != EVENT_TYPE_MBOX) */
{ void* CoPendMail(OS_EventID id,U32 timeout,StatusType* perr)
*perr = E_INVALID_ID; /* Invalid event type,not EVENT_TYPE_MBOX */ {
return Co_NULL; P_ECB pecb;
} void* pmail;
#endif P_OSTCB curTCB;
if(OSSchedLock != 0) /* Judge schedule is locked or not? */ if(OSIntNesting > 0) /* If the caller is ISR */
{ {
*perr = E_OS_IN_LOCK; /* Schedule is locked */ *perr = E_CALL;
return Co_NULL; /* return Co_NULL */ return Co_NULL;
} }
OsSchedLock();
if( pecb->eventCounter == 1) /* If there is already a message */ #if CFG_PAR_CHECKOUT_EN >0
{ if(id >= CFG_MAX_EVENT)
*perr = E_OK; {
pmail = pecb->eventPtr; /* Get the message */ *perr = E_INVALID_ID; /* Invalid 'id',retrun error */
pecb->eventPtr = Co_NULL; /* Clear the mailbox */ return Co_NULL;
pecb->eventCounter = 0; }
OsSchedUnlock(); #endif
return pmail; /* Return the message received */
} pecb = &EventTbl[id];
else /* If message is not available, task will pend */ #if CFG_PAR_CHECKOUT_EN >0
{ if(pecb->eventType != EVENT_TYPE_MBOX)
OsSchedUnlock(); {
curTCB = TCBRunning; *perr = E_INVALID_ID; /* Invalid event type,not EVENT_TYPE_MBOX */
if(timeout == 0) /* If time-out is not configured */ return Co_NULL;
{ }
EventTaskToWait(pecb,curTCB); /* Block task until event occurs */ #endif
*perr = E_OK;
if(OSSchedLock != 0) /* Judge schedule is locked or not? */
/* Have recived a message or the mailbox have been deleted */ {
pmail = curTCB->pmail; *perr = E_OS_IN_LOCK; /* Schedule is locked */
curTCB->pmail = Co_NULL; return Co_NULL; /* return Co_NULL */
return pmail; /* Return received message or Co_NULL */ }
} OsSchedLock();
else /* If time-out is configured */ if( pecb->eventCounter == 1) /* If there is already a message */
{ {
OsSchedLock(); *perr = E_OK;
pmail = pecb->eventPtr; /* Get the message */
/* Block task until event or timeout occurs */ pecb->eventPtr = Co_NULL; /* Clear the mailbox */
EventTaskToWait(pecb,curTCB); pecb->eventCounter = 0;
InsertDelayList(curTCB,timeout); OsSchedUnlock();
OsSchedUnlock(); return pmail; /* Return the message received */
if( curTCB->pmail == Co_NULL) /* Time-out occurred */ }
{ else /* If message is not available, task will pend */
*perr = E_TIMEOUT; {
return Co_NULL; OsSchedUnlock();
} curTCB = TCBRunning;
else /* Have recived a message or the mailbox have been deleted*/ if(timeout == 0) /* If time-out is not configured */
{ {
*perr = E_OK; EventTaskToWait(pecb,curTCB); /* Block task until event occurs */
pmail = curTCB->pmail; *perr = E_OK;
curTCB->pmail = Co_NULL;
return pmail; /* Return received message or Co_NULL */ /* Have recived a message or the mailbox have been deleted */
} OsSchedLock();
} pmail = curTCB->pmail;
} pecb->eventCounter = 0;
} curTCB->pmail = Co_NULL;
OsSchedUnlock();
return pmail; /* Return received message or Co_NULL */
/** }
******************************************************************************* else /* If time-out is configured */
* @brief Post a mailbox {
* @param[in] id Event ID. OsSchedLock();
* @param[in] pmail Pointer to mail that want to send.
* @param[out] None /* Block task until event or timeout occurs */
* @retval E_INVALID_ID EventTaskToWait(pecb,curTCB);
* @retval E_OK InsertDelayList(curTCB,timeout);
* OsSchedUnlock();
* @par Description if( curTCB->pmail == Co_NULL) /* Time-out occurred */
* @details This function is called to post a mail. {
* @note *perr = E_TIMEOUT;
******************************************************************************* return Co_NULL;
*/ }
StatusType CoPostMail(OS_EventID id,void* pmail) else /* Have recived a message or the mailbox have been deleted*/
{ {
P_ECB pecb; *perr = E_OK;
#if CFG_PAR_CHECKOUT_EN >0
if(id >= CFG_MAX_EVENT) OsSchedLock();
{ pmail = curTCB->pmail;
return E_INVALID_ID; /* Invalid id,return error */ pecb->eventCounter = 0;
} curTCB->pmail = Co_NULL;
#endif OsSchedUnlock();
pecb = &EventTbl[id]; return pmail; /* Return received message or Co_NULL */
#if CFG_PAR_CHECKOUT_EN >0 }
if(pecb->eventType != EVENT_TYPE_MBOX)/* Validate event control block type*/ }
{ }
return E_INVALID_ID; /* Event is not mailbox,return error*/ }
}
#endif
/**
if(pecb->eventCounter == 0) /* If mailbox doesn't already have a message*/ *******************************************************************************
{ * @brief Post a mailbox
OsSchedLock(); * @param[in] id Event ID.
pecb->eventPtr = pmail; /* Place message in mailbox */ * @param[in] pmail Pointer to mail that want to send.
pecb->eventCounter = 1; * @param[out] None
EventTaskToRdy(pecb); /* Check waiting list */ * @retval E_INVALID_ID
OsSchedUnlock(); * @retval E_OK
return E_OK; *
} * @par Description
else /* If there is already a message in mailbox */ * @details This function is called to post a mail.
{ * @note
return E_MBOX_FULL; /* Mailbox is full,and return "E_MBOX_FULL" */ *******************************************************************************
} */
} StatusType CoPostMail(OS_EventID id,void* pmail)
{
/** P_ECB pecb;
******************************************************************************* #if CFG_PAR_CHECKOUT_EN >0
* @brief Post a mailbox in ISR if(id >= CFG_MAX_EVENT)
* @param[in] id Event ID. {
* @param[in] pmail Pointer to mail that want to send. return E_INVALID_ID; /* Invalid id,return error */
* @param[out] None }
* @retval E_INVALID_ID #endif
* @retval E_OK
* pecb = &EventTbl[id];
* @par Description #if CFG_PAR_CHECKOUT_EN >0
* @details This function is called to post a mail in ISR. if(pecb->eventType != EVENT_TYPE_MBOX)/* Validate event control block type*/
* @note {
******************************************************************************* return E_INVALID_ID; /* Event is not mailbox,return error*/
*/ }
#if CFG_MAX_SERVICE_REQUEST > 0 #endif
StatusType isr_PostMail(OS_EventID id,void* pmail)
{ if(pecb->eventCounter == 0) /* If mailbox doesn't already have a message*/
if(OSSchedLock > 0) /* If scheduler is locked,(the caller is ISR) */ {
{ OsSchedLock();
/* Insert the request into service request queue */ pecb->eventPtr = pmail; /* Place message in mailbox */
if(InsertInSRQ(MBOX_REQ,id,pmail) == Co_FALSE) pecb->eventCounter = 1;
{ EventTaskToRdy(pecb); /* Check waiting list */
return E_SEV_REQ_FULL; /* If service request queue is full */ OsSchedUnlock();
} return E_OK;
else /* Operate successfully */ }
{ else /* If there is already a message in mailbox */
return E_OK; {
} return E_MBOX_FULL; /* Mailbox is full,and return "E_MBOX_FULL" */
} }
else }
{
return(CoPostMail(id,pmail)); /* Sends the message to the mailbox */ /**
} *******************************************************************************
} * @brief Post a mailbox in ISR
#endif * @param[in] id Event ID.
* @param[in] pmail Pointer to mail that want to send.
#endif * @param[out] None
* @retval E_INVALID_ID
* @retval E_OK
*
* @par Description
* @details This function is called to post a mail in ISR.
* @note
*******************************************************************************
*/
#if CFG_MAX_SERVICE_REQUEST > 0
StatusType isr_PostMail(OS_EventID id,void* pmail)
{
if(OSSchedLock > 0) /* If scheduler is locked,(the caller is ISR) */
{
/* Insert the request into service request queue */
if(InsertInSRQ(MBOX_REQ,id,pmail) == Co_FALSE)
{
return E_SEV_REQ_FULL; /* If service request queue is full */
}
else /* Operate successfully */
{
return E_OK;
}
}
else
{
return(CoPostMail(id,pmail)); /* Sends the message to the mailbox */
}
}
#endif
#endif
+298 -275
View File
@@ -1,275 +1,298 @@
/** /**
******************************************************************************* *******************************************************************************
* @file mm.c * @file mm.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief memory management implementation code of CooCox CoOS kernel. * @brief memory management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
/*---------------------------- Include ---------------------------------------*/ * notice, this list of conditions and the following disclaimer in the
#include <coocox.h> * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
#if CFG_MM_EN > 0 * from this software without specific prior written permission.
/*---------------------------- Variable Define -------------------------------*/ *
MM MemoryTbl[CFG_MAX_MM] = {{0}};/*!< Table which save memory control block. */ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
U32 MemoryIDVessel = 0; /*!< Memory ID container. */ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
/** * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
******************************************************************************* * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* @brief Create a memory partition * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* @param[in] memBuf Specify memory partition head address. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* @param[in] blockSize Specify memory block size. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* @param[in] blockNum Specify memory block number. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* @param[out] None * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* @retval E_CREATE_FAIL Create memory partition fail. * THE POSSIBILITY OF SUCH DAMAGE.
* @retval others Create memory partition successful. *
* * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
* @par Description *******************************************************************************
* @details This function is called to create a memory partition. */
*******************************************************************************
*/
OS_MMID CoCreateMemPartition(U8* memBuf,U32 blockSize,U32 blockNum) /*---------------------------- Include ---------------------------------------*/
{ #include <coocox.h>
U8 i,j;
U8 *memory;
P_MemBlk memBlk; #if CFG_MM_EN > 0
memory = memBuf; /*---------------------------- Variable Define -------------------------------*/
MM MemoryTbl[CFG_MAX_MM] = {{0}};/*!< Table which save memory control block. */
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ U32 MemoryIDVessel = 0; /*!< Memory ID container. */
if(memBuf == Co_NULL)
{ /**
return E_CREATE_FAIL; *******************************************************************************
} * @brief Create a memory partition
if(blockSize == 0) * @param[in] memBuf Specify memory partition head address.
{ * @param[in] blockSize Specify memory block size.
return E_CREATE_FAIL; * @param[in] blockNum Specify memory block number.
} * @param[out] None
if((blockSize&0x3) != 0) * @retval E_CREATE_FAIL Create memory partition fail.
{ * @retval others Create memory partition successful.
return E_CREATE_FAIL; *
} * @par Description
if(blockNum<=1) * @details This function is called to create a memory partition.
{ *******************************************************************************
return E_CREATE_FAIL; */
} OS_MMID CoCreateMemPartition(U8* memBuf,U32 blockSize,U32 blockNum)
#endif {
U8 i,j;
OsSchedLock(); /* Lock schedule */ U8 *memory;
for(i = 0; i < CFG_MAX_MM; i++) P_MemBlk memBlk;
{ memory = memBuf;
if((MemoryIDVessel & (1 << i)) == 0) /* Is free memory ID? */
{ #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
MemoryIDVessel |= (1<<i); /* Yes,assign ID to this memory block */ if(memBuf == Co_NULL)
OsSchedUnlock(); /* Unlock schedule */ {
MemoryTbl[i].memAddr = memory;/* Initialize memory control block*/ return E_CREATE_FAIL;
MemoryTbl[i].freeBlock = memory; }
MemoryTbl[i].blockSize = blockSize; if(blockSize == 0)
MemoryTbl[i].blockNum = blockNum; {
memBlk = (P_MemBlk)memory; /* Bulid list in this memory block*/ return E_CREATE_FAIL;
for(j=0;j<blockNum-1;j++) }
{ if((blockSize&0x3) != 0)
memory = memory+blockSize; {
memBlk->nextBlock = (P_MemBlk)memory; return E_CREATE_FAIL;
memBlk = memBlk->nextBlock; }
} if(blockNum<=1)
memBlk->nextBlock = Co_NULL; {
return i; /* Return memory block ID */ return E_CREATE_FAIL;
} }
} #endif
OsSchedUnlock(); /* Unlock schedule */
return E_CREATE_FAIL; /* Error return */ OsSchedLock(); /* Lock schedule */
} for(i = 0; i < CFG_MAX_MM; i++)
{
if((MemoryIDVessel & (1 << i)) == 0) /* Is free memory ID? */
/** {
******************************************************************************* MemoryIDVessel |= (1<<i); /* Yes,assign ID to this memory block */
* @brief Delete a memory partition OsSchedUnlock(); /* Unlock schedule */
* @param[in] mmID Specify memory partition that want to delete. MemoryTbl[i].memAddr = memory;/* Initialize memory control block*/
* @param[out] None MemoryTbl[i].freeBlock = memory;
* @retval E_INVALID_ID The memory partition id passed was invalid,delete fail. MemoryTbl[i].blockSize = blockSize;
* @retval E_OK Delete successful. MemoryTbl[i].blockNum = blockNum;
* memBlk = (P_MemBlk)memory; /* Bulid list in this memory block*/
* @par Description for(j=0;j<blockNum-1;j++)
* @details This function is called to Delete a memory partition. {
******************************************************************************* memory = memory+blockSize;
*/ memBlk->nextBlock = (P_MemBlk)memory;
StatusType CoDelMemoryPartition(OS_MMID mmID) memBlk = memBlk->nextBlock;
{ }
P_MM memCtl; memBlk->nextBlock = Co_NULL;
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ return i; /* Return memory block ID */
if(mmID >= CFG_MAX_MM) }
{ }
return E_INVALID_ID; OsSchedUnlock(); /* Unlock schedule */
} return E_CREATE_FAIL; /* Error return */
if( ((1<<mmID)&MemoryIDVessel) == 0) }
{
return E_INVALID_ID;
} /**
#endif *******************************************************************************
OsSchedLock(); /* Lock schedule */ * @brief Delete a memory partition
memCtl = &MemoryTbl[mmID]; /* Release memory control block */ * @param[in] mmID Specify memory partition that want to delete.
MemoryIDVessel &= ~(1<<mmID); * @param[out] None
OsSchedUnlock(); /* Unlock schedule */ * @retval E_INVALID_ID The memory partition id passed was invalid,delete fail.
* @retval E_OK Delete successful.
memCtl->memAddr = Co_NULL; *
memCtl->freeBlock = Co_NULL; * @par Description
memCtl->blockSize = 0; * @details This function is called to Delete a memory partition.
memCtl->blockNum = 0; *******************************************************************************
return E_OK; /* Return OK */ */
} StatusType CoDelMemoryPartition(OS_MMID mmID)
{
P_MM memCtl;
/** #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
******************************************************************************* if(mmID >= CFG_MAX_MM)
* @brief Get free block number in a memory partition {
* @param[in] mmID Specify memory partition. return E_INVALID_ID;
* }
* @param[out] E_INVALID_ID Invalid ID was passed and get counter failure. if( ((1<<mmID)&MemoryIDVessel) == 0)
* @param[out] E_OK Get current counter successful. {
* @retval fbNum The number of free block. return E_INVALID_ID;
* }
* @par Description #endif
* @details This function is called to get free block number in a memory OsSchedLock(); /* Lock schedule */
* partition. memCtl = &MemoryTbl[mmID]; /* Release memory control block */
******************************************************************************* MemoryIDVessel &= ~(1<<mmID);
*/ OsSchedUnlock(); /* Unlock schedule */
U32 CoGetFreeBlockNum(OS_MMID mmID,StatusType* perr)
{ memCtl->memAddr = Co_NULL;
U32 fbNum; memCtl->freeBlock = Co_NULL;
P_MM memCtl; memCtl->blockSize = 0;
P_MemBlk memBlk; memCtl->blockNum = 0;
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ return E_OK; /* Return OK */
if(mmID >= CFG_MAX_MM) }
{
*perr = E_INVALID_ID;
return 0; /**
} *******************************************************************************
if( ((1<<mmID)&MemoryIDVessel) == 0) * @brief Get free block number in a memory partition
{ * @param[in] mmID Specify memory partition.
*perr = E_INVALID_ID; /* Invalid memory id,return 0 */ *
return 0; * @param[out] E_INVALID_ID Invalid ID was passed and get counter failure.
} * @param[out] E_OK Get current counter successful.
#endif * @retval fbNum The number of free block.
memCtl = &MemoryTbl[mmID]; *
OsSchedLock(); /* Lock schedule */ * @par Description
memBlk = (P_MemBlk)(memCtl->freeBlock);/* Get the free item in memory list*/ * @details This function is called to get free block number in a memory
fbNum = 0; * partition.
while(memBlk != Co_NULL) /* Get counter of free item */ *******************************************************************************
{ */
fbNum++; U32 CoGetFreeBlockNum(OS_MMID mmID,StatusType* perr)
memBlk = memBlk->nextBlock; /* Get next free iterm */ {
} U32 fbNum;
OsSchedUnlock(); /* Unlock schedul */ P_MM memCtl;
*perr = E_OK; P_MemBlk memBlk;
return fbNum; /* Return the counter of free item */ #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
} if(mmID >= CFG_MAX_MM)
{
*perr = E_INVALID_ID;
/** return 0;
******************************************************************************* }
* @brief Get a memory buffer from memory partition if( ((1<<mmID)&MemoryIDVessel) == 0)
* @param[in] mmID Specify memory partition that want to assign buffer. {
* @param[out] None *perr = E_INVALID_ID; /* Invalid memory id,return 0 */
* @retval Co_NULL Assign buffer fail. return 0;
* @retval others Assign buffer successful,and return the buffer pointer. }
* #endif
* @par Description memCtl = &MemoryTbl[mmID];
* @details This function is called to Delete a memory partition. OsSchedLock(); /* Lock schedule */
******************************************************************************* memBlk = (P_MemBlk)(memCtl->freeBlock);/* Get the free item in memory list*/
*/ fbNum = 0;
void* CoGetMemoryBuffer(OS_MMID mmID) while(memBlk != Co_NULL) /* Get counter of free item */
{ {
P_MM memCtl; fbNum++;
P_MemBlk memBlk; memBlk = memBlk->nextBlock; /* Get next free iterm */
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ }
if(mmID >= CFG_MAX_MM) OsSchedUnlock(); /* Unlock schedul */
{ *perr = E_OK;
return Co_NULL; return fbNum; /* Return the counter of free item */
} }
if( ((1<<mmID)&MemoryIDVessel) == 0)
{
return Co_NULL; /**
} *******************************************************************************
#endif * @brief Get a memory buffer from memory partition
memCtl = &MemoryTbl[mmID]; * @param[in] mmID Specify memory partition that want to assign buffer.
OsSchedLock(); /* Lock schedule */ * @param[out] None
if(memCtl->freeBlock == Co_NULL ) /* Is there no free item in memory list */ * @retval Co_NULL Assign buffer fail.
{ * @retval others Assign buffer successful,and return the buffer pointer.
OsSchedUnlock(); /* Unlock schedule */ *
return Co_NULL; /* Yes,error return */ * @par Description
} * @details This function is called to Delete a memory partition.
memBlk = (P_MemBlk)memCtl->freeBlock; /* Get free memory block */ *******************************************************************************
memCtl->freeBlock = (U8*)memBlk->nextBlock; /* Reset the first free item */ */
OsSchedUnlock(); /* Unlock schedule */ void* CoGetMemoryBuffer(OS_MMID mmID)
return memBlk; /* Return free memory block address */ {
} P_MM memCtl;
P_MemBlk memBlk;
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
if(mmID >= CFG_MAX_MM)
/** {
******************************************************************************* return Co_NULL;
* @brief Free a memory buffer to memory partition }
* @param[in] mmID Specify memory partition. if( ((1<<mmID)&MemoryIDVessel) == 0)
* @param[in] buf Specify memory buffer that want to free. {
* @param[out] None return Co_NULL;
* @retval E_INVALID_ID The memory partition id passed was invalid. }
* @retval E_INVALID_PARAMETER The parameter passed was invalid. #endif
* @retval E_OK Free successful. memCtl = &MemoryTbl[mmID];
* OsSchedLock(); /* Lock schedule */
* @par Description if(memCtl->freeBlock == Co_NULL ) /* Is there no free item in memory list */
* @details This function is called to Delete a memory partition. {
******************************************************************************* OsSchedUnlock(); /* Unlock schedule */
*/ return Co_NULL; /* Yes,error return */
StatusType CoFreeMemoryBuffer(OS_MMID mmID,void* buf) }
{ memBlk = (P_MemBlk)memCtl->freeBlock; /* Get free memory block */
P_MM memCtl; memCtl->freeBlock = (U8*)memBlk->nextBlock; /* Reset the first free item */
P_MemBlk memBlk; OsSchedUnlock(); /* Unlock schedule */
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ return memBlk; /* Return free memory block address */
if(mmID >= CFG_MAX_MM) }
{
return E_INVALID_ID;
}
if( ((1<<mmID)&MemoryIDVessel) == 0) /**
{ *******************************************************************************
return E_INVALID_ID; * @brief Free a memory buffer to memory partition
} * @param[in] mmID Specify memory partition.
if(buf == Co_NULL) * @param[in] buf Specify memory buffer that want to free.
{ * @param[out] None
return E_INVALID_PARAMETER; * @retval E_INVALID_ID The memory partition id passed was invalid.
} * @retval E_INVALID_PARAMETER The parameter passed was invalid.
#endif * @retval E_OK Free successful.
*
memCtl = &MemoryTbl[mmID]; * @par Description
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ * @details This function is called to Delete a memory partition.
if((U32)buf < (U32)(memCtl->memAddr)) *******************************************************************************
{ */
return E_INVALID_PARAMETER; StatusType CoFreeMemoryBuffer(OS_MMID mmID,void* buf)
} {
if((U32)buf > (U32)(memCtl->memAddr + memCtl->blockSize*memCtl->blockNum)) P_MM memCtl;
{ P_MemBlk memBlk;
return E_INVALID_PARAMETER; #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
} if(mmID >= CFG_MAX_MM)
if(((U32)buf - (U32)(memCtl->memAddr))%(memCtl->blockSize) != 0) {
{ return E_INVALID_ID;
return E_INVALID_PARAMETER; }
} if( ((1<<mmID)&MemoryIDVessel) == 0)
#endif {
memBlk = (P_MemBlk)buf; /* Reset the first free item */ return E_INVALID_ID;
OsSchedLock(); }
memBlk->nextBlock = (P_MemBlk)memCtl->freeBlock; if(buf == Co_NULL)
memCtl->freeBlock = buf; {
OsSchedUnlock(); return E_INVALID_PARAMETER;
return E_OK; /* Return OK */ }
} #endif
#endif memCtl = &MemoryTbl[mmID];
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
if((U32)buf < (U32)(memCtl->memAddr))
{
return E_INVALID_PARAMETER;
}
if((U32)buf > (U32)(memCtl->memAddr + memCtl->blockSize*memCtl->blockNum))
{
return E_INVALID_PARAMETER;
}
if(((U32)buf - (U32)(memCtl->memAddr))%(memCtl->blockSize) != 0)
{
return E_INVALID_PARAMETER;
}
#endif
memBlk = (P_MemBlk)buf; /* Reset the first free item */
OsSchedLock();
memBlk->nextBlock = (P_MemBlk)memCtl->freeBlock;
memCtl->freeBlock = buf;
OsSchedUnlock();
return E_OK; /* Return OK */
}
#endif
+372 -349
View File
@@ -1,349 +1,372 @@
/** /**
******************************************************************************* *******************************************************************************
* @file mutex.c * @file mutex.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Mutex management implementation code of CooCox CoOS kernel. * @brief Mutex management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
/*---------------------------- Include ---------------------------------------*/ * documentation and/or other materials provided with the distribution.
#include <coocox.h> * * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
/*---------------------------- Variable Define -------------------------------*/ *
#if CFG_MUTEX_EN > 0 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
OS_MutexID MutexFreeID = 0; /*!< Point to next vliad mutex ID. */ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
MUTEX MutexTbl[CFG_MAX_MUTEX] = {{0}}; /*!< Mutex struct array */ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 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)
* @brief Create a mutex * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* @param[in] None * THE POSSIBILITY OF SUCH DAMAGE.
* @param[out] None *
* @retval E_CREATE_FAIL Create mutex fail. * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
* @retval others Create mutex successful. *******************************************************************************
* */
* @par Description
* @details This function is called to create a mutex.
* @note
******************************************************************************* /*---------------------------- Include ---------------------------------------*/
*/ #include <coocox.h>
OS_MutexID CoCreateMutex(void)
{
OS_MutexID id; /*---------------------------- Variable Define -------------------------------*/
P_MUTEX pMutex; #if CFG_MUTEX_EN > 0
OsSchedLock();
OS_MutexID MutexFreeID = 0; /*!< Point to next vliad mutex ID. */
/* Assign a free mutex control block */ MUTEX MutexTbl[CFG_MAX_MUTEX] = {{0}}; /*!< Mutex struct array */
if(MutexFreeID < CFG_MAX_MUTEX )
{
id = MutexFreeID++;
OsSchedUnlock(); /**
pMutex = &MutexTbl[id]; *******************************************************************************
pMutex->hipriTaskID = INVALID_ID; * @brief Create a mutex
pMutex->originalPrio = 0xff; * @param[in] None
pMutex->mutexFlag = MUTEX_FREE; /* Mutex is free,not was occupied */ * @param[out] None
pMutex->taskID = INVALID_ID; * @retval E_CREATE_FAIL Create mutex fail.
pMutex->waittingList = Co_NULL; * @retval others Create mutex successful.
return id; /* Return mutex ID */ *
} * @par Description
* @details This function is called to create a mutex.
OsSchedUnlock(); * @note
return E_CREATE_FAIL; /* No free mutex control block */ *******************************************************************************
} */
OS_MutexID CoCreateMutex(void)
{
OS_MutexID id;
/** P_MUTEX pMutex;
******************************************************************************* OsSchedLock();
* @brief Enter a critical area
* @param[in] mutexID Specify mutex. /* Assign a free mutex control block */
* @param[out] None if(MutexFreeID < CFG_MAX_MUTEX )
* @retval E_INVALID_ID Invalid mutex id. {
* @retval E_CALL Error call in ISR. id = MutexFreeID++;
* @retval E_OK Enter critical area successful. OsSchedUnlock();
* pMutex = &MutexTbl[id];
* @par Description pMutex->hipriTaskID = INVALID_ID;
* @details This function is called when entering a critical area. pMutex->originalPrio = 0xff;
* @note pMutex->mutexFlag = MUTEX_FREE; /* Mutex is free,not was occupied */
******************************************************************************* pMutex->taskID = INVALID_ID;
*/ pMutex->waittingList = Co_NULL;
StatusType CoEnterMutexSection(OS_MutexID mutexID) return id; /* Return mutex ID */
{ }
P_OSTCB ptcb,pCurTcb;
P_MUTEX pMutex; OsSchedUnlock();
return E_CREATE_FAIL; /* No free mutex control block */
#if CFG_EVENT_EN >0 }
P_ECB pecb;
#endif
if(OSIntNesting > 0) /* If the caller is ISR */ /**
{ *******************************************************************************
return E_CALL; * @brief Enter a critical area
} * @param[in] mutexID Specify mutex.
if(OSSchedLock != 0) /* Is OS lock? */ * @param[out] None
{ * @retval E_INVALID_ID Invalid mutex id.
return E_OS_IN_LOCK; /* Yes,error return */ * @retval E_CALL Error call in ISR.
} * @retval E_OK Enter critical area successful.
*
#if CFG_PAR_CHECKOUT_EN >0 * @par Description
if(mutexID >= MutexFreeID) /* Invalid 'mutexID' */ * @details This function is called when entering a critical area.
{ * @note
return E_INVALID_ID; *******************************************************************************
} */
#endif StatusType CoEnterMutexSection(OS_MutexID mutexID)
{
OsSchedLock(); P_OSTCB ptcb,pCurTcb;
pCurTcb = TCBRunning; P_MUTEX pMutex;
pMutex = &MutexTbl[mutexID];
#if CFG_EVENT_EN >0
pCurTcb->mutexID = mutexID; P_ECB pecb;
if(pMutex->mutexFlag == MUTEX_FREE) /* If mutex is available */ #endif
{
pMutex->originalPrio = pCurTcb->prio; /* Save priority of owning task */ if(OSIntNesting > 0) /* If the caller is ISR */
pMutex->taskID = pCurTcb->taskID; /* Acquire the resource */ {
pMutex->hipriTaskID = pCurTcb->taskID; return E_CALL;
pMutex->mutexFlag = MUTEX_OCCUPY; /* Occupy the mutex resource*/ }
} if(OSSchedLock != 0) /* Is OS lock? */
/* If the mutex resource had been occupied */ {
else if(pMutex->mutexFlag == MUTEX_OCCUPY) return E_OS_IN_LOCK; /* Yes,error return */
{ }
ptcb = &TCBTbl[pMutex->taskID];
if(ptcb->prio > pCurTcb->prio) /* Need to promote priority of owner? */ #if CFG_PAR_CHECKOUT_EN >0
{ if(mutexID >= MutexFreeID) /* Invalid 'mutexID' */
#if CFG_ORDER_LIST_SCHEDULE_EN ==0 {
DeleteTaskPri(ptcb->prio); return E_INVALID_ID;
ActiveTaskPri(pCurTcb->prio); }
#endif #endif
ptcb->prio = pCurTcb->prio; /* Promote prio of owner */
OsSchedLock();
/* Upgarde the highest priority about the mutex */ pCurTcb = TCBRunning;
pMutex->hipriTaskID = pCurTcb->taskID; pMutex = &MutexTbl[mutexID];
if(ptcb->state == TASK_READY) /* If the task is ready to run */
{ pCurTcb->mutexID = mutexID;
RemoveFromTCBRdyList(ptcb); /* Remove the task from READY list*/ if(pMutex->mutexFlag == MUTEX_FREE) /* If mutex is available */
InsertToTCBRdyList(ptcb); /* Insert the task into READY list*/ {
} pMutex->originalPrio = pCurTcb->prio; /* Save priority of owning task */
#if CFG_EVENT_EN >0 pMutex->taskID = pCurTcb->taskID; /* Acquire the resource */
/* If the task is waiting on a event */ pMutex->hipriTaskID = pCurTcb->taskID;
else if(ptcb->eventID != INVALID_ID) pMutex->mutexFlag = MUTEX_OCCUPY; /* Occupy the mutex resource*/
{ }
pecb = &EventTbl[ptcb->eventID]; /* If the mutex resource had been occupied */
else if(pMutex->mutexFlag == MUTEX_OCCUPY)
/* If the event waiting type is preemptive Priority */ {
if(pecb->eventSortType == EVENT_SORT_TYPE_PRIO) ptcb = &TCBTbl[pMutex->taskID];
{ if(ptcb->prio > pCurTcb->prio) /* Need to promote priority of owner? */
/* Remove the task from event waiting list */ {
RemoveEventWaittingList(ptcb); #if CFG_ORDER_LIST_SCHEDULE_EN ==0
DeleteTaskPri(ptcb->prio);
/* Insert the task into event waiting list */ ActiveTaskPri(pCurTcb->prio);
EventTaskToWait(pecb,ptcb); #endif
} ptcb->prio = pCurTcb->prio; /* Promote prio of owner */
}
#endif /* Upgarde the highest priority about the mutex */
} pMutex->hipriTaskID = pCurTcb->taskID;
if(ptcb->state == TASK_READY) /* If the task is ready to run */
pCurTcb->state = TASK_WAITING; /* Block current task */ {
TaskSchedReq = Co_TRUE; RemoveFromTCBRdyList(ptcb); /* Remove the task from READY list*/
pCurTcb->TCBnext = Co_NULL; InsertToTCBRdyList(ptcb); /* Insert the task into READY list*/
pCurTcb->TCBprev = Co_NULL; }
#if CFG_EVENT_EN >0
ptcb = pMutex->waittingList; /* If the task is waiting on a event */
if(ptcb == Co_NULL) /* If the event waiting list is empty */ else if(ptcb->eventID != INVALID_ID)
{ {
pMutex->waittingList = pCurTcb; /* Insert the task to head */ pecb = &EventTbl[ptcb->eventID];
}
else /* If the event waiting list is not empty */ /* If the event waiting type is preemptive Priority */
{ if(pecb->eventSortType == EVENT_SORT_TYPE_PRIO)
while(ptcb->TCBnext != Co_NULL) /* Insert the task to tail */ {
{ /* Remove the task from event waiting list */
ptcb = ptcb->TCBnext; RemoveEventWaittingList(ptcb);
}
ptcb->TCBnext = pCurTcb; /* Insert the task into event waiting list */
pCurTcb->TCBprev = ptcb; EventTaskToWait(pecb,ptcb);
pCurTcb->TCBnext = Co_NULL; }
} }
} #endif
OsSchedUnlock(); }
return E_OK;
} pCurTcb->state = TASK_WAITING; /* Block current task */
TaskSchedReq = Co_TRUE;
pCurTcb->TCBnext = Co_NULL;
/** pCurTcb->TCBprev = Co_NULL;
*******************************************************************************
* @brief Leave from a critical area ptcb = pMutex->waittingList;
* @param[in] mutexID Specify mutex id. if(ptcb == Co_NULL) /* If the event waiting list is empty */
* @param[out] None {
* @retval E_INVALID_ID Invalid mutex id. pMutex->waittingList = pCurTcb; /* Insert the task to head */
* @retval E_CALL Error call in ISR. }
* @retval E_OK Exit a critical area successful. else /* If the event waiting list is not empty */
* {
* @par Description while(ptcb->TCBnext != Co_NULL) /* Insert the task to tail */
* @details This function must be called when exiting from a critical area. {
* @note ptcb = ptcb->TCBnext;
******************************************************************************* }
*/ ptcb->TCBnext = pCurTcb;
StatusType CoLeaveMutexSection(OS_MutexID mutexID) pCurTcb->TCBprev = ptcb;
{ pCurTcb->TCBnext = Co_NULL;
P_OSTCB ptcb; }
P_MUTEX pMutex; }
U8 prio; OsSchedUnlock();
U8 taskID; return E_OK;
}
if(OSIntNesting > 0) /* If the caller is ISR */
{
return E_CALL; /**
} *******************************************************************************
* @brief Leave from a critical area
#if CFG_PAR_CHECKOUT_EN >0 * @param[in] mutexID Specify mutex id.
if(mutexID >= MutexFreeID) * @param[out] None
{ * @retval E_INVALID_ID Invalid mutex id.
return E_INVALID_ID; /* Invalid mutex id, return error */ * @retval E_CALL Error call in ISR.
} * @retval E_OK Exit a critical area successful.
#endif *
OsSchedLock(); * @par Description
pMutex = &MutexTbl[mutexID]; /* Obtain point of mutex control block*/ * @details This function must be called when exiting from a critical area.
ptcb = &TCBTbl[pMutex->taskID]; * @note
ptcb->mutexID = INVALID_ID; *******************************************************************************
if(pMutex->waittingList == Co_NULL) /* If the mutex waiting list is empty */ */
{ StatusType CoLeaveMutexSection(OS_MutexID mutexID)
pMutex->mutexFlag = MUTEX_FREE; /* The mutex resource is available */ {
pMutex->taskID = INVALID_ID; P_OSTCB ptcb;
OsSchedUnlock(); P_MUTEX pMutex;
} U8 prio;
else /* If there is at least one task waitting for the mutex */ U8 taskID;
{
taskID = pMutex->taskID; /* Get task ID of mutex owner */ if(OSIntNesting > 0) /* If the caller is ISR */
{
/* we havn't promoted current task's priority */ return E_CALL;
if(pMutex->hipriTaskID == taskID) }
{
ptcb = pMutex->waittingList;/* Point to mutex first waiting task */ #if CFG_PAR_CHECKOUT_EN >0
prio = ptcb->prio; if(mutexID >= MutexFreeID)
while(ptcb != Co_NULL) /* Find the highest priority task */ {
{ return E_INVALID_ID; /* Invalid mutex id, return error */
if(ptcb->prio < prio) }
{ #endif
prio = ptcb->prio; OsSchedLock();
pMutex->hipriTaskID = ptcb->taskID; pMutex = &MutexTbl[mutexID]; /* Obtain point of mutex control block*/
} ptcb = &TCBTbl[pMutex->taskID];
ptcb = ptcb->TCBnext; ptcb->mutexID = INVALID_ID;
} if(pMutex->waittingList == Co_NULL) /* If the mutex waiting list is empty */
} {
else /* we have promoted current task's priority */ pMutex->mutexFlag = MUTEX_FREE; /* The mutex resource is available */
{ pMutex->taskID = INVALID_ID;
prio = TCBTbl[taskID].prio; OsSchedUnlock();
} }
else /* If there is at least one task waitting for the mutex */
/* Reset the task priority */ {
pMutex->taskID = INVALID_ID; taskID = pMutex->taskID; /* Get task ID of mutex owner */
CoSetPriority(taskID,pMutex->originalPrio);
/* we havn't promoted current task's priority */
/* Find first task in waiting list ready to run */ if(pMutex->hipriTaskID == taskID)
ptcb = pMutex->waittingList; {
pMutex->waittingList = ptcb->TCBnext; ptcb = pMutex->waittingList;/* Point to mutex first waiting task */
pMutex->originalPrio = ptcb->prio; prio = ptcb->prio;
pMutex->taskID = ptcb->taskID; while(ptcb != Co_NULL) /* Find the highest priority task */
{
#if CFG_ORDER_LIST_SCHEDULE_EN ==0 if(ptcb->prio < prio)
if(prio != ptcb->prio) {
{ prio = ptcb->prio;
DeleteTaskPri(ptcb->prio); pMutex->hipriTaskID = ptcb->taskID;
ActiveTaskPri(prio); }
} ptcb = ptcb->TCBnext;
#endif }
}
ptcb->prio = prio; /* Raise the task's priority */ else /* we have promoted current task's priority */
{
/* Insert the task which acquire the mutex into ready list. */ prio = TCBTbl[taskID].prio;
ptcb->TCBnext = Co_NULL; }
ptcb->TCBprev = Co_NULL;
/* Reset the task priority */
InsertToTCBRdyList(ptcb); /* Insert the task into the READY list */ pMutex->taskID = INVALID_ID;
OsSchedUnlock(); CoSetPriority(taskID,pMutex->originalPrio);
}
return E_OK; /* Find first task in waiting list ready to run */
} ptcb = pMutex->waittingList;
pMutex->waittingList = ptcb->TCBnext;
/** pMutex->originalPrio = ptcb->prio;
******************************************************************************* pMutex->taskID = ptcb->taskID;
* @brief Remove a task from mutex waiting list
* @param[in] ptcb TCB which will remove out. #if CFG_ORDER_LIST_SCHEDULE_EN ==0
* @param[out] None if(prio != ptcb->prio)
* @retval None {
* DeleteTaskPri(ptcb->prio);
* @par Description ActiveTaskPri(prio);
* @details This function be called when delete a task. }
* @note #endif
*******************************************************************************
*/ ptcb->prio = prio; /* Raise the task's priority */
void RemoveMutexList(P_OSTCB ptcb)
{ /* Insert the task which acquire the mutex into ready list. */
U8 prio; ptcb->TCBnext = Co_NULL;
OS_TID taskID; ptcb->TCBprev = Co_NULL;
P_MUTEX pMutex;
pMutex = &MutexTbl[ptcb->mutexID]; InsertToTCBRdyList(ptcb); /* Insert the task into the READY list */
OsSchedUnlock();
/* If only one task waiting on mutex */ }
if((ptcb->TCBnext ==Co_NULL) && (ptcb->TCBprev == Co_NULL)) return E_OK;
{ }
pMutex->waittingList = Co_NULL; /* Waiting list is empty */
} /**
else if(ptcb->TCBnext == Co_NULL) /* If the task is the last of waiting list*/ *******************************************************************************
{ * @brief Remove a task from mutex waiting list
/* Remove task from mutex waiting list */ * @param[in] ptcb TCB which will remove out.
ptcb->TCBprev->TCBnext = Co_NULL; * @param[out] None
ptcb->TCBprev = Co_NULL; * @retval None
} *
else if(ptcb->TCBprev == Co_NULL)/* If the task is the first of waiting list*/ * @par Description
{ * @details This function be called when delete a task.
/* Remove task from waiting list */ * @note
ptcb->TCBnext->TCBprev = Co_NULL; *******************************************************************************
ptcb->TCBnext = Co_NULL; */
} void RemoveMutexList(P_OSTCB ptcb)
else /* If the task is in the middle of waiting list */ {
{ U8 prio;
/* Remove task from wait list */ OS_TID taskID;
ptcb->TCBnext->TCBprev = ptcb->TCBprev; P_MUTEX pMutex;
ptcb->TCBprev->TCBnext = ptcb->TCBnext; pMutex = &MutexTbl[ptcb->mutexID];
ptcb->TCBprev = Co_NULL;
ptcb->TCBnext = Co_NULL; /* If only one task waiting on mutex */
} if((ptcb->TCBnext ==Co_NULL) && (ptcb->TCBprev == Co_NULL))
{
ptcb->mutexID = INVALID_ID; pMutex->waittingList = Co_NULL; /* Waiting list is empty */
}
/* If the task have highest priority in mutex waiting list */ else if(ptcb->TCBnext == Co_NULL) /* If the task is the last of waiting list*/
if(pMutex->hipriTaskID == ptcb->taskID) {
{ /* Remove task from mutex waiting list */
ptcb = pMutex->waittingList; ptcb->TCBprev->TCBnext = Co_NULL;
prio = pMutex->originalPrio; ptcb->TCBprev = Co_NULL;
pMutex->hipriTaskID = pMutex->taskID; }
while(ptcb != Co_NULL) /* Find task ID of highest priority task*/ else if(ptcb->TCBprev == Co_NULL)/* If the task is the first of waiting list*/
{ {
if(ptcb->prio < prio) /* Remove task from waiting list */
{ ptcb->TCBnext->TCBprev = Co_NULL;
prio = ptcb->prio; ptcb->TCBnext = Co_NULL;
pMutex->hipriTaskID = ptcb->taskID; }
} else /* If the task is in the middle of waiting list */
ptcb = ptcb->TCBnext; {
} /* Remove task from wait list */
taskID = pMutex->taskID; ptcb->TCBnext->TCBprev = ptcb->TCBprev;
pMutex->taskID = INVALID_ID; ptcb->TCBprev->TCBnext = ptcb->TCBnext;
CoSetPriority(taskID,prio); /* Reset the mutex ower priority */ ptcb->TCBprev = Co_NULL;
pMutex->taskID = taskID; ptcb->TCBnext = Co_NULL;
} }
}
ptcb->mutexID = INVALID_ID;
#endif
/* If the task have highest priority in mutex waiting list */
if(pMutex->hipriTaskID == ptcb->taskID)
{
ptcb = pMutex->waittingList;
prio = pMutex->originalPrio;
pMutex->hipriTaskID = pMutex->taskID;
while(ptcb != Co_NULL) /* Find task ID of highest priority task*/
{
if(ptcb->prio < prio)
{
prio = ptcb->prio;
pMutex->hipriTaskID = ptcb->taskID;
}
ptcb = ptcb->TCBnext;
}
taskID = pMutex->taskID;
pMutex->taskID = INVALID_ID;
CoSetPriority(taskID,prio); /* Reset the mutex ower priority */
pMutex->taskID = taskID;
}
}
#endif
+432 -393
View File
@@ -1,393 +1,432 @@
/** /**
******************************************************************************* *******************************************************************************
* @file queue.c * @file queue.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Queue management implementation code of CooCox CoOS kernel. * @brief Queue management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
/*---------------------------- Include ---------------------------------------*/ * * Redistributions in binary form must reproduce the above copyright
#include <coocox.h> * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
#if CFG_QUEUE_EN > 0 * contributors may be used to endorse or promote products derived
/*---------------------------- Variable Define -------------------------------*/ * from this software without specific prior written permission.
QCB QueueTbl[CFG_MAX_QUEUE] = {{0}}; /*!< Queue control block table */ *
U32 QueueIDVessel = 0; /*!< Queue list mask */ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
/** * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
******************************************************************************* * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* @brief Create a queue * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* @param[in] qStart Pointer to mail pointer buffer. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* @param[in] size The length of queue. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* @param[in] sortType Mail queue waiting list sort type. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* @param[out] None * THE POSSIBILITY OF SUCH DAMAGE.
* @retval E_CREATE_FAIL Create queue fail. *
* @retval others Create queue successful. * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
* *******************************************************************************
* @par Description */
* @details This function is called to create a queue.
* @note /*---------------------------- Include ---------------------------------------*/
******************************************************************************* #include <coocox.h>
*/
OS_EventID CoCreateQueue(void **qStart, U16 size ,U8 sortType)
{ #if CFG_QUEUE_EN > 0
U8 i; /*---------------------------- Variable Define -------------------------------*/
P_ECB pecb; QCB QueueTbl[CFG_MAX_QUEUE] = {{0}}; /*!< Queue control block table */
U32 QueueIDVessel = 0; /*!< Queue list mask */
#if CFG_PAR_CHECKOUT_EN >0
if((qStart == Co_NULL) || (size == 0))
{
return E_CREATE_FAIL; /**
} *******************************************************************************
#endif * @brief Create a queue
* @param[in] qStart Pointer to mail pointer buffer.
OsSchedLock(); * @param[in] size The length of queue.
for(i = 0; i < CFG_MAX_QUEUE; i++) * @param[in] sortType Mail queue waiting list sort type.
{ * @param[out] None
/* Assign a free QUEUE control block */ * @retval E_CREATE_FAIL Create queue fail.
if((QueueIDVessel & (1 << i)) == 0) * @retval others Create queue successful.
{ *
QueueIDVessel |= (1<<i); * @par Description
OsSchedUnlock(); * @details This function is called to create a queue.
* @note
QueueTbl[i].qStart = qStart; /* Initialize the queue */ *******************************************************************************
QueueTbl[i].id = i; */
QueueTbl[i].head = 0; OS_EventID CoCreateQueue(void **qStart, U16 size ,U8 sortType)
QueueTbl[i].tail = 0; {
QueueTbl[i].qMaxSize = size; U8 i;
QueueTbl[i].qSize = 0; P_ECB pecb;
/* Get a event control block and initial the event content */ #if CFG_PAR_CHECKOUT_EN >0
pecb = CreatEvent(EVENT_TYPE_QUEUE,sortType,&QueueTbl[i]); if((qStart == Co_NULL) || (size == 0))
{
if(pecb == Co_NULL ) /* If there is no free EVENT control block*/ return E_CREATE_FAIL;
{ }
return E_CREATE_FAIL; #endif
}
return (pecb->id); OsSchedLock();
} for(i = 0; i < CFG_MAX_QUEUE; i++)
} {
/* Assign a free QUEUE control block */
OsSchedUnlock(); if((QueueIDVessel & (1 << i)) == 0)
return E_CREATE_FAIL; /* There is no free QUEUE control block */ {
} QueueIDVessel |= (1<<i);
OsSchedUnlock();
/** QueueTbl[i].qStart = qStart; /* Initialize the queue */
******************************************************************************* QueueTbl[i].id = i;
* @brief Delete a queue QueueTbl[i].head = 0;
* @param[in] id Event ID. QueueTbl[i].tail = 0;
* @param[in] opt Delete option. QueueTbl[i].qMaxSize = size;
* @param[out] None QueueTbl[i].qSize = 0;
* @retval E_INVALID_ID Invalid event ID.
* @retval E_INVALID_PARAMETER Invalid parameter. /* Get a event control block and initial the event content */
* @retval E_TASK_WAITTING Tasks waitting for the event,delete fail. pecb = CreatEvent(EVENT_TYPE_QUEUE,sortType,&QueueTbl[i]);
* @retval E_OK Event deleted successful.
* if(pecb == Co_NULL ) /* If there is no free EVENT control block*/
* @par Description {
* @details This function is called to delete a queue. return E_CREATE_FAIL;
* @note }
******************************************************************************* return (pecb->id);
*/ }
StatusType CoDelQueue(OS_EventID id,U8 opt) }
{
P_ECB pecb; OsSchedUnlock();
P_QCB pqcb; return E_CREATE_FAIL; /* There is no free QUEUE control block */
StatusType err; }
#if CFG_PAR_CHECKOUT_EN >0
if(id >= CFG_MAX_EVENT)
{ /**
return E_INVALID_ID; /* Invalid id,return error */ *******************************************************************************
} * @brief Delete a queue
#endif * @param[in] id Event ID.
* @param[in] opt Delete option.
pecb = &EventTbl[id]; * @param[out] None
#if CFG_PAR_CHECKOUT_EN >0 * @retval E_INVALID_ID Invalid event ID.
if( pecb->eventType != EVENT_TYPE_QUEUE) * @retval E_INVALID_PARAMETER Invalid parameter.
{ * @retval E_TASK_WAITTING Tasks waitting for the event,delete fail.
return E_INVALID_ID; /* The event is not queue,return error*/ * @retval E_OK Event deleted successful.
} *
#endif * @par Description
pqcb = (P_QCB)pecb->eventPtr; /* Point at queue control block */ * @details This function is called to delete a queue.
err = DeleteEvent(pecb,opt); /* Delete the event control block */ * @note
if(err == E_OK) /* If the event block have been deleted */ *******************************************************************************
{ */
QueueIDVessel &= ~((U32)(1<<(pqcb->id))); /* Update free queue list */ StatusType CoDelQueue(OS_EventID id,U8 opt)
pqcb->qStart = Co_NULL; {
pqcb->id = 0; P_ECB pecb;
pqcb->head = 0; P_QCB pqcb;
pqcb->tail = 0; StatusType err;
pqcb->qMaxSize = 0; #if CFG_PAR_CHECKOUT_EN >0
pqcb->qSize = 0; if(id >= CFG_MAX_EVENT)
} {
return err; return E_INVALID_ID; /* Invalid id,return error */
} }
#endif
pecb = &EventTbl[id];
/** #if CFG_PAR_CHECKOUT_EN >0
******************************************************************************* if( pecb->eventType != EVENT_TYPE_QUEUE)
* @brief Accept a mail from queue {
* @param[in] id Event ID. return E_INVALID_ID; /* The event is not queue,return error*/
* @param[out] perr A pointer to error code. }
* @retval Co_NULL #endif
* @retval A pointer to mail accepted. pqcb = (P_QCB)pecb->eventPtr; /* Point at queue control block */
* err = DeleteEvent(pecb,opt); /* Delete the event control block */
* @par Description if(err == E_OK) /* If the event block have been deleted */
* @details This function is called to accept a mail from queue. {
* @note QueueIDVessel &= ~((U32)(1<<(pqcb->id))); /* Update free queue list */
******************************************************************************* pqcb->qStart = Co_NULL;
*/ pqcb->id = 0;
void* CoAcceptQueueMail(OS_EventID id,StatusType* perr) pqcb->head = 0;
{ pqcb->tail = 0;
P_ECB pecb; pqcb->qMaxSize = 0;
P_QCB pqcb; pqcb->qSize = 0;
void* pmail; }
#if CFG_PAR_CHECKOUT_EN >0 return err;
if(id >= CFG_MAX_EVENT) }
{
*perr = E_INVALID_ID; /* Invalid id,return error */
return Co_NULL;
} /**
#endif *******************************************************************************
* @brief Accept a mail from queue
pecb = &EventTbl[id]; * @param[in] id Event ID.
#if CFG_PAR_CHECKOUT_EN >0 * @param[out] perr A pointer to error code.
if(pecb->eventType != EVENT_TYPE_QUEUE)/* Invalid event control block type*/ * @retval Co_NULL
{ * @retval A pointer to mail accepted.
*perr = E_INVALID_ID; *
return Co_NULL; * @par Description
} * @details This function is called to accept a mail from queue.
#endif * @note
pqcb = (P_QCB)pecb->eventPtr; /* Point at queue control block */ *******************************************************************************
OsSchedLock(); */
if(pqcb->qSize != 0) /* If there are any messages in the queue */ void* CoAcceptQueueMail(OS_EventID id,StatusType* perr)
{ {
/* Extract oldest message from the queue */ P_ECB pecb;
pmail = *(pqcb->qStart + pqcb->head); P_QCB pqcb;
pqcb->head++; /* Update the queue head */ void* pmail;
pqcb->qSize--; /* Update the number of messages in the queue */ #if CFG_PAR_CHECKOUT_EN >0
if(pqcb->head == pqcb->qMaxSize) if(id >= CFG_MAX_EVENT)
{ {
pqcb->head = 0; *perr = E_INVALID_ID; /* Invalid id,return error */
} return Co_NULL;
OsSchedUnlock(); }
*perr = E_OK; #endif
return pmail; /* Return message received */
} pecb = &EventTbl[id];
else /* If there is no message in the queue*/ #if CFG_PAR_CHECKOUT_EN >0
{ if(pecb->eventType != EVENT_TYPE_QUEUE)/* Invalid event control block type*/
OsSchedUnlock(); {
*perr = E_QUEUE_EMPTY; *perr = E_INVALID_ID;
return Co_NULL; /* Return Co_NULL */ return Co_NULL;
} }
} #endif
pqcb = (P_QCB)pecb->eventPtr; /* Point at queue control block */
OsSchedLock();
if(pqcb->qSize != 0) /* If there are any messages in the queue */
/** {
******************************************************************************* /* Extract oldest message from the queue */
* @brief Pend for a mail pmail = *(pqcb->qStart + pqcb->head);
* @param[in] id Event ID. pqcb->head++; /* Update the queue head */
* @param[in] timeout The longest time for writting mail. pqcb->qSize--; /* Update the number of messages in the queue */
* @param[out] perr A pointer to error code. if(pqcb->head == pqcb->qMaxSize)
* @retval Co_NULL {
* @retval A pointer to mail accept. pqcb->head = 0;
* }
* @par Description OsSchedUnlock();
* @details This function is called to wait for a mail. *perr = E_OK;
* @note return pmail; /* Return message received */
******************************************************************************* }
*/ else /* If there is no message in the queue*/
void* CoPendQueueMail(OS_EventID id,U32 timeout,StatusType* perr) {
{ OsSchedUnlock();
P_ECB pecb; *perr = E_QUEUE_EMPTY;
P_QCB pqcb; return Co_NULL; /* Return Co_NULL */
P_OSTCB curTCB; }
void* pmail; }
if(OSIntNesting > 0) /* If the caller is ISR */
{
*perr = E_CALL;
return Co_NULL; /**
} *******************************************************************************
#if CFG_PAR_CHECKOUT_EN >0 * @brief Pend for a mail
if(id >= CFG_MAX_EVENT) * @param[in] id Event ID.
{ * @param[in] timeout The longest time for writting mail.
*perr = E_INVALID_ID; /* Invalid event id,return error */ * @param[out] perr A pointer to error code.
return Co_NULL; * @retval Co_NULL
} * @retval A pointer to mail accept.
#endif *
* @par Description
pecb = &EventTbl[id]; * @details This function is called to wait for a mail.
#if CFG_PAR_CHECKOUT_EN >0 * @note
if(pecb->eventType != EVENT_TYPE_QUEUE) /* The event type is not queue */ *******************************************************************************
{ */
*perr = E_INVALID_ID; void* CoPendQueueMail(OS_EventID id,U32 timeout,StatusType* perr)
return Co_NULL; {
} P_ECB pecb;
#endif P_QCB pqcb;
if(OSSchedLock != 0) /* Judge schedule is locked or not? */ P_OSTCB curTCB;
{ void* pmail;
*perr = E_OS_IN_LOCK; /* Schedule is locked,return error */ if(OSIntNesting > 0) /* If the caller is ISR */
return Co_NULL; {
} *perr = E_CALL;
pqcb = (P_QCB)pecb->eventPtr; /* Point at queue control block */ return Co_NULL;
OsSchedLock(); }
if(pqcb->qSize != 0) /* If there are any messages in the queue */ #if CFG_PAR_CHECKOUT_EN >0
{ if(id >= CFG_MAX_EVENT)
/* Extract oldest message from the queue */ {
pmail = *(pqcb->qStart + pqcb->head); *perr = E_INVALID_ID; /* Invalid event id,return error */
pqcb->head++; /* Update the queue head */ return Co_NULL;
pqcb->qSize--; /* Update the number of messages in the queue */ }
if(pqcb->head == pqcb->qMaxSize)/* Check queue head */ #endif
{
pqcb->head = 0; pecb = &EventTbl[id];
} #if CFG_PAR_CHECKOUT_EN >0
OsSchedUnlock(); if(pecb->eventType != EVENT_TYPE_QUEUE) /* The event type is not queue */
*perr = E_OK; {
return pmail; /* Return message received */ *perr = E_INVALID_ID;
} return Co_NULL;
else /* If there is no message in the queue*/ }
{ #endif
OsSchedUnlock(); if(OSSchedLock != 0) /* Judge schedule is locked or not? */
curTCB = TCBRunning; {
if(timeout == 0) /* If time-out is not configured */ *perr = E_OS_IN_LOCK; /* Schedule is locked,return error */
{ return Co_NULL;
/* Block current task until the event occur */ }
EventTaskToWait(pecb,curTCB); pqcb = (P_QCB)pecb->eventPtr; /* Point at queue control block */
OsSchedLock();
/* Have recived message or the queue have been deleted */ if(pqcb->qSize != 0) /* If there are any messages in the queue */
pmail = curTCB->pmail; {
curTCB->pmail = Co_NULL; /* Extract oldest message from the queue */
*perr = E_OK; pmail = *(pqcb->qStart + pqcb->head);
return pmail; /* Return message received or Co_NULL */ pqcb->head++; /* Update the queue head */
} pqcb->qSize--; /* Update the number of messages in the queue */
else /* If time-out is configured */ if(pqcb->head == pqcb->qMaxSize)/* Check queue head */
{ {
OsSchedLock(); pqcb->head = 0;
}
/* Block current task until event or timeout occurs */ OsSchedUnlock();
EventTaskToWait(pecb,curTCB); *perr = E_OK;
InsertDelayList(curTCB,timeout); return pmail; /* Return message received */
OsSchedUnlock(); }
if(curTCB->pmail == Co_NULL) /* If time-out occurred */ else /* If there is no message in the queue*/
{ {
*perr = E_TIMEOUT; OsSchedUnlock();
return Co_NULL; curTCB = TCBRunning;
} if(timeout == 0) /* If time-out is not configured */
else /* If event occured */ {
{ /* Block current task until the event occur */
pmail = curTCB->pmail; EventTaskToWait(pecb,curTCB);
curTCB->pmail = Co_NULL;
*perr = E_OK; /* Have recived message or the queue have been deleted */
return pmail; /* Return message received or Co_NULL */ OsSchedLock();
} pmail = curTCB->pmail;
} curTCB->pmail = Co_NULL;
} pqcb->head++; /* Clear event sign */
} pqcb->qSize--;
if(pqcb->head == pqcb->qMaxSize)
{
pqcb->head = 0;
/** }
******************************************************************************* OsSchedUnlock();
* @brief Post a mail to queue *perr = E_OK;
* @param[in] id Event ID. return pmail; /* Return message received or Co_NULL */
* @param[in] pmail Pointer to mail that want to send. }
* @param[out] None else /* If time-out is configured */
* @retval E_OK {
* @retval E_INVALID_ID OsSchedLock();
* @retval E_QUEUE_FULL
* /* Block current task until event or timeout occurs */
* @par Description EventTaskToWait(pecb,curTCB);
* @details This function is called to post a mail to queue. InsertDelayList(curTCB,timeout);
* @note OsSchedUnlock();
******************************************************************************* if(curTCB->pmail == Co_NULL) /* If time-out occurred */
*/ {
StatusType CoPostQueueMail(OS_EventID id,void* pmail) *perr = E_TIMEOUT;
{ return Co_NULL;
P_ECB pecb; }
P_QCB pqcb; else /* If event occured */
#if CFG_PAR_CHECKOUT_EN >0 {
if(id >= CFG_MAX_EVENT) OsSchedLock();
{ pmail = curTCB->pmail;
return E_INVALID_ID; curTCB->pmail = Co_NULL;
} pqcb->head++; /* Clear event sign */
#endif pqcb->qSize--;
if(pqcb->head == pqcb->qMaxSize)
pecb = &EventTbl[id]; {
#if CFG_PAR_CHECKOUT_EN >0 pqcb->head = 0;
if(pecb->eventType != EVENT_TYPE_QUEUE) }
{ OsSchedUnlock();
return E_INVALID_ID; /* The event type isn't queue,return */ *perr = E_OK;
} return pmail; /* Return message received or Co_NULL */
#endif }
pqcb = (P_QCB)pecb->eventPtr; }
if(pqcb->qSize == pqcb->qMaxSize) /* If queue is full */ }
{ }
return E_QUEUE_FULL;
}
else /* If queue is not full */
{ /**
OsSchedLock(); *******************************************************************************
*(pqcb->qStart + pqcb->tail) = pmail; /* Insert message into queue */ * @brief Post a mail to queue
pqcb->tail++; /* Update queue tail */ * @param[in] id Event ID.
pqcb->qSize++; /* Update the number of messages in the queue */ * @param[in] pmail Pointer to mail that want to send.
if(pqcb->tail == pqcb->qMaxSize) /* Check queue tail */ * @param[out] None
{ * @retval E_OK
pqcb->tail = 0; * @retval E_INVALID_ID
} * @retval E_QUEUE_FULL
EventTaskToRdy(pecb); /* Check the event waiting list */ *
OsSchedUnlock(); * @par Description
return E_OK; * @details This function is called to post a mail to queue.
} * @note
} *******************************************************************************
*/
StatusType CoPostQueueMail(OS_EventID id,void* pmail)
/** {
******************************************************************************* P_ECB pecb;
* @brief Post a mail to queue in ISR P_QCB pqcb;
* @param[in] id Event ID. #if CFG_PAR_CHECKOUT_EN >0
* @param[in] pmail Pointer to mail that want to send. if(id >= CFG_MAX_EVENT)
* @param[out] None {
* @retval E_OK return E_INVALID_ID;
* @retval E_INVALID_ID }
* @retval E_QUEUE_FULL #endif
*
* @par Description pecb = &EventTbl[id];
* @details This function is called in ISR to post a mail to queue. #if CFG_PAR_CHECKOUT_EN >0
* @note if(pecb->eventType != EVENT_TYPE_QUEUE)
******************************************************************************* {
*/ return E_INVALID_ID; /* The event type isn't queue,return */
#if CFG_MAX_SERVICE_REQUEST > 0 }
StatusType isr_PostQueueMail(OS_EventID id,void* pmail) #endif
{ pqcb = (P_QCB)pecb->eventPtr;
if(OSSchedLock > 0) /* If scheduler is locked,(the caller is ISR) */ if(pqcb->qSize == pqcb->qMaxSize) /* If queue is full */
{ {
/* Insert the request into service request queue */ return E_QUEUE_FULL;
if(InsertInSRQ(QUEUE_REQ,id,pmail) == Co_FALSE) }
{ else /* If queue is not full */
return E_SEV_REQ_FULL; /* If service request queue is full */ {
} OsSchedLock();
else /* If the request have been inserted into service request queue */ *(pqcb->qStart + pqcb->tail) = pmail; /* Insert message into queue */
{ pqcb->tail++; /* Update queue tail */
return E_OK; pqcb->qSize++; /* Update the number of messages in the queue */
} if(pqcb->tail == pqcb->qMaxSize) /* Check queue tail */
} {
else /* The scheduler is unlocked */ pqcb->tail = 0;
{ }
return(CoPostQueueMail(id,pmail)); /* Send the message to the queue*/ EventTaskToRdy(pecb); /* Check the event waiting list */
} OsSchedUnlock();
} return E_OK;
#endif }
}
#endif
/**
*******************************************************************************
* @brief Post a mail to queue in ISR
* @param[in] id Event ID.
* @param[in] pmail Pointer to mail that want to send.
* @param[out] None
* @retval E_OK
* @retval E_INVALID_ID
* @retval E_QUEUE_FULL
*
* @par Description
* @details This function is called in ISR to post a mail to queue.
* @note
*******************************************************************************
*/
#if CFG_MAX_SERVICE_REQUEST > 0
StatusType isr_PostQueueMail(OS_EventID id,void* pmail)
{
if(OSSchedLock > 0) /* If scheduler is locked,(the caller is ISR) */
{
/* Insert the request into service request queue */
if(InsertInSRQ(QUEUE_REQ,id,pmail) == Co_FALSE)
{
return E_SEV_REQ_FULL; /* If service request queue is full */
}
else /* If the request have been inserted into service request queue */
{
return E_OK;
}
}
else /* The scheduler is unlocked */
{
return(CoPostQueueMail(id,pmail)); /* Send the message to the queue*/
}
}
#endif
#endif
+347 -322
View File
@@ -1,322 +1,347 @@
/** /**
******************************************************************************* *******************************************************************************
* @file sem.c * @file sem.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Semaphore management implementation code of CooCox CoOS kernel. * @brief Semaphore management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
/*---------------------------- Include ---------------------------------------*/ * notice, this list of conditions and the following disclaimer in the
#include <coocox.h> * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
#if CFG_SEM_EN >0 * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
/** *
******************************************************************************* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* @brief Create a semaphore * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* @param[in] initCnt Semaphore valid counter. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* @param[in] maxCnt Semaphore max initialize counter. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* @param[in] sortType Semaphore sort type. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* @param[out] None * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* @retval E_CREATE_FAIL Create semaphore fail. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* @retval others Create semaphore successful. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* @par Description * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* @details This function is called to create a semaphore. * THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************* *
*/ * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
OS_EventID CoCreateSem(U16 initCnt,U16 maxCnt,U8 sortType) *******************************************************************************
{ */
P_ECB pecb;
#if CFG_PAR_CHECKOUT_EN >0
if(initCnt > maxCnt) /*---------------------------- Include ---------------------------------------*/
{ #include <coocox.h>
return E_CREATE_FAIL; /* Invalid 'initCnt' or 'maxCnt' */
} #if CFG_SEM_EN >0
if ((sortType != EVENT_SORT_TYPE_FIFO) && (sortType != EVENT_SORT_TYPE_PRIO)) /**
{ *******************************************************************************
return E_CREATE_FAIL; /* Illegal sort type,return error */ * @brief Create a semaphore
} * @param[in] initCnt Semaphore valid counter.
#endif * @param[in] maxCnt Semaphore max initialize counter.
* @param[in] sortType Semaphore sort type.
/* Create a semaphore type event control block */ * @param[out] None
pecb = CreatEvent(EVENT_TYPE_SEM,sortType,Co_NULL); * @retval E_CREATE_FAIL Create semaphore fail.
if(pecb == Co_NULL) /* If failed to create event block */ * @retval others Create semaphore successful.
{ *
return E_CREATE_FAIL; * @par Description
} * @details This function is called to create a semaphore.
pecb->eventCounter = initCnt;/* Initialize event block */ *******************************************************************************
pecb->initialEventCounter = maxCnt; */
return (pecb->id); /* Return event id */ OS_EventID CoCreateSem(U16 initCnt,U16 maxCnt,U8 sortType)
} {
P_ECB pecb;
#if CFG_PAR_CHECKOUT_EN >0
/** if(initCnt > maxCnt)
******************************************************************************* {
* @brief Delete a semaphore return E_CREATE_FAIL; /* Invalid 'initCnt' or 'maxCnt' */
* @param[in] id Event ID which to be deleted. }
* @param[in] opt Delete option.
* @arg == OPT_DEL_ANYWAY Delete semaphore always if ((sortType != EVENT_SORT_TYPE_FIFO) && (sortType != EVENT_SORT_TYPE_PRIO))
* @arg == OPT_DEL_NO_PEND Delete semaphore only when no task pending on. {
* @param[out] None return E_CREATE_FAIL; /* Illegal sort type,return error */
* @retval E_INVALID_ID Invalid event ID. }
* @retval E_INVALID_PARAMETER Invalid parameter. #endif
* @retval E_TASK_WAITTING Tasks waitting for the event,delete fail.
* @retval E_OK Event deleted successful. /* Create a semaphore type event control block */
* pecb = CreatEvent(EVENT_TYPE_SEM,sortType,Co_NULL);
* @par Description if(pecb == Co_NULL) /* If failed to create event block */
* @details This function is called to delete a semaphore. {
* return E_CREATE_FAIL;
* @note }
******************************************************************************* pecb->eventCounter = initCnt;/* Initialize event block */
*/ pecb->initialEventCounter = maxCnt;
StatusType CoDelSem(OS_EventID id,U8 opt) return (pecb->id); /* Return event id */
{ }
P_ECB pecb;
#if CFG_PAR_CHECKOUT_EN >0 /**
if(id >= CFG_MAX_EVENT) *******************************************************************************
{ * @brief Delete a semaphore
return E_INVALID_ID; * @param[in] id Event ID which to be deleted.
} * @param[in] opt Delete option.
#endif * @arg == OPT_DEL_ANYWAY Delete semaphore always
* @arg == OPT_DEL_NO_PEND Delete semaphore only when no task pending on.
pecb = &EventTbl[id]; * @param[out] None
* @retval E_INVALID_ID Invalid event ID.
#if CFG_PAR_CHECKOUT_EN >0 * @retval E_INVALID_PARAMETER Invalid parameter.
if(pecb->eventType != EVENT_TYPE_SEM) * @retval E_TASK_WAITTING Tasks waitting for the event,delete fail.
{ * @retval E_OK Event deleted successful.
return E_INVALID_ID; /* The event type is not semaphore */ *
} * @par Description
#endif * @details This function is called to delete a semaphore.
*
return (DeleteEvent(pecb,opt));/* Delete the semaphore event control block*/ * @note
} *******************************************************************************
*/
StatusType CoDelSem(OS_EventID id,U8 opt)
/** {
******************************************************************************* P_ECB pecb;
* @brief Accept a semaphore without waitting
* @param[in] id Event ID #if CFG_PAR_CHECKOUT_EN >0
* @param[out] None if(id >= CFG_MAX_EVENT)
* @retval E_INVALID_ID Invalid event ID. {
* @retval E_SEM_EMPTY No semaphore exist. return E_INVALID_ID;
* @retval E_OK Get semaphore successful. }
* #endif
* @par Description
* @details This function is called accept a semaphore without waitting. pecb = &EventTbl[id];
*******************************************************************************
*/ #if CFG_PAR_CHECKOUT_EN >0
StatusType CoAcceptSem(OS_EventID id) if(pecb->eventType != EVENT_TYPE_SEM)
{ {
P_ECB pecb; return E_INVALID_ID; /* The event type is not semaphore */
#if CFG_PAR_CHECKOUT_EN >0 }
if(id >= CFG_MAX_EVENT) #endif
{
return E_INVALID_ID; return (DeleteEvent(pecb,opt));/* Delete the semaphore event control block*/
} }
#endif
pecb = &EventTbl[id]; /**
#if CFG_PAR_CHECKOUT_EN >0 *******************************************************************************
if( pecb->eventType != EVENT_TYPE_SEM) * @brief Accept a semaphore without waitting
{ * @param[in] id Event ID
return E_INVALID_ID; * @param[out] None
} * @retval E_INVALID_ID Invalid event ID.
#endif * @retval E_SEM_EMPTY No semaphore exist.
OsSchedLock(); * @retval E_OK Get semaphore successful.
if(pecb->eventCounter > 0) /* If semaphore is positive,resource available */ *
{ * @par Description
OsSchedUnlock(); * @details This function is called accept a semaphore without waitting.
pecb->eventCounter--; /* Decrement semaphore only if positive */ *******************************************************************************
return E_OK; */
} StatusType CoAcceptSem(OS_EventID id)
else /* Resource is not available */ {
{ P_ECB pecb;
OsSchedUnlock(); #if CFG_PAR_CHECKOUT_EN >0
return E_SEM_EMPTY; if(id >= CFG_MAX_EVENT)
} {
} return E_INVALID_ID;
}
#endif
/**
******************************************************************************* pecb = &EventTbl[id];
* @brief wait for a semaphore #if CFG_PAR_CHECKOUT_EN >0
* @param[in] id Event ID. if( pecb->eventType != EVENT_TYPE_SEM)
* @param[in] timeout The longest time for writting semaphore. {
* @para 0 return E_INVALID_ID;
* @para 0x1~0xff }
* @param[out] None #endif
* @retval E_CALL Error call in ISR. OsSchedLock();
* @retval E_INVALID_ID Invalid event ID. if(pecb->eventCounter > 0) /* If semaphore is positive,resource available */
* @retval E_TIMEOUT Semaphore was not received within the specified {
* 'timeout' time. pecb->eventCounter--; /* Decrement semaphore only if positive */
* @retval E_OK The call was successful and your task owns the OsSchedUnlock();
* resource,or the event you are waiting for occurred. return E_OK;
* }
* @par Description else /* Resource is not available */
* @details This function is called to waits for a semaphore. {
* @note IF this function is called in ISR,nothing to do and return immediately. OsSchedUnlock();
******************************************************************************* return E_SEM_EMPTY;
*/ }
StatusType CoPendSem(OS_EventID id,U32 timeout) }
{
P_ECB pecb;
P_OSTCB curTCB; /**
if(OSIntNesting > 0) /* If the caller is ISR */ *******************************************************************************
{ * @brief wait for a semaphore
return E_CALL; * @param[in] id Event ID.
} * @param[in] timeout The longest time for writting semaphore.
#if CFG_PAR_CHECKOUT_EN >0 * @para 0
if(id >= CFG_MAX_EVENT) * @para 0x1~0xff
{ * @param[out] None
return E_INVALID_ID; * @retval E_CALL Error call in ISR.
} * @retval E_INVALID_ID Invalid event ID.
#endif * @retval E_TIMEOUT Semaphore was not received within the specified
* 'timeout' time.
pecb = &EventTbl[id]; * @retval E_OK The call was successful and your task owns the
#if CFG_PAR_CHECKOUT_EN >0 * resource,or the event you are waiting for occurred.
if(pecb->eventType != EVENT_TYPE_SEM) *
{ * @par Description
return E_INVALID_ID; * @details This function is called to waits for a semaphore.
} * @note IF this function is called in ISR,nothing to do and return immediately.
#endif *******************************************************************************
if(OSSchedLock != 0) /* Schdule is locked? */ */
{ StatusType CoPendSem(OS_EventID id,U32 timeout)
return E_OS_IN_LOCK; /* Yes,error return */ {
} P_ECB pecb;
OsSchedLock(); P_OSTCB curTCB;
if(pecb->eventCounter > 0) /* If semaphore is positive,resource available */ if(OSIntNesting > 0) /* If the caller is ISR */
{ {
pecb->eventCounter--; /* Decrement semaphore only if positive */ return E_CALL;
OsSchedUnlock(); }
return E_OK; #if CFG_PAR_CHECKOUT_EN >0
} if(id >= CFG_MAX_EVENT)
else /* Resource is not available */ {
{ return E_INVALID_ID;
OsSchedUnlock(); }
curTCB = TCBRunning; #endif
if(timeout == 0) /* If time-out is not configured */
{ pecb = &EventTbl[id];
EventTaskToWait(pecb,curTCB); /* Block task until event occurs */ #if CFG_PAR_CHECKOUT_EN >0
curTCB->pmail = Co_NULL; if(pecb->eventType != EVENT_TYPE_SEM)
return E_OK; {
} return E_INVALID_ID;
else /* If time-out is configured */ }
{ #endif
OsSchedLock(); if(OSSchedLock != 0) /* Schdule is locked? */
{
/* Block task until event or timeout occurs */ return E_OS_IN_LOCK; /* Yes,error return */
EventTaskToWait(pecb,curTCB); }
InsertDelayList(curTCB,timeout); OsSchedLock();
if(pecb->eventCounter > 0) /* If semaphore is positive,resource available */
OsSchedUnlock(); {
if (curTCB->pmail == Co_NULL) /* If pmail is Co_NULL, time-out occurred*/ pecb->eventCounter--; /* Decrement semaphore only if positive */
{ OsSchedUnlock();
return E_TIMEOUT; return E_OK;
} }
else /* Event occurred or event have been deleted*/ else /* Resource is not available */
{ {
curTCB->pmail = Co_NULL; curTCB = TCBRunning;
return E_OK; if(timeout == 0) /* If time-out is not configured */
} {
} EventTaskToWait(pecb,curTCB); /* Block task until event occurs */
} pecb->eventCounter--;
} curTCB->pmail = Co_NULL;
OsSchedUnlock();
return E_OK;
/** }
******************************************************************************* else /* If time-out is configured */
* @brief Post a semaphore {
* @param[in] id id of event control block associated with the desired semaphore. /* Block task until event or timeout occurs */
* @param[out] None EventTaskToWait(pecb,curTCB);
* @retval E_INVALID_ID Parameter id passed was invalid event ID. InsertDelayList(curTCB,timeout);
* @retval E_SEM_FULL Semaphore full.
* @retval E_OK Semaphore had post successful. OsSchedUnlock();
* if (curTCB->pmail == Co_NULL) /* If pmail is Co_NULL, time-out occurred*/
* @par Description {
* @details This function is called to post a semaphore to corresponding event. return E_TIMEOUT;
* }
* @note else /* Event occurred or event have been deleted*/
******************************************************************************* {
*/ OsSchedLock();
StatusType CoPostSem(OS_EventID id) curTCB->pmail = Co_NULL;
{ pecb->eventCounter--;
P_ECB pecb; OsSchedUnlock();
#if CFG_PAR_CHECKOUT_EN >0 return E_OK;
if(id >= CFG_MAX_EVENT) }
{ }
return E_INVALID_ID; }
} }
#endif
pecb = &EventTbl[id]; /**
#if CFG_PAR_CHECKOUT_EN >0 *******************************************************************************
if(pecb->eventType != EVENT_TYPE_SEM) /* Invalid event control block type */ * @brief Post a semaphore
{ * @param[in] id id of event control block associated with the desired semaphore.
return E_INVALID_ID; * @param[out] None
} * @retval E_INVALID_ID Parameter id passed was invalid event ID.
#endif * @retval E_SEM_FULL Semaphore full.
* @retval E_OK Semaphore had post successful.
/* Make sure semaphore will not overflow */ *
if(pecb->eventCounter == pecb->initialEventCounter) * @par Description
{ * @details This function is called to post a semaphore to corresponding event.
return E_SEM_FULL; /* The counter of Semaphore reach the max number*/ *
} * @note
OsSchedLock(); *******************************************************************************
pecb->eventCounter++; /* Increment semaphore count to register event */ */
EventTaskToRdy(pecb); /* Check semaphore event waiting list */ StatusType CoPostSem(OS_EventID id)
OsSchedUnlock(); {
return E_OK; P_ECB pecb;
#if CFG_PAR_CHECKOUT_EN >0
} if(id >= CFG_MAX_EVENT)
{
return E_INVALID_ID;
/** }
******************************************************************************* #endif
* @brief Post a semaphore in ISR
* @param[in] id identifier of event control block associated with the pecb = &EventTbl[id];
* desired semaphore. #if CFG_PAR_CHECKOUT_EN >0
* @param[out] None if(pecb->eventType != EVENT_TYPE_SEM) /* Invalid event control block type */
* @retval E_INVALID_ID Parameter id passed was invalid event ID. {
* @retval E_NO_TASK_WAITTING There are one more tasks waitting for the event. return E_INVALID_ID;
* @retval E_OK Semaphore had signaled successful. }
* #endif
* @par Description
* @details This function is called in ISR to post a semaphore to corresponding /* Make sure semaphore will not overflow */
* event. if(pecb->eventCounter == pecb->initialEventCounter)
* @note {
******************************************************************************* return E_SEM_FULL; /* The counter of Semaphore reach the max number*/
*/ }
#if CFG_MAX_SERVICE_REQUEST > 0 OsSchedLock();
StatusType isr_PostSem(OS_EventID id) pecb->eventCounter++; /* Increment semaphore count to register event */
{ EventTaskToRdy(pecb); /* Check semaphore event waiting list */
if(OSSchedLock > 0) /* If scheduler is locked,(the caller is ISR) */ OsSchedUnlock();
{ return E_OK;
/* Initiate a post service handling request */
if(InsertInSRQ(SEM_REQ,id,Co_NULL) == Co_FALSE) }
{
return E_SEV_REQ_FULL; /* If service request queue is full */
} /**
else /* Operate successfully */ *******************************************************************************
{ * @brief Post a semaphore in ISR
return E_OK; * @param[in] id identifier of event control block associated with the
} * desired semaphore.
} * @param[out] None
else * @retval E_INVALID_ID Parameter id passed was invalid event ID.
{ * @retval E_NO_TASK_WAITTING There are one more tasks waitting for the event.
return(CoPostSem(id)); /* Post semaphore */ * @retval E_OK Semaphore had signaled successful.
} *
} * @par Description
#endif * @details This function is called in ISR to post a semaphore to corresponding
* event.
#endif * @note
*******************************************************************************
*/
#if CFG_MAX_SERVICE_REQUEST > 0
StatusType isr_PostSem(OS_EventID id)
{
if(OSSchedLock > 0) /* If scheduler is locked,(the caller is ISR) */
{
/* Initiate a post service handling request */
if(InsertInSRQ(SEM_REQ,id,Co_NULL) == Co_FALSE)
{
return E_SEV_REQ_FULL; /* If service request queue is full */
}
else /* Operate successfully */
{
return E_OK;
}
}
else
{
return(CoPostSem(id)); /* Post semaphore */
}
}
#endif
#endif
+188 -165
View File
@@ -1,165 +1,188 @@
/** /**
******************************************************************************* *******************************************************************************
* @file serviceReq.c * @file serviceReq.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief servive request management implementation code of CooCox CoOS kernel. * @brief servive request management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
/*---------------------------- Include ---------------------------------------*/ * documentation and/or other materials provided with the distribution.
#include <coocox.h> * * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
#if (CFG_TASK_WAITTING_EN > 0) || (CFG_TMR_EN >0) * from this software without specific prior written permission.
*
#if CFG_MAX_SERVICE_REQUEST > 0 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
/*---------------------------- Variable Define -------------------------------*/ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
SRQ ServiceReq = {0,0}; /*!< ISR server request queue */ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#endif * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
BOOL IsrReq = Co_FALSE; * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#if (CFG_TASK_WAITTING_EN > 0) * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
BOOL TimeReq = Co_FALSE; /*!< Time delay dispose request */ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#endif * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#if CFG_TMR_EN > 0 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
BOOL TimerReq = Co_FALSE; /*!< Timer dispose request */ * THE POSSIBILITY OF SUCH DAMAGE.
#endif *
* <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
/** *******************************************************************************
******************************************************************************* */
* @brief Insert into service requst queue
* @param[in] type Service request type.
* @param[in] id Service request event id,event id/flag id.
* @param[in] arg Service request argument. /*---------------------------- Include ---------------------------------------*/
* @param[out] None #include <coocox.h>
*
* @retval Co_FALSE Successfully insert into service request queue. #if (CFG_TASK_WAITTING_EN > 0) || (CFG_TMR_EN >0)
* @retval Co_TRUE Failure to insert into service request queue.
* #if CFG_MAX_SERVICE_REQUEST > 0
* @par Description /*---------------------------- Variable Define -------------------------------*/
* @details This function be called to insert a requst into service request SRQ ServiceReq = {0,0}; /*!< ISR server request queue */
* queue. #endif
* @note BOOL IsrReq = Co_FALSE;
******************************************************************************* #if (CFG_TASK_WAITTING_EN > 0)
*/ BOOL TimeReq = Co_FALSE; /*!< Time delay dispose request */
#if (CFG_MAX_SERVICE_REQUEST > 0) #endif
BOOL InsertInSRQ(U8 type,U8 id,void* arg)
{ #if CFG_TMR_EN > 0
P_SQC pcell; BOOL TimerReq = Co_FALSE; /*!< Timer dispose request */
U8 cnt; #endif
U8 heed;
IRQ_DISABLE_SAVE(); /**
if (ServiceReq.cnt >= CFG_MAX_SERVICE_REQUEST) *******************************************************************************
{ * @brief Insert into service requst queue
IRQ_ENABLE_RESTORE (); * @param[in] type Service request type.
* @param[in] id Service request event id,event id/flag id.
return Co_FALSE; /* Error return */ * @param[in] arg Service request argument.
} * @param[out] None
cnt = Inc8(&ServiceReq.cnt); *
heed = ServiceReq.head; * @retval Co_FALSE Successfully insert into service request queue.
IsrReq = Co_TRUE; * @retval Co_TRUE Failure to insert into service request queue.
pcell = &ServiceReq.cell[((cnt+heed)%CFG_MAX_SERVICE_REQUEST)];/*the tail */ *
pcell->type = type; /* Save service request type, */ * @par Description
pcell->id = id; /* event id */ * @details This function be called to insert a requst into service request
pcell->arg = arg; /* and parameter */ * queue.
IRQ_ENABLE_RESTORE (); * @note
*******************************************************************************
return Co_TRUE; /* Return OK */ */
} #if (CFG_MAX_SERVICE_REQUEST > 0)
#endif BOOL InsertInSRQ(U8 type,U8 id,void* arg)
{
P_SQC pcell;
U8 cnt;
/** U8 heed;
******************************************************************************* IRQ_DISABLE_SAVE();
* @brief Respond the request in the service request queue. if (ServiceReq.cnt >= CFG_MAX_SERVICE_REQUEST)
* @param[in] None {
* @param[out] None IRQ_ENABLE_RESTORE ();
* @retval None
* return Co_FALSE; /* Error return */
* @par Description }
* @details This function be called to respond the request in the service cnt = Inc8(&ServiceReq.cnt);
* request queue. heed = ServiceReq.head;
* @note IsrReq = Co_TRUE;
******************************************************************************* pcell = &ServiceReq.cell[((cnt+heed)%CFG_MAX_SERVICE_REQUEST)];/*the tail */
*/ pcell->type = type; /* Save service request type, */
void RespondSRQ(void) pcell->id = id; /* event id */
{ pcell->arg = arg; /* and parameter */
IRQ_ENABLE_RESTORE ();
#if CFG_MAX_SERVICE_REQUEST > 0
SQC cell; return Co_TRUE; /* Return OK */
}
#endif #endif
#if (CFG_TASK_WAITTING_EN > 0)
if(TimeReq == Co_TRUE) /* Time delay request? */
{ /**
TimeDispose(); /* Yes,call handler */ *******************************************************************************
TimeReq = Co_FALSE; /* Reset time delay request Co_FALSE */ * @brief Respond the request in the service request queue.
} * @param[in] None
#endif * @param[out] None
#if CFG_TMR_EN > 0 * @retval None
if(TimerReq == Co_TRUE) /* Timer request? */ *
{ * @par Description
TmrDispose(); /* Yes,call handler */ * @details This function be called to respond the request in the service
TimerReq = Co_FALSE; /* Reset timer request Co_FALSE */ * request queue.
} * @note
#endif *******************************************************************************
*/
#if CFG_MAX_SERVICE_REQUEST > 0 void RespondSRQ(void)
{
while (ServiceReq.cnt != 0)
{ #if CFG_MAX_SERVICE_REQUEST > 0
IRQ_DISABLE_SAVE (); /* need to protect the following */ SQC cell;
cell = ServiceReq.cell[ServiceReq.head]; /* extract one cell */
ServiceReq.head = (ServiceReq.head + 1) % /* move head (pop) */ #endif
CFG_MAX_SERVICE_REQUEST;
ServiceReq.cnt--; #if (CFG_TASK_WAITTING_EN > 0)
IRQ_ENABLE_RESTORE (); /* now use the cell copy */ if(TimeReq == Co_TRUE) /* Time delay request? */
{
switch(cell.type) /* Judge service request type */ TimeDispose(); /* Yes,call handler */
{ TimeReq = Co_FALSE; /* Reset time delay request Co_FALSE */
#if CFG_SEM_EN > 0 }
case SEM_REQ: /* Semaphore post request,call handler*/ #endif
CoPostSem(cell.id); #if CFG_TMR_EN > 0
break; if(TimerReq == Co_TRUE) /* Timer request? */
#endif {
#if CFG_MAILBOX_EN > 0 TmrDispose(); /* Yes,call handler */
case MBOX_REQ: /* Mailbox post request,call handler */ TimerReq = Co_FALSE; /* Reset timer request Co_FALSE */
CoPostMail(cell.id, cell.arg); }
break; #endif
#endif
#if CFG_FLAG_EN > 0 #if CFG_MAX_SERVICE_REQUEST > 0
case FLAG_REQ: /* Flag set request,call handler */
CoSetFlag(cell.id); while (ServiceReq.cnt != 0)
break; {
#endif IRQ_DISABLE_SAVE (); /* need to protect the following */
#if CFG_QUEUE_EN > 0 cell = ServiceReq.cell[ServiceReq.head]; /* extract one cell */
case QUEUE_REQ: /* Queue post request,call handler */ ServiceReq.head = (ServiceReq.head + 1) % /* move head (pop) */
CoPostQueueMail(cell.id, cell.arg); CFG_MAX_SERVICE_REQUEST;
break; ServiceReq.cnt--;
#endif IRQ_ENABLE_RESTORE (); /* now use the cell copy */
default: /* Others,break */
break; switch(cell.type) /* Judge service request type */
} {
} #if CFG_SEM_EN > 0
#endif case SEM_REQ: /* Semaphore post request,call handler*/
IRQ_DISABLE_SAVE (); /* need to protect the following */ CoPostSem(cell.id);
break;
if (ServiceReq.cnt == 0) /* another item in the queue already? */ #endif
{ #if CFG_MAILBOX_EN > 0
IsrReq = Co_FALSE; /* queue still empty here */ case MBOX_REQ: /* Mailbox post request,call handler */
} CoPostMail(cell.id, cell.arg);
IRQ_ENABLE_RESTORE (); /* now it is done and return */ break;
} #endif
#if CFG_FLAG_EN > 0
#endif case FLAG_REQ: /* Flag set request,call handler */
CoSetFlag(cell.id);
break;
#endif
#if CFG_QUEUE_EN > 0
case QUEUE_REQ: /* Queue post request,call handler */
CoPostQueueMail(cell.id, cell.arg);
break;
#endif
default: /* Others,break */
break;
}
}
#endif
IRQ_DISABLE_SAVE (); /* need to protect the following */
if (ServiceReq.cnt == 0) /* another item in the queue already? */
{
IsrReq = Co_FALSE; /* queue still empty here */
}
IRQ_ENABLE_RESTORE (); /* now it is done and return */
}
#endif
+1283 -1260
View File
File diff suppressed because it is too large Load Diff
+399 -376
View File
@@ -1,376 +1,399 @@
/** /**
******************************************************************************* *******************************************************************************
* @file time.c * @file time.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief time management implementation code of CooCox CoOS kernel. * @brief time management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
/*---------------------------- Include ---------------------------------------*/ * documentation and/or other materials provided with the distribution.
#include <coocox.h> * * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
#if CFG_TASK_WAITTING_EN > 0 * from this software without specific prior written permission.
*
/*---------------------------- Variable Define -------------------------------*/ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
P_OSTCB DlyList = Co_NULL; /*!< Header pointer to the DELAY list.*/ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
/** * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
******************************************************************************* * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* @brief Insert into DELAY list * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* @param[in] ptcb Task that want to insert into DELAY list. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* @param[in] ticks Delay system ticks. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* @param[out] None * THE POSSIBILITY OF SUCH DAMAGE.
* @retval None. *
* * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
* @par Description *******************************************************************************
* @details This function is called to insert task into DELAY list. */
*******************************************************************************
*/
void InsertDelayList(P_OSTCB ptcb,U32 ticks)
{ /*---------------------------- Include ---------------------------------------*/
S32 deltaTicks; #include <coocox.h>
P_OSTCB dlyNext;
#if CFG_TASK_WAITTING_EN > 0
if(ticks == 0) /* Is delay tick == 0? */
return; /* Yes,do nothing,return */ /*---------------------------- Variable Define -------------------------------*/
if(DlyList == Co_NULL) /* Is no item in DELAY list? */ P_OSTCB DlyList = Co_NULL; /*!< Header pointer to the DELAY list.*/
{
ptcb->delayTick = ticks; /* Yes,set this as first item */
DlyList = ptcb; /**
} *******************************************************************************
else * @brief Insert into DELAY list
{ *
/* No,find correct place ,and insert the task */ * @param[in] ptcb Task that want to insert into DELAY list.
dlyNext = DlyList; * @param[in] ticks Delay system ticks.
deltaTicks = ticks; /* Get task delay ticks */ * @param[out] None
* @retval None.
/* Find correct place */ *
while(dlyNext != Co_NULL) * @par Description
{ * @details This function is called to insert task into DELAY list.
/* Get delta ticks with previous item */ *******************************************************************************
deltaTicks -= dlyNext->delayTick; */
if(deltaTicks < 0) /* Is delta ticks<0? */ void InsertDelayList(P_OSTCB ptcb,U32 ticks)
{ {
/* Yes,get correct place */ S32 deltaTicks;
if(dlyNext->TCBprev != Co_NULL) /* Is head item of DELAY list? */ P_OSTCB dlyNext;
{
dlyNext->TCBprev->TCBnext = ptcb; /* No,insert into */ if(ticks == 0) /* Is delay tick == 0? */
ptcb->TCBprev = dlyNext->TCBprev; return; /* Yes,do nothing,return */
ptcb->TCBnext = dlyNext; if(DlyList == Co_NULL) /* Is no item in DELAY list? */
dlyNext->TCBprev = ptcb; {
} ptcb->delayTick = ticks; /* Yes,set this as first item */
else /* Yes,set task as first item */ DlyList = ptcb;
{ }
ptcb->TCBnext = DlyList; else
DlyList->TCBprev = ptcb; {
DlyList = ptcb; /* No,find correct place ,and insert the task */
} dlyNext = DlyList;
ptcb->delayTick = ptcb->TCBnext->delayTick+deltaTicks; deltaTicks = ticks; /* Get task delay ticks */
ptcb->TCBnext->delayTick -= ptcb->delayTick;
break; /* Find correct place */
} while(dlyNext != Co_NULL)
/* Is last item in DELAY list? */ {
else if((deltaTicks >= 0) && (dlyNext->TCBnext == Co_NULL) ) /* Get delta ticks with previous item */
{ deltaTicks -= dlyNext->delayTick;
ptcb->TCBprev = dlyNext; /* Yes,insert into */ if(deltaTicks < 0) /* Is delta ticks<0? */
dlyNext->TCBnext = ptcb; {
ptcb->delayTick = deltaTicks; /* Yes,get correct place */
break; if(dlyNext->TCBprev != Co_NULL) /* Is head item of DELAY list? */
} {
dlyNext = dlyNext->TCBnext; /* Get the next item in DELAY list */ dlyNext->TCBprev->TCBnext = ptcb; /* No,insert into */
} ptcb->TCBprev = dlyNext->TCBprev;
} ptcb->TCBnext = dlyNext;
dlyNext->TCBprev = ptcb;
ptcb->state = TASK_WAITING; /* Set task status as TASK_WAITING */ }
TaskSchedReq = Co_TRUE; else /* Yes,set task as first item */
} {
ptcb->TCBnext = DlyList;
DlyList->TCBprev = ptcb;
/** DlyList = ptcb;
******************************************************************************* }
* @brief Remove from the DELAY list ptcb->delayTick = ptcb->TCBnext->delayTick+deltaTicks;
* @param[in] ptcb Task that want to remove from the DELAY list. ptcb->TCBnext->delayTick -= ptcb->delayTick;
* @param[out] None break;
* @retval None }
* /* Is last item in DELAY list? */
* @par Description else if((deltaTicks >= 0) && (dlyNext->TCBnext == Co_NULL) )
* @details This function is called to remove task from the DELAY list. {
******************************************************************************* ptcb->TCBprev = dlyNext; /* Yes,insert into */
*/ dlyNext->TCBnext = ptcb;
void RemoveDelayList(P_OSTCB ptcb) ptcb->delayTick = deltaTicks;
{ break;
}
/* Is there only one item in the DELAY list? */ dlyNext = dlyNext->TCBnext; /* Get the next item in DELAY list */
if((ptcb->TCBprev == Co_NULL) && ( ptcb->TCBnext == Co_NULL)) }
{ }
DlyList = Co_NULL; /* Yes,set DELAY list as Co_NULL */
} ptcb->state = TASK_WAITING; /* Set task status as TASK_WAITING */
else if(ptcb->TCBprev == Co_NULL) /* Is the first item in DELAY list? */ TaskSchedReq = Co_TRUE;
{ }
/* Yes,remove task from the DELAY list,and reset the list */
DlyList = ptcb->TCBnext;
ptcb->TCBnext->delayTick += ptcb->delayTick; /**
ptcb->TCBnext->TCBprev = Co_NULL; *******************************************************************************
ptcb->TCBnext = Co_NULL; * @brief Remove from the DELAY list
* @param[in] ptcb Task that want to remove from the DELAY list.
} * @param[out] None
else if(ptcb->TCBnext == Co_NULL) /* Is the last item in DELAY list? */ * @retval None
{ *
ptcb->TCBprev->TCBnext = Co_NULL; /* Yes,remove task form DELAY list */ * @par Description
ptcb->TCBprev = Co_NULL; * @details This function is called to remove task from the DELAY list.
} *******************************************************************************
else /* No, remove task from DELAY list */ */
{ void RemoveDelayList(P_OSTCB ptcb)
ptcb->TCBprev->TCBnext = ptcb->TCBnext; {
ptcb->TCBnext->TCBprev = ptcb->TCBprev;
ptcb->TCBnext->delayTick += ptcb->delayTick; /* Is there only one item in the DELAY list? */
ptcb->TCBnext = Co_NULL; if((ptcb->TCBprev == Co_NULL) && ( ptcb->TCBnext == Co_NULL))
ptcb->TCBprev = Co_NULL; {
} DlyList = Co_NULL; /* Yes,set DELAY list as Co_NULL */
ptcb->delayTick = INVALID_VALUE; /* Set task delay tick value as invalid */ }
} else if(ptcb->TCBprev == Co_NULL) /* Is the first item in DELAY list? */
{
/** /* Yes,remove task from the DELAY list,and reset the list */
******************************************************************************* DlyList = ptcb->TCBnext;
* @brief Get current ticks ptcb->TCBnext->delayTick += ptcb->delayTick;
* @param[in] None ptcb->TCBnext->TCBprev = Co_NULL;
* @param[out] None ptcb->TCBnext = Co_NULL;
* @retval Return current system tick counter.
* }
* @par Description else if(ptcb->TCBnext == Co_NULL) /* Is the last item in DELAY list? */
* @details This function is called to obtain current system tick counter. {
******************************************************************************* ptcb->TCBprev->TCBnext = Co_NULL; /* Yes,remove task form DELAY list */
*/ ptcb->TCBprev = Co_NULL;
U64 CoGetOSTime(void) }
{ else /* No, remove task from DELAY list */
return OSTickCnt; /* Get system time(tick) */ {
} ptcb->TCBprev->TCBnext = ptcb->TCBnext;
ptcb->TCBnext->TCBprev = ptcb->TCBprev;
ptcb->TCBnext->delayTick += ptcb->delayTick;
/** ptcb->TCBnext = Co_NULL;
******************************************************************************* ptcb->TCBprev = Co_NULL;
* @brief Delay current task for specify ticks number }
* @param[in] ticks Specify system tick number which will delay. ptcb->delayTick = INVALID_VALUE; /* Set task delay tick value as invalid */
* @param[out] None }
* @retval E_CALL Error call in ISR.
* @retval E_OK The current task was insert to DELAY list successful,it /**
* will delay specify time. *******************************************************************************
* @par Description * @brief Get current ticks
* @details This function delay specify ticks for current task. * @param[in] None
* * @param[out] None
* @note This function be called in ISR,do nothing and return immediately. * @retval Return current system tick counter.
******************************************************************************* *
*/ * @par Description
StatusType CoTickDelay(U32 ticks) * @details This function is called to obtain current system tick counter.
{ *******************************************************************************
if(OSIntNesting >0) /* Is call in ISR? */ */
{ U64 CoGetOSTime(void)
return E_CALL; /* Yes,error return */ {
} return OSTickCnt; /* Get system time(tick) */
}
if(ticks == INVALID_VALUE) /* Is tick==INVALID_VALUE? */
{
return E_INVALID_PARAMETER; /* Yes,error return */ /**
} *******************************************************************************
if(ticks == 0) /* Is tick==0? */ * @brief Delay current task for specify ticks number
{ * @param[in] ticks Specify system tick number which will delay.
return E_OK; /* Yes,do nothing ,return OK */ * @param[out] None
} * @retval E_CALL Error call in ISR.
if(OSSchedLock != 0) /* Is OS lock? */ * @retval E_OK The current task was insert to DELAY list successful,it
{ * will delay specify time.
return E_OS_IN_LOCK; /* Yes,error return */ * @par Description
} * @details This function delay specify ticks for current task.
OsSchedLock(); /* Lock schedule */ *
InsertDelayList(TCBRunning,ticks); /* Insert task in DELAY list */ * @note This function be called in ISR,do nothing and return immediately.
OsSchedUnlock(); /* Unlock schedule,and call task schedule */ *******************************************************************************
return E_OK; /* Return OK */ */
} StatusType CoTickDelay(U32 ticks)
{
if(OSIntNesting >0) /* Is call in ISR? */
/** {
******************************************************************************* return E_CALL; /* Yes,error return */
* @brief Reset task delay ticks }
* @param[in] ptcb Task that want to insert into DELAY list.
* @param[in] ticks Specify system tick number which will delay . if(ticks == INVALID_VALUE) /* Is tick==INVALID_VALUE? */
* @param[out] None {
* @retval E_CALL Error call in ISR. return E_INVALID_PARAMETER; /* Yes,error return */
* @retval E_INVALID_ID Invalid task id. }
* @retval E_NOT_IN_DELAY_LIST Task not in delay list. if(ticks == 0) /* Is tick==0? */
* @retval E_OK The current task was inserted to DELAY list {
* successful,it will delay for specify time. return E_OK; /* Yes,do nothing ,return OK */
* @par Description }
* @details This function delay specify ticks for current task. if(OSSchedLock != 0) /* Is OS lock? */
******************************************************************************* {
*/ return E_OS_IN_LOCK; /* Yes,error return */
StatusType CoResetTaskDelayTick(OS_TID taskID,U32 ticks) }
{ OsSchedLock(); /* Lock schedule */
P_OSTCB ptcb; InsertDelayList(TCBRunning,ticks); /* Insert task in DELAY list */
OsSchedUnlock(); /* Unlock schedule,and call task schedule */
return E_OK; /* Return OK */
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ }
if(taskID >= CFG_MAX_USER_TASKS + SYS_TASK_NUM)
{
return E_INVALID_ID; /**
} *******************************************************************************
#endif * @brief Reset task delay ticks
* @param[in] ptcb Task that want to insert into DELAY list.
ptcb = &TCBTbl[taskID]; * @param[in] ticks Specify system tick number which will delay .
#if CFG_PAR_CHECKOUT_EN >0 * @param[out] None
if(ptcb->stkPtr == Co_NULL) * @retval E_CALL Error call in ISR.
{ * @retval E_INVALID_ID Invalid task id.
return E_INVALID_ID; * @retval E_NOT_IN_DELAY_LIST Task not in delay list.
} * @retval E_OK The current task was inserted to DELAY list
#endif * successful,it will delay for specify time.
* @par Description
if(ptcb->delayTick == INVALID_VALUE) /* Is tick==INVALID_VALUE? */ * @details This function delay specify ticks for current task.
{ *******************************************************************************
return E_NOT_IN_DELAY_LIST; /* Yes,error return */ */
} StatusType CoResetTaskDelayTick(OS_TID taskID,U32 ticks)
OsSchedLock(); /* Lock schedule */ {
RemoveDelayList(ptcb); /* Remove task from the DELAY list */ P_OSTCB ptcb;
if(ticks == 0) /* Is delay tick==0? */
{ #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
InsertToTCBRdyList(ptcb); /* Insert task into the DELAY list */ if(taskID >= CFG_MAX_USER_TASKS + SYS_TASK_NUM)
} {
else return E_INVALID_ID;
{ }
InsertDelayList(ptcb,ticks); /* No,insert task into DELAY list */ #endif
}
OsSchedUnlock(); /* Unlock schedule,and call task schedule */ ptcb = &TCBTbl[taskID];
return E_OK; /* Return OK */ #if CFG_PAR_CHECKOUT_EN >0
} if(ptcb->stkPtr == Co_NULL)
{
return E_INVALID_ID;
/** }
******************************************************************************* #endif
* @brief Delay current task for detail time
* @param[in] hour Specify the number of hours. if(ptcb->delayTick == INVALID_VALUE) /* Is tick==INVALID_VALUE? */
* @param[in] minute Specify the number of minutes. {
* @param[in] sec Specify the number of seconds. return E_NOT_IN_DELAY_LIST; /* Yes,error return */
* @param[in] millsec Specify the number of millseconds. }
* @param[out] None OsSchedLock(); /* Lock schedule */
* @retval E_CALL Error call in ISR. RemoveDelayList(ptcb); /* Remove task from the DELAY list */
* @retval E_INVALID_PARAMETER Parameter passed was invalid,delay fail.
* @retval E_OK The current task was inserted to DELAY list if(ticks == 0) /* Is delay tick==0? */
* successful,it will delay for specify time. {
* @par Description InsertToTCBRdyList(ptcb); /* Insert task into the DELAY list */
* @details This function delay specify time for current task. }
* else
* @note If this function called in ISR,do nothing and return immediately. {
******************************************************************************* InsertDelayList(ptcb,ticks); /* No,insert task into DELAY list */
*/ }
#if CFG_TIME_DELAY_EN >0 OsSchedUnlock(); /* Unlock schedule,and call task schedule */
StatusType CoTimeDelay(U8 hour,U8 minute,U8 sec,U16 millsec) return E_OK; /* Return OK */
{ }
U32 ticks;
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
if(OSIntNesting > 0) /**
{ *******************************************************************************
return E_CALL; * @brief Delay current task for detail time
} * @param[in] hour Specify the number of hours.
if((minute > 59)||(sec > 59)||(millsec > 999)) * @param[in] minute Specify the number of minutes.
return E_INVALID_PARAMETER; * @param[in] sec Specify the number of seconds.
#endif * @param[in] millsec Specify the number of millseconds.
if(OSSchedLock != 0) /* Is OS lock? */ * @param[out] None
{ * @retval E_CALL Error call in ISR.
return E_OS_IN_LOCK; /* Yes,error return */ * @retval E_INVALID_PARAMETER Parameter passed was invalid,delay fail.
} * @retval E_OK The current task was inserted to DELAY list
* successful,it will delay for specify time.
/* Get tick counter from time */ * @par Description
ticks = ((hour*3600) + (minute*60) + (sec)) * (CFG_SYSTICK_FREQ)\ * @details This function delay specify time for current task.
+ (millsec*CFG_SYSTICK_FREQ + 500)/1000; *
* @note If this function called in ISR,do nothing and return immediately.
CoTickDelay(ticks); /* Call tick delay */ *******************************************************************************
return E_OK; /* Return OK */ */
} #if CFG_TIME_DELAY_EN >0
#endif StatusType CoTimeDelay(U8 hour,U8 minute,U8 sec,U16 millsec)
{
U32 ticks;
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
if(OSIntNesting > 0)
/** {
******************************************************************************* return E_CALL;
* @brief Dispose time delay }
* @param[in] None if((minute > 59)||(sec > 59)||(millsec > 999))
* @param[out] None return E_INVALID_PARAMETER;
* @retval None #endif
* if(OSSchedLock != 0) /* Is OS lock? */
* @par Description {
* @details This function is called to dispose time delay of all task. return E_OS_IN_LOCK; /* Yes,error return */
******************************************************************************* }
*/
void TimeDispose(void) /* Get tick counter from time */
{ ticks = ((hour*3600) + (minute*60) + (sec)) * (CFG_SYSTICK_FREQ)\
P_OSTCB dlyList; + (millsec*CFG_SYSTICK_FREQ + 500)/1000;
dlyList = DlyList; /* Get first item of DELAY list */ CoTickDelay(ticks); /* Call tick delay */
while((dlyList != Co_NULL) && (dlyList->delayTick == 0) ) return E_OK; /* Return OK */
{ }
#endif
#if CFG_EVENT_EN > 0
if(dlyList->eventID != INVALID_ID) /* Is task in event waiting list? */
{
RemoveEventWaittingList(dlyList); /* Yes,remove task from list */
} /**
#endif *******************************************************************************
* @brief Dispose time delay
#if CFG_FLAG_EN > 0 * @param[in] None
if(dlyList->pnode != Co_NULL) /* Is task in flag waiting list? */ * @param[out] None
{ * @retval None
RemoveLinkNode(dlyList->pnode); /* Yes,remove task from list */ *
} * @par Description
#endif * @details This function is called to dispose time delay of all task.
dlyList->delayTick = INVALID_VALUE; /* Set delay tick value as invalid*/ *******************************************************************************
DlyList = dlyList->TCBnext; /* Get next item as the head of DELAY list*/ */
dlyList->TCBnext = Co_NULL; void TimeDispose(void)
{
InsertToTCBRdyList(dlyList); /* Insert task into READY list */ P_OSTCB dlyList;
dlyList = DlyList; /* Get the first item of DELAY list */ dlyList = DlyList; /* Get first item of DELAY list */
if(dlyList != Co_NULL) /* Is DELAY list as Co_NULL? */ while((dlyList != Co_NULL) && (dlyList->delayTick == 0) )
{ {
dlyList->TCBprev = Co_NULL; /* No,initialize the first item */
} #if CFG_EVENT_EN > 0
} if(dlyList->eventID != INVALID_ID) /* Is task in event waiting list? */
} {
RemoveEventWaittingList(dlyList); /* Yes,remove task from list */
}
/** #endif
*******************************************************************************
* @brief Dispose time delay in ISR #if CFG_FLAG_EN > 0
* @param[in] None if(dlyList->pnode != Co_NULL) /* Is task in flag waiting list? */
* @param[out] None {
* @retval None RemoveLinkNode(dlyList->pnode); /* Yes,remove task from list */
* }
* @par Description #endif
* @details This function is called in systick interrupt to dispose time delay dlyList->delayTick = INVALID_VALUE; /* Set delay tick value as invalid*/
* of all task. DlyList = dlyList->TCBnext; /* Get next item as the head of DELAY list*/
******************************************************************************* dlyList->TCBnext = Co_NULL;
*/
void isr_TimeDispose(void) InsertToTCBRdyList(dlyList); /* Insert task into READY list */
{
if(OSSchedLock > 1) /* Is schedule lock? */ dlyList = DlyList; /* Get the first item of DELAY list */
{ if(dlyList != Co_NULL) /* Is DELAY list as Co_NULL? */
IsrReq = Co_TRUE; {
TimeReq = Co_TRUE; /* Yes,set time request Co_TRUE */ dlyList->TCBprev = Co_NULL; /* No,initialize the first item */
} }
else }
{ }
TimeDispose(); /* No,call handler */
}
} /**
*******************************************************************************
* @brief Dispose time delay in ISR
#endif * @param[in] None
* @param[out] None
* @retval None
*
* @par Description
* @details This function is called in systick interrupt to dispose time delay
* of all task.
*******************************************************************************
*/
void isr_TimeDispose(void)
{
if(OSSchedLock > 1) /* Is schedule lock? */
{
IsrReq = Co_TRUE;
TimeReq = Co_TRUE; /* Yes,set time request Co_TRUE */
}
else
{
TimeDispose(); /* No,call handler */
}
}
#endif
+470 -447
View File
@@ -1,447 +1,470 @@
/** /**
******************************************************************************* *******************************************************************************
* @file timer.c * @file timer.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief timer management implementation code of CooCox CoOS kernel. * @brief timer management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
/*---------------------------- Include ---------------------------------------*/ * documentation and/or other materials provided with the distribution.
#include <coocox.h> * * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
/*---------------------------- Variable Define -------------------------------*/ * from this software without specific prior written permission.
#if CFG_TMR_EN > 0 *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
TmrCtrl TmrTbl[CFG_MAX_TMR]= {{0}};/*!< Table which save timer control block.*/ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
P_TmrCtrl TmrList = Co_NULL; /*!< The header of the TmrCtrl list. */ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
U32 TmrIDVessel = 0; /*!< Timer ID container. */ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 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
* @brief Insert a timer into the timer list * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* @param[in] tmrID Specify timer ID which insertted. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* @param[out] None * THE POSSIBILITY OF SUCH DAMAGE.
* @retval E_INVALID_ID Timer ID passed was invalid,insert fail. *
* @retval E_OK Insert successful. * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
* *******************************************************************************
* @par Description */
* @details This function is called to insert a timer into the timer list.
*******************************************************************************
*/
static void InsertTmrList(OS_TCID tmrID) /*---------------------------- Include ---------------------------------------*/
{ #include <coocox.h>
P_TmrCtrl pTmr;
S32 deltaTicks; /*---------------------------- Variable Define -------------------------------*/
U32 tmrCnt; #if CFG_TMR_EN > 0
tmrCnt = TmrTbl[tmrID].tmrCnt; /* Get timer time */
TmrCtrl TmrTbl[CFG_MAX_TMR]= {{0}};/*!< Table which save timer control block.*/
if(tmrCnt == 0) /* Is timer time==0? */ P_TmrCtrl TmrList = Co_NULL; /*!< The header of the TmrCtrl list. */
{ U32 TmrIDVessel = 0; /*!< Timer ID container. */
return; /* Do nothing,return */
}
/**
OsSchedLock(); /* Lock schedule */ *******************************************************************************
if(TmrList == Co_NULL) /* Is no item in timer list? */ * @brief Insert a timer into the timer list
{ * @param[in] tmrID Specify timer ID which insertted.
TmrList = &TmrTbl[tmrID]; /* Yes,set this as first item */ * @param[out] None
} * @retval E_INVALID_ID Timer ID passed was invalid,insert fail.
else /* No,find correct place ,and insert inserted timer */ * @retval E_OK Insert successful.
{ *
pTmr = TmrList; * @par Description
deltaTicks = tmrCnt; /* Get timer tick */ * @details This function is called to insert a timer into the timer list.
*******************************************************************************
/* find correct place */ */
while(pTmr != Co_NULL) static void InsertTmrList(OS_TCID tmrID)
{ {
deltaTicks -= pTmr->tmrCnt; /* Get ticks with previous item */ P_TmrCtrl pTmr;
if(deltaTicks < 0) /* Is delta ticks<0? */ S32 deltaTicks;
{ U32 tmrCnt;
/* Yes,get correct place */ tmrCnt = TmrTbl[tmrID].tmrCnt; /* Get timer time */
if(pTmr->tmrPrev!= Co_NULL)/* Is head item of timer list? */
{ if(tmrCnt == 0) /* Is timer time==0? */
/* No,insert into */ {
pTmr->tmrPrev->tmrNext = &TmrTbl[tmrID]; return; /* Do nothing,return */
TmrTbl[tmrID].tmrPrev = pTmr->tmrPrev; }
TmrTbl[tmrID].tmrNext = pTmr;
pTmr->tmrPrev = &TmrTbl[tmrID]; OsSchedLock(); /* Lock schedule */
} if(TmrList == Co_NULL) /* Is no item in timer list? */
else /* Yes,set task as first item */ {
{ TmrList = &TmrTbl[tmrID]; /* Yes,set this as first item */
TmrTbl[tmrID].tmrNext = TmrList; }
TmrList->tmrPrev = &TmrTbl[tmrID]; else /* No,find correct place ,and insert inserted timer */
TmrList = &TmrTbl[tmrID]; {
} pTmr = TmrList;
TmrTbl[tmrID].tmrCnt = TmrTbl[tmrID].tmrNext->tmrCnt+deltaTicks; deltaTicks = tmrCnt; /* Get timer tick */
TmrTbl[tmrID].tmrNext->tmrCnt -= TmrTbl[tmrID].tmrCnt;
break; /* find correct place */
} while(pTmr != Co_NULL)
/* Is last item in list? */ {
else if((deltaTicks >= 0) && (pTmr->tmrNext == Co_NULL)) deltaTicks -= pTmr->tmrCnt; /* Get ticks with previous item */
{ if(deltaTicks < 0) /* Is delta ticks<0? */
/* Yes,insert into */ {
TmrTbl[tmrID].tmrPrev = pTmr; /* Yes,get correct place */
pTmr->tmrNext = &TmrTbl[tmrID]; if(pTmr->tmrPrev!= Co_NULL)/* Is head item of timer list? */
TmrTbl[tmrID].tmrCnt = deltaTicks; {
break; /* No,insert into */
} pTmr->tmrPrev->tmrNext = &TmrTbl[tmrID];
pTmr = pTmr->tmrNext; /* Get the next item in timer list */ TmrTbl[tmrID].tmrPrev = pTmr->tmrPrev;
} TmrTbl[tmrID].tmrNext = pTmr;
} pTmr->tmrPrev = &TmrTbl[tmrID];
OsSchedUnlock(); /* Unlock schedule */ }
} else /* Yes,set task as first item */
{
TmrTbl[tmrID].tmrNext = TmrList;
/** TmrList->tmrPrev = &TmrTbl[tmrID];
******************************************************************************* TmrList = &TmrTbl[tmrID];
* @brief Remove a timer from the timer list }
* @param[in] tmrID Specify ID for a timer which removed form timer list. TmrTbl[tmrID].tmrCnt = TmrTbl[tmrID].tmrNext->tmrCnt+deltaTicks;
* @param[out] None TmrTbl[tmrID].tmrNext->tmrCnt -= TmrTbl[tmrID].tmrCnt;
* @retval None break;
* }
* @par Description /* Is last item in list? */
* @details This function is called to remove a timer from the timer list. else if((deltaTicks >= 0) && (pTmr->tmrNext == Co_NULL))
******************************************************************************* {
*/ /* Yes,insert into */
static void RemoveTmrList(OS_TCID tmrID) TmrTbl[tmrID].tmrPrev = pTmr;
{ pTmr->tmrNext = &TmrTbl[tmrID];
P_TmrCtrl pTmr; TmrTbl[tmrID].tmrCnt = deltaTicks;
break;
pTmr = &TmrTbl[tmrID]; }
pTmr = pTmr->tmrNext; /* Get the next item in timer list */
OsSchedLock(); /* Lock schedule */ }
}
/* Is there only one item in timer list? */ OsSchedUnlock(); /* Unlock schedule */
if((pTmr->tmrPrev == Co_NULL) && (pTmr->tmrNext == Co_NULL)) }
{
TmrList = Co_NULL; /* Yes,set timer list as Co_NULL */
} /**
else if(pTmr->tmrPrev == Co_NULL) /* Is the first item in timer list? */ *******************************************************************************
{ /* Yes,remove timer from list,and reset timer list */ * @brief Remove a timer from the timer list
TmrList = pTmr->tmrNext; * @param[in] tmrID Specify ID for a timer which removed form timer list.
TmrList->tmrPrev = Co_NULL; * @param[out] None
pTmr->tmrNext->tmrCnt += pTmr->tmrCnt; * @retval None
pTmr->tmrNext = Co_NULL; *
} * @par Description
else if(pTmr->tmrNext == Co_NULL) /* Is the last item in timer list? */ * @details This function is called to remove a timer from the timer list.
{ *******************************************************************************
/* Yes,remove timer form list */ */
pTmr->tmrPrev->tmrNext = Co_NULL; static void RemoveTmrList(OS_TCID tmrID)
pTmr->tmrPrev = Co_NULL; {
} P_TmrCtrl pTmr;
else /* No, remove timer from list */
{ pTmr = &TmrTbl[tmrID];
pTmr->tmrPrev->tmrNext = pTmr->tmrNext;
pTmr->tmrNext->tmrPrev = pTmr->tmrPrev; OsSchedLock(); /* Lock schedule */
pTmr->tmrNext->tmrCnt += pTmr->tmrCnt;
pTmr->tmrNext = Co_NULL; /* Is there only one item in timer list? */
pTmr->tmrPrev = Co_NULL; if((pTmr->tmrPrev == Co_NULL) && (pTmr->tmrNext == Co_NULL))
} {
OsSchedUnlock(); /* Unlock schedule */ TmrList = Co_NULL; /* Yes,set timer list as Co_NULL */
} }
else if(pTmr->tmrPrev == Co_NULL) /* Is the first item in timer list? */
{ /* Yes,remove timer from list,and reset timer list */
/** TmrList = pTmr->tmrNext;
******************************************************************************* TmrList->tmrPrev = Co_NULL;
* @brief Create a timer pTmr->tmrNext->tmrCnt += pTmr->tmrCnt;
* @param[in] tmrType Specify timer's type. pTmr->tmrNext = Co_NULL;
* @param[in] tmrCnt Specify timer initial counter value. }
* @param[in] tmrReload Specify timer reload value. else if(pTmr->tmrNext == Co_NULL) /* Is the last item in timer list? */
* @param[in] func Specify timer callback function entry. {
* @param[out] None /* Yes,remove timer form list */
* @retval E_CREATE_FAIL Create timer fail. pTmr->tmrPrev->tmrNext = Co_NULL;
* @retval others Create timer successful. pTmr->tmrPrev = Co_NULL;
* }
* @par Description else /* No, remove timer from list */
* @details This function is called to create a timer. {
******************************************************************************* pTmr->tmrPrev->tmrNext = pTmr->tmrNext;
*/ pTmr->tmrNext->tmrPrev = pTmr->tmrPrev;
OS_TCID CoCreateTmr(U8 tmrType, U32 tmrCnt, U32 tmrReload, vFUNCPtr func) pTmr->tmrNext->tmrCnt += pTmr->tmrCnt;
{ pTmr->tmrNext = Co_NULL;
U8 i; pTmr->tmrPrev = Co_NULL;
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ }
if((tmrType != TMR_TYPE_ONE_SHOT) && (tmrType != TMR_TYPE_PERIODIC)) OsSchedUnlock(); /* Unlock schedule */
{ }
return E_CREATE_FAIL;
}
if(func == Co_NULL) /**
{ *******************************************************************************
return E_CREATE_FAIL; * @brief Create a timer
} * @param[in] tmrType Specify timer's type.
#endif * @param[in] tmrCnt Specify timer initial counter value.
OsSchedLock(); /* Lock schedule */ * @param[in] tmrReload Specify timer reload value.
for(i = 0; i < CFG_MAX_TMR; i++) * @param[in] func Specify timer callback function entry.
{ * @param[out] None
if((TmrIDVessel & (1 << i)) == 0) /* Is free timer ID? */ * @retval E_CREATE_FAIL Create timer fail.
{ * @retval others Create timer successful.
TmrIDVessel |= (1<<i); /* Yes,assign ID to this timer */ *
OsSchedUnlock(); /* Unlock schedule */ * @par Description
TmrTbl[i].tmrID = i; /* Initialize timer as user set */ * @details This function is called to create a timer.
TmrTbl[i].tmrType = tmrType; *******************************************************************************
TmrTbl[i].tmrState = TMR_STATE_STOPPED; */
TmrTbl[i].tmrCnt = tmrCnt; OS_TCID CoCreateTmr(U8 tmrType, U32 tmrCnt, U32 tmrReload, vFUNCPtr func)
TmrTbl[i].tmrReload = tmrReload; {
TmrTbl[i].tmrCallBack = func; U8 i;
TmrTbl[i].tmrPrev = Co_NULL; #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
TmrTbl[i].tmrNext = Co_NULL; if((tmrType != TMR_TYPE_ONE_SHOT) && (tmrType != TMR_TYPE_PERIODIC))
return i; /* Return timer ID */ {
} return E_CREATE_FAIL;
} }
OsSchedUnlock(); /* Unlock schedule */ if(func == Co_NULL)
return E_CREATE_FAIL; /* Error return */ {
} return E_CREATE_FAIL;
}
#endif
/** OsSchedLock(); /* Lock schedule */
******************************************************************************* for(i = 0; i < CFG_MAX_TMR; i++)
* @brief Start counter {
* @param[in] tmrID Specify a timer which startted. if((TmrIDVessel & (1 << i)) == 0) /* Is free timer ID? */
* @param[out] None {
* @retval E_INVALID_ID The timer id passed was invalid,can't start timer TmrIDVessel |= (1<<i); /* Yes,assign ID to this timer */
* @retval E_OK Insert a timer to timer list and start it successful. OsSchedUnlock(); /* Unlock schedule */
* TmrTbl[i].tmrID = i; /* Initialize timer as user set */
* @par Description TmrTbl[i].tmrType = tmrType;
* @details This function is called to make a timer start countering. TmrTbl[i].tmrState = TMR_STATE_STOPPED;
******************************************************************************* TmrTbl[i].tmrCnt = tmrCnt;
*/ TmrTbl[i].tmrReload = tmrReload;
StatusType CoStartTmr(OS_TCID tmrID) TmrTbl[i].tmrCallBack = func;
{ TmrTbl[i].tmrPrev = Co_NULL;
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ TmrTbl[i].tmrNext = Co_NULL;
if(tmrID >= CFG_MAX_TMR) return i; /* Return timer ID */
{ }
return E_INVALID_ID; }
} OsSchedUnlock(); /* Unlock schedule */
if( (TmrIDVessel & (1<<tmrID)) == 0) return E_CREATE_FAIL; /* Error return */
{ }
return E_INVALID_ID;
}
#endif /**
*******************************************************************************
if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING) /* Is timer running? */ * @brief Start counter
{ * @param[in] tmrID Specify a timer which startted.
return E_OK; /* Yes,do nothing,return OK */ * @param[out] None
} * @retval E_INVALID_ID The timer id passed was invalid,can't start timer
* @retval E_OK Insert a timer to timer list and start it successful.
/* No,set timer status as TMR_STATE_RUNNING */ *
TmrTbl[tmrID].tmrState = TMR_STATE_RUNNING; * @par Description
InsertTmrList(tmrID); /* Insert this timer into timer list */ * @details This function is called to make a timer start countering.
return E_OK; /* Return OK */ *******************************************************************************
} */
StatusType CoStartTmr(OS_TCID tmrID)
{
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
/** if(tmrID >= CFG_MAX_TMR)
******************************************************************************* {
* @brief Stop countering for a spcify timer return E_INVALID_ID;
* @param[in] tmrID Specify a timer which stopped. }
* @param[out] None if( (TmrIDVessel & (1<<tmrID)) == 0)
* @retval E_INVALID_ID The timer id passed was invalid, stop failure. {
* @retval E_OK Stop a timer countering successful. return E_INVALID_ID;
* }
* @par Description #endif
* @details This function is called to stop a timer from counting.
******************************************************************************* if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING) /* Is timer running? */
*/ {
StatusType CoStopTmr(OS_TCID tmrID) return E_OK; /* Yes,do nothing,return OK */
{ }
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
if(tmrID >= CFG_MAX_TMR) /* No,set timer status as TMR_STATE_RUNNING */
{ TmrTbl[tmrID].tmrState = TMR_STATE_RUNNING;
return E_INVALID_ID; InsertTmrList(tmrID); /* Insert this timer into timer list */
} return E_OK; /* Return OK */
if((TmrIDVessel & (1<<tmrID)) == 0) }
{
return E_INVALID_ID;
}
#endif /**
*******************************************************************************
* @brief Stop countering for a spcify timer
if(TmrTbl[tmrID].tmrState == TMR_STATE_STOPPED)/* Does timer stop running?*/ * @param[in] tmrID Specify a timer which stopped.
{ * @param[out] None
return E_OK; /* Yes,do nothing,return OK */ * @retval E_INVALID_ID The timer id passed was invalid, stop failure.
} * @retval E_OK Stop a timer countering successful.
RemoveTmrList(tmrID); /* No,remove this timer from timer list */ *
* @par Description
/* Set timer status as TMR_STATE_STOPPED */ * @details This function is called to stop a timer from counting.
TmrTbl[tmrID].tmrState = TMR_STATE_STOPPED; *******************************************************************************
return E_OK; /* Return OK */ */
} StatusType CoStopTmr(OS_TCID tmrID)
{
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
/** if(tmrID >= CFG_MAX_TMR)
******************************************************************************* {
* @brief Delete a timer return E_INVALID_ID;
* @param[in] tmrID Specify a timer which deleted. }
* @param[out] None if((TmrIDVessel & (1<<tmrID)) == 0)
* @retval E_INVALID_ID The timer id passed was invalid,deleted failure. {
* @retval E_OK Delete a timer successful. return E_INVALID_ID;
* }
* @par Description #endif
* @details This function is called to delete a timer which created before.
*******************************************************************************
*/ if(TmrTbl[tmrID].tmrState == TMR_STATE_STOPPED)/* Does timer stop running?*/
StatusType CoDelTmr(OS_TCID tmrID) {
{ return E_OK; /* Yes,do nothing,return OK */
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ }
if(tmrID >= CFG_MAX_TMR) RemoveTmrList(tmrID); /* No,remove this timer from timer list */
{
return E_INVALID_ID; /* Set timer status as TMR_STATE_STOPPED */
} TmrTbl[tmrID].tmrState = TMR_STATE_STOPPED;
if( (TmrIDVessel & (1<<tmrID)) == 0) return E_OK; /* Return OK */
{ }
return E_INVALID_ID;
}
#endif /**
*******************************************************************************
if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING) /* Is timer running? */ * @brief Delete a timer
{ * @param[in] tmrID Specify a timer which deleted.
RemoveTmrList(tmrID); /* Yes,remove this timer from timer list*/ * @param[out] None
} * @retval E_INVALID_ID The timer id passed was invalid,deleted failure.
TmrIDVessel &=~(1<<tmrID); /* Release resource that this timer hold*/ * @retval E_OK Delete a timer successful.
return E_OK; /* Return OK */ *
} * @par Description
* @details This function is called to delete a timer which created before.
*******************************************************************************
/** */
******************************************************************************* StatusType CoDelTmr(OS_TCID tmrID)
* @brief Get current counter of specify timer {
* @param[in] tmrID Specify timer by ID. #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
* @param[out] E_INVALID_ID Invalid ID was passed and get counter failure. if(tmrID >= CFG_MAX_TMR)
* @param[out] E_OK Get current counter successful. {
* @retval Current counter of a timer which specify by id. return E_INVALID_ID;
* }
* @par Description if( (TmrIDVessel & (1<<tmrID)) == 0)
* @details This function is called to obtain current counter of specify timer. {
******************************************************************************* return E_INVALID_ID;
*/ }
U32 CoGetCurTmrCnt(OS_TCID tmrID,StatusType* perr) #endif
{
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING) /* Is timer running? */
if(tmrID >= CFG_MAX_TMR) {
{ RemoveTmrList(tmrID); /* Yes,remove this timer from timer list*/
*perr = E_INVALID_ID; }
return 0; TmrIDVessel &=~(1<<tmrID); /* Release resource that this timer hold*/
} return E_OK; /* Return OK */
if((TmrIDVessel & (1<<tmrID)) == 0) }
{
*perr = E_INVALID_ID;
return 0; /**
} *******************************************************************************
#endif * @brief Get current counter of specify timer
*perr = E_OK; * @param[in] tmrID Specify timer by ID.
return TmrTbl[tmrID].tmrCnt; /* Return timer counter */ * @param[out] E_INVALID_ID Invalid ID was passed and get counter failure.
} * @param[out] E_OK Get current counter successful.
* @retval Current counter of a timer which specify by id.
*
/** * @par Description
******************************************************************************* * @details This function is called to obtain current counter of specify timer.
* @brief Setting for a specify timer *******************************************************************************
* @param[in] tmrID Specify timer by ID. */
* @param[in] tmrCnt Specify timer counter which need to be set. U32 CoGetCurTmrCnt(OS_TCID tmrID,StatusType* perr)
* @param[in] tmrReload Specify timer reload value which need to be set. {
* @param[out] None #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
* @retval E_INVALID_ID The ID passed was invalid,set fail. if(tmrID >= CFG_MAX_TMR)
* @retval E_OK Set timer counter successful. {
* *perr = E_INVALID_ID;
* @par Description return 0;
* @details This function is called to set timer counter and reload value. }
******************************************************************************* if((TmrIDVessel & (1<<tmrID)) == 0)
*/ {
StatusType CoSetTmrCnt(OS_TCID tmrID,U32 tmrCnt,U32 tmrReload) *perr = E_INVALID_ID;
{ return 0;
#if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ }
if(tmrID >= CFG_MAX_TMR) #endif
{ *perr = E_OK;
return E_INVALID_ID; return TmrTbl[tmrID].tmrCnt; /* Return timer counter */
} }
if( (TmrIDVessel & (1<<tmrID)) == 0)
{
return E_INVALID_ID; /**
} *******************************************************************************
#endif * @brief Setting for a specify timer
TmrTbl[tmrID].tmrCnt = tmrCnt; /* Reset timer counter and reload value */ * @param[in] tmrID Specify timer by ID.
TmrTbl[tmrID].tmrReload = tmrReload; * @param[in] tmrCnt Specify timer counter which need to be set.
* @param[in] tmrReload Specify timer reload value which need to be set.
if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING) /* Is timer running? */ * @param[out] None
{ * @retval E_INVALID_ID The ID passed was invalid,set fail.
RemoveTmrList(tmrID); /* Yes,reorder timer in timer list */ * @retval E_OK Set timer counter successful.
InsertTmrList(tmrID); *
} * @par Description
return E_OK; /* Return OK */ * @details This function is called to set timer counter and reload value.
} *******************************************************************************
*/
StatusType CoSetTmrCnt(OS_TCID tmrID,U32 tmrCnt,U32 tmrReload)
/** {
******************************************************************************* #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
* @brief Timer counter dispose if(tmrID >= CFG_MAX_TMR)
* @param[in] None {
* @param[out] None return E_INVALID_ID;
* @retval None }
* if( (TmrIDVessel & (1<<tmrID)) == 0)
* @par Description {
* @details This function is called to dispose timer counter. return E_INVALID_ID;
******************************************************************************* }
*/ #endif
void TmrDispose(void) TmrTbl[tmrID].tmrCnt = tmrCnt; /* Reset timer counter and reload value */
{ TmrTbl[tmrID].tmrReload = tmrReload;
P_TmrCtrl pTmr;
if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING) /* Is timer running? */
pTmr = TmrList; /* Get first item of timer list */ {
while((pTmr != Co_NULL) && (pTmr->tmrCnt == 0) ) RemoveTmrList(tmrID); /* Yes,reorder timer in timer list */
{ InsertTmrList(tmrID);
if(pTmr->tmrType == TMR_TYPE_ONE_SHOT) /* Is a One-shot timer? */ }
{ return E_OK; /* Return OK */
/* Yes,remove this timer from timer list */ }
RemoveTmrList(pTmr->tmrID);
/* Set timer status as TMR_STATE_STOPPED */ /**
pTmr->tmrState = TMR_STATE_STOPPED; *******************************************************************************
(pTmr->tmrCallBack)(); /* Call timer callback function */ * @brief Timer counter dispose
} * @param[in] None
else if(pTmr->tmrType == TMR_TYPE_PERIODIC) /* Is a periodic timer? */ * @param[out] None
{ * @retval None
/* Yes,remove this timer from timer list */ *
RemoveTmrList(pTmr->tmrID); * @par Description
pTmr->tmrCnt = pTmr->tmrReload; /* Reset timer tick */ * @details This function is called to dispose timer counter.
InsertTmrList(pTmr->tmrID); /* Insert timer into timer list */ *******************************************************************************
(pTmr->tmrCallBack)(); /* Call timer callback function */ */
} void TmrDispose(void)
pTmr = TmrList; /* Get first item of timer list */ {
} P_TmrCtrl pTmr;
}
pTmr = TmrList; /* Get first item of timer list */
while((pTmr != Co_NULL) && (pTmr->tmrCnt == 0) )
/** {
******************************************************************************* if(pTmr->tmrType == TMR_TYPE_ONE_SHOT) /* Is a One-shot timer? */
* @brief Timer counter dispose in ISR {
* @param[in] None /* Yes,remove this timer from timer list */
* @param[out] None RemoveTmrList(pTmr->tmrID);
* @retval None
* /* Set timer status as TMR_STATE_STOPPED */
* @par Description pTmr->tmrState = TMR_STATE_STOPPED;
* @details This function is called to dispose timer counter. (pTmr->tmrCallBack)(); /* Call timer callback function */
******************************************************************************* }
*/ else if(pTmr->tmrType == TMR_TYPE_PERIODIC) /* Is a periodic timer? */
void isr_TmrDispose(void) {
{ /* Yes,remove this timer from timer list */
if(OSSchedLock > 1) /* Is schedule lock? */ RemoveTmrList(pTmr->tmrID);
{ pTmr->tmrCnt = pTmr->tmrReload; /* Reset timer tick */
IsrReq = Co_TRUE; InsertTmrList(pTmr->tmrID); /* Insert timer into timer list */
TimerReq = Co_TRUE; /* Yes,set timer request true */ (pTmr->tmrCallBack)(); /* Call timer callback function */
} }
else pTmr = TmrList; /* Get first item of timer list */
{ }
TmrDispose(); /* No,call handler */ }
}
}
/**
#endif *******************************************************************************
* @brief Timer counter dispose in ISR
* @param[in] None
* @param[out] None
* @retval None
*
* @par Description
* @details This function is called to dispose timer counter.
*******************************************************************************
*/
void isr_TmrDispose(void)
{
if(OSSchedLock > 1) /* Is schedule lock? */
{
IsrReq = Co_TRUE;
TimerReq = Co_TRUE; /* Yes,set timer request true */
}
else
{
TmrDispose(); /* No,call handler */
}
}
#endif
+109 -86
View File
@@ -1,86 +1,109 @@
/** /**
******************************************************************************* *******************************************************************************
* @file utility.c * @file utility.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Utility management implementation code of CooCox CoOS kernel. * @brief Utility management implementation code of CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
/*---------------------------- Include ---------------------------------------*/ * notice, this list of conditions and the following disclaimer in the
#include <coocox.h> * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
#if CFG_UTILITY_EN > 0 * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
/** * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
******************************************************************************* * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* @brief Convert tick number to time * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* @param[in] ticks Specifies the systerm tick numbers that will be converted. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* @param[out] hour Hours which converted. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* @param[out] minute minutes which converted. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* @param[out] sec seconds which converted. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* @param[out] millsec millseconds which converted. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* @retval None * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* @par Description * THE POSSIBILITY OF SUCH DAMAGE.
* @details This function is called to convert specify ticks to time format. *
******************************************************************************* * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
*/ *******************************************************************************
#if CFG_TICK_TO_TIME_EN > 0 */
void CoTickToTime(U32 ticks,U8* hour,U8* minute,U8* sec,U16* millsec)
{
U32 totalTime; /*---------------------------- Include ---------------------------------------*/
#include <coocox.h>
/* Convert ticks to time*/
totalTime = ticks * (1000/CFG_SYSTICK_FREQ); #if CFG_UTILITY_EN > 0
*millsec = totalTime%1000;
totalTime = totalTime/1000;
*sec = totalTime%60; /**
totalTime = totalTime/60; *******************************************************************************
*minute = totalTime%60; * @brief Convert tick number to time
totalTime = totalTime/60; * @param[in] ticks Specifies the systerm tick numbers that will be converted.
*hour = totalTime; * @param[out] hour Hours which converted.
} * @param[out] minute minutes which converted.
#endif /* CFG_TICK_TO_TIME_EN */ * @param[out] sec seconds which converted.
* @param[out] millsec millseconds which converted.
* @retval None
/** *
******************************************************************************* * @par Description
* @brief Convert time to tick * @details This function is called to convert specify ticks to time format.
* @param[in] hour Specifies the number of hours. *******************************************************************************
* @param[in] minute Specifies the number of minutes. */
* @param[in] sec Specifies the number of seconds. #if CFG_TICK_TO_TIME_EN > 0
* @param[in] millsec Specifies the number of millseconds. void CoTickToTime(U32 ticks,U8* hour,U8* minute,U8* sec,U16* millsec)
* @param[out] ticks Tick numbers that converted. {
* @retval E_INVALID_PARAMETER Invalid parameter be passed and convert fail. U32 totalTime;
* @retval E_OK Convert successful.
* /* Convert ticks to time*/
* @par Description totalTime = ticks * (1000/CFG_SYSTICK_FREQ);
* @details This function is called to convert specify time to tick number. *millsec = totalTime%1000;
******************************************************************************* totalTime = totalTime/1000;
*/ *sec = totalTime%60;
#if CFG_TIME_TO_TICK_EN > 0 totalTime = totalTime/60;
StatusType CoTimeToTick(U8 hour,U8 minute,U8 sec,U16 millsec,U32* ticks) *minute = totalTime%60;
{ totalTime = totalTime/60;
#if CFG_PAR_CHECKOUT_EN >0 *hour = totalTime;
/* Validate arguments to be within range */ }
if((minute > 59)||(sec > 59)||(millsec > 999)) #endif /* CFG_TICK_TO_TIME_EN */
return E_INVALID_PARAMETER;
#endif
/**
/* Convert time to ticks */ *******************************************************************************
*ticks = ((hour*3600) + (minute*60) + (sec)) * (CFG_SYSTICK_FREQ)\ * @brief Convert time to tick
+ (millsec*CFG_SYSTICK_FREQ + 500)/1000; * @param[in] hour Specifies the number of hours.
return E_OK; * @param[in] minute Specifies the number of minutes.
} * @param[in] sec Specifies the number of seconds.
#endif /* CFG_TIME_TO_TICK_EN */ * @param[in] millsec Specifies the number of millseconds.
* @param[out] ticks Tick numbers that converted.
#endif /* CFG_UTILITY_EN */ * @retval E_INVALID_PARAMETER Invalid parameter be passed and convert fail.
* @retval E_OK Convert successful.
*
* @par Description
* @details This function is called to convert specify time to tick number.
*******************************************************************************
*/
#if CFG_TIME_TO_TICK_EN > 0
StatusType CoTimeToTick(U8 hour,U8 minute,U8 sec,U16 millsec,U32* ticks)
{
#if CFG_PAR_CHECKOUT_EN >0
/* Validate arguments to be within range */
if((minute > 59)||(sec > 59)||(millsec > 999))
return E_INVALID_PARAMETER;
#endif
/* Convert time to ticks */
*ticks = ((hour*3600) + (minute*60) + (sec)) * (CFG_SYSTICK_FREQ)\
+ (millsec*CFG_SYSTICK_FREQ + 500)/1000;
return E_OK;
}
#endif /* CFG_TIME_TO_TICK_EN */
#endif /* CFG_UTILITY_EN */
+62 -39
View File
@@ -1,39 +1,62 @@
/** /**
******************************************************************************* *******************************************************************************
* @file utility.h * @file utility.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Utility function header file * @brief Utility function header file
* @details This file including some defines and declares related to utility * @details This file including some defines and declares related to utility
* function. * function.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _UTILITY_H * notice, this list of conditions and the following disclaimer in the
#define _UTILITY_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
/** * from this software without specific prior written permission.
* @struct Time struct utility.h *
* @brief Time struct * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* @details This struct use to manage time * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
*/ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
typedef struct SysTime * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
{ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
U8 sec; /*!< Second */ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
U8 min; /*!< Minute */ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
U8 hour; /*!< Hour */ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
U8 date; /*!< Date */ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
U8 month; /*!< Month */ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
U16 year; /*!< Year */ * THE POSSIBILITY OF SUCH DAMAGE.
}TIME; *
* <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
#endif *******************************************************************************
*/
#ifndef _UTILITY_H
#define _UTILITY_H
/**
* @struct Time struct utility.h
* @brief Time struct
* @details This struct use to manage time
*/
typedef struct SysTime
{
U8 sec; /*!< Second */
U8 min; /*!< Minute */
U8 hour; /*!< Hour */
U8 date; /*!< Date */
U8 month; /*!< Month */
U16 year; /*!< Year */
}TIME;
#endif
+332 -295
View File
@@ -1,295 +1,332 @@
/** /**
******************************************************************************* *******************************************************************************
* @file prot.c * @file prot.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Compiler adapter for CooCox CoOS kernel. * @brief Compiler adapter for CooCox CoOS kernel.
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2010 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
/*---------------------------- Include ---------------------------------------*/ * * Redistributions in binary form must reproduce the above copyright
#include "coocox.h" * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
//****************************************************************************** * contributors may be used to endorse or promote products derived
// EQUATES * from this software without specific prior written permission.
//****************************************************************************** *
U32 NVIC_INT_CTRL = 0xE000ED04; // Interrupt control state register * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
U32 NVIC_PENDSVSET = 0x10000000; // Value to trigger PendSV exception * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
U32 INT_EXIT = 0xFFFFFFFC; * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
//****************************************************************************** * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// PUBLIC FUNCTIONS * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
//****************************************************************************** * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
extern U8 Inc8(volatile U8 *data) ; * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
extern U8 Dec8(volatile U8 *data) ; * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
extern void IRQ_ENABLE_RESTORE(void); * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
extern void IRQ_DISABLE_SAVE(void); * THE POSSIBILITY OF SUCH DAMAGE.
extern void SetEnvironment(OS_STK *pstk) __attribute__ ((naked)); *
extern void SwitchContext(void) __attribute__ ((naked)); * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
extern void PendSV_Handler(void) __attribute__ ((naked)); *******************************************************************************
*/
/** /*---------------------------- Include ---------------------------------------*/
****************************************************************************** #include "coocox.h"
* @brief Plus a byte integers and Saved into memory cell
* @param[in] data byte integers.
* @param[out] None //******************************************************************************
* @retval Returns Original value. // EQUATES
* //******************************************************************************
* @par Description U32 NVIC_INT_CTRL = 0xE000ED04; // Interrupt control state register
* @details This function is called to Plus a byte integers U32 NVIC_PENDSVSET = 0x10000000; // Value to trigger PendSV exception
* and Saved into memory cell. U32 INT_EXIT = 0xFFFFFFFC;
******************************************************************************
*/ //******************************************************************************
U8 Inc8 (volatile U8 *data) // PUBLIC FUNCTIONS
{ //******************************************************************************
register U8 result = 0; extern U8 Inc8(volatile U8 *data) ;
extern U8 Dec8(volatile U8 *data) ;
__asm volatile extern void IRQ_ENABLE_RESTORE(void);
( extern void IRQ_DISABLE_SAVE(void);
" PUSH {R1} \n" extern void SetEnvironment(OS_STK *pstk) __attribute__ ((naked));
" CPSID I \n" extern void SwitchContext(void) __attribute__ ((naked));
" LDRB R1,[%1] \n" extern void PendSV_Handler(void) __attribute__ ((naked));
" ADD R1,#1 \n"
" STRB R1,[%1] \n"
" CPSIE I \n" /**
" SUB R1,#0x1 \n" ******************************************************************************
" MOVS %0,R1 \n" * @brief Plus a byte integers and Saved into memory cell
" POP {R1} \n" * @param[in] data byte integers.
:"=r"(result) * @param[out] None
:"r"(data) * @retval Returns Original value.
); *
return (result); * @par Description
* @details This function is called to Plus a byte integers
} * and Saved into memory cell.
******************************************************************************
*/
/** U8 Inc8 (volatile U8 *data)
****************************************************************************** {
* @brief Decrease a byte integers and Saved into memory cell register U8 result = 0;
* @param[in] data byte integers.
* @param[out] None __asm volatile
* @retval Returns Original value. (
* " PUSH {R1} \n"
* @par Description " CPSID I \n"
* @details This function is called to Decrease a byte integers " LDRB R1,[%1] \n"
* and Saved into memory cell. " ADD R1,#1 \n"
****************************************************************************** " STRB R1,[%1] \n"
*/ " CPSIE I \n"
U8 Dec8 (volatile U8 *data) " SUB R1,#0x1 \n"
{ " MOVS %0,R1 \n"
register U8 result = 0; " POP {R1} \n"
__asm volatile :"=r"(result)
( :"r"(data)
" PUSH {R1} \n" );
" CPSID I \n" return (result);
" LDRB R1,[%1] \n"
" SUB R1,#1 \n" }
" STRB R1,[%1] \n"
" CPSIE I \n"
" MOVS %0,R1 \n" /**
" POP {R1} \n" ******************************************************************************
:"=r"(result) * @brief Decrease a byte integers and Saved into memory cell
:"r"(data) * @param[in] data byte integers.
); * @param[out] None
return (result); * @retval Returns Original value.
} *
* @par Description
/** * @details This function is called to Decrease a byte integers
****************************************************************************** * and Saved into memory cell.
* @brief ENABLE Interrupt ******************************************************************************
* @param[in] None */
* @param[out] None U8 Dec8 (volatile U8 *data)
* @retval None {
* register U8 result = 0;
* @par Description __asm volatile
* @details This function is called to ENABLE Interrupt. (
****************************************************************************** " PUSH {R1} \n"
*/ " CPSID I \n"
void IRQ_ENABLE_RESTORE(void) " LDRB R1,[%1] \n"
{ " SUB R1,#1 \n"
__asm volatile " STRB R1,[%1] \n"
( " CPSIE I \n"
" CPSIE I \n" " MOVS %0,R1 \n"
); " POP {R1} \n"
return; :"=r"(result)
} :"r"(data)
);
/** return (result);
****************************************************************************** }
* @brief Close Interrupt
* @param[in] None /**
* @param[out] None ******************************************************************************
* @retval None * @brief ENABLE Interrupt
* * @param[in] None
* @par Description * @param[out] None
* @details This function is called to close Interrupt. * @retval None
****************************************************************************** *
*/ * @par Description
void IRQ_DISABLE_SAVE(void) * @details This function is called to ENABLE Interrupt.
{ ******************************************************************************
__asm volatile */
( void IRQ_ENABLE_RESTORE(void)
" CPSID I \n" {
); __asm volatile
return; (
} " CPSIE I \n"
);
return;
/** }
******************************************************************************
* @brief Set environment for Coocox OS running /**
* @param[in] pstk stack pointer ******************************************************************************
* @param[out] None * @brief Close Interrupt
* @retval None. * @param[in] None
* * @param[out] None
* @par Description * @retval None
* @details This function is called to Set environment *
* for Coocox OS running. * @par Description
****************************************************************************** * @details This function is called to close Interrupt.
*/ ******************************************************************************
void SetEnvironment (OS_STK *pstk) */
{ void IRQ_DISABLE_SAVE(void)
__asm volatile {
( __asm volatile
" SUB R0,#28 \n" (
" MSR PSP,R0 \n" " CPSID I \n"
" BX LR \n" );
); return;
}
}
/**
/** ******************************************************************************
****************************************************************************** * @brief Set environment for Coocox OS running
* @brief Do ready work to Switch Context for task change * @param[in] pstk stack pointer
* @param[in] None * @param[out] None
* @param[out] None * @retval None.
* @retval None. *
* * @par Description
* @par Description * @details This function is called to Set environment
* @details This function is called to Do ready work to * for Coocox OS running.
* Switch Context for task change ******************************************************************************
****************************************************************************** */
*/ void SetEnvironment (OS_STK *pstk)
void SwitchContext(void) {
{ __asm volatile
__asm volatile (
( #if CFG_CHIP_TYPE == 3
" LDR R3,=NVIC_INT_CTRL \n" " SUB R0,#100 \n"
" LDR R3,[R3] \n" #else
" LDR R2,=NVIC_PENDSVSET \n" " SUB R0,#28 \n"
" LDR R1,[R2] \n" #endif
" STR R1, [R3] \n" " MSR PSP,R0 \n"
" BX LR \n" " BX LR \n"
); );
} }
/**
/** ******************************************************************************
****************************************************************************** * @brief Do ready work to Switch Context for task change
* @brief Switch Context for task change * @param[in] None
* @param[in] None * @param[out] None
* @param[out] None * @retval None.
* @retval None. *
* * @par Description
* @par Description * @details This function is called to Do ready work to
* @details This function is called to Switch Context for task change. * Switch Context for task change
****************************************************************************** ******************************************************************************
*/ */
#if CFG_CHIP_TYPE == 2 void SwitchContext(void)
void PendSV_Handler(void) {
{ __asm volatile
__asm volatile (
( " LDR R3,=NVIC_INT_CTRL \n"
" LDR R3,=TCBRunning \n" " LDR R3,[R3] \n"
" LDR R1,[R3] \n" // R1 == running tcb " LDR R2,=NVIC_PENDSVSET \n"
" LDR R2,=TCBNext \n" " LDR R1,[R2] \n"
" LDR R2,[R2] \n" // R2 == next tcb " STR R1, [R3] \n"
" BX LR \n"
" CMP R1,R2 \n" );
" BEQ exitPendSV \n"
" MRS R0, PSP \n" // Get PSP point (can not use PUSH,in ISR,SP is MSP ) }
" SUB R0,R0,#32 \n"
" STR R0,[R1] \n" // Save orig PSP
// Store r4-r11,r0 -= regCnt * 4,r0 is new stack /**
// top point (addr h->l r11,r10,...,r5,r4) ******************************************************************************
" STMIA R0!,{R4-R7} \n" // Save old context (R4-R7) * @brief Switch Context for task change
" MOV R4,R8 \n" * @param[in] None
" MOV R5,R9 \n" * @param[out] None
" MOV R6,R10 \n" * @retval None.
" MOV R7,R11 \n" *
" STMIA R0!,{R4-R7} \n" // Save old context (R8-R11) * @par Description
* @details This function is called to Switch Context for task change.
" popStk: \n" ******************************************************************************
" STR R2, [R3] \n" // TCBRunning = TCBNext; */
" LDR R0, [R2] \n" // Get SP of task that be switch into. #if CFG_CHIP_TYPE == 2
void PendSV_Handler(void)
" ADD R0,R0,#16 \n" {
" LDMIA R0!,{R4-R7} \n" // Restore new Context (R8-R11) __asm volatile
" MOV R8,R4 \n" (
" MOV R9,R5 \n" " LDR R3,=TCBRunning \n"
" MOV R10,R6 \n" " LDR R1,[R3] \n" // R1 == running tcb
" MOV R11,R7 \n" " LDR R2,=TCBNext \n"
" SUB R0,R0,#32 \n" " LDR R2,[R2] \n" // R2 == next tcb
" LDMIA R0!,{R4-R7} \n" // Restore new Context (R4-R7)
" ADD R0,R0,#16 \n" " CMP R1,R2 \n"
" MSR PSP, R0 \n" // Mov new stack point to PSP " BEQ exitPendSV \n"
" MRS R0, PSP \n" // Get PSP point (can not use PUSH,in ISR,SP is MSP )
" exitPendSV: \n"
" LDR R3,=OSSchedLock \n" " SUB R0,R0,#32 \n"
" MOV R0, #0x0 \n" " STR R0,[R1] \n" // Save orig PSP
" STRB R0, [R3] \n" // Store r4-r11,r0 -= regCnt * 4,r0 is new stack
// top point (addr h->l r11,r10,...,r5,r4)
" LDR R3,=INT_EXIT \n" " STMIA R0!,{R4-R7} \n" // Save old context (R4-R7)
" LDR R0, [R3] \n" " MOV R4,R8 \n"
" BX R0 \n" // Exit interrupt " MOV R5,R9 \n"
); " MOV R6,R10 \n"
} " MOV R7,R11 \n"
#endif " STMIA R0!,{R4-R7} \n" // Save old context (R8-R11)
#if CFG_CHIP_TYPE == 1 " popStk: \n"
void PendSV_Handler(void) " STR R2, [R3] \n" // TCBRunning = TCBNext;
{ " LDR R0, [R2] \n" // Get SP of task that be switch into.
////////debug block /////////////////////////
__asm volatile " ADD R0,R0,#16 \n"
( " LDMIA R0!,{R4-R7} \n" // Restore new Context (R8-R11)
" LDR R3,=TCBRunning \n" " MOV R8,R4 \n"
" LDR R1,[R3] \n" // R1 == running tcb " MOV R9,R5 \n"
" LDR R2,=TCBNext \n" " MOV R10,R6 \n"
" LDR R2,[R2] \n" // R2 == next tcb " MOV R11,R7 \n"
" SUB R0,R0,#32 \n"
" CMP R1,R2 \n" " LDMIA R0!,{R4-R7} \n" // Restore new Context (R4-R7)
" BEQ exitPendSV \n" " ADD R0,R0,#16 \n"
" MSR PSP, R0 \n" // Mov new stack point to PSP
" MRS R0, PSP \n" // Get PSP point (can not use PUSH,in ISR,SP is MSP )
" STMDB R0!,{R4-R11} \n" // Store r4-r11,r0 -= regCnt * 4,r0 is new stack " exitPendSV: \n"
// top point (addr h->l r11,r10,...,r5,r4) " LDR R3,=OSSchedLock \n"
" STR R0,[R1] \n" // Save orig PSP " MOV R0, #0x0 \n"
" STRB R0, [R3] \n"
" STR R2, [R3] \n" // TCBRunning = TCBNext;
" LDR R0, [R2] \n" // Get SP of task that be switch into. " LDR R3,=INT_EXIT \n"
" LDMIA R0!,{R4-R11} \n" // POP {R4-R11},R0 += regCnt * 4 " LDR R0, [R3] \n"
" MSR PSP, R0 \n" // Mov new stack point to PSP " BX R0 \n" // Exit interrupt
);
}
" exitPendSV: \n" #endif
" LDR R3,=OSSchedLock\n"
" MOVS R0, #0x0 \n" #if CFG_CHIP_TYPE == 1 || 3 == CFG_CHIP_TYPE
" STRB R0, [R3] \n" void PendSV_Handler(void)
" ORR LR,LR,#0x04 \n" // Ensure exception return uses process stack {
" BX LR \n" // Exit interrupt ////////debug block /////////////////////////
); __asm volatile
} (
#endif " LDR R3,=TCBRunning \n"
" LDR R1,[R3] \n" // R1 == running tcb
" LDR R2,=TCBNext \n"
" LDR R2,[R2] \n" // R2 == next tcb
" CMP R1,R2 \n"
" BEQ exitPendSV \n"
" MRS R0, PSP \n" // Get PSP point (can not use PUSH,in ISR,SP is MSP )
" STMDB R0!,{R4-R11} \n" // Store r4-r11,r0 -= regCnt * 4,r0 is new stack
// top point (addr h->l r11,r10,...,r5,r4)
#if CFG_CHIP_TYPE == 3
" VSTMDB R0!, {S16-S31} \n" // store remaining FPU registers
#endif // CFG_FPU_ENABLE
" STR R0,[R1] \n" // Save orig PSP
" STR R2, [R3] \n" // TCBRunning = TCBNext;
" LDR R0, [R2] \n" // Get SP of task that be switch into.
#if CFG_CHIP_TYPE == 3
" VLDMIA R0!, {S16-S31} \n" // load remaining FPU registers
#endif // CFG_FPU_ENABLE
" LDMIA R0!,{R4-R11} \n" // POP {R4-R11},R0 += regCnt * 4
" MSR PSP, R0 \n" // Mov new stack point to PSP
" exitPendSV: \n"
" LDR R3,=OSSchedLock\n"
" MOVS R0, #0x0 \n"
" STRB R0, [R3] \n"
" ORR LR,LR,#0x04 \n" // Ensure exception return uses process stack
#if CFG_CHIP_TYPE == 3
" LDR LR,=0xFFFFFFED \n"
#endif
" BX LR \n" // Exit interrupt
);
}
#endif
+75 -50
View File
@@ -1,50 +1,75 @@
/** /**
******************************************************************************* *******************************************************************************
* @file OsArch.h * @file OsArch.h
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief Implement function declare related to Cortex-M3(ARM-v7) * @brief Implement function declare related to Cortex-M3(ARM-v7)
* @details This header file including functions or defines related to * @details This header file including functions or defines related to
* Cortex-M3(ARM-v7). * Cortex-M3(ARM-v7).
******************************************************************************* *******************************************************************************
* @copy * @copy
* *
* INTERNAL FILE,DON'T PUBLIC. * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
#ifndef _CPU_H * notice, this list of conditions and the following disclaimer in the
#define _CPU_H * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived
#define NVIC_ST_CTRL (*((volatile U32 *)0xE000E010)) * from this software without specific prior written permission.
#define NVIC_ST_RELOAD (*((volatile U32 *)0xE000E014)) *
#define RELOAD_VAL ((U32)(( (U32)CFG_CPU_FREQ) / (U32)CFG_SYSTICK_FREQ) -1) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
/*!< Initial System tick. */ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#define InitSysTick() NVIC_ST_RELOAD = RELOAD_VAL; \ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
NVIC_ST_CTRL = 0x0007 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#define NVIC_SYS_PRI2 (*((volatile U32 *)0xE000ED1C)) * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#define NVIC_SYS_PRI3 (*((volatile U32 *)0xE000ED20)) * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
/*!< Initialize PendSV,SVC and SysTick interrupt priority to lowest. */ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
#define InitInt() NVIC_SYS_PRI2 |= 0xFF000000;\ * THE POSSIBILITY OF SUCH DAMAGE.
NVIC_SYS_PRI3 |= 0xFFFF0000 *
* <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
*******************************************************************************
/*---------------------------- Variable declare ------------------------------*/ */
extern U64 OSTickCnt; /*!< Counter for current system ticks. */
/*!< Initial context of task being created */ #ifndef _CPU_H
extern OS_STK *InitTaskContext(FUNCPtr task,void *param,OS_STK *pstk); #define _CPU_H
extern void SwitchContext(void); /*!< Switch context */
extern void SetEnvironment(OS_STK *pstk);/*!< Set environment for run */
extern U8 Inc8 (volatile U8 *data); #define NVIC_ST_CTRL (*((volatile U32 *)0xE000E010))
extern U8 Dec8 (volatile U8 *data); #define NVIC_ST_RELOAD (*((volatile U32 *)0xE000E014))
extern void IRQ_ENABLE_RESTORE(void); #define RELOAD_VAL ((U32)(( (U32)CFG_CPU_FREQ) / (U32)CFG_SYSTICK_FREQ) -1)
extern void IRQ_DISABLE_SAVE(void);
#endif /*!< Initial System tick. */
#define InitSysTick() NVIC_ST_RELOAD = RELOAD_VAL; \
NVIC_ST_CTRL = 0x0007
#define NVIC_SYS_PRI2 (*((volatile U32 *)0xE000ED1C))
#define NVIC_SYS_PRI3 (*((volatile U32 *)0xE000ED20))
/*!< Initialize PendSV,SVC and SysTick interrupt priority to lowest. */
#define InitInt() NVIC_SYS_PRI2 |= 0xFF000000;\
NVIC_SYS_PRI3 |= 0xFFFF0000
/*---------------------------- Variable declare ------------------------------*/
extern U64 OSTickCnt; /*!< Counter for current system ticks. */
/*!< Initial context of task being created */
extern OS_STK *InitTaskContext(FUNCPtr task,void *param,OS_STK *pstk);
extern void SwitchContext(void); /*!< Switch context */
extern void SetEnvironment(OS_STK *pstk);/*!< Set environment for run */
extern U8 Inc8 (volatile U8 *data);
extern U8 Dec8 (volatile U8 *data);
extern void IRQ_ENABLE_RESTORE(void);
extern void IRQ_DISABLE_SAVE(void);
#endif /* _CPU_H */
+126 -96
View File
@@ -1,96 +1,126 @@
/** /**
******************************************************************************* *******************************************************************************
* @file arch.c * @file arch.c
* @version V1.1.4 * @version V1.1.6
* @date 2011.04.20 * @date 2014.05.23
* @brief This file provides InitTaskContext() and SysTick_Handler(). * @brief This file provides InitTaskContext() and SysTick_Handler().
******************************************************************************* *******************************************************************************
* @copy * @copy
* WRITE COPY INFORMATION USE CAPITAL LETTER * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions
* <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2> * are met:
******************************************************************************* *
*/ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
/*---------------------------- Include ---------------------------------------*/ * * Redistributions in binary form must reproduce the above copyright
#include <coocox.h> * notice, this list of conditions and the following disclaimer in the
U64 OSTickCnt = 0; /*!< Current system tick counter */ * documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
/** * contributors may be used to endorse or promote products derived
****************************************************************************** * from this software without specific prior written permission.
* @brief Initial task context *
* @param[in] task Entry point of task. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* @param[in] param The parameter pass to task. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* @param[in] pstk The pointer to stack top. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* @param[out] None * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* @retval Returns location of new stack top. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* @par Description * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* @details This function is called to initialize the stack frame of the * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* task being created. * 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.
OS_STK *InitTaskContext(FUNCPtr task,void *param,OS_STK *pstk) *
{ * <h2><center>&copy; COPYRIGHT 2014 CooCox </center></h2>
OS_STK *context; *******************************************************************************
context = pstk; */
*(context--) = (U32)0x01000000L; /* xPSR */
*(context--) = (U32)task; /* Entry point of task. */ /*---------------------------- Include ---------------------------------------*/
*(context) = (U32)0xFFFFFFFEL; #include <coocox.h>
context = context - 5; U64 OSTickCnt = 0; /*!< Current system tick counter */
*(context) = (U32)param; /* R0: argument */
context = context - 8; /**
******************************************************************************
return (context); /* Returns location of new stack top. */ * @brief Initial task context
} * @param[in] task Entry point of task.
* @param[in] param The parameter pass to task.
* @param[in] pstk The pointer to stack top.
* @param[out] None
/** * @retval Returns location of new stack top.
******************************************************************************* *
* @brief System tick interrupt handler. * @par Description
* @param[in] None * @details This function is called to initialize the stack frame of the
* @param[out] None * task being created.
* @retval None ******************************************************************************
* */
* @par Description OS_STK *InitTaskContext(FUNCPtr task,void *param,OS_STK *pstk)
* @details This is system tick interrupt headler. {
* @note CoOS may schedule when exiting this ISR. OS_STK *context;
******************************************************************************* context = pstk;
*/ #if CFG_CHIP_TYPE == 3
void SysTick_Handler(void) context = context - 18;
{ #endif
OSSchedLock++; /* Lock scheduler. */ *(context--) = (U32)0x01000000L; /* xPSR */
OSTickCnt++; /* Increment systerm time. */ *(context--) = (U32)task; /* Entry point of task. */
#if CFG_TASK_WAITTING_EN >0 *(context) = (U32)0xFFFFFFFEL;
if(DlyList != Co_NULL) /* Have task in delay list? */ context = context - 5;
{ *(context) = (U32)param; /* R0: argument */
if(DlyList->delayTick > 1) /* Delay time > 1? */ context = context - 8;
{ #if CFG_CHIP_TYPE == 3
DlyList->delayTick--; /* Decrease delay time of the list head. */ context = context - 16;
} #endif
else // *(--context) = 0xfffffffd; /* LR */
{
DlyList->delayTick = 0; return (context); /* Returns location of new stack top. */
isr_TimeDispose(); /* Call hander for delay time list */ }
}
}
#endif
/**
#if CFG_TMR_EN > 0 *******************************************************************************
if(TmrList != Co_NULL) /* Have timer in working? */ * @brief System tick interrupt handler.
{ * @param[in] None
if(TmrList->tmrCnt > 1) /* Timer time > 1? */ * @param[out] None
{ * @retval None
TmrList->tmrCnt--; /* Decrease timer time of the list head. */ *
} * @par Description
else * @details This is system tick interrupt headler.
{ * @note CoOS may schedule when exiting this ISR.
TmrList->tmrCnt = 0; *******************************************************************************
isr_TmrDispose(); /* Call hander for timer list */ */
} void SysTick_Handler(void)
} {
#endif OSSchedLock++; /* Lock scheduler. */
TaskSchedReq = Co_TRUE; OSTickCnt++; /* Increment systerm time. */
OsSchedUnlock(); #if CFG_TASK_WAITTING_EN >0
} if(DlyList != Co_NULL) /* Have task in delay list? */
{
if(DlyList->delayTick > 1) /* Delay time > 1? */
{
DlyList->delayTick--; /* Decrease delay time of the list head. */
}
else
{
DlyList->delayTick = 0;
isr_TimeDispose(); /* Call hander for delay time list */
}
}
#endif
#if CFG_TMR_EN > 0
if(TmrList != Co_NULL) /* Have timer in working? */
{
if(TmrList->tmrCnt > 1) /* Timer time > 1? */
{
TmrList->tmrCnt--; /* Decrease timer time of the list head. */
}
else
{
TmrList->tmrCnt = 0;
isr_TmrDispose(); /* Call hander for timer list */
}
}
#endif
TaskSchedReq = Co_TRUE;
OsSchedUnlock();
}
+40 -17
View File
@@ -720,7 +720,7 @@ ifeq ($(PCB), $(filter $(PCB), SKY9X 9XRPRO))
CPPSRC += targets/sky9x/coproc_driver.cpp CPPSRC += targets/sky9x/coproc_driver.cpp
endif endif
TRGT = arm-none-eabi- TRGT = arm-none-eabi-
MCU = cortex-m3 MCU = cortex-m3
OPT = s OPT = s
SDCARD = YES SDCARD = YES
BUZZER = NO BUZZER = NO
@@ -733,7 +733,7 @@ ifeq ($(PCB), $(filter $(PCB), SKY9X 9XRPRO))
ifeq ($(SPORT_FILE_LOG), YES) ifeq ($(SPORT_FILE_LOG), YES)
CPPDEFS += -DSPORT_FILE_LOG CPPDEFS += -DSPORT_FILE_LOG
endif endif
INCDIRS += targets/sky9x CoOS/kernel CoOS/portable INCDIRS += targets/sky9x CoOS CoOS/kernel CoOS/portable
GUIGENERALSRC += gui/$(GUIDIRECTORY)/menu_general_hardware.cpp gui/$(GUIDIRECTORY)/menu_general_diagkeys.cpp gui/$(GUIDIRECTORY)/menu_general_diaganas.cpp GUIGENERALSRC += gui/$(GUIDIRECTORY)/menu_general_hardware.cpp gui/$(GUIDIRECTORY)/menu_general_diagkeys.cpp gui/$(GUIDIRECTORY)/menu_general_diaganas.cpp
BOARDSRC = main_arm.cpp targets/sky9x/board_sky9x.cpp BOARDSRC = main_arm.cpp targets/sky9x/board_sky9x.cpp
EXTRABOARDSRC = targets/sky9x/lcd_driver.cpp EXTRABOARDSRC = targets/sky9x/lcd_driver.cpp
@@ -779,6 +779,7 @@ ifeq ($(PCB), TARANIS)
LCDSIZE = 212 LCDSIZE = 212
GUIDIRECTORY = Taranis GUIDIRECTORY = Taranis
ifeq ($(PCBREV), REV9E) ifeq ($(PCBREV), REV9E)
MCU = cortex-m4
FLAVOUR = taranis-x9e FLAVOUR = taranis-x9e
CPPDEFS = -DREVPLUS -DREV9E CPPDEFS = -DREVPLUS -DREV9E
ifeq ($(LCD_DUAL_BUFFER), YES) ifeq ($(LCD_DUAL_BUFFER), YES)
@@ -787,6 +788,7 @@ ifeq ($(PCB), TARANIS)
HAPTIC = YES HAPTIC = YES
EXTRABOARDSRC += targets/taranis/bluetooth_driver.cpp EXTRABOARDSRC += targets/taranis/bluetooth_driver.cpp
else ifeq ($(PCBREV), REVPLUS) else ifeq ($(PCBREV), REVPLUS)
MCU = cortex-m3
FLAVOUR = taranis-plus FLAVOUR = taranis-plus
CPPDEFS = -DREVPLUS CPPDEFS = -DREVPLUS
ifeq ($(LCD_DUAL_BUFFER), YES) ifeq ($(LCD_DUAL_BUFFER), YES)
@@ -794,12 +796,15 @@ ifeq ($(PCB), TARANIS)
endif endif
HAPTIC = YES HAPTIC = YES
else ifeq ($(PCBREV), REV3) else ifeq ($(PCBREV), REV3)
MCU = cortex-m3
FLAVOUR = taranis FLAVOUR = taranis
CPPDEFS = -DREV3 CPPDEFS = -DREV3
else ifeq ($(PCBREV), REV4a) else ifeq ($(PCBREV), REV4a)
MCU = cortex-m3
FLAVOUR = taranis FLAVOUR = taranis
CPPDEFS = -DREV4a CPPDEFS = -DREV4a
else else
MCU = cortex-m3
FLAVOUR = taranis FLAVOUR = taranis
CPPDEFS = -DREV4 CPPDEFS = -DREV4
endif endif
@@ -829,7 +834,6 @@ ifeq ($(PCB), TARANIS)
endif endif
LDSCRIPT = targets/taranis/stm32_flash_bl.ld LDSCRIPT = targets/taranis/stm32_flash_bl.ld
TRGT = arm-none-eabi- TRGT = arm-none-eabi-
MCU = cortex-m3
OPT = s OPT = s
CPPDEFS += -DHSE_VALUE=12000000 CPPDEFS += -DHSE_VALUE=12000000
BITMAPS += $(patsubst %.png,%.lbm,$(wildcard bitmaps/Taranis/*.png)) bitmaps/Taranis/mainmenu.lbm BITMAPS += $(patsubst %.png,%.lbm,$(wildcard bitmaps/Taranis/*.png)) bitmaps/Taranis/mainmenu.lbm
@@ -843,8 +847,13 @@ ifeq ($(PCB), TARANIS)
PPM_CENTER_ADJUSTABLE = YES PPM_CENTER_ADJUSTABLE = YES
DSM2 = PPM DSM2 = PPM
CPPDEFS += -DPCBTARANIS -DCPUARM -DCPUSTM32 -DVIRTUALINPUTS -DLUAINPUTS -DXCURVES -DEEPROM_VARIANT=0 -DAUDIO -DPXX CPPDEFS += -DPCBTARANIS -DCPUARM -DCPUSTM32 -DVIRTUALINPUTS -DLUAINPUTS -DXCURVES -DEEPROM_VARIANT=0 -DAUDIO -DPXX
INCDIRS += targets/taranis CoOS/kernel CoOS/portable INCDIRS += targets/taranis CoOS CoOS/kernel CoOS/portable
EXTRAINCDIRS += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/include ifeq ($(PCBREV), REV9E)
CPPDEFS += -DSTM32F40_41xxx
EXTRAINCDIRS += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Include targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc
else
EXTRAINCDIRS += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/include
endif
EXTRAINCDIRS += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc EXTRAINCDIRS += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc
EXTRAINCDIRS += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/hid/inc EXTRAINCDIRS += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/hid/inc
GUIGENERALSRC += gui/$(GUIDIRECTORY)/menu_general_hardware.cpp GUIGENERALSRC += gui/$(GUIDIRECTORY)/menu_general_hardware.cpp
@@ -857,17 +866,31 @@ ifeq ($(PCB), TARANIS)
CPPSRC += tasks_arm.cpp audio_arm.cpp sbus.cpp telemetry/telemetry.cpp CPPSRC += tasks_arm.cpp audio_arm.cpp sbus.cpp telemetry/telemetry.cpp
CPPSRC += targets/taranis/pulses_driver.cpp targets/taranis/keys_driver.cpp targets/taranis/adc_driver.cpp targets/taranis/trainer_driver.cpp targets/taranis/audio_driver.cpp targets/taranis/uart3_driver.cpp targets/taranis/telemetry_driver.cpp CPPSRC += targets/taranis/pulses_driver.cpp targets/taranis/keys_driver.cpp targets/taranis/adc_driver.cpp targets/taranis/trainer_driver.cpp targets/taranis/audio_driver.cpp targets/taranis/uart3_driver.cpp targets/taranis/telemetry_driver.cpp
CPPSRC += bmp.cpp gui/$(GUIDIRECTORY)/view_channels.cpp gui/$(GUIDIRECTORY)/view_about.cpp gui/$(GUIDIRECTORY)/view_text.cpp loadboot.cpp debug.cpp CPPSRC += bmp.cpp gui/$(GUIDIRECTORY)/view_channels.cpp gui/$(GUIDIRECTORY)/view_about.cpp gui/$(GUIDIRECTORY)/view_text.cpp loadboot.cpp debug.cpp
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c ifeq ($(PCBREV), REV9E)
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/misc.c SRC += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c SRC += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/misc.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dbgmcu.c SRC += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rcc.c SRC += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dbgmcu.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_spi.c SRC += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dma.c SRC += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spi.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rtc.c SRC += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dma.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_pwr.c SRC += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rtc.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_usart.c SRC += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_pwr.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s SRC += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_usart.c
SRC += targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f40_41xxx.s
else
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/misc.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dbgmcu.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rcc.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_spi.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dma.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rtc.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_pwr.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_usart.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s
endif
SRC += targets/taranis/usb_bsp.c targets/taranis/usbd_desc.c SRC += targets/taranis/usb_bsp.c targets/taranis/usbd_desc.c
SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c
SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd.c SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd.c
@@ -1621,7 +1644,7 @@ OBJS = $(TMP:.s=.o)
@echo @echo
@echo $(MSG_COMPILING) $@ @echo $(MSG_COMPILING) $@
$(CC) $(ARMCPPFLAGS) $< -o allsrc.o $(CC) $(ARMCPPFLAGS) $< -o allsrc.o
$(CC) $(OBJS) allsrc.o -mcpu=cortex-m3 -mthumb -nostartfiles -lm -T$(LDSCRIPT) -Wl,-Map=$(TARGET).map,--cref,--no-warn-mismatch,--gc-sections $(NEWLIB_NANO_FLAGS) -o $@ $(CC) $(OBJS) allsrc.o -mcpu=$(MCU) -mthumb -nostartfiles -lm -T$(LDSCRIPT) -Wl,-Map=$(TARGET).map,--cref,--no-warn-mismatch,--gc-sections $(NEWLIB_NANO_FLAGS) -o $@
endif endif
# Target: clean project. # Target: clean project.
+54 -29
View File
@@ -27,7 +27,11 @@ BINX = $(CP) -O binary
OBJDIR = . OBJDIR = .
MCU = cortex-m3 ifeq ($(PCBREV), REV9E)
MCU = cortex-m4
else
MCU = cortex-m3
endif
# List all default C defines here, like -D_DEBUG=1 # List all default C defines here, like -D_DEBUG=1
DDEFS = DDEFS =
@@ -109,8 +113,16 @@ else
CPPDEFS += -DHSE_VALUE=12000000 CPPDEFS += -DHSE_VALUE=12000000
CPPDEFS += -DPCBTARANIS CPPDEFS += -DPCBTARANIS
FULL_PRJ = $(PROJECT)_ramBoot FULL_PRJ = $(PROJECT)_ramBoot
EXTRAINCDIRS += ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc ifeq ($(PCBREV), REV9E)
EXTRAINCDIRS += ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include CPPDEFS += -DSTM32F40_41xxx
EXTRAINCDIRS += ../targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc
EXTRAINCDIRS += ../targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include
EXTRAINCDIRS += ../targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Include
else
EXTRAINCDIRS += ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc
EXTRAINCDIRS += ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include
EXTRAINCDIRS += ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/include
endif
EXTRAINCDIRS += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc EXTRAINCDIRS += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc
EXTRAINCDIRS += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc EXTRAINCDIRS += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc
EXTRAINCDIRS += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc EXTRAINCDIRS += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc
@@ -141,32 +153,40 @@ endif
# Define ASM defines here # Define ASM defines here
UADEFS = UADEFS =
SRC =
ifeq ($(PCB), TARANIS) ifeq ($(PCB), TARANIS)
SRC = ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c \ ifeq ($(PCBREV), REV9E)
../targets/taranis/i2c.c \ SRC += ../targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c
../targets/taranis/delays.c \ SRC += ../targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rcc.c \ SRC += ../targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c
../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c \ SRC += ../targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spi.c
../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_spi.c \ SRC += ../targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/src/misc.c
../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/misc.c \ else
../FatFs/ff.c \ SRC += ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c
../FatFs/option/ccsbcs.c \ SRC += ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rcc.c
../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c \ SRC += ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c
../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd.c \ SRC += ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_spi.c
../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c \ SRC += ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/misc.c
../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_core.c \ endif
../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_ioreq.c \ SRC += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c
../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_req.c \ SRC += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd.c
../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_data.c \ SRC += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c
../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c \ SRC += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_core.c
../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_bot.c \ SRC += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_ioreq.c
../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c \ SRC += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_req.c
../targets/taranis/usbd_desc.c \ SRC += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_data.c
../targets/taranis/aspi.c \ SRC += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c
../targets/taranis/usb_bsp.c \ SRC += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_bot.c
../targets/taranis/usb_driver.c \ SRC += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c
../targets/taranis/pwr_driver.c \ SRC += ../targets/taranis/i2c.c ../targets/taranis/delays.c
init.c SRC += ../FatFs/ff.c ../FatFs/option/ccsbcs.c
SRC += ../targets/taranis/usbd_desc.c
SRC += ../targets/taranis/aspi.c
SRC += ../targets/taranis/usb_bsp.c
SRC += ../targets/taranis/usb_driver.c
SRC += ../targets/taranis/pwr_driver.c
SRC += init.c
CPPSRC = ../targets/taranis/lcd_driver.cpp \ CPPSRC = ../targets/taranis/lcd_driver.cpp \
../targets/taranis/configure_pins.cpp \ ../targets/taranis/configure_pins.cpp \
@@ -186,7 +206,12 @@ ifeq ($(PCBREV), REV9E)
endif endif
# List ASM source files here # List ASM source files here
ASRC = ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s
ifeq ($(PCBREV), REV9E)
ASRC = ../targets/taranis/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f40_41xxx.s
else
ASRC = ../targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s
endif
else else
+13 -8
View File
@@ -355,17 +355,22 @@ void menuChannelsView(uint8_t event);
#define KEY_MOVE_UP KEY_PLUS #define KEY_MOVE_UP KEY_PLUS
#define KEY_MOVE_DOWN KEY_MINUS #define KEY_MOVE_DOWN KEY_MINUS
#if defined(REV9E) #if defined(REV9E)
#define CURSOR_MOVED_LEFT(event) (EVT_KEY_MASK(event) == KEY_MINUS) #define CURSOR_MOVED_LEFT(event) (EVT_KEY_MASK(event) == KEY_MINUS)
#define CURSOR_MOVED_RIGHT(event) (EVT_KEY_MASK(event) == KEY_PLUS) #define CURSOR_MOVED_RIGHT(event) (EVT_KEY_MASK(event) == KEY_PLUS)
#define CASE_EVT_ROTARY_MOVE_RIGHT CASE_EVT_ROTARY_RIGHT
#define CASE_EVT_ROTARY_MOVE_LEFT CASE_EVT_ROTARY_LEFT
#define IS_ROTARY_MOVE_RIGHT IS_ROTARY_RIGHT
#define IS_ROTARY_MOVE_LEFT IS_ROTARY_LEFT
#else #else
#define CURSOR_MOVED_LEFT(event) (EVT_KEY_MASK(event) == KEY_PLUS) #define CURSOR_MOVED_LEFT(event) (EVT_KEY_MASK(event) == KEY_PLUS)
#define CURSOR_MOVED_RIGHT(event) (EVT_KEY_MASK(event) == KEY_MINUS) #define CURSOR_MOVED_RIGHT(event) (EVT_KEY_MASK(event) == KEY_MINUS)
#define CASE_EVT_ROTARY_MOVE_RIGHT CASE_EVT_ROTARY_LEFT
#define CASE_EVT_ROTARY_MOVE_LEFT CASE_EVT_ROTARY_RIGHT
#define IS_ROTARY_MOVE_RIGHT IS_ROTARY_LEFT
#define IS_ROTARY_MOVE_LEFT IS_ROTARY_RIGHT
#endif #endif
#define CASE_EVT_ROTARY_MOVE_RIGHT CASE_EVT_ROTARY_LEFT
#define CASE_EVT_ROTARY_MOVE_LEFT CASE_EVT_ROTARY_RIGHT
#define IS_ROTARY_MOVE_RIGHT IS_ROTARY_LEFT
#define IS_ROTARY_MOVE_LEFT IS_ROTARY_RIGHT
#define REPEAT_LAST_CURSOR_MOVE() { if (CURSOR_MOVED_LEFT(event) || CURSOR_MOVED_RIGHT(event)) putEvent(event); else m_posHorz = 0; } #define REPEAT_LAST_CURSOR_MOVE() { if (CURSOR_MOVED_LEFT(event) || CURSOR_MOVED_RIGHT(event)) putEvent(event); else m_posHorz = 0; }
#define MOVE_CURSOR_FROM_HERE() if (m_posHorz > 0) REPEAT_LAST_CURSOR_MOVE() #define MOVE_CURSOR_FROM_HERE() if (m_posHorz > 0) REPEAT_LAST_CURSOR_MOVE()
+3
View File
@@ -51,6 +51,9 @@
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
#include "AT91SAM3S4.h" #include "AT91SAM3S4.h"
#elif defined(PCBTARANIS) && defined(REV9E)
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#elif defined(PCBTARANIS) #elif defined(PCBTARANIS)
#include "stm32f2xx.h" #include "stm32f2xx.h"
#include "stm32f2xx_gpio.h" #include "stm32f2xx_gpio.h"
@@ -35,7 +35,7 @@
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f2xx.h" #include "../../CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
/** @addtogroup STM32F2xx_StdPeriph_Driver /** @addtogroup STM32F2xx_StdPeriph_Driver
* @{ * @{
@@ -12,15 +12,15 @@
* is using in the C source code, usually in main.c. This file contains: * is using in the C source code, usually in main.c. This file contains:
* - Configuration section that allows to select: * - Configuration section that allows to select:
* - The device used in the target application * - The device used in the target application
* - To use or not the peripheral’s drivers in application code(i.e. * - To use or not the peripheral�s drivers in application code(i.e.
* code will be based on direct access to peripheral’s registers * code will be based on direct access to peripheral�s registers
* rather than drivers API), this option is controlled by * rather than drivers API), this option is controlled by
* "#define USE_STDPERIPH_DRIVER" * "#define USE_STDPERIPH_DRIVER"
* - To change few application-specific parameters such as the HSE * - To change few application-specific parameters such as the HSE
* crystal frequency * crystal frequency
* - Data structures and the address mapping for all peripherals * - Data structures and the address mapping for all peripherals
* - Peripheral's registers declarations and bits definition * - Peripheral's registers declarations and bits definition
* - Macros to access peripheral’s registers hardware * - Macros to access peripheral�s registers hardware
* *
****************************************************************************** ******************************************************************************
* @attention * @attention
@@ -53,6 +53,8 @@
#ifndef __STM32F4xx_H #ifndef __STM32F4xx_H
#define __STM32F4xx_H #define __STM32F4xx_H
#define assert_param(xx)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
@@ -467,7 +469,7 @@ typedef enum IRQn
* @} * @}
*/ */
#include "core_cm4.h" /* Cortex-M4 processor and core peripherals */ #include "../../../../Include/core_cm4.h" /* Cortex-M4 processor and core peripherals */
#include "system_stm32f4xx.h" #include "system_stm32f4xx.h"
#include <stdint.h> #include <stdint.h>
@@ -1,438 +0,0 @@
/**
******************************************************************************
* @file startup_stm32f40xx.s
* @author MCD Application Team
* @version V1.3.0
* @date 08-November-2013
* @brief STM32F401xx Devices vector table for RIDE7 toolchain.
* This module performs:
* - Set the initial SP
* - Set the initial PC == Reset_Handler,
* - Set the vector table entries with the exceptions ISR address
* - Configure the clock system
* - Branches to main in the C library (which eventually
* calls main()).
* After Reset the Cortex-M4 processor is in Thread mode,
* priority is Privileged, and the Stack is set to Main.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
.syntax unified
.cpu cortex-m3
.fpu softvfp
.thumb
.global g_pfnVectors
.global Default_Handler
/* start address for the initialization values of the .data section.
defined in linker script */
.word _sidata
/* start address for the .data section. defined in linker script */
.word _sdata
/* end address for the .data section. defined in linker script */
.word _edata
/* start address for the .bss section. defined in linker script */
.word _sbss
/* end address for the .bss section. defined in linker script */
.word _ebss
/* stack used for SystemInit_ExtMemCtl; always internal RAM used */
/**
* @brief This is the code that gets called when the processor first
* starts execution following a reset event. Only the absolutely
* necessary set is performed, after which the application
* supplied main() routine is called.
* @param None
* @retval : None
*/
.section .text.Reset_Handler
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
CopyDataInit:
ldr r3, =_sidata
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopCopyDataInit:
ldr r0, =_sdata
ldr r3, =_edata
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
movs r3, #0
str r3, [r2], #4
LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
/* Call the clock system intitialization function.*/
bl SystemInit
/* Call the application's entry point.*/
bl main
bx lr
.size Reset_Handler, .-Reset_Handler
/**
* @brief This is the code that gets called when the processor receives an
* unexpected interrupt. This simply enters an infinite loop, preserving
* the system state for examination by a debugger.
* @param None
* @retval None
*/
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
/******************************************************************************
*
* The minimal vector table for a Cortex M3. Note that the proper constructs
* must be placed on this to ensure that it ends up at physical address
* 0x0000.0000.
*
*******************************************************************************/
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
.size g_pfnVectors, .-g_pfnVectors
g_pfnVectors:
.word _estack
.word Reset_Handler
.word NMI_Handler
.word HardFault_Handler
.word MemManage_Handler
.word BusFault_Handler
.word UsageFault_Handler
.word 0
.word 0
.word 0
.word 0
.word SVC_Handler
.word DebugMon_Handler
.word 0
.word PendSV_Handler
.word SysTick_Handler
/* External Interrupts */
.word WWDG_IRQHandler /* Window WatchDog */
.word PVD_IRQHandler /* PVD through EXTI Line detection */
.word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */
.word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */
.word FLASH_IRQHandler /* FLASH */
.word RCC_IRQHandler /* RCC */
.word EXTI0_IRQHandler /* EXTI Line0 */
.word EXTI1_IRQHandler /* EXTI Line1 */
.word EXTI2_IRQHandler /* EXTI Line2 */
.word EXTI3_IRQHandler /* EXTI Line3 */
.word EXTI4_IRQHandler /* EXTI Line4 */
.word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */
.word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */
.word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */
.word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */
.word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */
.word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */
.word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */
.word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word EXTI9_5_IRQHandler /* External Line[9:5]s */
.word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */
.word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */
.word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */
.word TIM1_CC_IRQHandler /* TIM1 Capture Compare */
.word TIM2_IRQHandler /* TIM2 */
.word TIM3_IRQHandler /* TIM3 */
.word TIM4_IRQHandler /* TIM4 */
.word I2C1_EV_IRQHandler /* I2C1 Event */
.word I2C1_ER_IRQHandler /* I2C1 Error */
.word I2C2_EV_IRQHandler /* I2C2 Event */
.word I2C2_ER_IRQHandler /* I2C2 Error */
.word SPI1_IRQHandler /* SPI1 */
.word SPI2_IRQHandler /* SPI2 */
.word USART1_IRQHandler /* USART1 */
.word USART2_IRQHandler /* USART2 */
.word 0 /* Reserved */
.word EXTI15_10_IRQHandler /* External Line[15:10]s */
.word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */
.word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */
.word 0 /* Reserved */
.word SDIO_IRQHandler /* SDIO */
.word TIM5_IRQHandler /* TIM5 */
.word SPI3_IRQHandler /* SPI3 */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */
.word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */
.word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */
.word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */
.word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word OTG_FS_IRQHandler /* USB OTG FS */
.word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */
.word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */
.word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */
.word USART6_IRQHandler /* USART6 */
.word I2C3_EV_IRQHandler /* I2C3 event */
.word I2C3_ER_IRQHandler /* I2C3 error */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word FPU_IRQHandler /* FPU */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word SPI4_IRQHandler /* SPI4 */
/*******************************************************************************
*
* Provide weak aliases for each Exception handler to the Default_Handler.
* As they are weak aliases, any function with the same name will override
* this definition.
*
*******************************************************************************/
.weak NMI_Handler
.thumb_set NMI_Handler,Default_Handler
.weak HardFault_Handler
.thumb_set HardFault_Handler,Default_Handler
.weak MemManage_Handler
.thumb_set MemManage_Handler,Default_Handler
.weak BusFault_Handler
.thumb_set BusFault_Handler,Default_Handler
.weak UsageFault_Handler
.thumb_set UsageFault_Handler,Default_Handler
.weak SVC_Handler
.thumb_set SVC_Handler,Default_Handler
.weak DebugMon_Handler
.thumb_set DebugMon_Handler,Default_Handler
.weak PendSV_Handler
.thumb_set PendSV_Handler,Default_Handler
.weak SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler
.weak WWDG_IRQHandler
.thumb_set WWDG_IRQHandler,Default_Handler
.weak PVD_IRQHandler
.thumb_set PVD_IRQHandler,Default_Handler
.weak TAMP_STAMP_IRQHandler
.thumb_set TAMP_STAMP_IRQHandler,Default_Handler
.weak RTC_WKUP_IRQHandler
.thumb_set RTC_WKUP_IRQHandler,Default_Handler
.weak FLASH_IRQHandler
.thumb_set FLASH_IRQHandler,Default_Handler
.weak RCC_IRQHandler
.thumb_set RCC_IRQHandler,Default_Handler
.weak EXTI0_IRQHandler
.thumb_set EXTI0_IRQHandler,Default_Handler
.weak EXTI1_IRQHandler
.thumb_set EXTI1_IRQHandler,Default_Handler
.weak EXTI2_IRQHandler
.thumb_set EXTI2_IRQHandler,Default_Handler
.weak EXTI3_IRQHandler
.thumb_set EXTI3_IRQHandler,Default_Handler
.weak EXTI4_IRQHandler
.thumb_set EXTI4_IRQHandler,Default_Handler
.weak DMA1_Stream0_IRQHandler
.thumb_set DMA1_Stream0_IRQHandler,Default_Handler
.weak DMA1_Stream1_IRQHandler
.thumb_set DMA1_Stream1_IRQHandler,Default_Handler
.weak DMA1_Stream2_IRQHandler
.thumb_set DMA1_Stream2_IRQHandler,Default_Handler
.weak DMA1_Stream3_IRQHandler
.thumb_set DMA1_Stream3_IRQHandler,Default_Handler
.weak DMA1_Stream4_IRQHandler
.thumb_set DMA1_Stream4_IRQHandler,Default_Handler
.weak DMA1_Stream5_IRQHandler
.thumb_set DMA1_Stream5_IRQHandler,Default_Handler
.weak DMA1_Stream6_IRQHandler
.thumb_set DMA1_Stream6_IRQHandler,Default_Handler
.weak ADC_IRQHandler
.thumb_set ADC_IRQHandler,Default_Handler
.weak EXTI9_5_IRQHandler
.thumb_set EXTI9_5_IRQHandler,Default_Handler
.weak TIM1_BRK_TIM9_IRQHandler
.thumb_set TIM1_BRK_TIM9_IRQHandler,Default_Handler
.weak TIM1_UP_TIM10_IRQHandler
.thumb_set TIM1_UP_TIM10_IRQHandler,Default_Handler
.weak TIM1_TRG_COM_TIM11_IRQHandler
.thumb_set TIM1_TRG_COM_TIM11_IRQHandler,Default_Handler
.weak TIM1_CC_IRQHandler
.thumb_set TIM1_CC_IRQHandler,Default_Handler
.weak TIM2_IRQHandler
.thumb_set TIM2_IRQHandler,Default_Handler
.weak TIM3_IRQHandler
.thumb_set TIM3_IRQHandler,Default_Handler
.weak TIM4_IRQHandler
.thumb_set TIM4_IRQHandler,Default_Handler
.weak I2C1_EV_IRQHandler
.thumb_set I2C1_EV_IRQHandler,Default_Handler
.weak I2C1_ER_IRQHandler
.thumb_set I2C1_ER_IRQHandler,Default_Handler
.weak I2C2_EV_IRQHandler
.thumb_set I2C2_EV_IRQHandler,Default_Handler
.weak I2C2_ER_IRQHandler
.thumb_set I2C2_ER_IRQHandler,Default_Handler
.weak SPI1_IRQHandler
.thumb_set SPI1_IRQHandler,Default_Handler
.weak SPI2_IRQHandler
.thumb_set SPI2_IRQHandler,Default_Handler
.weak USART1_IRQHandler
.thumb_set USART1_IRQHandler,Default_Handler
.weak USART2_IRQHandler
.thumb_set USART2_IRQHandler,Default_Handler
.weak EXTI15_10_IRQHandler
.thumb_set EXTI15_10_IRQHandler,Default_Handler
.weak RTC_Alarm_IRQHandler
.thumb_set RTC_Alarm_IRQHandler,Default_Handler
.weak OTG_FS_WKUP_IRQHandler
.thumb_set OTG_FS_WKUP_IRQHandler,Default_Handler
.weak DMA1_Stream7_IRQHandler
.thumb_set DMA1_Stream7_IRQHandler,Default_Handler
.weak SDIO_IRQHandler
.thumb_set SDIO_IRQHandler,Default_Handler
.weak TIM5_IRQHandler
.thumb_set TIM5_IRQHandler,Default_Handler
.weak SPI3_IRQHandler
.thumb_set SPI3_IRQHandler,Default_Handler
.weak DMA2_Stream0_IRQHandler
.thumb_set DMA2_Stream0_IRQHandler,Default_Handler
.weak DMA2_Stream1_IRQHandler
.thumb_set DMA2_Stream1_IRQHandler,Default_Handler
.weak DMA2_Stream2_IRQHandler
.thumb_set DMA2_Stream2_IRQHandler,Default_Handler
.weak DMA2_Stream3_IRQHandler
.thumb_set DMA2_Stream3_IRQHandler,Default_Handler
.weak DMA2_Stream4_IRQHandler
.thumb_set DMA2_Stream4_IRQHandler,Default_Handler
.weak OTG_FS_IRQHandler
.thumb_set OTG_FS_IRQHandler,Default_Handler
.weak DMA2_Stream5_IRQHandler
.thumb_set DMA2_Stream5_IRQHandler,Default_Handler
.weak DMA2_Stream6_IRQHandler
.thumb_set DMA2_Stream6_IRQHandler,Default_Handler
.weak DMA2_Stream7_IRQHandler
.thumb_set DMA2_Stream7_IRQHandler,Default_Handler
.weak USART6_IRQHandler
.thumb_set USART6_IRQHandler,Default_Handler
.weak I2C3_EV_IRQHandler
.thumb_set I2C3_EV_IRQHandler,Default_Handler
.weak I2C3_ER_IRQHandler
.thumb_set I2C3_ER_IRQHandler,Default_Handler
.weak FPU_IRQHandler
.thumb_set FPU_IRQHandler,Default_Handler
.weak SPI4_IRQHandler
.thumb_set SPI4_IRQHandler,Default_Handler
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -100,7 +100,9 @@ LoopFillZerobss:
bcc FillZerobss bcc FillZerobss
/* Call the clock system intitialization function.*/ /* Call the clock system intitialization function.*/
bl SystemInit bl SystemInit
/* Call C++ constructors for static objects */
bl __libc_init_array
/* Call the application's entry point.*/ /* Call the application's entry point.*/
bl main bl main
bx lr bx lr
@@ -1,516 +0,0 @@
/**
******************************************************************************
* @file startup_stm32f40xx.s
* @author MCD Application Team
* @version V1.3.0
* @date 08-November-2013
* @brief STM32F40xxx/41xxx Devices vector table for RIDE7 toolchain.
* Same as startup_stm32f40xx.s and maintained for legacy purpose
* This module performs:
* - Set the initial SP
* - Set the initial PC == Reset_Handler,
* - Set the vector table entries with the exceptions ISR address
* - Configure the clock system and the external SRAM mounted on
* STM324xG-EVAL board to be used as data memory (optional,
* to be enabled by user)
* - Branches to main in the C library (which eventually
* calls main()).
* After Reset the Cortex-M4 processor is in Thread mode,
* priority is Privileged, and the Stack is set to Main.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
.syntax unified
.cpu cortex-m3
.fpu softvfp
.thumb
.global g_pfnVectors
.global Default_Handler
/* start address for the initialization values of the .data section.
defined in linker script */
.word _sidata
/* start address for the .data section. defined in linker script */
.word _sdata
/* end address for the .data section. defined in linker script */
.word _edata
/* start address for the .bss section. defined in linker script */
.word _sbss
/* end address for the .bss section. defined in linker script */
.word _ebss
/* stack used for SystemInit_ExtMemCtl; always internal RAM used */
/**
* @brief This is the code that gets called when the processor first
* starts execution following a reset event. Only the absolutely
* necessary set is performed, after which the application
* supplied main() routine is called.
* @param None
* @retval : None
*/
.section .text.Reset_Handler
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
CopyDataInit:
ldr r3, =_sidata
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopCopyDataInit:
ldr r0, =_sdata
ldr r3, =_edata
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
movs r3, #0
str r3, [r2], #4
LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
/* Call the clock system intitialization function.*/
bl SystemInit
/* Call the application's entry point.*/
bl main
bx lr
.size Reset_Handler, .-Reset_Handler
/**
* @brief This is the code that gets called when the processor receives an
* unexpected interrupt. This simply enters an infinite loop, preserving
* the system state for examination by a debugger.
* @param None
* @retval None
*/
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
/******************************************************************************
*
* The minimal vector table for a Cortex M3. Note that the proper constructs
* must be placed on this to ensure that it ends up at physical address
* 0x0000.0000.
*
*******************************************************************************/
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
.size g_pfnVectors, .-g_pfnVectors
g_pfnVectors:
.word _estack
.word Reset_Handler
.word NMI_Handler
.word HardFault_Handler
.word MemManage_Handler
.word BusFault_Handler
.word UsageFault_Handler
.word 0
.word 0
.word 0
.word 0
.word SVC_Handler
.word DebugMon_Handler
.word 0
.word PendSV_Handler
.word SysTick_Handler
/* External Interrupts */
.word WWDG_IRQHandler /* Window WatchDog */
.word PVD_IRQHandler /* PVD through EXTI Line detection */
.word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */
.word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */
.word FLASH_IRQHandler /* FLASH */
.word RCC_IRQHandler /* RCC */
.word EXTI0_IRQHandler /* EXTI Line0 */
.word EXTI1_IRQHandler /* EXTI Line1 */
.word EXTI2_IRQHandler /* EXTI Line2 */
.word EXTI3_IRQHandler /* EXTI Line3 */
.word EXTI4_IRQHandler /* EXTI Line4 */
.word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */
.word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */
.word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */
.word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */
.word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */
.word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */
.word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */
.word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */
.word CAN1_TX_IRQHandler /* CAN1 TX */
.word CAN1_RX0_IRQHandler /* CAN1 RX0 */
.word CAN1_RX1_IRQHandler /* CAN1 RX1 */
.word CAN1_SCE_IRQHandler /* CAN1 SCE */
.word EXTI9_5_IRQHandler /* External Line[9:5]s */
.word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */
.word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */
.word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */
.word TIM1_CC_IRQHandler /* TIM1 Capture Compare */
.word TIM2_IRQHandler /* TIM2 */
.word TIM3_IRQHandler /* TIM3 */
.word TIM4_IRQHandler /* TIM4 */
.word I2C1_EV_IRQHandler /* I2C1 Event */
.word I2C1_ER_IRQHandler /* I2C1 Error */
.word I2C2_EV_IRQHandler /* I2C2 Event */
.word I2C2_ER_IRQHandler /* I2C2 Error */
.word SPI1_IRQHandler /* SPI1 */
.word SPI2_IRQHandler /* SPI2 */
.word USART1_IRQHandler /* USART1 */
.word USART2_IRQHandler /* USART2 */
.word USART3_IRQHandler /* USART3 */
.word EXTI15_10_IRQHandler /* External Line[15:10]s */
.word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */
.word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */
.word TIM8_BRK_TIM12_IRQHandler /* TIM8 Break and TIM12 */
.word TIM8_UP_TIM13_IRQHandler /* TIM8 Update and TIM13 */
.word TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */
.word TIM8_CC_IRQHandler /* TIM8 Capture Compare */
.word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */
.word FSMC_IRQHandler /* FSMC */
.word SDIO_IRQHandler /* SDIO */
.word TIM5_IRQHandler /* TIM5 */
.word SPI3_IRQHandler /* SPI3 */
.word UART4_IRQHandler /* UART4 */
.word UART5_IRQHandler /* UART5 */
.word TIM6_DAC_IRQHandler /* TIM6 and DAC1&2 underrun errors */
.word TIM7_IRQHandler /* TIM7 */
.word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */
.word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */
.word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */
.word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */
.word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */
.word ETH_IRQHandler /* Ethernet */
.word ETH_WKUP_IRQHandler /* Ethernet Wakeup through EXTI line */
.word CAN2_TX_IRQHandler /* CAN2 TX */
.word CAN2_RX0_IRQHandler /* CAN2 RX0 */
.word CAN2_RX1_IRQHandler /* CAN2 RX1 */
.word CAN2_SCE_IRQHandler /* CAN2 SCE */
.word OTG_FS_IRQHandler /* USB OTG FS */
.word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */
.word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */
.word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */
.word USART6_IRQHandler /* USART6 */
.word I2C3_EV_IRQHandler /* I2C3 event */
.word I2C3_ER_IRQHandler /* I2C3 error */
.word OTG_HS_EP1_OUT_IRQHandler /* USB OTG HS End Point 1 Out */
.word OTG_HS_EP1_IN_IRQHandler /* USB OTG HS End Point 1 In */
.word OTG_HS_WKUP_IRQHandler /* USB OTG HS Wakeup through EXTI */
.word OTG_HS_IRQHandler /* USB OTG HS */
.word DCMI_IRQHandler /* DCMI */
.word CRYP_IRQHandler /* CRYP crypto */
.word HASH_RNG_IRQHandler /* Hash and Rng */
.word FPU_IRQHandler /* FPU */
/*******************************************************************************
*
* Provide weak aliases for each Exception handler to the Default_Handler.
* As they are weak aliases, any function with the same name will override
* this definition.
*
*******************************************************************************/
.weak NMI_Handler
.thumb_set NMI_Handler,Default_Handler
.weak HardFault_Handler
.thumb_set HardFault_Handler,Default_Handler
.weak MemManage_Handler
.thumb_set MemManage_Handler,Default_Handler
.weak BusFault_Handler
.thumb_set BusFault_Handler,Default_Handler
.weak UsageFault_Handler
.thumb_set UsageFault_Handler,Default_Handler
.weak SVC_Handler
.thumb_set SVC_Handler,Default_Handler
.weak DebugMon_Handler
.thumb_set DebugMon_Handler,Default_Handler
.weak PendSV_Handler
.thumb_set PendSV_Handler,Default_Handler
.weak SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler
.weak WWDG_IRQHandler
.thumb_set WWDG_IRQHandler,Default_Handler
.weak PVD_IRQHandler
.thumb_set PVD_IRQHandler,Default_Handler
.weak TAMP_STAMP_IRQHandler
.thumb_set TAMP_STAMP_IRQHandler,Default_Handler
.weak RTC_WKUP_IRQHandler
.thumb_set RTC_WKUP_IRQHandler,Default_Handler
.weak FLASH_IRQHandler
.thumb_set FLASH_IRQHandler,Default_Handler
.weak RCC_IRQHandler
.thumb_set RCC_IRQHandler,Default_Handler
.weak EXTI0_IRQHandler
.thumb_set EXTI0_IRQHandler,Default_Handler
.weak EXTI1_IRQHandler
.thumb_set EXTI1_IRQHandler,Default_Handler
.weak EXTI2_IRQHandler
.thumb_set EXTI2_IRQHandler,Default_Handler
.weak EXTI3_IRQHandler
.thumb_set EXTI3_IRQHandler,Default_Handler
.weak EXTI4_IRQHandler
.thumb_set EXTI4_IRQHandler,Default_Handler
.weak DMA1_Stream0_IRQHandler
.thumb_set DMA1_Stream0_IRQHandler,Default_Handler
.weak DMA1_Stream1_IRQHandler
.thumb_set DMA1_Stream1_IRQHandler,Default_Handler
.weak DMA1_Stream2_IRQHandler
.thumb_set DMA1_Stream2_IRQHandler,Default_Handler
.weak DMA1_Stream3_IRQHandler
.thumb_set DMA1_Stream3_IRQHandler,Default_Handler
.weak DMA1_Stream4_IRQHandler
.thumb_set DMA1_Stream4_IRQHandler,Default_Handler
.weak DMA1_Stream5_IRQHandler
.thumb_set DMA1_Stream5_IRQHandler,Default_Handler
.weak DMA1_Stream6_IRQHandler
.thumb_set DMA1_Stream6_IRQHandler,Default_Handler
.weak ADC_IRQHandler
.thumb_set ADC_IRQHandler,Default_Handler
.weak CAN1_TX_IRQHandler
.thumb_set CAN1_TX_IRQHandler,Default_Handler
.weak CAN1_RX0_IRQHandler
.thumb_set CAN1_RX0_IRQHandler,Default_Handler
.weak CAN1_RX1_IRQHandler
.thumb_set CAN1_RX1_IRQHandler,Default_Handler
.weak CAN1_SCE_IRQHandler
.thumb_set CAN1_SCE_IRQHandler,Default_Handler
.weak EXTI9_5_IRQHandler
.thumb_set EXTI9_5_IRQHandler,Default_Handler
.weak TIM1_BRK_TIM9_IRQHandler
.thumb_set TIM1_BRK_TIM9_IRQHandler,Default_Handler
.weak TIM1_UP_TIM10_IRQHandler
.thumb_set TIM1_UP_TIM10_IRQHandler,Default_Handler
.weak TIM1_TRG_COM_TIM11_IRQHandler
.thumb_set TIM1_TRG_COM_TIM11_IRQHandler,Default_Handler
.weak TIM1_CC_IRQHandler
.thumb_set TIM1_CC_IRQHandler,Default_Handler
.weak TIM2_IRQHandler
.thumb_set TIM2_IRQHandler,Default_Handler
.weak TIM3_IRQHandler
.thumb_set TIM3_IRQHandler,Default_Handler
.weak TIM4_IRQHandler
.thumb_set TIM4_IRQHandler,Default_Handler
.weak I2C1_EV_IRQHandler
.thumb_set I2C1_EV_IRQHandler,Default_Handler
.weak I2C1_ER_IRQHandler
.thumb_set I2C1_ER_IRQHandler,Default_Handler
.weak I2C2_EV_IRQHandler
.thumb_set I2C2_EV_IRQHandler,Default_Handler
.weak I2C2_ER_IRQHandler
.thumb_set I2C2_ER_IRQHandler,Default_Handler
.weak SPI1_IRQHandler
.thumb_set SPI1_IRQHandler,Default_Handler
.weak SPI2_IRQHandler
.thumb_set SPI2_IRQHandler,Default_Handler
.weak USART1_IRQHandler
.thumb_set USART1_IRQHandler,Default_Handler
.weak USART2_IRQHandler
.thumb_set USART2_IRQHandler,Default_Handler
.weak USART3_IRQHandler
.thumb_set USART3_IRQHandler,Default_Handler
.weak EXTI15_10_IRQHandler
.thumb_set EXTI15_10_IRQHandler,Default_Handler
.weak RTC_Alarm_IRQHandler
.thumb_set RTC_Alarm_IRQHandler,Default_Handler
.weak OTG_FS_WKUP_IRQHandler
.thumb_set OTG_FS_WKUP_IRQHandler,Default_Handler
.weak TIM8_BRK_TIM12_IRQHandler
.thumb_set TIM8_BRK_TIM12_IRQHandler,Default_Handler
.weak TIM8_UP_TIM13_IRQHandler
.thumb_set TIM8_UP_TIM13_IRQHandler,Default_Handler
.weak TIM8_TRG_COM_TIM14_IRQHandler
.thumb_set TIM8_TRG_COM_TIM14_IRQHandler,Default_Handler
.weak TIM8_CC_IRQHandler
.thumb_set TIM8_CC_IRQHandler,Default_Handler
.weak DMA1_Stream7_IRQHandler
.thumb_set DMA1_Stream7_IRQHandler,Default_Handler
.weak FSMC_IRQHandler
.thumb_set FSMC_IRQHandler,Default_Handler
.weak SDIO_IRQHandler
.thumb_set SDIO_IRQHandler,Default_Handler
.weak TIM5_IRQHandler
.thumb_set TIM5_IRQHandler,Default_Handler
.weak SPI3_IRQHandler
.thumb_set SPI3_IRQHandler,Default_Handler
.weak UART4_IRQHandler
.thumb_set UART4_IRQHandler,Default_Handler
.weak UART5_IRQHandler
.thumb_set UART5_IRQHandler,Default_Handler
.weak TIM6_DAC_IRQHandler
.thumb_set TIM6_DAC_IRQHandler,Default_Handler
.weak TIM7_IRQHandler
.thumb_set TIM7_IRQHandler,Default_Handler
.weak DMA2_Stream0_IRQHandler
.thumb_set DMA2_Stream0_IRQHandler,Default_Handler
.weak DMA2_Stream1_IRQHandler
.thumb_set DMA2_Stream1_IRQHandler,Default_Handler
.weak DMA2_Stream2_IRQHandler
.thumb_set DMA2_Stream2_IRQHandler,Default_Handler
.weak DMA2_Stream3_IRQHandler
.thumb_set DMA2_Stream3_IRQHandler,Default_Handler
.weak DMA2_Stream4_IRQHandler
.thumb_set DMA2_Stream4_IRQHandler,Default_Handler
.weak ETH_IRQHandler
.thumb_set ETH_IRQHandler,Default_Handler
.weak ETH_WKUP_IRQHandler
.thumb_set ETH_WKUP_IRQHandler,Default_Handler
.weak CAN2_TX_IRQHandler
.thumb_set CAN2_TX_IRQHandler,Default_Handler
.weak CAN2_RX0_IRQHandler
.thumb_set CAN2_RX0_IRQHandler,Default_Handler
.weak CAN2_RX1_IRQHandler
.thumb_set CAN2_RX1_IRQHandler,Default_Handler
.weak CAN2_SCE_IRQHandler
.thumb_set CAN2_SCE_IRQHandler,Default_Handler
.weak OTG_FS_IRQHandler
.thumb_set OTG_FS_IRQHandler,Default_Handler
.weak DMA2_Stream5_IRQHandler
.thumb_set DMA2_Stream5_IRQHandler,Default_Handler
.weak DMA2_Stream6_IRQHandler
.thumb_set DMA2_Stream6_IRQHandler,Default_Handler
.weak DMA2_Stream7_IRQHandler
.thumb_set DMA2_Stream7_IRQHandler,Default_Handler
.weak USART6_IRQHandler
.thumb_set USART6_IRQHandler,Default_Handler
.weak I2C3_EV_IRQHandler
.thumb_set I2C3_EV_IRQHandler,Default_Handler
.weak I2C3_ER_IRQHandler
.thumb_set I2C3_ER_IRQHandler,Default_Handler
.weak OTG_HS_EP1_OUT_IRQHandler
.thumb_set OTG_HS_EP1_OUT_IRQHandler,Default_Handler
.weak OTG_HS_EP1_IN_IRQHandler
.thumb_set OTG_HS_EP1_IN_IRQHandler,Default_Handler
.weak OTG_HS_WKUP_IRQHandler
.thumb_set OTG_HS_WKUP_IRQHandler,Default_Handler
.weak OTG_HS_IRQHandler
.thumb_set OTG_HS_IRQHandler,Default_Handler
.weak DCMI_IRQHandler
.thumb_set DCMI_IRQHandler,Default_Handler
.weak CRYP_IRQHandler
.thumb_set CRYP_IRQHandler,Default_Handler
.weak HASH_RNG_IRQHandler
.thumb_set HASH_RNG_IRQHandler,Default_Handler
.weak FPU_IRQHandler
.thumb_set FPU_IRQHandler,Default_Handler
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -1,551 +0,0 @@
/**
******************************************************************************
* @file startup_stm32f427_437xx.s
* @author MCD Application Team
* @version V1.3.0
* @date 08-November-2013
* @brief STM32F427xx/437xx Devices vector table for RIDE7 toolchain.
* This module performs:
* - Set the initial SP
* - Set the initial PC == Reset_Handler,
* - Set the vector table entries with the exceptions ISR address
* - Configure the clock system and the external SRAM mounted on
* STM324x7I-EVAL board to be used as data memory (optional,
* to be enabled by user)
* - Branches to main in the C library (which eventually
* calls main()).
* After Reset the Cortex-M4 processor is in Thread mode,
* priority is Privileged, and the Stack is set to Main.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
.syntax unified
.cpu cortex-m3
.fpu softvfp
.thumb
.global g_pfnVectors
.global Default_Handler
/* start address for the initialization values of the .data section.
defined in linker script */
.word _sidata
/* start address for the .data section. defined in linker script */
.word _sdata
/* end address for the .data section. defined in linker script */
.word _edata
/* start address for the .bss section. defined in linker script */
.word _sbss
/* end address for the .bss section. defined in linker script */
.word _ebss
/* stack used for SystemInit_ExtMemCtl; always internal RAM used */
/**
* @brief This is the code that gets called when the processor first
* starts execution following a reset event. Only the absolutely
* necessary set is performed, after which the application
* supplied main() routine is called.
* @param None
* @retval : None
*/
.section .text.Reset_Handler
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
CopyDataInit:
ldr r3, =_sidata
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopCopyDataInit:
ldr r0, =_sdata
ldr r3, =_edata
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
movs r3, #0
str r3, [r2], #4
LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
/* Call the clock system intitialization function.*/
bl SystemInit
/* Call the application's entry point.*/
bl main
bx lr
.size Reset_Handler, .-Reset_Handler
/**
* @brief This is the code that gets called when the processor receives an
* unexpected interrupt. This simply enters an infinite loop, preserving
* the system state for examination by a debugger.
* @param None
* @retval None
*/
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
/******************************************************************************
*
* The minimal vector table for a Cortex M3. Note that the proper constructs
* must be placed on this to ensure that it ends up at physical address
* 0x0000.0000.
*
*******************************************************************************/
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
.size g_pfnVectors, .-g_pfnVectors
g_pfnVectors:
.word _estack
.word Reset_Handler
.word NMI_Handler
.word HardFault_Handler
.word MemManage_Handler
.word BusFault_Handler
.word UsageFault_Handler
.word 0
.word 0
.word 0
.word 0
.word SVC_Handler
.word DebugMon_Handler
.word 0
.word PendSV_Handler
.word SysTick_Handler
/* External Interrupts */
.word WWDG_IRQHandler /* Window WatchDog */
.word PVD_IRQHandler /* PVD through EXTI Line detection */
.word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */
.word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */
.word FLASH_IRQHandler /* FLASH */
.word RCC_IRQHandler /* RCC */
.word EXTI0_IRQHandler /* EXTI Line0 */
.word EXTI1_IRQHandler /* EXTI Line1 */
.word EXTI2_IRQHandler /* EXTI Line2 */
.word EXTI3_IRQHandler /* EXTI Line3 */
.word EXTI4_IRQHandler /* EXTI Line4 */
.word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */
.word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */
.word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */
.word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */
.word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */
.word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */
.word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */
.word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */
.word CAN1_TX_IRQHandler /* CAN1 TX */
.word CAN1_RX0_IRQHandler /* CAN1 RX0 */
.word CAN1_RX1_IRQHandler /* CAN1 RX1 */
.word CAN1_SCE_IRQHandler /* CAN1 SCE */
.word EXTI9_5_IRQHandler /* External Line[9:5]s */
.word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */
.word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */
.word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */
.word TIM1_CC_IRQHandler /* TIM1 Capture Compare */
.word TIM2_IRQHandler /* TIM2 */
.word TIM3_IRQHandler /* TIM3 */
.word TIM4_IRQHandler /* TIM4 */
.word I2C1_EV_IRQHandler /* I2C1 Event */
.word I2C1_ER_IRQHandler /* I2C1 Error */
.word I2C2_EV_IRQHandler /* I2C2 Event */
.word I2C2_ER_IRQHandler /* I2C2 Error */
.word SPI1_IRQHandler /* SPI1 */
.word SPI2_IRQHandler /* SPI2 */
.word USART1_IRQHandler /* USART1 */
.word USART2_IRQHandler /* USART2 */
.word USART3_IRQHandler /* USART3 */
.word EXTI15_10_IRQHandler /* External Line[15:10]s */
.word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */
.word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */
.word TIM8_BRK_TIM12_IRQHandler /* TIM8 Break and TIM12 */
.word TIM8_UP_TIM13_IRQHandler /* TIM8 Update and TIM13 */
.word TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */
.word TIM8_CC_IRQHandler /* TIM8 Capture Compare */
.word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */
.word FSMC_IRQHandler /* FSMC */
.word SDIO_IRQHandler /* SDIO */
.word TIM5_IRQHandler /* TIM5 */
.word SPI3_IRQHandler /* SPI3 */
.word UART4_IRQHandler /* UART4 */
.word UART5_IRQHandler /* UART5 */
.word TIM6_DAC_IRQHandler /* TIM6 and DAC1&2 underrun errors */
.word TIM7_IRQHandler /* TIM7 */
.word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */
.word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */
.word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */
.word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */
.word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */
.word ETH_IRQHandler /* Ethernet */
.word ETH_WKUP_IRQHandler /* Ethernet Wakeup through EXTI line */
.word CAN2_TX_IRQHandler /* CAN2 TX */
.word CAN2_RX0_IRQHandler /* CAN2 RX0 */
.word CAN2_RX1_IRQHandler /* CAN2 RX1 */
.word CAN2_SCE_IRQHandler /* CAN2 SCE */
.word OTG_FS_IRQHandler /* USB OTG FS */
.word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */
.word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */
.word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */
.word USART6_IRQHandler /* USART6 */
.word I2C3_EV_IRQHandler /* I2C3 event */
.word I2C3_ER_IRQHandler /* I2C3 error */
.word OTG_HS_EP1_OUT_IRQHandler /* USB OTG HS End Point 1 Out */
.word OTG_HS_EP1_IN_IRQHandler /* USB OTG HS End Point 1 In */
.word OTG_HS_WKUP_IRQHandler /* USB OTG HS Wakeup through EXTI */
.word OTG_HS_IRQHandler /* USB OTG HS */
.word DCMI_IRQHandler /* DCMI */
.word CRYP_IRQHandler /* CRYP crypto */
.word HASH_RNG_IRQHandler /* Hash and Rng */
.word FPU_IRQHandler /* FPU */
.word UART7_IRQHandler /* UART7 */
.word UART8_IRQHandler /* UART8 */
.word SPI4_IRQHandler /* SPI4 */
.word SPI5_IRQHandler /* SPI5 */
.word SPI6_IRQHandler /* SPI6 */
.word SAI1_IRQHandler /* SAI1 */
.word LTDC_IRQHandler /* LTDC */
.word LTDC_ER_IRQHandler /* LTDC error */
.word DMA2D_IRQHandler /* DMA2D */
/*******************************************************************************
*
* Provide weak aliases for each Exception handler to the Default_Handler.
* As they are weak aliases, any function with the same name will override
* this definition.
*
*******************************************************************************/
.weak NMI_Handler
.thumb_set NMI_Handler,Default_Handler
.weak HardFault_Handler
.thumb_set HardFault_Handler,Default_Handler
.weak MemManage_Handler
.thumb_set MemManage_Handler,Default_Handler
.weak BusFault_Handler
.thumb_set BusFault_Handler,Default_Handler
.weak UsageFault_Handler
.thumb_set UsageFault_Handler,Default_Handler
.weak SVC_Handler
.thumb_set SVC_Handler,Default_Handler
.weak DebugMon_Handler
.thumb_set DebugMon_Handler,Default_Handler
.weak PendSV_Handler
.thumb_set PendSV_Handler,Default_Handler
.weak SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler
.weak WWDG_IRQHandler
.thumb_set WWDG_IRQHandler,Default_Handler
.weak PVD_IRQHandler
.thumb_set PVD_IRQHandler,Default_Handler
.weak TAMP_STAMP_IRQHandler
.thumb_set TAMP_STAMP_IRQHandler,Default_Handler
.weak RTC_WKUP_IRQHandler
.thumb_set RTC_WKUP_IRQHandler,Default_Handler
.weak FLASH_IRQHandler
.thumb_set FLASH_IRQHandler,Default_Handler
.weak RCC_IRQHandler
.thumb_set RCC_IRQHandler,Default_Handler
.weak EXTI0_IRQHandler
.thumb_set EXTI0_IRQHandler,Default_Handler
.weak EXTI1_IRQHandler
.thumb_set EXTI1_IRQHandler,Default_Handler
.weak EXTI2_IRQHandler
.thumb_set EXTI2_IRQHandler,Default_Handler
.weak EXTI3_IRQHandler
.thumb_set EXTI3_IRQHandler,Default_Handler
.weak EXTI4_IRQHandler
.thumb_set EXTI4_IRQHandler,Default_Handler
.weak DMA1_Stream0_IRQHandler
.thumb_set DMA1_Stream0_IRQHandler,Default_Handler
.weak DMA1_Stream1_IRQHandler
.thumb_set DMA1_Stream1_IRQHandler,Default_Handler
.weak DMA1_Stream2_IRQHandler
.thumb_set DMA1_Stream2_IRQHandler,Default_Handler
.weak DMA1_Stream3_IRQHandler
.thumb_set DMA1_Stream3_IRQHandler,Default_Handler
.weak DMA1_Stream4_IRQHandler
.thumb_set DMA1_Stream4_IRQHandler,Default_Handler
.weak DMA1_Stream5_IRQHandler
.thumb_set DMA1_Stream5_IRQHandler,Default_Handler
.weak DMA1_Stream6_IRQHandler
.thumb_set DMA1_Stream6_IRQHandler,Default_Handler
.weak ADC_IRQHandler
.thumb_set ADC_IRQHandler,Default_Handler
.weak CAN1_TX_IRQHandler
.thumb_set CAN1_TX_IRQHandler,Default_Handler
.weak CAN1_RX0_IRQHandler
.thumb_set CAN1_RX0_IRQHandler,Default_Handler
.weak CAN1_RX1_IRQHandler
.thumb_set CAN1_RX1_IRQHandler,Default_Handler
.weak CAN1_SCE_IRQHandler
.thumb_set CAN1_SCE_IRQHandler,Default_Handler
.weak EXTI9_5_IRQHandler
.thumb_set EXTI9_5_IRQHandler,Default_Handler
.weak TIM1_BRK_TIM9_IRQHandler
.thumb_set TIM1_BRK_TIM9_IRQHandler,Default_Handler
.weak TIM1_UP_TIM10_IRQHandler
.thumb_set TIM1_UP_TIM10_IRQHandler,Default_Handler
.weak TIM1_TRG_COM_TIM11_IRQHandler
.thumb_set TIM1_TRG_COM_TIM11_IRQHandler,Default_Handler
.weak TIM1_CC_IRQHandler
.thumb_set TIM1_CC_IRQHandler,Default_Handler
.weak TIM2_IRQHandler
.thumb_set TIM2_IRQHandler,Default_Handler
.weak TIM3_IRQHandler
.thumb_set TIM3_IRQHandler,Default_Handler
.weak TIM4_IRQHandler
.thumb_set TIM4_IRQHandler,Default_Handler
.weak I2C1_EV_IRQHandler
.thumb_set I2C1_EV_IRQHandler,Default_Handler
.weak I2C1_ER_IRQHandler
.thumb_set I2C1_ER_IRQHandler,Default_Handler
.weak I2C2_EV_IRQHandler
.thumb_set I2C2_EV_IRQHandler,Default_Handler
.weak I2C2_ER_IRQHandler
.thumb_set I2C2_ER_IRQHandler,Default_Handler
.weak SPI1_IRQHandler
.thumb_set SPI1_IRQHandler,Default_Handler
.weak SPI2_IRQHandler
.thumb_set SPI2_IRQHandler,Default_Handler
.weak USART1_IRQHandler
.thumb_set USART1_IRQHandler,Default_Handler
.weak USART2_IRQHandler
.thumb_set USART2_IRQHandler,Default_Handler
.weak USART3_IRQHandler
.thumb_set USART3_IRQHandler,Default_Handler
.weak EXTI15_10_IRQHandler
.thumb_set EXTI15_10_IRQHandler,Default_Handler
.weak RTC_Alarm_IRQHandler
.thumb_set RTC_Alarm_IRQHandler,Default_Handler
.weak OTG_FS_WKUP_IRQHandler
.thumb_set OTG_FS_WKUP_IRQHandler,Default_Handler
.weak TIM8_BRK_TIM12_IRQHandler
.thumb_set TIM8_BRK_TIM12_IRQHandler,Default_Handler
.weak TIM8_UP_TIM13_IRQHandler
.thumb_set TIM8_UP_TIM13_IRQHandler,Default_Handler
.weak TIM8_TRG_COM_TIM14_IRQHandler
.thumb_set TIM8_TRG_COM_TIM14_IRQHandler,Default_Handler
.weak TIM8_CC_IRQHandler
.thumb_set TIM8_CC_IRQHandler,Default_Handler
.weak DMA1_Stream7_IRQHandler
.thumb_set DMA1_Stream7_IRQHandler,Default_Handler
.weak FSMC_IRQHandler
.thumb_set FSMC_IRQHandler,Default_Handler
.weak SDIO_IRQHandler
.thumb_set SDIO_IRQHandler,Default_Handler
.weak TIM5_IRQHandler
.thumb_set TIM5_IRQHandler,Default_Handler
.weak SPI3_IRQHandler
.thumb_set SPI3_IRQHandler,Default_Handler
.weak UART4_IRQHandler
.thumb_set UART4_IRQHandler,Default_Handler
.weak UART5_IRQHandler
.thumb_set UART5_IRQHandler,Default_Handler
.weak TIM6_DAC_IRQHandler
.thumb_set TIM6_DAC_IRQHandler,Default_Handler
.weak TIM7_IRQHandler
.thumb_set TIM7_IRQHandler,Default_Handler
.weak DMA2_Stream0_IRQHandler
.thumb_set DMA2_Stream0_IRQHandler,Default_Handler
.weak DMA2_Stream1_IRQHandler
.thumb_set DMA2_Stream1_IRQHandler,Default_Handler
.weak DMA2_Stream2_IRQHandler
.thumb_set DMA2_Stream2_IRQHandler,Default_Handler
.weak DMA2_Stream3_IRQHandler
.thumb_set DMA2_Stream3_IRQHandler,Default_Handler
.weak DMA2_Stream4_IRQHandler
.thumb_set DMA2_Stream4_IRQHandler,Default_Handler
.weak ETH_IRQHandler
.thumb_set ETH_IRQHandler,Default_Handler
.weak ETH_WKUP_IRQHandler
.thumb_set ETH_WKUP_IRQHandler,Default_Handler
.weak CAN2_TX_IRQHandler
.thumb_set CAN2_TX_IRQHandler,Default_Handler
.weak CAN2_RX0_IRQHandler
.thumb_set CAN2_RX0_IRQHandler,Default_Handler
.weak CAN2_RX1_IRQHandler
.thumb_set CAN2_RX1_IRQHandler,Default_Handler
.weak CAN2_SCE_IRQHandler
.thumb_set CAN2_SCE_IRQHandler,Default_Handler
.weak OTG_FS_IRQHandler
.thumb_set OTG_FS_IRQHandler,Default_Handler
.weak DMA2_Stream5_IRQHandler
.thumb_set DMA2_Stream5_IRQHandler,Default_Handler
.weak DMA2_Stream6_IRQHandler
.thumb_set DMA2_Stream6_IRQHandler,Default_Handler
.weak DMA2_Stream7_IRQHandler
.thumb_set DMA2_Stream7_IRQHandler,Default_Handler
.weak USART6_IRQHandler
.thumb_set USART6_IRQHandler,Default_Handler
.weak I2C3_EV_IRQHandler
.thumb_set I2C3_EV_IRQHandler,Default_Handler
.weak I2C3_ER_IRQHandler
.thumb_set I2C3_ER_IRQHandler,Default_Handler
.weak OTG_HS_EP1_OUT_IRQHandler
.thumb_set OTG_HS_EP1_OUT_IRQHandler,Default_Handler
.weak OTG_HS_EP1_IN_IRQHandler
.thumb_set OTG_HS_EP1_IN_IRQHandler,Default_Handler
.weak OTG_HS_WKUP_IRQHandler
.thumb_set OTG_HS_WKUP_IRQHandler,Default_Handler
.weak OTG_HS_IRQHandler
.thumb_set OTG_HS_IRQHandler,Default_Handler
.weak DCMI_IRQHandler
.thumb_set DCMI_IRQHandler,Default_Handler
.weak CRYP_IRQHandler
.thumb_set CRYP_IRQHandler,Default_Handler
.weak HASH_RNG_IRQHandler
.thumb_set HASH_RNG_IRQHandler,Default_Handler
.weak FPU_IRQHandler
.thumb_set FPU_IRQHandler,Default_Handler
.weak UART7_IRQHandler
.thumb_set UART7_IRQHandler,Default_Handler
.weak UART8_IRQHandler
.thumb_set UART8_IRQHandler,Default_Handler
.weak SPI4_IRQHandler
.thumb_set SPI4_IRQHandler,Default_Handler
.weak SPI5_IRQHandler
.thumb_set SPI5_IRQHandler,Default_Handler
.weak SPI6_IRQHandler
.thumb_set SPI6_IRQHandler,Default_Handler
.weak SAI1_IRQHandler
.thumb_set SAI1_IRQHandler,Default_Handler
.weak LTDC_IRQHandler
.thumb_set LTDC_IRQHandler,Default_Handler
.weak LTDC_ER_IRQHandler
.thumb_set LTDC_ER_IRQHandler,Default_Handler
.weak DMA2D_IRQHandler
.thumb_set DMA2D_IRQHandler,Default_Handler
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -1,552 +0,0 @@
/**
******************************************************************************
* @file startup_stm32f427x.s
* @author MCD Application Team
* @version V1.3.0
* @date 08-November-2013
* @brief STM32F427xx/437xx Devices vector table for RIDE7 toolchain.
* Same as startup_stm32f427_437xx.s and maintained for legacy purpose
* This module performs:
* - Set the initial SP
* - Set the initial PC == Reset_Handler,
* - Set the vector table entries with the exceptions ISR address
* - Configure the clock system and the external SRAM mounted on
* STM324x7I-EVAL board to be used as data memory
* (optional, to be enabled by user)
* - Branches to main in the C library (which eventually
* calls main()).
* After Reset the Cortex-M4 processor is in Thread mode,
* priority is Privileged, and the Stack is set to Main.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
.syntax unified
.cpu cortex-m3
.fpu softvfp
.thumb
.global g_pfnVectors
.global Default_Handler
/* start address for the initialization values of the .data section.
defined in linker script */
.word _sidata
/* start address for the .data section. defined in linker script */
.word _sdata
/* end address for the .data section. defined in linker script */
.word _edata
/* start address for the .bss section. defined in linker script */
.word _sbss
/* end address for the .bss section. defined in linker script */
.word _ebss
/* stack used for SystemInit_ExtMemCtl; always internal RAM used */
/**
* @brief This is the code that gets called when the processor first
* starts execution following a reset event. Only the absolutely
* necessary set is performed, after which the application
* supplied main() routine is called.
* @param None
* @retval : None
*/
.section .text.Reset_Handler
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
CopyDataInit:
ldr r3, =_sidata
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopCopyDataInit:
ldr r0, =_sdata
ldr r3, =_edata
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
movs r3, #0
str r3, [r2], #4
LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
/* Call the clock system intitialization function.*/
bl SystemInit
/* Call the application's entry point.*/
bl main
bx lr
.size Reset_Handler, .-Reset_Handler
/**
* @brief This is the code that gets called when the processor receives an
* unexpected interrupt. This simply enters an infinite loop, preserving
* the system state for examination by a debugger.
* @param None
* @retval None
*/
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
/******************************************************************************
*
* The minimal vector table for a Cortex M3. Note that the proper constructs
* must be placed on this to ensure that it ends up at physical address
* 0x0000.0000.
*
*******************************************************************************/
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
.size g_pfnVectors, .-g_pfnVectors
g_pfnVectors:
.word _estack
.word Reset_Handler
.word NMI_Handler
.word HardFault_Handler
.word MemManage_Handler
.word BusFault_Handler
.word UsageFault_Handler
.word 0
.word 0
.word 0
.word 0
.word SVC_Handler
.word DebugMon_Handler
.word 0
.word PendSV_Handler
.word SysTick_Handler
/* External Interrupts */
.word WWDG_IRQHandler /* Window WatchDog */
.word PVD_IRQHandler /* PVD through EXTI Line detection */
.word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */
.word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */
.word FLASH_IRQHandler /* FLASH */
.word RCC_IRQHandler /* RCC */
.word EXTI0_IRQHandler /* EXTI Line0 */
.word EXTI1_IRQHandler /* EXTI Line1 */
.word EXTI2_IRQHandler /* EXTI Line2 */
.word EXTI3_IRQHandler /* EXTI Line3 */
.word EXTI4_IRQHandler /* EXTI Line4 */
.word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */
.word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */
.word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */
.word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */
.word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */
.word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */
.word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */
.word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */
.word CAN1_TX_IRQHandler /* CAN1 TX */
.word CAN1_RX0_IRQHandler /* CAN1 RX0 */
.word CAN1_RX1_IRQHandler /* CAN1 RX1 */
.word CAN1_SCE_IRQHandler /* CAN1 SCE */
.word EXTI9_5_IRQHandler /* External Line[9:5]s */
.word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */
.word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */
.word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */
.word TIM1_CC_IRQHandler /* TIM1 Capture Compare */
.word TIM2_IRQHandler /* TIM2 */
.word TIM3_IRQHandler /* TIM3 */
.word TIM4_IRQHandler /* TIM4 */
.word I2C1_EV_IRQHandler /* I2C1 Event */
.word I2C1_ER_IRQHandler /* I2C1 Error */
.word I2C2_EV_IRQHandler /* I2C2 Event */
.word I2C2_ER_IRQHandler /* I2C2 Error */
.word SPI1_IRQHandler /* SPI1 */
.word SPI2_IRQHandler /* SPI2 */
.word USART1_IRQHandler /* USART1 */
.word USART2_IRQHandler /* USART2 */
.word USART3_IRQHandler /* USART3 */
.word EXTI15_10_IRQHandler /* External Line[15:10]s */
.word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */
.word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */
.word TIM8_BRK_TIM12_IRQHandler /* TIM8 Break and TIM12 */
.word TIM8_UP_TIM13_IRQHandler /* TIM8 Update and TIM13 */
.word TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */
.word TIM8_CC_IRQHandler /* TIM8 Capture Compare */
.word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */
.word FSMC_IRQHandler /* FSMC */
.word SDIO_IRQHandler /* SDIO */
.word TIM5_IRQHandler /* TIM5 */
.word SPI3_IRQHandler /* SPI3 */
.word UART4_IRQHandler /* UART4 */
.word UART5_IRQHandler /* UART5 */
.word TIM6_DAC_IRQHandler /* TIM6 and DAC1&2 underrun errors */
.word TIM7_IRQHandler /* TIM7 */
.word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */
.word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */
.word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */
.word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */
.word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */
.word ETH_IRQHandler /* Ethernet */
.word ETH_WKUP_IRQHandler /* Ethernet Wakeup through EXTI line */
.word CAN2_TX_IRQHandler /* CAN2 TX */
.word CAN2_RX0_IRQHandler /* CAN2 RX0 */
.word CAN2_RX1_IRQHandler /* CAN2 RX1 */
.word CAN2_SCE_IRQHandler /* CAN2 SCE */
.word OTG_FS_IRQHandler /* USB OTG FS */
.word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */
.word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */
.word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */
.word USART6_IRQHandler /* USART6 */
.word I2C3_EV_IRQHandler /* I2C3 event */
.word I2C3_ER_IRQHandler /* I2C3 error */
.word OTG_HS_EP1_OUT_IRQHandler /* USB OTG HS End Point 1 Out */
.word OTG_HS_EP1_IN_IRQHandler /* USB OTG HS End Point 1 In */
.word OTG_HS_WKUP_IRQHandler /* USB OTG HS Wakeup through EXTI */
.word OTG_HS_IRQHandler /* USB OTG HS */
.word DCMI_IRQHandler /* DCMI */
.word CRYP_IRQHandler /* CRYP crypto */
.word HASH_RNG_IRQHandler /* Hash and Rng */
.word FPU_IRQHandler /* FPU */
.word UART7_IRQHandler /* UART7 */
.word UART8_IRQHandler /* UART8 */
.word SPI4_IRQHandler /* SPI4 */
.word SPI5_IRQHandler /* SPI5 */
.word SPI6_IRQHandler /* SPI6 */
.word SAI1_IRQHandler /* SAI1 */
.word LTDC_IRQHandler /* LTDC */
.word LTDC_ER_IRQHandler /* LTDC error */
.word DMA2D_IRQHandler /* DMA2D */
/*******************************************************************************
*
* Provide weak aliases for each Exception handler to the Default_Handler.
* As they are weak aliases, any function with the same name will override
* this definition.
*
*******************************************************************************/
.weak NMI_Handler
.thumb_set NMI_Handler,Default_Handler
.weak HardFault_Handler
.thumb_set HardFault_Handler,Default_Handler
.weak MemManage_Handler
.thumb_set MemManage_Handler,Default_Handler
.weak BusFault_Handler
.thumb_set BusFault_Handler,Default_Handler
.weak UsageFault_Handler
.thumb_set UsageFault_Handler,Default_Handler
.weak SVC_Handler
.thumb_set SVC_Handler,Default_Handler
.weak DebugMon_Handler
.thumb_set DebugMon_Handler,Default_Handler
.weak PendSV_Handler
.thumb_set PendSV_Handler,Default_Handler
.weak SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler
.weak WWDG_IRQHandler
.thumb_set WWDG_IRQHandler,Default_Handler
.weak PVD_IRQHandler
.thumb_set PVD_IRQHandler,Default_Handler
.weak TAMP_STAMP_IRQHandler
.thumb_set TAMP_STAMP_IRQHandler,Default_Handler
.weak RTC_WKUP_IRQHandler
.thumb_set RTC_WKUP_IRQHandler,Default_Handler
.weak FLASH_IRQHandler
.thumb_set FLASH_IRQHandler,Default_Handler
.weak RCC_IRQHandler
.thumb_set RCC_IRQHandler,Default_Handler
.weak EXTI0_IRQHandler
.thumb_set EXTI0_IRQHandler,Default_Handler
.weak EXTI1_IRQHandler
.thumb_set EXTI1_IRQHandler,Default_Handler
.weak EXTI2_IRQHandler
.thumb_set EXTI2_IRQHandler,Default_Handler
.weak EXTI3_IRQHandler
.thumb_set EXTI3_IRQHandler,Default_Handler
.weak EXTI4_IRQHandler
.thumb_set EXTI4_IRQHandler,Default_Handler
.weak DMA1_Stream0_IRQHandler
.thumb_set DMA1_Stream0_IRQHandler,Default_Handler
.weak DMA1_Stream1_IRQHandler
.thumb_set DMA1_Stream1_IRQHandler,Default_Handler
.weak DMA1_Stream2_IRQHandler
.thumb_set DMA1_Stream2_IRQHandler,Default_Handler
.weak DMA1_Stream3_IRQHandler
.thumb_set DMA1_Stream3_IRQHandler,Default_Handler
.weak DMA1_Stream4_IRQHandler
.thumb_set DMA1_Stream4_IRQHandler,Default_Handler
.weak DMA1_Stream5_IRQHandler
.thumb_set DMA1_Stream5_IRQHandler,Default_Handler
.weak DMA1_Stream6_IRQHandler
.thumb_set DMA1_Stream6_IRQHandler,Default_Handler
.weak ADC_IRQHandler
.thumb_set ADC_IRQHandler,Default_Handler
.weak CAN1_TX_IRQHandler
.thumb_set CAN1_TX_IRQHandler,Default_Handler
.weak CAN1_RX0_IRQHandler
.thumb_set CAN1_RX0_IRQHandler,Default_Handler
.weak CAN1_RX1_IRQHandler
.thumb_set CAN1_RX1_IRQHandler,Default_Handler
.weak CAN1_SCE_IRQHandler
.thumb_set CAN1_SCE_IRQHandler,Default_Handler
.weak EXTI9_5_IRQHandler
.thumb_set EXTI9_5_IRQHandler,Default_Handler
.weak TIM1_BRK_TIM9_IRQHandler
.thumb_set TIM1_BRK_TIM9_IRQHandler,Default_Handler
.weak TIM1_UP_TIM10_IRQHandler
.thumb_set TIM1_UP_TIM10_IRQHandler,Default_Handler
.weak TIM1_TRG_COM_TIM11_IRQHandler
.thumb_set TIM1_TRG_COM_TIM11_IRQHandler,Default_Handler
.weak TIM1_CC_IRQHandler
.thumb_set TIM1_CC_IRQHandler,Default_Handler
.weak TIM2_IRQHandler
.thumb_set TIM2_IRQHandler,Default_Handler
.weak TIM3_IRQHandler
.thumb_set TIM3_IRQHandler,Default_Handler
.weak TIM4_IRQHandler
.thumb_set TIM4_IRQHandler,Default_Handler
.weak I2C1_EV_IRQHandler
.thumb_set I2C1_EV_IRQHandler,Default_Handler
.weak I2C1_ER_IRQHandler
.thumb_set I2C1_ER_IRQHandler,Default_Handler
.weak I2C2_EV_IRQHandler
.thumb_set I2C2_EV_IRQHandler,Default_Handler
.weak I2C2_ER_IRQHandler
.thumb_set I2C2_ER_IRQHandler,Default_Handler
.weak SPI1_IRQHandler
.thumb_set SPI1_IRQHandler,Default_Handler
.weak SPI2_IRQHandler
.thumb_set SPI2_IRQHandler,Default_Handler
.weak USART1_IRQHandler
.thumb_set USART1_IRQHandler,Default_Handler
.weak USART2_IRQHandler
.thumb_set USART2_IRQHandler,Default_Handler
.weak USART3_IRQHandler
.thumb_set USART3_IRQHandler,Default_Handler
.weak EXTI15_10_IRQHandler
.thumb_set EXTI15_10_IRQHandler,Default_Handler
.weak RTC_Alarm_IRQHandler
.thumb_set RTC_Alarm_IRQHandler,Default_Handler
.weak OTG_FS_WKUP_IRQHandler
.thumb_set OTG_FS_WKUP_IRQHandler,Default_Handler
.weak TIM8_BRK_TIM12_IRQHandler
.thumb_set TIM8_BRK_TIM12_IRQHandler,Default_Handler
.weak TIM8_UP_TIM13_IRQHandler
.thumb_set TIM8_UP_TIM13_IRQHandler,Default_Handler
.weak TIM8_TRG_COM_TIM14_IRQHandler
.thumb_set TIM8_TRG_COM_TIM14_IRQHandler,Default_Handler
.weak TIM8_CC_IRQHandler
.thumb_set TIM8_CC_IRQHandler,Default_Handler
.weak DMA1_Stream7_IRQHandler
.thumb_set DMA1_Stream7_IRQHandler,Default_Handler
.weak FSMC_IRQHandler
.thumb_set FSMC_IRQHandler,Default_Handler
.weak SDIO_IRQHandler
.thumb_set SDIO_IRQHandler,Default_Handler
.weak TIM5_IRQHandler
.thumb_set TIM5_IRQHandler,Default_Handler
.weak SPI3_IRQHandler
.thumb_set SPI3_IRQHandler,Default_Handler
.weak UART4_IRQHandler
.thumb_set UART4_IRQHandler,Default_Handler
.weak UART5_IRQHandler
.thumb_set UART5_IRQHandler,Default_Handler
.weak TIM6_DAC_IRQHandler
.thumb_set TIM6_DAC_IRQHandler,Default_Handler
.weak TIM7_IRQHandler
.thumb_set TIM7_IRQHandler,Default_Handler
.weak DMA2_Stream0_IRQHandler
.thumb_set DMA2_Stream0_IRQHandler,Default_Handler
.weak DMA2_Stream1_IRQHandler
.thumb_set DMA2_Stream1_IRQHandler,Default_Handler
.weak DMA2_Stream2_IRQHandler
.thumb_set DMA2_Stream2_IRQHandler,Default_Handler
.weak DMA2_Stream3_IRQHandler
.thumb_set DMA2_Stream3_IRQHandler,Default_Handler
.weak DMA2_Stream4_IRQHandler
.thumb_set DMA2_Stream4_IRQHandler,Default_Handler
.weak ETH_IRQHandler
.thumb_set ETH_IRQHandler,Default_Handler
.weak ETH_WKUP_IRQHandler
.thumb_set ETH_WKUP_IRQHandler,Default_Handler
.weak CAN2_TX_IRQHandler
.thumb_set CAN2_TX_IRQHandler,Default_Handler
.weak CAN2_RX0_IRQHandler
.thumb_set CAN2_RX0_IRQHandler,Default_Handler
.weak CAN2_RX1_IRQHandler
.thumb_set CAN2_RX1_IRQHandler,Default_Handler
.weak CAN2_SCE_IRQHandler
.thumb_set CAN2_SCE_IRQHandler,Default_Handler
.weak OTG_FS_IRQHandler
.thumb_set OTG_FS_IRQHandler,Default_Handler
.weak DMA2_Stream5_IRQHandler
.thumb_set DMA2_Stream5_IRQHandler,Default_Handler
.weak DMA2_Stream6_IRQHandler
.thumb_set DMA2_Stream6_IRQHandler,Default_Handler
.weak DMA2_Stream7_IRQHandler
.thumb_set DMA2_Stream7_IRQHandler,Default_Handler
.weak USART6_IRQHandler
.thumb_set USART6_IRQHandler,Default_Handler
.weak I2C3_EV_IRQHandler
.thumb_set I2C3_EV_IRQHandler,Default_Handler
.weak I2C3_ER_IRQHandler
.thumb_set I2C3_ER_IRQHandler,Default_Handler
.weak OTG_HS_EP1_OUT_IRQHandler
.thumb_set OTG_HS_EP1_OUT_IRQHandler,Default_Handler
.weak OTG_HS_EP1_IN_IRQHandler
.thumb_set OTG_HS_EP1_IN_IRQHandler,Default_Handler
.weak OTG_HS_WKUP_IRQHandler
.thumb_set OTG_HS_WKUP_IRQHandler,Default_Handler
.weak OTG_HS_IRQHandler
.thumb_set OTG_HS_IRQHandler,Default_Handler
.weak DCMI_IRQHandler
.thumb_set DCMI_IRQHandler,Default_Handler
.weak CRYP_IRQHandler
.thumb_set CRYP_IRQHandler,Default_Handler
.weak HASH_RNG_IRQHandler
.thumb_set HASH_RNG_IRQHandler,Default_Handler
.weak FPU_IRQHandler
.thumb_set FPU_IRQHandler,Default_Handler
.weak UART7_IRQHandler
.thumb_set UART7_IRQHandler,Default_Handler
.weak UART8_IRQHandler
.thumb_set UART8_IRQHandler,Default_Handler
.weak SPI4_IRQHandler
.thumb_set SPI4_IRQHandler,Default_Handler
.weak SPI5_IRQHandler
.thumb_set SPI5_IRQHandler,Default_Handler
.weak SPI6_IRQHandler
.thumb_set SPI6_IRQHandler,Default_Handler
.weak SAI1_IRQHandler
.thumb_set SAI1_IRQHandler,Default_Handler
.weak LTDC_IRQHandler
.thumb_set LTDC_IRQHandler,Default_Handler
.weak LTDC_ER_IRQHandler
.thumb_set LTDC_ER_IRQHandler,Default_Handler
.weak DMA2D_IRQHandler
.thumb_set DMA2D_IRQHandler,Default_Handler
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -1,551 +0,0 @@
/**
******************************************************************************
* @file startup_stm32f429_439xx.s
* @author MCD Application Team
* @version V1.3.0
* @date 08-November-2013
* @brief STM32F429xx/439xx Devices vector table for RIDE7 toolchain.
* This module performs:
* - Set the initial SP
* - Set the initial PC == Reset_Handler,
* - Set the vector table entries with the exceptions ISR address
* - Configure the clock system and the external SRAM mounted on
* STM324x9I-EVAL board to be used as data memory (optional,
* to be enabled by user)
* - Branches to main in the C library (which eventually
* calls main()).
* After Reset the Cortex-M4 processor is in Thread mode,
* priority is Privileged, and the Stack is set to Main.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
.syntax unified
.cpu cortex-m3
.fpu softvfp
.thumb
.global g_pfnVectors
.global Default_Handler
/* start address for the initialization values of the .data section.
defined in linker script */
.word _sidata
/* start address for the .data section. defined in linker script */
.word _sdata
/* end address for the .data section. defined in linker script */
.word _edata
/* start address for the .bss section. defined in linker script */
.word _sbss
/* end address for the .bss section. defined in linker script */
.word _ebss
/* stack used for SystemInit_ExtMemCtl; always internal RAM used */
/**
* @brief This is the code that gets called when the processor first
* starts execution following a reset event. Only the absolutely
* necessary set is performed, after which the application
* supplied main() routine is called.
* @param None
* @retval : None
*/
.section .text.Reset_Handler
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
CopyDataInit:
ldr r3, =_sidata
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopCopyDataInit:
ldr r0, =_sdata
ldr r3, =_edata
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
movs r3, #0
str r3, [r2], #4
LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
/* Call the clock system intitialization function.*/
bl SystemInit
/* Call the application's entry point.*/
bl main
bx lr
.size Reset_Handler, .-Reset_Handler
/**
* @brief This is the code that gets called when the processor receives an
* unexpected interrupt. This simply enters an infinite loop, preserving
* the system state for examination by a debugger.
* @param None
* @retval None
*/
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
/******************************************************************************
*
* The minimal vector table for a Cortex M3. Note that the proper constructs
* must be placed on this to ensure that it ends up at physical address
* 0x0000.0000.
*
*******************************************************************************/
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
.size g_pfnVectors, .-g_pfnVectors
g_pfnVectors:
.word _estack
.word Reset_Handler
.word NMI_Handler
.word HardFault_Handler
.word MemManage_Handler
.word BusFault_Handler
.word UsageFault_Handler
.word 0
.word 0
.word 0
.word 0
.word SVC_Handler
.word DebugMon_Handler
.word 0
.word PendSV_Handler
.word SysTick_Handler
/* External Interrupts */
.word WWDG_IRQHandler /* Window WatchDog */
.word PVD_IRQHandler /* PVD through EXTI Line detection */
.word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */
.word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */
.word FLASH_IRQHandler /* FLASH */
.word RCC_IRQHandler /* RCC */
.word EXTI0_IRQHandler /* EXTI Line0 */
.word EXTI1_IRQHandler /* EXTI Line1 */
.word EXTI2_IRQHandler /* EXTI Line2 */
.word EXTI3_IRQHandler /* EXTI Line3 */
.word EXTI4_IRQHandler /* EXTI Line4 */
.word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */
.word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */
.word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */
.word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */
.word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */
.word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */
.word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */
.word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */
.word CAN1_TX_IRQHandler /* CAN1 TX */
.word CAN1_RX0_IRQHandler /* CAN1 RX0 */
.word CAN1_RX1_IRQHandler /* CAN1 RX1 */
.word CAN1_SCE_IRQHandler /* CAN1 SCE */
.word EXTI9_5_IRQHandler /* External Line[9:5]s */
.word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */
.word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */
.word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */
.word TIM1_CC_IRQHandler /* TIM1 Capture Compare */
.word TIM2_IRQHandler /* TIM2 */
.word TIM3_IRQHandler /* TIM3 */
.word TIM4_IRQHandler /* TIM4 */
.word I2C1_EV_IRQHandler /* I2C1 Event */
.word I2C1_ER_IRQHandler /* I2C1 Error */
.word I2C2_EV_IRQHandler /* I2C2 Event */
.word I2C2_ER_IRQHandler /* I2C2 Error */
.word SPI1_IRQHandler /* SPI1 */
.word SPI2_IRQHandler /* SPI2 */
.word USART1_IRQHandler /* USART1 */
.word USART2_IRQHandler /* USART2 */
.word USART3_IRQHandler /* USART3 */
.word EXTI15_10_IRQHandler /* External Line[15:10]s */
.word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */
.word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */
.word TIM8_BRK_TIM12_IRQHandler /* TIM8 Break and TIM12 */
.word TIM8_UP_TIM13_IRQHandler /* TIM8 Update and TIM13 */
.word TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */
.word TIM8_CC_IRQHandler /* TIM8 Capture Compare */
.word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */
.word FSMC_IRQHandler /* FSMC */
.word SDIO_IRQHandler /* SDIO */
.word TIM5_IRQHandler /* TIM5 */
.word SPI3_IRQHandler /* SPI3 */
.word UART4_IRQHandler /* UART4 */
.word UART5_IRQHandler /* UART5 */
.word TIM6_DAC_IRQHandler /* TIM6 and DAC1&2 underrun errors */
.word TIM7_IRQHandler /* TIM7 */
.word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */
.word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */
.word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */
.word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */
.word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */
.word ETH_IRQHandler /* Ethernet */
.word ETH_WKUP_IRQHandler /* Ethernet Wakeup through EXTI line */
.word CAN2_TX_IRQHandler /* CAN2 TX */
.word CAN2_RX0_IRQHandler /* CAN2 RX0 */
.word CAN2_RX1_IRQHandler /* CAN2 RX1 */
.word CAN2_SCE_IRQHandler /* CAN2 SCE */
.word OTG_FS_IRQHandler /* USB OTG FS */
.word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */
.word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */
.word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */
.word USART6_IRQHandler /* USART6 */
.word I2C3_EV_IRQHandler /* I2C3 event */
.word I2C3_ER_IRQHandler /* I2C3 error */
.word OTG_HS_EP1_OUT_IRQHandler /* USB OTG HS End Point 1 Out */
.word OTG_HS_EP1_IN_IRQHandler /* USB OTG HS End Point 1 In */
.word OTG_HS_WKUP_IRQHandler /* USB OTG HS Wakeup through EXTI */
.word OTG_HS_IRQHandler /* USB OTG HS */
.word DCMI_IRQHandler /* DCMI */
.word CRYP_IRQHandler /* CRYP crypto */
.word HASH_RNG_IRQHandler /* Hash and Rng */
.word FPU_IRQHandler /* FPU */
.word UART7_IRQHandler /* UART7 */
.word UART8_IRQHandler /* UART8 */
.word SPI4_IRQHandler /* SPI4 */
.word SPI5_IRQHandler /* SPI5 */
.word SPI6_IRQHandler /* SPI6 */
.word SAI1_IRQHandler /* SAI1 */
.word LTDC_IRQHandler /* LTDC */
.word LTDC_ER_IRQHandler /* LTDC error */
.word DMA2D_IRQHandler /* DMA2D */
/*******************************************************************************
*
* Provide weak aliases for each Exception handler to the Default_Handler.
* As they are weak aliases, any function with the same name will override
* this definition.
*
*******************************************************************************/
.weak NMI_Handler
.thumb_set NMI_Handler,Default_Handler
.weak HardFault_Handler
.thumb_set HardFault_Handler,Default_Handler
.weak MemManage_Handler
.thumb_set MemManage_Handler,Default_Handler
.weak BusFault_Handler
.thumb_set BusFault_Handler,Default_Handler
.weak UsageFault_Handler
.thumb_set UsageFault_Handler,Default_Handler
.weak SVC_Handler
.thumb_set SVC_Handler,Default_Handler
.weak DebugMon_Handler
.thumb_set DebugMon_Handler,Default_Handler
.weak PendSV_Handler
.thumb_set PendSV_Handler,Default_Handler
.weak SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler
.weak WWDG_IRQHandler
.thumb_set WWDG_IRQHandler,Default_Handler
.weak PVD_IRQHandler
.thumb_set PVD_IRQHandler,Default_Handler
.weak TAMP_STAMP_IRQHandler
.thumb_set TAMP_STAMP_IRQHandler,Default_Handler
.weak RTC_WKUP_IRQHandler
.thumb_set RTC_WKUP_IRQHandler,Default_Handler
.weak FLASH_IRQHandler
.thumb_set FLASH_IRQHandler,Default_Handler
.weak RCC_IRQHandler
.thumb_set RCC_IRQHandler,Default_Handler
.weak EXTI0_IRQHandler
.thumb_set EXTI0_IRQHandler,Default_Handler
.weak EXTI1_IRQHandler
.thumb_set EXTI1_IRQHandler,Default_Handler
.weak EXTI2_IRQHandler
.thumb_set EXTI2_IRQHandler,Default_Handler
.weak EXTI3_IRQHandler
.thumb_set EXTI3_IRQHandler,Default_Handler
.weak EXTI4_IRQHandler
.thumb_set EXTI4_IRQHandler,Default_Handler
.weak DMA1_Stream0_IRQHandler
.thumb_set DMA1_Stream0_IRQHandler,Default_Handler
.weak DMA1_Stream1_IRQHandler
.thumb_set DMA1_Stream1_IRQHandler,Default_Handler
.weak DMA1_Stream2_IRQHandler
.thumb_set DMA1_Stream2_IRQHandler,Default_Handler
.weak DMA1_Stream3_IRQHandler
.thumb_set DMA1_Stream3_IRQHandler,Default_Handler
.weak DMA1_Stream4_IRQHandler
.thumb_set DMA1_Stream4_IRQHandler,Default_Handler
.weak DMA1_Stream5_IRQHandler
.thumb_set DMA1_Stream5_IRQHandler,Default_Handler
.weak DMA1_Stream6_IRQHandler
.thumb_set DMA1_Stream6_IRQHandler,Default_Handler
.weak ADC_IRQHandler
.thumb_set ADC_IRQHandler,Default_Handler
.weak CAN1_TX_IRQHandler
.thumb_set CAN1_TX_IRQHandler,Default_Handler
.weak CAN1_RX0_IRQHandler
.thumb_set CAN1_RX0_IRQHandler,Default_Handler
.weak CAN1_RX1_IRQHandler
.thumb_set CAN1_RX1_IRQHandler,Default_Handler
.weak CAN1_SCE_IRQHandler
.thumb_set CAN1_SCE_IRQHandler,Default_Handler
.weak EXTI9_5_IRQHandler
.thumb_set EXTI9_5_IRQHandler,Default_Handler
.weak TIM1_BRK_TIM9_IRQHandler
.thumb_set TIM1_BRK_TIM9_IRQHandler,Default_Handler
.weak TIM1_UP_TIM10_IRQHandler
.thumb_set TIM1_UP_TIM10_IRQHandler,Default_Handler
.weak TIM1_TRG_COM_TIM11_IRQHandler
.thumb_set TIM1_TRG_COM_TIM11_IRQHandler,Default_Handler
.weak TIM1_CC_IRQHandler
.thumb_set TIM1_CC_IRQHandler,Default_Handler
.weak TIM2_IRQHandler
.thumb_set TIM2_IRQHandler,Default_Handler
.weak TIM3_IRQHandler
.thumb_set TIM3_IRQHandler,Default_Handler
.weak TIM4_IRQHandler
.thumb_set TIM4_IRQHandler,Default_Handler
.weak I2C1_EV_IRQHandler
.thumb_set I2C1_EV_IRQHandler,Default_Handler
.weak I2C1_ER_IRQHandler
.thumb_set I2C1_ER_IRQHandler,Default_Handler
.weak I2C2_EV_IRQHandler
.thumb_set I2C2_EV_IRQHandler,Default_Handler
.weak I2C2_ER_IRQHandler
.thumb_set I2C2_ER_IRQHandler,Default_Handler
.weak SPI1_IRQHandler
.thumb_set SPI1_IRQHandler,Default_Handler
.weak SPI2_IRQHandler
.thumb_set SPI2_IRQHandler,Default_Handler
.weak USART1_IRQHandler
.thumb_set USART1_IRQHandler,Default_Handler
.weak USART2_IRQHandler
.thumb_set USART2_IRQHandler,Default_Handler
.weak USART3_IRQHandler
.thumb_set USART3_IRQHandler,Default_Handler
.weak EXTI15_10_IRQHandler
.thumb_set EXTI15_10_IRQHandler,Default_Handler
.weak RTC_Alarm_IRQHandler
.thumb_set RTC_Alarm_IRQHandler,Default_Handler
.weak OTG_FS_WKUP_IRQHandler
.thumb_set OTG_FS_WKUP_IRQHandler,Default_Handler
.weak TIM8_BRK_TIM12_IRQHandler
.thumb_set TIM8_BRK_TIM12_IRQHandler,Default_Handler
.weak TIM8_UP_TIM13_IRQHandler
.thumb_set TIM8_UP_TIM13_IRQHandler,Default_Handler
.weak TIM8_TRG_COM_TIM14_IRQHandler
.thumb_set TIM8_TRG_COM_TIM14_IRQHandler,Default_Handler
.weak TIM8_CC_IRQHandler
.thumb_set TIM8_CC_IRQHandler,Default_Handler
.weak DMA1_Stream7_IRQHandler
.thumb_set DMA1_Stream7_IRQHandler,Default_Handler
.weak FSMC_IRQHandler
.thumb_set FSMC_IRQHandler,Default_Handler
.weak SDIO_IRQHandler
.thumb_set SDIO_IRQHandler,Default_Handler
.weak TIM5_IRQHandler
.thumb_set TIM5_IRQHandler,Default_Handler
.weak SPI3_IRQHandler
.thumb_set SPI3_IRQHandler,Default_Handler
.weak UART4_IRQHandler
.thumb_set UART4_IRQHandler,Default_Handler
.weak UART5_IRQHandler
.thumb_set UART5_IRQHandler,Default_Handler
.weak TIM6_DAC_IRQHandler
.thumb_set TIM6_DAC_IRQHandler,Default_Handler
.weak TIM7_IRQHandler
.thumb_set TIM7_IRQHandler,Default_Handler
.weak DMA2_Stream0_IRQHandler
.thumb_set DMA2_Stream0_IRQHandler,Default_Handler
.weak DMA2_Stream1_IRQHandler
.thumb_set DMA2_Stream1_IRQHandler,Default_Handler
.weak DMA2_Stream2_IRQHandler
.thumb_set DMA2_Stream2_IRQHandler,Default_Handler
.weak DMA2_Stream3_IRQHandler
.thumb_set DMA2_Stream3_IRQHandler,Default_Handler
.weak DMA2_Stream4_IRQHandler
.thumb_set DMA2_Stream4_IRQHandler,Default_Handler
.weak ETH_IRQHandler
.thumb_set ETH_IRQHandler,Default_Handler
.weak ETH_WKUP_IRQHandler
.thumb_set ETH_WKUP_IRQHandler,Default_Handler
.weak CAN2_TX_IRQHandler
.thumb_set CAN2_TX_IRQHandler,Default_Handler
.weak CAN2_RX0_IRQHandler
.thumb_set CAN2_RX0_IRQHandler,Default_Handler
.weak CAN2_RX1_IRQHandler
.thumb_set CAN2_RX1_IRQHandler,Default_Handler
.weak CAN2_SCE_IRQHandler
.thumb_set CAN2_SCE_IRQHandler,Default_Handler
.weak OTG_FS_IRQHandler
.thumb_set OTG_FS_IRQHandler,Default_Handler
.weak DMA2_Stream5_IRQHandler
.thumb_set DMA2_Stream5_IRQHandler,Default_Handler
.weak DMA2_Stream6_IRQHandler
.thumb_set DMA2_Stream6_IRQHandler,Default_Handler
.weak DMA2_Stream7_IRQHandler
.thumb_set DMA2_Stream7_IRQHandler,Default_Handler
.weak USART6_IRQHandler
.thumb_set USART6_IRQHandler,Default_Handler
.weak I2C3_EV_IRQHandler
.thumb_set I2C3_EV_IRQHandler,Default_Handler
.weak I2C3_ER_IRQHandler
.thumb_set I2C3_ER_IRQHandler,Default_Handler
.weak OTG_HS_EP1_OUT_IRQHandler
.thumb_set OTG_HS_EP1_OUT_IRQHandler,Default_Handler
.weak OTG_HS_EP1_IN_IRQHandler
.thumb_set OTG_HS_EP1_IN_IRQHandler,Default_Handler
.weak OTG_HS_WKUP_IRQHandler
.thumb_set OTG_HS_WKUP_IRQHandler,Default_Handler
.weak OTG_HS_IRQHandler
.thumb_set OTG_HS_IRQHandler,Default_Handler
.weak DCMI_IRQHandler
.thumb_set DCMI_IRQHandler,Default_Handler
.weak CRYP_IRQHandler
.thumb_set CRYP_IRQHandler,Default_Handler
.weak HASH_RNG_IRQHandler
.thumb_set HASH_RNG_IRQHandler,Default_Handler
.weak FPU_IRQHandler
.thumb_set FPU_IRQHandler,Default_Handler
.weak UART7_IRQHandler
.thumb_set UART7_IRQHandler,Default_Handler
.weak UART8_IRQHandler
.thumb_set UART8_IRQHandler,Default_Handler
.weak SPI4_IRQHandler
.thumb_set SPI4_IRQHandler,Default_Handler
.weak SPI5_IRQHandler
.thumb_set SPI5_IRQHandler,Default_Handler
.weak SPI6_IRQHandler
.thumb_set SPI6_IRQHandler,Default_Handler
.weak SAI1_IRQHandler
.thumb_set SAI1_IRQHandler,Default_Handler
.weak LTDC_IRQHandler
.thumb_set LTDC_IRQHandler,Default_Handler
.weak LTDC_ER_IRQHandler
.thumb_set LTDC_ER_IRQHandler,Default_Handler
.weak DMA2D_IRQHandler
.thumb_set DMA2D_IRQHandler,Default_Handler
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -259,7 +259,7 @@
* @{ * @{
*/ */
#include "stm32f4xx.h" #include "../../Include/stm32f4xx.h"
/** /**
* @} * @}
@@ -293,9 +293,9 @@
through STLINK MCO pin of STM32F103 microcontroller. The frequency cannot be changed through STLINK MCO pin of STM32F103 microcontroller. The frequency cannot be changed
and is fixed at 8 MHz. and is fixed at 8 MHz.
Hardware configuration needed for Nucleo Board: Hardware configuration needed for Nucleo Board:
– SB54, SB55 OFF � SB54, SB55 OFF
– R35 removed � R35 removed
– SB16, SB50 ON */ � SB16, SB50 ON */
/* #define USE_HSE_BYPASS */ /* #define USE_HSE_BYPASS */
#if defined (USE_HSE_BYPASS) #if defined (USE_HSE_BYPASS)
@@ -451,7 +451,9 @@ void SystemInit(void)
#ifdef VECT_TAB_SRAM #ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else #else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ // SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
extern uint32_t g_pfnVectors ;
SCB->VTOR = (uint32_t) &g_pfnVectors ; /* Vector Table Relocation in Internal FLASH */
#endif #endif
} }
@@ -166,9 +166,9 @@
#endif #endif
#include <stdint.h> /* standard types definitions */ #include <stdint.h> /* standard types definitions */
#include <core_cmInstr.h> /* Core Instruction Access */ #include "core_cmInstr.h" /* Core Instruction Access */
#include <core_cmFunc.h> /* Core Function Access */ #include "core_cmFunc.h" /* Core Function Access */
#include <core_cm4_simd.h> /* Compiler specific SIMD Intrinsics */ #include "core_cm4_simd.h" /* Compiler specific SIMD Intrinsics */
#endif /* __CORE_CM4_H_GENERIC */ #endif /* __CORE_CM4_H_GENERIC */
@@ -35,7 +35,7 @@
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h" #include "../../CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
/** @addtogroup STM32F4xx_StdPeriph_Driver /** @addtogroup STM32F4xx_StdPeriph_Driver
* @{ * @{
@@ -34,7 +34,7 @@
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h" #include "../../CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
/** @addtogroup STM32F4xx_StdPeriph_Driver /** @addtogroup STM32F4xx_StdPeriph_Driver
* @{ * @{
@@ -35,7 +35,7 @@
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h" #include "../../CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
/** @addtogroup STM32F4xx_StdPeriph_Driver /** @addtogroup STM32F4xx_StdPeriph_Driver
* @{ * @{
@@ -35,7 +35,7 @@
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h" #include "../../CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
/** @addtogroup STM32F4xx_StdPeriph_Driver /** @addtogroup STM32F4xx_StdPeriph_Driver
* @{ * @{
@@ -35,7 +35,7 @@
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h" #include "../../CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
/** @addtogroup STM32F4xx_StdPeriph_Driver /** @addtogroup STM32F4xx_StdPeriph_Driver
* @{ * @{
@@ -35,7 +35,7 @@
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h" #include "../../CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
/** @addtogroup STM32F4xx_StdPeriph_Driver /** @addtogroup STM32F4xx_StdPeriph_Driver
* @{ * @{
@@ -34,7 +34,7 @@
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h" #include "../../CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
/** @addtogroup STM32F4xx_StdPeriph_Driver /** @addtogroup STM32F4xx_StdPeriph_Driver
* @{ * @{
@@ -35,7 +35,7 @@
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h" #include "../../CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
/** @addtogroup STM32F4xx_StdPeriph_Driver /** @addtogroup STM32F4xx_StdPeriph_Driver
* @{ * @{
@@ -35,7 +35,7 @@
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h" #include "../../CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
/** @addtogroup STM32F4xx_StdPeriph_Driver /** @addtogroup STM32F4xx_StdPeriph_Driver
* @{ * @{
@@ -35,7 +35,7 @@
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h" #include "../../CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
/** @addtogroup STM32F4xx_StdPeriph_Driver /** @addtogroup STM32F4xx_StdPeriph_Driver
* @{ * @{
-2
View File
@@ -15,8 +15,6 @@
extern "C" { extern "C" {
#endif #endif
#include "./STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
#define __no_operation __NOP #define __no_operation __NOP
#define LCD_NCS_HIGH() GPIO_LCD_NCS->BSRRL = PIN_LCD_NCS #define LCD_NCS_HIGH() GPIO_LCD_NCS->BSRRL = PIN_LCD_NCS
+4 -2
View File
@@ -142,9 +142,11 @@ void audioEnd()
#if !defined(SIMU) #if !defined(SIMU)
extern "C" void TIM6_DAC_IRQHandler() extern "C" void TIM6_DAC_IRQHandler()
{ {
DAC->CR &= ~DAC_CR_DMAEN1 ; // Stop DMA requests DAC->CR &= ~DAC_CR_DMAEN1 ; // Stop DMA requests
#if !defined(REV9E)
DAC->CR &= ~DAC_CR_DMAUDRIE1 ; // Stop underrun interrupt DAC->CR &= ~DAC_CR_DMAUDRIE1 ; // Stop underrun interrupt
DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag #endif
DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag
} }
extern "C" void DMA1_Stream5_IRQHandler() extern "C" void DMA1_Stream5_IRQHandler()
@@ -41,7 +41,6 @@ extern "C" {
#endif #endif
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" #include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h"
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_bsp.h" #include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_bsp.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_dbgmcu.h"
#if defined(__cplusplus) && !defined(SIMU) #if defined(__cplusplus) && !defined(SIMU)
} }
#endif #endif
+29 -16
View File
@@ -43,15 +43,31 @@
extern "C" { extern "C" {
#endif #endif
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_rcc.h" #if defined(REV9E)
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_gpio.h" #include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_spi.h" #include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_rcc.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_rtc.h" #include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_gpio.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_pwr.h" #include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_spi.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_dma.h" #include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_rtc.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_usart.h" #include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_pwr.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h" #include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_dma.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/misc.h" #include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_usart.h"
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_flash.h"
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_dbgmcu.h"
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/misc.h"
#else
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_rcc.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_gpio.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_spi.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_rtc.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_pwr.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_dma.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_usart.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_flash.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_dbgmcu.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/misc.h"
#endif
#if !defined(SIMU) #if !defined(SIMU)
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_core.h" #include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_core.h"
@@ -157,11 +173,8 @@ uint32_t isBootloaderStart(const void * buffer);
void init_no_pulses(uint32_t port); void init_no_pulses(uint32_t port);
void disable_no_pulses(uint32_t port); void disable_no_pulses(uint32_t port);
void init_ppm( uint32_t module_index ); void init_ppm( uint32_t module_index );
void disable_ppm( uint32_t module_index );
void set_external_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive); void set_external_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive);
#if defined(TARANIS_INTERNAL_PPM) void disable_ppm( uint32_t module_index );
void set_internal_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive);
#endif
void init_pxx( uint32_t module_index ); void init_pxx( uint32_t module_index );
void disable_pxx( uint32_t module_index ); void disable_pxx( uint32_t module_index );
void init_dsm2( uint32_t module_index ); void init_dsm2( uint32_t module_index );
@@ -170,13 +183,13 @@ void disable_dsm2( uint32_t module_index );
// Trainer driver // Trainer driver
void init_trainer_ppm(void); void init_trainer_ppm(void);
void stop_trainer_ppm(void); void stop_trainer_ppm(void);
void set_trainer_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive);
void init_trainer_capture(void); void init_trainer_capture(void);
void stop_trainer_capture(void); void stop_trainer_capture(void);
void init_cppm_on_heartbeat_capture(void); void init_cppm_on_heartbeat_capture(void);
void stop_cppm_on_heartbeat_capture(void); void stop_cppm_on_heartbeat_capture(void);
void init_sbus_on_heartbeat_capture(void); void init_sbus_on_heartbeat_capture(void);
void stop_sbus_on_heartbeat_capture(void); void stop_sbus_on_heartbeat_capture(void);
void set_trainer_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive);
// Keys driver // Keys driver
void keysInit(void); void keysInit(void);
@@ -238,7 +251,7 @@ void turnBacklightOff(void);
#define setBacklight(xx) turnBacklightOn(xx, g_eeGeneral.backlightColor) #define setBacklight(xx) turnBacklightOn(xx, g_eeGeneral.backlightColor)
#define __BACKLIGHT_ON turnBacklightOn(g_eeGeneral.backlightBright, g_eeGeneral.backlightColor) #define __BACKLIGHT_ON turnBacklightOn(g_eeGeneral.backlightBright, g_eeGeneral.backlightColor)
#define __BACKLIGHT_OFF turnBacklightOff() #define __BACKLIGHT_OFF turnBacklightOff()
#define IS_BACKLIGHT_ON() (TIM4->CCR4 != 0) || (TIM4->CCR2 != 0) #define IS_BACKLIGHT_ON() (TIM_BL->CCR4 != 0) || (TIM_BL->CCR2 != 0)
#else #else
#define setBacklight(xx) TIM10->CCR1 = 100-xx #define setBacklight(xx) TIM10->CCR1 = 100-xx
#define __BACKLIGHT_ON TIM10->CCR1 = 100-g_eeGeneral.backlightBright #define __BACKLIGHT_ON TIM10->CCR1 = 100-g_eeGeneral.backlightBright
@@ -294,7 +307,7 @@ void uart3SbusInit(void);
void uart3Stop(void); void uart3Stop(void);
// BT driver // BT driver
int bt_open(); int bt_open(void);
int bt_write(const void *buffer, int len); int bt_write(const void *buffer, int len);
int bt_read(void *buffer, int len); int bt_read(void *buffer, int len);
@@ -36,16 +36,6 @@
#include "../../opentx.h" #include "../../opentx.h"
#if defined(__cplusplus) && !defined(SIMU)
extern "C" {
#endif
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h"
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_bsp.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_dbgmcu.h"
#if defined(__cplusplus) && !defined(SIMU)
}
#endif
void configure_pins( uint32_t pins, uint16_t config ) void configure_pins( uint32_t pins, uint16_t config )
{ {
uint32_t address ; uint32_t address ;
@@ -1,5 +1,4 @@
#include "../../opentx.h" #include "../../opentx.h"
#include "stm32f2xx_flash.h"
//After reset, write is not allowed in the Flash control register (FLASH_CR) to protect the //After reset, write is not allowed in the Flash control register (FLASH_CR) to protect the
//Flash memory against possible unwanted operations due, for example, to electric //Flash memory against possible unwanted operations due, for example, to electric
+17 -6
View File
@@ -324,14 +324,25 @@
#define PIN_FS_DP GPIO_Pin_12 // PA.12 #define PIN_FS_DP GPIO_Pin_12 // PA.12
// BackLight // BackLight
#if defined (REVPLUS) #if defined(REV9E)
#define RCC_AHB1Periph_GPIOBL RCC_AHB1Periph_GPIOD #define TIM_BL TIM9
#define GPIO_Pin_BL GPIO_Pin_15 // PD.15 #define GPIOBL GPIOE
#define Pin_BL_AF GPIO_AF_TIM4 #define RCC_AHB1Periph_GPIOBL RCC_AHB1Periph_GPIOE
#define Pin_BL_AF GPIO_AF_TIM9
#define GPIO_Pin_BL GPIO_Pin_6 // PE.06
#define GPIO_PinSource_BL GPIO_PinSource6
#define Pin_BLW_AF GPIO_AF_TIM9
#define GPIO_Pin_BLW GPIO_Pin_5 // PE.05
#define GPIO_PinSource_BLW GPIO_PinSource5
#elif defined (REVPLUS)
#define TIM_BL TIM4
#define GPIOBL GPIOD #define GPIOBL GPIOD
#define RCC_AHB1Periph_GPIOBL RCC_AHB1Periph_GPIOD
#define Pin_BL_AF GPIO_AF_TIM4
#define GPIO_Pin_BL GPIO_Pin_15 // PD.15
#define GPIO_PinSource_BL GPIO_PinSource15 #define GPIO_PinSource_BL GPIO_PinSource15
#define GPIO_Pin_BLW GPIO_Pin_13 // PD.13
#define Pin_BLW_AF GPIO_AF_TIM4 #define Pin_BLW_AF GPIO_AF_TIM4
#define GPIO_Pin_BLW GPIO_Pin_13 // PD.13
#define GPIO_PinSource_BLW GPIO_PinSource13 #define GPIO_PinSource_BLW GPIO_PinSource13
#else #else
#define RCC_AHB1Periph_GPIOBL RCC_AHB1Periph_GPIOB #define RCC_AHB1Periph_GPIOBL RCC_AHB1Periph_GPIOB
@@ -353,7 +364,7 @@
#define PIN_LCD_CLK GPIO_Pin_10 // PC.10 #define PIN_LCD_CLK GPIO_Pin_10 // PC.10
#define PIN_LCD_NCS GPIO_Pin_15 // PA.15 #define PIN_LCD_NCS GPIO_Pin_15 // PA.15
#define PIN_LCD_A0 GPIO_Pin_11 // PC.11 #define PIN_LCD_A0 GPIO_Pin_11 // PC.11
#define PIN_LCD_RST GPIO_Pin_12 // PD.12 #define PIN_LCD_RST GPIO_Pin_15 // TOTO PD.12
#else #else
#define RCC_AHB1Periph_LCD RCC_AHB1Periph_GPIOD #define RCC_AHB1Periph_LCD RCC_AHB1Periph_GPIOD
#define GPIO_LCD_SPI GPIOD #define GPIO_LCD_SPI GPIOD
+25 -7
View File
@@ -271,8 +271,26 @@ static void LCD_BL_Config()
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOBL, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOBL, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
#if defined(REVPLUS) #if defined(REV9E)
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_BL|GPIO_Pin_BLW;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOBL, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOBL, GPIO_PinSource_BL, Pin_BL_AF);
GPIO_PinAFConfig(GPIOBL, GPIO_PinSource_BLW, Pin_BL_AF);
RCC->APB2ENR |= RCC_APB2ENR_TIM9EN ; // Enable clock
TIM9->ARR = 100 ;
TIM9->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 50000 - 1; // 20us * 100 = 2ms => 500Hz
TIM9->CCMR1 = TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 ; // PWM
TIM9->CCMR2 = TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2 ; // PWM
TIM9->CCER = TIM_CCER_CC4E | TIM_CCER_CC2E ;
TIM9->CCR2 = 0 ;
TIM9->CCR4 = 80 ;
TIM9->EGR = 0 ;
TIM9->CR1 = TIM_CR1_CEN ; // Counter enable
#elif defined(REVPLUS)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_BL|GPIO_Pin_BLW; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_BL|GPIO_Pin_BLW;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
@@ -430,16 +448,16 @@ void lcdSetRefVolt(uint8_t val)
AspiCmd(val+CONTRAST_OFS); //0--255 AspiCmd(val+CONTRAST_OFS); //0--255
} }
#if defined(REVPLUS) #if defined(REV9E) || defined(REVPLUS)
void turnBacklightOn(uint8_t level, uint8_t color) void turnBacklightOn(uint8_t level, uint8_t color)
{ {
TIM4->CCR4 = ((100-level)*(20-color))/20; TIM_BL->CCR4 = ((100-level)*(20-color))/20;
TIM4->CCR2 = ((100-level)*color)/20; TIM_BL->CCR2 = ((100-level)*color)/20;
} }
void turnBacklightOff(void) void turnBacklightOff(void)
{ {
TIM4->CCR4 = 0; TIM_BL->CCR4 = 0;
TIM4->CCR2 = 0; TIM_BL->CCR2 = 0;
} }
#endif #endif
+39
View File
@@ -37,6 +37,15 @@
#include "board_taranis.h" #include "board_taranis.h"
#include "../../pwr.h" #include "../../pwr.h"
#ifdef REV9E
#define POWER_STATE_OFF 0
#define POWER_STATE_START 1
#define POWER_STATE_RUNNING 2
#define POWER_STATE_STOPPING 3
#define POWER_STATE_STOPPED 4
uint8_t PowerState = POWER_STATE_OFF ;
#endif
void pwrInit() void pwrInit()
{ {
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
@@ -104,6 +113,36 @@ uint32_t pwrCheck()
{ {
#if defined(SIMU) #if defined(SIMU)
return e_power_on; return e_power_on;
#elif defined(REV9E)
uint32_t switchValue = GPIO_ReadInputDataBit(GPIOPWR, PIN_PWR_STATUS) == Bit_RESET;
switch ( PowerState )
{
case POWER_STATE_OFF :
PowerState = POWER_STATE_START ;
return e_power_on ;
case POWER_STATE_START :
if ( !switchValue ) {
PowerState = POWER_STATE_RUNNING ;
}
return e_power_on ;
case POWER_STATE_RUNNING :
if ( switchValue ) {
PowerState = POWER_STATE_STOPPING ;
// return e_power_on;
}
return e_power_on ;
case POWER_STATE_STOPPING :
if ( !switchValue ) {
PowerState = POWER_STATE_STOPPED ;
}
return e_power_off ;
case POWER_STATE_STOPPED :
return e_power_off ;
}
#else #else
if (GPIO_ReadInputDataBit(GPIOPWR, PIN_PWR_STATUS) == Bit_RESET) if (GPIO_ReadInputDataBit(GPIOPWR, PIN_PWR_STATUS) == Bit_RESET)
return e_power_on; return e_power_on;
+5 -5
View File
@@ -38,7 +38,7 @@
void rotencInit() void rotencInit()
{ {
configure_pins( 0x0060, PIN_INPUT | PIN_PULLUP | PIN_PORTE ) ; configure_pins( GPIO_Pin_12|GPIO_Pin_13, PIN_INPUT | PIN_PULLUP | PIN_PORTD ) ;
} }
void rotencEnd() void rotencEnd()
@@ -51,18 +51,18 @@ void checkRotaryEncoder()
{ {
register uint32_t dummy ; register uint32_t dummy ;
dummy = GPIOE->IDR ; // Read Rotary encoder ( PE6, PE5 ) dummy = GPIOD->IDR ; // Read Rotary encoder ( PE6, PE5 )
dummy >>= 5 ; dummy >>= 12 ;
dummy &= 0x03 ; // pick out the two bits dummy &= 0x03 ; // pick out the two bits
if ( dummy != ( Rotary_position & 0x03 ) ) if ( dummy != ( Rotary_position & 0x03 ) )
{ {
if ( ( Rotary_position & 0x01 ) ^ ( ( dummy & 0x02) >> 1 ) ) if ( ( Rotary_position & 0x01 ) ^ ( ( dummy & 0x02) >> 1 ) )
{ {
++x9de_rotenc; --x9de_rotenc;
} }
else else
{ {
--x9de_rotenc; ++x9de_rotenc;
} }
Rotary_position &= ~0x03 ; Rotary_position &= ~0x03 ;
Rotary_position |= dummy ; Rotary_position |= dummy ;
+2 -3
View File
@@ -27,9 +27,8 @@
*/ */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_rcc.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_gpio.h" #include "board_taranis.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/misc.h"
#include "usb_bsp.h" #include "usb_bsp.h"
#include "usbd_conf.h" #include "usbd_conf.h"
+5 -2
View File
@@ -29,8 +29,11 @@
#ifndef __USB_CONF__H__ #ifndef __USB_CONF__H__
#define __USB_CONF__H__ #define __USB_CONF__H__
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h" #if defined(REV9E)
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
#else
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
#endif
/* USB Core and PHY interface configuration. /* USB Core and PHY interface configuration.
Tip: To avoid modifying these defines each time you need to change the USB Tip: To avoid modifying these defines each time you need to change the USB
@@ -33,7 +33,7 @@
#if defined(__cplusplus) && !defined(SIMU) #if defined(__cplusplus) && !defined(SIMU)
extern "C" { extern "C" {
#endif #endif
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/misc.h"
#include "usbd_msc_mem.h" #include "usbd_msc_mem.h"
#include "usb_conf.h" #include "usb_conf.h"