/
main.c
104 lines (87 loc) · 1.46 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* ======== Standard MSP430 includes ========
*/
#include <msp430.h>
/*
* ======== Grace related includes ========
*/
#include <ti/mcu/msp430/Grace.h>
#include "main.h"
#include "printf.h"
BYTE rxBuf[256];
int rxIdx;
int txIdx;
int tick = 0;
int rxIdxStore = 0;
BYTE idleResetCounter = 0;
void waitForTick()
{
tick = 0;
while (tick < 1)
{
// _BIS_SR(LPM0_bits + GIE);
while (rxIdx != txIdx)
{
{
while (UCA0STAT & UCBUSY)
{
}
UCA0TXBUF = rxBuf[txIdx++];
if (txIdx >= RXBUF_SIZE)
{
txIdx = 0;
}
}
}
}
if (rxIdxStore != rxIdx)
{
P1OUT = (P1OUT | BIT0) & ~ BIT6 ;
rxIdxStore = rxIdx;
idleResetCounter = 0;
}
else
{
P1OUT &= ~BIT0;
if (idleResetCounter < IDLERESETINTERVAL)
{
idleResetCounter++;
if ((P1IN & BIT3) == 0)
{
idleResetCounter = IDLERESETINTERVAL;
}
}
else if (idleResetCounter == IDLERESETINTERVAL)
{
UCB0CTL1 |= UCSWRST;
UCB0CTL1 &= ~UCSWRST;
IE2 |= UCB0RXIE;
P1OUT |= BIT6;
idleResetCounter = IDLERESETINTERVAL + 1;
}
}
}
/*
* ======== main ========
*/
int main(void)
{
Grace_init(); // Activate Grace-generated configuration
// >>>>> Fill-in user code here <<<<<
int j = 0;
while(1)
{
int i;
for (i=0; i< 3; i++)
{
waitForTick();
}
if (!(P2IN & BIT6))
{
printf("%i) Test output from SPI adaptor\r\n", j);
// putc(1);
j++;
}
}
return (0);
}