📄 rtdbms.cpp
字号:
#include "common.h"
yxbw_buf_t yxbw_buf;// yx bw buffer used in nbb protocol
soe_buf_t soe_buf;// soe buffer for each port
memdb_data_t dbdata;
void rtdbmsinit(void)
{
memset(&dbdata, 0, sizeof(memdb_data_t));
}
void insert_soe(soe_record_t *ptr)
{
int i;
OS_ENTER_CRITICAL();
memcpy(&soe_buf.buf[soe_buf.write], ptr, sizeof(soe_record_t));
soe_buf.write++;
if (soe_buf.write >= YXBW_BUF_SIZE) soe_buf.write = 0;
// write pointer out of boundary
for (i = 0; i < MAX_PORT; i++) {
if (soe_buf.count[i] >= YXBW_BUF_SIZE) { // buffer overflow
soe_buf.read[i]++;
if (soe_buf.read[i] >= YXBW_BUF_SIZE) // drop lastest one
soe_buf.read[i] = 0;
}
else soe_buf.count[i]++;
}
OS_EXIT_CRITICAL();
}
// judge having soe or not
BOOLEAN is_soe(INT8U portno)
{
if (soe_buf.count[portno] == 0) return (FALSE);
else return (TRUE);
}
// get a soe from soe queue
void get_soe(INT8U portno, soe_record_t *ptr)
{
if (portno >= MAX_PORT) return; // only SLAVE protocol have soe
OS_ENTER_CRITICAL();
if (soe_buf.count[portno] > 0) {
memcpy(ptr, &soe_buf.buf[soe_buf.read[portno]], sizeof(soe_record_t));
soe_buf.read[portno]++;
soe_buf.count[portno]--; // decrease soe amount
if (soe_buf.read[portno] >= YXBW_BUF_SIZE)
soe_buf.read[portno] = 0; // read pointer out of boundary
}
OS_EXIT_CRITICAL();
}
INT16U get_soe_num(INT8U portno)
{
return (soe_buf.count[portno]);
}
INT16U get_yx_bw_num(INT8U portno)
{
return (yxbw_buf.count[portno]);
}
// insert a yxbw to yxbw queue
// new one overwrite old one
void insert_yx_bw(yxbw_record_t *ptr)
{
int i;
OS_ENTER_CRITICAL();
memcpy(&yxbw_buf.buf[yxbw_buf.write], ptr, sizeof(yxbw_record_t));
yxbw_buf.write++;
if (yxbw_buf.write >= YXBW_BUF_SIZE) yxbw_buf.write = 0;
// write pointer out of boundary
for (i = 0; i < MAX_PORT; i++) {
if (yxbw_buf.count[i] >= YXBW_BUF_SIZE) { // buffer overflow
yxbw_buf.read[i]++;
if (yxbw_buf.read[i] >= YXBW_BUF_SIZE) // drop lastest one
yxbw_buf.read[i] = 0;
}
else yxbw_buf.count[i]++;
}
OS_EXIT_CRITICAL();
}
// judge having yxbw or not
BOOLEAN is_yx_bw(INT8U portno)
{
if (yxbw_buf.count[portno] == 0) return (FALSE);
else return (TRUE);
}
// get a yxbw from yxbw queue
void get_yx_bw(INT8U portno, yxbw_record_t *ptr)
{
if (portno >= MAX_PORT) return; // only SLAVE protocol have soe
OS_ENTER_CRITICAL();
if (yxbw_buf.count[portno] > 0) {
memcpy(ptr, &yxbw_buf.buf[yxbw_buf.read[portno]], sizeof(yxbw_record_t));
yxbw_buf.read[portno]++;
yxbw_buf.count[portno]--; // decrease soe amount
if (yxbw_buf.read[portno] >= YXBW_BUF_SIZE)
yxbw_buf.read[portno] = 0; // read pointer out of boundary
}
OS_EXIT_CRITICAL();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -