Пример #1
0
/**
 * Disables notifications on tap or double tap events
 *
 * @param Pointer to sensor structure
 * @param which event to get notifications for
 *
 * @return 0 on success, non-zero on failure
 */
static int
adxl345_sensor_unset_notification(struct sensor * sensor,
                                  sensor_event_type_t sensor_event_type)
{
#if MYNEWT_VAL(ADXL345_INT_ENABLE)
    struct adxl345 * adxl345;
    uint8_t ints_to_disable = 0;

    if ((sensor_event_type & ~(SENSOR_EVENT_TYPE_DOUBLE_TAP |
                               SENSOR_EVENT_TYPE_SINGLE_TAP)) != 0) {
        return SYS_EINVAL;
    }

    /*XXX for now we do not support registering for both events */
    if (sensor_event_type == (SENSOR_EVENT_TYPE_DOUBLE_TAP |
                                        SENSOR_EVENT_TYPE_SINGLE_TAP)) {
        return SYS_EINVAL;
    }

    adxl345 = (struct adxl345 *)SENSOR_GET_DEVICE(sensor);

    adxl345->pdd.notify_ctx.snec_evtype &= ~sensor_event_type;
    adxl345->pdd.registered_mask &= ~ADXL345_NOTIFY_MASK;

    ints_to_disable |= ADXL345_INT_SINGLE_TAP_BIT;
    ints_to_disable |= ADXL345_INT_DOUBLE_TAP_BIT;
   
    return disable_interrupt(sensor, ints_to_disable);
    
#else
    return SYS_ENODEV;
#endif
}
Пример #2
0
void i2c_setup_interrupt(const hw_module_t *port, bool state)
{
    if (state) {
        // register the IRQ sub-routine 
        register_interrupt_routine(port->irq_id, port->irq_subroutine);
        
        // enable the IRQ at the ARM core level 
        enable_interrupt(port->irq_id, CPU_0, 0);
        
        // clear the status register 
        HW_I2C_I2SR_WR(port->instance, 0);
        
        // and enable the interrupts in the I2C controller 
        HW_I2C_I2CR(port->instance).B.IIEN = 1;
    } else {
        // disable the IRQ at the ARM core level 
        disable_interrupt(port->irq_id, CPU_0);
        
        // and disable the interrupts in the I2C controller 
        HW_I2C_I2CR(port->instance).B.IIEN = 0;
        
        // clear the status register 
        HW_I2C_I2SR_WR(port->instance, 0);
    }
}
Пример #3
0
static int boot_rockbox(void)
{
    int rc;
    void (*kernel_entry)(void);

    printf("Mounting disk...");
    rc = disk_mount_all();
    if (rc <= 0)
        error(EDISK,rc, true);

    printf("Loading firmware...");
    rc = load_firmware((unsigned char *)CONFIG_SDRAM_START, BOOTFILE, 0x400000);
    if(rc <= EFILE_EMPTY)
        return rc;
    else
    {
        printf("Starting Rockbox...");
        adc_close(); /* Disable SADC, seems to fix the re-init Rockbox does */

        disable_interrupt();
        kernel_entry = (void*) CONFIG_SDRAM_START;
        kernel_entry();

        return 0; /* Shouldn't happen */
    }
}
Пример #4
0
/**
 * Run all kernel module initializers.
 */
