#include
#include
#define ADC1_DR_Address ((u32)0x4001204C)
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/* ----------------- APPLICATION GLOBALS ------------------ */
static OS_TCB AppTaskStartTCB;
static OS_TCB AppTaskConfigTCB;
static OS_TCB AppTasktestsemTCB;
static CPU_STK AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE];
static CPU_STK AppTaskConfigStk[APP_CFG_TASK_START_STK_SIZE];
static CPU_STK AppTasktestsemStk[APP_CFG_TASK_START_STK_SIZE];
OS_SEM testsem;
OS_TMR MYTIMER1;
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg);
static void AppTaskCreate (void);
static void AppObjCreate (void);
static void userTaskStart (void);
static void userTasksem (void);
void MYCALLBACKFUNCT(void *p_arg) ;
/*
*********************************************************************************************************
* main()
*
* Description : This is the standard entry point for C code. It is assumed that your code will call
* main() once you have performed all necessary initialization.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* ?¨??????±???
*********************************************************************************************************
*/
CPU_FP32 AD_value_1,AD_value_2;
CPU_INT16U ADC_ConvertedValue[2];
/*********************************************************************************************************/
int main(void)
{
OS_ERR err;
BSP_IntDisAll(); /* Disable all interrupts. */
OSInit(&err); /* Init uC/OS-III. */
ADC1_CH6_DMA_Config(ADC1_DR_Address,ADC_ConvertedValue);
ADC_SoftwareStartConv(ADC1);
OSTaskCreate((OS_TCB *)&AppTaskStartTCB, /* Create the start task */
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR )AppTaskStart,
(void *)0,
(OS_PRIO )APP_CFG_TASK_START_PRIO,
(CPU_STK *)&AppTaskStartStk[0],
(CPU_STK_SIZE )AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE / 10],
(CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void *)0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSStart(&err); /* Start multitasking (i.e. give control to uC/OS-III). */
(void)&err;
return (0);
}
/*
*********************************************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
*
* Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
OS_ERR err;
(void)p_arg;
BSP_Init(); /* Initialize BSP functions */
CPU_Init(); /* Initialize the uC/CPU services */
BSP_Tick_Init(); /* Start Tick Initialization */
Mem_Init(); /* Initialize Memory Management Module */
Math_Init(); /* Initialize Mathematical Module */
#if OS_CFG_STAT_TASK_EN > 0u
OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_IntDisMeasMaxCurReset();
#endif
BSP_LED_Off(0);
#if (APP_CFG_SERIAL_EN == DEF_ENABLED)
App_SerialInit(); /* Initialize Serial Communication */
#endif
APP_TRACE_DBG(("Creating Application kernel objects\n\r"));
AppObjCreate(); /* Create Applicaiton kernel objects ???????ó??????????±ê?????à */
APP_TRACE_DBG(("Creating Application Tasks\n\r"));
AppTaskCreate(); /* Create Application tasks ???¨???ò???????? */
while (DEF_TRUE) { /* Task body, always written as an infinite loop. ???????÷?????ò??????while???·??? */
//BSP_LED_Toggle(0);
OSTimeDlyHMSM(0, 0, 0, 100,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
}
/*
*********************************************************************************************************
* AppTaskCreate()
*
* Description : Create application tasks.
*
* Argument(s) : none
*
* Return(s) : none
*
* Caller(s) : AppTaskStart()
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AppTaskCreate (void)
{
//BSP_LED_Toggle(1);
OS_ERR err;
OSTaskCreate((OS_TCB *)&AppTaskConfigTCB, /* Create the start task */
(CPU_CHAR *)"user task Start",
(OS_TASK_PTR )userTaskStart,
(void *)0,
(OS_PRIO )APP_USER_PRIO_3,
(CPU_STK *)&AppTaskConfigStk[0],
(CPU_STK_SIZE )AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE / 10],
(CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void *)0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
/********************check err is a must**** yj add************************************/
if(err != OS_ERR_NONE)
{
; //???í?ó???????í
}
OSTaskCreate((OS_TCB *)&AppTasktestsemTCB, /* Create the start task */
(CPU_CHAR *)"user sem Start",
(OS_TASK_PTR )userTasksem,
(void *)0,
(OS_PRIO )APP_USER_PRIO_4,
(CPU_STK *)&AppTasktestsemStk[0],
(CPU_STK_SIZE )AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE / 10],
(CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void *)0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
/********************check err is a must**** yj add************************************/
if(err != OS_ERR_NONE)
{
; //???í?ó???????í
}
OSSemCreate( &testsem,
"my testsem",
(OS_SEM_CTR)0,
&err);
if(err != OS_ERR_NONE)
{
; //???í?ó???????í
}
OSTmrCreate((OS_TMR *)&MYTIMER1,
(CPU_CHAR *)"TIME TEST",
(OS_TICK ) 0,
(OS_TICK ) 10,
(OS_OPT ) OS_OPT_TMR_PERIODIC,
(OS_TMR_CALLBACK_PTR ) MYCALLBACKFUNCT,
(void * )0,
(OS_ERR *)&err );
OSTmrStart((OS_TMR *)&MYTIMER1,
(OS_ERR *)&err);
while (DEF_TRUE) {
/* Task body, always written as an infinite loop. ???????÷?????ò??????while???·??? */
// BSP_LED_Toggle(2);
OSTimeDlyHMSM(0, 0, 0, 100,
OS_OPT_TIME_HMSM_STRICT,
&err);}
}
/*
*********************************************************************************************************
* AppObjCreate()
*
* Description : Create application kernel objects tasks.
*
* Argument(s) : none
*
* Return(s) : none
*
* Caller(s) : AppTaskStart()
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AppObjCreate (void)
{
}
static void userTaskStart(void) //???????????è???????©???÷
{
OS_ERR err;
CPU_TS ts;
while(DEF_ON){ //?????????????????·?
OSSemPend( &testsem,
10,
OS_OPT_PEND_BLOCKING,
&ts,
&err );
if(err == OS_ERR_NONE)
{
// ; //???í?ó???????í
BSP_LED_Toggle(1);
}
}
}
static void userTasksem(void) //???????????è???????©???÷
{
OS_ERR err;
// BSP_LED_Toggle(3);
while(DEF_TRUE){q
BSP_LED_Toggle(4);
OSSemPost( &testsem,
OS_OPT_POST_1,
&err ) ;
if(err != OS_ERR_NONE)
{
; //???í?ó???????í
}
OSTimeDlyHMSM(0, 0, 0, 100,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
}
void MYCALLBACKFUNCT(void *p_arg)
{
BSP_LED_Toggle(2);
}
我也是新手,在网上看了很多的资料感觉学习起来还是比较晦涩,对于新手来说,感觉还是直接贴出代码来给大家交流比较好。希望对入门的同学有用
硬件是stm32f407的discover开发板
阅读(1776) | 评论(0) | 转发(0) |