-
Notifications
You must be signed in to change notification settings - Fork 1
/
hello.c
260 lines (218 loc) · 7.25 KB
/
hello.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/ssi.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "adis.h"
#include "hardware_utils.h"
#include "abcc_user_def.h"
#include "user_setup.h"
#include "user_adi.h"
#include "abcc.h"
#include "abcc_sys_adapt.h"
#include "ad_obj.h"
#include "abcc_td.h"
/*******************************************************************************
** Constants
********************************************************************************
*/
typedef enum ABCCPowerStateType{
ABCCPOWER_RESET,
ABCCPOWER_STARTDRIVER,
ABCCPOWER_RESETRELEASE,
ABCCPOWER_WAITCOM,
ABCCPOWER_RUNNING,
ABCCPOWER_RESETREQ,
}ABCCPowerStateType;
/*******************************************************************************
** Globals
********************************************************************************
*/
BOOL8 fResetABCC = FALSE;
ABCCPowerStateType ABCCPowerState = ABCCPOWER_RESET;
//*****************************************************************************
//
// This function sets up UART0 to be used for a console to display information
// as the example is running.
//
//*****************************************************************************
void InitConsole(void)
{
//
// Enable GPIO port A which is used for UART0 pins.
// TODO: change this to whichever GPIO port you are using.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Configure the pin muxing for UART0 functions on port A0 and A1.
// This step is not necessary if your part does not support pin muxing.
// TODO: change this to select the port/pin you are using.
//
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
//
// Enable UART0 so that we can configure the clock.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//
// Select the alternate (UART) function for these pins.
// TODO: change this to select the port/pin you are using.
//
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 9600, 16000000);
}
/*------------------------------------------------------------------------------
** PrintException()
** Prints out network object specific error codes. Can be used for debugging
** when exceptions occur.
**------------------------------------------------------------------------------
*/
static void PrintException( ABP_MsgType* psNewMessage )
{
switch ( psNewMessage->sHeader.bSourceId )
{
case US_ANB_EXC_SRC_ID:
if ( !ABCC_VerifyMessage( psNewMessage ) )
{
while(1);
}
break;
case US_NW_EXC_SRC_ID:
if ( !ABCC_VerifyMessage( psNewMessage ) )
{
while(1);
}
break;
default:
while(1);
}
}
//*****************************************************************************
//
// Configure SSI0 in master Freescale (SPI) mode. This example will send out
// 3 bytes of data, then wait for 3 bytes of data to come in. This will all be
// done using the polling method.
//
//*****************************************************************************
int main(void)
{
#if defined(TARGET_IS_TM4C129_RA0) || \
defined(TARGET_IS_TM4C129_RA1) || \
defined(TARGET_IS_TM4C129_RA2)
#endif
//
// Set the clocking to run directly from the external crystal/oscillator.
// TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
// crystal on your board.
//
#if defined(TARGET_IS_TM4C129_RA0) || \
defined(TARGET_IS_TM4C129_RA1) || \
defined(TARGET_IS_TM4C129_RA2)
SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320,
CLOCK_RATE);
#else
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
#endif
BOOL8 fPrintErrorMessage = TRUE;
/*
* initializing spi
*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);
io_init();
iADI_err=adis_init();
SysCtlDelay(800000);
while(1)
{
switch( ABCCPowerState )
{
case ABCCPOWER_RESET:
ABCC_SYS_HWReset();
ABCCPowerState = ABCCPOWER_STARTDRIVER;
break;
case ABCCPOWER_STARTDRIVER:
if( ABCC_StartDriver( ABCC_GetOpmode(), FALSE ) == ABCC_OK )
{
ABCCPowerState = ABCCPOWER_RESETRELEASE;
}
break;
case ABCCPOWER_RESETRELEASE:
ABCC_HWReleaseReset();
ABCCPowerState = ABCCPOWER_WAITCOM;
break;
case ABCCPOWER_WAITCOM:
if( ABCC_isReadyForCommunication() )
{
AD_NewWrPd();
ABCCPowerState = ABCCPOWER_RUNNING;
}
break;
case ABCCPOWER_RUNNING:
if( fResetABCC )
{
fResetABCC = FALSE;
ABCCPowerState = ABCCPOWER_RESETREQ;
break;
}
/*
** Check if an exception has occurred and prints out the exception code and info.
*/
int ali= ABCC_AnbState();
if(ali==4){
int ali= ABCC_AnbState();
}
if( ( ali== ABP_ANB_STATE_EXCEPTION ) ) /* An error has occurred. */
{
if( fPrintErrorMessage )
{
ABP_MsgType* psANBMsgCmd;
ABP_MsgType* psNWMsgCmd;
psANBMsgCmd = ABCC_MsgAlloc();
ABCC_GetAttribute( psANBMsgCmd, ABP_OBJ_NUM_ANB, 1, ABP_ANB_IA_EXCEPTION, US_ANB_EXC_SRC_ID );
ABCC_SendCmdMsg( psANBMsgCmd, PrintException );
psNWMsgCmd = ABCC_MsgAlloc();
ABCC_GetAttribute( psNWMsgCmd, ABP_OBJ_NUM_NW, 1, ABP_NW_IA_EXCEPTION_INFO, US_NW_EXC_SRC_ID );
ABCC_SendCmdMsg( psNWMsgCmd, PrintException );
fPrintErrorMessage = FALSE;
}
}
else /* No error. */
{
fPrintErrorMessage = TRUE;
}
/*
** This function runs the driver and must be called cyclically.
** Typcally this function is called from the main loop.
*/
ABCC_RunDriver();
break;
case ABCCPOWER_RESETREQ:
ABCC_ShutdownDriver();
ABCCPowerState = ABCCPOWER_RESET;
break;
default:
break;
}
}
return(0);
}