Demo entry 6661902

1215212

   

Submitted by anonymous on Nov 23, 2017 at 10:52
Language: C++. Code size: 13.7 kB.

/*
*********************************************************************************************************
*                                            EXAMPLE CODE
*
*               This file is provided as an example on how to use Micrium products.
*
*               Please feel free to use any application code labeled as 'EXAMPLE CODE' in
*               your application products.  Example code may be used as is, in whole or in
*               part, or may be used as a reference only. This file can be modified as
*               required to meet the end-product requirements.
*
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*
*               You can find our product's user manual, API reference, release notes and
*               more information at https://doc.micrium.com.
*               You can contact us at www.micrium.com.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                            EXAMPLE CODE
*
*                                     ST Microelectronics STM32
*                                              on the
*
*                                           STM3240G-EVAL
*                                         Evaluation Board
*
* Filename      : app.c
* Version       : V1.00
* Programmer(s) : DC
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                             INCLUDE FILES
*********************************************************************************************************
*/

#include  <stdarg.h>
#include  <stdio.h>
#include  <math.h>
#include  <stm32f4xx_hal.h>

#include  <cpu.h>
#include  <lib_math.h>
#include  <lib_mem.h>
#include  <os.h>

#include  <app_cfg.h>
#include  <bsp.h>
#include  <bsp_os.h>
#include  <serial_bsp_stm3240x.h>

/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/

                                                                /* --------------- APPLICATION GLOBALS ---------------- */
static  OS_STK       AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE];
                                                                /* --------------- SEMAPHORE TASK TEST ---------------- */
static  OS_STK       AppTask0Stk[APP_CFG_TASK_OBJ_STK_SIZE];

static  OS_STK       AppTask1Stk[APP_CFG_TASK_OBJ_STK_SIZE];

static  OS_STK       AppTask2Stk[APP_CFG_TASK_OBJ_STK_SIZE];
/*
*********************************************************************************************************
*                                         FUNCTION PROTOTYPES
*********************************************************************************************************
*/

static  void  AppTaskCreate  (void);

static  void  AppTaskStart   (void  *p_arg);

static  void  AppTask0  (void  *p_arg);
static  void  AppTask1  (void  *p_arg);
static  void  AppTask2  (void  *p_arg);

static  OS_EVENT    *AppSECMBox;
static  OS_EVENT    *AppMINMBox;
OS_EVENT    *AppUSARTSem;
OS_EVENT    *LEDSem;
/*
*********************************************************************************************************
*                                                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
*
* Notes       : 1) STM32F4xx HAL library initialization:
*                      a) Configures the Flash prefetch, intruction and data caches.
*                      b) Configures the Systick to generate an interrupt. However, the function ,
*                         HAL_InitTick(), that initializes the Systick has been overwritten since Micrium's
*                         RTOS has its own Systick initialization and it is recommended to initialize the
*                         Systick after multitasking has started.
*
*********************************************************************************************************
*/

int main(void)
{
    HAL_Init();                                                 /* See Note 1.                                          */

    BSP_IntDisAll();    
                                        /* Disable all Interrupts.                              */

    OSInit();                                                   /* Init uC/OS-II.                                       */

    OSTaskCreate( AppTaskStart,                              /* Create the start task                                */
                     0,
                    &AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE - 1],
                     APP_CFG_TASK_START_PRIO
				);
    OSStart();                                                  /* Start multitasking (i.e. give control to uC/OS-II).  */

    while (DEF_ON) {                                            /* Should Never Get Here.                               */
        ;
    }
}


/*
*********************************************************************************************************
*                                          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)
{
   (void)p_arg;

    BSP_Init();                                                 /* Initialize BSP functions                             */
    CPU_Init();                                                 /* Initialize the uC/CPU services                       */

//		App_SerialInit();                                           /* Initialize Serial Communication for Application ...  */

    AppTaskCreate();                                            /* Create Application tasks                             */

    BSP_LED_Off(0u);
	
	OSTaskDel(OS_PRIO_SELF);
}

/*
*********************************************************************************************************
*                                          AppTaskCreate()
*
* Description : Create Application Tasks.
*
* Argument(s) : none
*
* Return(s)   : none
*
* Caller(s)   : AppTaskStart()
*
* Note(s)     : none.
*********************************************************************************************************
*/

