コード例 #1
0
/**
 * Only used in UDP mode. First call will send the start marker. When all
 * ttcp data has been sent, a number of end markers will be sent. After
 * end marker transmission, this function will complete the ttcp process.
 */
static void
udp_send_data(struct ttcp* ttcp)
{
        /* send start marker first time */
        if (!ttcp->udp_started) {
                if (udp_send_bytes(ttcp, 4) == 0) {
                        ttcp->udp_started = 1;
                        ttcp->start_time = timer_get_ms();
                }
        }

        /* normal case */
        else if (ttcp->left) {
                /* send data */
                if (udp_send_bytes(ttcp, ttcp->buflen) == 0)
                        ttcp->left -= ttcp->buflen;
        }

        /* end marker? */
        else if (ttcp->left == 0 && ttcp->udp_end_marker_left) {
                if (udp_send_bytes(ttcp, 4) == 0)
                        ttcp->udp_end_marker_left--;
        }

        /* all end markers sent */
        else if (ttcp->left == 0) {
                ttcp_done(ttcp, 0);
                return;
        }

        ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
                                           udp_timeout_cb, ttcp);
}
コード例 #2
0
/**
 * Only used in TCP mode.
 * Will transmit a maximum of pbuf->tot_len bytes.
 * Called upon connect and when there's space available in the TCP send window
 *
 */
static void
tcp_send_data(struct ttcp *ttcp)
{
        err_t err;
        uint32_t len;

	len = ttcp->left;

        /* don't send more than we have in the payload */
        if (len > ttcp->buflen)
                len = ttcp->buflen;

        /* We cannot send more data than space available in the send
           buffer. */
        if (len > tcp_sndbuf(ttcp->tpcb))
                len = tcp_sndbuf(ttcp->tpcb);

        err = tcp_write(ttcp->tpcb, ttcp->payload, len, 0);

        /* ERR_MEM now means out of buffers, try again later */

        if (err == ERR_OK)
                ttcp->left -= len;
        else if (err != ERR_MEM)
                printk("TTCP [%p]: tcp_write failed %d\n", ttcp, tcp_sndbuf(ttcp->tpcb));

        ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
                                           tcp_timeout_cb, ttcp);
}
コード例 #3
0
/**
 * Only used in TCP mode.
 * Scheduled by tcp_send_data(). tcp_sent() is not used for performance reasons.
 */
static void
tcp_timeout_cb(void *ctx)
{
        struct ttcp *ttcp = ctx;

        if (ttcp->left > 0) {
                tcp_send_data(ttcp);
                if (ttcp->verbose) {
                        printk(".");
                        if (ttcp->print_cnt % 80 == 0)
                                printk("\n");
                        ttcp->print_cnt++;
                }
                return;
        }

        /* all sent - empty queue */
        if (ttcp->tpcb->snd_queuelen)
                ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
                                                   tcp_timeout_cb, ttcp);
        else
                ttcp_done(ttcp, 0);
}
コード例 #4
0
ファイル: lwip_setup.c プロジェクト: drbokko/86Duino
int start_ip_stack(struct net_cfg *cfg, 
                   struct ip_addr ipaddr, 
                   struct ip_addr netmask,
                   struct ip_addr gw) {

        if (cfg->dhcp_enabled) {
                IP4_ADDR(&gw, 0,0,0,0);
                IP4_ADDR(&ipaddr, 0,0,0,0);
                IP4_ADDR(&netmask, 0,0,0,0);
        }
        
        /* add wl to lwip interface list and set as default */
        cfg->netif = netif_add(cfg->netif, 
                               &ipaddr, 
                               &netmask, 
                               &gw, 
                               NULL,
                               wlif_init, /* init */
                               ethernet_input /* handles ARP and IP packets */);

        if (cfg->netif == NULL)
            return -1;
        netif_set_default(cfg->netif);

        /* register lwip timer callbacks for tcp, arp and dhcp protocols */
        timer_sched_timeout_cb(5000, TIMEOUT_PERIODIC, 
                               etharp_tmr_cb, NULL);
        timer_sched_timeout_cb(TCP_TMR_INTERVAL, TIMEOUT_PERIODIC, 
                               tcp_tmr_cb, NULL);
        timer_sched_timeout_cb(DHCP_FINE_TIMER_MSECS, TIMEOUT_PERIODIC, 
                               dhcp_fine_tmr_cb, NULL);
        timer_sched_timeout_cb(DHCP_COARSE_TIMER_MSECS, TIMEOUT_PERIODIC,
                               dhcp_coarse_tmr_cb, NULL);
        timer_sched_timeout_cb(IP_TMR_INTERVAL, TIMEOUT_PERIODIC,
                               ip_tmr_cb, NULL);
        timer_sched_timeout_cb(DNS_TMR_INTERVAL, TIMEOUT_PERIODIC,
                                      dns_tmr_cb, NULL);

        return 1;
}
コード例 #5
0
ファイル: ard_tcp.c プロジェクト: 4bcat/Arduino
static void cleanSockStateDelayed(void * arg)
{
	INFO_TCP("arg %p\n", arg);
	timer_sched_timeout_cb(1000, TIMEOUT_ONESHOT,
			cleanSockState_cb, arg);
}