Kaynağa Gözat

change: netdrv,改变数据放入ram的宏声明

Wendal Chen 5 ay önce
ebeveyn
işleme
c6d66ab904

+ 8 - 0
components/network/netdrv/include/luat_netdrv.h

@@ -116,4 +116,12 @@ void luat_netdrv_netif_set_link_down(struct netif* netif);
 
 extern uint32_t g_netdrv_debug_enable;
 
+#ifndef __NETDRV_CODE_IN_RAM__
+#ifdef __LUAT_C_CODE_IN_RAM__
+#define __NETDRV_CODE_IN_RAM__ __LUAT_C_CODE_IN_RAM__
+#else
+#define __NETDRV_CODE_IN_RAM__
+#endif
+#endif
+
 #endif

+ 3 - 7
components/network/netdrv/src/luat_netdrv.c

@@ -11,10 +11,6 @@
 #define LUAT_LOG_TAG "netdrv"
 #include "luat_log.h"
 
-#ifndef __USER_FUNC_IN_RAM__
-#define __USER_FUNC_IN_RAM__ 
-#endif
-
 static luat_netdrv_t* drvs[NW_ADAPTER_QTY];
 
 uint32_t g_netdrv_debug_enable;
@@ -129,7 +125,7 @@ void luat_netdrv_print_pkg(const char* tag, uint8_t* buff, size_t len) {
 
 #define NAPT_CHKSUM_16BIT_LEN        sizeof(uint16_t)
 
-__USER_FUNC_IN_RAM__ uint32_t alg_hdr_16bitsum(const uint16_t *buff, uint16_t len)
+__NETDRV_CODE_IN_RAM__ uint32_t alg_hdr_16bitsum(const uint16_t *buff, uint16_t len)
 {
     uint32_t sum = 0;
 
@@ -150,7 +146,7 @@ __USER_FUNC_IN_RAM__ uint32_t alg_hdr_16bitsum(const uint16_t *buff, uint16_t le
     return sum;
 }
 
-__USER_FUNC_IN_RAM__ uint16_t alg_iphdr_chksum(const uint16_t *buff, uint16_t len)
+__NETDRV_CODE_IN_RAM__ uint16_t alg_iphdr_chksum(const uint16_t *buff, uint16_t len)
 {
     uint32_t sum = alg_hdr_16bitsum(buff, len);
 
@@ -160,7 +156,7 @@ __USER_FUNC_IN_RAM__ uint16_t alg_iphdr_chksum(const uint16_t *buff, uint16_t le
     return (uint16_t)(~sum);
 }
 
-__USER_FUNC_IN_RAM__ uint16_t alg_tcpudphdr_chksum(uint32_t src_addr, uint32_t dst_addr, uint8_t proto, const uint16_t *buff, uint16_t len)
+__NETDRV_CODE_IN_RAM__ uint16_t alg_tcpudphdr_chksum(uint32_t src_addr, uint32_t dst_addr, uint8_t proto, const uint16_t *buff, uint16_t len)
 {
     uint32_t sum = 0;
 

+ 1 - 5
components/network/netdrv/src/luat_netdrv_event.c

@@ -9,10 +9,6 @@
 #define LUAT_LOG_TAG "netdrv"
 #include "luat_log.h"
 
-#ifndef __USER_FUNC_IN_RAM__
-#define __USER_FUNC_IN_RAM__ 
-#endif
-
 netdrv_tcpevt_reg_t g_netdrv_tcpevt_regs[NW_ADAPTER_QTY] = {0};
 
 void luat_netdrv_register_tcp_event_cb(uint8_t id, uint8_t flags, luat_netdrv_tcp_evt_cb cb, void* userdata) {
@@ -32,7 +28,7 @@ void luat_netdrv_register_tcp_event_cb(uint8_t id, uint8_t flags, luat_netdrv_tc
 }
 
 
-__USER_FUNC_IN_RAM__ void luat_netdrv_fire_tcp_event(netdrv_tcp_evt_t* evt) {
+__NETDRV_CODE_IN_RAM__ void luat_netdrv_fire_tcp_event(netdrv_tcp_evt_t* evt) {
     if (evt == NULL || evt->id >= NW_ADAPTER_QTY) {
         LLOGE("TCP事件网络适配器ID无效 %d", evt ? evt->id : -1);
         return;

+ 8 - 12
components/network/netdrv/src/luat_netdrv_napt.c

@@ -46,10 +46,6 @@ luat_netdrv_napt_ctx_t *g_napt_udp_ctx;
 #define NAPT_ETH_HDR_LEN             sizeof(struct ethhdr)
 #define NAPT_CHKSUM_16BIT_LEN        sizeof(u16)
 
-#ifndef __USER_FUNC_IN_RAM__
-#define __USER_FUNC_IN_RAM__ 
-#endif
-
 static void check_it(const char* tag, luat_netdrv_napt_llist_t* it, luat_netdrv_napt_llist_t* prev, size_t id) {
     uint32_t tmp = (uint32_t)it;
     if (tmp == 0 || tmp > 0xc300000) {
@@ -58,11 +54,11 @@ static void check_it(const char* tag, luat_netdrv_napt_llist_t* it, luat_netdrv_
 }
 
 #if !defined(LUAT_USE_PSRAM) && !defined(LUAT_USE_NETDRV_NAPT)
-__USER_FUNC_IN_RAM__ int luat_netdrv_napt_pkg_input(int id, uint8_t* buff, size_t len) {
+__NETDRV_CODE_IN_RAM__ int luat_netdrv_napt_pkg_input(int id, uint8_t* buff, size_t len) {
     return 0;
 }
 #else
-__USER_FUNC_IN_RAM__ int luat_netdrv_napt_pkg_input(int id, uint8_t* buff, size_t len) {
+__NETDRV_CODE_IN_RAM__ int luat_netdrv_napt_pkg_input(int id, uint8_t* buff, size_t len) {
     if (s_gw_adapter_id < 0) {
         // LLOGD("NAPT 未开启");
         return 0; // NAPT没有开启
@@ -245,7 +241,7 @@ void luat_netdrv_napt_enable(int adapter_id) {
     }
     s_gw_adapter_id = adapter_id;
 }
-__USER_FUNC_IN_RAM__ static size_t luat_napt_tcp_port_alloc(luat_netdrv_napt_ctx_t *napt_ctx) {
+__NETDRV_CODE_IN_RAM__ static size_t luat_napt_tcp_port_alloc(luat_netdrv_napt_ctx_t *napt_ctx) {
     size_t offset;
     size_t soffset;
     for (size_t i = 0; i <= NAPT_PORT_RANGE_END - NAPT_PORT_RANGE_START; i++) {
@@ -274,7 +270,7 @@ static void print_item(const char* tag, luat_netdrv_napt_tcpudp_t* it) {
     LLOGD("%s %s:%d -> %s:%d local %d", tag, buff2, it->wnet_port, buff, it->inet_port, it->wnet_local_port);
 }
 
-__USER_FUNC_IN_RAM__ static void mapping_cleanup(luat_netdrv_napt_ctx_t *napt_ctx) {
+__NETDRV_CODE_IN_RAM__ static void mapping_cleanup(luat_netdrv_napt_ctx_t *napt_ctx) {
     uint64_t tnow = luat_mcu_tick64_ms();
     luat_netdrv_napt_tcpudp_t* it = NULL;
     uint64_t tdiff = 0;
@@ -334,7 +330,7 @@ __USER_FUNC_IN_RAM__ static void mapping_cleanup(luat_netdrv_napt_ctx_t *napt_ct
 }
 
 
-__USER_FUNC_IN_RAM__ static void update_tcp_stat_wnet(struct tcp_hdr *tcphdr, luat_netdrv_napt_tcpudp_t* t) {
+__NETDRV_CODE_IN_RAM__ static void update_tcp_stat_wnet(struct tcp_hdr *tcphdr, luat_netdrv_napt_tcpudp_t* t) {
     if ((TCPH_FLAGS(tcphdr) & (TCP_SYN|TCP_ACK)) == (TCP_SYN|TCP_ACK)) {
       t->synack = 1;
     //   LLOGD("收到TCP SYN ACK, 连接已建立");
@@ -352,7 +348,7 @@ __USER_FUNC_IN_RAM__ static void update_tcp_stat_wnet(struct tcp_hdr *tcphdr, lu
 //   LLOGD("TCP链路状态 synack %d fin1 %d finack2 %d rst %d", t->synack, t->fin1, t->finack2, t->rst);
 }
 
-__USER_FUNC_IN_RAM__ static void update_tcp_stat_inet(struct tcp_hdr *tcphdr, luat_netdrv_napt_tcpudp_t* t) {
+__NETDRV_CODE_IN_RAM__ static void update_tcp_stat_inet(struct tcp_hdr *tcphdr, luat_netdrv_napt_tcpudp_t* t) {
     if ((TCPH_FLAGS(tcphdr) & TCP_FIN))
         t->fin2 = 1;
     if (t->fin1 && (TCPH_FLAGS(tcphdr) & TCP_ACK))
@@ -363,7 +359,7 @@ __USER_FUNC_IN_RAM__ static void update_tcp_stat_inet(struct tcp_hdr *tcphdr, lu
 }
 
 // 外网到内网
-__USER_FUNC_IN_RAM__ int luat_netdrv_napt_tcp_wan2lan(napt_ctx_t* ctx, luat_netdrv_napt_tcpudp_t* mapping, luat_netdrv_napt_ctx_t *napt_ctx) {
+__NETDRV_CODE_IN_RAM__ int luat_netdrv_napt_tcp_wan2lan(napt_ctx_t* ctx, luat_netdrv_napt_tcpudp_t* mapping, luat_netdrv_napt_ctx_t *napt_ctx) {
     int ret = -1;
     uint16_t iphdr_len = (ctx->iphdr->_v_hl & 0x0F) * 4;
     // struct ip_hdr* ip_hdr = ctx->iphdr;
@@ -411,7 +407,7 @@ __USER_FUNC_IN_RAM__ int luat_netdrv_napt_tcp_wan2lan(napt_ctx_t* ctx, luat_netd
 }
 
 // 内网到外网
-__USER_FUNC_IN_RAM__ int luat_netdrv_napt_tcp_lan2wan(napt_ctx_t* ctx, luat_netdrv_napt_tcpudp_t* mapping, luat_netdrv_napt_ctx_t *napt_ctx) {
+__NETDRV_CODE_IN_RAM__ int luat_netdrv_napt_tcp_lan2wan(napt_ctx_t* ctx, luat_netdrv_napt_tcpudp_t* mapping, luat_netdrv_napt_ctx_t *napt_ctx) {
     int ret = -1;
     luat_netdrv_napt_tcpudp_t* it = NULL;
     uint16_t iphdr_len = (ctx->iphdr->_v_hl & 0x0F) * 4;

+ 1 - 5
components/network/netdrv/src/luat_netdrv_napt_tcp.c

@@ -22,11 +22,7 @@ extern luat_netdrv_napt_ctx_t *g_napt_tcp_ctx;
 #define u8 uint8_t
 #define NAPT_ETH_HDR_LEN             sizeof(struct ethhdr)
 
-#ifndef __USER_FUNC_IN_RAM__
-#define __USER_FUNC_IN_RAM__ 
-#endif
-
-__USER_FUNC_IN_RAM__ int luat_napt_tcp_handle(napt_ctx_t* ctx) {
+__NETDRV_CODE_IN_RAM__ int luat_napt_tcp_handle(napt_ctx_t* ctx) {
     uint16_t iphdr_len = (ctx->iphdr->_v_hl & 0x0F) * 4;
     struct ip_hdr* ip_hdr = ctx->iphdr;
     struct tcp_hdr *tcp_hdr = (struct tcp_hdr*)(((uint8_t*)ctx->iphdr) + iphdr_len);

+ 1 - 5
components/network/netdrv/src/luat_netdrv_napt_udp.c

@@ -19,12 +19,8 @@ extern luat_netdrv_napt_ctx_t *g_napt_udp_ctx;
 #define u8 uint8_t
 #define NAPT_ETH_HDR_LEN sizeof(struct ethhdr)
 
-#ifndef __USER_FUNC_IN_RAM__
-#define __USER_FUNC_IN_RAM__ 
-#endif
-
 static uint8_t *udp_buff;
-__USER_FUNC_IN_RAM__ int luat_napt_udp_handle(napt_ctx_t *ctx)
+__NETDRV_CODE_IN_RAM__ int luat_napt_udp_handle(napt_ctx_t *ctx)
 {
     uint16_t iphdr_len = (ctx->iphdr->_v_hl & 0x0F) * 4;
     struct ip_hdr *ip_hdr = ctx->iphdr;