示例#1
0
文件: init.c 项目: Karamax/arrakis
/**
 * Perform Sanity check of user-configurable values, and initialize all modules.
 *
 * \param card_name Name of service implementing ethernet driver
 * \param queueid Queueid which is allocated to this application
 * \param opt_waitset Optional pointer to waitset to be used by LWIP
 * \param opt_mutex Optional pointer to mutex to protect multi-threaded domains
 *
 * \returns True iff init completes
 */
bool lwip_init_ex(const char *card_name, uint64_t queueid,
                  struct waitset *opt_waitset, struct thread_mutex *opt_mutex)
{
    printf("lwip_init_ex: starting......................\n");
    DEBUGPRINTPS("LWIP_other: Inside lwip_init\n");
    static bool run_once;

    if (run_once) {
        return false;
    }
    run_once = true;

    if (opt_waitset == NULL) {
        printf("#### %s Going ahead with default wait-set\n", disp_name());
        lwip_waitset = get_default_waitset();
    } else {
        printf("#### %s Going ahead with non-default wait-set\n", disp_name());
//        lwip_waitset = get_default_waitset();
        lwip_waitset = opt_waitset;
    }

    if (opt_mutex != NULL) {
        lwip_mutex = opt_mutex;
    }

    /* Sanity check user-configurable values */
    lwip_sanity_check();
    DEBUGPRINTPS("LWIP: lwip_init: done with sanity check\n");
    printf("LWIP: done with sanity check\n");
    /* Modules initialization */
    char port_manager_name[MAX_NET_SERVICE_NAME_LEN];

    snprintf(port_manager_name, sizeof(port_manager_name), "%s%s",
             card_name, NET_PORTS_MNG_SUFFIX);

    // Connecting to the port_manager_service
    idc_connect_port_manager_service(port_manager_name);


    if (is_ctl != 1) {
        // connecting to ARP lookup service
        // Doing this before everything else so that we know all needed
        // services are up and running.
        char ARP_service_name[MAX_NET_SERVICE_NAME_LEN];
        snprintf(ARP_service_name, sizeof(ARP_service_name), "%s%s",
             card_name, NET_ARP_LOOKUP_SUFFIX);
        idc_connect_ARP_lookup_service(ARP_service_name);
    }

    DEBUGPRINTPS("LWIP: lwip_init: done with connection setup\n");
    printf("LWIP: done with connection setup\n");
    remaining_lwip_initialization((char *) card_name, queueid);

    if (is_ctl != 1) {
        DEBUGPRINTPS("getting IP from ARP service\n");
        printf("LWIP: getting IP from ARP service\n");
        idc_get_ip_from_ARP_lookup();
    }

    // Register timers... (TCP only)
    // FIXME: These timers should be added only when first TCP connection
    // is requested and not when networking is started!!!!
    static struct periodic_event tcp_timer;
    errval_t err = periodic_event_create(&tcp_timer, lwip_waitset,
                                         TCP_TMR_INTERVAL * 1000,
                                         MKCLOSURE((void (*)(void *))
                                                   call_tcp_tmr, NULL));
    assert(err_is_ok(err));

    // FIXME: I am not sure if this should be in the codepath for both
    // is_ctl and non-is_ctl.  Specially becasuse non is_ctl is anyways
    // adding one interface with idc_get_ip* call.

    // Bring interface up
    struct ip_addr ipaddr, netmask, gw;

    ip_addr_set(&ipaddr, IP_ADDR_ANY);
    ip_addr_set(&netmask, IP_ADDR_ANY);
    ip_addr_set(&gw, IP_ADDR_ANY);
    struct netif *n = netif_add(&netif, &ipaddr, &netmask, &gw,
                                NULL, bfeth_init, ethernet_input);

    assert(n != NULL);
    extern bool lwip_init_done;
    lwip_init_done = true;

    printf("lwip_init_ex: done......................\n");
    return true;
}
示例#2
0
int main(int argc, char *argv[])
{
    BLINK_PRINT(("%s, pid: %u\r\n", disp_name(), disp_get_domain_id()));
    
    uint32_t blink_rate = (argc > 1) ? atoi(argv[1]) : 1; 
    uint32_t no_of_blinks = (argc > 2) ? atoi(argv[2]) : 10; 
    
    delayus_t delay = 1000.0/(float)blink_rate;
    
    errval_t err;
    struct capref retcap;
    size_t retlen;
    err = aos_rpc_get_dev_cap(&local_rpc, OMAP44XX_MAP_L4_PER_UART3,
        OMAP44XX_MAP_L4_PER_UART3_SIZE, &retcap, &retlen);
    if (err_is_fail(err)) {
        debug_printf("Failed to get IO Cap from init... %s\n");
        err_print_calltrace(err);
        abort();
    }
    BLINK_PRINT("dev cap received, dev mapped. OK\r\n");
    
    size_t offset = GPIO1_BASE - 0x40000000;
    lvaddr_t uart_addr = (1UL << 28)*3;
    err = paging_map_user_device(get_current_paging_state(), uart_addr,
                            retcap, offset, OMAP44XX_MAP_L4_PER_UART3_SIZE,
                            VREGION_FLAGS_READ_WRITE_NOCACHE);
                            
    set_gpio1_registers(uart_addr);
    BLINK_PRINT("user device registers set. OK\r\n");

    err = periodic_event_create(&pe, get_default_waitset(), delay,  
                                    MKCLOSURE((void *) blink_led, NULL));
    if (err_is_fail(err)) {
        DEBUG_ERR(err, "failed to register periodic event!\n");
        err_print_calltrace(err);
    } else {
        BLINK_PRINT("periodic event registered.\r\n");
    }
    
    for(uint32_t i = 0; i < no_of_blinks; i++) {
        err = event_dispatch(get_default_waitset());
        if (err_is_fail(err)) {
            DEBUG_ERR(err, "failed to dispatch event\n");
            err_print_calltrace(err);
        }
    }
    
    err = periodic_event_cancel(&pe);
    if(err_is_fail(err)){
        err_print_calltrace(err);
        abort();
    }
    
    BLINK_PRINT("blink exiting\n");

    err = aos_rpc_send_string(&local_rpc, "bye");
    if (err_is_fail(err)) {
        DEBUG_ERR(err, "fail to say bye\n");
        err_print_calltrace(err);
    }

    return 0;
}