Просмотр исходного кода

Fixed resource preemption due to high priority of pnet threads

kurisaw 1 год назад
Родитель
Сommit
1eae26f034

+ 60 - 4
osal/src/rtthread/sys/osal_cc.h

@@ -36,17 +36,73 @@ extern "C" {
 #define CC_FROM_LE32(x) ((uint32_t)(x))
 #define CC_FROM_LE64(x) ((uint64_t)(x))
 #define CC_TO_BE16(x)   ((uint16_t)__builtin_bswap16 (x))
-#define CC_TO_BE32(x)   ((uint32_t)__builtin_bswap32 (x))
-#define CC_TO_BE64(x)   ((uint64_t)__builtin_bswap64 (x))
+#if defined(__GNUC__) || defined(__clang__)
 #define CC_FROM_BE16(x) ((uint16_t)__builtin_bswap16 (x))
+#define CC_TO_BE32(x)   ((uint32_t)__builtin_bswap32 (x))
 #define CC_FROM_BE32(x) ((uint32_t)__builtin_bswap32 (x))
+#else
+#define CC_FROM_BE16(x)   ( \
+        (uint16_t)( \
+            (((x) & 0xFF00U) >> 8) | \
+            (((x) & 0x00FFU) << 8) \
+        ) \
+    )
+#define CC_TO_BE32(x)   ( \
+    (typeof(x)) ( \
+        ((x) & 0xFF000000U) >> 24 | \
+        ((x) & 0x00FF0000U) >> 8  | \
+        ((x) & 0x0000FF00U) << 8  | \
+        ((x) & 0x000000FFU) << 24 \
+    ) \
+)
+#define CC_FROM_BE32(x)   ( \
+    (typeof(x)) ( \
+        ((x) & 0xFF000000U) >> 24 | \
+        ((x) & 0x00FF0000U) >> 8  | \
+        ((x) & 0x0000FF00U) << 8  | \
+        ((x) & 0x000000FFU) << 24 \
+    ) \
+)
+#endif
+#define CC_TO_BE64(x)   ((uint64_t)__builtin_bswap64 (x))
 #define CC_FROM_BE64(x) ((uint64_t)__builtin_bswap64 (x))
 #else
+#if defined(__GNUC__) || defined(__clang__)
 #define CC_TO_LE16(x)   ((uint16_t)__builtin_bswap16 (x))
-#define CC_TO_LE32(x)   ((uint32_t)__builtin_bswap32 (x))
-#define CC_TO_LE64(x)   ((uint64_t)__builtin_bswap64 (x))
 #define CC_FROM_LE16(x) ((uint16_t)__builtin_bswap16 (x))
 #define CC_FROM_LE32(x) ((uint32_t)__builtin_bswap32 (x))
+#define CC_TO_LE32(x)   ((uint32_t)__builtin_bswap32 (x))
+#else
+#define CC_TO_LE16(x)   ( \
+        (uint16_t)( \
+            (((x) & 0xFF00U) >> 8) | \
+            (((x) & 0x00FFU) << 8) \
+        ) \
+    )
+#define CC_FROM_LE16(x)   ( \
+        (uint16_t)( \
+            (((x) & 0xFF00U) >> 8) | \
+            (((x) & 0x00FFU) << 8) \
+        ) \
+    )
+#define CC_FROM_LE32(x)   ( \
+    (typeof(x)) ( \
+        ((x) & 0xFF000000U) >> 24 | \
+        ((x) & 0x00FF0000U) >> 8  | \
+        ((x) & 0x0000FF00U) << 8  | \
+        ((x) & 0x000000FFU) << 24 \
+    ) \
+)
+#define CC_TO_LE32(x)   ( \
+    (typeof(x)) ( \
+        ((x) & 0xFF000000U) >> 24 | \
+        ((x) & 0x00FF0000U) >> 8  | \
+        ((x) & 0x0000FF00U) << 8  | \
+        ((x) & 0x000000FFU) << 24 \
+    ) \
+)
+#endif
+#define CC_TO_LE64(x)   ((uint64_t)__builtin_bswap64 (x))
 #define CC_FROM_LE64(x) ((uint64_t)__builtin_bswap64 (x))
 #define CC_TO_BE16(x)   ((uint16_t)(x))
 #define CC_TO_BE32(x)   ((uint32_t)(x))

+ 2 - 1
src/common/pf_lldp.c

@@ -1963,7 +1963,8 @@ int pf_lldp_recv (
    pnal_buf_t * p_frame_buf,
    uint16_t offset)
 {
-   uint8_t * buf = p_frame_buf->payload + offset;
+   // uint8_t * buf = p_frame_buf->payload + offset;
+   uint8_t * buf = (uint8_t *)(p_frame_buf->payload) + offset;
    uint16_t buf_len = p_frame_buf->len - offset;
    pf_lldp_peer_info_t peer_data;
    int err = 0;

+ 17 - 2
src/device/pf_cmwrr.c

@@ -214,8 +214,23 @@ static int pf_cmwrr_write (
          p_ar->arep);
    }
 
