硬汉嵌入式论坛

 找回密码
 立即注册
查看: 2591|回复: 0
收起左侧

[以太网] 新版的RL-TCPnet V7.X可以移植到各种RTOS下的net_rtos.h和net_rtos2.h接口文件

[复制链接]

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115691
QQ
发表于 2019-5-15 10:29:04 | 显示全部楼层 |阅读模式
默认是提供了CMSIS-RTOS V1封装层接口和V2封装层接口
下面是V1接口实现,不愿意用封装层,直接用其它RTOS的原始API就行

  1. /*------------------------------------------------------------------------------
  2. * MDK Middleware - Component ::Network
  3. * Copyright (c) 2004-2018 ARM Germany GmbH. All rights reserved.
  4. *------------------------------------------------------------------------------
  5. * Name:    net_rtos.h
  6. * Purpose: Network CMSIS-RTOS abstraction layer
  7. * Rev.:    V7.7.1
  8. *----------------------------------------------------------------------------*/

  9. #include "cmsis_os.h"
  10. #include "rl_net_lib.h"

  11. /* Avoid syntax-checker errors in editor */
  12. #ifndef NET_THREAD_STACK_SIZE
  13.   #define NET_THREAD_STACK_SIZE 1024
  14.   #define NET_THREAD_PRIORITY   osPriorityNormal
  15. #endif

  16. #if (osCMSIS < 0x20000U)
  17.   #define STATIC        static
  18. #else
  19.   #define STATIC
  20. #endif

  21. extern const osMutexDef_t os_mutex_def_net_lock;
  22. extern const osMutexDef_t os_mutex_def_mem_lock;
  23. extern const osTimerDef_t os_timer_def_net_tick;
  24. extern const osThreadDef_t os_thread_def_netCore_Thread;
  25. extern const osThreadDef_t os_thread_def_netETH_Thread;
  26. extern const osThreadDef_t os_thread_def_netPPP_Thread;
  27. extern const osThreadDef_t os_thread_def_netSLIP_Thread;
  28. extern const osSemaphoreDef_t os_semaphore_def_eth0_lock;
  29. extern const osSemaphoreDef_t os_semaphore_def_ppp_lock;
  30. extern const osSemaphoreDef_t os_semaphore_def_slip_lock;

  31. /* Network core resources */
  32. STATIC osMutexDef(net_lock);
  33. STATIC osMutexDef(mem_lock);
  34. STATIC osTimerDef(net_tick, net_sys_tick);
  35.        osThreadDef(netCore_Thread, NET_THREAD_PRIORITY, 1, NET_THREAD_STACK_SIZE);

  36. /* Ethernet interface resources */
  37. #if (ETH0_ENABLE)
  38. STATIC osSemaphoreDef(eth0_lock);
  39.        osThreadDef(netETH_Thread, ETH0_THREAD_PRIORITY, 1, ETH0_THREAD_STACK_SIZE);
  40. #endif

  41. /* PPP interface resources */
  42. #if (PPP_ENABLE)
  43. STATIC osSemaphoreDef(ppp_lock);
  44.        osThreadDef(netPPP_Thread, PPP_THREAD_PRIORITY, 1, PPP_THREAD_STACK_SIZE);
  45. #endif

  46. /* SLIP interface resources */
  47. #if (SLIP_ENABLE)
  48. STATIC osSemaphoreDef(slip_lock);
  49.        osThreadDef(netSLIP_Thread, SLIP_THREAD_PRIORITY, 1, SLIP_THREAD_STACK_SIZE);
  50. #endif


  51. /* Create network core thread */
  52. NETOS_ID netos_thread_create (void) {
  53.   return (osThreadCreate (osThread(netCore_Thread), NULL));
  54. }

  55. /* Delete network thread */
  56. void netos_thread_delete (NETOS_ID thread) {
  57.   osThreadTerminate (thread);
  58. }

  59. /* Get running thread identifier */
  60. NETOS_ID netos_thread_id (void) {
  61.   return (osThreadGetId ());
  62. }

  63. /* Pass control to next ready thread */
  64. void netos_thread_pass (void) {
  65.   osThreadYield ();
  66. }

  67. /* Create periodic tick timer */
  68. NETOS_ID netos_timer_create (void) {
  69.   return (osTimerCreate (osTimer(net_tick), osTimerPeriodic, NULL));
  70. }

  71. /* Delete periodic tick timer */
  72. void netos_timer_delete (NETOS_ID timer) {
  73.   osTimerDelete (timer);
  74. }

  75. /* Start periodic tick timer */
  76. void netos_timer_start (NETOS_ID timer, uint32_t interval_ms) {
  77.   osTimerStart (timer, interval_ms);
  78. }

  79. /* Create network protection mutex */
  80. NETOS_ID netos_mutex_create (uint8_t sys_id) {
  81.   switch (sys_id) {
  82.     case 0:  return (osMutexCreate (osMutex(net_lock)));
  83.     default: return (osMutexCreate (osMutex(mem_lock)));
  84.   }
  85. }

  86. /* Delete network protection mutex */
  87. void netos_mutex_delete (NETOS_ID mutex) {
  88.   osMutexDelete (mutex);
  89. }

  90. /* Lock network protection mutex */
  91. void netos_lock (NETOS_ID mutex) {
  92.   osMutexWait (mutex, osWaitForever);
  93. }

  94. /* Unlock network protection mutex */
  95. void netos_unlock (NETOS_ID mutex) {
  96.   osMutexRelease (mutex);
  97. }

  98. /* Wait for thread signal/event flag */
  99. void netos_flag_wait (uint32_t flag, uint32_t ms) {
  100.   osSignalWait ((int32_t)flag, ms);
  101. }

  102. /* Set thread signal/event flag */
  103. void netos_flag_set (NETOS_ID thread, uint32_t flag) {
  104.   osSignalSet (thread, (int32_t)flag);
  105. }

  106. /* Clear thread signal/event flag */
  107. void netos_flag_clear (NETOS_ID thread, uint32_t flag) {
  108.   osSignalClear (thread, (int32_t)flag);
  109. }

  110. /* Delay thread execution */
  111. void netos_delay (uint32_t ms) {
  112.   osDelay (ms);
  113. }

  114. /* Create network interface thread and semaphore */
  115. NETOS_ID netif_create (uint8_t netif, NETOS_ID *semaphore) {
  116.   switch (netif) {
  117. #if (ETH0_ENABLE)
  118.     case  NETIF_ETH:
  119.       *semaphore = osSemaphoreCreate (osSemaphore(eth0_lock), 1);
  120.       return (osThreadCreate (osThread(netETH_Thread), NULL));
  121. #endif
  122. #if (PPP_ENABLE)
  123.     case NETIF_PPP:
  124.       *semaphore = osSemaphoreCreate (osSemaphore(ppp_lock), 1);
  125.       return (osThreadCreate (osThread(netPPP_Thread), NULL));
  126. #endif
  127. #if (SLIP_ENABLE)
  128.     case NETIF_SLIP:
  129.       *semaphore = osSemaphoreCreate (osSemaphore(slip_lock), 1);
  130.       return (osThreadCreate (osThread(netSLIP_Thread), NULL));
  131. #endif
  132.   }
  133.   return (NULL);
  134. }

  135. /* Delete network interface thread and semaphore */
  136. void netif_delete (NETOS_ID thread, NETOS_ID semaphore) {
  137.   osSemaphoreDelete (semaphore);
  138.   osThreadTerminate (thread);
  139. }

  140. /* Lock interface protection semaphore */
  141. void netif_lock (NETOS_ID semaphore) {
  142.   osSemaphoreWait (semaphore, osWaitForever);
  143. }

  144. /* Unlock interface protection semaphore */
  145. void netif_unlock (NETOS_ID semaphore) {
  146.   osSemaphoreRelease (semaphore);
  147. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-12 05:12 , Processed in 0.188280 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表