/** * Should allocate a pbuf and transfer the bytes of the incoming * packet from the interface into the pbuf. * * @param netif the lwip network interface structure for this ethernetif * @return a pbuf filled with the received packet (including MAC header) * NULL on memory error */ static struct pbuf *low_level_input(UNUSED_ARG(struct netif *, netif)) { struct pbuf *p, *q; size_t len; len = eth_getFrameLen(); if (UNLIKELY(len <= 0)) return NULL; #if ETH_PAD_SIZE len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ #endif proc_forbid(); /* We allocate a pbuf chain of pbufs from the pool. */ p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); if (p != NULL) { #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif for (q = p; q != NULL; q = q->next) eth_getFrame(q->payload, q->len); #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif LINK_STATS_INC(link.recv); } else { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); } proc_permit(); return p; }
static err_t low_level_output(UNUSED_ARG(struct netif *, netif), struct pbuf *p) { struct pbuf *q; #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif proc_forbid(); for (q = p; q != NULL; q = q->next) eth_putFrame(q->payload, q->len); eth_sendFrame(); #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif LINK_STATS_INC(link.xmit); proc_permit(); return ERR_OK; }
void NORETURN context_switch(void) { IRQ_ENABLE; timer_init(); proc_init(); #if CONFIG_USE_HP_TIMER ser_init(&out, CONFIG_CTX_DEBUG_PORT); ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE); #endif #if CONFIG_USE_LED LED_INIT(); #endif proc_forbid(); hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack); lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack); main_proc = proc_current(); proc_setPri(hp_proc, 2); proc_setPri(lp_proc, 1); proc_permit(); while (1) { timer_delay(100); sig_send(lp_proc, SIG_USER0); sig_wait(SIG_USER0); #if CONFIG_USE_HP_TIMER kfile_printf(&out.fd, "Switch: %lu.%lu usec\n\r", hptime_to_us((end - start)), hptime_to_us((end - start) * 1000) % 1000); #endif } }
/** * Terminate the current process */ void proc_exit(void) { LOG_INFO("%p:%s", current_process, proc_currentName()); #if CONFIG_KERN_MONITOR monitor_remove(current_process); #endif proc_forbid(); #if CONFIG_KERN_HEAP /* * Set the task as zombie, its resources will be freed in proc_new() in * a lazy way, when another process will be created. */ proc_addZombie(current_process); #endif current_process = NULL; proc_permit(); proc_switch(); /* never reached */ ASSERT(0); }