feat: 添加CM3/4/7的硬件与软件浮点单元构建矩阵,变更api接口为dr_*
This commit is contained in:
+56
-56
@@ -6,70 +6,70 @@
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define DATAROUTER_WEAK __attribute__((weak))
|
||||
#define DR_WEAK __attribute__((weak))
|
||||
#else
|
||||
#define DATAROUTER_WEAK
|
||||
#define DR_WEAK
|
||||
#endif
|
||||
|
||||
#ifndef DATAROUTER_MAX_PORTS
|
||||
#define DATAROUTER_MAX_PORTS 64
|
||||
#ifndef DR_MAX_PORTS
|
||||
#define DR_MAX_PORTS 64
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int send_type;
|
||||
datarouter_send_handler_t handlers[DATAROUTER_MAX_HANDLERS_PER_PORT];
|
||||
dr_send_handler_t handlers[DR_MAX_HANDLERS_PER_PORT];
|
||||
int count;
|
||||
uint8_t in_use;
|
||||
} port_entry_t;
|
||||
|
||||
static port_entry_t ports[DATAROUTER_MAX_PORTS];
|
||||
static port_entry_t ports[DR_MAX_PORTS];
|
||||
static uint8_t initialized;
|
||||
|
||||
/* ---- 元数据 ---- */
|
||||
|
||||
static const char *send_names[] = {
|
||||
#define DATAROUTER_SEND(id, desc) #id,
|
||||
DATAROUTER_SEND_CAPABILITIES
|
||||
#undef DATAROUTER_SEND
|
||||
#define DR_SEND(id, desc) #id,
|
||||
DR_SEND_CAPABILITIES
|
||||
#undef DR_SEND
|
||||
};
|
||||
|
||||
static const char *send_descs[] = {
|
||||
#define DATAROUTER_SEND(id, desc) desc,
|
||||
DATAROUTER_SEND_CAPABILITIES
|
||||
#undef DATAROUTER_SEND
|
||||
#define DR_SEND(id, desc) desc,
|
||||
DR_SEND_CAPABILITIES
|
||||
#undef DR_SEND
|
||||
};
|
||||
|
||||
static const char *recv_names[] = {
|
||||
#define DATAROUTER_RECV(id, desc) #id,
|
||||
DATAROUTER_RECV_CAPABILITIES
|
||||
#undef DATAROUTER_RECV
|
||||
#define DR_RECV(id, desc) #id,
|
||||
DR_RECV_CAPABILITIES
|
||||
#undef DR_RECV
|
||||
};
|
||||
|
||||
static const char *recv_descs[] = {
|
||||
#define DATAROUTER_RECV(id, desc) desc,
|
||||
DATAROUTER_RECV_CAPABILITIES
|
||||
#undef DATAROUTER_RECV
|
||||
#define DR_RECV(id, desc) desc,
|
||||
DR_RECV_CAPABILITIES
|
||||
#undef DR_RECV
|
||||
};
|
||||
|
||||
/* ---- 弱符号接收回调 ---- */
|
||||
|
||||
#define DATAROUTER_RECV(id, desc) \
|
||||
DATAROUTER_WEAK void datarouter_on_recv_##id( \
|
||||
#define DR_RECV(id, desc) \
|
||||
DR_WEAK void dr_on_recv_##id( \
|
||||
uint32_t port_id, const void *data, size_t len) \
|
||||
{ (void)port_id; (void)data; (void)len; }
|
||||
DATAROUTER_RECV_CAPABILITIES
|
||||
#undef DATAROUTER_RECV
|
||||
DR_RECV_CAPABILITIES
|
||||
#undef DR_RECV
|
||||
|
||||
/* ---- 发送触发函数 ---- */
|
||||
|
||||
#define DATAROUTER_SEND(id, desc) \
|
||||
int datarouter_send_##id(const void *data, size_t len) \
|
||||
#define DR_SEND(id, desc) \
|
||||
int dr_send_##id(const void *data, size_t len) \
|
||||
{ \
|
||||
if (!initialized) return -1; \
|
||||
int called = 0; \
|
||||
for (uint32_t _p = 0; _p < DATAROUTER_MAX_PORTS; _p++) { \
|
||||
for (uint32_t _p = 0; _p < DR_MAX_PORTS; _p++) { \
|
||||
if (!ports[_p].in_use) continue; \
|
||||
if (ports[_p].send_type != DATAROUTER_SEND_##id) continue; \
|
||||
if (ports[_p].send_type != DR_SEND_##id) continue; \
|
||||
for (int _h = 0; _h < ports[_p].count; _h++) { \
|
||||
ports[_p].handlers[_h](_p, data, len); \
|
||||
called = 1; \
|
||||
@@ -77,74 +77,74 @@ DATAROUTER_RECV_CAPABILITIES
|
||||
} \
|
||||
return called ? 0 : -2; \
|
||||
}
|
||||
DATAROUTER_SEND_CAPABILITIES
|
||||
#undef DATAROUTER_SEND
|
||||
DR_SEND_CAPABILITIES
|
||||
#undef DR_SEND
|
||||
|
||||
/* ---- 端口管理 ---- */
|
||||
|
||||
void datarouter_init(void)
|
||||
void dr_init(void)
|
||||
{
|
||||
if (initialized) return;
|
||||
memset(ports, 0, sizeof(ports));
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
void datarouter_reset(void)
|
||||
void dr_reset(void)
|
||||
{
|
||||
initialized = 0;
|
||||
memset(ports, 0, sizeof(ports));
|
||||
}
|
||||
|
||||
datarouter_port_t datarouter_port_create(void)
|
||||
dr_port_t dr_port_create(void)
|
||||
{
|
||||
if (!initialized) return DATAROUTER_INVALID_PORT;
|
||||
for (int i = 0; i < DATAROUTER_MAX_PORTS; i++) {
|
||||
if (!initialized) return DR_INVALID_PORT;
|
||||
for (int i = 0; i < DR_MAX_PORTS; i++) {
|
||||
if (!ports[i].in_use) {
|
||||
ports[i].in_use = 1;
|
||||
ports[i].send_type = -1;
|
||||
ports[i].count = 0;
|
||||
return (datarouter_port_t)i;
|
||||
return (dr_port_t)i;
|
||||
}
|
||||
}
|
||||
return DATAROUTER_INVALID_PORT;
|
||||
return DR_INVALID_PORT;
|
||||
}
|
||||
|
||||
void datarouter_port_delete(datarouter_port_t port)
|
||||
void dr_port_delete(dr_port_t port)
|
||||
{
|
||||
if (!initialized) return;
|
||||
if (port < 0 || port >= DATAROUTER_MAX_PORTS) return;
|
||||
if (port < 0 || port >= DR_MAX_PORTS) return;
|
||||
ports[port].in_use = 0;
|
||||
}
|
||||
|
||||
void datarouter_port_set_send_type(datarouter_port_t port, int cap_id)
|
||||
void dr_port_set_send_type(dr_port_t port, int cap_id)
|
||||
{
|
||||
if (!initialized) return;
|
||||
if (port < 0 || port >= DATAROUTER_MAX_PORTS || !ports[port].in_use) return;
|
||||
if (port < 0 || port >= DR_MAX_PORTS || !ports[port].in_use) return;
|
||||
ports[port].send_type = cap_id;
|
||||
}
|
||||
|
||||
int datarouter_port_get_send_type(datarouter_port_t port)
|
||||
int dr_port_get_send_type(dr_port_t port)
|
||||
{
|
||||
if (!initialized) return -1;
|
||||
if (port < 0 || port >= DATAROUTER_MAX_PORTS || !ports[port].in_use) return -1;
|
||||
if (port < 0 || port >= DR_MAX_PORTS || !ports[port].in_use) return -1;
|
||||
return ports[port].send_type;
|
||||
}
|
||||
|
||||
int datarouter_port_add_handler(datarouter_port_t port, datarouter_send_handler_t handler)
|
||||
int dr_port_add_handler(dr_port_t port, dr_send_handler_t handler)
|
||||
{
|
||||
if (!initialized) return -1;
|
||||
if (port < 0 || port >= DATAROUTER_MAX_PORTS || !ports[port].in_use) return -1;
|
||||
if (ports[port].count >= DATAROUTER_MAX_HANDLERS_PER_PORT) return -2;
|
||||
if (port < 0 || port >= DR_MAX_PORTS || !ports[port].in_use) return -1;
|
||||
if (ports[port].count >= DR_MAX_HANDLERS_PER_PORT) return -2;
|
||||
for (int i = 0; i < ports[port].count; i++)
|
||||
if (ports[port].handlers[i] == handler) return -3;
|
||||
ports[port].handlers[ports[port].count++] = handler;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int datarouter_port_remove_handler(datarouter_port_t port, datarouter_send_handler_t handler)
|
||||
int dr_port_remove_handler(dr_port_t port, dr_send_handler_t handler)
|
||||
{
|
||||
if (!initialized) return -1;
|
||||
if (port < 0 || port >= DATAROUTER_MAX_PORTS || !ports[port].in_use) return -1;
|
||||
if (port < 0 || port >= DR_MAX_PORTS || !ports[port].in_use) return -1;
|
||||
for (int i = 0; i < ports[port].count; i++) {
|
||||
if (ports[port].handlers[i] == handler) {
|
||||
ports[port].handlers[i] = ports[port].handlers[--ports[port].count];
|
||||
@@ -154,26 +154,26 @@ int datarouter_port_remove_handler(datarouter_port_t port, datarouter_send_handl
|
||||
return -2;
|
||||
}
|
||||
|
||||
void datarouter_port_clear_handlers(datarouter_port_t port)
|
||||
void dr_port_clear_handlers(dr_port_t port)
|
||||
{
|
||||
if (!initialized) return;
|
||||
if (port < 0 || port >= DATAROUTER_MAX_PORTS || !ports[port].in_use) return;
|
||||
if (port < 0 || port >= DR_MAX_PORTS || !ports[port].in_use) return;
|
||||
ports[port].count = 0;
|
||||
}
|
||||
|
||||
int datarouter_port_handler_count(datarouter_port_t port)
|
||||
int dr_port_handler_count(dr_port_t port)
|
||||
{
|
||||
if (!initialized) return -1;
|
||||
if (port < 0 || port >= DATAROUTER_MAX_PORTS || !ports[port].in_use) return -1;
|
||||
if (port < 0 || port >= DR_MAX_PORTS || !ports[port].in_use) return -1;
|
||||
return ports[port].count;
|
||||
}
|
||||
|
||||
/* ---- 元数据查询 ---- */
|
||||
|
||||
int datarouter_send_cap_count(void) { return DATAROUTER_SEND_CAP_COUNT; }
|
||||
const char *datarouter_send_cap_name(int c) { return (c<0||c>=DATAROUTER_SEND_CAP_COUNT)?NULL:send_names[c]; }
|
||||
const char *datarouter_send_cap_desc(int c) { return (c<0||c>=DATAROUTER_SEND_CAP_COUNT)?NULL:send_descs[c]; }
|
||||
int dr_send_cap_count(void) { return DR_SEND_CAP_COUNT; }
|
||||
const char *dr_send_cap_name(int c) { return (c<0||c>=DR_SEND_CAP_COUNT)?NULL:send_names[c]; }
|
||||
const char *dr_send_cap_desc(int c) { return (c<0||c>=DR_SEND_CAP_COUNT)?NULL:send_descs[c]; }
|
||||
|
||||
int datarouter_recv_cap_count(void) { return DATAROUTER_RECV_CAP_COUNT; }
|
||||
const char *datarouter_recv_cap_name(int c) { return (c<0||c>=DATAROUTER_RECV_CAP_COUNT)?NULL:recv_names[c]; }
|
||||
const char *datarouter_recv_cap_desc(int c) { return (c<0||c>=DATAROUTER_RECV_CAP_COUNT)?NULL:recv_descs[c]; }
|
||||
int dr_recv_cap_count(void) { return DR_RECV_CAP_COUNT; }
|
||||
const char *dr_recv_cap_name(int c) { return (c<0||c>=DR_RECV_CAP_COUNT)?NULL:recv_names[c]; }
|
||||
const char *dr_recv_cap_desc(int c) { return (c<0||c>=DR_RECV_CAP_COUNT)?NULL:recv_descs[c]; }
|
||||
|
||||
Reference in New Issue
Block a user