min.c 4.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#include "msp430.h"
#include "stdio.h"
#include "lib/radio_drv/radio_drv.h"
#include "lib/radio_drv/cc1x_utils.h"
#include "lib/radio_drv/hal_spi_rf.h"
#include "lib/uart_drv/uart_drv.h"
#include "LaunchPad_trx_demo.h"

/******************************************************************************
 * LOCAL FUNCTIONS
 */
extern void msp_setup(void);
13
unsigned long volatile time_counter;
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

/******************************************************************************
 * GLOBALS
 */
char u_str[UART_BUFF_SIZE];
unsigned char txBuffer[TX_BUFF_SIZE];
char user_button_pushed;
unsigned char wakeup_on_wdt;
trx_cfg_struct trx_cfg;


/******************************************************************************
 * @fn         main
 *
 * @brief      Main GUI application level control loop is implemented in the
 *             main loop. It is a state machine that cycles thru various states
 *             during the interactive use by the operator. The presents a text
 *             based GUI, the user is then promted to type in a command with
 *             a given set of parameters. The state machine then calls a simpler
 *             parser that tries to figure out what the user wants to do.
 *
 * input parameters
 *
 * @param       void
 *
 * output parameters
 *
 * @return      void
 *
 */
enum state_names {IDLE_RESET, WAIT, OPERATE};
void main (void)
{

	char idle_counter = 0;
	unsigned char u_str_length;
  enum state_names state = WAIT;

	/*  Stop WDT */
	WDTCTL = WDTPW + WDTHOLD;

	/* Setup MSP specific functions, IO's, timers and WDT */
56
    //Comes from lib/hal_mcu/hal_mcu.c
57
58
59
	msp_setup();

	/* Initialize the UART port */
60
	hal_uart_init();
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

	/* enable uart echo function */
	//uart_drv_toggle_echo();

	/* initialize the radio subsystem */
	//trx_cfg.bit_rate = radio_init(1);
	//trx_cfg.bit_rate = trx_cfg.bit_rate * 100;

	// Perform initial setup of the CC radio
	//trx_cfg.b_length = TX_BUFF_SIZE;
	//rf_default_setup(&trx_cfg);

	/* Configure LED ports */
  // Defined in hal_spi_rf_exp430fr5994
	LED1_PxDIR |= LED1_PIN;
	LED2_PxDIR |= LED2_PIN;
	LED3_PxDIR |= LED3_PIN;
	LED4_PxDIR |= LED4_PIN;

	/* default all LEDs to off */
	HAL_LED1_OFF();
	HAL_LED2_OFF();
	HAL_LED3_OFF();
	HAL_LED4_OFF();

	/* Generally we use the WDT time wake the statemachine */
	wakeup_on_wdt = 1;

	/* indicator that button has been pressed */
	user_button_pushed = 0;

	/* Infinite loop with a 1 second timer */
	while(1)
	{

		/* Put MCU in low power mode, wait for UART and blink LED */
97
		//Skip Low power mode to debug
98
		HAL_LED2_OFF();
99
		//_BIS_SR(LPM0_bits + GIE);
100
101
102
103
104
105
106
107
108
		HAL_LED2_ON();
		idle_counter++;


		/*
		 *    Main loop of state machine
		 */
		switch(state)
		{
109
		/* print the tick state to the UART buffer */
110
		case WAIT:
111
112
113
114
115
            if(time_counter>5){
                state = IDLE_RESET;
                uartSendString("Tic:\n\r");
                time_counter = 0;
            }
116
			state = OPERATE;
117
118
119
120
121
122
123
124
125
126
			HAL_LED1_OFF();
            break;
        case OPERATE:
            if(time_counter>5){
                state = WAIT;
                uartSendString("Tic:\n\r");
                time_counter = 0;
            }
			HAL_LED1_ON();
            break;
127
128
129
130
131
132
		default:
			state = WAIT;
			break;
		}
	}
}
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192


/******************************************************************************
 * @fn         uartSendString
 *
 * @brief      Implements a simple uart string sender by automatically finding
 *             the end of line delimeter and using it to call the uart sub
 *             functions
 *
 * input parameters
 *
 * @param            unsigned char *str
 *
 * output parameters
 *
 * @return      void
 *
 */
void uartSendString(char *str)
{
	unsigned char ii;

	for(ii=0;ii<UART_BUFF_SIZE;ii++)
	{
		if(str[ii] == 13)
		{
			uart_put_str(str, ii+1);
			ii = UART_BUFF_SIZE;
		}
	}
	return;
}

/******************************************************************************
 * @fn         wdt_isr
 *
 * @brief      Interrupt service routine for watch dog timer.
 *
 * input parameters
 *
 * @param       void
 *
 * output parameters
 *
 * @return      void
 *
 */
HAL_ISR_FUNC_DECLARATION(wdt_isr,WDT)
{
	/* global "0.5 second" counter used for printing time stamped packet sniffer data */
	time_counter++;

	/* check to see if wake on wdt is enabled */
	if(wakeup_on_wdt == 1)
	{

		/* exit from low power mode on ISR exit */
		//_BIC_SR_IRQ(LPM3_bits);
	}
}