Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msp430: twi: move interrupt handler for USCI_Bx to twi.c #589

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions hardware/msp430/cores/msp430/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#include "twi.h"
#include "usci_isr_handler.h"

#if defined(__MSP430_HAS_USCI_B0__) || defined(__MSP430_HAS_USCI_B1__) || defined(__MSP430_HAS_EUSCI_B0__)
static boolean still_asleep; // Used to validate whether a user ISR has issued wakeup() inside LPM3/LPM4 sleep modes.
#endif

static volatile uint8_t twi_state;
static volatile uint8_t twi_sendStop; // should the transaction end with a stop
static volatile uint8_t twi_inRepStart; // in the middle of a repeated start
Expand Down Expand Up @@ -797,6 +801,42 @@ void i2c_state_isr(void) // I2C Service
}
#endif

#if defined(__MSP430_HAS_USCI_B0__) || defined(__MSP430_HAS_USCI_B1__)
#ifndef USE_USCI_B1
__attribute__((interrupt(USCI_B0_VECTOR)))
void USCIB0_ISR(void)
{
still_asleep = stay_asleep;

/* USCI_B0 I2C state change interrupt. */
if ((UCB0CTL0 & UCMODE_3) == UCMODE_3 && (UCB0IFG & (UCALIFG | UCNACKIFG | UCSTTIFG | UCSTPIFG)) != 0)
i2c_state_isr();
/* USCI_B0 I2C TX RX interrupt. */
if ((UCB0CTL0 & UCMODE_3) == UCMODE_3 && (UCB0IFG & (UCTXIFG | UCRXIFG)) != 0)
i2c_txrx_isr();

if (still_asleep != stay_asleep)
__bic_SR_register_on_exit(LPM4_bits);
}
#else
__attribute__((interrupt(USCI_B1_VECTOR)))
void USCIB1_ISR(void)
{
still_asleep = stay_asleep;

/* USCI_B1 I2C state change interrupt. */
if ((UCB1CTL0 & UCMODE_3) == UCMODE_3 && (UCB1IFG & (UCALIFG | UCNACKIFG | UCSTTIFG | UCSTPIFG)) != 0)
i2c_state_isr();
/* USCI_B1 I2C TX RX interrupt. */
if ((UCB1CTL0 & UCMODE_3) == UCMODE_3 && (UCB1IFG & (UCTXIFG | UCRXIFG)) != 0)
i2c_txrx_isr();

if (still_asleep != stay_asleep)
__bic_SR_register_on_exit(LPM4_bits);
}
#endif
#endif

#ifdef __MSP430_HAS_EUSCI_B0__
__attribute__((interrupt(USCI_B0_VECTOR)))
void USCI_B0_ISR(void)
Expand Down
38 changes: 2 additions & 36 deletions hardware/msp430/cores/msp430/usci_isr_handler.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Energia.h"
#if defined(__MSP430_HAS_USCI__) || defined(__MSP430_HAS_USCI_A0__) || defined(__MSP430_HAS_USCI_A1__) \
|| defined(__MSP430_HAS_EUSCI_A0__)|| defined(__MSP430_HAS_USCI_B0__) || defined(__MSP430_HAS_USCI_B1__)
|| defined(__MSP430_HAS_EUSCI_A0__)
#include "usci_isr_handler.h"
/* This dummy function ensures that, when called from any module that
* is interested in having the USCIAB0TX_VECTOR and USCIAB0TX_VECTOR
Expand Down Expand Up @@ -60,41 +60,6 @@ void USCIA1_ISR(void)
}
#endif

#if defined(__MSP430_HAS_USCI_B0__) || defined(__MSP430_HAS_USCI_B1__)
#ifndef USE_USCI_B1
__attribute__((interrupt(USCI_B0_VECTOR)))
void USCIB0_ISR(void)
{
still_asleep = stay_asleep;

/* USCI_B0 I2C state change interrupt. */
if ((UCB0CTL0 & UCMODE_3) == UCMODE_3 && (UCB0IFG & (UCALIFG | UCNACKIFG | UCSTTIFG | UCSTPIFG)) != 0)
i2c_state_isr();
/* USCI_B0 I2C TX RX interrupt. */
if ((UCB0CTL0 & UCMODE_3) == UCMODE_3 && (UCB0IFG & (UCTXIFG | UCRXIFG)) != 0)
i2c_txrx_isr();

if (still_asleep != stay_asleep)
__bic_SR_register_on_exit(LPM4_bits);
}
#else
__attribute__((interrupt(USCI_B1_VECTOR)))
void USCIB1_ISR(void)
{
still_asleep = stay_asleep;

/* USCI_B1 I2C state change interrupt. */
if ((UCB1CTL0 & UCMODE_3) == UCMODE_3 && (UCB1IFG & (UCALIFG | UCNACKIFG | UCSTTIFG | UCSTPIFG)) != 0)
i2c_state_isr();
/* USCI_B1 I2C TX RX interrupt. */
if ((UCB1CTL0 & UCMODE_3) == UCMODE_3 && (UCB1IFG & (UCTXIFG | UCRXIFG)) != 0)
i2c_txrx_isr();

if (still_asleep != stay_asleep)
__bic_SR_register_on_exit(LPM4_bits);
}
#endif
#endif

#endif //defined(__MSP430_HAS_USCI_A0__) || defined(__MSP430_HAS_USCI_A1__) || defined(__MSP430_HAS_EUSCI_A0__)

Expand Down Expand Up @@ -144,3 +109,4 @@ void USCIAB0RX_ISR(void)
}
#endif // __MSP430_HAS_USCI__
#endif // entire file

2 changes: 1 addition & 1 deletion hardware/msp430/cores/msp430/usci_isr_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define usci_isr_handler_h

#if defined(__MSP430_HAS_USCI__) || defined(__MSP430_HAS_USCI_A0__) || defined(__MSP430_HAS_USCI_A1__) \
|| defined(__MSP430_HAS_EUSCI_A0__)|| defined(__MSP430_HAS_USCI_B0__) || defined(__MSP430_HAS_USCI_B1__)
|| defined(__MSP430_HAS_EUSCI_A0__)

typedef void CHardwareSerial;
#ifdef __cplusplus
Expand Down