打印

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

[复制链接]
291|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
哈金|  楼主 | 2018-8-8 12:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
默认是提供了CMSIS-RTOS V1封装层接口和V2封装层接口
下面是V1接口实现,不愿意用封装层,直接用其它RTOS的原始API就行

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

#include "cmsis_os.h"
#include "rl_net_lib.h"

/* Avoid syntax-checker errors in editor */
#ifndef NET_THREAD_STACK_SIZE
  #define NET_THREAD_STACK_SIZE 1024
  #define NET_THREAD_PRIORITY   osPriorityNormal
#endif

#if (osCMSIS < 0x20000U)
  #define STATIC        static
#else
  #define STATIC
#endif

extern const osMutexDef_t os_mutex_def_net_lock;
extern const osMutexDef_t os_mutex_def_mem_lock;
extern const osTimerDef_t os_timer_def_net_tick;
extern const osThreadDef_t os_thread_def_netCore_Thread;
extern const osThreadDef_t os_thread_def_netETH_Thread;
extern const osThreadDef_t os_thread_def_netPPP_Thread;
extern const osThreadDef_t os_thread_def_netSLIP_Thread;
extern const osSemaphoreDef_t os_semaphore_def_eth0_lock;
extern const osSemaphoreDef_t os_semaphore_def_ppp_lock;
extern const osSemaphoreDef_t os_semaphore_def_slip_lock;

/* Network core resources */
STATIC osMutexDef(net_lock);
STATIC osMutexDef(mem_lock);
STATIC osTimerDef(net_tick, net_sys_tick);
       osThreadDef(netCore_Thread, NET_THREAD_PRIORITY, 1, NET_THREAD_STACK_SIZE);

/* Ethernet interface resources */
#if (ETH0_ENABLE)
STATIC osSemaphoreDef(eth0_lock);
       osThreadDef(netETH_Thread, ETH0_THREAD_PRIORITY, 1, ETH0_THREAD_STACK_SIZE);
#endif

/* PPP interface resources */
#if (PPP_ENABLE)
STATIC osSemaphoreDef(ppp_lock);
       osThreadDef(netPPP_Thread, PPP_THREAD_PRIORITY, 1, PPP_THREAD_STACK_SIZE);
#endif

/* SLIP interface resources */
#if (SLIP_ENABLE)
STATIC osSemaphoreDef(slip_lock);
       osThreadDef(netSLIP_Thread, SLIP_THREAD_PRIORITY, 1, SLIP_THREAD_STACK_SIZE);
#endif


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

/* Delete network thread */
void netos_thread_delete (NETOS_ID thread) {
  osThreadTerminate (thread);
}

/* Get running thread identifier */
NETOS_ID netos_thread_id (void) {
  return (osThreadGetId ());
}

/* Pass control to next ready thread */
void netos_thread_pass (void) {
  osThreadYield ();
}

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

/* Delete periodic tick timer */
void netos_timer_delete (NETOS_ID timer) {
  osTimerDelete (timer);
}

/* Start periodic tick timer */
void netos_timer_start (NETOS_ID timer, uint32_t interval_ms) {
  osTimerStart (timer, interval_ms);
}

/* Create network protection mutex */
NETOS_ID netos_mutex_create (uint8_t sys_id) {
  switch (sys_id) {
    case 0:  return (osMutexCreate (osMutex(net_lock)));
    default: return (osMutexCreate (osMutex(mem_lock)));
  }
}

/* Delete network protection mutex */
void netos_mutex_delete (NETOS_ID mutex) {
  osMutexDelete (mutex);
}

/* Lock network protection mutex */
void netos_lock (NETOS_ID mutex) {
  osMutexWait (mutex, osWaitForever);
}

/* Unlock network protection mutex */
void netos_unlock (NETOS_ID mutex) {
  osMutexRelease (mutex);
}

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

/* Set thread signal/event flag */
void netos_flag_set (NETOS_ID thread, uint32_t flag) {
  osSignalSet (thread, (int32_t)flag);
}

/* Clear thread signal/event flag */
void netos_flag_clear (NETOS_ID thread, uint32_t flag) {
  osSignalClear (thread, (int32_t)flag);
}

/* Delay thread execution */
void netos_delay (uint32_t ms) {
  osDelay (ms);
}

/* Create network interface thread and semaphore */
NETOS_ID netif_create (uint8_t netif, NETOS_ID *semaphore) {
  switch (netif) {
#if (ETH0_ENABLE)
    case  NETIF_ETH:
      *semaphore = osSemaphoreCreate (osSemaphore(eth0_lock), 1);
      return (osThreadCreate (osThread(netETH_Thread), NULL));
#endif
#if (PPP_ENABLE)
    case NETIF_PPP:
      *semaphore = osSemaphoreCreate (osSemaphore(ppp_lock), 1);
      return (osThreadCreate (osThread(netPPP_Thread), NULL));
#endif
#if (SLIP_ENABLE)
    case NETIF_SLIP:
      *semaphore = osSemaphoreCreate (osSemaphore(slip_lock), 1);
      return (osThreadCreate (osThread(netSLIP_Thread), NULL));
#endif
  }
  return (NULL);
}

/* Delete network interface thread and semaphore */
void netif_delete (NETOS_ID thread, NETOS_ID semaphore) {
  osSemaphoreDelete (semaphore);
  osThreadTerminate (thread);
}

/* Lock interface protection semaphore */
void netif_lock (NETOS_ID semaphore) {
  osSemaphoreWait (semaphore, osWaitForever);
}

/* Unlock interface protection semaphore */
void netif_unlock (NETOS_ID semaphore) {
  osSemaphoreRelease (semaphore);
}

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

432

主题

433

帖子

1

粉丝