void exec_init_array(void)
{
    extern void dyndebug_early_boot_init(void);
    extern void kmem_init(void);
    extern void dynmem_init(void);
    extern void vralloc_init(void);
    int n;

#ifdef configDYNDEBUG
    dyndebug_early_boot_init();
#endif

    kputs("\n\nZeKe PreInit\n");
    n = __hw_preinit_array_end - __hw_preinit_array_start;
    exec_array(__hw_preinit_array_start, n);

    /*
     * Memory allocator initializers.
     */
    kmem_init();
    dynmem_init();
    vralloc_init();

    kputs("SubsysInit\n");
    n  = __init_array_end - __init_array_start;
    exec_array(__init_array_start, n);

    kputs("PostInit\n");
    disable_interrupt();
    n = __hw_postinit_array_end - __hw_postinit_array_start;
    exec_array(__hw_postinit_array_start, n);
    enable_interrupt();
}
Пример #5
0
void pre_init(void) {
    morecore_area = core_buf;
    morecore_size = SERVER_CORE_SIZE;
    serial_lock();
    // Initialize the serial port
    set_dlab(0); // we always assume the dlab is 0 unless we explicitly change it
    disable_interrupt();
    disable_fifo();
    reset_lcr();
    reset_mcr();
    clear_iir();
    set_baud_rate(BAUD_RATE);
    reset_state();
    enable_fifo();
    enable_interrupt();
    clear_iir();
    // all done
    init_colours();
    /* query what getchar clients exist */
    num_getchar_clients = getchar_num_badges();
    getchar_clients = calloc(num_getchar_clients, sizeof(getchar_client_t));
    for (int i = 0; i < num_getchar_clients; i++) {
        unsigned int badge = getchar_enumerate_badge(i);
        assert(badge <= num_getchar_clients);
        getchar_clients[badge].client_id = badge;
        getchar_clients[badge].buf = getchar_buf(badge);
        getchar_clients[badge].last_head = -1;
    }
    set_putchar(serial_putchar);
    serial_irq_reg_callback(serial_irq, 0);
    /* Start regular heartbeat of 500ms */
    timeout_periodic(0, 500000000);
    serial_unlock();
}
Пример #6
0
int main(void) {
	int i;

	/* TODO: run test_printk() */
	/*
	test_printk();
*/
	disable_interrupt();
	init_pcbs();
	setup_irq(8, irq0_handle);
	setup_irq(0x80, irq1_handle);
	setup_irq(9, keyboard_int);
	/*
	kthread_create(test1_a, stack1+KSTACK_SIZE);
	kthread_create(test1_b, stack2+KSTACK_SIZE);
	kthread_create(test1_c, stack3+KSTACK_SIZE);
	kthread_create(test_thread_a, stack1+KSTACK_SIZE);
	kthread_create(test_thread_b, stack2+KSTACK_SIZE);
	
	kthread_create(test_msg_c, stack1+KSTACK_SIZE);
	kthread_create(test_msg_d, stack2+KSTACK_SIZE);
	
	kthread_create(test_thread_in_thread, stack1+KSTACK_SIZE);
	*/
	UserThread_create(0x2000);
	kthread_create(tty_driver, stack2+KSTACK_SIZE);
        enable_interrupt(); 
	
	while (1) {
		idle_cpu();
	}
}
Пример #7
0
void panic(char *str) {
    /* TODO: you can modify it as your wish */
    disable_interrupt();
    printk("\n\n** Kernel panic: %s **\n", str);
    while (1) {
        idle_cpu();
    }
}
Пример #8
0
void kernelUpdateCursor(int x,int y){
	uint16_t cursorLocation = y * 80 + x;
	disable_interrupt();
	outportb(0x3D4, 14);
	outportb(0x3D5, cursorLocation >> 8);
	outportb(0x3D4, 15);
	outportb(0x3D5, cursorLocation);
	enable_interrupt();
}
Пример #9
0
/* 游戏主循环。
 * 在初始化工作结束后,main函数就跳转到主循环执行。
 * 在主循环执行期间随时会插入异步的中断。时钟中断最终调用timer_event,
 * 键盘中断最终调用keyboard_event。中断处理完成后将返回主循环原位置继续执行。
 *
 * tick是时钟中断中维护的信号,数值含义是“系统到当前时刻已经发生过的时钟中断数”
 * HZ是时钟控制器硬件每秒产生的中断数,在include/device/timer.h中定义
 * now是主循环已经正确处理的时钟中断数,即游戏已经处理到的物理时间点
 *
 * 由于qemu-kvm在访问内存映射IO区域时每次都会产生陷入,在30FPS时,
 * 对显存区域每秒会产生30*320*200/4次陷入,从而消耗过多时间导致跳帧的产生(实际FPS<30)。
 * 在CFLAGS中增加-DSLOW可以在此情况下提升FPS。如果FPS仍太小,可以尝试
 * -DTOOSLOW,此时将会采用隔行扫描的方式更新屏幕(可能会降低显示效果)。
 * 这些机制的实现在device/video.c中。
 * */
