event 机制实验

 

 

#include <stdio.h>
//#include <stdint.h>

#include <board.h>

#include <rtthread.h>
#include <rthw.h>
#include <finsh.h>

#include "adbg.h"
#include "utils.h"
#include "stm32f10x.h"

#include "user_config.h"
#include "upstream_thread.h"
#include "receivefram_thread.h"



#include "led.h"
#include "tim.h"
#include "usart.h"
#include "io.h"


typedef enum
{
    MB_MRE_NO_ERR,                  /*!< no error. */
    MB_MRE_NO_REG,                  /*!< illegal register address. */
    MB_MRE_ILL_ARG,                 /*!< illegal argument. */
    MB_MRE_REV_DATA,                /*!< receive data error. */
    MB_MRE_TIMEDOUT,                /*!< timeout error occurred. */
    MB_MRE_MASTER_BUSY,             /*!< master is busy now. */
    MB_MRE_EXE_FUN                  /*!< execute function error. */
} eMBMasterReqErrCode;

typedef enum
{
    EV_MASTER_READY                    = 1<<0,  /*!< Startup finished. */
    EV_MASTER_FRAME_RECEIVED           = 1<<1,  /*!< Frame received. */
    EV_MASTER_EXECUTE                  = 1<<2,  /*!< Execute function. */
    EV_MASTER_FRAME_SENT               = 1<<3,  /*!< Frame sent. */
    EV_MASTER_ERROR_PROCESS            = 1<<4,  /*!< Frame error process. */
    EV_MASTER_PROCESS_SUCESS           = 1<<5,  /*!< Request process success. */
    EV_MASTER_ERROR_RESPOND_TIMEOUT    = 1<<6,  /*!< Request respond timeout. */
    EV_MASTER_ERROR_RECEIVE_DATA       = 1<<7,  /*!< Request receive data error. */
    EV_MASTER_ERROR_EXECUTE_FUNCTION   = 1<<8,  /*!< Request execute function error. */
} eMBMasterEventType;


#ifndef TRUE
#define TRUE            1
#endif
#ifndef FALSE
#define FALSE           0
#endif














static struct rt_event     xMasterOsEvent;


uint8_t 
xMBMasterPortEventInit( void )
{
    rt_event_init(&xMasterOsEvent,"master event",RT_IPC_FLAG_PRIO);
    return TRUE;
}

uint8_t
xMBMasterPortEventPost( eMBMasterEventType eEvent )
{
    rt_event_send(&xMasterOsEvent, eEvent);
    return TRUE;
}

void upstream_thread_entry(void *parameter)
{
    eMBMasterReqErrCode    eErrStatus = MB_MRE_NO_ERR;
    rt_uint32_t recvedEvent;
    
    rt_thread_delay(300);
    
    rt_event_init(&xMasterOsEvent,"master event",RT_IPC_FLAG_PRIO);
    
    while(1)
    {
        ADBG_N(1000,"recvedEvent Test !\n");
        rt_event_recv(&xMasterOsEvent,
                        EV_MASTER_PROCESS_SUCESS | EV_MASTER_ERROR_RESPOND_TIMEOUT
                        | EV_MASTER_ERROR_RECEIVE_DATA
                        | EV_MASTER_ERROR_EXECUTE_FUNCTION,
                        RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER,
                        &recvedEvent);
        switch (recvedEvent)
        {
            case EV_MASTER_PROCESS_SUCESS:
            {
                ADBG_N(1000,"recv event 0x%x\n",recvedEvent);
                break;
            }
            case EV_MASTER_ERROR_RESPOND_TIMEOUT:
            {
                ADBG_N(1000,"recv event 0x%x\n",recvedEvent);
                break;
            }
            case EV_MASTER_ERROR_RECEIVE_DATA:
            {
                ADBG_N(1000,"recv event 0x%x\n",recvedEvent);
                break;
            }
            case EV_MASTER_ERROR_EXECUTE_FUNCTION:
            {
                ADBG_N(1000,"recv event 0x%x\n",recvedEvent);
                break;
            }
        }
    }
}



void _test_send(uint32_t t)
{
    xMBMasterPortEventPost(t);
}

#ifdef RT_USING_FINSH
#include <finsh.h>
void test_event(uint32_t t)
{
    _test_send(t);
}
FINSH_FUNCTION_EXPORT(test_event, try to xMBMasterPortEventPost )
#endif

 

posted @ 2016-08-23 10:32  mrsandstorm  阅读(685)  评论(0编辑  收藏  举报