171 lines
4.0 KiB
C
171 lines
4.0 KiB
C
|
/****************************************************************
|
|||
|
* porting.h *
|
|||
|
* 2022-11-15 *
|
|||
|
****************************************************************/
|
|||
|
|
|||
|
#ifndef _PROTOCOL_PORTING_H_
|
|||
|
|
|||
|
#define _PROTOCOL_PORTING_H_
|
|||
|
|
|||
|
/* <20><><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD> */
|
|||
|
#include <stdlib.h>
|
|||
|
#include "stdint.h"
|
|||
|
#include <stdbool.h>
|
|||
|
#include "sys.h"
|
|||
|
|
|||
|
#define NELEMENTS(x) (sizeof(x)/sizeof((x)[0]))
|
|||
|
|
|||
|
#define _SUCCESS 0
|
|||
|
#define _FAILURE 1
|
|||
|
#define _OVERTIME 2
|
|||
|
#define _ABANDON 3
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
typedef struct {
|
|||
|
unsigned short deepth; /* <20>ܹ<EFBFBD><DCB9>ж<EFBFBD><D0B6><EFBFBD>Ԫ<EFBFBD><D4AA> */
|
|||
|
unsigned short occupy; /* <20><>ռ<EFBFBD><D5BC>Ԫ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD> */
|
|||
|
unsigned short stsize; /* ÿ<><C3BF>Ԫ<EFBFBD>صĴ<D8B5>С */
|
|||
|
void *array; /* <20><><EFBFBD>ŵĻ<C5B5><C4BB><EFBFBD> */
|
|||
|
void *limit; /* <20><><EFBFBD><EFBFBD>ĩβ */
|
|||
|
void *wp; /* дָ<D0B4><D6B8> */
|
|||
|
void *rp; /* <20><>ָ<EFBFBD><D6B8> */
|
|||
|
} st_fifo_t;
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @brief: <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>FIFO
|
|||
|
*
|
|||
|
*
|
|||
|
*/
|
|||
|
void sfifo_init(st_fifo_t *stfifo, void *array, unsigned short stsize, unsigned short deepth);
|
|||
|
|
|||
|
void sfifo_reset(st_fifo_t *stfifo);
|
|||
|
|
|||
|
|
|||
|
bool sfifo_write(st_fifo_t *stfifo, const void *stunit);
|
|||
|
|
|||
|
bool sfifo_empty(st_fifo_t *stfifo);
|
|||
|
|
|||
|
bool sfifo_full(st_fifo_t *stfifo);
|
|||
|
|
|||
|
unsigned int sfifo_read(st_fifo_t *stfifo,void *stunit);
|
|||
|
|
|||
|
unsigned int sfifo_occupy_get(st_fifo_t *stfifo);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#define QUEUEMEM unsigned char
|
|||
|
#define QUEUENODE struct node
|
|||
|
|
|||
|
typedef struct node{
|
|||
|
QUEUENODE *next;
|
|||
|
} NODE;
|
|||
|
|
|||
|
typedef struct {
|
|||
|
QUEUENODE *head;
|
|||
|
QUEUENODE *tail;
|
|||
|
unsigned short item;
|
|||
|
} QUEUE;
|
|||
|
|
|||
|
bool CreateQueue(QUEUE *que);
|
|||
|
unsigned short QueueItem(QUEUE *que);
|
|||
|
QUEUEMEM *QueueHead(QUEUE *que);
|
|||
|
QUEUEMEM *QueueTail(QUEUE *que);
|
|||
|
QUEUEMEM *QueueNext(QUEUEMEM *element);
|
|||
|
QUEUEMEM *DelQueueElement(QUEUE *que, QUEUEMEM *element);
|
|||
|
QUEUEMEM *DelQueueHead(QUEUE *que);
|
|||
|
QUEUEMEM *DelQueueTail(QUEUE *que);
|
|||
|
bool AppendQueue(QUEUE *que, QUEUEMEM *element);
|
|||
|
bool InsertBeforeQueue(QUEUE *que, QUEUEMEM *element,QUEUEMEM *curelement);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/* <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>صĽӿ<C4BD><D3BF><EFBFBD>ֲ */
|
|||
|
/*
|
|||
|
* void mem_cpy (void* dst, const void* src, int cnt); CAN_COPY
|
|||
|
* void mem_set (void* dst, int val, int cnt);
|
|||
|
* int mem_cmp (const void* dst, const void* src, int cnt);
|
|||
|
* void *mem_malloc(mem_size_t size);
|
|||
|
* void mem_free(void *mem);
|
|||
|
*/
|
|||
|
#define CAN_MALLOC(size) malloc(size)
|
|||
|
#define CAN_COPY(p_des, p_src, size) memcpy((p_des), (p_src), (size))
|
|||
|
#define CAN_CMPY(p_des, p_src, size) memcmp((p_des), (p_src), (size))
|
|||
|
#define CAN_FREE(p) free(p)
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*
|
|||
|
* <EFBFBD>źŵĻص<EFBFBD>
|
|||
|
* para:
|
|||
|
* signal: <EFBFBD>źű<EFBFBD>־
|
|||
|
* para1: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뷢<EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* para2: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뷢<EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
typedef void (*signal_callback)(unsigned int signal, int para1, int para2);
|
|||
|
|
|||
|
/*
|
|||
|
* \brief: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PID
|
|||
|
* \para:
|
|||
|
* signal: my_signal_e <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD>ź<EFBFBD>ֵ
|
|||
|
* para1,para2: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>my_kill <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>Ϣ<EFBFBD>ص<EFBFBD>֮<EFBFBD>䴫<EFBFBD>ݲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
int can_kill(unsigned int signal, unsigned int para1, unsigned int para2);
|
|||
|
|
|||
|
/*
|
|||
|
* \brief: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PID <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣsignal
|
|||
|
* \para:
|
|||
|
* signal: Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
* cb: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* \return:
|
|||
|
* 0-<EFBFBD>ɹ<EFBFBD> <0 ʧ<EFBFBD><EFBFBD>
|
|||
|
* \remark:
|
|||
|
* 1) my_signal_queue_create <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϢID<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>my_signal
|
|||
|
* 2) ͬһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>my_signal<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD>Ҫ<EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
int can_signal(unsigned int signal, signal_callback cb);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>CAN<EFBFBD>ź<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
typedef enum {
|
|||
|
E_CAN_SIGNAL_NULL = 0,
|
|||
|
E_CAN_MSG_SIG,
|
|||
|
E_CAN_MSG_CB_SIG, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>źŵķ<C5B5><C4B7>ͻص<CDBB> */
|
|||
|
E_CAN_15765_NET_SIG,
|
|||
|
E_CAN_15765_SS_SIG,
|
|||
|
} can_signal_e;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*************************************<2A><>ʱ<EFBFBD><CAB1>********************************************************/
|
|||
|
typedef unsigned int TIMER;
|
|||
|
typedef void (*can_tmr_func)(TIMER tmr_id); //<2F><>ʱִ<CAB1><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
TIMER can_timer_create(can_tmr_func cb);
|
|||
|
|
|||
|
void can_timer_remove(TIMER tmr);
|
|||
|
|
|||
|
void can_timer_start(TIMER tmr,unsigned int ms);
|
|||
|
|
|||
|
|
|||
|
void can_timer_stop(TIMER tmr);
|
|||
|
|
|||
|
bool can_timer_switch(TIMER tmr);
|
|||
|
|
|||
|
|
|||
|
#endif
|
|||
|
|
|||
|
|