Statistics
| Branch: | Tag: | Revision:

mongoose / examples / MSP432 / ccs / MSP432_MG_hello / MSP_EXP432P401R.c @ eaef5bd1

History | View | Annotate | Download (19.5 KB)

1
/* clang-format off */
2
/*
3
 * Copyright (c) 2015-2016, Texas Instruments Incorporated
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 * *  Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 *
13
 * *  Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 *
17
 * *  Neither the name of Texas Instruments Incorporated nor the names of
18
 *    its contributors may be used to endorse or promote products derived
19
 *    from this software without specific prior written permission.
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
 */
33

    
34
/*
35
 *  ======== MSP_EXP432P401R.c ========
36
 *  This file is responsible for setting up the board specific items for the
37
 *  MSP_EXP432P401R board.
38
 */
39

    
40
#include <stdbool.h>
41

    
42
#include <ti/drivers/ports/DebugP.h>
43
#include <ti/drivers/ports/HwiP.h>
44
#include <ti/drivers/Power.h>
45
#include <ti/drivers/power/PowerMSP432.h>
46

    
47
#include <msp.h>
48
#include <rom.h>
49
#include <rom_map.h>
50
#include <dma.h>
51
#include <gpio.h>
52
#include <i2c.h>
53
#include <pmap.h>
54
#include <spi.h>
55
#include <timer_a.h>
56
#include <uart.h>
57
#include <wdt_a.h>
58

    
59
#include <interrupt.h>
60

    
61
#include "MSP_EXP432P401R.h"
62

    
63
/*
64
 *  =============================== DMA ===============================
65
 */
66
#if defined(__TI_COMPILER_VERSION__)
67
#pragma DATA_ALIGN(dmaControlTable, 256)
68
#elif defined(__IAR_SYSTEMS_ICC__)
69
#pragma data_alignment=256
70
#elif defined(__GNUC__)
71
__attribute__ ((aligned (256)))
72
#endif
73
static DMA_ControlTable dmaControlTable[8];
74
static bool dmaInitialized = false;
75

    
76
/*
77
 *  ======== dmaErrorHwi ========
78
 */
79
static void dmaErrorHwi(uintptr_t arg)
80
{
81
    DebugP_log1("DMA error code: %d\n", MAP_DMA_getErrorStatus());
82
    MAP_DMA_clearErrorStatus();
83
    DebugP_log0("DMA error!!\n");
84
    while(1);
85
}
86

    
87
/*
88
 *  ======== MSP_EXP432P401R_initDMA ========
89
 */
90
void MSP_EXP432P401R_initDMA(void)
91
{
92
    HwiP_Params hwiParams;
93
    HwiP_Handle dmaErrorHwiHandle;
94

    
95
    if (!dmaInitialized) {
96
        HwiP_Params_init(&hwiParams);
97
        dmaErrorHwiHandle = HwiP_create(INT_DMA_ERR, dmaErrorHwi, &hwiParams);
98
        if (dmaErrorHwiHandle == NULL) {
99
            DebugP_log0("Failed to create DMA error Hwi!!\n");
100
            while (1);
101
        }
102

    
103
        MAP_DMA_enableModule();
104
        MAP_DMA_setControlBase(dmaControlTable);
105

    
106
        dmaInitialized = true;
107
    }
108
}
109

    
110
/*
111
 *  ======== MSP_EXP432P401R_initGeneral ========
112
 */
113
void MSP_EXP432P401R_initGeneral(void)
114
{
115
    Power_init();
116
}
117

    
118
/*
119
 *  =============================== GPIO ===============================
120
 */
121
/* Place into subsections to allow the TI linker to remove items properly */
122
#if defined(__TI_COMPILER_VERSION__)
123
#pragma DATA_SECTION(GPIOMSP432_config, ".const:GPIOMSP432_config")
124
#endif
125

    
126
#include <ti/drivers/GPIO.h>
127
#include <ti/drivers/gpio/GPIOMSP432.h>
128

    
129
/*
130
 * Array of Pin configurations
131
 * NOTE: The order of the pin configurations must coincide with what was
132
 *       defined in MSP_EXP432P401R.h
133
 * NOTE: Pins not used for interrupts should be placed at the end of the
134
 *       array.  Callback entries can be omitted from callbacks array to
135
 *       reduce memory usage.
136
 */
