]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blobdiff - src/arch/sys_arch.c
HALCoGen+LwIP Demo for TMS570 (BE) - only files coppied
[pes-rpp/rpp-lwip.git] / src / arch / sys_arch.c
index 3724d0b787b5bf3f8395e9af7c244362e3e6c424..efa3464f507e25282240cc7877b833c2157254a7 100644 (file)
 
 /* 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