first commit for opensource

first commit for opensource
This commit is contained in:
supowang
2019-09-16 13:19:50 +08:00
parent 08ab013b8e
commit edb2879617
6303 changed files with 5472815 additions and 23 deletions

View File

@@ -0,0 +1,89 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __CC_H__
#define __CC_H__
#include "cpu.h"
#include <stdlib.h>
#include <stdio.h>
typedef int sys_prot_t;
// #define LWIP_PROVIDE_ERRNO
#if defined (__GNUC__) & !defined (__CC_ARM)
#define LWIP_TIMEVAL_PRIVATE 0
#include <sys/time.h>
#endif
/* define compiler specific symbols */
#if defined (__ICCARM__)
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#define PACK_STRUCT_USE_INCLUDES
#elif defined (__GNUC__)
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#elif defined (__CC_ARM)
#define PACK_STRUCT_BEGIN __packed
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#elif defined (__TASKING__)
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#endif
#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \
x, __LINE__, __FILE__); } while(0)
/* Define random number generator function */
#define LWIP_RAND() ((u32_t)rand())
#endif /* __CC_H__ */

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __CPU_H__
#define __CPU_H__
#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#endif /* __CPU_H__ */

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __PERF_H__
#define __PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __PERF_H__ */

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2017 Simon Goldschmidt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Simon Goldschmidt
*
*/
#ifndef __SYS_ARCH_H__
#define __SYS_ARCH_H__
#include "lwip/opt.h"
#if (NO_SYS != 0)
#error "NO_SYS need to be set to 0 to use threaded API"
#endif
#include <tos.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SYS_MBOX_NULL (k_queue_t*)K_NULL
#define SYS_SEM_NULL (k_sem_t*)K_NULL
#define SYS_MRTEX_NULL (k_mutex_t*)K_NULL
typedef k_sem_t sys_sem_t;
typedef k_mutex_t sys_mutex_t;
typedef k_queue_t sys_mbox_t;
typedef k_task_t* sys_thread_t;
#ifdef __cplusplus
}
#endif
#endif /* __SYS_ARCH_H__ */

View File

