zoukankan      html  css  js  c++  java
  • 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 !
    ");
            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
    ",recvedEvent);
                    break;
                }
                case EV_MASTER_ERROR_RESPOND_TIMEOUT:
                {
                    ADBG_N(1000,"recv event 0x%x
    ",recvedEvent);
                    break;
                }
                case EV_MASTER_ERROR_RECEIVE_DATA:
                {
                    ADBG_N(1000,"recv event 0x%x
    ",recvedEvent);
                    break;
                }
                case EV_MASTER_ERROR_EXECUTE_FUNCTION:
                {
                    ADBG_N(1000,"recv event 0x%x
    ",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
  • 相关阅读:
    ThinkPHP5查询-select与find理解
    Gradle一分钟实现Spring-MVC
    CentOS 7 之Helloworld with c
    Python3学习之二Django搭建
    Python3学习之一环境搭建
    CentOS 7 之安装Mono&MonoDevelop
    CentOS 7 之Cisco Anyconnect Secure Mobility Client
    CentOS 7 之Shell学习笔记
    CentOS 7 之安装X Window System
    CentOS 7 之几个新特性(转)
  • 原文地址:https://www.cnblogs.com/mrsandstorm/p/5798290.html
Copyright © 2011-2022 走看看