/**
***************************************************************************************
* @file uCos-III(a os which support round robin scheduling)transplant Project/main.c
* @author Lx-technologies Team W.Long
* @version V0.1
* @date 10/10/2012
* @brief Main program body.(some of the notes in this project shows my own opinion)
* @hardware STM32F103RBT6 Cortex-M3(thumb2)
***************************************************************************************
* @copy
*
* <h2><center>© COPYRIGHT 2012 Lx-technologies Team </center></h2>
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "includes.h" /*we put it here*/
/* OS Variables --------------------------------------------------------------*/
/*OS TCB*/
static OS_TCB AppTaskStartTCB;
static OS_TCB task1TCB;
static OS_TCB task2TCB;
/*OS Stack*/
static CPU_STK AppTaskStartStk[128];
static CPU_STK task1Stk[128];
static CPU_STK task2Stk[128];
/*OS thread declaration*/
static void AppTaskStart(void* p_arg);
static void task1(void* p_arg);
static void task2(void* p_arg);
void SysTick_Configuration(void);
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
/* Private function prototypes -----------------------------------------------*/
void Delay(__IO uint32_t nCount);
void LED_Configuration();
void Handle_Led(unsigned char,unsigned char);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
OS_ERR err;
/*hardware initial*/
LED_Configuration(); /* Configure LED Pin */
OSInit(&err); /*Init uCOS-III*/
/*create a StartTask*/
OSTaskCreate( (OS_TCB *)&AppTaskStartTCB,
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR )AppTaskStart,
(void *)0,
(OS_PRIO )3,
(CPU_STK *)&AppTaskStartStk[0],
(CPU_STK_SIZE)12,
(CPU_STK_SIZE)128,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void *)0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
/*task scheduling start*/
OSStart(&err);
while(1); /*will never reach here*/
}
/**
*@brief task function body
*@param *p_arg:NULL
*@retval None
*@author Huawei technologies Co.Ltd W.Long
*/
static void AppTaskStart(void* p_arg)
{
CPU_INT32U cpu_clk_freq;
CPU_INT32U cnts;
OS_ERR err;
p_arg=p_arg; /*avoid warning*/
CPU_Init(); /*Initialize the uC/CPU service*/
cpu_clk_freq = BSP_CPU_ClkFreq(); /*Determine SysTick reference frequency*/
cnts = cpu_clk_freq/(CPU_INT32U)OSCfg_TickRate_Hz; /*Determine nbr SysTick increments*/
OS_CPU_SysTickInit(cnts); /*Initialize uC/OS periodic time source(System Tick)*/
/*Create user's task in here*/
OSTaskCreate( (OS_TCB *)&task1TCB, /*API explaination:task control block is a struct which is implemented in os.h*/
(CPU_CHAR *)"task1", /*task name*/
(OS_TASK_PTR )task1,
(void *)0,
(OS_PRIO )2, /*Priority of the task*/
(CPU_STK *)&task1Stk[0], /*stack of the task*/
(CPU_STK_SIZE)12,
(CPU_STK_SIZE)128,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void *)0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
/*we create task2 in here*/
OSTaskCreate( (OS_TCB *)&task2TCB,
(CPU_CHAR *)"task2",
(OS_TASK_PTR )task2,
(void *)0,
(OS_PRIO )2,
(CPU_STK *)&task2Stk[0],
(CPU_STK_SIZE)12,
(CPU_STK_SIZE)128,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void *)0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
while(1)
{
OSTimeDlyHMSM(0,0,0,999,OS_OPT_TIME_HMSM_STRICT,&err); /*dismiss the StartTask by suspending*/
}
}
/**
*@brief task1 function body
*@param *p_arg:NULL pointer
*@retval None
*@author Huawei technologies Co.Ltd W.Long
*/
static void task1(void *p_arg)
{
OS_ERR err;
p_arg=p_arg;
while(1)
{
Handle_Led(1,1);
OSTimeDlyHMSM(0,0,0,400,OS_OPT_TIME_HMSM_STRICT,&err);
Handle_Led(1,0);
OSTimeDlyHMSM(0,0,0,400,OS_OPT_TIME_HMSM_STRICT,&err);
}
}
static void task2(void *p_arg)
{
OS_ERR err;
p_arg=p_arg;
while(1)
{
Handle_Led(2,1);
OSTimeDlyHMSM(0,0,0,800,OS_OPT_TIME_HMSM_STRICT,&err);
Handle_Led(2,0);
OSTimeDlyHMSM(0,0,0,800,OS_OPT_TIME_HMSM_STRICT,&err);
}
}
/**
* @brief Inserts a delay time.
* @param nCount: specifies the delay time length.
* @retval None
*/
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
/* User functions ------------------------------------------------------------*/
/**
* @brief Initialize GPIO of LED
* @param none
* @retval none
* @programmer Huawei technologies Co.Ltd W.Long
*/
void LED_Configuration()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*turn off all of the led*/
GPIO_SetBits(GPIOA,GPIO_Pin_2 | GPIO_Pin_3);
GPIO_SetBits(GPIOB,GPIO_Pin_2);
}
/**
* @brief Set LED status
* @param Led_Num:the serial number of LED
* @param Status: 0 represents turning off the led,1 represents turning on the led
* @retval None
* @author Huawei technologies Co.Ltd software designer W.Long
*/
void Handle_Led(unsigned char Led_Num,unsigned char Status)
{
if(Status==1)
{
switch(Led_Num)
{
case 1:GPIO_ResetBits(GPIOA,GPIO_Pin_2);break;
case 2:GPIO_ResetBits(GPIOB,GPIO_Pin_2);break;
case 3:GPIO_ResetBits(GPIOA,GPIO_Pin_3);break;
default:break;
}
}
else
{
switch(Led_Num)
{
case 1:GPIO_SetBits(GPIOA,GPIO_Pin_2);break;
case 2:GPIO_SetBits(GPIOB,GPIO_Pin_2);break;
case 3:GPIO_SetBits(GPIOA,GPIO_Pin_3);break;
default:break;
}
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**
* @}
*/
/*
* @brief handle SystemInit missing error
* @param none
* @retval none
* @programmer:Huawei technologies Co.Ltd W.Long
*/
void SystemInit(void)
{
/*do nothing*/
}
/******************* (C) COPYRIGHT 2012 Lx technologies Co.Ltd *****END OF FILE****/
***************************************************************************************
* @file uCos-III(a os which support round robin scheduling)transplant Project/main.c
* @author Lx-technologies Team W.Long
* @version V0.1
* @date 10/10/2012
* @brief Main program body.(some of the notes in this project shows my own opinion)
* @hardware STM32F103RBT6 Cortex-M3(thumb2)
***************************************************************************************
* @copy
*
* <h2><center>© COPYRIGHT 2012 Lx-technologies Team </center></h2>
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "includes.h" /*we put it here*/
/* OS Variables --------------------------------------------------------------*/
/*OS TCB*/
static OS_TCB AppTaskStartTCB;
static OS_TCB task1TCB;
static OS_TCB task2TCB;
/*OS Stack*/
static CPU_STK AppTaskStartStk[128];
static CPU_STK task1Stk[128];
static CPU_STK task2Stk[128];
/*OS thread declaration*/
static void AppTaskStart(void* p_arg);
static void task1(void* p_arg);
static void task2(void* p_arg);
void SysTick_Configuration(void);
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
/* Private function prototypes -----------------------------------------------*/
void Delay(__IO uint32_t nCount);
void LED_Configuration();
void Handle_Led(unsigned char,unsigned char);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
OS_ERR err;
/*hardware initial*/
LED_Configuration(); /* Configure LED Pin */
OSInit(&err); /*Init uCOS-III*/
/*create a StartTask*/
OSTaskCreate( (OS_TCB *)&AppTaskStartTCB,
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR )AppTaskStart,
(void *)0,
(OS_PRIO )3,
(CPU_STK *)&AppTaskStartStk[0],
(CPU_STK_SIZE)12,
(CPU_STK_SIZE)128,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void *)0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
/*task scheduling start*/
OSStart(&err);
while(1); /*will never reach here*/
}
/**
*@brief task function body
*@param *p_arg:NULL
*@retval None
*@author Huawei technologies Co.Ltd W.Long
*/
static void AppTaskStart(void* p_arg)
{
CPU_INT32U cpu_clk_freq;
CPU_INT32U cnts;
OS_ERR err;
p_arg=p_arg; /*avoid warning*/
CPU_Init(); /*Initialize the uC/CPU service*/
cpu_clk_freq = BSP_CPU_ClkFreq(); /*Determine SysTick reference frequency*/
cnts = cpu_clk_freq/(CPU_INT32U)OSCfg_TickRate_Hz; /*Determine nbr SysTick increments*/
OS_CPU_SysTickInit(cnts); /*Initialize uC/OS periodic time source(System Tick)*/
/*Create user's task in here*/
OSTaskCreate( (OS_TCB *)&task1TCB, /*API explaination:task control block is a struct which is implemented in os.h*/
(CPU_CHAR *)"task1", /*task name*/
(OS_TASK_PTR )task1,
(void *)0,
(OS_PRIO )2, /*Priority of the task*/
(CPU_STK *)&task1Stk[0], /*stack of the task*/
(CPU_STK_SIZE)12,
(CPU_STK_SIZE)128,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void *)0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
/*we create task2 in here*/
OSTaskCreate( (OS_TCB *)&task2TCB,
(CPU_CHAR *)"task2",
(OS_TASK_PTR )task2,
(void *)0,
(OS_PRIO )2,
(CPU_STK *)&task2Stk[0],
(CPU_STK_SIZE)12,
(CPU_STK_SIZE)128,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void *)0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
while(1)
{
OSTimeDlyHMSM(0,0,0,999,OS_OPT_TIME_HMSM_STRICT,&err); /*dismiss the StartTask by suspending*/
}
}
/**
*@brief task1 function body
*@param *p_arg:NULL pointer
*@retval None
*@author Huawei technologies Co.Ltd W.Long
*/
static void task1(void *p_arg)
{
OS_ERR err;
p_arg=p_arg;
while(1)
{
Handle_Led(1,1);
OSTimeDlyHMSM(0,0,0,400,OS_OPT_TIME_HMSM_STRICT,&err);
Handle_Led(1,0);
OSTimeDlyHMSM(0,0,0,400,OS_OPT_TIME_HMSM_STRICT,&err);
}
}
static void task2(void *p_arg)
{
OS_ERR err;
p_arg=p_arg;
while(1)
{
Handle_Led(2,1);
OSTimeDlyHMSM(0,0,0,800,OS_OPT_TIME_HMSM_STRICT,&err);
Handle_Led(2,0);
OSTimeDlyHMSM(0,0,0,800,OS_OPT_TIME_HMSM_STRICT,&err);
}
}
/**
* @brief Inserts a delay time.
* @param nCount: specifies the delay time length.
* @retval None
*/
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
/* User functions ------------------------------------------------------------*/
/**
* @brief Initialize GPIO of LED
* @param none
* @retval none
* @programmer Huawei technologies Co.Ltd W.Long
*/
void LED_Configuration()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*turn off all of the led*/
GPIO_SetBits(GPIOA,GPIO_Pin_2 | GPIO_Pin_3);
GPIO_SetBits(GPIOB,GPIO_Pin_2);
}
/**
* @brief Set LED status
* @param Led_Num:the serial number of LED
* @param Status: 0 represents turning off the led,1 represents turning on the led
* @retval None
* @author Huawei technologies Co.Ltd software designer W.Long
*/
void Handle_Led(unsigned char Led_Num,unsigned char Status)
{
if(Status==1)
{
switch(Led_Num)
{
case 1:GPIO_ResetBits(GPIOA,GPIO_Pin_2);break;
case 2:GPIO_ResetBits(GPIOB,GPIO_Pin_2);break;
case 3:GPIO_ResetBits(GPIOA,GPIO_Pin_3);break;
default:break;
}
}
else
{
switch(Led_Num)
{
case 1:GPIO_SetBits(GPIOA,GPIO_Pin_2);break;
case 2:GPIO_SetBits(GPIOB,GPIO_Pin_2);break;
case 3:GPIO_SetBits(GPIOA,GPIO_Pin_3);break;
default:break;
}
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**
* @}
*/
/*
* @brief handle SystemInit missing error
* @param none
* @retval none
* @programmer:Huawei technologies Co.Ltd W.Long
*/
void SystemInit(void)
{
/*do nothing*/
}
/******************* (C) COPYRIGHT 2012 Lx technologies Co.Ltd *****END OF FILE****/