/* 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)
{
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 */
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 */
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;
}
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
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