//main function int main(void) { char key ; //1. system initialazation STARTUP; //2. initialise peripherals init_pioa() ; //3. initially turn led off led_off() ; //4. initialize timer init_tc() ; //5. initialize interrupt controller init_aic() ; tc -> Channel_0.CCR = 0x5; //6. start the timer //7. wait until the user presses 'x' while ( (key = getchar() != 'x')) {} //8. then cleanup peripherals and system clear_aic(); clear_tc() ; led_off() ; //9. turn off led CLEANUP; //and exit return 0 ; }
//FIQ handler void FIQ_handler(void) { unsigned int data_in = 0; unsigned int fiq = 0 ; unsigned int data_out; fiq = aic -> IPR ; // read the IRQ source if (fiq & (1<<PIOA_ID)) { data_in = pioa->ISR; //clear the interrupt source of pioa aic->ICCR = AIC(PIOA_ID); //then clears the interrupt from aic data_in = pioa->PDSR; //read input of PDSR (line 1) if ( data_in & 0x01 ) { //button pressed if (button_state == BUT_IDLE) { button_state = BUT_PRESSED; if ( led_state == LED_IDLE ){ tc -> Channel_0.CCR = 0x5 ; // start the timer led_state = LED_FLASHING ; }else{ clear_tc(); led_state = LED_IDLE; } } }else{ if(button_state == BUT_PRESSED) button_state = BUT_IDLE; } } if (fiq & (1<<TC0_ID)) { //if source of interrupt is 17 timer/counter 0 data_out = tc -> Channel_0.SR ; // clear timer IRQ aic -> ICCR = (1<<TC0_ID) ; // then clear pending from aic data_out = pioa->ODSR; pioa->SODR = data_out & PIO(OBIT); pioa->CODR = data_out & PIO(OBIT); tc -> Channel_0.CCR = 0x5 ; // start the timer } }
//main function int main(void) { char key ; STARTUP; init_pioa() ; init_tc() ; init_aic() ; while ( (key = getchar() != 'e')) {} clear_aic(); clear_tc() ; CLEANUP; //and exit return 0 ; }
static irqreturn_t txdtc_interrupt_handler(int irq, void *dev_id) { static int cycle = 0; static char bits[10]; /* 11 send clock */ static char in_byte = 0x00; int j=0; clear_tc(TXD_CLOCK_CHN); /* The data bit send cycle */ if( in_byte ) { at91_set_gpio_value(AT91_PIN_PB4, bits[cycle]); if(unlikely(STOP_BIT == cycle)) { /* A byte data send over, tx_ring tail head on */ tx_ring.tail = (tx_ring.tail + 1) & (CIRC_BUF_SIZE - 1); /* All the bit in a bytes send over */ in_byte = 0x00; } cycle++; } /* First cycle used to prepare the send data */ else if ( CIRC_CNT(tx_ring.head, tx_ring.tail, CIRC_BUF_SIZE) > 0 ) { /* Start bit send low level*/ bits[START_BIT]=LOWLEVEL; /* 8bits data in a byte */ for(j=0; j<8; j++) bits[j+START_BIT+1]=(tx_ring.buf[tx_ring.tail]>>j) & 0x01; /* Stop bit send high level*/ bits[STOP_BIT]=HIGHLEVEL; /* Goes to next cycle start to send every bit in a bytes */ in_byte = 0x01; cycle = START_BIT; send_over = 0; }