]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/commitdiff
mutex protection fixed; some not well working tries to make !NO_SYS version working
authorJan Dolezal <pm.jenik@gmail.com>
Fri, 23 Aug 2013 08:10:44 +0000 (10:10 +0200)
committerJan Dolezal <pm.jenik@gmail.com>
Fri, 23 Aug 2013 08:10:44 +0000 (10:10 +0200)
src/arch/sys_arch.c
src/core/pbuf.c
src/core/tcp_out.c
src/include/arch/cc.h
src/include/arch/lwipopts.h
src/include/arch/sys_arch.h

index 2a1fcac5370c9246d9457b871b7b2cb24b2a5eb0..ec28329a410237df2235408bed1335d46205cfef 100644 (file)
@@ -175,8 +175,10 @@ sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
 
 #endif /* NO_SYS */
 
+
 #if SYS_ARCH_SEMPHR_PROTECT
 sys_mutex_t sys_arch_prot_semphr;
+xTaskHandle protectedTask = NULL;
 #endif /* SYS_ARCH_SEMPHR_PROTECT */
 
 /* void sys_init(void). lwIP system initialization. This function is called before the any other
@@ -237,17 +239,31 @@ sys_prot_t sys_arch_protect(void)
     status = (IntMasterStatusGet() & 0xFF);
 
     _disable_IRQ();
-    _disable_FIQ();
+    /* while interrupts ethernet related or interrupt for context switch don't use FIQ, we dont need to disable it */
+/*    _disable_FIQ(); */
     return status;
 #else /* !SYS_ARCH_SEMPHR_PROTECT */
-    if(xSemaphoreTake(sys_arch_prot_semphr,0) == pdFALSE) /* if semphr was already taken */
-    {
-       return TRUE;
-    }
-    else
-    {
-       return FALSE;
+    taskENTER_CRITICAL();
+    if(protectedTask == xTaskGetCurrentTaskHandle()){ /* if protected task calls nested sys_arch_protect we let it know that it was protected already */
+        taskEXIT_CRITICAL();
+        return TRUE;
+    } else {
+       while(1)
+       {
+               sys_mutex_lock(&sys_arch_prot_semphr);
+               if(protectedTask == NULL)
+               {
+               protectedTask = xTaskGetCurrentTaskHandle();
+               break;
+               }
+               else
+               {
+                       sys_mutex_unlock(&sys_arch_prot_semphr); /* we shouldn't get here ever */
+               }
+       }
     }
+    taskEXIT_CRITICAL();
+    return FALSE;
 #endif /* !SYS_ARCH_SEMPHR_PROTECT */
 }
 
@@ -268,14 +284,18 @@ void sys_arch_unprotect(sys_prot_t lev)
     if((lev & 0x80) == 0) {
         _enable_IRQ();
     }
-    if((lev & 0x40) == 0) {
+    /* while interrupts ethernet related or interrupt for context switch don't use FIQ, we dont need to protect against it */
+/*    if((lev & 0x40) == 0) {
         _enable_FIQ();
-    }
+    }*/
 #else /* !SYS_ARCH_SEMPHR_PROTECT */
-    if(!lev) /* if semaphore was unlocked */
+    taskENTER_CRITICAL();
+    if(!lev) /* if task wasn't already protected when sys_arch_protect() was called, unprotect it now */
     {
+       protectedTask = NULL;
        sys_mutex_unlock(&sys_arch_prot_semphr);
     }
+    taskEXIT_CRITICAL();
 #endif /* !SYS_ARCH_SEMPHR_PROTECT */
 }
 
index 1e5e53b12a434e7f5ca333389f6457ab4d2b5431..32c78e24f75c91a9f0fc441b952f71f687f25a0a 100644 (file)
@@ -581,6 +581,12 @@ pbuf_header(struct pbuf *p, s16_t header_size_increment)
   return 0;
 }
 
+/*** RPP - Notificating semaphore that we got free pbuf (FreeRTOS semaphore) ***/
+#if !NO_SYS
+extern xSemaphoreHandle pbufFreed;
+#endif
+/*** end driver notification declare ***/
+
 /**
  * Dereference a pbuf chain or queue and deallocate any no-longer-used
  * pbufs at the head of this chain or queue.
@@ -689,6 +695,11 @@ pbuf_free(struct pbuf *p)
     }
   }
   PERF_STOP("pbuf_free");
+  /*** RPP - Notify driver that we got free space for it (FreeRTOS semaphore) ***/
+#if !NO_SYS
+  if (ref == 0 && type == PBUF_POOL)xSemaphoreGive(pbufFreed);
+#endif
+  /*** end driver notification ***/
   /* return number of de-allocated pbufs */
   return count;
 }
