コード例 #1
0
ファイル: startup.c プロジェクト: WalkingScorpion/Scorpio
void system_initial(void)
{
	mem_init();
	sys_thread_init();
	psp_init();
}
コード例 #2
0
ファイル: sr_base.c プロジェクト: 1573472562/netfpga
void* sr_init_low_level_subystem(int argc, char **argv)
{
    /* -- VNS default parameters -- */
    char  *host   = "vrhost";
    char  *rtable = "rtable";
    char  *server = "171.67.71.18";
    char  *cpuhw  = CPU_HW_FILENAME;
    uint16_t port =  12345;
    uint16_t topo =  0;

    char  *client = 0;
    char  *logfile = 0;


    char  *interface = "nf2c0"; /* Default NetFPGA interface for card 0 */

    /* -- singleton instance of router, passed to sr_get_global_instance
          to become globally accessible                                  -- */
    static struct sr_instance* sr = 0;

    int c;

    if ( sr )
    {
        fprintf(stderr,  "Warning: because of limitations in lwip, ");
        fprintf(stderr,  " sr supports 1 router instance per process. \n ");
        return 0;
    }

    sr = (struct sr_instance*) malloc(sizeof(struct sr_instance));

    while ((c = getopt(argc, argv, "hs:v:p:c:t:r:l:i:m:")) != EOF)
    {
        switch (c)
        {
            case 'h':
                usage(argv[0]);
                exit(0);
                break;
            case 'p':
                port = atoi((char *) optarg);
                break;
            case 't':
                topo = atoi((char *) optarg);
                break;
            case 'v':
                host = optarg;
                break;
            case 'r':
                rtable = optarg;
                break;
            case 'c':
                client = optarg;
                break;
            case 's':
                server = optarg;
                break;
            case 'l':
                logfile = optarg;
                break;
            case 'm':
                cpuhw = optarg;
                break;
            case 'i':
                interface = optarg;
                if (strncmp(interface, "nf2c", 4) != 0) {
                        usage(argv[0]);
                        exit(1);
                }
                break;
        } /* switch */
    } /* -- while -- */

        /* Set the NetFPGA interface name */
    strncpy(sr->interface, interface, 31);
    sr->interface[31] = '\0';

#ifdef _CPUMODE_
    Debug(" \n ");
    Debug(" < -- Starting sr in cpu mode -- >\n");
    Debug(" \n ");
#else
    Debug(" < -- Starting sr in router mode  -- >\n");
    Debug(" \n ");
#endif /* _CPUMODE_ */

    /* -- required by lwip, must be called from the main thread -- */
    sys_thread_init();

    /* -- zero out sr instance and set default configurations -- */
    sr_init_instance(sr);

#ifdef _CPUMODE_
    sr->topo_id = 0;
    strncpy(sr->vhost,  "cpu",    SR_NAMELEN);
    strncpy(sr->rtable, rtable, SR_NAMELEN);

    if ( sr_cpu_init_hardware(sr, cpuhw) )
    { exit(1); }
    sr_integ_hw_setup(sr);
#else
    sr->topo_id = topo;
    strncpy(sr->vhost,  host,    SR_NAMELEN);
    strncpy(sr->rtable, rtable, SR_NAMELEN);
#endif /* _CPUMODE_ */

    if(! client )
    { sr_set_user(sr); }
    else
    { strncpy(sr->user, client,  SR_NAMELEN); }

    if ( gethostname(sr->lhost,  SR_NAMELEN) == -1 )
    {
        perror("gethostname(..)");
        return 0;
    }

    /* -- log all packets sent/received to logfile (if non-null) -- */
    sr_vns_init_log(sr, logfile);

    sr_lwip_transport_startup();


#ifndef _CPUMODE_
    Debug("Client %s connecting to Server %s:%d\n",
            sr->user, server, port);
    Debug("Requesting topology %d\n", topo);

    /* -- connect to VNS and reserve host -- */
    if(sr_vns_connect_to_server(sr,port,server) == -1)
    { return 0; }

    /* read from server until the hardware is setup */
    while (! sr->hw_init )
    {
        if(sr_vns_read_from_server(sr) == -1 )
        {
            fprintf(stderr, "Error: could not get hardware information ");
            fprintf(stderr, "from the server");
            sr_destroy_instance(sr);
            return 0;
        }
    }
#endif

    /* -- start low-level network thread, dissown sr -- */
    sys_thread_new(sr_low_level_network_subsystem, (void*)sr /* dissown */);

    return sr->interface_subsystem;
}/* -- main -- */