137
GPIO_PinConfig gpioPinConfigs[] = {
138
    /* Input pins */
139
    /* MSP_EXP432P401R_S1 */
140
    GPIOMSP432_P1_1 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
141
    /* MSP_EXP432P401R_S2 */
142
    GPIOMSP432_P1_4 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
143

    
144
    /* Output pins */
145
    /* MSP_EXP432P401R_LED1 */
146
    GPIOMSP432_P1_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
147
    /* MSP_EXP432P401R_LED_RED */
148
    GPIOMSP432_P2_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
149

    
150
    /*
151
     * MSP_EXP432P401R_LED_GREEN & MSP_EXP432P401R_LED_BLUE are used for
152
     * PWM examples.  Uncomment the following lines if you would like to control
153
     * the LEDs with the GPIO driver.
154
     */
155
    /* MSP_EXP432P401R_LED_GREEN */
156
    //GPIOMSP432_P2_1 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
157
    /* MSP_EXP432P401R_LED_BLUE */
158
    //GPIOMSP432_P2_2 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW
159
};
160

    
161
/*
162
 * Array of callback function pointers
163
 * NOTE: The order of the pin configurations must coincide with what was
164
 *       defined in MSP_EXP432P401R.h
165
 * NOTE: Pins not used for interrupts can be omitted from callbacks array to
166
 *       reduce memory usage (if placed at end of gpioPinConfigs array).
167
 */
168
GPIO_CallbackFxn gpioCallbackFunctions[] = {
169
    /* MSP_EXP432P401R_S1 */
170
    NULL,
171
    /* MSP_EXP432P401R_S2 */
172
    NULL
173
};
174

    
175
const GPIOMSP432_Config GPIOMSP432_config = {
176
    .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs,
177
    .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions,
178
    .numberOfPinConfigs = sizeof(gpioPinConfigs)/sizeof(GPIO_PinConfig),
179
    .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn),
180
    .intPriority = (~0)
181
};
182

    
183
/*
184
 *  ======== MSP_EXP432P401R_initGPIO ========
185
 */
186
void MSP_EXP432P401R_initGPIO(void)
187
{
188
    /* Initialize peripheral and pins */
189
    GPIO_init();
190
}
191

    
192
/*
193
 *  =============================== I2C ===============================
194
 */
195
/* Place into subsections to allow the TI linker to remove items properly */
196
#if defined(__TI_COMPILER_VERSION__)
197
#pragma DATA_SECTION(I2C_config, ".const:I2C_config")
198
#pragma DATA_SECTION(i2cMSP432HWAttrs, ".const:i2cMSP432HWAttrs")
199
#endif
200

    
201
#include <ti/drivers/I2C.h>
202
#include <ti/drivers/i2c/I2CMSP432.h>
203

    
204
I2CMSP432_Object i2cMSP432Objects[MSP_EXP432P401R_I2CCOUNT];
205

    
206
const I2CMSP432_HWAttrs i2cMSP432HWAttrs[MSP_EXP432P401R_I2CCOUNT] = {
207
    {
208
        .baseAddr = EUSCI_B0_BASE,
209
        .intNum = INT_EUSCIB0,
210
        .intPriority = (~0),
211
        .clockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK
212
    }
213
};
214

    
215
const I2C_Config I2C_config[] = {
216
    {
217
        .fxnTablePtr = &I2CMSP432_fxnTable,
218
        .object = &i2cMSP432Objects[0],
219
        .hwAttrs = &i2cMSP432HWAttrs[0]
220
    },
221
    {NULL, NULL, NULL}
222
};
223

    
224
/*
225
 *  ======== MSP_EXP432P401R_initI2C ========
226
 */
227
void MSP_EXP432P401R_initI2C(void)
228
{
229
    /*
230
     * NOTE: TI-RTOS examples configure EUSCIB0 as either SPI or I2C.  Thus,
231
     * a conflict occurs when the I2C & SPI drivers are used simultaneously in
232
     * an application.  Modify the pin mux settings in this file and resolve the
233
     * conflict before running your the application.
234
     */
235
    /* Configure Pins 1.6 & 1.7 as SDA & SCL, respectively. */
236
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
237
        GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
238

    
239
    /* Initialize the I2C driver */
240
    I2C_init();
241
}
242

    
243
/*
244
 *  =============================== Power ===============================
245
 */
246
const PowerMSP432_Config PowerMSP432_config = {
247
    .policyInitFxn = &PowerMSP432_initPolicy,
248
    .policyFxn = &PowerMSP432_sleepPolicy,
249
    .initialPerfLevel = 2,
250
    .enablePolicy = false,
251
    .enablePerf = true
252
};
253

    
254
/*
255
 *  =============================== PWM ===============================
256
 */