index b9fc339eb15f386c1eb0b360b40b0e2b1b5b7069..6541e79ac8dbb6d1587e65ee539cf2319275ea3b 100644 (file)
@@ -1119,6 +1119,17 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
 
     LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_output_segment: rtseq %"U32_F"\n", pcb->rtseq));
   }
+
+    /* XXX: patch from web
+     * If the reference count is more than 1, we assume the driver still
+     * has a reference and it is still queued to be sent from before,
+     * so we don't need to retransmit.
+     */
+/*    if (seg->p->ref > 1) {
+      return;
+    }*/
+
+
   LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output_segment: %"U32_F":%"U32_F"\n",
           htonl(seg->tcphdr->seqno), htonl(seg->tcphdr->seqno) +
           seg->len));
index 819db79ae9a0b2640e46ea084f7312b6e4ba3d6a..68e69de0ed55857a1bd036ba4c924c02a7d7b9b8 100644 (file)
@@ -118,11 +118,11 @@ typedef u32_t               mem_ptr_t;
 //#define DEBUG
 #ifdef DEBUG
 
-#define LWIP_PLATFORM_DIAG(expr)
+#define LWIP_PLATFORM_DIAG(expr)        LWIP_PLATFORM_ASSERT(expr)
 
 //extern void __error__(char *pcFilename, unsigned long ulLine);
-extern int32_t rpp_sci_printf(const char* format, ...);
-#define LWIP_PLATFORM_ASSERT(expr)      rpp_sci_printf((const char *) expr)
+extern int32_t rpp_sci_printkb(const char* format, ...);
+#define LWIP_PLATFORM_ASSERT(expr)      rpp_sci_printkb((const char *) expr)
 /*
 {                                       \
     if(!(expr))                         \
index 3261a9cc2e9c5884930a49304909c6517877cc56..9629bad4a43fe2f46310403301f34425330006dc 100644 (file)
                                            /* default is LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN)*/
 #define ETH_PAD_SIZE                    0
 #define MEMP_NUM_NETCONN                10
-#define LWIP_NETCONN                    1          /*default is 1*/
+#define LWIP_NETCONN                    !NO_SYS & 1 /*default is 1 - can be used only when NO_SYS = 0*/
 
 /*****************************************************************************
 **                           Socket  Options
 
 #define LWIP_SO_RCVTIMEO                1           /* enable receive timeout; default is 0 */
 
-/*****************************************************************************
-**                          Debugging options
-*****************************************************************************/
-#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_OFF
-#define LWIP_DBG_TYPES_ON               (LWIP_DBG_ON | LWIP_DBG_TRACE \
-                                         |LWIP_DBG_STATE | LWIP_DBG_FRESH)
-
 /*****************************************************************************
 **                          Mbox options
 *****************************************************************************/
-#define TCPIP_MBOX_SIZE                 10
+#define TCPIP_MBOX_SIZE                 20
 #define DEFAULT_RAW_RECVMBOX_SIZE       10
 #define DEFAULT_UDP_RECVMBOX_SIZE       10
 #define DEFAULT_TCP_RECVMBOX_SIZE       10
 #define DEFAULT_ACCEPTMBOX_SIZE         10
 
