Ejemplo n.º 1
0
/** Post a message to an mbox - may not fail
 * -> blocks if full, only used from tasks not from ISR
 * @param mbox mbox to posts the message
 * @param msg message to post (ATTENTION: can be NULL)
 */
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
{
    RT_DEBUG_NOT_IN_INTERRUPT;

    rt_mb_send_wait(*mbox, (rt_uint32_t)msg, RT_WAITING_FOREVER);

    return;
}
Ejemplo n.º 2
0
void sys_mbox_post(sys_mbox_t mbox, void *msg)
{
#if SYS_DEBUG
	{
		struct rt_thread *thread;
		thread = rt_thread_self();

		LWIP_DEBUGF(SYS_DEBUG, ("%s, Post mail: %s ,0x%x\n",thread->name,
			mbox->parent.parent.name, (rt_uint32_t)msg));
	}
#endif

	rt_mb_send_wait(mbox, (rt_uint32_t)msg,RT_WAITING_FOREVER);

	return;
}
Ejemplo n.º 3
0
static void pcap_thread_entry(void* parameter)
{
    pcap_if_t *netif;
    pcap_t *tap;
    char errbuf[PCAP_ERRBUF_SIZE];
    struct pcap_pkthdr *header;
    const u_char *pkt_data;
    int res;

    netif = (pcap_if_t *) parameter;

    /* Open the adapter */
    if ((tap = pcap_open_live(netif->name,
        65536, // portion of the packet to capture. 
        1,     // promiscuous mode (nonzero means promiscuous)
        1,     // read timeout, 0 blocked, -1 no timeout
        errbuf )) == NULL)
    {
        rt_kprintf("Unable to open the adapter. %s is not supported by WinPcap\n", netif->name);
        return;
    }

    NETIF_PCAP(&pcap_netif_device) = tap;

    /* Read the packets */
    while (1)
    {
        struct eth_device* eth;
        struct pbuf *p;

        rt_enter_critical();
        res = pcap_next_ex(tap, &header, &pkt_data);
        rt_exit_critical();

        if (res == 0) continue;

        eth = (struct eth_device*) &pcap_netif_device;

        p = pbuf_alloc(PBUF_LINK, header->len, PBUF_RAM);
        pbuf_take(p, pkt_data, header->len);
        
        /* send to packet mailbox */
        rt_mb_send_wait(packet_mb, (rt_uint32_t)p, RT_WAITING_FOREVER);
        /* notify eth rx thread to receive packet */
        eth_device_ready(eth);
    }
}
Ejemplo n.º 4
0
err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p)
{
	struct eth_tx_msg msg;
	struct eth_device* enetif;

	enetif = (struct eth_device*)netif->state;

	/* send a message to eth tx thread */
	msg.netif = netif;
	msg.buf   = p;
	if (rt_mb_send_wait(&eth_tx_thread_mb, (rt_uint32_t) &msg, RT_WAITING_FOREVER) == RT_EOK) {
		/* waiting for ack */
		rt_sem_take(&(enetif->tx_ack), RT_WAITING_FOREVER);
	}

	return ERR_OK;
}