257
/* Place into subsections to allow the TI linker to remove items properly */
258
#if defined(__TI_COMPILER_VERSION__)
259
#pragma DATA_SECTION(PWM_config, ".const:PWM_config")
260
#pragma DATA_SECTION(pwmTimerMSP432HWAttrs, ".const:pwmTimerMSP432HWAttrs")
261
#endif
262

    
263
#include <ti/drivers/PWM.h>
264
#include <ti/drivers/pwm/PWMTimerMSP432.h>
265

    
266
PWMTimerMSP432_Object pwmTimerMSP432Objects[MSP_EXP432P401R_PWMCOUNT];
267

    
268
const PWMTimerMSP432_HWAttrs pwmTimerMSP432HWAttrs[MSP_EXP432P401R_PWMCOUNT] = {
269
    {
270
        .baseAddr = TIMER_A1_BASE,
271
        .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1
272
    },
273
    {
274
        .baseAddr = TIMER_A1_BASE,
275
        .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_2
276
    }
277
};
278

    
279
const PWM_Config PWM_config[] = {
280
    {
281
        .fxnTablePtr = &PWMTimerMSP432_fxnTable,
282
        .object = &pwmTimerMSP432Objects[0],
283
        .hwAttrs = &pwmTimerMSP432HWAttrs[0]
284
    },
285
    {
286
        .fxnTablePtr = &PWMTimerMSP432_fxnTable,
287
        .object = &pwmTimerMSP432Objects[1],
288
        .hwAttrs = &pwmTimerMSP432HWAttrs[1]
289
    },
290
    {NULL, NULL, NULL}
291
};
292

    
293
/*
294
 *  ======== MSP_EXP432P401R_initPWM ========
295
 */
296
void MSP_EXP432P401R_initPWM(void)
297
{
298
    /* Use Port Map on Port2 get Timer outputs on pins with LEDs (2.1, 2.2) */
299
    const uint8_t portMap [] = {
300
        PM_NONE, PM_TA1CCR1A, PM_TA1CCR2A, PM_NONE,
301
        PM_NONE, PM_NONE,     PM_NONE,     PM_NONE
302
    };
303

    
304
    /* Mapping capture compare registers to Port 2 */
305
    MAP_PMAP_configurePorts((const uint8_t *) portMap, PMAP_P2MAP, 1,
306
        PMAP_DISABLE_RECONFIGURATION);
307

    
308
    /* Enable PWM output on GPIO pins */
309
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,
310
        GPIO_PIN1 | GPIO_PIN2, GPIO_PRIMARY_MODULE_FUNCTION);
311

    
312
    PWM_init();
313
}
314

    
315
/*
316
 *  =============================== SDSPI ===============================
317
 */
318
/* Place into subsections to allow the TI linker to remove items properly */
319
#if defined(__TI_COMPILER_VERSION__)
320
#pragma DATA_SECTION(SDSPI_config, ".const:SDSPI_config")
321
#pragma DATA_SECTION(sdspiMSP432HWAttrs, ".const:sdspiMSP432HWAttrs")
322
#endif
323

    
324
#include <ti/drivers/SDSPI.h>
325
#include <ti/drivers/sdspi/SDSPIMSP432.h>
326

    
327
SDSPIMSP432_Object sdspiMSP432Objects[MSP_EXP432P401R_SDSPICOUNT];
328

    
329
const SDSPIMSP432_HWAttrs sdspiMSP432HWAttrs[MSP_EXP432P401R_SDSPICOUNT] = {
330
    {
331
        .baseAddr = EUSCI_B0_BASE,
332
        .clockSource = EUSCI_B_SPI_CLOCKSOURCE_SMCLK,
333

    
334
        /* CLK, MOSI & MISO ports & pins */
335
        .portSCK = GPIO_PORT_P1,
336
        .pinSCK = GPIO_PIN5,
337
        .sckMode = GPIO_PRIMARY_MODULE_FUNCTION,
338

    
339
        .portMISO = GPIO_PORT_P1,
340
        .pinMISO = GPIO_PIN7,
341
        .misoMode = GPIO_PRIMARY_MODULE_FUNCTION,
342

    
343
        .portMOSI = GPIO_PORT_P1,
344
        .pinMOSI = GPIO_PIN6,
345
        .mosiMode = GPIO_PRIMARY_MODULE_FUNCTION,
346

    
347
        /* Chip select port & pin */
348
        .portCS = GPIO_PORT_P4,
349
        .pinCS = GPIO_PIN6
350
    }
351
};
352

    
353
const SDSPI_Config SDSPI_config[] = {
354
    {
355
        .fxnTablePtr = &SDSPIMSP432_fxnTable,
356
        .object = &sdspiMSP432Objects[0],
357
        .hwAttrs = &sdspiMSP432HWAttrs[0]
358
    },
359
    {NULL, NULL, NULL}
360
};
361

    
362
/*
363
 *  ======== MSP_EXP432P401R_initSDSPI ========
364
 */