@@ -0,0 +1,70 @@
/**
******************************************************************************
* File Name : ethernetif.h
* Description : This file provides initialization code for LWIP
* middleWare.
******************************************************************************
* This notice applies to any and all portions of this file
* that are not between comment pairs USER CODE BEGIN and
* USER CODE END. Other portions of this file, whether
* inserted by the user or by software development tools
* are owned by their respective copyright owners.
*
* Copyright (c) 2018 STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
#ifndef _ETHER_NETIF_DRV_H_
#define _ETHER_NETIF_DRV_H_
#include "lwip/err.h"
#include "lwip/netif.h"
#include "lwip/opt.h"
#include "lwip/pbuf.h"
typedef struct ethernetif_drv_st {
int (*init) (struct netif* netif);
int (*write)(struct netif *netif, struct pbuf *p);
struct pbuf * (*read)(struct netif *netif);
} ethernetif_drv_t;
int ethernetif_drv_register(ethernetif_drv_t *api);
err_t ethernetif_init(struct netif *netif);
void ethernetif_input(void *arg);
#endif

View File

@@ -0,0 +1,228 @@
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/*
* This file is a skeleton for developing Ethernet network interface
* drivers for lwIP. Add code to the low_level functions and do a
* search-and-replace for the word "ethernetif" to replace it with
* something that better describes your network interface.
*/
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/timeouts.h"
#include "netif/etharp.h"
#include "ethernetif.h"
#include "string.h"
/* Define those to better describe your network interface. */
#define IFNAME0 's'
#define IFNAME1 't'
static struct netif *the_netif = NULL;
static ethernetif_drv_t ethernetif_drv = { NULL };
int ethernetif_drv_register(ethernetif_drv_t *drv)
{
if (!drv) {
return ERR_ARG;
}
ethernetif_drv.init = drv->init;
ethernetif_drv.write = drv->write;
ethernetif_drv.read = drv->read;
return ERR_OK;
}
/**
* In this function, the hardware should be initialized.
* Called from ethernetif_init().
*
* @param netif the already initialized lwip network interface structure
* for this ethernetif
*/
static void ethernetif_drv_init(struct netif *netif)
{
if (ethernetif_drv.init) {
(void)ethernetif_drv.init(netif);
the_netif = netif;
}
}
/**
* This function should do the actual transmission of the packet. The packet is
* contained in the pbuf that is passed to the function. This pbuf
* might be chained.
*
* @param netif the lwip network interface structure for this ethernetif
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
* @return ERR_OK if the packet could be sent
* an err_t value if the packet couldn't be sent
*
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
* strange results. You might consider waiting for space in the DMA queue
* to become availale since the stack doesn't retry to send a packet
* dropped because of memory failure (except for the TCP timers).
*/
static err_t ethernetif_drv_write(struct netif *netif, struct pbuf *p)
{
err_t rc = ERR_IF;
if (ethernetif_drv.write) {
rc = ethernetif_drv.write(netif, p);
}
return rc;
}
/**
* Should allocate a pbuf and transfer the bytes of the incoming
* packet from the interface into the pbuf.
*
* @param netif the lwip network interface structure for this ethernetif
* @return a pbuf filled with the received packet (including MAC header)
* NULL on memory error
*/
static struct pbuf *ethernetif_drv_read(struct netif *netif)
{
struct pbuf *p = NULL;
if (ethernetif_drv.read) {
p = ethernetif_drv.read(netif);
}
return p;
}
#if !LWIP_ARP
/**
* This function has to be completed by user in case of ARP OFF.
*
* @param netif the lwip network interface structure for this ethernetif
* @return ERR_OK if ...
*/
static err_t low_level_output_arp_off(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr)
{
err_t errval;
errval = ERR_OK;
return errval;
}
#endif /* LWIP_ARP */
/**
* This function is the ethernetif_input task, it is processed when a packet
* is ready to be read from the interface. It uses the function ethernetif_drv_read()
* that should handle the actual reception of bytes from the network
* interface. Then the type of the received packet is determined and
* the appropriate input function is called.
*
* @param netif the lwip network interface structure for this ethernetif
*/
void ethernetif_input(void *arg)
{
err_t rc;
struct pbuf *p;
/* move received packet into a new pbuf */
do {
SYS_ARCH_DECL_PROTECT(sr);
SYS_ARCH_PROTECT(sr);
p = ethernetif_drv_read(the_netif);
SYS_ARCH_UNPROTECT(sr);
if (!p) {
return;
}
rc = the_netif->input(p, the_netif);
if (rc != ERR_OK) {
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
pbuf_free(p);
p = NULL;
}
} while (p);
}
/**
* Should be called at the beginning of the program to set up the
* network interface. It calls the function ethernetif_drv_init() to do the
* actual setup of the hardware.
*
* This function should be passed as a parameter to netif_add().
*
* @param netif the lwip network interface structure for this ethernetif
* @return ERR_OK if the loopif is initialized
* ERR_MEM if private data couldn't be allocated
* any other err_t on error
*/
err_t ethernetif_init(struct netif *netif)
{
LWIP_ASSERT("netif != NULL", (netif != NULL));
#if LWIP_NETIF_HOSTNAME
/* Initialize interface hostname */
netif->hostname = "lwip";
#endif /* LWIP_NETIF_HOSTNAME */
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call.
* You can instead declare your own function an call etharp_output()
* from it if you have to do some checks before sending (e.g. if link
* is available...) */
#if LWIP_IPV4
#if LWIP_ARP || LWIP_ETHERNET
#if LWIP_ARP
netif->output = etharp_output;
#else
/* The user should write ist own code in low_level_output_arp_off function */
netif->output = low_level_output_arp_off;
#endif /* LWIP_ARP */
#endif /* LWIP_ARP || LWIP_ETHERNET */
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */
netif->linkoutput = ethernetif_drv_write;
/* initialize the hardware */
ethernetif_drv_init(netif);
return ERR_OK;
}

View File

