加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
msg.hpp 4.53 KB
一键复制 编辑 原始数据 按行查看 历史
pengrui_2009 提交于 2018-12-06 19:09 . 1.modify some feature.
/*
* msg.h
*
* the header file of msg
*
* Copyright (C) 2002-2003 Stephen Rothwell, IBM Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef _MSG_H_
#define _MSG_H_
#include <stdint.h>
#include <semaphore.h> //sem_t
#include <pthread.h> //pthread_mutex
#include <time.h>
#include <sys/times.h>
#include "config.h"
#include "typedef.h"
/*************************************************
macros define
*************************************************/
//msg prio
#define MSG_PRIO_MIN 0 //lowest prio
#define MSG_PRIO_MAX 99 //highest prio
//msg block flag
#define MSG_RECV_BLOCK 0 //block recv
#define MSG_RECV_NONBLOCK 0xffff //noblock recv
#define CFG_MSG_REALSIZE (CFG_MSG_SIZE + 1)
/*************************************************
structs define
*************************************************/
class msg_t
{
public:
uint16_t type; //msg type
uint16_t wpara; //msg param
uint32_t lpara; //msg extend data
struct timespec time_spec;
uint32_t priv;
} ;
class msg_prio_t
{
msg_t msg;
uint8_t prio;
} ;
class msg_info_st
{
sem_t sem;
pthread_mutex_t mutex;
uint32_t head;
uint32_t tail;
msg_prio_t message[CFG_MSG_REALSIZE];
} ;
/*************************************************
global static variable
*************************************************/
class msg
{
public:
static int msg_inited;
static msg_info_st msg_info[CFG_MSG_MAX];
/******************************************************************************
* Function: msg_init
* Description: init msg
* Param: no
* Return: 0 - success
-ERR_SYS - system error
-ERR_BUSY - module opend
* Comment:
******************************************************************************/
static int msg_init(void);
/******************************************************************************
* Function: msg_send
* Description: send msg
* Param: id - msg id
msg - msg info
prio - msg prio(0 is lowest,99 is highest)
* Return: 0 - success
-ERR_SYS - system error
-ERR_NOINIT - no init
-ERR_NODEV - no device
-ERR_INVAL - invalid pram
-ERR_NOMEM - msg is full
* Comment:
******************************************************************************/
static int msg_send(uint8_t id, msg_t *msg, uint8_t prio);
/******************************************************************************
* Function: msg_recv
* Description: recv msg
* Param: id - msg id
msg - msg recv
timeout - timeout time(0:block, 0xffff:noblock, other:wait times second£©
* Return: 0 - success
-ERR_SYS - system error
-ERR_NODEV - no such msg queue
-ERR_NOINIT - no init
-ERR_TIMEOUT - timeout
* Comment:
******************************************************************************/
static int msg_recv(uint8_t id, msg_t *msg, uint16_t timeout);
/******************************************************************************
* Function: msg_recv_prio
* Description: recv msg with high prio
* Param: id - msg id
msg - msg info recv
timeout - timeout time (0:block,0xffff:noblock,other:wait second time)
* Return: 0 - success
-ERR_SYS - system error
-ERR_NODEV - no msg queue
-ERR_NOINIT - no init
-ERR_TIMEOUT - recv timeout
* Comment:
******************************************************************************/
static int msg_recv_prio(uint8_t id, msg_t *msg, uint16_t timeout);
/******************************************************************************
* Function: msg_clear
* Description: clear msg
* Param: id - msg id
* Return: 0 - success
-ERR_SYS - system error
-ERR_NODEV - no msg queue
-ERR_NOINIT - no init
* Comment:
******************************************************************************/
static int msg_clear(uint8_t id);
/******************************************************************************
* Function: msg_getsize
* Description: get msg count
* Param: id - msg id
* Return: >0 - msg size
-ERR_SYS - system error
-ERR_NODEV - no msg queue
-ERR_NOINIT - no init
* Comment:
******************************************************************************/
static int msg_getsize(uint8_t id);
} ;
#endif /* _MSG_H_ */
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化