365
void MSP_EXP432P401R_initSDSPI(void)
366
{
367
    SDSPI_init();
368
}
369

    
370
/*
371
 *  =============================== SPI ===============================
372
 */
373
/* Place into subsections to allow the TI linker to remove items properly */
374
#if defined(__TI_COMPILER_VERSION__)
375
#pragma DATA_SECTION(SPI_config, ".const:SPI_config")
376
#pragma DATA_SECTION(spiMSP432DMAHWAttrs, ".const:spiMSP432DMAHWAttrs")
377
#endif
378

    
379
#include <ti/drivers/SPI.h>
380
#include <ti/drivers/spi/SPIMSP432DMA.h>
381

    
382
SPIMSP432DMA_Object spiMSP432DMAObjects[MSP_EXP432P401R_SPICOUNT];
383

    
384
const SPIMSP432DMA_HWAttrs spiMSP432DMAHWAttrs[MSP_EXP432P401R_SPICOUNT] = {
385
    {
386
        .baseAddr = EUSCI_B0_BASE,
387
        .bitOrder = EUSCI_B_SPI_MSB_FIRST,
388
        .clockSource = EUSCI_B_SPI_CLOCKSOURCE_SMCLK,
389

    
390
        .defaultTxBufValue = 0,
391

    
392
        .dmaIntNum = INT_DMA_INT1,
393
        .intPriority = (~0),
394
        .rxDMAChannelIndex = DMA_CH1_EUSCIB0RX0,
395
        .txDMAChannelIndex = DMA_CH0_EUSCIB0TX0
396
    },
397
    {
398
        .baseAddr = EUSCI_B2_BASE,
399
        .bitOrder = EUSCI_B_SPI_MSB_FIRST,
400
        .clockSource = EUSCI_B_SPI_CLOCKSOURCE_SMCLK,
401

    
402
        .defaultTxBufValue = 0,
403

    
404
        .dmaIntNum = INT_DMA_INT2,
405
        .intPriority = (~0),
406
        .rxDMAChannelIndex = DMA_CH5_EUSCIB2RX0,
407
        .txDMAChannelIndex = DMA_CH4_EUSCIB2TX0
408
    }
409
};
410

    
411
const SPI_Config SPI_config[] = {
412
    {
413
        .fxnTablePtr = &SPIMSP432DMA_fxnTable,
414
        .object = &spiMSP432DMAObjects[0],
415
        .hwAttrs = &spiMSP432DMAHWAttrs[0]
416
    },
417
    {
418
        .fxnTablePtr = &SPIMSP432DMA_fxnTable,
419
        .object = &spiMSP432DMAObjects[1],
420
        .hwAttrs = &spiMSP432DMAHWAttrs[1]
421
    },
422
    {NULL, NULL, NULL},
423
};
424

    
425
/*
426
 *  ======== MSP_EXP432P401R_initSPI ========
427
 */
428
void MSP_EXP432P401R_initSPI(void)
429
{
430
    /*
431
     * NOTE: TI-RTOS examples configure EUSCIB0 as either SPI or I2C.  Thus,
432
     * a conflict occurs when the I2C & SPI drivers are used simultaneously in
433
     * an application.  Modify the pin mux settings in this file and resolve the
434
     * conflict before running your the application.
435
     */
436
    /* Configure CLK, MOSI & MISO for SPI0 (EUSCI_B0) */
437
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1,
438
        GPIO_PIN5 | GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION);
439
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN7,
440
        GPIO_PRIMARY_MODULE_FUNCTION);
441

    
442
    /* Configure CLK, MOSI & MISO for SPI1 (EUSCI_B2) */
443
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3,
444
        GPIO_PIN5 | GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION);
445
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3, GPIO_PIN7,
446
        GPIO_PRIMARY_MODULE_FUNCTION);
