Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2019-10-26 11:46:31 +0300
committerDavid Crocker <dcrocker@eschertech.com>2019-10-26 11:46:31 +0300
commit587f49d5699a6a0fc3cb8307e17dd5c2fa43f73b (patch)
tree311cc1342502b74cad2808ee6bf4e9cb66a7ac4c /src/Networking/LwipEthernet/Lwip
parentc25d73194252791ceb479ced79ffc77b31c810fe (diff)
Cached memory and Lwip networking changes
Put CAN, GMAC and some DMA buffers in new .ram_nocache memory section (needs new linker script in CoreNG) Added option to use separate Ethernet GMAC task (not working yet, so disabled - see LWIP_GMAC_TASK in compiler settings) Added code to set up non-cached memory usnig MPU (not working yet, so disabled)
Diffstat (limited to 'src/Networking/LwipEthernet/Lwip')
-rw-r--r--src/Networking/LwipEthernet/Lwip/lwipopts.h12
-rw-r--r--src/Networking/LwipEthernet/Lwip/src/core/sys.c105
-rw-r--r--src/Networking/LwipEthernet/Lwip/src/core/sys.cpp255
-rw-r--r--src/Networking/LwipEthernet/Lwip/src/include/arch/cc.h2
-rw-r--r--src/Networking/LwipEthernet/Lwip/src/include/arch/sys_arch.h10
-rw-r--r--src/Networking/LwipEthernet/Lwip/src/include/lwip/sys.h15
6 files changed, 278 insertions, 121 deletions
diff --git a/src/Networking/LwipEthernet/Lwip/lwipopts.h b/src/Networking/LwipEthernet/Lwip/lwipopts.h
index cd6e92a9..367f37c8 100644
--- a/src/Networking/LwipEthernet/Lwip/lwipopts.h
+++ b/src/Networking/LwipEthernet/Lwip/lwipopts.h
@@ -56,7 +56,11 @@
* use lwIP facilities.
* Uses Raw API only.
*/
-#define NO_SYS 1
+#ifndef LWIP_GMAC_TASK
+# error LWIP_GMAC_TASK must be defined in compiler settings
+#endif
+
+#define NO_SYS (!LWIP_GMAC_TASK)
/**
* LWIP_NETIF_STATUS_CALLBACK==1: Support a callback function whenever an interface
@@ -271,17 +275,19 @@ extern uint32_t trueRandom(void);
------------------------------------
*/
+#define FreeRtosIdlePriority 0
+
/** The stack sizes allocated to the netif stack: (256 * 4) = 1048 bytes. */
#define netifINTERFACE_TASK_STACK_SIZE 256
/** The priority of the netif stack. */
-#define netifINTERFACE_TASK_PRIORITY (tskIDLE_PRIORITY + 4)
+#define netifINTERFACE_TASK_PRIORITY (FreeRtosIdlePriority + 4) //TODO adjust
/** The stack sizes allocated to the TCPIP stack: (256 * 4) = 1048 bytes. */
#define TCPIP_THREAD_STACKSIZE 256
/** The priority of the TCPIP stack. */
-#define TCPIP_THREAD_PRIO (tskIDLE_PRIORITY + 5)
+#define TCPIP_THREAD_PRIO (FreeRtosIdlePriority + 5) //TODO adjust
/** The mailbox size for the tcpip thread messages */
#define TCPIP_MBOX_SIZE 16
diff --git a/src/Networking/LwipEthernet/Lwip/src/core/sys.c b/src/Networking/LwipEthernet/Lwip/src/core/sys.c
deleted file mode 100644
index d96efc8d..00000000
--- a/src/Networking/LwipEthernet/Lwip/src/core/sys.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * @file
- * lwIP Operating System abstraction
- *
- */
-
-/*
- * 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>
- *
- */
-
-/**
- * @defgroup sys_layer Porting (system abstraction layer)
- * @ingroup lwip
- * @verbinclude "sys_arch.txt"
- *
- * @defgroup sys_os OS abstraction layer
- * @ingroup sys_layer
- * No need to implement functions in this section in NO_SYS mode.
- *
- * @defgroup sys_sem Semaphores
- * @ingroup sys_os
- *
- * @defgroup sys_mutex Mutexes
- * @ingroup sys_os
- * Mutexes are recommended to correctly handle priority inversion,
- * especially if you use LWIP_CORE_LOCKING .
- *
- * @defgroup sys_mbox Mailboxes
- * @ingroup sys_os
- *
- * @defgroup sys_time Time
- * @ingroup sys_layer
- *
- * @defgroup sys_prot Critical sections
- * @ingroup sys_layer
- * Used to protect short regions of code against concurrent access.
- * - Your system is a bare-metal system (probably with an RTOS)
- * and interrupts are under your control:
- * Implement this as LockInterrupts() / UnlockInterrupts()
- * - Your system uses an RTOS with deferred interrupt handling from a
- * worker thread: Implement as a global mutex or lock/unlock scheduler
- * - Your system uses a high-level OS with e.g. POSIX signals:
- * Implement as a global mutex
- *
- * @defgroup sys_misc Misc
- * @ingroup sys_os
- */
-
-#include <Lwip/src/include/lwip/opt.h>
-#include <Lwip/src/include/lwip/sys.h>
-
-/* Most of the functions defined in sys.h must be implemented in the
- * architecture-dependent file sys_arch.c */
-
-#if !NO_SYS
-
-#ifndef sys_msleep
-/**
- * Sleep for some ms. Timeouts are NOT processed while sleeping.
- *
- * @param ms number of milliseconds to sleep
- */
-void
-sys_msleep(u32_t ms)
-{
- if (ms > 0) {
- sys_sem_t delaysem;
- err_t err = sys_sem_new(&delaysem, 0);
- if (err == ERR_OK) {
- sys_arch_sem_wait(&delaysem, ms);
- sys_sem_free(&delaysem);
- }
- }
-}
-#endif /* sys_msleep */
-
-#endif /* !NO_SYS */
diff --git a/src/Networking/LwipEthernet/Lwip/src/core/sys.cpp b/src/Networking/LwipEthernet/Lwip/src/core/sys.cpp
new file mode 100644
index 00000000..fed46104
--- /dev/null
+++ b/src/Networking/LwipEthernet/Lwip/src/core/sys.cpp
@@ -0,0 +1,255 @@
+/**
+ * @file
+ * lwIP Operating System abstraction
+ *
+ */
+
+/*
+ * 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>
+ *
+ */
+
+/**
+ * @defgroup sys_layer Porting (system abstraction layer)
+ * @ingroup lwip
+ * @verbinclude "sys_arch.txt"
+ *
+ * @defgroup sys_os OS abstraction layer
+ * @ingroup sys_layer
+ * No need to implement functions in this section in NO_SYS mode.
+ *
+ * @defgroup sys_sem Semaphores
+ * @ingroup sys_os
+ *
+ * @defgroup sys_mutex Mutexes
+ * @ingroup sys_os
+ * Mutexes are recommended to correctly handle priority inversion,
+ * especially if you use LWIP_CORE_LOCKING .
+ *
+ * @defgroup sys_mbox Mailboxes
+ * @ingroup sys_os
+ *
+ * @defgroup sys_time Time
+ * @ingroup sys_layer
+ *
+ * @defgroup sys_prot Critical sections
+ * @ingroup sys_layer
+ * Used to protect short regions of code against concurrent access.
+ * - Your system is a bare-metal system (probably with an RTOS)
+ * and interrupts are under your control:
+ * Implement this as LockInterrupts() / UnlockInterrupts()
+ * - Your system uses an RTOS with deferred interrupt handling from a
+ * worker thread: Implement as a global mutex or lock/unlock scheduler
+ * - Your system uses a high-level OS with e.g. POSIX signals:
+ * Implement as a global mutex
+ *
+ * @defgroup sys_misc Misc
+ * @ingroup sys_os
+ */
+
+extern "C" {
+
+#include <Lwip/src/include/lwip/opt.h>
+#include <Lwip/src/include/lwip/sys.h>
+
+}
+
+#if !NO_SYS
+
+#include <RTOSIface/RTOSIface.h>
+
+extern void delay(uint32_t ms);
+extern uint32_t millis();
+
+extern "C" {
+
+/* Most of the functions defined in sys.h must be implemented in the
+ * architecture-dependent file sys_arch.c */
+
+/* sys_init() must be called before anything else. */
+void sys_init()
+{
+ // nothing needed yet
+}
+
+/**
+ * @ingroup sys_mutex
+ * Create a new mutex.
+ * Note that mutexes are expected to not be taken recursively by the lwIP code,
+ * so both implementation types (recursive or non-recursive) should work.
+ * @param mutex pointer to the mutex to create
+ * @return ERR_OK if successful, another err_t otherwise
+ */
+err_t sys_mutex_new(sys_mutex_t *mutex)
+{
+ mutex->m = new Mutex;
+ mutex->m->Create("LWIP"); // note, this will give duplicate mutex names but we can't help that
+ return ERR_OK;
+}
+
+/**
+ * @ingroup sys_mutex
+ * Lock a mutex
+ * @param mutex the mutex to lock
+ */
+void sys_mutex_lock(sys_mutex_t *mutex)
+{
+ mutex->m->Take();
+}
+
+/**
+ * @ingroup sys_mutex
+ * Unlock a mutex
+ * @param mutex the mutex to unlock
+ */
+void sys_mutex_unlock(sys_mutex_t *mutex)
+{
+ mutex->m->Release();
+}
+
+/* Mailbox functions. */
+
+/**
+ * @ingroup sys_mbox
+ * Create a new mbox of specified size
+ * @param mbox pointer to the mbox to create
+ * @param size (minimum) number of messages in this mbox
+ * @return ERR_OK if successful, another err_t otherwise
+ */
+err_t sys_mbox_new(sys_mbox_t *mbox, int size)
+{
+ auto q = new Queue<void *>;
+ q->Create("LWIP", size);
+ mbox->m = q;
+ return (q->IsValid()) ? ERR_OK : ERR_MEM;
+}
+
+/**
+ * @ingroup sys_mbox
+ * Post a message to an mbox - may not fail
+ * -> blocks if full, only used from tasks not from ISR
+ * @param mbox mbox to posts the message
+ * @param msg message to post (ATTENTION: can be NULL)
+ */
+void sys_mbox_post(sys_mbox_t *mbox, void *msg)
+{
+ static_cast<Queue<void*>*>(mbox->m)->PutToBack(msg, Mutex::TimeoutUnlimited);
+}
+
+/**
+ * @ingroup sys_mbox
+ * Try to post a message to an mbox - may fail if full or ISR
+ * @param mbox mbox to posts the message
+ * @param msg message to post (ATTENTION: can be NULL)
+ */
+err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
+{
+ return (static_cast<Queue<void*>*>(mbox->m)->PutToBack(msg, 0)) ? ERR_OK : ERR_WOULDBLOCK;
+}
+
+/**
+ * @ingroup sys_mbox
+ * Wait for a new message to arrive in the mbox
+ * @param mbox mbox to get a message from
+ * @param msg pointer where the message is stored
+ * @param timeout maximum time (in milliseconds) to wait for a message (0 = wait forever)
+ * @return time (in milliseconds) waited for a message, may be 0 if not waited
+ or SYS_ARCH_TIMEOUT on timeout
+ * The returned time has to be accurate to prevent timer jitter!
+ */
+u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
+{
+ const uint32_t now = millis();
+ return ((static_cast<Queue<void*>*>(mbox->m)->Get(*msg, timeout)))
+ ? millis() - now
+ : SYS_ARCH_TIMEOUT;
+}
+
+/**
+ * @ingroup sys_mbox
+ * Wait for a new message to arrive in the mbox
+ * @param mbox mbox to get a message from
+ * @param msg pointer where the message is stored
+ * @return 0 (milliseconds) if a message has been received
+ * or SYS_MBOX_EMPTY if the mailbox is empty
+ */
+u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
+{
+ return ((static_cast<Queue<void*>*>(mbox->m)->Get(*msg, 0)))
+ ? 0
+ : SYS_MBOX_EMPTY;
+}
+
+/**
+ * @ingroup sys_mbox
+ * Delete an mbox
+ * @param mbox mbox to delete
+ */
+void sys_mbox_free(sys_mbox_t *mbox);
+
+/**
+ * @ingroup sys_mbox
+ * Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid
+ */
+int sys_mbox_valid(sys_mbox_t *mbox);
+
+/**
+ * @ingroup sys_mbox
+ * Set an mbox invalid so that sys_mbox_valid returns 0
+ */
+void sys_mbox_set_invalid(sys_mbox_t *mbox);
+
+#ifndef sys_mbox_valid_val
+/**
+ * Same as sys_mbox_valid() but taking a value, not a pointer
+ */
+#define sys_mbox_valid_val(mbox) sys_mbox_valid(&(mbox))
+#endif
+#ifndef sys_mbox_set_invalid_val
+/**
+ * Same as sys_mbox_set_invalid() but taking a value, not a pointer
+ */
+#define sys_mbox_set_invalid_val(mbox) sys_mbox_set_invalid(&(mbox))
+#endif
+
+
+/**
+ * Sleep for some ms. Timeouts are NOT processed while sleeping.
+ *
+ * @param ms number of milliseconds to sleep
+ */
+void sys_msleep(u32_t ms)
+{
+ delay(ms);
+}
+
+}
+
+#endif /* !NO_SYS */
diff --git a/src/Networking/LwipEthernet/Lwip/src/include/arch/cc.h b/src/Networking/LwipEthernet/Lwip/src/include/arch/cc.h
index e7a123b5..c9132ea7 100644
--- a/src/Networking/LwipEthernet/Lwip/src/include/arch/cc.h
+++ b/src/Networking/LwipEthernet/Lwip/src/include/arch/cc.h
@@ -96,7 +96,7 @@ typedef uintptr_t mem_ptr_t;
to let sys.h use binary semaphores instead of mutexes - as before in 1.3.2
Refer CHANGELOG
*/
-#define LWIP_COMPAT_MUTEX 1
+#define LWIP_COMPAT_MUTEX 0
/* Make lwip/arch.h define the codes which are used throughout */
#define LWIP_PROVIDE_ERRNO
diff --git a/src/Networking/LwipEthernet/Lwip/src/include/arch/sys_arch.h b/src/Networking/LwipEthernet/Lwip/src/include/arch/sys_arch.h
index b8a2a709..d077feed 100644
--- a/src/Networking/LwipEthernet/Lwip/src/include/arch/sys_arch.h
+++ b/src/Networking/LwipEthernet/Lwip/src/include/arch/sys_arch.h
@@ -8,8 +8,16 @@ typedef void * sys_prot_t;
typedef void * sys_sem_t;
-typedef void * sys_mbox_t;
+typedef struct
+{
+ struct QueueBase *m;
+} sys_mbox_t;
typedef void * sys_thread_t;
+typedef struct
+{
+ struct Mutex *m;
+} sys_mutex_t;
+
#endif /* __ARCH_SYS_ARCH_H__ */
diff --git a/src/Networking/LwipEthernet/Lwip/src/include/lwip/sys.h b/src/Networking/LwipEthernet/Lwip/src/include/lwip/sys.h
index a3e4f0aa..3bfa245f 100644
--- a/src/Networking/LwipEthernet/Lwip/src/include/lwip/sys.h
+++ b/src/Networking/LwipEthernet/Lwip/src/include/lwip/sys.h
@@ -267,8 +267,6 @@ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg);
* The returned time has to be accurate to prevent timer jitter!
*/
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout);
-/* Allow port to override with a macro, e.g. special timeout for sys_arch_mbox_fetch() */
-#ifndef sys_arch_mbox_tryfetch
/**
* @ingroup sys_mbox
* Wait for a new message to arrive in the mbox
@@ -278,32 +276,27 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout);
* or SYS_MBOX_EMPTY if the mailbox is empty
*/
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg);
-#endif
-/**
- * For now, we map straight to sys_arch implementation.
- */
+
#define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg)
+#define sys_mbox_fetch(mbox, msg) sys_arch_mbox_fetch(mbox, msg, 0)
+
/**
* @ingroup sys_mbox
* Delete an mbox
* @param mbox mbox to delete
*/
void sys_mbox_free(sys_mbox_t *mbox);
-#define sys_mbox_fetch(mbox, msg) sys_arch_mbox_fetch(mbox, msg, 0)
-#ifndef sys_mbox_valid
/**
* @ingroup sys_mbox
* Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid
*/
int sys_mbox_valid(sys_mbox_t *mbox);
-#endif
-#ifndef sys_mbox_set_invalid
/**
* @ingroup sys_mbox
* Set an mbox invalid so that sys_mbox_valid returns 0
*/
void sys_mbox_set_invalid(sys_mbox_t *mbox);
-#endif
+
#ifndef sys_mbox_valid_val
/**
* Same as sys_mbox_valid() but taking a value, not a pointer