//vs2008_ucos\uCOSII_port\app_test.h.c app_cfg.h include.h cpu_def.h cpu.h.c os_cfg.h
/* UCOSII 2.86 在VS2008 上的移植
步骤1: 下载源码,将uCOS-II中的所有文件复制到uCOSII文件夹
将如下文件加入到工程即可
os_cfg_r.h
os_dbg_r.c
ucosii.h
ucosii.c 此文件包含了所有的源代码
步骤2: 添加如下文件到 uCOSII_port文件夹,然后加入到工程
app_test.h
app_test.c
app_cfg.h
include.h
cpu_def.h
cpu.h
cpu_c.c
os_cfg.h
os_cpu.h
os_cpu_c.c
步骤3:添加文件包含路径,在main函数调用App_Test() 即可。
/*****************************************************************************************
* ucosii 测试函数
* Filename : app_test.h
* Version : V2.86
* 环境:VS2008
* 编者:张永辉 2013年5月27日
*****************************************************************************************/
#ifndef APP_TEST_H
#define APP_TEST_H
int App_Test (void);
//****************************************************************************************
#endif
/*****************************************************************************************
* OS测试函数
* Filename : app_test.c
* Version : V2.86
*****************************************************************************************/
#include <includes.h>
#include "app_test.h"
OS_STK AppStartTaskStk[APP_OS_CFG_START_TASK_STK_SIZE];
/*****************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*****************************************************************************************/
static void App_TaskStart (void *p_arg);
/*****************************************************************************************
* C ENTRY POINT
*****************************************************************************************/
int App_Test (void)
{
INT8U err;
OSInit(); // Initialize OS
OSTaskCreateExt((void (*)(void *)) App_TaskStart,
(void * ) 0,
(OS_STK * )&AppStartTaskStk[APP_OS_CFG_START_TASK_STK_SIZE-1],
(INT8U ) APP_OS_CFG_START_TASK_PRIO,
(INT16U ) APP_OS_CFG_START_TASK_PRIO,
(OS_STK * )&AppStartTaskStk[0],
(INT32U ) APP_OS_CFG_START_TASK_STK_SIZE,
(void * ) 0,
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
/* Give a name to tasks. */
#if (OS_TASK_NAME_SIZE >= 6)
OSTaskNameSet(APP_OS_CFG_START_TASK_PRIO, "Start", &err);
#endif
#if (OS_TASK_NAME_SIZE >= 5)
OSTaskNameSet(OS_TASK_IDLE_PRIO, "Idle", &err);
#endif
#if ((OS_TASK_NAME_SIZE >= 5) && \
(OS_TASK_STAT_EN > 0))
OSTaskNameSet(OS_TASK_STAT_PRIO, "Stat", &err);
#endif
OSStart(); // Start OS
return 0;
}
/******************************************************************************************
* App_TaskStart()
* Description : Startup task example code
* Arguments : p_arg Argument passed by 'OSTaskCreate'. p_arg' is not used
* Returns : none.
******************************************************************************************/
void App_TaskStart (void *p_arg)
{
int i = 0;
(void)&p_arg; /* Prevent compiler warning. */
#if OS_TASK_STAT_EN > 0
OSStatInit(); /* Determine CPU capacity. */
#endif
while (1) /* Task body, always written as an infinite loop.*/
{
printf("Delay %d second and print\n",i++);
OSTimeDlyHMSM(0, 0, 1, 0);
}
}
/*****************************************************************************************
* Filename : app_cfg.h
* Version : V2.86
* Programmer(s) : SR
*****************************************************************************************/
/*****************************************************************************************
* TASKS PRIORITIES
*****************************************************************************************/
#define APP_OS_CFG_START_TASK_PRIO 5
/*****************************************************************************************
* STACK SIZES
* Size of the task stacks (# of OS_STK entries)
*****************************************************************************************/
#define APP_OS_CFG_START_TASK_STK_SIZE 128
/*****************************************************************************************
* EXAMPLE CODE
* (c) Copyright 1998-2008; Micrium, Inc.; Weston, FL
* MASTER INCLUDE FILE
* Filename : includes.h
* Version : V2.86
* Programmer(s) : SR
******************************************************************************************/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <app_cfg.h>
#include <ucos_ii.h>
/***************************************************************************************************
* uC/CPU
* CPU CONFIGURATION & PORT LAYER
* (c) Copyright 2004-2008; Micrium, Inc.; Weston, FL
* CPU CONFIGURATION DEFINES
* Filename : cpu_def.h
* Version : V1.20
* Programmer(s) : ITJ
* CPU WORD CONFIGURATION
* Note(s) :
* (1) Configure CPU_CFG_ADDR_SIZE & CPU_CFG_DATA_SIZE in 'cpu.h' with CPU's word sizes :
*
* CPU_WORD_SIZE_08 8-bit word size
* CPU_WORD_SIZE_16 16-bit word size
* CPU_WORD_SIZE_32 32-bit word size
* CPU_WORD_SIZE_64 64-bit word size See Note #1a
*
* (a) 64-bit word size NOT currently supported.
*
* (b) Ideally, CPU_WORD_SIZE #define's would be calculated at compile-time through use of
* the sizeof() operator. However, some compilers do NOT allow pre-processor directives
* to include run-time macro's -- e.g. 'sizeof()'.
*
*(2) Configure CPU_CFG_ENDIAN_TYPE in 'cpu.h' with CPU's data-word-memory order :
*
* CPU_ENDIAN_TYPE_BIG Big- endian word order (CPU words' most significant
* octet @ lowest memory address)
* CPU_ENDIAN_TYPE_LITTLE Little-endian word order (CPU words' least significant
* octet @ lowest memory address)
*****************************************************************************************/
/* ----------------------- CPU WORD SIZE --------------------*/
#define CPU_WORD_SIZE_08 1 /* 8-bit word size = sizeof(CPU_INT08x). */
#define CPU_WORD_SIZE_16 2 /* 16-bit word size = sizeof(CPU_INT16x). */
#define CPU_WORD_SIZE_32 4 /* 32-bit word size = sizeof(CPU_INT32x). */
#define CPU_WORD_SIZE_64 8 /* 64-bit word size = sizeof(CPU_INT64x) [see Note #1a]. */
/* ------------------- CPU WORD-ENDIAN ORDER ----------------*/
#define CPU_ENDIAN_TYPE_NONE 0 /* */
#define CPU_ENDIAN_TYPE_BIG 1 /* Big- endian word order (CPU words' most significant ...*/
/* ... octet @ lowest mem addr). */
#define CPU_ENDIAN_TYPE_LITTLE 2 /* Little-endian word order (CPU words' least significant ...*/
/* ... octet @ lowest mem addr). */
/***************************************************************************************************
* CRITICAL SECTION CONFIGURATION
* Note(s) :
*(1) Configure CPU_CFG_CRITICAL_METHOD with CPU's/compiler's critical section method :
* Enter/Exit critical sections by ...
* CPU_CRITICAL_METHOD_INT_DIS_EN Disable/Enable interrupts
* CPU_CRITICAL_METHOD_STATUS_STK Push/Pop interrupt status onto stack
* CPU_CRITICAL_METHOD_STATUS_LOCAL Save/Restore interrupt status to local variable
*
* (a) CPU_CRITICAL_METHOD_INT_DIS_EN is NOT a preferred method since it does NOT support
* multiple levels of interrupts. However, with some CPUs/compilers, this is the only
* available method.
* (b) CPU_CRITICAL_METHOD_STATUS_STK is one preferred method since it DOES support multiple
* levels of interrupts. However, this method assumes that the compiler allows in-line
* assembly AND will correctly modify the local stack pointer when interrupt status is
* pushed/popped onto the stack.
*
* (c) CPU_CRITICAL_METHOD_STATUS_LOCAL is one preferred method since it DOES support multiple
* levels of interrupts. However, this method assumes that the compiler provides C-level
* &/or assembly-level functionality for the following :
* ENTER CRITICAL SECTION :
* (a) Save interrupt status into a local variable
* (b) Disable interrupts
* EXIT CRITICAL SECTION :
* (c) Restore interrupt status from a local variable
*
*(2) Critical section macro's most likely require inline assembly. If the compiler does NOT
* allow inline assembly in C source files, critical section macro's MUST call an assembly
* subroutine defined in a 'cpu_a.asm' file located in the following software directory :
* \<CPU-Compiler Directory>\<cpu>\<compiler>\
* where
* <CPU-Compiler Directory> directory path for common CPU-compiler software
* <cpu> directory name for specific CPU
* <compiler> directory name for specific compiler
*(3) To save/restore interrupt status, a local variable 'cpu_sr' of type 'CPU_SR' MAY need to
* be declared (e.g. if 'CPU_CRITICAL_METHOD_STATUS_LOCAL' method is configured). Configure
* 'CPU_SR' data type in 'cpu.h' with the appropriate-sized CPU data type large enough to
* completely store the CPU's/compiler's status word.
***************************************************************************************************/
/* ------ CPU CRITICAL SECTION METHODS ------- */
#define CPU_CRITICAL_METHOD_NONE 0 /* */
#define CPU_CRITICAL_METHOD_INT_DIS_EN 1 /* DIS/EN ints. */
#define CPU_CRITICAL_METHOD_STATUS_STK 2 /* Push/Pop int status onto stk. */
#define CPU_CRITICAL_METHOD_STATUS_LOCAL 3 /* Save/Restore int status to local var. */
/*****************************************************************************************
* uC/CPU
* software available. Your honesty is greatly appreciated.
*
* CPU PORT FILE
* Win32
* Microsoft Visual Studio
* Filename : cpu.h
* Version : V1.21
* Programmer(s) : FGK
* ITJ
* SR
******************************************************************************************
* MODULE
*****************************************************************************************/
#ifndef CPU_CFG_MODULE_PRESENT
#define CPU_CFG_MODULE_PRESENT
/*****************************************************************************************
* CPU INCLUDE FILES
* Note(s) : (1) The following CPU files are located in the following directories :
* (a) \<CPU-Compiler Directory>\cpu_def.h
* (b) \<CPU-Compiler Directory>\<cpu>\<compiler>\cpu*.*
* where
* <CPU-Compiler Directory> directory path for common CPU-compiler software
* <cpu> directory name for specific CPU
* <compiler> directory name for specific compiler
* (2) Compiler MUST be configured to include the '\<CPU-Compiler Directory>\' directory & the
* specific CPU-compiler directory as additional include path directories.
*****************************************************************************************/
#include <cpu_def.h>
/*****************************************************************************************
* CONFIGURE STANDARD DATA TYPES
* Note(s) : (1) Configure standard data types according to CPU-/compiler-specifications.
* (2) (a) (1) 'CPU_FNCT_VOID' data type defined to replace the commonly-used function pointer
* data type of a pointer to a function which returns void & has no arguments.
* (2) Example function pointer usage :
* CPU_FNCT_VOID FnctName;
* FnctName();
* (b) (1) 'CPU_FNCT_PTR' data type defined to replace the commonly-used function pointer
* data type of a pointer to a function which returns void & has a single void
* pointer argument.
* (2) Example function pointer usage :
* CPU_FNCT_PTR FnctName;
* void *pobj
* FnctName(pobj);
*****************************************************************************************/
typedef void CPU_VOID;
typedef unsigned char CPU_CHAR; /* 8-bit character */
typedef unsigned char CPU_BOOLEAN; /* 8-bit boolean or logical */
typedef unsigned char CPU_INT08U; /* 8-bit unsigned integer */
typedef signed char CPU_INT08S; /* 8-bit signed integer */
typedef unsigned short CPU_INT16U; /* 16-bit unsigned integer */
typedef signed short CPU_INT16S; /* 16-bit signed integer */
typedef unsigned int CPU_INT32U; /* 32-bit unsigned integer */
typedef signed int CPU_INT32S; /* 32-bit signed integer */
typedef float CPU_FP32; /* 32-bit floating point */
typedef double CPU_FP64; /* 64-bit floating point */
typedef void (*CPU_FNCT_VOID)(void); /* See Note #2a. */
typedef void (*CPU_FNCT_PTR )(void *); /* See Note #2b. */
/*****************************************************************************************
* CPU WORD CONFIGURATION
* Note(s) :
* (1) Configure CPU_CFG_ADDR_SIZE & CPU_CFG_DATA_SIZE with CPU's word sizes :
*
* CPU_WORD_SIZE_08 8-bit word size
* CPU_WORD_SIZE_16 16-bit word size
* CPU_WORD_SIZE_32 32-bit word size
* CPU_WORD_SIZE_64 64-bit word size See Note #1a
* (a) 64-bit word size NOT currently supported.
* (2) Configure CPU_CFG_ENDIAN_TYPE with CPU's data-word-memory order :
* CPU_ENDIAN_TYPE_BIG Big- endian word order (CPU words' most significant
* octet @ lowest memory address)
* CPU_ENDIAN_TYPE_LITTLE Little-endian word order (CPU words' least significant
* octet @ lowest memory address)
*****************************************************************************************/
/* Define CPU word sizes (see Note #1) */
#define CPU_CFG_ADDR_SIZE CPU_WORD_SIZE_32 /* Defines CPU address word size. */
#define CPU_CFG_DATA_SIZE CPU_WORD_SIZE_32 /* Defines CPU data word size. */
#define CPU_CFG_ENDIAN_TYPE CPU_ENDIAN_TYPE_LITTLE /* Defines CPU data word-memory order. */
/*****************************************************************************************
* CONFIGURE CPU ADDRESS & DATA TYPES
*****************************************************************************************/
/* CPU address type based on address bus size. */
#if (CPU_CFG_ADDR_SIZE == CPU_WORD_SIZE_32)
typedef CPU_INT32U CPU_ADDR;
#elif (CPU_CFG_ADDR_SIZE == CPU_WORD_SIZE_16)
typedef CPU_INT16U CPU_ADDR;
#else
typedef CPU_INT08U CPU_ADDR;
#endif
/* CPU data type based on data bus size. */
#if (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_32)
typedef CPU_INT32U CPU_DATA;
#elif (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_16)
typedef CPU_INT16U CPU_DATA;
#else
typedef CPU_INT08U CPU_DATA;
#endif
typedef CPU_DATA CPU_ALIGN; /* Defines CPU data-word-alignment size. */
typedef CPU_DATA CPU_SIZE_T; /* Defines CPU standard 'size_t' size. */
typedef CPU_INT32U CPU_STK; /* Defines CPU stack size entry. */
/*****************************************************************************************
* CPU ERROR CODES DATA TYPE
*****************************************************************************************/
typedef CPU_INT16U CPU_ERR;
/*****************************************************************************************
* CRITICAL SECTION CONFIGURATION
* Note(s) :
*(1) Configure CPU_CFG_CRITICAL_METHOD with CPU's/compiler's critical section method :
* Enter/Exit critical sections by ...
*
* CPU_CRITICAL_METHOD_INT_DIS_EN Disable/Enable interrupts
* CPU_CRITICAL_METHOD_STATUS_STK Push/Pop interrupt status onto stack
* CPU_CRITICAL_METHOD_STATUS_LOCAL Save/Restore interrupt status to local variable
*
* (a) CPU_CRITICAL_METHOD_INT_DIS_EN is NOT a preferred method since it does NOT support
* multiple levels of interrupts. However, with some CPUs/compilers, this is the only
* available method.
*
* (b) CPU_CRITICAL_METHOD_STATUS_STK is one preferred method since it DOES support multiple
* levels of interrupts. However, this method assumes that the compiler allows in-line
* assembly AND will correctly modify the local stack pointer when interrupt status is
* pushed/popped onto the stack.
*
* (c) CPU_CRITICAL_METHOD_STATUS_LOCAL is one preferred method since it DOES support multiple
* levels of interrupts. However, this method assumes that the compiler provides C-level
* &/or assembly-level functionality for the following :
*
* ENTER CRITICAL SECTION :
* (a) Save interrupt status into a local variable
* (b) Disable interrupts
*
* EXIT CRITICAL SECTION :
* (c) Restore interrupt status from a local variable
*
*(2) Critical section macro's most likely require inline assembly. If the compiler does NOT
* allow inline assembly in C source files, critical section macro's MUST call an assembly
* subroutine defined in a 'cpu_a.asm' file located in the following software directory :
* \<CPU-Compiler Directory>\<cpu>\<compiler>\
* where
* <CPU-Compiler Directory> directory path for common CPU-compiler software
* <cpu> directory name for specific CPU
* <compiler> directory name for specific compiler
*(3) To save/restore interrupt status, a local variable 'cpu_sr' of type 'CPU_SR' MAY need to
* be declared (e.g. if 'CPU_CRITICAL_METHOD_STATUS_LOCAL' method is configured). Configure
* 'CPU_SR' data type with the appropriate-sized CPU data type large enough to completely
* store the CPU's/compiler's status word.
******************************************************************************************/
typedef CPU_INT32U CPU_SR; /* Defines CPU status register size (see Note #3). */
/* Configure CPU critical method (see Note #1) : */
#define CPU_CFG_CRITICAL_METHOD CPU_CRITICAL_METHOD_INT_DIS_EN
#define CPU_CRITICAL_ENTER() { CPU_IntDis(); }
#define CPU_CRITICAL_EXIT() { CPU_IntEn(); }
/*****************************************************************************************
* FUNCTION PROTOTYPES
*****************************************************************************************/
void CPU_IntDis (void);
void CPU_IntEn (void);
/*****************************************************************************************
* CONFIGURATION ERRORS
*****************************************************************************************/
#ifndef CPU_CFG_ADDR_SIZE
#error "CPU_CFG_ADDR_SIZE not #define'd in 'cpu.h' "
#error " [MUST be CPU_WORD_SIZE_08 8-bit alignment]"
#error " [ || CPU_WORD_SIZE_16 16-bit alignment]"
#error " [ || CPU_WORD_SIZE_32 32-bit alignment]"
#elif ((CPU_CFG_ADDR_SIZE != CPU_WORD_SIZE_08) && \
(CPU_CFG_ADDR_SIZE != CPU_WORD_SIZE_16) && \
(CPU_CFG_ADDR_SIZE != CPU_WORD_SIZE_32))
#error "CPU_CFG_ADDR_SIZE illegally #define'd in 'cpu.h' "
#error " [MUST be CPU_WORD_SIZE_08 8-bit alignment]"
#error " [ || CPU_WORD_SIZE_16 16-bit alignment]"
#error " [ || CPU_WORD_SIZE_32 32-bit alignment]"
#endif
#ifndef CPU_CFG_DATA_SIZE
#error "CPU_CFG_DATA_SIZE not #define'd in 'cpu.h' "
#error " [MUST be CPU_WORD_SIZE_08 8-bit alignment]"
#error " [ || CPU_WORD_SIZE_16 16-bit alignment]"
#error " [ || CPU_WORD_SIZE_32 32-bit alignment]"
#elif ((CPU_CFG_DATA_SIZE != CPU_WORD_SIZE_08) && \
(CPU_CFG_DATA_SIZE != CPU_WORD_SIZE_16) && \
(CPU_CFG_DATA_SIZE != CPU_WORD_SIZE_32))
#error "CPU_CFG_DATA_SIZE illegally #define'd in 'cpu.h' "
#error " [MUST be CPU_WORD_SIZE_08 8-bit alignment]"
#error " [ || CPU_WORD_SIZE_16 16-bit alignment]"
#error " [ || CPU_WORD_SIZE_32 32-bit alignment]"
#endif
#ifndef CPU_CFG_ENDIAN_TYPE
#error "CPU_CFG_ENDIAN_TYPE not #define'd in 'cpu.h' "
#error " [MUST be CPU_ENDIAN_TYPE_BIG ]"
#error " [ || CPU_ENDIAN_TYPE_LITTLE]"
#elif ((CPU_CFG_ENDIAN_TYPE != CPU_ENDIAN_TYPE_BIG ) && \
(CPU_CFG_ENDIAN_TYPE != CPU_ENDIAN_TYPE_LITTLE))
#error "CPU_CFG_ENDIAN_TYPE illegally #define'd in 'cpu.h' "
#error " [MUST be CPU_ENDIAN_TYPE_BIG ]"
#error " [ || CPU_ENDIAN_TYPE_LITTLE]"
#endif
#ifndef CPU_CFG_CRITICAL_METHOD
#error "CPU_CFG_CRITICAL_METHOD not #define'd in 'cpu.h' "
#error " [MUST be CPU_CRITICAL_METHOD_INT_DIS_EN ]"
#error " [ || CPU_CRITICAL_METHOD_STATUS_STK ]"
#error " [ || CPU_CRITICAL_METHOD_STATUS_LOCAL]"
#elif ((CPU_CFG_CRITICAL_METHOD != CPU_CRITICAL_METHOD_INT_DIS_EN ) && \
(CPU_CFG_CRITICAL_METHOD != CPU_CRITICAL_METHOD_STATUS_STK ) && \
(CPU_CFG_CRITICAL_METHOD != CPU_CRITICAL_METHOD_STATUS_LOCAL))
#error "CPU_CFG_CRITICAL_METHOD illegally #define'd in 'cpu.h' "
#error " [MUST be CPU_CRITICAL_METHOD_INT_DIS_EN ]"
#error " [ || CPU_CRITICAL_METHOD_STATUS_STK ]"
#error " [ || CPU_CRITICAL_METHOD_STATUS_LOCAL]"
#endif
/*****************************************************************************************
* MODULE END
*****************************************************************************************/
#endif
/*****************************************************************************************
* uC/CPU
* CPU CONFIGURATION & PORT LAYER
* (c) Copyright 2004-2009; Micrium, Inc.; Weston, FL
* CPU PORT FILE
* Win32
* Microsoft Visual Studio
* Filename : cpu_c.c
* Version : V1.21
* Programmer(s) : FGK
*****************************************************************************************/
#include <includes.h>
/*****************************************************************************************
* CPU_IntDis()
* Description : This function disables interrupts for critical sections of code.
* Argument(s) : none.
* Return(s) : none.
* Note(s) : none.
*****************************************************************************************/
void CPU_IntDis (void)
{
OSCriticalEnter();
}
/*****************************************************************************************
* CPU_IntEn()
* Description : This function enables interrupts after critical sections of code.
* Argument(s) : none.
* Return(s) : none.
* Note(s) : none.
*****************************************************************************************/
void CPU_IntEn (void)
{
OSCriticalExit();
}