447

    
448
    MSP_EXP432P401R_initDMA();
449
    SPI_init();
450
}
451

    
452
/*
453
 *  =============================== UART ===============================
454
 */
455
/* Place into subsections to allow the TI linker to remove items properly */
456
#if defined(__TI_COMPILER_VERSION__)
457
#pragma DATA_SECTION(UART_config, ".const:UART_config")
458
#pragma DATA_SECTION(uartMSP432HWAttrs, ".const:uartMSP432HWAttrs")
459
#endif
460

    
461
#include <ti/drivers/UART.h>
462
#include <ti/drivers/uart/UARTMSP432.h>
463

    
464
UARTMSP432_Object uartMSP432Objects[MSP_EXP432P401R_UARTCOUNT];
465
unsigned char uartMSP432RingBuffer[MSP_EXP432P401R_UARTCOUNT][32];
466

    
467
/*
468
 * The baudrate dividers were determined by using the MSP430 baudrate
469
 * calculator
470
 * http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
471
 */
472
const UARTMSP432_BaudrateConfig uartMSP432Baudrates[] = {
473
    /* {baudrate, input clock, prescalar, UCBRFx, UCBRSx, oversampling} */
474
    {
475
        .outputBaudrate = 115200,
476
        .inputClockFreq = 12000000,
477
        .prescalar = 6,
478
        .hwRegUCBRFx = 8,
479
        .hwRegUCBRSx = 32,
480
        .oversampling = 1
481
    },
482
    {115200, 6000000,   3,  4,   2, 1},
483
    {115200, 3000000,   1, 10,   0, 1},
484
    {9600,   12000000, 78,  2,   0, 1},
485
    {9600,   6000000,  39,  1,   0, 1},
486
    {9600,   3000000,  19,  8,  85, 1},
487
    {9600,   32768,     3,  0, 146, 0}
488
};
489

    
490
const UARTMSP432_HWAttrs uartMSP432HWAttrs[MSP_EXP432P401R_UARTCOUNT] = {
491
    {
492
        .baseAddr = EUSCI_A0_BASE,
493
        .intNum = INT_EUSCIA0,
494
        .intPriority = (~0),
495
        .clockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK,
496
        .bitOrder = EUSCI_A_UART_LSB_FIRST,
497
        .numBaudrateEntries = sizeof(uartMSP432Baudrates) /
498
            sizeof(UARTMSP432_BaudrateConfig),
499
        .baudrateLUT = uartMSP432Baudrates,
500
        .ringBufPtr  = uartMSP432RingBuffer[0],
501
        .ringBufSize = sizeof(uartMSP432RingBuffer[0])
502
    },
503
    {
504
        .baseAddr = EUSCI_A2_BASE,
505
        .intNum = INT_EUSCIA2,
506
        .intPriority = (~0),
507
        .clockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK,
508
        .bitOrder = EUSCI_A_UART_LSB_FIRST,
509
        .numBaudrateEntries = sizeof(uartMSP432Baudrates) /
510
            sizeof(UARTMSP432_BaudrateConfig),
511
        .baudrateLUT = uartMSP432Baudrates,
512
        .ringBufPtr  = uartMSP432RingBuffer[1],
513
        .ringBufSize = sizeof(uartMSP432RingBuffer[1])
514
    }
515
};
516

    
517
const UART_Config UART_config[] = {
518
    {
519
        .fxnTablePtr = &UARTMSP432_fxnTable,
520
        .object = &uartMSP432Objects[0],
521
        .hwAttrs = &uartMSP432HWAttrs[0]
522
    },
523
    {
524
        .fxnTablePtr = &UARTMSP432_fxnTable,
525
        .object = &uartMSP432Objects[1],
526
        .hwAttrs = &uartMSP432HWAttrs[1]
527
    },
528
    {NULL, NULL, NULL}
529
};
530

    
531
/*
532
 *  ======== MSP_EXP432P401R_initUART ========
533
 */
534
void MSP_EXP432P401R_initUART(void)
535
{
536
    /* Set P1.2 & P1.3 in UART mode */
537
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
538
        GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
539

    
540
    /* Set P3.2 & P3.3 in UART mode */
541
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3,
542
        GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
543

    
544
    /* Initialize the UART driver */
545
    UART_init();
546
}
547

    
548
/*
549
 *  =============================== Watchdog ===============================
550
 */
