u32_t sys_arch_sem_wait(struct sys_sem** sem, u32_t __timeout) { register u32_t timeout = __timeout; if(timeout) timeout += timer_getms(); #if CONFIG_SMP __sync_synchronize(); #endif (*sem)->lock--; while( ((*sem)->lock < 0) && (__timeout ? timeout > timer_getms() : 1) ) sys_yield(); if(__timeout == 0) return SYS_ARCH_TIMEOUT; int s = timeout - (timeout - timer_getms()); if(s < timeout) return s; return SYS_ARCH_TIMEOUT; }
u32_t sys_arch_mbox_fetch(struct sys_mbox** mbox, void** msg, u32_t timeout) { if(timeout) { timeout += timer_getms(); while(((*mbox)->count == 0) && (timeout > timer_getms())) sys_yield(); } else while(((*mbox)->count == 0)) sys_yield(); if((*mbox)->count == 0) return SYS_ARCH_TIMEOUT; void* mx = (*mbox)->msg[0]; memcpy(&(*mbox)->msg[0], &(*mbox)->msg[1], sizeof(void*) * (--(*mbox)->count)); if(msg) *msg = mx; if(timeout == 0) return SYS_ARCH_TIMEOUT; int s = timeout - (timeout - timer_getms()); if(s < timeout) return s; return SYS_ARCH_TIMEOUT; }
static void tcpip_init_done(void* arg) { current_task->name = "[tcpipd]"; current_task->description = "TCP/IP Stack daemon"; current_task->priority = TASK_PRIO_MIN; #if DEBUG kprintf(LOG "[%d] tcpip: initialized in %d MS\n", sys_getpid(), (uintptr_t) (timer_getms() - (uintptr_t) arg)); #else (void) arg; #endif struct netif* lo = netif_find("lo0"); if(likely(lo)) { netif_set_up(lo); netif_set_default(lo); } else kprintf(WARN "netif: Loopback interface not found\n"); ip_addr_t dns[2]; IP4_ADDR(&dns[0], 8, 8, 8, 8); IP4_ADDR(&dns[1], 8, 8, 4, 4); dns_setserver(0, &dns[0]); dns_setserver(1, &dns[1]); }
int network_init() { #if DEBUG tcpip_init(tcpip_init_done, (void*) ((uintptr_t) timer_getms())); #else tcpip_init(tcpip_init_done, NULL); #endif return 0; }
static void tcpip_init_done(void* arg) { #if DEBUG kprintf(LOG, "[%d] tcpip: initialized in %d MS\n", sys_getpid(), timer_getms() - (uint32_t) arg); #else (void) arg; #endif struct netif* lo = netif_find("lo0"); if(likely(lo)) { netif_set_up(lo); netif_set_default(lo); } else kprintf(WARN, "netif: Loopback interface not found\n"); lwip_socket_init(); }
void timer_delay(long ms) { volatile long ticks = timer_getms() + ms; while(ticks > timer_getms()) ; }
u32_t sys_now() { return timer_getms(); }