-   (void)subslot;
-   if (p_write_request->index <= PF_IDX_USER_MAX)
+   if (
+      (pf_cmdev_get_subslot_full (
+          net,
+          p_write_request->api,
+          p_write_request->slot_number,
+          p_write_request->subslot_number,
+          &subslot) == 0) &&
+      (((subslot->ownsm_state != PF_OWNSM_STATE_IOC) &&
+        (subslot->ownsm_state != PF_OWNSM_STATE_IOS)) ||
+       (subslot->owner != p_ar)))
+   {
+      p_result->pnio_status.error_code = PNET_ERROR_CODE_WRITE;
+      p_result->pnio_status.error_decode = PNET_ERROR_DECODE_PNIORW;
+      p_result->pnio_status.error_code_1 = PNET_ERROR_CODE_1_ACC_ACCESS_DENIED;
+      p_result->pnio_status.error_code_2 = 0;
+   }
+   else if (p_write_request->index <= PF_IDX_USER_MAX)
    {
       /* User defined indexes */
       ret = pf_fspm_cm_write_ind (

+ 53 - 17
src/ports/rtthread/pn_dev/sampleapp_main.c

@@ -26,6 +26,9 @@
 
 #include <string.h>
 
+#include <rtthread.h>
+#include <netdev.h>
+
 #ifdef RT_USING_DFS
 #include <dfs_fs.h>
 #include "dfs_ramfs.h"
@@ -39,7 +42,7 @@
 
 #define APP_LOG_LEVEL                  APP_LOG_LEVEL_DEBUG
 
-#define APP_BG_WORKER_THREAD_PRIORITY  6
+#define APP_BG_WORKER_THREAD_PRIORITY  26
 #define APP_BG_WORKER_THREAD_STACKSIZE 4096 /* bytes */
 
 /********************************** Globals ***********************************/
@@ -48,9 +51,37 @@ static app_data_t * sample_app = NULL;
 static pnet_cfg_t pnet_cfg = {0};
 app_args_t app_args = {0};
 
+static bool app_status = 0;
+
 /****************************** Main ******************************************/
 
-void pnet_main (void *param)
+static void pnet_app(void);
+
+static void netdev_status_callback(struct netdev *netdev, rt_bool_t up)
+{
+    if (up)
+    {
+        pnet_app();
+    }
+    else
+    {
+        return;
+    }
+}
+
+void netdev_monitor_init(void *param)
+{
+    struct netdev *netdev = netdev_get_by_name("e0");
+    if (netdev == RT_NULL)
+    {
+        APP_LOG_ERROR("Failed to get network device.\n");
+    }
+
+    netdev_set_status_callback(netdev, netdev_status_callback);
+}
+INIT_APP_EXPORT(netdev_monitor_init);
+
+void pnet_main ()
 {
    int ret;
    app_utils_netif_namelist_t netif_name_list;
@@ -117,23 +148,28 @@ void pnet_main (void *param)
    app_loop_forever (sample_app);
 }
 
-int pnet_app(void)
+static void pnet_app(void)
 {
+    if(app_status == 0)
+    {
 #if defined(PNET_USING_RAMFS)
-	rt_align(PNET_RAMFS_SIZE)
-   static char ramfs_buf[PNET_RAMFS_SIZE];
-   if (dfs_mount(RT_NULL, "/", "ram", 0, dfs_ramfs_create(ramfs_buf, PNET_RAMFS_SIZE)) == 0)
-   {
-      rt_kprintf("RAM file system initializated!\n");
-   }
-   else
-   {
-      rt_kprintf("RAM file system initializate failed!\n");
-   }
+        rt_align(PNET_RAMFS_SIZE)
+       static char ramfs_buf[PNET_RAMFS_SIZE];
+       if (dfs_mount(RT_NULL, "/", "ram", 0, dfs_ramfs_create(ramfs_buf, PNET_RAMFS_SIZE)) == 0)
+       {
+          rt_kprintf("RAM file system initializated!\n");
+       }
+       else
+       {
+          rt_kprintf("RAM file system initializate failed!\n");
+       }
 #endif
 
-    rt_thread_t pnet_thread = rt_thread_create("pnet", pnet_main, RT_NULL, 5124, 10, 10);
-    rt_thread_startup(pnet_thread);
-    return 0;
+        rt_thread_t pnet_thread = rt_thread_create("pnet", pnet_main, RT_NULL, 5124, 25, 10);
+        rt_thread_startup(pnet_thread);
+        app_status = 1;
+        return;
+    }
+
+    return;
 }
-MSH_CMD_EXPORT(pnet_app, pnet_app)