+/*****************************************************************************
+**                          Debugging options
+*****************************************************************************/
+#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_ALL
+#define LWIP_DBG_TYPES_ON               (LWIP_DBG_ON | LWIP_DBG_TRACE \
+                                         |LWIP_DBG_STATE | LWIP_DBG_FRESH)
+
+#define ALL_DBG_ON                      0
+
+
+/**
+ * ETHARP_DEBUG: Enable debugging in etharp.c.
+ */
+#define ETHARP_DEBUG                    LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * NETIF_DEBUG: Enable debugging in netif.c.
+ */
+#define NETIF_DEBUG                     LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * PBUF_DEBUG: Enable debugging in pbuf.c.
+ */
+#define PBUF_DEBUG                      LWIP_DBG_ON | ALL_DBG_ON
+
+/**
+ * API_LIB_DEBUG: Enable debugging in api_lib.c.
+ */
+#define API_LIB_DEBUG                   LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * API_MSG_DEBUG: Enable debugging in api_msg.c.
+ */
+#define API_MSG_DEBUG                   LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * SOCKETS_DEBUG: Enable debugging in sockets.c.
+ */
+#define SOCKETS_DEBUG                   LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * ICMP_DEBUG: Enable debugging in icmp.c.
+ */
+#define ICMP_DEBUG                      LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * IGMP_DEBUG: Enable debugging in igmp.c.
+ */
+#define IGMP_DEBUG                      LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * INET_DEBUG: Enable debugging in inet.c.
+ */
+#define INET_DEBUG                      LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * IP_DEBUG: Enable debugging for IP.
+ */
+#define IP_DEBUG                        LWIP_DBG_ON | ALL_DBG_ON
+
+/**
+ * IP_REASS_DEBUG: Enable debugging in ip_frag.c for both frag & reass.
+ */
+#define IP_REASS_DEBUG                  LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * RAW_DEBUG: Enable debugging in raw.c.
+ */
+#define RAW_DEBUG                       LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * MEM_DEBUG: Enable debugging in mem.c.
+ */
+#define MEM_DEBUG                       LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * MEMP_DEBUG: Enable debugging in memp.c.
+ */
+#define MEMP_DEBUG                      LWIP_DBG_ON | ALL_DBG_ON
+
+/**
+ * SYS_DEBUG: Enable debugging in sys.c.
+ */
+#define SYS_DEBUG                       LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * TIMERS_DEBUG: Enable debugging in timers.c.
+ */
+#define TIMERS_DEBUG                    LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * TCP_DEBUG: Enable debugging for TCP.
+ */
+#define TCP_DEBUG                       LWIP_DBG_ON | ALL_DBG_ON
+
+/**
+ * TCP_INPUT_DEBUG: Enable debugging in tcp_in.c for incoming debug.
+ */
+#define TCP_INPUT_DEBUG                 LWIP_DBG_ON | ALL_DBG_ON
+
+/**
+ * TCP_FR_DEBUG: Enable debugging in tcp_in.c for fast retransmit.
+ */
+#define TCP_FR_DEBUG                    LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * TCP_RTO_DEBUG: Enable debugging in TCP for retransmit
+ * timeout.
+ */
+#define TCP_RTO_DEBUG                   LWIP_DBG_ON | ALL_DBG_ON
+
+/**
+ * TCP_CWND_DEBUG: Enable debugging for TCP congestion window.
+ */
+#define TCP_CWND_DEBUG                  LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * TCP_WND_DEBUG: Enable debugging in tcp_in.c for window updating.
+ */
+#define TCP_WND_DEBUG                   LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * TCP_OUTPUT_DEBUG: Enable debugging in tcp_out.c output functions.
+ */
+#define TCP_OUTPUT_DEBUG                LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * TCP_RST_DEBUG: Enable debugging for TCP with the RST message.
+ */
+#define TCP_RST_DEBUG                   LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * TCP_QLEN_DEBUG: Enable debugging for TCP queue lengths.
+ */
+#define TCP_QLEN_DEBUG                  LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * UDP_DEBUG: Enable debugging in UDP.
+ */
+#define UDP_DEBUG                       LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * TCPIP_DEBUG: Enable debugging in tcpip.c.
+ */
+#define TCPIP_DEBUG                     LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * PPP_DEBUG: Enable debugging for PPP.
+ */
+#define PPP_DEBUG                       LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * SLIP_DEBUG: Enable debugging in slipif.c.
+ */
+#define SLIP_DEBUG                      LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * DHCP_DEBUG: Enable debugging in dhcp.c.
+ */
+#define DHCP_DEBUG                      LWIP_DBG_ON | ALL_DBG_ON
+
+/**
+ * AUTOIP_DEBUG: Enable debugging in autoip.c.
+ */
+#define AUTOIP_DEBUG                    LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * SNMP_MSG_DEBUG: Enable debugging for SNMP messages.
+ */
+#define SNMP_MSG_DEBUG                  LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * SNMP_MIB_DEBUG: Enable debugging for SNMP MIBs.
+ */
+#define SNMP_MIB_DEBUG                  LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * DNS_DEBUG: Enable debugging for DNS.
+ */
+#define DNS_DEBUG                       LWIP_DBG_OFF | ALL_DBG_ON
+
+/**
+ * IP6_DEBUG: Enable debugging for IPv6.
+ */
+#define IP6_DEBUG                       LWIP_DBG_OFF | ALL_DBG_ON
+
 
 #endif /* __LWIPOPTS_H__ */
index b46a6359292db2768789371d83ce96e0af716127..66741cbdfaf6c59807e0fb18847ffe4ad2ce860d 100644 (file)
@@ -53,8 +53,8 @@
 
 #define portQUEUE_OVERHEAD_BYTES 0
 
-/* 1 - semaphores are used to protect critical sections; 0 - interrupt disable is used to protect critical sections */
-#define SYS_ARCH_SEMPHR_PROTECT    1
+/* 1 - semaphore/mutexe is used to protect critical sections; 0 - interrupt disable is used to protect critical sections */
+#define SYS_ARCH_SEMPHR_PROTECT    0 & !NO_SYS
 
 typedef u8_t sys_prot_t;