示例#1
0
文件: schedule.c 项目: drewt/Telos
_Noreturn void sched_start(void)
{
	idle_pid = create_kernel_process(idle_proc, NULL, 0);
	create_init();
	current = next();
	switch_to(current);
}
示例#2
0
/* kernel_main()
 *  This is called by the low-level architecture startup routine. It sets up
 *  the kernel proper and generally gets the operating system off the ground.
 */
void kernel_main(unsigned int initial_stack)
{
    initial_esp = initial_stack; /* as given to us by multiboot */
    
    /* Set up the default kernel flags. Change these by adding their 
     * corresponding option when booting the kernel.
     */
    kern.flags.preempt_kernel = TRUE;
    kern.flags.debug_sched = FALSE;
    kern.flags.debug_task = FALSE;
    kern.flags.debug_interrupt = FALSE;
    kern.flags.debug_ticks = FALSE;
    kern.flags.stats = FALSE;

    /* Before we do anything with the higher-level kernel, move the kernel 
     * stack to a known location. This has to copy and remap all absolute
     * memory addresses.
     */
    move_stack((void *)STACK_LOC, STACK_SIZE);

    /* Extract and set any options given to the kernel */
    parse_cmdline(kern.cmdline);
    
    /* Now that all the lower-level startup has been done, we can set up
     * the higher-level kernel functions.
     */
    init_vt();
    print_startup();
    setup_initrd();
    load_kernel_symbols();
    init_sched();
    init_task();
    create_init();

    /* Start the kthread daemon going to set up other kernel threads */
    kthread_create(kthreadd, "kthreadd");

    /* And we're done */
    kprintf("Kernel startup complete in %ldms\n\n",
            kern.current_time_offset.tv_msec);
    
    /* We need to wait a bit here for all the threads to settle themselves 
     * before going away.
     */
    sleep(100);

    /* The kernel task has finished the startup, so remove the task from the
     * system. This should never return, so panic if it does.
     */
    task_exit();
    panic("Kernel task did not die when it was supposed to :-(");
}
示例#3
0
int ct36x_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	int err = -1;
	int binchksum;
	int updcnt;
	struct ct36x_ts_info *ts;
	struct device *dev;

	if ( CT36X_TS_CORE_DEBUG )
	printk(">>>>> %s() called <<<<< \n", __FUNCTION__);

	dev = &client->dev;
#ifdef CONFIG_OF
	if (ts_com->owner != NULL) return -ENODEV;
	memset(ts_com, 0 ,sizeof(struct touch_pdata));
	ts_com = (struct touch_pdata*)client->dev.platform_data;
	printk("ts_com->owner = %s\n", ts_com->owner);
	ct36x_platform_get_cfg(&ct36x_ts);
	ct36x_ts.client = client;
	i2c_set_clientdata(client, &ct36x_ts);
	ts_com->hardware_reset = ct36x_hw_reset;
	ts_com->read_version = ct36x_read_version;
	ts_com->upgrade_touch = ct36x_upgrade_touch;
#else
	struct ct36x_platform_data *pdata;
	pdata = dev->platform_data;

	if ( pdata ) {
		ct36x_ts.i2c_address = client->addr;
		ct36x_ts.irq = pdata->irq;
		ct36x_ts.rst = pdata->rst;
		ct36x_ts.ss = pdata->ss;
		ct36x_platform_get_cfg(&ct36x_ts);

		ct36x_ts.client = client;
		i2c_set_clientdata(client, &ct36x_ts);
	} else {
		printk("No platform data for device %s.\n", DRIVER_NAME);
	}
	
	plat_data = dev->platform_data;
#endif
	ts = (struct ct36x_ts_info *)i2c_get_clientdata(client);

	/* Create Proc Entry File */
	//ts->proc_entry = create_proc_entry(DRIVER_NAME, 0666/*S_IFREG | S_IRUGO | S_IWUSR*/, NULL);
	ts->proc_entry = proc_create(DRIVER_NAME, 0666/*S_IFREG | S_IRUGO | S_IWUSR*/, NULL, &ct36x_ts_fops);
	if ( ts->proc_entry == NULL ) {
		dev_err(dev, "Failed creating proc dir entry file.\n");
	}
	//else {
		//ts->proc_entry->proc_fops = &ct36x_ts_fops;
	//}

	/* register early suspend */
#ifdef CONFIG_HAS_EARLYSUSPEND
	ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	ts->early_suspend.suspend = ct36x_early_suspend;
	ts->early_suspend.resume = ct36x_early_resume;
	register_early_suspend(&ts->early_suspend);