void
main_loop(void) {
	int now = 0, target;
	int num_draw = 0;
	bool redraw;

	while (TRUE) {
		wait_for_interrupt();
		disable_interrupt();
		if (now == tick) {
			enable_interrupt();
			continue;
		}
		assert(now < tick);
		target = tick; /* now总是小于tick,因此我们需要“追赶”当前的时间 */
		enable_interrupt();

		redraw = FALSE;
		while (update_keypress())
			;

		/* 依次模拟已经错过的时钟中断。一次主循环如果执行时间长,期间可能到来多次时钟中断,
		 * 从而主循环中维护的时钟可能与实际时钟相差较多。为了维持游戏的正常运行,必须补上
		 * 期间错过的每一帧游戏逻辑。 */
		while (now < target) {
			/* 每隔一定时间产生一个新的字符 */
			if (now % (HZ / CHARACTER_PER_SECOND) == 0) {
				create_new_letter();
			}
			/* 每隔一定时间更新屏幕上字符的位置 */
			if (now % (HZ / UPDATE_PER_SECOND) == 0) {
				update_letter_pos();
			}
			/* 每隔一定时间需要刷新屏幕。注意到这里实现了“跳帧”的机制:假设
			 *   HZ = 1000, FPS = 100, now = 10, target = 1000
			 * 即我们要模拟990个时钟中断之间发生的事件,其中包含了9次屏幕更新,
			 * 但redraw flag只被置一次。 */
			if (now % (HZ / FPS) == 0) {
				redraw = TRUE;
			}
			/* 更新fps统计信息 */
			if (now % (HZ / 2) == 0) {
				int now_fps = num_draw * 2 + 1;
				if (now_fps > FPS) now_fps = FPS;
				set_fps(now_fps);
				num_draw = 0;
			}
			now ++;
		}

		if (redraw) { /* 当需要重新绘图时重绘 */
			num_draw ++;
			redraw_screen();
		}
	}
}
Пример #10
0
int
abort(const char *fname, int line) {
	/* 当程序遇到不可恢复的错误时,首先将外部中断关闭以防其他错误发生,
     * 然后显示出错信息后,等待下一个中断到来(实际永远等不到)。*/
	disable_interrupt();
	blue_screen(fname, line);
	while (TRUE) {
		wait_for_interrupt();
	}
}
Пример #11
0
bool 
wait_restart(void){
    disable_interrupt();
    if ( query_key('r' - 'a') ){
        release_key('r' - 'a');
        return true;
    }
    enable_interrupt();
    return false;
}
Пример #12
0
bool 
update_keypress(void){
    disable_interrupt();
    move_by_key('a',y,-4,SCR_WIDTH - 8);
    move_by_key('d',y,4,SCR_WIDTH - 8);
    move_by_key('w',x,-4,SCR_HEIGHT - 8);
    move_by_key('s',x,4,SCR_HEIGHT - 8);
    enable_interrupt();
    return false;
}
Пример #13
0
void _changeIntRamVect (char vector, void (* funct)(void)) {
    short int i;
    if (vector >= sizeof(vector_it_NearRAM)/sizeof(*vector_it_NearRAM) ) return;
    i = _readFlg();               /// store Interrupt flag
    disable_interrupt ();         /// disable interrupt
    vector_it_NearRAM [vector] = funct;    /// change vector in Ram Table

    if (i & (1<<6))               /// restore interrupt flag
        enable_interrupt ();
}
void power_off(void)
{
    /* Disable interrupts on this core */
    disable_interrupt(IRQ_FIQ_STATUS);

    /* Mask them on both cores */
    CPU_INT_DIS = -1;
    COP_INT_DIS = -1;

    while (1)
        DEV_RS = -1;
}
Пример #15
0
static int boot_of(void)
{
    int fd, rc, len, i, checksum = 0;
    void (*kernel_entry)(int, void*, void*);

    printf("Mounting disk...");
    rc = disk_mount_all();
    if (rc <= 0)
        error(EDISK, rc, true);

    /* TODO: get this from the NAND flash instead of SD */
    fd = open("/ccpmp.bin", O_RDONLY);
    if(fd < 0)
        return EFILE_NOT_FOUND;

    lseek(fd, 4, SEEK_SET);
    rc = read(fd, (char*)&len, 4); /* CPU is LE */
    if(rc < 4)
        return EREAD_IMAGE_FAILED;

    len += 8;
    printf("Reading %d bytes...", len);

    lseek(fd, 0, SEEK_SET);
    rc = read(fd, (void*)0x80004000, len);
    if(rc < len)
        return EREAD_IMAGE_FAILED;

    close(fd);

    for(i=0; i<len; i++)
        checksum += ((unsigned char*)0x80004000)[i];

    *((unsigned int*)0x80004000) = checksum;

    printf("Starting the OF...");

    /* OF requires all clocks on */
    __cpm_start_all();

    disable_interrupt();
    __dcache_writeback_all();
    __icache_invalidate_all();

    for(i=8000; i>0; i--)
        asm volatile("nop\n");

    kernel_entry = (void*) 0x80004008;
    kernel_entry(0, "Jan 10 2008", "15:34:42"); /* Reversed from the SPL */

    return 0; /* Shouldn't happen */
}
Пример #16
0
void uart_setup_interrupt(uint32_t instance, void (*irq_subroutine)(void), uint8_t state)
{
    uint32_t irq_id = UART_IRQS(instance);

    if (state == TRUE) {
        /* register the IRQ sub-routine */
        register_interrupt_routine(irq_id, irq_subroutine);
        /* enable the IRQ */
        enable_interrupt(irq_id, CPU_0, 0);
    } else
        /* disable the IRQ */
        disable_interrupt(irq_id, CPU_0);
}
Пример #17
0
void init_timer_interrupt(void)
{
	TimerRegs.T16PWM0CMP0DAT.all = 390;  //approx 50KHz. by spec//15.6MHz/312=50kHz//[Ken Zhang]change to 40kHz,25us
	TimerRegs.T16PWM0CMP1DAT.all = 0xffff;
	TimerRegs.T16PWM0CMPCTRL.all = 2;
	TimerRegs.T16PWM0CNTCTRL.all = 0x00c;

	disable_fast_interrupt(); //make sure fast interrupt is disabled
	disable_interrupt();
	write_firqpr (0x02000000); //make them all irqs except FAULT_INT  
	write_reqmask(0x02020000); //enable FAULT_INT and PWM0_INT 
	enable_interrupt();
	enable_fast_interrupt(); //make sure fast interrupt is enabled for OVP shutdown
}
Пример #18
0
void Timer0Handler (void)
{
	enable_interrupt();			/* handles nested interrupt */
	T0IR = 1;			/* clear interrupt flag */
	timer0_counter++;

#ifdef MTHOMAS_MOD
	if ( timer0CallbackFunction != NULL ) {
		timer0CallbackFunction();
	}
#endif

	disable_interrupt();
	VICVectAddr = 0;	/* Acknowledge Interrupt */
}
Пример #19
0
void power_off(void)
{
#ifdef HAVE_REMOTE_LCD
    lcd_remote_off();
#endif

    /* Disable interrupts on this core */
    disable_interrupt(IRQ_FIQ_STATUS);

    /* Mask them on both cores */
    CPU_INT_DIS = -1;
    COP_INT_DIS = -1;

    while (1)
        GPIOB_OUTPUT_VAL |= 0x80;
}
Пример #20
0
int _mtx_trylock(mtx_t * mtx, char * whr)
#endif
{
    int ticket;
    int retval;

    if (MTX_OPT(mtx, MTX_OPT_DINT)) {
        cpu_istate = get_interrupt_state();
        disable_interrupt();
    }

    switch (mtx->mtx_type) {
    case MTX_TYPE_SPIN:
        retval = test_and_set((int *)(&mtx->mtx_lock));
        break;

    case MTX_TYPE_TICKET:
        ticket = atomic_inc(&mtx->ticket.queue);

        if (atomic_read(&mtx->ticket.dequeue) == ticket) {
            mtx->mtx_lock = 1;
            return 0; /* Got it */
        } else {
            atomic_dec(&mtx->ticket.queue);
             if (MTX_OPT(mtx, MTX_OPT_DINT))
                set_interrupt_state(cpu_istate);
            return 1; /* No luck */
        }
        break;

    default:
        MTX_TYPE_NOTSUP();
        if (MTX_OPT(mtx, MTX_OPT_DINT))
            set_interrupt_state(cpu_istate);

        return -ENOTSUP;
    }

    /* Handle priority ceiling. */
    priceil_set(mtx);

#ifdef configLOCK_DEBUG
    mtx->mtx_ldebug = whr;
#endif

    return retval;
}
Пример #21
0
void imx233_system_prepare_shutdown(void)
{
    /* wait a bit, useful for the user to stop touching anything */
    sleep(HZ / 2);
    /* disable watchdog just in case since we will disable interrupts */
    imx233_rtc_enable_watchdog(false);
    /* disable interrupts, it's probably better to avoid any action so close
     * to shutdown */
    disable_interrupt(IRQ_FIQ_STATUS);
#ifdef SANSA_FUZEPLUS
    /* This pin seems to be important to shutdown the hardware properly */
    imx233_pinctrl_acquire(0, 9, "power off");
    imx233_pinctrl_set_function(0, 9, PINCTRL_FUNCTION_GPIO);
    imx233_pinctrl_enable_gpio(0, 9, true);
    imx233_pinctrl_set_gpio(0, 9, true);
#endif
}
Пример #22
0
void epit_setup_interrupt(uint32_t instance, void (*irq_subroutine)(void), bool enableIt)
{
    uint32_t irq_id = EPIT_IRQS(instance);

    if (enableIt)
    {    
        // register the IRQ sub-routine 
        register_interrupt_routine(irq_id, irq_subroutine);
        
        // enable the IRQ 
        enable_interrupt(irq_id, CPU_0, 0);
    }
    else
    {
        // disable the IRQ 
        disable_interrupt(irq_id, CPU_0);
    }
}
Пример #23
0
/*!
 * @brief Setup SNVS interrupt.
 *
 * Enables or disables the related HW module interrupt, and attached the related
 * sub-routine into the vector table.
 *
 * @param   port Pointer to the SNVS module structure.
 * @param   state true to enable or false to disable.
 */
