From eb35fef30d3c0ff4fc915b299ffb8d3e25074770 Mon Sep 17 00:00:00 2001 From: Jan Dolezal Date: Mon, 29 Jul 2013 17:47:56 +0200 Subject: [PATCH] HALCoGen+LwIP Demo for TMS570 (BE) - only files coppied --- src/arch/sys_arch.c | 31 ++++++++++++++++++++----------- src/include/arch/cc.h | 5 +++-- src/include/arch/lwipopts.h | 31 ++++++++++++++++--------------- src/include/arch/sys_arch.h | 37 ++++++++++++++++++++++--------------- src/include/lwip/opt.h | 2 +- 5 files changed, 62 insertions(+), 44 deletions(-) diff --git a/src/arch/sys_arch.c b/src/arch/sys_arch.c index 3724d0b7..efa3464f 100644 --- a/src/arch/sys_arch.c +++ b/src/arch/sys_arch.c @@ -49,17 +49,18 @@ /* For mutexes you can just set option in opt.h/lwipopts.h LWIP_COMPAT_MUTEX, * which is using defined semaphores. This is basicaly doing the same thing. */ +#if !LWIP_COMPAT_MUTEX /* Create a new mutex */ err_t sys_mutex_new(sys_mutex_t *mutex) { *mutex = xSemaphoreCreateMutex(); - if(mutex != NULL)return ERR_OK; + if(*mutex != NULL)return ERR_OK; return ERR_MEM; } /* locks a mutex */ void inline sys_mutex_lock(sys_mutex_t *mutex) { - xSemaphoreTake(*mutex,0); + xSemaphoreTake(*mutex,portMAX_DELAY); /* block time changed from 0 to portMAX_DELAY -- it might break timers! - just testing stability */ } /* unlocks a mutex */ void inline sys_mutex_unlock(sys_mutex_t *mutex) @@ -71,12 +72,13 @@ void inline sys_mutex_free(sys_mutex_t *mutex) { vSemaphoreDelete(*mutex); } +#endif /* creates a new semaphore */ err_t sys_sem_new(sys_sem_t *sem, u8_t count) { *sem = xSemaphoreCreateCounting( SEMPHR_MAX_CNT, count); /* it's supposedly possible to use vSemaphoreCreateBinary */ - if(sem != NULL)return ERR_OK; + if(*sem != NULL)return ERR_OK; return ERR_MEM; } /* signals a semaphore */ @@ -88,8 +90,15 @@ void inline sys_sem_signal(sys_sem_t *sem) u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) { portTickType ticksBeforeSemphr = xTaskGetTickCount(); - if(xSemaphoreTake( *sem, timeout / portTICK_RATE_MS ) == pdFALSE) /* note that it is important for the semaphores to return an accurate count of elapsed milliseconds, since they are used to schedule timers in lwIP */ - return SYS_ARCH_TIMEOUT; + if(timeout == 0) + { + xSemaphoreTake( *sem, portMAX_DELAY ); + } + else + { + if(xSemaphoreTake( *sem, timeout / portTICK_RATE_MS ) == pdFALSE) /* note that it is important for the semaphores to return an accurate count of elapsed milliseconds, since they are used to schedule timers in lwIP */ + return SYS_ARCH_TIMEOUT; + } return ( (xTaskGetTickCount() - ticksBeforeSemphr) / portTICK_RATE_MS ); /* return time spent waiting for the semaphore - u can use xTaskGetTickCount() */ } /* deletes a semaphore */ @@ -102,22 +111,22 @@ void inline sys_sem_free(sys_sem_t *sem) err_t sys_mbox_new(sys_mbox_t *mbox, int size) { *mbox = xQueueCreate( size, sizeof( MBOX_PTR_TYPE ) ); - if(mbox == 0)return ERR_MEM; + if(*mbox == NULL)return ERR_MEM; return ERR_OK; } /* posts the "msg" to the mailbox, blocks if mbox full */ void inline sys_mbox_post(sys_mbox_t *mbox, void *msg) { - while(xQueueSendToBack(*mbox, msg, portMAX_DELAY) == errQUEUE_FULL); + while(xQueueSendToBack(*mbox, &msg, portMAX_DELAY) == errQUEUE_FULL); } /* returns ERR_MEM if mailbox is full, ERR_OK if "msg" is posted */ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) { #if TRYPOST_ISR_SAFE signed portBASE_TYPE *pxHigherPriorityTaskWoken; - if(xQueueSendToBackFromISR( *mbox, msg, pxHigherPriorityTaskWoken ) == errQUEUE_FULL) + if(xQueueSendToBackFromISR( *mbox, &msg, pxHigherPriorityTaskWoken ) == errQUEUE_FULL) #else - if(xQueueSendToBack(*mbox, msg, 0) == errQUEUE_FULL) + if(xQueueSendToBack(*mbox, &msg, 0) == errQUEUE_FULL) #endif return ERR_MEM; return ERR_OK; @@ -138,7 +147,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) } return ( (xTaskGetTickCount() - ticksBeforeFetch) / portTICK_RATE_MS ); /* return time spent waiting for the space in the mailbox */ } -/* if message is not present immediately returns SYS_MBOX_EMPTY, on success returns 0 */ +/* if message is not present immediately returns SYS_MBOX_EMPTY, on success returns 0 ms */ u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) { #if TRYFETCH_ISR_SAFE @@ -203,7 +212,7 @@ u32_t sys_now(void) unsigned int IntMasterStatusGet (void) { - return 0;//(unsigned int)(0xC0 & _get_CPSR()); + return (unsigned int)(0xC0 & _get_CPSR()); } /** * This function is used to lock access to critical sections when lwipopt.h diff --git a/src/include/arch/cc.h b/src/include/arch/cc.h index e027ef4e..b22709ca 100644 --- a/src/include/arch/cc.h +++ b/src/include/arch/cc.h @@ -64,12 +64,12 @@ typedef u32_t mem_ptr_t; /*#endif*/ /* Define (sn)printf formatters for these lwIP types */ -/*#define U16_F "hu" +#define U16_F "hu" #define S16_F "hd" #define X16_F "hx" #define U32_F "u" #define S32_F "d" -#define X32_F "x"*/ +#define X32_F "x" #if defined(__arm__) && defined(__ARMCC_VERSION) @@ -117,6 +117,7 @@ typedef u32_t mem_ptr_t; /* TODO: make the debug work */ +//#define DEBUG #ifdef DEBUG #define LWIP_PLATFORM_DIAG(expr) diff --git a/src/include/arch/lwipopts.h b/src/include/arch/lwipopts.h index 392369d0..4ffd93fc 100644 --- a/src/include/arch/lwipopts.h +++ b/src/include/arch/lwipopts.h @@ -49,7 +49,7 @@ ** For Example, for IP Address 192.168.247.1, use the corresponding hex ** value 0xC0A8F701. */ -#define STATIC_IP_ADDRESS 0 +#define STATIC_IP_ADDRESS 1 /***************************************************************************** ** lwIP SPECIFIC DEFINITIONS - To be used by lwIP stack @@ -72,11 +72,11 @@ /***************************************************************************** ** Memory Options *****************************************************************************/ -#define MEM_ALIGNMENT 4 -#define MEM_SIZE (30 * 1024) /* 30K */ -#define MEMP_NUM_PBUF 48 -#define MEMP_NUM_TCP_PCB 16 -#define PBUF_POOL_SIZE 96 +#define MEM_ALIGNMENT 4 /* dflt 1 */ +#define MEM_SIZE 1600 // (30 * 1024) /* 30K */ /* dflt 1600 */ +#define MEMP_NUM_PBUF 16 // 48 /* dflt 16 */ +#define MEMP_NUM_TCP_PCB 5 // 16 /* dflt 5 */ +#define PBUF_POOL_SIZE 16 // 96 /* dflt 16 */ /***************************************************************************** ** IP Options @@ -87,7 +87,7 @@ /***************************************************************************** ** DHCP Options *****************************************************************************/ -#define LWIP_DHCP 1 +#define LWIP_DHCP 0 #define DHCP_DOES_ARP_CHECK 0 /***************************************************************************** @@ -101,8 +101,8 @@ /***************************************************************************** ** TCP Options *****************************************************************************/ -#define TCP_WND 4096 /* default is 2048 */ -#define TCP_MSS 1500 /* default is 128 */ +#define TCP_WND 2048 // 4096 /* default is 2048 */ +#define TCP_MSS 128 // 1500 /* default is 128 */ #define TCP_SND_BUF (4 * TCP_MSS) /***************************************************************************** @@ -112,7 +112,8 @@ #define PBUF_POOL_BUFSIZE 256 /* default is LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN)*/ #define ETH_PAD_SIZE 0 -#define LWIP_NETCONN 0 /*default is 1*/ +#define MEMP_NUM_NETCONN 10 +#define LWIP_NETCONN 1 /*default is 1*/ /***************************************************************************** ** Socket Options @@ -129,11 +130,11 @@ /***************************************************************************** ** Mbox options *****************************************************************************/ -#define TCPIP_MBOX_SIZE 20 -#define DEFAULT_RAW_RECVMBOX_SIZE 20 -#define DEFAULT_UDP_RECVMBOX_SIZE 20 -#define DEFAULT_TCP_RECVMBOX_SIZE 20 -#define DEFAULT_ACCEPTMBOX_SIZE 20 +#define TCPIP_MBOX_SIZE 10 +#define DEFAULT_RAW_RECVMBOX_SIZE 10 +#define DEFAULT_UDP_RECVMBOX_SIZE 10 +#define DEFAULT_TCP_RECVMBOX_SIZE 10 +#define DEFAULT_ACCEPTMBOX_SIZE 10 #endif /* __LWIPOPTS_H__ */ diff --git a/src/include/arch/sys_arch.h b/src/include/arch/sys_arch.h index 8615c205..d49f6c2f 100644 --- a/src/include/arch/sys_arch.h +++ b/src/include/arch/sys_arch.h @@ -63,22 +63,22 @@ typedef u8_t sys_prot_t; /* Typedefs for the various port-specific types. */ #if !NO_SYS -typedef xQueueHandle sys_mbox_t; -typedef xSemaphoreHandle sys_sem_t; -typedef xTaskHandle sys_thread_t; +typedef xQueueHandle sys_mbox_t; /* *xQUEUE */ +typedef xSemaphoreHandle sys_sem_t; /* *xQUEUE */ +typedef xTaskHandle sys_thread_t; /* *void */ #if !LWIP_COMPAT_MUTEX -typedef xSemaphoreHandle sys_mutex_t; +typedef xSemaphoreHandle sys_mutex_t; /* *xQUEUE */ /* For mutexes you can just set option in opt.h/lwipopts.h LWIP_COMPAT_MUTEX, * which is using defined semaphores. This is basicaly doing the same thing. */ #define sys_mutex_valid(mutex) sys_sem_valid(mutex) #define sys_mutex_set_invalid(mutex) sys_sem_set_invalid(mutex) +#endif /* LWIP_COMPAT_MUTEX */ -#define sys_sem_valid(sem) (*sem != SYS_SEM_NULL) +#define sys_sem_valid(sem) ((*sem != SYS_SEM_NULL) ? 1 : 0) #define sys_sem_set_invalid(sem) (*sem = SYS_SEM_NULL) -#define sys_mbox_valid(mbox) (*mbox != SYS_MBOX_NULL) +#define sys_mbox_valid(mbox) ((*mbox != SYS_MBOX_NULL) ? 1 : 0) #define sys_mbox_set_invalid(mbox) (*mbox = SYS_MBOX_NULL) -#endif #define SEMPHR_MAX_CNT 1 #define MBOX_PTR_TYPE void * @@ -87,10 +87,18 @@ typedef xSemaphoreHandle sys_mutex_t; #endif /* !NO_SYS */ -/* TODO: try with SYS_ARCH_PROTECT defined and without it */ -/* DETAILS in sys.h */ -/* #define SYS_ARCH_PROTECT */ -#ifndef SYS_ARCH_PROTECT +#ifdef SYS_TEST_PROT_SEM + +#define SYS_ARCH_DECL_PROTECT(lev) xSemaphoreHandle lev; lev = xSemaphoreCreateCounting(5,0) + +#define SYS_ARCH_PROTECT(lev) sys_sem_wait(&lev) + +#define SYS_ARCH_UNPROTECT(lev) sys_sem_signal(&lev) + +#endif + +/* when used SYS_ARCH_PROTECT from sys.h, then it might cause instability of the system */ +#ifdef SYS_ARCH_PROTECT #if SYS_LIGHTWEIGHT_PROT @@ -99,10 +107,10 @@ typedef xSemaphoreHandle sys_mutex_t; #define SYS_ARCH_PROTECT(lev) portENTER_CRITICAL() /* consider putting here taskENTER_CRITICAL() ... freeRTOS */ #define SYS_ARCH_UNPROTECT(lev) portEXIT_CRITICAL() /* consider putting here taskEXIT_CRITICAL() ... freeRTOS */ -sys_prot_t sys_arch_protect(void); -void sys_arch_unprotect(sys_prot_t pval); +//sys_prot_t sys_arch_protect(void); +//void sys_arch_unprotect(sys_prot_t pval); -#else +#else /* SYS_LIGHTWEIGHT_PROT */ #define SYS_ARCH_DECL_PROTECT(lev) #define SYS_ARCH_PROTECT(lev) @@ -113,6 +121,5 @@ void sys_arch_unprotect(sys_prot_t pval); #endif /* SYS_ARCH_PROTECT */ - #endif /* __ARCH_SYS_ARCH_H__ */ diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index e51f8e55..3b07b041 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -42,7 +42,7 @@ * Include user defined options first. Anything not defined in these files * will be set to standard values. Override anything you dont like! */ -#include "lwipopts.h" +#include "arch/lwipopts.h" #include "lwip/debug.h" /* -- 2.39.2