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(); } }
void packet_byte_to_sendq(unsigned char pkt_byte) { // wait until buffer empties while(serial_rb_full(&stx)) { __asm__("nop"); } serial_rb_write(&stx, pkt_byte); 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; }
void client_server_tx_stx(unsigned char *data, int size) { int i; for(i = 0; i < size; i++) { if(serial_rb_full(&stx)) { break; } serial_rb_write(&stx, data[i]); } if(i > 0) { IE2 |= UCA0TXIE; } }
void client_server_tx_stx(unsigned char *data, int size) { int i; for(i = 0; i < size; i++) { if(serial_rb_full(&stx)) { break; } serial_rb_write(&stx, data[i]); } if(i > 0) { USART_CR1(USART1) |= USART_CR1_TXEIE; } }
interrupt(USCIAB0RX_VECTOR) USCI0RX_ISR(void) { if (!serial_rb_full(&srx)) { serial_rb_write(&srx, UCA0RXBUF); } }