void snvs_srtc_setup_interrupt(void (*irq_subroutine)(void), uint8_t state)
{
    uint32_t irq_id = IMX_INT_SNVS;

    if (state)
    {
        // register the IRQ sub-routine 
        register_interrupt_routine(irq_id, irq_subroutine);
        
        // enable the IRQ 
        enable_interrupt(irq_id, CPU_0, 0);
    }
    else
    {
        // disable the IRQ 
        disable_interrupt(irq_id, CPU_0);
    }
}
Пример #24
0
//改变蛇的运动方向
void ChangeDir()
{
	disable_interrupt();
	//寻找已经按下的键,若有多个键按下,处理优先级以此为上下左右
	int i;
	for(i=0;i<4;i++)
	{
		if(query_key(i))
			switch(i)
			{
				case 0:snake.dir = up;break;
				case 1:snake.dir = down;break;
				case 2:snake.dir = left;break;
				case 3:snake.dir = right;break;
			}
		release_key(i);
	}	
	enable_interrupt();
}	
Пример #25
0
void serial_init(gdb_state_t *gdb) {
    // Initialize the serial port
    int UNUSED error;
    error = serial_lock();
    gdb_state = gdb;
    set_dlab(0); // we always assume the dlab is 0 unless we explicitly change it
    disable_interrupt();
    disable_fifo();
    reset_lcr();
    reset_mcr();
    clear_iir();
    set_baud_rate(BAUD_RATE);
    reset_state();
    enable_fifo();
    enable_interrupt();
    clear_iir();
    initialise_buffer();
    error = serial_unlock();

}
Пример #26
0
Файл: main.c Проект: NJUOS/Lab0
void
play(void) { //主循环
	const char *text = "http://cslab.nju.edu.cn/opsystem";
	static char buf[2];
	int text_len = 32;
	int w = SCR_WIDTH / 8;
	int color = 0, start_pos = 0, clk = 0;

	for (; ; clk = (clk + 1) % 5) { // 主循环是一个死循环
		int i;
		prepare_buffer(); // 在绘图之前,先需要准备缓冲区

		if (clk == 0) {
			start_pos = (start_pos + 1) % w;
		}
		color = (color + 1) % 72;
		for (i = 0; i < text_len; i ++) { // 计算每个字符的位置 然后显示在屏幕上
			int j = (i + start_pos) % w;
			int d = 50 * sin(2 * PI * j / w);
			buf[0] = text[i];
			draw_string(buf, 8 * j, SCR_HEIGHT / 2 - 4 + d, 32 + color);
		}
		
		// 在左下角显示键盘扫描码
		draw_string(itoa(last_key), 0, SCR_HEIGHT - 8, live > 0 ? 10: 7);
		if (live > 0) live --;

		i = HZ / 60;	
		while (i) {
			wait_for_interrupt();
			disable_interrupt(); // 关闭中断是为了防止数据竞争(data race)。
			if (timers > 0) {
				timers --;
				i --;
			}
			enable_interrupt();
		}

		display_buffer(); // 绘图结束后,调用这个函数将绘制的图像显示到屏幕上
	}
}
Пример #27
0
/**
 * Disable the high threshold interrupt
 *
 * @param ptr to sensor
 * @param the Sensor type
 *
 * @return 0 on success, non-zero on failure
 */
