Exemple #1
0
static void accept_new(int accept_fd)
{
	int from, to, feid, teid;

	while (1) {
		from = net_accept(cos_spd_id(), accept_fd);
		assert(from != accept_fd);
		if (-EAGAIN == from) {
			return;
		} else if (from < 0) {
			BUG();
			return;
		}
		feid = evt_get();
		assert(feid > 0);
		if (0 < net_accept_data(cos_spd_id(), from, feid)) BUG();

		teid = evt_get();
		assert(teid > 0);
		to = tsplit(cos_spd_id(), td_root, "", 0, TOR_RW, teid);
		if (to < 0) {
			printc("torrent split returned %d", to);
			BUG();
		}

		mapping_add(from, to, feid, teid);
	}
}
Exemple #2
0
static void 
accept_new(int accept_fd)
{
	int from, to, feid, teid;

	while (1) {
		feid = evt_get();
		assert(feid > 0);
		from = from_tsplit(cos_spd_id(), accept_fd, "", 0, TOR_RW, feid);
		assert(from != accept_fd);
		if (-EAGAIN == from) {
			evt_put(feid);
			return;
		} else if (from < 0) {
			printc("from torrent returned %d\n", from);
			BUG();
			return;
		}
		teid = evt_get();
		assert(teid > 0);
		to = tsplit(cos_spd_id(), td_root, "", 0, TOR_RW, teid);
		if (to < 0) {
			printc("torrent split returned %d", to);
			BUG();
		}

		mapping_add(from, to, feid, teid);
	}
}
Exemple #3
0
static void *
gdb_mapping_add(uintptr_t vaddr, unsigned len, unsigned prot, size_t *valid) {
//kprintf("map add %x, nocache,dir,raw=%x/%x %x/%x %x/%x\n", vaddr, nocache.start, nocache.end, direct.start, direct.end, raw.start, raw.end);
	if(MAP_IN_RANGE(inout, vaddr)) {
		if(debug_flag > 2) kprintf("in/out access for 0x%x\n", vaddr);
		*valid = len;
		return (void *)vaddr;
	}
	if(MAP_IN_RANGE(raw, vaddr)) {
		if(debug_flag > 2) kprintf("raw access for 0x%x\n", vaddr);
		*valid = len;
		return (void *)vaddr;
	}
	if(MAP_IN_RANGE(direct, vaddr)) {
		paddr_t	paddr;

		if(vaddrinfo(NULL, vaddr, &paddr, valid) == PROT_NONE) return(NULL);
		if(debug_flag > 2) kprintf("direct access for 0x%x\n", vaddr);
		return (void *)vaddr;
	}
	if(MAP_IN_RANGE(nocache, vaddr)) {
		if(debug_flag > 2) kprintf("nocache access for 0x%x\n", vaddr);
		prot |= PROT_NOCACHE;
	}
	return mapping_add(vaddr, len, prot, valid);
}
Exemple #4
0
static void 
accept_new(int accept_fd)
{
	int eid;

	eid = evt_get();
	assert(eid > 0);
	pid_torrent = from_tsplit(cos_spd_id(), accept_fd, "", 0, TOR_RW, eid);
	assert(pid_torrent!= accept_fd);
	
	printc("accept_new: eid %d pid_torrent %d (accept_fd %d)\n", 
	       eid, pid_torrent, accept_fd);
	
	if (-EAGAIN == pid_torrent) {
		evt_free(cos_spd_id(), eid);
		return;
	} else if (pid_torrent < 0) {
		printc("pwrite to id_torrent %d\n", pid_torrent);
		BUG();
		return;
	}
	
	mapping_add(pid_torrent, 0, eid, 0);
}
Exemple #5
0
int main(int argc,char *argv[]) {
    char *name = NULL;
    int c;
    int joystick = -1;
    int num_joysticks;
    unsigned int i;

    memset(mappings,0,sizeof(mappings));

    while ((c = getopt(argc,argv,":hn:j:m:"))!=-1) {
        switch (c) {
        case 'h':
            usage(argv[0],0);
            break;
        case 'j':
            joystick = atoi(optarg);
            break;
        case 'm':
            if (mapping_add(optarg)==-1) {
                fprintf(stderr,"Failed to add mapping\n");
                usage(argv[0],1);
            }
            break;
        case 'n':
            name = optarg;
            break;
        case ':':
            fprintf(stderr,"Option -%c requires an operand\n",optopt);
            usage(argv[0],1);
            break;
        case '?':
            fprintf(stderr,"Unrecognized option: -%c\n", optopt);
            usage(argv[0],1);
            break;
        }
    }

    // initialize NXT
    nxt = nxt_open(name);
    if (nxt==NULL) {
        fprintf(stderr,"Could not find NXT\n");
        return 1;
    }

    // initialize Joystick
    if (SDL_Init(SDL_INIT_JOYSTICK)==-1) {
        printf("Can't init SDL:  %s\n", SDL_GetError());
        return 1;
    }
    num_joysticks = SDL_NumJoysticks();
    if (joystick==-1) {
        for (i=0; i<num_joysticks; i++) {
            printf("#%u:\t%s\n",i,SDL_JoystickName(i));
        }
        return 0;
    }
    if (joystick>=num_joysticks) {
        fprintf(stderr,"Joystick #%u doesn't exist\n",joystick);
        return 1;
    }
    joy = SDL_JoystickOpen(joystick);
    SDL_JoystickEventState(SDL_IGNORE);

    atexit(quit);

    // run mappings
    while (1) {
        SDL_JoystickUpdate();

        for (i=0; i<MAPPING_MAXNUM; i++) {
            if (mappings[i].present) {
                int axis = SDL_JoystickGetAxis(joy,mappings[i].axis);
                if (axis!=-1) {
                    int power = (int)((float)axis*mappings[i].factor);
                    nxt_motor_run(nxt, mappings[i].motor, power);
                }
            }
        }

        SDL_Delay(10);
    }

    return nxt_error(nxt);

}