551
/* Place into subsections to allow the TI linker to remove items properly */
552
#if defined(__TI_COMPILER_VERSION__)
553
#pragma DATA_SECTION(Watchdog_config, ".const:Watchdog_config")
554
#pragma DATA_SECTION(watchdogMSP432HWAttrs, ".const:watchdogMSP432HWAttrs")
555
#endif
556

    
557
#include <ti/drivers/Watchdog.h>
558
#include <ti/drivers/watchdog/WatchdogMSP432.h>
559

    
560
WatchdogMSP432_Object watchdogMSP432Objects[MSP_EXP432P401R_WATCHDOGCOUNT];
561

    
562
const WatchdogMSP432_HWAttrs
563
    watchdogMSP432HWAttrs[MSP_EXP432P401R_WATCHDOGCOUNT] = {
564
    {
565
        .baseAddr = WDT_A_BASE,
566
        .intNum = INT_WDT_A,
567
        .intPriority = (~0),
568
        .clockSource = WDT_A_CLOCKSOURCE_SMCLK,
569
        .clockDivider = WDT_A_CLOCKDIVIDER_8192K
570
    },
571
};
572

    
573
const Watchdog_Config Watchdog_config[] = {
574
    {
575
        .fxnTablePtr = &WatchdogMSP432_fxnTable,
576
        .object = &watchdogMSP432Objects[0],
577
        .hwAttrs = &watchdogMSP432HWAttrs[0]
578
    },
579
    {NULL, NULL, NULL}
580
};
581

    
582
/*
583
 *  ======== MSP_EXP432P401R_initWatchdog ========
584
 */
585
void MSP_EXP432P401R_initWatchdog(void)
586
{
587
    /* Initialize the Watchdog driver */
588
    Watchdog_init();
589
}
590

    
591
/*
592
 *  =============================== WiFi ===============================
593
 */
594
/* Place into subsections to allow the TI linker to remove items properly */
595
#if defined(__TI_COMPILER_VERSION__)
596
#pragma DATA_SECTION(WiFi_config, ".const:WiFi_config")
597
#pragma DATA_SECTION(wiFiCC3100HWAttrs, ".const:wiFiCC3100HWAttrs")
598
#endif
599

    
600
#include <ti/drivers/WiFi.h>
601
#include <ti/drivers/wifi/WiFiCC3100.h>
602

    
603
WiFiCC3100_Object wiFiCC3100Objects[MSP_EXP432P401R_WIFICOUNT];
604

    
605
const WiFiCC3100_HWAttrs wiFiCC3100HWAttrs[MSP_EXP432P401R_WIFICOUNT] = {
606
    {
607
        .irqPort = GPIO_PORT_P2,
608
        .irqPin = GPIO_PIN5,
609
        .irqIntNum = INT_PORT2,
610

    
611
        .csPort = GPIO_PORT_P3,
612
        .csPin = GPIO_PIN0,
613

    
614
        .enPort = GPIO_PORT_P4,
615
        .enPin = GPIO_PIN1
616
    }
617
};
618

    
619
const WiFi_Config WiFi_config[] = {
620
    {
621
        .fxnTablePtr = &WiFiCC3100_fxnTable,
622
        .object = &wiFiCC3100Objects[0],
623
        .hwAttrs = &wiFiCC3100HWAttrs[0]
624
    },
625
    {NULL, NULL, NULL},
626
};
627

    
628
/*
629
 *  ======== MSP_EXP432P401R_initWiFi ========
630
 */
631
void MSP_EXP432P401R_initWiFi(void)
632
{
633
    /* Configure EN & CS pins to disable CC3100 */
634
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P3, GPIO_PIN0);
635
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN1);
636
    MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P3, GPIO_PIN0);
637
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN1);
638

    
639
    /* Configure CLK, MOSI & MISO for SPI0 (EUSCI_B0) */
640
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1,
641
        GPIO_PIN5 | GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION);
642
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN7,
643
        GPIO_PRIMARY_MODULE_FUNCTION);
644

    
645
    /* Configure IRQ pin */
646
    MAP_GPIO_setAsInputPinWithPullDownResistor(GPIO_PORT_P2, GPIO_PIN5);
647
    MAP_GPIO_interruptEdgeSelect(GPIO_PORT_P2, GPIO_PIN5,
648
        GPIO_LOW_TO_HIGH_TRANSITION);
649

    
650
    /* Initialize SPI and WiFi drivers */
651
    MSP_EXP432P401R_initDMA();
652
    SPI_init();
653
    WiFi_init();
654
}