static  void  AppTaskCreate (void)
{
                                                                /* ----------- CREATE KERNEL TEST TASK ---------- */
    OSTaskCreate( AppTask0,
					0,
                    &AppTask0Stk[APP_CFG_TASK_OBJ_STK_SIZE - 1],
                     APP_CFG_TASK0_PRIO);


    OSTaskCreate( AppTask1,
                     0,
                    &AppTask1Stk[APP_CFG_TASK_OBJ_STK_SIZE - 1],
                     APP_CFG_TASK1_PRIO
                     );
	
		OSTaskCreate( AppTask2,
                     0,
                    &AppTask2Stk[APP_CFG_TASK_OBJ_STK_SIZE - 1],
                     APP_CFG_TASK2_PRIO
                     );
}

/*
*********************************************************************************************************
*                                          AppTask0()
*
* Description : Test uC/OS-II Events.
*
* Argument(s) : p_arg is the argument passed to 'AppTask0' by 'OSTaskCreate()'.
*
* Return(s)   : none
*
* Caller(s)   : This is a task
*
* Note(s)     : none.
*********************************************************************************************************
*/

void KEY_Init(void)
{
	GPIO_InitTypeDef  GPIO_InitStructure;
	
	
	uint8_t data[]="------------|2015021263|------------|          |------------";
	uint16_t temp = 0, i = 0, aa = 1;
	uint8_t dat[300] = {'0'};
	uint8_t kk = 1, mm = 0;
	for (i = 0; i <300; i+=5)
	{
		dat[i] = 0xFF;
		dat[i + 1] = temp;
		if(kk == 1) 	dat[i + 2] = 0;
		if(kk == 2)		dat[i + 2] = 1;
		if(kk == 3)   dat[i + 2] = 2;
		if(kk == 4)		dat[i + 2] = 3;
		if(kk == 5)		dat[i + 2] = 4;
		dat[i + 3] = data[mm];
		dat[i + 4] = 0x05;
		temp++;
		aa++;
		mm++;
		
		if(aa == 13)	
		{	
			kk = 2;
			temp = 0;
		}
		if(aa == 25) 
		{			
			kk = 3;
			temp = 0;
		}
		if (aa == 37)
		{
			kk = 4;
			temp = 0;
		}
		if (aa == 49)
		{
			kk = 5;
			temp = 0;
		}
		
		HAL_UART_Transmit_IT(&huart1,dat,300);
	}
	
	
	
	BSP_PeriphEn(BSP_PERIPH_ID_GPIOE); 					// ʹÄÜGPIOEʱÖÓ

	GPIO_InitStructure.Pin = DEF_BIT_02;				// KEY0¶ÔÓ¦Òý½Å
	GPIO_InitStructure.Mode = GPIO_MODE_INPUT;			// ÆÕͨÊäÈëģʽ
	GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;			// 100M
	GPIO_InitStructure.Pull = GPIO_PULLUP;				// ÉÏÀ­
	HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);			// ³õʼ»¯GPIOE2
} 

static  void  AppTask0 (void  *p_arg)
{
   CPU_INT08U  os_err;	
//	CPU_INT08U  Key_Value = 50;	
//	CPU_INT08U  fen = 0;
	CPU_INT08U  sec = 52;
	(void)p_arg;

	AppUSARTSem = OSSemCreate(1);	
	SerialBSP_Init();
	KEY_Init();
	
	LEDSem = OSSemCreate(1);
	AppSECMBox = OSMboxCreate(NULL);									// ´´½¨ÓÊÏä
    while (DEF_TRUE) {
		
		/*while(HAL_GPIO_ReadPin(GPIOE,DEF_BIT_02)==GPIO_PIN_SET)			// ÅжÏÊÇ·ñÓа´¼ü
		{
			OSTimeDly(2);												// ÑÓʱÊÍ·ÅCPUʹÓÃȨ£¬Ï൱ÓÚ10msѲ¼ìÒ»´Î
		}
		if((Key_Value += 50)==200)										// ÈýÖÖ²»Í¬µÄÑÓʱʱ¼ä
			Key_Value = 10;
		
		OSMboxPost(AppKeyMBox,&Key_Value);								// °´¼ü°´Ï£¬·¢ËÍÓÊÏä
		
		while(HAL_GPIO_ReadPin(GPIOE,DEF_BIT_02)==GPIO_PIN_RESET)		// ¼ì²â°´¼üµ¯Æð
		{
			OSTimeDly(2);												// ÑÓʱÊÍ·ÅCPUʹÓÃȨ£¬Ï൱ÓÚ10msѲ¼ìÒ»´Î
		}*/
//		OSMboxPost(AppKeyMBox,&fen);
	
		
		OSMboxPost(AppSECMBox,&sec);
		
		OSTimeDly(200);	
		sec++;
			if(sec == 60)
			{
				sec = 0;
			}
			
    }
}