static int
adxl345_sensor_clear_high_thresh(struct sensor *sensor,
                                  sensor_type_t type)
{
    struct adxl345 *adxl345;
    uint8_t ints_to_disable = ADXL345_INT_ACTIVITY_BIT;

    if (type != SENSOR_TYPE_ACCELEROMETER) {
        return SYS_EINVAL;
    }

    adxl345 = (struct adxl345 *)SENSOR_GET_DEVICE(sensor);

    /* if neither high or low threshs are now set disable read mask */
    if((adxl345->pdd.int_enable & ADXL345_INT_INACTIVITY_BIT) == 0) {
        adxl345->pdd.read_ctx.srec_type &= ~type;
        adxl345->pdd.registered_mask &= ~ADXL345_READ_MASK;
    }

    return disable_interrupt(sensor, ints_to_disable);
}
Пример #28
0
void main(void)
{
  disable_interrupt();
  
  clock_init();

  /* workaround to wait for LSM9DS0 ready */
  clock_delay_usec(60000);

  /* serial port */
  serial_init();

  /* one wire UART based LIN (ULIN) */
  ulin_init();

  /* real time timer */
  rtimer_init();

  /* radio configuration */
  rf_init(RADIO_CHANNEL);

  /* comment this line out to prevent bluetooth board from crashing */
  printf("\nSMAC2.0 - [%x:%x]\n", rf_get_short_addr1(), rf_get_short_addr0());
  
  enable_interrupt();

  /* module specific initialization - modules.h */
  module_init();

  /* flash bank used as storage */
  flash_bank_select(FLASH_BANK_7);

  /* looping services */
  while(1)
  {
    json_service();
    serial_service();
    ulin_service();
  }
}
Пример #29
0
/*!
 * @brief Setup keypad interrupt.
 *
 * Enables or disables the related HW module interrupt, and attached the related sub-routine
 * into the vector table.
 *
 * @param state Flag indicating whether to enable (true) or disable (false) the interrupt.
 */