#endif

	/* Check I2C Functionality */
	err = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
	if ( !err ) {
		dev_err(dev, "Check I2C Functionality Failed.\n");
		goto ERR_I2C_CHK;
	}

	/* Request platform resources (gpio/interrupt pins) */
	err = ct36x_platform_get_resource(ts);
	if ( err ) {
		dev_err(dev, "Unable to request platform resource for device %s.\n", DRIVER_NAME);
		goto ERR_PLAT_RSC;
	}

	/* Hardware reset */
	#ifdef CONFIG_OF
	ct36x_platform_hw_reset(ts);
	#else
	ct36x_platform_hw_reset(pdata);
	#endif

	updcnt = 5;
	while (updcnt--) {
		if (ct36x_test_read(client, client->addr, (char *)&binchksum, 1) == 1) 
			break;
	}
	if (updcnt <= 0) {
		printk("ct36x touch not exit!\n");
		goto ERR_PLAT_RSC;
	}
	binchksum = 0;

#ifdef LATE_UPGRADE
	ts_com->upgrade_task = kthread_run(ct36x_late_upgrade, NULL, "ct36x_late_upgrade");
	if (!ts_com->upgrade_task)
		printk("%s creat upgrade process failed\n", __func__);
	else
		printk("%s creat upgrade process sucessful\n", __func__);
#else
	// Get binary Checksum
	binchksum = ct36x_chip_get_binchksum(ts->data.buf);
	if ( CT36X_TS_CORE_DEBUG )
	printk("Bin checksum: 0x%x\n", binchksum);

	// Get firmware Checksum
	fwchksum = ct36x_chip_get_fwchksum(client, ts->data.buf);
	if ( CT36X_TS_CORE_DEBUG )
	printk("Fw checksum: 0x%x\n", fwchksum);
	//while(1){}
	updcnt = 2;
	while ( binchksum != fwchksum && updcnt--) {
		/* Update Firmware */
		ct36x_chip_go_bootloader(client, ts->data.buf);

		/* Hardware reset */
		#ifdef CONFIG_OF
		ct36x_platform_hw_reset(&ct36x_ts);
		#else
		ct36x_platform_hw_reset(plat_data);
		#endif

		// Get firmware Checksum
		fwchksum = ct36x_chip_get_fwchksum(client, ts->data.buf);

		if ( CT36X_TS_CORE_DEBUG )
		printk("Fw checksum: 0x%x\n", fwchksum);
	}
#if defined(CONFIG_TOUCHSCREEN_CT36X_CHIP_CT365)
	ct36x_check_trim(ct36x_ts.client);
#endif
	printk("Fw update %s. 0x%x, 0x%x\n", binchksum != fwchksum ? "Failed" : "Success", binchksum, fwchksum);

	/* Hardware reset */
	#ifdef CONFIG_OF
	ct36x_platform_hw_reset(&ct36x_ts);
	#else
	ct36x_platform_hw_reset(plat_data);
	#endif
