return ERR_MEM;
return ERR_OK;
}
-/* TODO: message which arrives may be NULL */
+/* message which arrives may be NULL */
/* blocks the thread until a message arrives in the mailbox or timeout expires */
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
{
#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)
}
*/
- /* 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) ;*/
#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
*/
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
*/
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) {
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 */