/* * Start sending (unless already sending) */ void uart_send_next_msg(void) { // Disable interrupts to make sure UartTxBuffer state isn't modified in the middle __bic_status_register(GIE); if (UartTxBufferLength > 0 && uart_state != UART_STATE_TX) { uart_state = UART_STATE_TX; UCA0TXBUF = UartTxBuffer[UartTxBuffer_i]; // Send first byte } // Enable interrupts __bis_status_register(GIE); }
/* Change the current power-saving mode. */ enum lpm_mode lpm_set(enum lpm_mode target) { enum lpm_mode last_mode = lpm_get(); switch (target) { case LPM_ON: // fully running MCU __bic_status_register(CPUOFF | OSCOFF | SCG0 | SCG1); break; case LPM_IDLE: // lightest mode => LPM0 mode of MSP430 __bic_status_register(OSCOFF | SCG0 | SCG1); // only stops CPU block __bis_status_register(CPUOFF); break; case LPM_SLEEP: // mid-level mode => LPM1 mode of MSP430 __bic_status_register(OSCOFF | SCG1); // stops CPU and master clock blocks __bis_status_register(CPUOFF | SCG0); break; case LPM_POWERDOWN: // deep-level mode => LPM3 mode of MSP430 __bic_status_register(OSCOFF); // stops all blocks except auxiliary clock (timers) __bis_status_register(CPUOFF | SCG0 | SCG1); break; case LPM_OFF: // MCU totally down (LPM4), only RESET or NMI can resume execution __bis_status_register(CPUOFF | OSCOFF | SCG0 | SCG1); // all blocks off break; default: printf("ERROR: trying to set an invalid low-power mode!\n"); printf(" Operation aborted.\n\n"); } return last_mode; }
/* * Append new message to transmit buffer */ uint8_t uart_tx_append_msg(unsigned char *buf, unsigned char len) { int i; // Disable interrupts to make sure UartTxBuffer state isn't modified in the middle __bic_status_register(GIE); // Check that there's enough space if (UartTxBufferLength + len >= UART_BUF_LEN) { // Enable interrupts __bis_status_register(GIE); return 0; } for (i = 0; i < len; ++i) { UartTxBuffer[UartTxBufferLength + i] = buf[i]; } UartTxBufferLength += i; // Enable interrupts __bis_status_register(GIE); return i; }
/* resume the MSP430 MCU */ inline void lpm_awake(void) { // disable all power savings mechanisms __bic_status_register(CPUOFF | OSCOFF | SCG0 | SCG1); }