forked from AlaskaResearchCubeSat/IGRF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UCint.c
48 lines (44 loc) · 1.08 KB
/
UCint.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <msp430.h>
#include "uart.h"
//buffers for USB UART
struct Tx TxBuf;
struct Rx RxBuf;
//UART TX ISR called to transmit UART data
void USB_TX(void) __interrupt[USCIAB1TX_VECTOR]{
unsigned char flags=UC1IFG&(UC1IE);
//process UART TXIFG
if(flags&UCA1TXIFG){
unsigned short t=TxBuf.out;
//check if their are more chars
if(TxBuf.in!=t){
//more chars TX next
UCA1TXBUF=TxBuf.buf[t++];
TxBuf.out=(t)%TX_SIZE;
}else{
//buffer empty disable TX
TxBuf.done=1;
UC1IFG&=~UCA1TXIFG;
}
//more room in buffer, exit LPM
LPM4_EXIT;
}
}
// receive UART ISR
void USB_rx(void) __interrupt[USCIAB1RX_VECTOR]{
unsigned char flags=UC1IFG&(UC1IE);
//process UART RXIFG
if(flags&UCA1RXIFG){
unsigned int t;
t=(RxBuf.in+1)%RX_SIZE;
//check if there is room
if(t!=RxBuf.out){
//write char in buffer
RxBuf.buf[RxBuf.in]=UCA1RXBUF;
//advance index
RxBuf.in=t;
//new char ready, exit LPM
LPM4_EXIT;
}
//if no room char is lost
}
}