@@ -0,0 +1,327 @@
/*
* Copyright (c) 2017 Simon Goldschmidt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Simon Goldschmidt
*
*/
/* lwIP includes. */
#include "lwip/debug.h"
#include "lwip/def.h"
#include "lwip/sys.h"
#include "lwip/mem.h"
#include "lwip/stats.h"
#if !NO_SYS
#if defined(LWIP_PROVIDE_ERRNO)
int errno;
#endif
u32_t sys_jiffies(void)
{
return tos_systick_get();
}
u32_t sys_now(void)
{
return tos_systick_get();
}
void sys_init(void)
{
}
sys_prot_t sys_arch_protect(void)
{
TOS_CPU_CPSR_ALLOC();
TOS_CPU_INT_DISABLE();
return cpu_cpsr;
}
void sys_arch_unprotect(sys_prot_t cpu_cpsr)
{
TOS_CPU_INT_ENABLE();
}
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
{
k_err_t rc;
rc = tos_sem_create(sem, count);
#if SYS_STATS
++lwip_stats.sys.sem.used;
if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) {
lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
}
#endif
if (rc == K_ERR_NONE) {
return ERR_OK;
}
#if SYS_STATS
++lwip_stats.sys.sem.err;
#endif
printf("[sys_arch]:new sem fail!\n");
return ERR_MEM;
}
void sys_sem_free(sys_sem_t *sem)
{
#if SYS_STATS
--lwip_stats.sys.sem.used;
#endif
tos_sem_destroy(sem);
}
int sys_sem_valid(sys_sem_t *sem)
{
return sem->pend_obj.type == PEND_TYPE_SEM;
}
void sys_sem_set_invalid(sys_sem_t *sem)
{
sem->pend_obj.type = PEND_TYPE_NONE;
}
/*
<20><><EFBFBD><EFBFBD>timeout<75><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>򷵻<EFBFBD>ֵΪ
<20>ȴ<EFBFBD><C8B4>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѵĺ<D1B5><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20>ź<EFBFBD><C5BA><EFBFBD>δ<EFBFBD><CEB4>ָ<EFBFBD><D6B8>ʱ<EFBFBD><CAB1><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD>źţ<C5BA><C5A3><EFBFBD><EFBFBD><EFBFBD>ֵΪ
SYS_ARCH_TIMEOUT<55><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̲߳<DFB3><CCB2>صȴ<D8B5><C8B4>ź<EFBFBD><C5BA><EFBFBD>
<20>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㡣 */
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
{
k_tick_t wait_tick = 0;
k_tick_t start_tick = 0;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD><C5BA><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ч
if (sem == SYS_SEM_NULL) {
return SYS_ARCH_TIMEOUT;
}
//<2F><><EFBFBD>Ȼ<EFBFBD>ȡ<EFBFBD><C8A1>ʼ<EFBFBD>ȴ<EFBFBD><C8B4>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>
start_tick = sys_now();
//timeout != 0<><30><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ms<6D><73><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3>ʱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>
if (timeout != 0) {
//<2F><>msת<73><D7AA><EFBFBD><EFBFBD>ʱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>
wait_tick = timeout / (1000 / TOS_CFG_CPU_TICK_PER_SECOND);
if (wait_tick == 0) {
wait_tick = 1;
}
} else {
wait_tick = TOS_TIME_FOREVER; //һֱ<D2BB><D6B1><EFBFBD><EFBFBD>
}
//<2F>ȴ<EFBFBD><C8B4>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>ʱ<EFBFBD><EFBFBD><E4A3AC><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD>ʾ<EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>ʱ
if (tos_sem_pend(sem, wait_tick) == K_ERR_NONE) {
return ((sys_now() - start_tick) * (1000 / TOS_CFG_CPU_TICK_PER_SECOND));
}
return SYS_ARCH_TIMEOUT;
}
void sys_sem_signal(sys_sem_t *sem)
{
if (tos_sem_post(sem) != K_ERR_NONE) {
printf("[sys_arch]:sem signal fail!\n");
}
}
err_t sys_mutex_new(sys_mutex_t *mutex)
{
k_err_t rc;
rc = tos_mutex_create(mutex);
if (rc == K_ERR_NONE) {
return ERR_OK;
}
printf("[sys_arch]:new mutex fail!\n");
return ERR_MEM;
}
void sys_mutex_free(sys_mutex_t *mutex)
{
tos_mutex_destroy(mutex);
}
int sys_mutex_valid(sys_mutex_t *mutex)
{
return mutex->pend_obj.type == PEND_TYPE_MUTEX;
}
void sys_mutex_set_invalid(sys_mutex_t *mutex)
{
mutex->pend_obj.type = PEND_TYPE_NONE;
}
void sys_mutex_lock(sys_mutex_t *mutex)
{
tos_mutex_pend(mutex);
}
void sys_mutex_unlock(sys_mutex_t *mutex)
{
tos_mutex_post(mutex);
}
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn function, void *arg, int stacksize, int prio)
{
k_err_t rc;
sys_thread_t task;
k_stack_t *task_stack;
task = tos_mmheap_alloc(sizeof(k_task_t));
if (!task) {
printf("[sys_arch]:memalloc k_task_t fail!\n");
return NULL;
}
task_stack = tos_mmheap_alloc(stacksize);
if (!task_stack) {
printf("[sys_arch]:memalloc task stack fail!\n");
return NULL;
}
/* <20><><EFBFBD><EFBFBD>MidPriority_Task<73><6B><EFBFBD><EFBFBD> */
rc = tos_task_create(task, (char*)name, function, arg,
prio, task_stack, stacksize, 20);
if (rc != K_ERR_NONE) {
printf("[sys_arch]:create task fail! code: %d \r\n", rc);
return NULL;
}
return task;
}
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
{
k_err_t rc;
rc = tos_queue_create(mbox);
if (rc != K_ERR_NONE) {
printf("Create mbox fail! code : %d \r\n", rc);
return ERR_MEM;
}
return ERR_OK;
}
void sys_mbox_free(sys_mbox_t *mbox)
{
tos_queue_destroy(mbox);
}
int sys_mbox_valid(sys_mbox_t *mbox)
{
return mbox->pend_obj.type == PEND_TYPE_QUEUE;
}
void sys_mbox_set_invalid(sys_mbox_t *mbox)
{
mbox->pend_obj.type = PEND_TYPE_NONE;
}
void sys_mbox_post(sys_mbox_t *q, void *msg)
{
tos_queue_post(q, msg, sizeof(void *));
}
err_t sys_mbox_trypost(sys_mbox_t *q, void *msg)
{
if (tos_queue_post(q, msg, sizeof(void *)) == K_ERR_NONE) {
return ERR_OK;
}
return ERR_MEM;
}
err_t sys_mbox_trypost_fromisr(sys_mbox_t *q, void *msg)
{
return sys_mbox_trypost(q, msg);
}
u32_t sys_arch_mbox_fetch(sys_mbox_t *q, void **msg, u32_t timeout)
{
void *dummyptr;
k_tick_t wait_tick = 0;
k_tick_t start_tick = 0;
size_t size = sizeof(void *);
if (!msg) { // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B4A2>Ϣ<EFBFBD>ĵط<C4B5><D8B7>Ƿ<EFBFBD><C7B7><EFBFBD>Ч
msg = &dummyptr;
}
// <20><><EFBFBD>Ȼ<EFBFBD>ȡ<EFBFBD><C8A1>ʼ<EFBFBD>ȴ<EFBFBD><C8B4>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>
start_tick = sys_now();
// timeout != 0<><30><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ms<6D><73><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3>ʱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>
if (timeout != 0) {
//<2F><>msת<73><D7AA><EFBFBD><EFBFBD>ʱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>
wait_tick = timeout / (1000 / TOS_CFG_CPU_TICK_PER_SECOND);
if (wait_tick == 0) {
wait_tick = 1;
}
} else { // һֱ<D2BB><D6B1><EFBFBD><EFBFBD>
wait_tick = TOS_TIME_FOREVER;
}
// <20>ȴ<EFBFBD><C8B4>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>ʱ<EFBFBD><EFBFBD><E4A3AC><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD>ʾ<EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>ʱ
if (tos_queue_pend(q,&(*msg),&size, wait_tick) == K_ERR_NONE) {
return ((sys_now() - start_tick) * (1000 / TOS_CFG_CPU_TICK_PER_SECOND));
}
*msg = NULL;
return SYS_ARCH_TIMEOUT;
}
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *q, void **msg)
{
void *dummyptr;
size_t size = sizeof(void *);
if (!msg) {
msg = &dummyptr;
}
if (tos_queue_pend(q, &(*msg), &size, 0) == K_ERR_NONE) {
return ERR_OK;
}
return SYS_MBOX_EMPTY;
}
#endif /* !NO_SYS */