void HotPlugService (void) { DisableInterrupts(0xFF); Active9232(); if ((HDCP_TxSupports == true)) { if (HDCP_AksvValid == true) { // AV MUTE TPI_DEBUG_PRINT (("TMDS -> Enabled (Video Muted)\n")); ReadModifyWriteTPI(0x1A, BIT_6 | BIT_4 | BIT_3, 0x40 | 0x00 | 0x08); tmdsPoweredUp = true; EnableInterrupts(BIT_0 | 0x02 | 0x10 | 0x20 | 0x40 | 0x80); } } else { TPI_DEBUG_PRINT (("TMDS -> Enabled\n")); ReadModifyWriteTPI(0x1A, BIT_6 | BIT_4 | BIT_3, 0x40 | 0x00 | 0x08); tmdsPoweredUp = TRUE; EnableInterrupts(0x01 | 0x02 | 0x10 | 0x40); } TxPowerStateD0(); I2C_WriteByte(TPI_SLAVE_ADDR, 0xcd, 0x0); I2C_WriteByte(TPI_SLAVE_ADDR, 0x19, 0x0); }
static void xmbrs_flush_chars(struct tty_struct *tty) { volatile unsigned int *uartp; struct xmb_serial *info = (struct xmb_serial *)tty->driver_data; unsigned long flags; if (serial_paranoia_check(info, tty->device, "xmbrs_flush_chars")) return; uartp = (volatile unsigned int *) info->addr; EnableInterrupts(uartp); /* If there are chars waiting in RX buffer then enable interrupt to permit receiving them */ save_flags_cli(flags); if ( (uartp[XUL_STATUS_REG_OFFSET/4] & XUL_SR_RX_FIFO_VALID_DATA) && (info->flags & ASYNC_INITIALIZED) ) { EnableInterrupts(uartp); } /* Any chars pending to go out (and tty not stopped etc)? */ if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || !info->xmit_buf) return; /* Force remaining chars out */ save_flags_cli(flags); EnableInterrupts(uartp); force_tx_fifo_fill(info); restore_flags(flags); }
int main(void){ // Real Lab13 // for the real board grader to work // you must connect PD3 to your DAC output TExaS_Init(SW_PIN_PE3210, DAC_PIN_PB3210,ScopeOn); // activate grader and set system clock to 80 MHz // PortE used for piano keys, PortB used for DAC Sound_Init(); // initialize SysTick timer and DAC Piano_Init(); EnableInterrupts(); // enable after all initialization are done DAC_Init(); while(1){ volatile unsigned long current_switch; current_switch = Piano_In(); if (current_switch == 0x01){ EnableInterrupts(); Sound_Tone(4780); } else if (current_switch == 0x02){ EnableInterrupts(); Sound_Tone(4259); } else if (current_switch == 0x04){ EnableInterrupts(); Sound_Tone(3794); } else if (current_switch == 0x08){ EnableInterrupts(); Sound_Tone(3189); } // else if (current_switch == 0x00){ // Sound_Off(); // DisableInterrupts(); // } delay(10); } }
int main(void){ // configurar a UART1 U1BRG = ((20000000 + 8 * 38400) / (16 * 38400)) - 1; U1MODEbits.BRGH = 0; //divisão por 16 U1MODEbits.PDSEL = 0b10; U1MODEbits.STSEL = 0; // 1 stop bit - 1 U1STAbits.URXEN = 1; U1STAbits.UTXEN = 1; U1MODEbits.ON = 1; IFS0bits.U1RXIF = 1; // UART interrupts U1STAbits.URXISEL = 00; IEC0bits.U1RXIE = 1; IPC6bits.U1IP = 3; EnableInterrupts(); // ADC TRISBbits.TRISB14 = 1; // RB4 digital output disconnected AD1PCFGbits.PCFG14 = 0; // RB4 configured as analog input (AN4) AD1CHSbits.CH0SA = 14; // Selects AN7 as input for the A/D converter AD1CON2bits.SMPI = 7; // 8 conversoes AD1CON1bits.SSRC = 7; AD1CON1bits.CLRASAM = 1; AD1CON3bits.SAMC = 16; AD1CON1bits.ON = 1; IPC6bits.AD1IP = 3; IEC1bits.AD1IE = 1; IFS1bits.AD1IF = 0; EnableInterrupts(); // Timer 4 PR4 = 34482; T4CONbits.TCKPS = 2; TMR4 = 0; //Timer 4 interrupts IFS0bits.T4IF = 0; IPC4bits.T4IP = 2; IEC0bits.T4IE = 1; //Timer 2 PR2 = 49999; T2CONbits.TCKPS = 2; TMR2 = 0; T2CONbits.TON = 1; OC1CONbits.OCM = 6; OC1CONbits.OCTSEL = 0; OC1RS = 12500; OC1CONbits.ON = 1; while(1); return 0; }
// ******** OS_Wait ************ // decrement semaphore and spin/block if less than zero // input: pointer to a counting semaphore // output: none void OS_Wait(Sema4Type *s){ DisableInterrupts(); while( s->Value <= 0){ //TODO: implement Blocking EnableInterrupts(); DisableInterrupts(); } s->Value--; EnableInterrupts(); }
// ******** OS_bWait ************ // if the semaphore is 0 then spin/block // if the semaphore is 1, then clear semaphore to 0 // input: pointer to a binary semaphore // output: none void OS_bWait(Sema4Type *semaPt){ DisableInterrupts(); while( semaPt->Value != 1){ //TODO: implement Blocking EnableInterrupts(); OS_Suspend(); DisableInterrupts(); } semaPt->Value =0; EnableInterrupts(); return; }
// ------------------------- OS_bWait -------------------------------- void OS_bWait(Sema4Type *semaPt){ DisableInterrupts(); while (semaPt->Value <= 0){ unlinkTCB(&Actives, RunPt); linkTCB(&(semaPt->Blocked), RunPt); RunPt->blockSt = semaPt; OS_Suspend(); EnableInterrupts(); } DisableInterrupts(); (*semaPt).Value = 0; EnableInterrupts(); }
static void xmbrs_unthrottle(struct tty_struct * tty) { struct xmb_serial *info = (struct xmb_serial *)tty->driver_data; #ifdef SERIAL_DEBUG_THROTTLE char buf[64]; printk("unthrottle %s: %d....\n", _tty_name(tty, buf), tty->ldisc.chars_in_buffer(tty)); #endif if (serial_paranoia_check(info, tty->device, "xmbrs_unthrottle")) return; if (I_IXOFF(tty)) { if (info->x_char) info->x_char = 0; else { /* Force START_CHAR (xon) out */ volatile unsigned int *uartp; unsigned long flags; info->x_char = START_CHAR(tty); uartp = (volatile unsigned int *) info->addr; save_flags_cli(flags); EnableInterrupts(uartp); force_tx_fifo_fill(info); restore_flags(flags); } } }
int main(void){ // Digital ports configuration TRISE = TRISE | 0xF0; // RE7-4 configured as input // UART1 configuration U1BRG = ((PBCLK+8*115200)/(16*115200))-1; // 115200 baudrate U1MODEbits.PDSEL = 0; // 8 bits no parity U1MODEbits.STSEL = 0; // 1 stop bit U1STAbits.URXEN = 1; // Receiver enable U1STAbits.URXISEL = 0; // Receiver interrupt mode U1MODEbits.ON = 1; // UART enable // Timer 2 configuration T2CONbits.TCKPS = 4; // 1:16 prescaler PR2 = PBCLK/16/100-1; // 100Hz frequency TMR2 = 0; // Reset T2 count register IEC0bits.T2IE = 1; // Enable T2 interrupts IPC2bits.T2IP = 4; // T2 interrupt priority IFS0bits.T2IF = 0; // Reset T2 interrupt flag T2CONbits.TON = 1; // Enable T2 EnableInterrupts(); // Global interrupt enable while(1); return 0; }
//debug code int main(void){ PLL_Init(Bus80MHz); // bus clock at 50 MHz Output_Init(); SYSCTL_RCGCGPIO_R |= 0x20; // activate port F //ADC0_InitTimer0ATriggerSeq3(2, F30HZ); // ADC channel 0, 1000 Hz sampling ADC0_InitTimer0ATriggerSeq3PD3(F30HZ); //ADC0_InitSWTriggerSeq3_Ch9(); while((SYSCTL_PRGPIO_R&0x0020) == 0){};// ready? GPIO_PORTF_DIR_R |= 0x02; // make PF1 output (PF1 built-in LEDs) GPIO_PORTF_AFSEL_R &= ~0x02; // disable alt funct on PF1 GPIO_PORTF_DEN_R |= 0x02; // enable digital I/O on PF1 // configure PF1 as GPIO GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF0FF)+0x00000000; GPIO_PORTF_AMSEL_R = 0; // disable analog functionality on PF EnableInterrupts(); plotInit(); while(1){ GPIO_PORTF_DATA_R ^= 0x02; // toggle LED //ADCvalue = ADC0_InSeq3(); temperature = adcToTemp(ADCvalue + offset); plotPoint(); ST7735_SetCursor(1,2); ST7735_sDecOut2(temperature); ST7735_SetCursor(2,1); ST7735_OutUDec(ADCvalue + offset); } }
void EXTI0_IRQHandler(void) { DisableInterrupts(); PressButtom = TRUE; EXTI_ClearITPendingBit(EXTI_Line0); EnableInterrupts(); }
void main (void) { int i; // counter // Init I/O TRISD = 0b00000000; // PORTD bits 7:0 are all outputs (0) TRISEbits.TRISE0 = 1; // TRISE0 input INTCON2bits.RBPU = 0; // enable PORTB internal pullups WPUBbits.WPUB0 = 1; // enable pull up on RB0 SetIntOSC(&ClockSpeed); // Set initial clock speed (250kHz) SetupINT0Switch(); // Init switch EnableInterrupts(); // Turn on interrupts while (1) { // delay and count on LEDs here. Interrupt handles switch and freq changes LATD = LED_Count++; // output count to PORTD LEDs for (i = 0; i < 10; i++)// delay 1 sec @ 250kHz { __delay_ms(100); } } }
void Touch_BeginWaitForTouch(void){ // XP = 1 XN = DIG IN, INT ON FALL EDGE YP = Hi-Z YN = 0 DisableInterrupts(); // Set XP high TOUCH_XP = 0xFF; // Set YN low TOUCH_YN = 0x00; // Configure XN (PA3) for digital input GPIO_PORTA_DIR_R &= ~0x08; // Configure YP (PE5) for analog Hi-Z GPIO_PORTE_DIR_R &= ~0x20; GPIO_PORTE_DEN_R &= ~0x20; // Setup falling edge interrupt on XN (PA3) GPIO_PORTA_PUR_R |= 0x08; // enable weak pull up GPIO_PORTA_IS_R &= ~0x08; // (d) PF4 is edge-sensitive GPIO_PORTA_IBE_R &= ~0x08; // PF4 is not both edges GPIO_PORTA_IEV_R &= ~0x08; // PF4 falling edge event GPIO_PORTA_ICR_R = 0x08; // (e) clear flag4 GPIO_PORTA_IM_R |= 0x08; // (f) arm interrupt on PF4 NVIC_PRI0_R = (NVIC_PRI7_R&0xFFFFFF00)|0x000000a0; NVIC_EN0_R = NVIC_EN0_INT0; // (h) enable interrupt 30 in NVIC EnableInterrupts(); }
boolean CInterruptSystem::Initialize (void) { TExceptionTable *pTable = (TExceptionTable *) ARM_EXCEPTION_TABLE_BASE; pTable->IRQ = ARM_OPCODE_BRANCH (ARM_DISTANCE (pTable->IRQ, IRQStub)); CleanDataCache (); DataSyncBarrier (); InvalidateInstructionCache (); FlushBranchTargetCache (); DataSyncBarrier (); InstructionSyncBarrier (); #ifndef USE_RPI_STUB_AT DataMemBarrier (); write32 (ARM_IC_FIQ_CONTROL, 0); write32 (ARM_IC_DISABLE_IRQS_1, (u32) -1); write32 (ARM_IC_DISABLE_IRQS_2, (u32) -1); write32 (ARM_IC_DISABLE_BASIC_IRQS, (u32) -1); DataMemBarrier (); #endif EnableInterrupts (); return TRUE; }
int main(void){ TExaS_Init(SW_PIN_PE3210,DAC_PIN_PB3210,ScopeOn); // bus clock at 80 MHz //Timer0A_Init(&songTask, F80HZ); Piano_Init(); Sound_Init(0); DAC_Init(); Heartbeat_Init(); // other initialization EnableInterrupts(); uint32_t input; while(1){ GPIO_PORTF_DATA_R ^= 0x04; input = Piano_In(); if (input == 0x04){ Sound_Play(A); } else if (input == 0x02){ Sound_Play(C); } else if (input == 0x01){ Sound_Play(Eb); } else if (input == 0x07){ Sound_Play(A); } else { Sound_Play(0); } } }
int main(void){ Output_Init(); // ST7735_XYplotInit("Temp", 0, 100, 0, 100); PLL_Init(Bus80MHz); // 80 MHz SYSCTL_RCGCGPIO_R |= 0x20; // activate port F ADC0_InitSWTriggerSeq3_Ch9(); // allow time to finish activating Timer0A_Init100HzInt(); // set up Timer0A for 100 Hz interrupts GPIO_PORTF_DIR_R |= 0x06; // make PF2, PF1 out (built-in LED) GPIO_PORTF_AFSEL_R &= ~0x06; // disable alt funct on PF2, PF1 GPIO_PORTF_DEN_R |= 0x06; // enable digital I/O on PF2, PF1 // configure PF2 as GPIO GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF00F)+0x00000000; GPIO_PORTF_AMSEL_R = 0; // disable analog functionality on PF PF2 = 0; // turn off LED EnableInterrupts(); ST7735_SetCursor(6,0); printf("C"); ST7735_SetCursor(13,0); printf("ADC"); while(1){ PF1 ^= 0x02; // toggles when running in main temperature = adcToTemp(ADCvalue); ST7735_SetCursor(0,0); ST7735_sDecOut2(temperature); ST7735_SetCursor(9,0); ST7735_OutUDec(ADCvalue); } }
int main(void) { configureAll(); EnableInterrupts(); // Global Interrupt Enable while (1) { switch (readMode()) { case 0: // Measure input voltage IEC0bits.T1IE = 1; // Enable timer T1 interrupts setPWM(0); // Turn off LED break; case 1: // Freeze IEC0bits.T1IE = 0; // Disable timer T1 interrupts setPWM(100); // Turn on LED with max brightness break; case 2: // LED brigthness control IEC0bits.T1IE = 0; // Disable timer T1 interrupts value2displays = pwmValues[readLEDValues()]; setPWM(value2displays); break; case 3: break; } } return 0; }
// 3. Subroutines Section // MAIN: Mandatory for a C Program to be executable int main(void){ TExaS_Init(SW_PIN_PF40, LED_PIN_PF31,ScopeOn); // activate grader and set system clock to 80 MHz PortF_Init(); // Init port PF4 PF3 PF1 EnableInterrupts(); // enable interrupts for the grader while(1){ SetReady(); WaitForASLow(); ClearReady(); Delay1ms(10); WaitForASHigh(); Delay1ms(250); SetVT(); Delay1ms(250); ClearVT(); // Follows the nine steps list above // a) Ready signal goes high // b) wait for switch to be pressed // c) Ready signal goes low // d) wait 10ms // e) wait for switch to be released // f) wait 250ms // g) VT signal goes high // h) wait 250ms // i) VT signal goes low } }
/* * Setup the timer 0 to generate the tick interrupts at the required frequency. */ static void prvSetupTimerInterrupt( void ) { uint32_t ulCompareMatch; /* Calculate the match value required for our wanted tick rate. */ ulCompareMatch = 1000000 / configTICK_RATE_HZ; /* Protect against divide by zero. Using an if() statement still results in a warning - hence the #if. */ #if portPRESCALE_VALUE != 0 { ulCompareMatch /= ( portPRESCALE_VALUE + 1 ); } #endif DisableInterrupts(); pRegs->CTL = 0x003E0000; pRegs->LOD = ulCompareMatch; pRegs->RLD = ulCompareMatch; pRegs->DIV = portTIMER_PRESCALE; pRegs->CLI = 0; pRegs->CTL = 0x003E00A2; RegisterInterrupt(64, vTickISR, NULL); EnableInterrupt(64); EnableInterrupts(); }
// gets all events EventMaskType GetAllEvents() { DisableInterrupts(); EventMaskType tmpevents = eventmemory; EnableInterrupts(); return tmpevents; }
// gets all events which are set in "eventmask" and returns them EventMaskType GetEvent(EventMaskType eventmask) { DisableInterrupts(); EventMaskType tmpevents = eventmask & eventmemory; EnableInterrupts(); return tmpevents; }
int main(void) { unsigned int i = 0, speedCounter = 0; initADC(); EnableInterrupts(); // Configure displays as outputs TRISB = TRISB & 0xFC00; while (1) { delay(5); if (i++ == 4) { AD1CON1bits.ASAM = 1; i = 0; } if (speedCounter++ >= speedValues[speed]) { if (++c >= 12) c = 0; speedCounter = 0; } send2displays(c); } return 0; }
// ******** OS_SysTick_Handler ************ // Thread Switcher, uses SysTick as periodic timer, calls PendSV to actually switch threads // Implement Thread Manager implicitly here // input: none, uses globals RUNPT and NEXTRUNPT // output: none, should switch threads when finished void OS_SysTick_Handler(void){ tcbType *i, *j; int pri; int x; DisableInterrupts(); //Thread Scheduler if(RRSCHEDULER){ //ROUND ROBBIN SCHEDULER for(i=RUNPT->next; i->sleep>0 || i->blockedOn!=0; i=i->next){ //OLD SLEEP DECRIMENTER //if(i->sleep>0){//decriment sleep counter // i->sleep=i->sleep-1; //} } NEXTRUNPT=i; }else if(PRIORITYSCHEDULER){ //PRIORITY SCHEDULER pri=7; j=RUNPT->next; x=0; do{ x++; //find thread with highest priority that isnt sleeping or blocked if(j->blockedOn==NULL && j->sleep==0 && j->workingPriority<pri){ pri=j->workingPriority; i=j; } j=j->next; //}while(j!=RUNPT->next); }while(x<NUMTHREADS); /* //Priority Scheduler, failed for case where lowest thread got blocked. for(i=RUNPT->next,pri=RUNPT->workingPriority,x=0; i->sleep>0 || i->blockedOn!=NULL || (i->workingPriority > pri); i=i->next, x++){ //Possible ERROR HERE, needs rethought //search for next thread untill you find one that is not sleeping, not blocked, and has a priority equal or less than the current RUNPT if(x>=NUMTHREADS && pri<7){ x=0; pri++; } } */ //OLD SLEEP DECRIMENTER //if(i->sleep>0){//decriment sleep counter // i->sleep=i->sleep-1; //} NEXTRUNPT=i; RUNPT->lastRun=OS_Time(); RUNPT->workingPriority = RUNPT->realPriority; } EnableInterrupts(); //Switch Threads (trigger PendSV) NVIC_INT_CTRL_R = 0x10000000; //PendSV_Handler(); }
int main(void){ DisableInterrupts(); TExaS_Init(SSI0_Real_Nokia5110_Scope); // set system clock to 80 MHz Random_Init(1); Nokia5110_Init(); PF1Init(); //SysTick_Init(2666666); //Initialize SysTick with 30 Hz interrupts SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed Nokia5110_ClearBuffer(); Nokia5110_DisplayBuffer(); // draw buffer ADC0_Init(); Game_Init(); SwitchLed_Init(); Sound_Init(); Timer2_Init(&Sound_Play,7256); //11.025 kHz. 80,000,000/11,025 cycles, which is about 7256 GameOverFlag = 0; EnableInterrupts(); while(1){ while(Semaphore==0){}; Semaphore = 0; if(GameOverFlag){ State_GameOver(); } else{ Draw_GameFrame(); // update the LCD } if((GameOverFlag == 0) && (Check_GameOver())){ //just detected game over Delay100ms(2);//Delay 200ms GameOverFlag = Check_GameOver(); //SysTick_Init(2666666);//Re-initialize with 30 Hz interrupt SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed } } }
byte MHD_Bridge_detect(void) { byte temp = 0; byte BridgeOn = 0; DisableInterrupts(); msleep(180); if(!gpio_get_value(GPIO_ACCESSORY_INT)&& MHD_HW_IsOn()) { temp = ReadIndexedRegister(INDEXED_PAGE_0, 0x09); if ((temp & RSEN) == 0x00) { BridgeOn = FALSE; //ReadModifyWriteTPI(0x79, SI_BIT_5 | SI_BIT_4, SI_BIT_4); //force HPD to 0 ReadModifyWriteIndexedRegister(INDEXED_PAGE_0, 0x79, SI_BIT_5 | SI_BIT_4, SI_BIT_4); } else { BridgeOn = TRUE; //ReadModifyWriteTPI(0x79, BIT_5 | BIT_4, 0); //back to current state } printk("[MHD] Bridge detect %x :: HPD %d\n",BridgeOn,gpio_get_value(GPIO_HDMI_HPD)); //ReadModifyWriteTPI(0x79, SI_BIT_5 | SI_BIT_4, 0); //back to current state ReadModifyWriteIndexedRegister(INDEXED_PAGE_0, 0x79, SI_BIT_5 | SI_BIT_4, 0); } MHD_INT_clear(); EnableInterrupts(); printk("[MHD]MHD_Bridge_detect -- \n"); return BridgeOn; }
void EdgeCounter_Init(void){ volatile unsigned long delay; SYSCTL_RCGC2_R |= 0x00000020; // (a) activate clock for port F delay = SYSCTL_RCGC2_R; GPIO_PORTF_LOCK_R = 0x4C4F434B; // 2) unlock PortF PF0 GPIO_PORTF_CR_R = 0x1F; // allow changes to PF4-0 GPIO_PORTF_AMSEL_R = 0x00; // 3) disable analog function GPIO_PORTF_PCTL_R = 0x00000000; // 4) GPIO clear bit PCTL GPIO_PORTF_DIR_R = 0x0E; // 5) PF4,PF0 input, PF3,PF2,PF1 outpu GPIO_PORTF_AFSEL_R = 0x00; // 6) no alternate function GPIO_PORTF_PUR_R = 0x11; // enable pullup resistors on PF4,PF0 GPIO_PORTF_DEN_R = 0x1F; // 7) enable digital pins PF4-PF0 GPIO_PORTF_IS_R &= ~0x11; // (d) PF4 is edge-sensitive GPIO_PORTF_IBE_R &= ~0x11; // PF4 is not both edges GPIO_PORTF_IEV_R &= ~0x11; // PF4 falling edge event GPIO_PORTF_ICR_R = 0x11; // (e) clear flag4 GPIO_PORTF_IM_R |= 0x11; // (f) arm interrupt on PF4 NVIC_PRI7_R = (NVIC_PRI7_R&0xFF00FFFF)|0x00A00000; // (g) priority 5 NVIC_EN0_R = 0x40000000; // (h) enable interrupt 30 in NVIC EnableInterrupts(); // (i) Enable global Interrupt flag (I) }
void CondBroadcast (struct Cond *cond) { struct Process *proc; if (current_process == NULL) return; do { DisableInterrupts(); proc = LIST_HEAD (&cond->blocked_list); if (proc != NULL) { LIST_REM_HEAD (&cond->blocked_list, blocked_entry); proc->state = PROC_STATE_READY; SchedReady (proc); Reschedule(); } proc = LIST_HEAD (&cond->blocked_list); EnableInterrupts(); } while (proc != NULL); }
// 3. Subroutines Section // MAIN: Mandatory for a C Program to be executable int main(void){ PLL_Init(); // 80 MHz Port_Init(); ADC0_InitSWTriggerSeq3_Ch1(); EnableInterrupts(); SysFun(); /*Initialize ports , ADC and timers*/ while(1){ /*Your code goes here*/ a= ADC0_InSeq3(); t1=a+(10000/4096)+10000; in1=50; while(in1) { GPIO_PORTA_DATA_R |= (0x20); SysLoad(t1); GPIO_PORTA_DATA_R &= ~(0x20); SysLoad(t-t1); in1=in1-1; } } }
int main(void){ unsigned long i,last,now, SW1, SW2; TExaS_Init(SW_PIN_PF40, LED_PIN_PF1); // activate grader and set system clock to 16 MHz PortF_Init(); // initialize PF1 to output SysTick_Init(); // initialize SysTick, runs at 16 MHz i = 0; // array index last = NVIC_ST_CURRENT_R; EnableInterrupts(); // enable interrupts for the grader while(1){ SW1= GPIO_PORTF_DATA_R & 0x01; SW2= GPIO_PORTF_DATA_R & 0x10; if(!SW1 || !SW2) { Led = GPIO_PORTF_DATA_R; // read previous Led = Led^0x02; // toggle red LED GPIO_PORTF_DATA_R = Led; // output if(i<50){ now = NVIC_ST_CURRENT_R; Time[i] = (last-now)&0x00FFFFFF; // 24-bit time difference //Data[i] = GPIO_PORTF_DATA_R&0x02; // record PF1 Data[i] = GPIO_PORTF_DATA_R&0x13; // record PF1 last = now; i++; } Delay(); } else { GPIO_PORTF_DATA_R &=~0x02 ; // output } } }
void Timer0A_Init(){ INTPERIOD = timer_period; TIMER0_CFG_R = TIMER_CFG_16_BIT; // configure for 16-bit timer mode //TIMER 1 - Frequency TIMER0_TAMR_R = TIMER_TAMR_TAMR_PERIOD;// configure for periodic mode //***** WORK WITH THE NUMBERS HERE ********** // TIMER0_TAILR_R = 50000; // start value to count down from TIMER0_IMR_R |= TIMER_IMR_TATOIM;// enable timeout (rollover) interrupt TIMER0_ICR_R = TIMER_ICR_TATOCINT;// clear timer0A timeout flag // **** interrupt initialization **** // Timer0A=priority 2 NVIC_PRI4_R = (NVIC_PRI4_R&0x00FFFFFF)|0x40000000; // top 3 bits NVIC_EN0_R |= NVIC_EN0_INT19; // enable interrupt 19 in NVIC TIMER0_ICR_R = TIMER_ICR_TATOCINT;// clear timer0A timeout flag TIMER0_CTL_R |= TIMER_CTL_TAEN; // enable timer0A 16-b, periodic, interrupts NVIC_PRI5_R = (NVIC_PRI5_R&0xFFFFFF00)|0x00000040; // bits 5-7 NVIC_EN0_R |= NVIC_EN0_INT19+NVIC_EN0_INT20; EnableInterrupts(); }