return ERR_MEM;
}
/* locks a mutex */
-void inline sys_mutex_lock(sys_mutex_t *mutex)
+void sys_mutex_lock(sys_mutex_t *mutex)
{
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)
+void sys_mutex_unlock(sys_mutex_t *mutex)
{
xSemaphoreGive(*mutex);
}
/* frees memory space formerly taken by mutex */
-void inline sys_mutex_free(sys_mutex_t *mutex)
+void sys_mutex_free(sys_mutex_t *mutex)
{
vSemaphoreDelete(*mutex);
}
return ERR_MEM;
}
/* signals a semaphore */
-void inline sys_sem_signal(sys_sem_t *sem)
+void sys_sem_signal(sys_sem_t *sem)
{
xSemaphoreGive(*sem);
}
return ( (xTaskGetTickCount() - ticksBeforeSemphr) / portTICK_RATE_MS ); /* return time spent waiting for the semaphore - u can use xTaskGetTickCount() */
}
/* deletes a semaphore */
-void inline sys_sem_free(sys_sem_t *sem)
+void sys_sem_free(sys_sem_t *sem)
{
vSemaphoreDelete(*sem);
}
return ERR_OK;
}
/* posts the "msg" to the mailbox, blocks if mbox full */
-void inline sys_mbox_post(sys_mbox_t *mbox, void *msg)
+void sys_mbox_post(sys_mbox_t *mbox, void *msg)
{
while(xQueueSendToBack(*mbox, &msg, portMAX_DELAY) == errQUEUE_FULL);
}
return 0; /* we waited 0ms */
}
/* deletes a mbox */
-void inline sys_mbox_free(sys_mbox_t *mbox)
+void sys_mbox_free(sys_mbox_t *mbox)
{
vQueueDelete(*mbox);
}
#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
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 */
}
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 */
}