#endif
	/* allocate input device */
	ts->input = input_allocate_device();
	if ( !ts->input ) {
		dev_err(dev, "Unable to allocate input device for device %s.\n", DRIVER_NAME);
		err = -ENOMEM;
		goto ERR_INPUT_ALLOC;
	}

	/* config input device */
	__set_bit(EV_SYN, ts->input->evbit);
	__set_bit(EV_KEY, ts->input->evbit);
	__set_bit(EV_ABS, ts->input->evbit);

	__set_bit(INPUT_PROP_DIRECT, ts->input->propbit);
	input_mt_init_slots(ts->input, CT36X_TS_POINT_NUM, 0);

	//input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, CT36X_TS_ABS_X_MAX, 0, 0);
	//input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, CT36X_TS_ABS_Y_MAX, 0, 0);
	#ifdef CONFIG_OF
	if (ts_com->pol & 4)
		swap(ts_com->xres, ts_com->yres);
	input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, ts_com->xres, 0, 0);
	input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, ts_com->yres, 0, 0);
	#else
	input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, plat_data->x_max, 0, 0);
	input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, plat_data->y_max, 0, 0);
	#endif
	input_set_abs_params(ts->input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
	input_set_abs_params(ts->input, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
	ts->input->name = DRIVER_NAME;
	ts->input->id.bustype =	BUS_I2C;

	/* register input device */
	err = input_register_device(ts->input);
	if ( err ) {
		dev_err(dev, "Unable to register input device for device %s.\n", DRIVER_NAME);
		goto ERR_INPUT_REGIS;
	}

	/* Create work queue */
	INIT_WORK(&ts->event_work, ct36x_ts_workfunc);
	ts->workqueue = create_singlethread_workqueue(dev_name(&client->dev));

	/* Init irq */
	//gpio_set_status(GPIO_FT_IRQ, gpio_status_in);
  //gpio_irq_set(170, GPIO_IRQ(FT_IRQ-INT_GPIO_0, GPIO_IRQ_FALLING));
	//err = request_irq(ts->irq, ct36x_ts_irq, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, DRIVER_NAME, ts);
	#ifndef CONFIG_OF
	if (pdata->init_gpio) {
  	pdata->init_gpio();
	}
	#endif
	err = request_irq(ts->irq, ct36x_ts_irq, IRQF_DISABLED,  DRIVER_NAME, ts);
	#ifdef LATE_UPGRADE
	disable_irq(ts->irq);
	#endif
	if ( err ) {
		dev_err(dev, "Unable to request irq for device %s.\n", DRIVER_NAME);
		goto ERR_IRQ_REQ;
	}

	/* Set device is ready */
	ts->state = CT36X_STATE_NORMAL;

	/* power denoisy*/
	//ct36x_chip_set_adapter_on(client, ts->data.buf);
	//ct36x_chip_set_adapter_off(client, ts->data.buf);
	//ct36x_ts_adapter(0);
	create_init(client->dev, ts_com);
	printk("%s: over\n",__func__);
	return 0;

	ERR_IRQ_REQ:
	destroy_workqueue(ts->workqueue);
	ERR_INPUT_REGIS:
	input_free_device(ts->input);
	ERR_INPUT_ALLOC:
	ERR_PLAT_RSC:
	ct36x_platform_put_resource(ts);
	ERR_I2C_CHK:
#ifdef CONFIG_HAS_EARLYSUSPEND
	unregister_early_suspend(&ts->early_suspend);
#endif
	remove_proc_entry(DRIVER_NAME, NULL);
	ts_com->owner = NULL;
	return err;
}
示例#4
0
void fuzix_main(void)
{
	/* setup state */
	inint = false;
	udata.u_insys = true;

#ifdef PROGTOP		/* FIXME */
	ramtop = (uaddr_t)PROGTOP;
#endif

	tty_init();

	if (d_open(TTYDEV, 0) != 0)
		panic(PANIC_NOTTY);

	/* Sign on messages */
	kprintf(
			"FUZIX version %s\n"
			"Copyright (c) 1988-2002 by H.F.Bower, D.Braun, S.Nitschke, H.Peraza\n"
			"Copyright (c) 1997-2001 by Arcady Schekochikhin, Adriano C. R. da Cunha\n"
			"Copyright (c) 2013-2015 Will Sowerbutts <*****@*****.**>\n"
			"Copyright (c) 2014-2015 Alan Cox <*****@*****.**>\nDevboot\n",
			sysinfo.uname);

#ifndef SWAPDEV
#ifdef PROC_SIZE
	maxproc = procmem / PROC_SIZE;
	/* Check we don't exceed the process table size limit */
	if (maxproc > PTABSIZE) {
		kprintf("WARNING: Increase PTABSIZE to %d to use available RAM\n",
				maxproc);
		maxproc = PTABSIZE;
	}
#else
	maxproc = PTABSIZE;
#endif
#else
	maxproc = PTABSIZE;
#endif
	/* Used as a stop marker to make compares fast on process
	   scheduling and the like */
	ptab_end = &ptab[maxproc];

	/* Parameters message */
	kprintf("%dkB total RAM, %dkB available to processes (%d processes max)\n", ramsize, procmem, maxproc);
	bufinit();
	fstabinit();
	pagemap_init();
	create_init();

	/* runtime configurable, defaults to build time setting */
	ticks_per_dsecond = TICKSPERSEC / 10;

	kputs("Enabling interrupts ... ");
	__hard_ei();		/* Physical interrupts on */
	kputs("ok.\n");

	/* get the root device */
	root_dev = get_root_dev();

	/* finish building argv */
	complete_init();

	/* initialise hardware devices */
	device_init();

	/* Mount the root device */
	kprintf("Mounting root fs (root_dev=%d, r%c): ", root_dev,
		ro ? 'o' : 'w');

	if (fmount(root_dev, NULLINODE, ro))
		panic(PANIC_NOFILESYS);
	root = i_open(root_dev, ROOTINODE);
	if (!root)
		panic(PANIC_NOROOT);

	kputs("OK\n");

	udata.u_cwd = i_ref(root);
	udata.u_root = i_ref(root);
	rdtime32(&udata.u_time);
	exec_or_die();
}
void main()
{

// Initialize Irobot
 create_init();
	pinMode(LEFT_LED, INPUT);
	pinMode(RIGHT_LED, INPUT);
	pinMode(FRONT_LED, INPUT);

while(1) {

	  delay (1000);	  
	  if(digitalRead(FRONT_LED) == 1) {
		if(digitalRead(RIGHT_LED) == 1 && digitalRead(LEFT_LED) == 1)
		{
			forward();
			//delay(100);
		}else {
			stop();
		}	
	  }
	  else{	
		printf("ENtered turn right\n");
		while(digitalRead(LEFT_LED) == 1 || digitalRead(RIGHT_LED) == 1)
		{	forward();			
			delay(50);		
		}	
		if (digitalRead(RIGHT_LED) == 0) {
			while (digitalRead(LEFT_LED) == 1)
				{right();
				 delay(300);}		
		}	
		printf("before while\n");
		while(digitalRead(LEFT_LED) == 0)
		{	right();
			delay(50);	
		}		
		printf("after while\n");
		while(digitalRead(LEFT_LED) == 1 && digitalRead(FRONT_LED) == 1) 
		{	forward();
			delay(50);		
		}		
		printf("after forward\n");
		if (digitalRead(FRONT_LED) == 0) {
			while (digitalRead(LEFT_LED) == 1) 
				{right();
				  delay(50);}
			printf("left led on\n");
		}

			while (digitalRead(LEFT_LED) == 0)
				{right();
				  delay(50);}	
			printf("left led off\n");
			forward();
			delay(1000);
			printf("turning left");
			left();
			printf("left turned");			
			delay(1000);


	  }


}
reverse();
delay(1000);

right();
left();
forward();
delay(1000);
stop();

}
示例#6
0
文件: start.c 项目: Abioy/FUZIX
void fuzix_main(void)
{
	/* setup state */
	inint = false;
	udata.u_insys = true;

	ramtop = PROGTOP;

	tty_init();

	if (d_open(TTYDEV, 0) != 0)
		panic("no tty");

	/* Sign on messages (stashed in a buffer so we can bin them */
	kprintf((char *)bufpool[0].bf_data, uname_str);

#ifndef SWAPDEV
#ifdef PROC_SIZE
	maxproc = procmem / PROC_SIZE;
	/* Check we don't exceed the process table size limit */
	if (maxproc > PTABSIZE) {
		kprintf((char *)bufpool[1].bf_data, maxproc);
		maxproc = PTABSIZE;
	}
#else
	maxproc = PTABSIZE;
#endif
#else
	maxproc = PTABSIZE;
#endif
	/* Parameters message */
	kprintf((char *)bufpool[2].bf_data, ramsize, procmem, maxproc);
	/* Now blow away the strings */
	bufinit();
	pagemap_init();

	create_init();
        kprintf("%x:%x\n", udata.u_page, udata.u_page2);
        kprintf("%x:%x\n", udata.u_ptab->p_page, udata.u_ptab->p_page2);
	kputs("Enabling interrupts ... ");
        ei();
	kputs("ok.\n");

	/* initialise hardware devices */
	device_init();

	root_dev = DEFAULT_ROOT;
	if (cmdline && *cmdline) {
		while (*cmdline == ' ')
			++cmdline;
		root_dev = *cmdline - '0';
	} else {
		kputs("bootdev: ");
		udata.u_base = bootline;
		udata.u_sysio = 1;
		udata.u_count = 2;
		udata.u_euid = 0;	/* Always begin as superuser */

		cdread(TTYDEV, O_RDONLY);	/* read root filesystem name from tty */
		if (*bootline >= '0')
			root_dev = *bootline - '0';
	}

	/* Mount the root device */
	kprintf("Mounting root fs (root_dev=%d): ", root_dev);

	if (fmount(root_dev, NULLINODE, 0))
		panic("no filesys");
	root = i_open(root_dev, ROOTINODE);
	if (!root)
		panic("no root");

	kputs("OK\n");

	i_ref(udata.u_cwd = root);
	i_ref(udata.u_root = root);
	rdtime32(&udata.u_time);
	exec_or_die();
}