//***************************************************************************** // // The SysTick Timer interrupt handler. // //***************************************************************************** void SysTickTimerHandler(void) { IntMasterDisable(); SYSTICKINT_FLAG = true; IntMasterEnable(); }
//***************************************************************************** // // The interrupt handler for the first timer interrupt. // //***************************************************************************** void Timer1IntHandler(void) { // // Clear the timer interrupt. // TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); DEBUG_TP5(0); // // Update the interrupt status. // IntMasterDisable(); if(GetDMCmode() != BIT_MODE ) { /*------------------------------------------------------------*/ /* EncoderTick(QEI0_BASE); time is 3~ microsecond */ /* EncoderTick(QEI0_BASE); time is 3~ microsecond */ /*------------------------------------------------------------*/ EncoderTick(QEI0_BASE); // PITCH Encoder EncoderTick(QEI1_BASE); // ROLL Encoder } IntMasterEnable(); DEBUG_TP5(1); }
//***************************************************************************** // // Gets the current number of UART messages waiting to be processed. // // This function returns the number of unprocessed messages that are currently // in the UART ring buffer. // // \return Current number of UART messages in the buffer. // //***************************************************************************** uint_fast16_t RemoTIUARTGetRxMsgCount(void) { bool bIntState; uint_fast16_t ui16Temp; // // Turn off interrupts and save Interrupt enable state. // bIntState = IntMasterDisable(); // // Copy message count to local variable. // ui16Temp = g_ui16RxMsgCount; // // Restore interrupt enable state. // if(!bIntState) { IntMasterEnable(); } // // Return a snapshot of the message count. // return(ui16Temp); }
// ******************************************************* // Returns the raw RTC time which is the same number // of systick interrupts. unsigned long long mRTCGetRaw(void) { IntMasterDisable(); unsigned long long ticks = g_ullRTCTicks; IntMasterEnable(); return ticks; }
//***************************************************************************** // // Register a callback for UART transmission complete.. // // \param pfnCallback is a pointer to a tRemoTICallback function. // // Register the \e pfnCallback that will be called when a UART transmisssion is // complete. The Transmit buffer has just been emptied of its last byte. Only // one callback is active at a time. Calling this function more than once // will override earlier callbacks. Pass \b NULL to unregister. // // \return None. // //***************************************************************************** void RemoTIUARTRegisterTxCompleteCallback(tRemoTICallback *pfnCallback) { bool bIntState; // // Turn off interrupts and save previous interrupt enable state. // bIntState = IntMasterDisable(); // // Register the callback. // g_pfnTxCallback = pfnCallback; // // Restore interrupt master enable state. // if(!bIntState) { IntMasterEnable(); } // // Finished. // }
/***************************************************** * Function: init_BtnHandler * Description: Initializes button interrupt * Initializes timer for button counter * Input: NONE * Output: NONE *****************************************************/ void init_BtnHandler(void) { // Unlock un-maskable pin HWREG(BTN_OVERRIDE_REG + GPIO_O_LOCK) = GPIO_LOCK_KEY; // Set up our interrupt for button presses IntMasterDisable(); // Disable all interrupts GPIOIntDisable(BTN_OVERRIDE_REG, BTN_OVERRIDE); GPIOPinTypeGPIOInput(BTN_OVERRIDE_REG, BTN_OVERRIDE); GPIOPadConfigSet(BTN_OVERRIDE_REG, BTN_OVERRIDE, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU); // Set Pull-up GPIOIntTypeSet(BTN_OVERRIDE_REG, BTN_OVERRIDE, GPIO_BOTH_EDGES); // Set edge to trigger on GPIOIntClear(BTN_OVERRIDE_REG, BTN_OVERRIDE); // Clear the interrupt bit GPIOIntEnable(BTN_OVERRIDE_REG, BTN_OVERRIDE); // Enable the interrupt IntEnable(INT_GPIOE); // Lock un-maskable pin HWREG(BTN_OVERRIDE_REG + GPIO_O_LOCK) = 0; // Setup timer interrupt for button pressing // This timer will run up and when it is released we will check how long it was running SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(BTN_OVERRIDE_TIM_BASE, TIMER_CFG_PERIODIC); // Setup interrupt as 32 bit timer counting up TimerLoadSet(BTN_OVERRIDE_TIM_BASE, BTN_OVERRIDE_TIM, clockTime/1000); // Load Timer IntEnable(INT_TIMER0A); TimerIntEnable(BTN_OVERRIDE_TIM_BASE, TIMER_TIMA_TIMEOUT); // Turn the input pin to the button high GPIOPinTypeGPIOOutput(BTN_OVERRIDE_CONTROL_REG, BTN_OVERRIDE_CONTROL); GPIOPinWrite(BTN_OVERRIDE_CONTROL_REG, BTN_OVERRIDE_CONTROL, BTN_OVERRIDE_CONTROL); }
//***************************************************************************** // //! This is the code that gets called when the processor receives an unexpected //! interrupt. This simply enters an infinite loop, preserving the system //! state for examination by a debugger. //! //! \return None. // //***************************************************************************** void IntDefaultHandler(void) { // // Disable all interrupts. // IntMasterDisable(); // // Turn off all the PWM outputs. // PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT | PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT, false); // // Turn on STATUS and MODE LEDs. They will remain on. // BlinkStart(STATUS_LED, 1, 1, 1); BlinkStart(MODE_LED, 1, 1, 1); BlinkHandler(); // // Go into an infinite loop. // while(1) { } }
void ADC0IntHandler() { unsigned long adc0Value; // Holds the ADC result char adc0String[5]; // Holds the string-converted ADC result // 清ADC0中断标志. // ADCIntClear (unsigned long ulBase, unsigned long ulSequenceNum) ADCIntClear(ADC0_BASE, 0); //从SSO读出转换结果 (FIFO0),本例中只有一个采样.如果要使用多个转换源,需要使用数组做为参数传递给API函数,保存FIFO转换结果. // long ADCSequenceDataGet (unsigned long ulBase,unsigned long ulSequenceNum,unsigned long *pulBuffer) ADCSequenceDataGet(ADC0_BASE, 0, &adc0Value); adc0Value= ((59960 - (adc0Value * 100)) / 356); // 在OLED上显示当前温度 usprintf(adc0String, "%d", adc0Value); IntMasterDisable(); RIT128x96x4StringDraw("Current temp : ", 6, 48, 15); RIT128x96x4StringDraw(adc0String, 94, 48, 15); IntMasterEnable(); // ADC模块空闲,可以进行下一次转换 adc_busy=0; }
//***************************************************************************** // // Main routine for the mouse. // //***************************************************************************** void USBMouseMain(void) { // // Disable interrupts while changing the variables below. // IntMasterDisable(); switch(sMouseState.eState) { case MOUSE_PENDING: { // // Send the report since there is one pending. // USBDHIDMouseStateChange((void *)&g_sMouseDevice, (uint8_t)sMouseState.i32X, (uint8_t)sMouseState.i32Y, sMouseState.ui8Buttons); // // Clear out the report data so that pending data does not // continually accumulate. // sMouseState.i32X = 0; sMouseState.i32Y = 0; if(sMouseState.ui8Buttons) { // // Need to always send out that all buttons are released. // sMouseState.ui8Buttons = 0; sMouseState.eState = MOUSE_SENDING_PEND; } else { // // Switch to sending state and wait for the transmit to be // complete. // sMouseState.eState = MOUSE_SENDING; } break; } case MOUSE_DISCONNECT: case MOUSE_SENDING: case MOUSE_SENDING_PEND: case MOUSE_IDLE: default: { break; } } // // Enable interrupts now that the main loop is complete. // IntMasterEnable(); }
//***************************************************************************** // // Change the value of a variable atomically. // // \param pui32Val points to the index whose value is to be modified. // \param ui32Delta is the number of bytes to increment the index by. // \param ui32Size is the size of the buffer the index refers to. // // This function is used to increment a read or write buffer index that may be // written in various different contexts. It ensures that the // read/modify/write sequence is not interrupted and, hence, guards against // corruption of the variable. The new value is adjusted for buffer wrap. // // \return None. // //***************************************************************************** static void UpdateIndexAtomic(volatile uint32_t *pui32Val, uint32_t ui32Delta, uint32_t ui32Size) { bool bIntsOff; // // Turn interrupts off temporarily. // bIntsOff = IntMasterDisable(); // // Update the variable value. // *pui32Val += ui32Delta; // // Correct for wrap. We use a loop here since we don't want to use a // modulus operation with interrupts off but we don't want to fail in // case ui32Delta is greater than ui32Size (which is extremely unlikely // but...) // while(*pui32Val >= ui32Size) { *pui32Val -= ui32Size; } // // Restore the interrupt state // if(!bIntsOff) { IntMasterEnable(); } }
/************************************************************************************//** ** \brief Disables the generation IRQ interrupts and stores information on ** whether or not the interrupts were already disabled before explicitly ** disabling them with this function. Normally used as a pair together ** with IrqInterruptRestore during a critical section. ** \return none. ** ****************************************************************************************/ void IrqInterruptDisable(void) { if (interruptNesting == 0) { IntMasterDisable(); } interruptNesting++; } /*** end of IrqInterruptDisable ***/
//Print at x,y with given brightness void oled_d_print_xyb(char *str, unsigned long x, unsigned long y, unsigned long b) { IntMasterDisable(); RIT128x96x4StringDraw(str, x, y, b); IntMasterEnable(); }
//Print at 0,0 with full brightness void oled_d_print_origin(char *str) { IntMasterDisable(); RIT128x96x4StringDraw(str, 0, 0, MAX_BRIGHTNESS); IntMasterEnable(); }
//Clear the screen void oled_d_clear(void) { IntMasterDisable(); RIT128x96x4Clear(); IntMasterEnable(); }
/**************************************************************************//** * @brief Connect interrupt service routine to 32 kHz timer interrupt. * * @param pFnHandle Void function pointer to interrupt service routine * * @return None ******************************************************************************/ void halTimer32kIntConnect(void (*pFnHandle)(void)) { tBoolean intDisabled = IntMasterDisable(); SleepModeIntRegister(&halTimer32kIsr); // Register function and IntDisable(INT_SMTIM); // disable SMTIM interrupts pFptr = pFnHandle; // Set custom ISR if(!intDisabled) IntMasterEnable(); }
//Print at x,y with full brightness void oled_d_print_xy(char *str, unsigned long x, unsigned long y) { IntMasterDisable(); RIT128x96x4StringDraw(str, x, y, MAX_BRIGHTNESS); IntMasterEnable(); }
//##### INTERNAL BEGIN ##### //***************************************************************************** // // Send a wakup packet to the remote network processors UART interface. // // This function will send a NULL character to the UART interface repeatedly // in order to awaken the RNP and cause it to start listening for UART packets. // // \return None. // //***************************************************************************** void RemoTIUARTWake(void) { #if 0 bool bIntState; uint32_t ui32Ticks; // // Disable Master interrupts. Record previous interrupt state to properly // restore it later. // bIntState = IntMasterDisable(); // // Tick counter for tracking how many times we send the NULL character set. // ui32Ticks = 0; // // If the TX interrupt is enabled. If it is assume UART is already // awake. If it is not then wake up the UART on the RNP with a null char. // if((HWREG(g_ui32UARTBase + UART_O_IM) & 0x20) != UART_IM_TXIM); { do { // // Send consecutive NULL characters. // UARTCharPut(g_ui32UARTBase, 0); UARTCharPut(g_ui32UARTBase, 0); UARTCharPut(g_ui32UARTBase, 0); UARTCharPut(g_ui32UARTBase, 0); // // Delay 10 milliseconds to allow time for RNP to process and wake. // SysCtlDelay(SysCtlClockGet() / (100 * 3)); ui32Ticks++; // // Send the NULL character set until we get a character back or we have // tried 10 times to get a response. // } while((ui32Ticks < 10) & (UARTCharsAvail(g_ui32UARTBase) == 0)); } // // Restore the master interrupt enable to it previous state. // if(!bIntState) { IntMasterEnable(); } #endif // 0 }
static void flashEraseCallback(void) { // Disable global interrupts IntMasterDisable(); // Erase Flash CCA page FlashMainPageErase(CC2538_FLASH_CCA_ADDRESS); // Reset the board SysCtrlReset(); }
void HardwareInit() { IntMasterDisable(); // // Datasheet says use PLL if reading from ADC // SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ); // SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ); ConsoleInit(115200); A3906Init(); SysTickInit(1000); RMBD01Init(); IntMasterEnable(); }
static void clock_init(void) { /** * Disable global interrupts */ bool bIntDisabled = IntMasterDisable(); /** * Configure the 32 kHz pins, PD6 and PD7, for crystal operation * By default they are configured as GPIOs */ GPIODirModeSet(GPIO_D_BASE, 0x40, GPIO_DIR_MODE_IN); GPIODirModeSet(GPIO_D_BASE, 0x80, GPIO_DIR_MODE_IN); IOCPadConfigSet(GPIO_D_BASE, 0x40, IOC_OVERRIDE_ANA); IOCPadConfigSet(GPIO_D_BASE, 0x80, IOC_OVERRIDE_ANA); /** * Set the real-time clock to use the 32khz internal crystal * Set the system clock to use the external 32 MHz crystal * Set the system clock to 32 MHz */ SysCtrlClockSet(true, false, SYS_CTRL_SYSDIV_32MHZ); /** * Set the IO clock to operate at 16 MHz * This way peripherals can run while the system clock is gated */ SysCtrlIOClockSet(SYS_CTRL_SYSDIV_16MHZ); /** * Wait until the selected clock configuration is stable */ while (!((HWREG(SYS_CTRL_CLOCK_STA)) & (SYS_CTRL_CLOCK_STA_XOSC_STB))); /** * Define what peripherals run in each mode */ SysCtrlDeepSleepSetting(); SysCtrlSleepSetting(); SysCtrlRunSetting(); SysCtrlWakeupSetting(); /** * Re-enable interrupt if initially enabled. */ if(!bIntDisabled) { IntMasterEnable(); } }
void hidUpdateKeyboardInReport(KEYBOARD_IN_REPORT *pNewReport) { bool intDisabled = IntMasterDisable(); hidData.keyboardInReport.modifiers = pNewReport->modifiers; hidData.keyboardInReport.pKeyCodes[0] = pNewReport->pKeyCodes[0]; hidData.keyboardInReport.pKeyCodes[1] = pNewReport->pKeyCodes[1]; hidData.keyboardInReport.pKeyCodes[2] = pNewReport->pKeyCodes[2]; hidData.keyboardInReport.pKeyCodes[3] = pNewReport->pKeyCodes[3]; hidData.keyboardInReport.pKeyCodes[4] = pNewReport->pKeyCodes[4]; hidData.keyboardInReport.pKeyCodes[5] = pNewReport->pKeyCodes[5]; if(!intDisabled) { IntMasterEnable(); } }
//***************************************************************************** // // Puts a UART message on the line to the RNP. // // \param pui8Msg pointer to the data that will be put on the bus. Must be // already formated with SOF, length and checksum by the caller. // // \param ui16Length the number of bytes that are to be put out the UART. // // This function copies the message to the ring buffer and then starts a // transmission process. Application must assure that transmitter is not busy. // //***************************************************************************** void RemoTIUARTPutMsg(uint8_t* pui8Msg, uint_fast16_t ui16Length) { bool bIntState; // // Capture the current state of the master interrupt enable. // bIntState = IntMasterDisable(); // // Store the message in the ringbuffer for transmission. // RingBufWrite(&g_rbRemoTITxRingBuf, pui8Msg, ui16Length); // // If the UART transmit is idle prime the transmitter with first byte and. // enable transmit interrupts. // if(!g_bTxBusy) { // // Enable the TX interrupts and start the transmission of the first // byte. // UARTIntEnable(g_ui32UARTBase, UART_INT_TX); UARTCharPutNonBlocking(g_ui32UARTBase, RingBufReadOne(&g_rbRemoTITxRingBuf)); // // Set the Transmit busy flag. // g_bTxBusy = true; } // // Restore the master interrupt enable to its previous state. // if(!bIntState) { IntMasterEnable(); } // // Finished. // }
void HardwareInit() { IntMasterDisable(); // Set the system clock to run at 50MHz from the PLL. // PLL=400MHz // sysc2000000lk = 400MHz/2/4 = 50MHz //SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Set the system clock to run at 20MHz from the PLL. // PLL=100MHz // sysc2000000lk = 100MHz/2/4 = 20MHz //SysCtlClockSet(SYSCTL_SYSDIV_10| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ulSysClock = ROM_SysCtlClockGet(); if (InitUART(UART0_BASE,SysCtlClockGet(),19200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)) == -1) while (1); // hang if (InitUART(UART1_BASE,SysCtlClockGet(),9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)) == -1) while (1); // hang SysTickInit(1000); // 1msec counter TimerInit(1); // 100ms counter BBLedInit(); DEBUG_LED1(1); DEBUG_LED1(0); DEBUG_LED2(1); DEBUG_LED2(0); MasterI2C0Init(SysCtlClockGet() >= 40000000L); // Need 40MHz for 400K A3906Init(); RMBD01Init(); Encoder_Init(QEI0_BASE); // J6 PITCH Encoder Encoder_Init(QEI1_BASE); // J8 ROLL Encoder EncoderLinesSet(QEI0_BASE,64); EncoderLinesSet(QEI1_BASE,64); //HBridgeInit(); //GPIOPinInit('E',4,false,false); /*TP5 */ //GPIOPinInit('E',5,false,false); /*TP6 */ IntMasterEnable(); }
//***************************************************************************** // // The interrupt handler for the first timer interrupt. // //***************************************************************************** void Timer0IntHandler(void) { // // Clear the timer interrupt. // TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Update the interrupt status. // IntMasterDisable(); if(GetDMCflag(DMC_ENGINE_CONNECT)) { SetDMCflag(DMC_MOTOR_TEST,DMC_MOTOR_TEST); if(!GetDMCflag(DMC_MOTOR_TEST)) { #ifdef MINTRON if(MotorPositionError(PITCH_MOTOR) == -1) { Set_OSD_Titel(0xF); cpPutMessage(UART1_BASE,0x10,sizeof(LensZoomWrite),(unsigned char *)&LensZoomWrite); } else if(MotorPositionError(ROLL_MOTOR) == -1) { Set_OSD_Titel(0xF); cpPutMessage(UART1_BASE,0x10,sizeof(LensZoomWrite),(unsigned char *)&LensZoomWrite); } #endif } } Motor[ROLL_MOTOR].deg2sec = ((Motor[ROLL_MOTOR].aangle - Motor[ROLL_MOTOR].cur_angle)*Motor[ROLL_MOTOR].direction)*100.0f; Motor[ROLL_MOTOR].cur_angle = Motor[ROLL_MOTOR].aangle; Motor[PITCH_MOTOR].deg2sec = ((Motor[PITCH_MOTOR].aangle - Motor[PITCH_MOTOR].cur_angle)*Motor[PITCH_MOTOR].direction)*100.0f; Motor[PITCH_MOTOR].cur_angle = Motor[PITCH_MOTOR].aangle; IntMasterEnable(); }
/** * read rtc time * * output: s .. seconds * subs .. subseconds **/ void rtc_get_time(uint32_t *s,uint32_t *subs) { uint32_t ls1,ls2,lss; IntMasterDisable(); do { ls1 = HWREG(HIB_RTCC); lss = HWREG(HIB_RTCSS); ls2 = HWREG(HIB_RTCC); } while (ls1!=ls2); IntMasterEnable(); *s = ls1; *subs = lss; }
void system_Process_System_State(void) { switch (system_GetState()) { case SYSTEM_POWER_UP: break; case SYSTEM_INITIALIZE: break; case SYSTEM_CALIB_SENSOR: break; case SYSTEM_SAVE_CALIB_SENSOR: break; case SYSTEM_ESTIMATE_MOTOR_MODEL: ProcessSpeedControl(); break; case SYSTEM_SAVE_MOTOR_MODEL: break; case SYSTEM_WAIT_TO_RUN: break; case SYSTEM_RUN_SOLVE_MAZE: pid_Wallfollow_process(); ProcessSpeedControl(); break; case SYSTEM_RUN_IMAGE_PROCESSING: LED1_ON(); ProcessSpeedControl(); break; case SYSTEM_ERROR: speed_Enable_Hbridge(false); system_Enable_BoostCircuit(false); IntMasterDisable(); while (1) { LED1_ON(); LED2_ON(); LED3_ON(); ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3); LED1_OFF(); LED2_OFF(); LED3_OFF(); ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3); } // break; } }
void AREQ(uint8_t *data,uint8_t length){ //Disable SRDY Interrupt IntMasterDisable(); //MRDY Goes Low MRDY_write(0); //Wait untill SRDY Goes Low while(SRDY_read()); //Transfer Data SPI_transfer(data,length+3); //Wait SRDY Goes High while(!SRDY_read()); //MRDY Goes High MRDY_write(1); //Enable SRDY Interrupt IntMasterEnable(); }
void BattSenseISR(void) { uint8_t temp; uint32_t BattResult; static uint32_t avrBattResult = 2700; ROM_ADCIntClear(ADC1_BASE, 3); ROM_ADCSequenceDataGet(ADC1_BASE, 3, &BattResult); avrBattResult = (4 * avrBattResult + BattResult) / 5; if (avrBattResult < 2500) { ROM_GPIOPinWrite(ENABLE_PORT, ENA_LEFT_PIN | ENA_RIGHT_PIN, 0x00); SetPWM(MOTOR_LEFT, DEFAULT, 0); SetPWM(MOTOR_RIGHT, DEFAULT, 0); BoostDisable(); IntMasterDisable(); } }
// ******************************************************* // Returns the height of the heli. This is the location of // the helicopter on the vertical axis. unsigned long heightGet(void) { //* we could just read ADC every time we call this //* not much need to use systick as with yaw?? //* could combine yaw and height ISRs in one. int sum = 0; short i = 0; IntMasterDisable(); for (i = 0; i < CIRCBUF_SIZE; i++) { sum += (int)readCircBuf(&g_heightBuf); } IntMasterEnable(); //g_height = (unsigned long)( sum/(CIRCBUF_SIZE*1024) ); return (unsigned long)( 100 - (100*sum/(CIRCBUF_SIZE*1024)) ); }
//***************************************************************************** // // The interrupt handler for the second timer interrupt. // //***************************************************************************** void Timer1IntHandler(void) { // // Clear the timer interrupt. // TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // // Toggle the flag for the second timer. // HWREGBITW(&g_ulFlags, 1) ^= 1; // // Update the interrupt status on the display. // IntMasterDisable(); RIT128x96x4StringDraw(HWREGBITW(&g_ulFlags, 1) ? "1" : "0", 90, 32, 15); IntMasterEnable(); }