Exemple #1
0
FTVOID ft9xx_int_timer (FTVOID)
{
#if defined(DEF_TIMER)
/* The Timer Prescaler will divide the 100MHz Master clock down to 2kHz */
#define TIMER_PRESCALER (50000)
#define TIMER_M_SEC     (100000/TIMER_PRESCALER)
#define TIMER_SEC       (1000*TIMER_M_SEC)
#define TIMER_PRI       (17) //why this number? I don't know, copy from sample.
    /* Enable Timers... */
    sys_enable(sys_device_timer_wdt);
    /* Set up the Timer tick to be 0.5 ms... */
    timer_prescaler(TIMER_PRESCALER);
    /* Set up Timer A to be triggered 1 second */
    timer_init(timer_select_a,              /* Device */
               TIMER_SEC,                   /* Initial Value */
               timer_direction_down,        /* Count Direction */
               timer_prescaler_select_on,   /* Prescaler Select */
               timer_mode_continuous);      /* Timer Mode */

    /* Enable the timers... */
    timer_enable_interrupt(timer_select_a);

    /* Register the interrupt... */
    interrupt_attach(interrupt_timers, TIMER_PRI, timerISR);

    /* Start all the timers at the same time... */
    timer_start(timer_select_a);
#endif
}
status_t block_device_init_driver (void)
{
  int32_t i ;
  char alpha_num[8], semaphore_name_buffer[64], * semaphore_prefix = "block_device_" ;
  char isr_semaphore_name[64] ;
  
  watch (status_t)
  {
    block_device_controls = kernel_malloc (sizeof (block_device_control_t) * 
        SOCLIB_BLOCK_DEVICES_NDEV, true) ;
    ensure (block_device_controls != NULL, DNA_OUT_OF_MEM) ;
    

    for (i = 0 ; i < SOCLIB_BLOCK_DEVICES_NDEV ; i++)
    {
      dna_itoa (i, alpha_num) ;
      dna_strcpy (semaphore_name_buffer, semaphore_prefix) ;
      dna_strcat (semaphore_name_buffer, alpha_num) ;
      dna_strcat (semaphore_name_buffer, "_sem") ;

      semaphore_create (semaphore_name_buffer, 1, 
          &block_device_controls[i] . semaphore_id) ;

      block_device_controls[i] . should_enable_irq = 
        (bool) SOCLIB_BLOCK_DEVICES[i] . should_enable_irq ;
      block_device_controls[i] . port = 
        (block_device_register_map_t) SOCLIB_BLOCK_DEVICES[i] . base_address ;

      cpu_read (UINT32, 
          & (block_device_controls[i] . port -> BLOCK_DEVICE_SIZE), 
          block_device_controls[i] . block_count) ;
      cpu_read (UINT32, 
          & (block_device_controls[i] . port -> BLOCK_DEVICE_BLOCK_SIZE), 
          block_device_controls[i] . block_size) ;

      if (block_device_controls[i] . should_enable_irq) {
        block_device_controls[i] . irq = SOCLIB_BLOCK_DEVICES[i] . irq ;
        interrupt_attach (0, SOCLIB_BLOCK_DEVICES[i] . irq, 0x0, 
            block_device_isr, false) ;
        dna_strcpy (isr_semaphore_name, semaphore_name_buffer) ;
        dna_strcat (isr_semaphore_name, "_isr") ;
        semaphore_create (isr_semaphore_name, 0, 
            &block_device_controls[i] . isr_semaphore_id) ;
      }

    }

    return DNA_OK ;
  }
}
Exemple #3
0
static void
kerext_md_attach(void *d) {
	struct mdriver_entry	*md = d;
	int						level;
	int						id;

	level = get_interrupt_level(NULL, md->intr);
	if(level < 0) {
		crash();
	}
	lock_kernel();
	id = interrupt_attach(level, &md_intr, md, 0);
	if(id < 0) {
		crash();
	}
	md->internal = id;
}