/*
*********************************************************************************************************
*                                          AppTask1()
*
* Description : Test uC/OS-II events.
*
* Argument(s) : p_arg is the argument passed to 'AppTask1' by 'OSTaskCreate()'.
*
* Return(s)   : none
*
* Caller(s)   : This is a task
*
* Note(s)     : none.
*********************************************************************************************************
*/


void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
	OSSemPost(AppUSARTSem);
}

	
	
static  void  AppTask1 (void  *p_arg)
{
	CPU_INT08U  TIME;
	CPU_INT08U DAT = 12;
	CPU_INT08U  os_err;
	
//	CPU_INT08U i;
		CPU_INT08U tx_Buf[5]={0xff,0x00,0x03,'0',0x05};
    (void) p_arg;

    while (DEF_TRUE) {
	
		TIME = *(CPU_INT08U*)OSMboxPend(	(OS_EVENT  *)AppSECMBox,				// µÈ´ýÓÊÏä
												(INT32U     )0,
												(INT8U     *)&os_err);
		
		/*	BSP_LED_On(2);
			OSTimeDly(Key_Value);
			BSP_LED_Off(2); */
		
		OSSemPend(	(OS_EVENT  *)AppUSARTSem,				// µÈ´ýUART·¢ËÍÍê±Ï
					(INT32U     )0,
					(INT8U     *)&os_err);
		tx_Buf[1] =0x03;
		tx_Buf[3] = DAT/10+'0';
		
//		while(huart1.gState!=HAL_UART_STATE_READY);
		HAL_UART_Transmit_IT(&huart1, tx_Buf, 5);
		
		OSSemPend(	(OS_EVENT  *)AppUSARTSem,				// µÈ´ýUART·¢ËÍÍê±Ï
					(INT32U     )0,
					(INT8U     *)&os_err);
		tx_Buf[1] = 0x04;
		tx_Buf[3] = DAT%10+'0' ;
				if(TIME==59)
		{
			DAT++;
			if (DAT == 24) DAT = 0;
		}
//  	while(huart1.gState!=HAL_UART_STATE_READY);
		HAL_UART_Transmit_IT(&huart1, tx_Buf, 5);
		
		OSSemPend(	(OS_EVENT  *)AppUSARTSem,				// µÈ´ýUART·¢ËÍÍê±Ï
					(INT32U     )0,
					(INT8U     *)&os_err);
		tx_Buf[1] = 0x05;
		tx_Buf[3] = ':';
//		while(huart1.gState!=HAL_UART_STATE_READY);
		HAL_UART_Transmit_IT(&huart1, tx_Buf, 5); 
		
		OSSemPend(	(OS_EVENT  *)AppUSARTSem,				// µÈ´ýUART·¢ËÍÍê±Ï
					(INT32U     )0,
					(INT8U     *)&os_err);
		tx_Buf[1] = 0x06;
		tx_Buf[3] =TIME/10 + '0';
//		while(huart1.gState!=HAL_UART_STATE_READY);
		HAL_UART_Transmit_IT(&huart1, tx_Buf, 5); 
		
		OSSemPend(	(OS_EVENT  *)AppUSARTSem,				// µÈ´ýUART·¢ËÍÍê±Ï
					(INT32U     )0,
					(INT8U     *)&os_err);
		tx_Buf[1] = 0x07;
		tx_Buf[3] = TIME%10 + '0';
//		while(huart1.gState!=HAL_UART_STATE_READY);
		HAL_UART_Transmit_IT(&huart1, tx_Buf, 5); 
		if (TIME%5 == 0)	
		os_err = OSSemPost(LEDSem);
		
    }
}

static  void  AppTask2 (void  *p_arg)
{
	CPU_INT08U  os_err;
	(void)p_arg;
	while (DEF_TRUE) {
		OSSemPend((OS_EVENT  *)LEDSem,			
              (INT32U     )0,
              (INT8U     *)&os_err);	
		
		BSP_LED_On(1);
				OSTimeDlyHMSM(0u, 0u, 3u, 0u);
		BSP_LED_Off(1);
        OSTimeDlyHMSM(0u, 0u, 0u, 0u);
       
    }
	
}

This snippet took 0.02 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).