/// @brief Setup all timers tasksi and enable interrupts /// /// @see clock_task() /// @see: timer_hal.c for hardware dependent interface // /// @return void MEMSPACE void init_timers() { printf("Timers init called\n"); if(!timers_configured) { install_timers_isr(); timers_configured = 1; timers_enabled = 0; printf("Timers configured\n"); } delete_all_timers(); clock_clear(); printf("Clock Init\n"); /// See time.c if(set_timers(clock_task,1) == -1) printf("Clock task init failed\n"); printf("Clock Installed\n"); enable_timers(); printf("Timers enabled\n"); }
void irq_handler(){ uint32_t pending = inw(VIC_VBASE+INTERRUPT_STATUS); uint32_t irq = 0; while(pending > 0){ irq = inw(VIC_VBASE+INTERRUPT_NUMBER); if(actions[irq].handler){ (*actions[irq].handler)(irq, actions[irq].opaque); }else{ pic_disable(irq); } pending = inw(VIC_VBASE+INTERRUPT_STATUS); } #if 0 if(status & (1<<TIMER0_IRQ)){ //kprintf("@"); ticks++; //assert(pls_read(current) != NULL); run_timer_list(); clock_clear(); } if( status & (1<<UART_IRQ) ){ //if ((c = cons_getc()) == 13) { // debug_monitor(tf); //} //else { extern void dev_stdin_write(char c); char c = cons_getc(); dev_stdin_write(c); //} //kprintf("#"); serial_clear(); } #endif }
/////////////////////////////////////////////////////////////////////// // Hardware and variable init. /////////////////////////////////////////////////////////////////////// void init(void) { // Oscillator selection OSCCONbits.IRCF0 = 1; OSCCONbits.IRCF1 = 1; OSCCONbits.IRCF2 = 1; // All digital pins on porta ADCON1 = 0x0F; // Set initial port state PORTA = 1; PORTB = 0; PORTC = 0x04; TRISA = PortAConfig; TRISB = PortBConfig; TRISC = PortCConfig; // PortB pullups enable INTCON2bits.NOT_RBPU = 0; // Enable the main 1-sec timer that will interrupt every second OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_32); WriteTimer0(TMR0_VAL); // Load initial timer value // Serial interface init (9600 @ 8 MHz, BRGH = 1 => 51) OpenUSART(USART_ASYNCH_MODE & USART_TX_INT_OFF & USART_RX_INT_ON & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 51); uart_state = IDLE; rx_pointer = 0; // Enable interrupts GIE and PEIE INTCON |= 0xC0; // Clear the clock clock_clear(); // Clear possible existing interrupt flags INTCONbits.INT0IF = 0; INTCONbits.TMR0IF = 0; PIR1bits.TMR1IF = 0; output = 0; switchpoint_init(); }
void clock_init_arm(uint32_t base, int irq) { // ARM_TIMER_DIV: pre-divider: clock = apb_clock / (x+1), 1MHz outw(ARM_TIMER_DIV,0x000000F9); // ARM_TIMER_CTL: control: // 1: 23-bit counter, 5: interrupt on, 7: timer on // 3..2: prescale off, 23..16: prescale, freq = clock / (x+1) outw(ARM_TIMER_CTL,0x003E00A2); clock_clear(); reload_timer(); register_irq(TIMER0_IRQ, clock_int_handler, 0); pic_enable(TIMER0_IRQ); }
static int clock_int_handler(int irq, void *data) { __common_timer_int_handler(); clock_clear(); return 0; }