void kpp_setup_interrupt(bool state)
{
    if (state)
    {    
        // clear status flags and synchronizer chains 
        kpp_clear_status();
        
        // register the IRQ sub-routine 
        register_interrupt_routine(IMX_INT_KPP, &kpp_interrupt_routine);
        
        // enable the IRQ 
        enable_interrupt(IMX_INT_KPP, CPU_0, 0);
    }
    else
    {
        // disable the IRQ 
        disable_interrupt(IMX_INT_KPP, CPU_0);
        
        // clear status flags and synchronizer chains 
        kpp_clear_status();
    }
}
Пример #30
0
void  kernel_panic (const char* fmt, ...) {
		
	/*va_list		args;
	va_start (args, fmt);
	va_end (args);*/

	disable_interrupt ();
	char* panicMessage="Sorry SeaStar encountered a critical problem and cannot continue\n\
			    Yeah this is a Kernel Panic. Any unsaved work is lost.\n\
			    Please restart your computer.\n\n";

	kernelClrScr (0x1f);
	kernelGotoXY (0,0);
	kernelSetColor (0x1f);
	kernelPuts (panicMessage);

	kernelPrintf ("*** STOP: ");
	int i=0;	
	for(i=0;fmt[i] != '\0';i++)
		kernelPrintf ("%c",fmt[i]);

	while(1);
}