__interrupt void ADC10_ISR_HOOK(void) { /* USER CODE START (section: ADC10_ISR_HOOK) */ ADC_ISR(); __bis_SR_register_on_exit(LPM3_bits); /* USER CODE END (section: ADC10_ISR_HOOK) */ }
__interrupt void Port_2(void) { P1OUT = 0xFF; // Turn all LEDs off timeout = TIMEOUT; // Reset timeout mode = (mode + 1) % (NUMBER_OF_IMAGES + 1); // Scroll through mode if (mode == 0) { // Go into low power mode with interrupts __bis_SR_register_on_exit(LPM4_bits | GIE); } else { // wake up from low power mode __bic_SR_register_on_exit(LPM4_bits); current_image = images[mode - 1]; current_image_length = image_lengths[mode - 1]; } while(!(P2IN & BIT5)); // Wait until button is released for (volatile int x = 0; x < 0xFFF; x++); // Crude loop, works as a debouncer P2IFG &= ~BIT5; // Clear button interrupt }
__interrupt void PORT1_ISR_HOOK(void) { /* USER CODE START (section: PORT1_ISR_HOOK) */ GPIO_ISR(); __bis_SR_register_on_exit(LPM3_bits); /* USER CODE END (section: PORT1_ISR_HOOK) */ }
__interrupt void TIMER0_A0_ISR_HOOK(void) { /* USER CODE START (section: TIMER0_A0_ISR_HOOK) */ timer_ISR(); __bis_SR_register_on_exit(LPM3_bits); /* USER CODE END (section: TIMER0_A0_ISR_HOOK) */ }
__interrupt void USCI0RX_ISR_HOOK(void) { /* USER CODE START (section: USCI0RX_ISR_HOOK) */ UART_RX_ISR(); __bis_SR_register_on_exit(LPM3_bits); /* USER CODE END (section: USCI0RX_ISR_HOOK) */ }
__interrupt void USCI_UART_RX_ISR_implement(){ int exit_code; if ( NULL != USCI_UART_RX_ISR_proxy ) { exit_code = USCI_UART_RX_ISR_proxy(USCI_A0_VECTOR, UCA0RXBUF); if (exit_code>0) __bis_SR_register_on_exit(exit_code); if (exit_code<0) __bic_SR_register_on_exit(-exit_code); } }
void uartRxInterrupt() { // IE2 &= ~UCA0RXIFG; Происходит автоматически, когда читаешь из RXBUF register bufferValueType tmp = UCA0RXBUF; cycledBufferPushBack(&rxBuffer, tmp); // Включаем вложенные прерыания, для таймера, он приоритетнее __bis_SR_register(GIE); // Ставим флаг того, что нужно сделать. taskRegister |= TASK_NEW_BYTE_ON_UART; // Будим контроллер по выходу из прерывания, для него появилась работа! __bis_SR_register_on_exit(GIE); }
__interrupt void USCIAB0RX_VECTOR_ISR_wrapper(){ int16_t exit_code; isr_callback_8 *callback = USCIAB0RX_ISR_callbacks; while (NULL != *callback){ exit_code = (*callback)((USCIAB0RX_VECTOR << 8), UCA0RXBUF); callback++; if (exit_code>0) { __bis_SR_register_on_exit(exit_code); break; } if (exit_code<0){ __bic_SR_register_on_exit(-exit_code); break; } } }
__interrupt void ADC12_ISR_wrapper(void) { int16_t exit_code; isr_callback *callback = ADC12_ISR_callbacks; while (NULL != *callback){ exit_code = (*callback)((ADC12_VECTOR << 8) + ADC12IV); callback++; if (exit_code>0) { __bis_SR_register_on_exit(exit_code); break; } if (exit_code<0){ __bic_SR_register_on_exit(-exit_code); break; } } }
__interrupt void TIMERB1_ISR_wrapper(void) { int16_t exit_code; isr_callback_16 *callback = TIMERB1_ISR_callbacks; while (NULL != *callback){ exit_code = (*callback)((TIMERB1_VECTOR << 8) + TB0IV, TA0R); callback++; if (exit_code>0) { __bis_SR_register_on_exit(exit_code); break; } if (exit_code<0){ __bic_SR_register_on_exit(-exit_code); break; } } }
__interrupt void TIMERA0_ISR_HOOK(void) { static unsigned char pulse; // Slowly pulses DEVICES_OUT = 0; // Turn everything off for a moment // DO this first to let the battery voltage rise a bit without load before we check it. static unsigned char step; // Cycle this though to keep track of pwm values step++; if (!step) { // Did we overflow? // Generate the variable that we use elsewhere for pulsing... static int pulse_dir; if (pulse<=5) { pulse_dir = 1; } else if (pulse>=70) { pulse_dir = -1; } pulse += pulse_dir; if (white_led_countdown) { // Keep dimming the white LED until off if we are in a countdown white_led_countdown--; } } unsigned powerdown_flag=0; // shoud we turn off? // Compute the PWM channels based on current state // All channels start at zero default then we change them as nessisary unsigned char white_led_PWM=0; // 0-255 unsigned char motor_PWM=0; // 0-255 unsigned char red_led_PWM=0; // 0-255 if ( !(DEVICES_IN & PG_BIT) ) { // Charger connected motor_speed_index = 0; // Turn off motor when charger connected TODO: is this correct UI? if ( !(DEVICES_IN & EOG_BIT) ) { // Charger battery full? white_led_PWM = 255; } else if ( !( DEVICES_IN & CHARGE_BIT)) { // Charge in progress white_led_PWM = pulse; } else { white_led_PWM = 100; red_led_PWM = pulse; } // Note that we will never power down if charger connected, so LEDs can show charging status } else { // No charger connected // We check for low batt condition inside the timing loop so we can detect // if the battery level drops aschyonously. This will likely happen while the motor is on // since that will lower the batt voltage, but could also happen the moment the user turns us // on and we are on the first pass through this timing loop, in which case we will turn off // without ever turning on the motor // TODO: Use SVSCTL to detect low battery and eliminate the low battery circuit and get software control over setpoint if ( !(DEVICES_IN & LOWBATT_BIT)) { // Low Battery detected? low_batt_detected_flag = 1; } if (low_batt_detected_flag) { red_led_PWM=200; // Show red LED to user (they will only see if button pressed becuase otherwsie we will power down immedeately) motor_speed_index = 0; // Turn off motor (which will lead to powerdown) } if (motor_speed_index==0) { // Motor currently off? powerdown_flag = 1; // Powerdown when button is released } motor_PWM = motor_speeds[ motor_speed_index ]; white_led_PWM = white_led_countdown; // Blink the white LED if there was a recent button press } if (button_lockout_countdown) { // Are we currently in a debounce cycle? if (DEVICES_IN & BUTTON_BIT) { // button currently pressed? button_lockout_countdown = BUTTON_LOCKOUT_TIME; // Reset lockout countdown counter since button is pressed right now; (we need to see it unpress for a min time) if (button_longpress_countdown) { // Currently in a longpress countdown? // Check how long we have been down for button_longpress_countdown--; // If we have been down long enough... if (!button_longpress_countdown) { // Turn off motor immedeately for user feedback motor_speed_index = 0; // Goto off mode just in case battery level rises again while button down, we will need to button cycle to turn on again // then power down when button released powerdown_flag = 1; } } } else { // button currently up // We know button_lockout_countdown>0 if we get here from enclosing if button_lockout_countdown--; // count down... button_longpress_countdown = LONG_BUTTON_PRESS; // Start waiting for long press from scatch (we need to see continuously press) } } // We should only power down if we are not currently debouncing a press otherwise we // might immedeately wake up again from bounces if (!button_lockout_countdown && powerdown_flag) { // Make sure we are not in a debounce lockout - button has been safely released // Remeber that all outputs are low right now because we turned them off at the // top of the routine. // We can only wake from this mode via a pin change that would signal // either a button press or the charger being connected powerup_flag = 1; // A global to tell the int route to init variables on powerup. __bis_SR_register_on_exit( LPM4_bits | GIE); // Good night! return; } // Remeber that when we get here, all devices are still off becuase we turnted them off at the // top of this routine // Simulate PWM by turning on bit when step is less than current PWM setting if (step<motor_PWM) { DEVICES_OUT|= MOTOR_BIT; } if (step<white_led_PWM) { DEVICES_OUT|= WHITE_LED_BIT; } if (step<red_led_PWM) { DEVICES_OUT|= RED_LED_BIT; } }
__interrupt void interrupt_fast_timeout (void) { stop_fast_timeout(); MRFI_Sleep(); __bis_SR_register_on_exit(LPM3_bits); }