]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/commitdiff
arch protect changed from interrupt to mutex
authorJan Dolezal <pm.jenik@gmail.com>
Mon, 12 Aug 2013 13:00:00 +0000 (15:00 +0200)
committerJan Dolezal <pm.jenik@gmail.com>
Mon, 12 Aug 2013 13:00:00 +0000 (15:00 +0200)
src/arch/sys_arch.c
src/include/arch/sys_arch.h

index 266ade174ffe92d7716f5a1ca9ea6ba229c7517b..489a987d30b617a05f47492742902a01b844134b 100644 (file)
@@ -175,14 +175,19 @@ 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;
+#endif /* SYS_ARCH_SEMPHR_PROTECT */
 
-/* TODO: research on what put to sys_init() >>
- * void sys_init(void). lwIP system initialization. This function is called before the any other
+/* void sys_init(void). lwIP system initialization. This function is called before the any other
  * sys_arch-function is called and is meant to be used to initialize anything that has to be up and
  * running for the rest of the functions to work. for example to set up a pool of semaphores.
  * This function is called from lwip_init() */
 void sys_init(void) /* initialize sys_arch layer */
 {
+#if SYS_ARCH_SEMPHR_PROTECT
+       sys_mutex_new(&sys_arch_prot_semphr);
+#endif /* SYS_ARCH_SEMPHR_PROTECT */
 }
 
 u32_t sys_jiffies(void)
@@ -201,7 +206,7 @@ u32_t sys_now(void)
 
        }
        */
-       /* for configTICK_RATE_Hz = 1000; when GetTickCount() fce returns 64-bit unsigned type it holds
+       /* for configTICK_RATE_Hz = 1000; when GetTickCount() fnc returns 64-bit unsigned type it holds
        about half billion years, for unsigned 32-bit type just about an hour ; ((((2³²)÷1000)÷configTICK_RATE_HZ)÷3600)÷24 */
        /*return (xTaskGetTickCount()*1000 / configTICK_RATE_HZ) ;*/
 
@@ -210,10 +215,13 @@ u32_t sys_now(void)
 
 #if SYS_LIGHTWEIGHT_PROT
 
+#if !SYS_ARCH_SEMPHR_PROTECT
 unsigned int IntMasterStatusGet        (void)
 {
     return (unsigned int)(0xC0 & _get_CPSR());
 }
+#endif /* !SYS_ARCH_SEMPHR_PROTECT */
+
 /**
  * This function is used to lock access to critical sections when lwipopt.h
  * defines SYS_LIGHTWEIGHT_PROT. It disables interrupts and returns a value
@@ -224,23 +232,24 @@ unsigned int IntMasterStatusGet   (void)
  */
 sys_prot_t sys_arch_protect(void)
 {
+#if !SYS_ARCH_SEMPHR_PROTECT
     sys_prot_t status;
     status = (IntMasterStatusGet() & 0xFF);
 
     _disable_IRQ();
     _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;
+    }
+#endif /* !SYS_ARCH_SEMPHR_PROTECT */
 }
-/*
-sys_prot_t sys_arch_protect(void)
-{
-    sys_prot_t status;
-    status = (IntMasterStatusGet() & 0xFF);
-
-    _disable_IRQ();
-    return status;
-}
-*/
 
 /**
  * This function is used to unlock access to critical sections when lwipopt.h
@@ -253,6 +262,7 @@ sys_prot_t sys_arch_protect(void)
  */
 void sys_arch_unprotect(sys_prot_t lev)
 {
+#if !SYS_ARCH_SEMPHR_PROTECT
     /* Only turn interrupts back on if they were originally on when the matching
        sys_arch_protect() call was made. */
     if((lev & 0x80) == 0) {
@@ -261,17 +271,13 @@ void sys_arch_unprotect(sys_prot_t lev)
     if((lev & 0x40) == 0) {
         _enable_FIQ();
     }
-}
-/*
-void sys_arch_unprotect(sys_prot_t lev)
-{*/
-    /* Only turn interrupts back on if they were originally on when the matching
-       sys_arch_protect() call was made. */
-/*    if((lev & 0xFF) == 0) {
-        _enable_IRQ();
+#else /* !SYS_ARCH_SEMPHR_PROTECT */
+    if(!lev) /* if semaphore was unlocked */
+    {
+       sys_mutex_unlock(&sys_arch_prot_semphr);
     }
+#endif /* !SYS_ARCH_SEMPHR_PROTECT */
 }
-*/
 
 #endif /* SYS_LIGHTWEIGHT_PROT */
 
index 0d418d5e6308ff4b0a0d168bc52714a6415e95fb..b46a6359292db2768789371d83ce96e0af716127 100644 (file)
@@ -53,6 +53,9 @@
 
 #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
+
 typedef u8_t sys_prot_t;
 
 /* The values for an unallocated entities. */
@@ -85,10 +88,6 @@ typedef xSemaphoreHandle sys_mutex_t; /* *xQUEUE */
 #define TRYPOST_ISR_SAFE           0
 #define TRYFETCH_ISR_SAFE          0
 
-/* 1 - semaphores are used to protect critical sections; 0 - interrupt disable is used to protect critical sections */
-/* because of FIQ using for irq */
-//#define SYS_ARCH_SEMPHR_PROTECT    1
-
 #endif /* !NO_SYS */
 
 #endif /* __ARCH_SYS_ARCH_H__ */