void usart1_isr(void) { unsigned char c; /* Check if we were called because of RXNE. */ if (((USART_CR1(USART1) & USART_CR1_RXNEIE) != 0) && ((USART_SR(USART1) & USART_SR_RXNE) != 0) && (!serial_rb_full(&srx))) { c = serial_recv(); serial_rb_write(&srx, c); } /* Check if we were called because of TXE. */ else if (((USART_CR1(USART1) & USART_CR1_TXEIE) != 0) && ((USART_SR(USART1) & USART_SR_TXE) != 0)) { if(!serial_rb_empty(&stx)) { serial_send(serial_rb_read(&stx)); } else { /* Disable the TXE interrupt, it's no longer needed. */ USART_CR1(USART1) &= ~USART_CR1_TXEIE; } } else { c = serial_recv(); } }
interrupt(USCIAB0TX_VECTOR) USCI0TX_ISR(void) { if(!serial_rb_empty(&stx)) { serial_send(serial_rb_read(&stx)); } else { IE2 &= ~UCA0TXIE; } }
unsigned char packet_byte_from_rcvq() { // wait until data arrived in buffer while(serial_rb_empty(&srx)) { __asm__("nop"); } return serial_rb_read(&srx); }
interrupt(USCIAB0TX_VECTOR) USCI0TX_ISR(void) { if(!serial_rb_empty(&stx)) { serial_send(serial_rb_read(&stx)); } else { /* Disable the TX interrupt, it's no longer needed. */ IE2 &= ~UCA0TXIE; } }
int main(void) { int i; clock_init(); gpio_init(); serial_init(9600); serirq_init(); nrf_init(); nrf_configure_sb(); prx.size = PL_SIZE; ptx.size = PL_SIZE; while (1) { ptx.data[0] = 0; while(!serial_rb_empty(&srx) && ptx.data[0] < (PL_SIZE - 1)) { ptx.data[ptx.data[0] + 1] = serial_rb_read(&srx); ptx.data[0]++; } if(ptx.data[0] > 0) { #ifdef MSP430 P1OUT |= RXTX_LED; #else gpio_set(GPIOC, TX_LED); #endif // switch to PTX for sending out data ... nrf_set_mode_ptx(); nrf_send_blocking(&ptx); nrf_set_mode_prx(); } if(nrf_receive(&prx) != 0 && prx.data[0] > 0) { if(!serial_rb_full(&stx)) { for(i = 0; i < prx.data[0]; i++) serial_rb_write(&stx, prx.data[i + 1]); #ifdef MSP430 P1OUT |= RXTX_LED; IE2 |= UCA0TXIE; #else gpio_set(GPIOC, RX_LED); USART_CR1(USART1) |= USART_CR1_TXEIE; #endif } } } return 0; }