Esempio n. 1
0
int
ctl_byname(const char *name, void *oldp, size_t *oldlenp, void *newp,
    size_t newlen)
{
	int ret;
	size_t depth;
	ctl_node_t const *nodes[CTL_MAX_DEPTH];
	size_t mib[CTL_MAX_DEPTH];
	const ctl_named_node_t *node;

	if (ctl_initialized == false && ctl_init()) {
		ret = EAGAIN;
		goto label_return;
	}

	depth = CTL_MAX_DEPTH;
	ret = ctl_lookup(name, nodes, mib, &depth);
	if (ret != 0)
		goto label_return;

	node = ctl_named_node(nodes[depth-1]);
	if (node != NULL && node->ctl)
		ret = node->ctl(mib, depth, oldp, oldlenp, newp, newlen);
	else {
		/* The name refers to a partial path through the ctl tree. */
		ret = ENOENT;
	}

label_return:
	return(ret);
}
Esempio n. 2
0
int
ctl_byname(const char *name, void *oldp, size_t *oldlenp, void *newp,
    size_t newlen)
{
	int ret;
	size_t depth;
	ctl_node_t const *nodes[CTL_MAX_DEPTH];
	size_t mib[CTL_MAX_DEPTH];

	if (ctl_initialized == false && ctl_init()) {
		ret = EAGAIN;
		goto RETURN;
	}

	depth = CTL_MAX_DEPTH;
	ret = ctl_lookup(name, nodes, mib, &depth);
	if (ret != 0)
		goto RETURN;

	if (nodes[depth-1]->ctl == NULL) {
		/* The name refers to a partial path through the ctl tree. */
		ret = ENOENT;
		goto RETURN;
	}

	ret = nodes[depth-1]->ctl(mib, depth, oldp, oldlenp, newp, newlen);
RETURN:
	return(ret);
}
Esempio n. 3
0
// Module init
static int  cryptctl_init(void)
{
	// init the control device
	ctl_init();
	
	// init the sampledev stuff
	//sampledev_init();
	
	return 0;
}
Esempio n. 4
0
int
ctl_nametomib(const char *name, size_t *mibp, size_t *miblenp)
{
	int ret;

	if (ctl_initialized == false && ctl_init()) {
		ret = EAGAIN;
		goto label_return;
	}

	ret = ctl_lookup(name, NULL, mibp, miblenp);
label_return:
	return(ret);
}
Esempio n. 5
0
int
ctl_bymib(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
    void *newp, size_t newlen)
{
	int ret;
	const ctl_named_node_t *node;
	size_t i;

	if (ctl_initialized == false && ctl_init()) {
		ret = EAGAIN;
		goto label_return;
	}

	/* Iterate down the tree. */
	node = super_root_node;
	for (i = 0; i < miblen; i++) {
		assert(node);
		assert(node->nchildren > 0);
		if (ctl_named_node(node->children) != NULL) {
			/* Children are named. */
			if (node->nchildren <= mib[i]) {
				ret = ENOENT;
				goto label_return;
			}
			node = ctl_named_children(node, mib[i]);
		} else {
			const ctl_indexed_node_t *inode;

			/* Indexed element. */
			inode = ctl_indexed_node(node->children);
			node = inode->index(mib, miblen, mib[i]);
			if (node == NULL) {
				ret = ENOENT;
				goto label_return;
			}
		}
	}

	/* Call the ctl function. */
	if (node && node->ctl)
		ret = node->ctl(mib, miblen, oldp, oldlenp, newp, newlen);
	else {
		/* Partial MIB. */
		ret = ENOENT;
	}

label_return:
	return(ret);
}
Esempio n. 6
0
int
ctl_bymib(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
    void *newp, size_t newlen)
{
	int ret;
	const ctl_node_t *node;
	size_t i;

	if (ctl_initialized == false && ctl_init()) {
		ret = EAGAIN;
		goto RETURN;
	}

	/* Iterate down the tree. */
	node = super_root_node;
	for (i = 0; i < miblen; i++) {
		if (node->u.named.children[0].named) {
			/* Children are named. */
			if (node->u.named.nchildren <= mib[i]) {
				ret = ENOENT;
				goto RETURN;
			}
			node = &node->u.named.children[mib[i]];
		} else {
			const ctl_node_t *inode;

			/* Indexed element. */
			inode = &node->u.named.children[0];
			node = inode->u.indexed.index(mib, miblen, mib[i]);
			if (node == NULL) {
				ret = ENOENT;
				goto RETURN;
			}
		}
	}

	/* Call the ctl function. */
	if (node->ctl == NULL) {
		/* Partial MIB. */
		ret = ENOENT;
		goto RETURN;
	}
	ret = node->ctl(mib, miblen, oldp, oldlenp, newp, newlen);

RETURN:
	return(ret);
}
Esempio n. 7
0
File: main.c Progetto: smlng/r2c2
int main(int argc, char **argv)
{
    pthread_t ctl_thread;
    int res;

    if (argc < 3) {
        fprintf(stderr,"usage: %s <controller> <remoteIP>\n", argv[0]);
        return 1;
    }

    js = ctl_init(argv[1]);
    if (js < 0) {
        fprintf(stderr,"error: unable to open joystick");
        return 1;
    }

    /* start the reader thread */
    res = pthread_create(&ctl_thread, NULL, ctl_read, NULL);
    if (res < 0) {
        fprintf(stderr,"error: unable to start reader thread");
        return 1;
    }

    char ctl_data[CONF_COMM_MSGLEN];
    pthread_mutex_lock(&msg_lock);
    r2c2_msg.type = CONF_COMM_MSGCTL;
    r2c2_msg.speed = 0;
    r2c2_msg.steer = 0;
    r2c2_msg.buttons = 0;
    pthread_mutex_unlock(&msg_lock);
    while (1) {
        usleep(CONF_CTL_INTERVAL);
        pthread_mutex_lock(&msg_lock);
        ctl_data[0] = r2c2_msg.type;
        memcpy(&(ctl_data[1]), &r2c2_msg.speed, 2);
        memcpy(&(ctl_data[3]), &r2c2_msg.steer, 2);
        memcpy(&(ctl_data[5]), &r2c2_msg.buttons, 2);
        pthread_mutex_unlock(&msg_lock);
        r2c2_send(argv[2], CONF_COMM_PORT, ctl_data, CONF_COMM_MSGLEN);
    }
    close(sendfd);
    pthread_join(ctl_thread, NULL);
    close(js);
    return 0;
}
Esempio n. 8
0
int main(int argc, char** argv) {
	int wstat, ret;
	pid_t pid;
	struct timeval tv;
	service_t *svc;
	
	// initialize wake structure, which is owned by main
	memset(wake, 0, sizeof(*wake));
	// just in case, but probably redundant
	FD_ZERO(&wake->fd_read);
	FD_ZERO(&wake->fd_write);
	FD_ZERO(&wake->fd_err);
	FD_ZERO(&wake->fd_ready_read);
	FD_ZERO(&wake->fd_ready_write);
	FD_ZERO(&wake->fd_ready_err);
	// wake structure holds current time so we don't keep calling clock_gettime()
	wake->now= gettime_mon_frac();
	
	log_init();
	svc_init();
	fd_init();
	ctl_init();

	// Special defaults when running as init
	if (getpid() == 1) {
		opt_config_file= CONFIG_FILE_DEFAULT_PATH;
		opt_terminate_guard= 1;
	}
	
	umask(077);

	// parse arguments, overriding default values
	parse_opts(argv+1);
	
	// Check for required options
	if (!opt_interactive && !opt_config_file && !opt_socket_path)
		fatal(EXIT_BAD_OPTIONS, "require -i or -c or -S");
	
	// Initialize file descriptor object pool
	if (opt_fd_pool_count > 0 && opt_fd_pool_size_each > 0)
		if (!fd_preallocate(opt_fd_pool_count, opt_fd_pool_size_each))
			fatal(EXIT_INVALID_ENVIRONMENT, "Unable to preallocate file descriptor objects");
	if (!fd_init_special_handles())
		fatal(EXIT_BROKEN_PROGRAM_STATE, "Can't initialize all special handles");

	if (!register_open_fds())
		fatal(EXIT_BAD_OPTIONS, "Not enough FD objects to register all open FDs");

	// Set up signal handlers and signal mask and signal self-pipe
	// Do this AFTER registering all open FDs, because it creates a pipe
	sig_init();
	
	// Initialize service object pool
	if (opt_svc_pool_count > 0 && opt_svc_pool_size_each > 0)
		if (!svc_preallocate(opt_svc_pool_count, opt_svc_pool_size_each))
			fatal(EXIT_INVALID_ENVIRONMENT, "Unable to preallocate service objects");

	// Initialize controller object pool
	control_socket_init();

	if (opt_socket_path && !control_socket_start(STRSEG(opt_socket_path)))
		fatal(EXIT_INVALID_ENVIRONMENT, "Can't create controller socket");
	
	if (opt_interactive)
		if (!setup_interactive_mode())
			fatal(EXIT_INVALID_ENVIRONMENT, "stdin/stdout are not usable!");

	if (opt_config_file)
		if (!setup_config_file(opt_config_file))
			fatal(EXIT_INVALID_ENVIRONMENT, "Unable to process config file");

	if (opt_mlockall) {
		// Lock all memory into ram. init should never be "swapped out".
		if (mlockall(MCL_CURRENT | MCL_FUTURE))
			log_error("mlockall: %s", strerror(errno));
	}
	
	// fork and setsid if requested, but not if PID 1 or interactive
	if (opt_daemonize) {
		if (getpid() == 1 || opt_interactive)
			log_warn("Ignoring --daemonize (see manual)");
		else
			daemonize();
	}

	// terminate is disabled when running as init, so this is an infinite loop
	// (except when debugging)
	wake->now= gettime_mon_frac();
	while (!main_terminate) {
		// set our wait parameters so other methods can inject new wake reasons
		wake->next= wake->now + (200LL<<32); // wake at least every 200 seconds
		wake->max_fd= -1;
		
		log_run();

		// collect new signals since last iteration and set read-wake on signal fd
		sig_run();
		
		// reap all zombies, possibly waking services
		while ((pid= waitpid(-1, &wstat, WNOHANG)) > 0) {
			log_trace("waitpid found pid = %d", (int)pid);
			if ((svc= svc_by_pid(pid)))
				svc_handle_reaped(svc, wstat);
			else
				log_trace("pid does not belong to any service");
		}
		if (pid < 0)
			log_trace("waitpid: %s", strerror(errno));
		
		// run state machine of each service that is active.
		svc_run_active();
		
		// possibly accept new controller connections
		control_socket_run();
		
		// run controller state machines
		ctl_run();
		
		log_run();
		
		// Wait until an event or the next time a state machine needs to run
		// (state machines edit wake.next)
		wake->now= gettime_mon_frac();
		if (wake->next - wake->now > 0) {
			tv.tv_sec= (long)((wake->next - wake->now) >> 32);
			tv.tv_usec= (long)((((wake->next - wake->now)&0xFFFFFFFFLL) * 1000000) >> 32);
			log_trace("wait up to %d.%d sec", tv.tv_sec, tv.tv_usec);
		}
		else
Esempio n. 9
0
File: init.c Progetto: fixos/fixos
// Real entry point of the OS :
void init() {
	unsigned int freq;

	interrupt_init();

	earlyterm_init();
	earlyterm_clear();

	kbd_init();
	rtc_init();
	time_init();

	earlyterm_write("Kernel initialization...\n");

	set_kernel_print(&earlyterm_write);
	printk(LOG_INFO, "cmd args: '%s'\n", &cmdargs_begin);

	cmdline_parse(&cmdargs_begin, 1024);

	mmu_init();
	pm_init_pages();

	stimer_init();
	hwkbd_start_periodic_update();

	DBG_WAIT;

	interrupt_inhibit_all(0);


	// console initialisation as soon as possible
	dev_init();
	// add TTY device (on major 4)
	ttydev_device.init();
	dev_register_device(&ttydev_device, 4);

	// add virtual terminal TTYs
	vt_init();

	// USB initialisation
	usb_init();
	// add usb-acm TTY
	acm_usb_init();

	DBG_WAIT;

	// will be the last message displayed on early console
	printk(LOG_INFO, "Switching screen to tty1...\n  The display will be cleared.\n");
	console_make_active();

	// in all cases, Virtual Terminals should be made active (tty1)
	DBG_WAIT;
	vt_set_active(0);


	// need to be changed for "overclocking" :
	//freq_change(FREQ_STC_4, FREQ_DIV_1, FREQ_DIV_4);
	
	freq_time_calibrate();

	freq = freq_get_internal_hz();
	printk(LOG_INFO, "CPU freq : %d.%dMHz\n", freq/1000000, (freq/100000)%10);

	freq = freq_get_peripheral_hz();
	printk(LOG_INFO, "Peripheral freq : %d.%dMHz\n", freq/1000000, (freq/100000)%10);

	// initialize sysctl tables
	ctl_init();

	//test_keyboard_int();

	//test_virtual_mem();

	//asm volatile ("trapa #50");

	//DBG_WAIT;
	

	// Initializing VFS and device sub-sytems, mount platform filesystems,
	// register platform devices...
	
	vfs_init();
	vfs_file_init();

	vfs_register_fs(&smemfs_file_system, VFS_REGISTER_STATIC);
	vfs_register_fs(&protofs_file_system, VFS_REGISTER_STATIC);
	vfs_mount("protofs", NULL, VFS_MOUNT_ROOT);

	vfs_create("/", "dev", INODE_TYPE_PARENT, INODE_FLAG_READ | INODE_FLAG_EXEC, 0);
	vfs_create("/dev", "tty1", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00040000);
	vfs_create("/dev", "tty2", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00040001);
	vfs_create("/dev", "serial", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00030000);

	vfs_create("/dev", "console", INODE_TYPE_DEV, INODE_FLAG_WRITE, 
			console_get_device());

	DBG_WAIT;

	// keyboard input for virtual terminals
	kbd_set_kstroke_handler(&vt_key_stroke);


	// mount additional filesystems
	vfs_create("/", "mnt", INODE_TYPE_PARENT, INODE_FLAG_WRITE, 0);
	vfs_create("/mnt", "smem", INODE_TYPE_PARENT, INODE_FLAG_WRITE, 0);

	vfs_mount("smemfs", "/mnt/smem", VFS_MOUNT_NORMAL);
	
	DBG_WAIT;

	// set /dev/display device
	_display_device.init();
	dev_register_device(&_display_device, 0x20);
	vfs_create("/dev", "display", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00200001);


	// direct keyboard device on major 0x21
	fxkeyboard_device.init();
	dev_register_device(&fxkeyboard_device, 0x21);
	vfs_create("/dev", "keyboard", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00210000);


	DBG_WAIT;

	//test_keymatrix();
//	test_keyboard();
	/*while(1) {
		char c;
		if(vfs_read(console, &c, 1) == 1) {
			vfs_write(console, &c, 1);
		}
	}*/

	DBG_WAIT;

	//test_vfs();

	//test_sdcard();

	//test_sleep_funcs();


	// EEPROM-related code commented to avoid useless write cycles ;)
	//test_eeprom();
	
	/*char mybuf[128];
	int len;

	len = usb_receive(USB_EP_ADDR_EP1OUT, mybuf, 10, 0);
	printk(LOG_DEBUG, "usb_receive ret=%d\n", len);
	if(len > 0) {
		mybuf[len] = '\0';
		printk(LOG_DEBUG, "content = '%s'\n", mybuf);
	}
	

	while(!_magic_lock);
	set_kernel_print(&print_usb_ep2);

	test_vfs();
*/

	// memory area subsystem
	mem_area_init();
	

	process_init();
	sched_init();
	test_process();
	

	printk(LOG_WARNING, "End of init job, sleeping...\n");
	while(1)
		printk(LOG_WARNING, "IER: 0x%x 0x%x\n", USB.IFR0.BYTE, USB.IFR1.BYTE);
}