]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - i3-mote/i3-mote.git/blob - Basic-Test-Package/MSP432/Test_MSP432_I2C_M24xx256/MSP432P401R_I3M.c
MSP432 Test TI-RTOS
[i3-mote/i3-mote.git] / Basic-Test-Package / MSP432 / Test_MSP432_I2C_M24xx256 / MSP432P401R_I3M.c
1 /*
2  * Copyright (c) 2015-2016, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
33 /*
34  *  ======== MSP_I3MSP432P401R.c ========
35  *  This file is responsible for setting up the board specific items for the
36  *  MSP_I3MSP432P401R board.
37  */
39 #include <stdbool.h>
41 #include <ti/drivers/Power.h>
42 #include <ti/drivers/power/PowerMSP432.h>
44 #include <msp.h>
45 #include <rom.h>
46 #include <rom_map.h>
47 #include <dma.h>
48 #include <gpio.h>
49 #include <i2c.h>
50 #include <pmap.h>
51 #include <spi.h>
52 #include <timer_a.h>
53 #include <uart.h>
54 #include <wdt_a.h>
55 #include <adc14.h>
56 #include <ref_a.h>
57 #include <interrupt.h>
59 #include <MSP432P401R_I3M.h>
61 /*
62  *  =============================== ADC ===============================
63  */
64 #if defined(__TI_COMPILER_VERSION__)
65 #pragma DATA_SECTION(ADC_config, ".const:ADC_config")
66 #pragma DATA_SECTION(adcMSP432HWAttrs, ".const:adcMSP432HWAttrs")
67 #endif
69 #include <ti/drivers/ADC.h>
70 #include <ti/drivers/adc/ADCMSP432.h>
72 /* ADC objects */
73 ADCMSP432_Object adcMSP432Objects[MSP_I3MSP432P401R_ADCCOUNT];
75 /* ADC configuration structure */
76 const ADCMSP432_HWAttrs adcMSP432HWAttrs[MSP_I3MSP432P401R_ADCCOUNT] = {
77     {
78         .channel = ADC_INPUT_A0,
79         .gpioPort = GPIO_PORT_P5,
80         .gpioPin = GPIO_PIN5,
81         .gpioMode = GPIO_TERTIARY_MODULE_FUNCTION,
82         .refVoltage = REF_A_VREF2_5V,
83         .resolution = ADC_14BIT
84     },
85     {
86         .channel = ADC_INPUT_A1,
87         .gpioPort = GPIO_PORT_P5,
88         .gpioPin = GPIO_PIN4,
89         .gpioMode = GPIO_TERTIARY_MODULE_FUNCTION,
90         .refVoltage = REF_A_VREF1_45V,
91         .resolution = ADC_8BIT
92     }
93 };
95 const ADC_Config ADC_config[] = {
96     {
97         .fxnTablePtr = &ADCMSP432_fxnTable,
98         .object = &adcMSP432Objects[0],
99         .hwAttrs = &adcMSP432HWAttrs[0]
100     },
101     {
102         .fxnTablePtr = &ADCMSP432_fxnTable,
103         .object = &adcMSP432Objects[1],
104         .hwAttrs = &adcMSP432HWAttrs[1]
105     },
106     {NULL, NULL, NULL}
107 };
109 void MSP_I3MSP432P401R_initADC(void)
111     ADC_init();
114 /*
115  *  =============================== DMA ===============================
116  */
118 #include <ti/drivers/dma/UDMAMSP432.h>
121 #if defined(__TI_COMPILER_VERSION__)
122 #pragma DATA_ALIGN(dmaControlTable, 256)
123 #elif defined(__IAR_SYSTEMS_ICC__)
124 #pragma data_alignment=256
125 #elif defined(__GNUC__)
126 __attribute__ ((aligned (256)))
127 #endif
128 static DMA_ControlTable dmaControlTable[8];
130 /*
131  *  ======== dmaErrorHwi ========
132  *  This is the handler for the uDMA error interrupt.
133  */
134 static void dmaErrorHwi(uintptr_t arg)
136     int status = MAP_DMA_getErrorStatus();
137     MAP_DMA_clearErrorStatus();
139     /* Suppress unused variable warning */
140     (void)status;
142     while (1);
145 UDMAMSP432_Object udmaMSP432Object;
147 const UDMAMSP432_HWAttrs udmaMSP432HWAttrs = {
148     .controlBaseAddr = (void *)dmaControlTable,
149     .dmaErrorFxn = (UDMAMSP432_ErrorFxn)dmaErrorHwi,
150     .intNum = INT_DMA_ERR,
151     .intPriority = (~0)
152 };
154 const UDMAMSP432_Config UDMAMSP432_config = {
155     .object = &udmaMSP432Object,
156     .hwAttrs = &udmaMSP432HWAttrs
157 };
159 /*
160  *  ======== MSP_I3MSP432P401R_initGeneral ========
161  */
162 void MSP_I3MSP432P401R_initGeneral(void)
164     Power_init();
167 /*
168  *  =============================== GPIO ===============================
169  */
170 /* Place into subsections to allow the TI linker to remove items properly */
171 #if defined(__TI_COMPILER_VERSION__)
172 #pragma DATA_SECTION(GPIOMSP432_config, ".const:GPIOMSP432_config")
173 #endif
175 #include <ti/drivers/GPIO.h>
176 #include <ti/drivers/gpio/GPIOMSP432.h>
178 /*
179  * Array of Pin configurations
180  * NOTE: The order of the pin configurations must coincide with what was
181  *       defined in MSP_I3MSP432P401R.h
182  * NOTE: Pins not used for interrupts should be placed at the end of the
183  *       array.  Callback entries can be omitted from callbacks array to
184  *       reduce memory usage.
185  */
186 GPIO_PinConfig gpioPinConfigs[] = {
187     /* Input pins */
188     /* MSP_I3MSP432P401R_S1 */
189         GPIOMSP432_P6_1 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
191     /* Output pins */
192         /* MSP_I3MSP432P401R_SPI1_IRQ */
193         GPIOMSP432_P4_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
195         /* MSP_I3MSP432P401R_SPI1_CS */
196     GPIOMSP432_P2_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
198         /* MSP_I3MSP432P401R_SPI2_CS */
199         GPIOMSP432_P3_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
201     /*
202      * MSP_I3MSP432P401R_LED_GREEN & MSP_I3MSP432P401R_LED_BLUE are used for
203      * PWM examples.  Uncomment the following lines if you would like to control
204      * the LEDs with the GPIO driver.
205      */
206     /* MSP_I3MSP432P401R_LED_GREEN */
207     GPIOMSP432_P6_2 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
209     /* MSP_I3MSP432P401R_LED_RED */
210         GPIOMSP432_P6_3 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW
212 };
214 /*
215  * Array of callback function pointers
216  * NOTE: The order of the pin configurations must coincide with what was
217  *       defined in MSP_I3MSP432P401R.h
218  * NOTE: Pins not used for interrupts can be omitted from callbacks array to
219  *       reduce memory usage (if placed at end of gpioPinConfigs array).
220  */
221 GPIO_CallbackFxn gpioCallbackFunctions[] = {
222     /* MSP_I3MSP432P401R_S1 */
223     NULL,
224     /* MSP_I3MSP432P401R_S2 */
225     NULL
226 };
228 const GPIOMSP432_Config GPIOMSP432_config = {
229     .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs,
230     .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions,
231     .numberOfPinConfigs = sizeof(gpioPinConfigs)/sizeof(GPIO_PinConfig),
232     .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn),
233     .intPriority = (~0)
234 };
236 /*
237  *  ======== MSP_I3MSP432P401R_initGPIO ========
238  */
239 void MSP_I3MSP432P401R_initGPIO(void)
241     /* Initialize peripheral and pins */
242     GPIO_init();
245 /*
246  *  =============================== I2C ===============================
247  */
248 /* Place into subsections to allow the TI linker to remove items properly */
249 #if defined(__TI_COMPILER_VERSION__)
250 #pragma DATA_SECTION(I2C_config, ".const:I2C_config")
251 #pragma DATA_SECTION(i2cMSP432HWAttrs, ".const:i2cMSP432HWAttrs")
252 #endif
254 #include <ti/drivers/I2C.h>
255 #include <ti/drivers/i2c/I2CMSP432.h>
257 I2CMSP432_Object i2cMSP432Objects[MSP_I3MSP432P401R_I2CCOUNT];
259 const I2CMSP432_HWAttrs i2cMSP432HWAttrs[MSP_I3MSP432P401R_I2CCOUNT] = {
260     {
261         .baseAddr = EUSCI_B2_BASE,
262         .intNum = INT_EUSCIB2,
263         .intPriority = (~0),
264         .clockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK
265     }
266 };
268 const I2C_Config I2C_config[] = {
269     {
270         .fxnTablePtr = &I2CMSP432_fxnTable,
271         .object = &i2cMSP432Objects[0],
272         .hwAttrs = &i2cMSP432HWAttrs[0]
273     },
274     {NULL, NULL, NULL}
275 };
277 /*
278  *  ======== MSP_I3MSP432P401R_initI2C ========
279  */
280 void MSP_I3MSP432P401R_initI2C(void)
282     /*
283      * NOTE: TI-RTOS examples configure EUSCIB0 as either SPI or I2C.  Thus,
284      * a conflict occurs when the I2C & SPI drivers are used simultaneously in
285      * an application.  Modify the pin mux settings in this file and resolve the
286      * conflict before running your the application.
287      */
288     /* Configure Pins 1.6 & 1.7 as SDA & SCL, respectively. */
289     // BMH MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
290         // BMH    GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
292         MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3,
293                 GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
296     /* Initialize the I2C driver */
297     I2C_init();
300 /*
301  *  =============================== Power ===============================
302  */
303 const PowerMSP432_ConfigV1 PowerMSP432_config = {
304     .policyInitFxn = &PowerMSP432_initPolicy,
305     .policyFxn = &PowerMSP432_sleepPolicy,
306     .initialPerfLevel = 2,
307     .enablePolicy = true,
308     .enablePerf = true,
309     .enableParking = true
310 };
312 /*
313  *  =============================== PWM ===============================
314  */
315 /* Place into subsections to allow the TI linker to remove items properly */
316 #if defined(__TI_COMPILER_VERSION__)
317 #pragma DATA_SECTION(PWM_config, ".const:PWM_config")
318 #pragma DATA_SECTION(pwmTimerMSP432HWAttrs, ".const:pwmTimerMSP432HWAttrs")
319 #endif
321 #include <ti/drivers/PWM.h>
322 #include <ti/drivers/pwm/PWMTimerMSP432.h>
324 PWMTimerMSP432_Object pwmTimerMSP432Objects[MSP_I3MSP432P401R_PWMCOUNT];
326 const PWMTimerMSP432_HWAttrsV1 pwmTimerMSP432HWAttrs[MSP_I3MSP432P401R_PWMCOUNT] = {
327     {
328         .timerBaseAddr = TIMER_A1_BASE,
329         .clockSource = TIMER_A_CLOCKSOURCE_SMCLK,
330         .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1,
331         .gpioPort = GPIO_PORT_P2,
332         .gpioPinIndex = GPIO_PIN1,
333         .pwmMode = GPIO_PRIMARY_MODULE_FUNCTION
334     },
335     {
336         .timerBaseAddr = TIMER_A1_BASE,
337         .clockSource = TIMER_A_CLOCKSOURCE_SMCLK,
338         .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_2,
339         .gpioPort = GPIO_PORT_P2,
340         .gpioPinIndex = GPIO_PIN2,
341         .pwmMode = GPIO_PRIMARY_MODULE_FUNCTION
342     }
343 };
345 const PWM_Config PWM_config[] = {
346     {
347         .fxnTablePtr = &PWMTimerMSP432_fxnTable,
348         .object = &pwmTimerMSP432Objects[0],
349         .hwAttrs = &pwmTimerMSP432HWAttrs[0]
350     },
351     {
352         .fxnTablePtr = &PWMTimerMSP432_fxnTable,
353         .object = &pwmTimerMSP432Objects[1],
354         .hwAttrs = &pwmTimerMSP432HWAttrs[1]
355     },
356     {NULL, NULL, NULL}
357 };
359 /*
360  *  ======== MSP_I3MSP432P401R_initPWM ========
361  */
362 void MSP_I3MSP432P401R_initPWM(void)
364     /* Use Port Map on Port2 get Timer outputs on pins with LEDs (2.1, 2.2) */
365     const uint8_t portMap [] = {
366         PM_NONE, PM_TA1CCR1A, PM_TA1CCR2A, PM_NONE,
367         PM_NONE, PM_NONE,     PM_NONE,     PM_NONE
368     };
370     /* Mapping capture compare registers to Port 2 */
371     MAP_PMAP_configurePorts((const uint8_t *) portMap, PMAP_P2MAP, 1,
372         PMAP_DISABLE_RECONFIGURATION);
374     PWM_init();
377 /*
378  *  =============================== SDSPI ===============================
379  */
380 /* Place into subsections to allow the TI linker to remove items properly */
381 #if 0
382         #if defined(__TI_COMPILER_VERSION__)
383         #pragma DATA_SECTION(SDSPI_config, ".const:SDSPI_config")
384         #pragma DATA_SECTION(sdspiMSP432HWAttrs, ".const:sdspiMSP432HWAttrs")
385         #endif
387         #include <ti/drivers/SDSPI.h>
388         #include <ti/drivers/sdspi/SDSPIMSP432.h>
390         SDSPIMSP432_Object sdspiMSP432Objects[MSP_I3MSP432P401R_SDSPICOUNT];
392         const SDSPIMSP432_HWAttrs sdspiMSP432HWAttrs[MSP_I3MSP432P401R_SDSPICOUNT] = {
393                 {
394                         .baseAddr = EUSCI_B0_BASE,
395                         .clockSource = EUSCI_B_SPI_CLOCKSOURCE_SMCLK,
397                         /* CLK, MOSI & MISO ports & pins */
398                         .portSCK = GPIO_PORT_P1,
399                         .pinSCK = GPIO_PIN5,
400                         .sckMode = GPIO_PRIMARY_MODULE_FUNCTION,
402                         .portMISO = GPIO_PORT_P1,
403                         .pinMISO = GPIO_PIN7,
404                         .misoMode = GPIO_PRIMARY_MODULE_FUNCTION,
406                         .portMOSI = GPIO_PORT_P1,
407                         .pinMOSI = GPIO_PIN6,
408                         .mosiMode = GPIO_PRIMARY_MODULE_FUNCTION,
410                         /* Chip select port & pin */
411                         .portCS = GPIO_PORT_P4,
412                         .pinCS = GPIO_PIN6
413                 }
414         };
416         const SDSPI_Config SDSPI_config[] = {
417                 {
418                         .fxnTablePtr = &SDSPIMSP432_fxnTable,
419                         .object = &sdspiMSP432Objects[0],
420                         .hwAttrs = &sdspiMSP432HWAttrs[0]
421                 },
422                 {NULL, NULL, NULL}
423         };
424 #endif
426 /*
427  *  ======== MSP_I3MSP432P401R_initSDSPI ========
428  */
429 #if 0
431         void MSP_I3MSP432P401R_initSDSPI(void)
432         {
433                 SDSPI_init();
434         }
436 #endif
438 /*
439  *  =============================== SPI ===============================
440  */
441 /* Place into subsections to allow the TI linker to remove items properly */
442 #if defined(__TI_COMPILER_VERSION__)
443 #pragma DATA_SECTION(SPI_config, ".const:SPI_config")
444 #pragma DATA_SECTION(spiMSP432DMAHWAttrs, ".const:spiMSP432DMAHWAttrs")
445 #endif
447 #include <ti/drivers/SPI.h>
448 #include <ti/drivers/spi/SPIMSP432DMA.h>
450 SPIMSP432DMA_Object spiMSP432DMAObjects[MSP_I3MSP432P401R_SPICOUNT];
452 const SPIMSP432DMA_HWAttrs spiMSP432DMAHWAttrs[MSP_I3MSP432P401R_SPICOUNT] = {
453                 {
454                         .baseAddr = EUSCI_B0_BASE,
455                         .bitOrder = EUSCI_B_SPI_MSB_FIRST,
456                         .clockSource = EUSCI_B_SPI_CLOCKSOURCE_SMCLK,
458                         .defaultTxBufValue = 0,
460                         .dmaIntNum = INT_DMA_INT0,
461                         .intPriority = (~0),
462                         .rxDMAChannelIndex = DMA_CH1_EUSCIB0RX0,
463                         .txDMAChannelIndex = DMA_CH0_EUSCIB0TX0
464                 },
465         {
466                 .baseAddr = EUSCI_A1_BASE,
467                 .bitOrder = EUSCI_A_SPI_MSB_FIRST,
468                 .clockSource = EUSCI_A_SPI_CLOCKSOURCE_SMCLK,
470                 .defaultTxBufValue = 0,
472                 .dmaIntNum = INT_DMA_INT1,
473                 .intPriority = (~0),
474                 .rxDMAChannelIndex = DMA_CH3_EUSCIA1RX,
475                 .txDMAChannelIndex = DMA_CH2_EUSCIA1TX
476         },
477     {
478         .baseAddr = EUSCI_A2_BASE,
479         .bitOrder = EUSCI_A_SPI_MSB_FIRST,
480         .clockSource = EUSCI_A_SPI_CLOCKSOURCE_SMCLK,
482         .defaultTxBufValue = 0,
484         .dmaIntNum = INT_DMA_INT2,
485         .intPriority = (~0),
486         .rxDMAChannelIndex = DMA_CH5_EUSCIA2RX,
487         .txDMAChannelIndex = DMA_CH4_EUSCIA2TX
488     }
490 };
492 const SPI_Config SPI_config[] = {
493     {
494         .fxnTablePtr = &SPIMSP432DMA_fxnTable,
495         .object = &spiMSP432DMAObjects[0],
496         .hwAttrs = &spiMSP432DMAHWAttrs[0]
497     },
498     {
499         .fxnTablePtr = &SPIMSP432DMA_fxnTable,
500         .object = &spiMSP432DMAObjects[1],
501         .hwAttrs = &spiMSP432DMAHWAttrs[1]
502     },
504     {
505         .fxnTablePtr = &SPIMSP432DMA_fxnTable,
506         .object = &spiMSP432DMAObjects[2],
507         .hwAttrs = &spiMSP432DMAHWAttrs[2]
508     },
509     {NULL, NULL, NULL},
510 };
512 /*
513  *  ======== MSP_I3MSP432P401R_initSPI ========
514  */
515 void MSP_I3MSP432P401R_initSPI(void)
517     /*
518      * NOTE: TI-RTOS examples configure EUSCIB0 as either SPI or I2C.  Thus,
519      * a conflict occurs when the I2C & SPI drivers are used simultaneously in
520      * an application.  Modify the pin mux settings in this file and resolve the
521      * conflict before running your the application.
522      */
524     /* Configure CLK, MOSI & MISO for SPI0 (EUSCI_B0) */
525     MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1,
526         GPIO_PIN5 | GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION);
527     MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN7,
528         GPIO_PRIMARY_MODULE_FUNCTION);
531 /* Configure CLK, MOSI & MISO for SPI0 (EUSCI_A1)*/
532 #if 0
533     #warning SPI_SLAVE_MODE
534         MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2,
535                 GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
536         MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN2,
537                 GPIO_PRIMARY_MODULE_FUNCTION);
538 #endif
540 #if 1
541         #warning SPI_MASTER_MODE
542         MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,
543                 GPIO_PIN1 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
544         MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2, GPIO_PIN2,
545                 GPIO_PRIMARY_MODULE_FUNCTION);
546 #endif
548     /* Configure CLK, MOSI & MISO for SPI0 (EUSCI_A2) */
549     MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3,
550         GPIO_PIN1 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
551     MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3, GPIO_PIN2,
552         GPIO_PRIMARY_MODULE_FUNCTION);
554     SPI_init();
557 /*
558  *  =============================== UART ===============================
559  */
560 /* Place into subsections to allow the TI linker to remove items properly */
561 #if defined(__TI_COMPILER_VERSION__)
562 #pragma DATA_SECTION(UART_config, ".const:UART_config")
563 #pragma DATA_SECTION(uartMSP432HWAttrs, ".const:uartMSP432HWAttrs")
564 #endif
566 #include <ti/drivers/UART.h>
567 #include <ti/drivers/uart/UARTMSP432.h>
569 UARTMSP432_Object uartMSP432Objects[MSP_I3MSP432P401R_UARTCOUNT];
570 unsigned char uartMSP432RingBuffer[MSP_I3MSP432P401R_UARTCOUNT][32];
572 /*
573  * The baudrate dividers were determined by using the MSP430 baudrate
574  * calculator
575  * http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
576  */
577 const UARTMSP432_BaudrateConfig uartMSP432Baudrates[] = {
578     /* {baudrate, input clock, prescalar, UCBRFx, UCBRSx, oversampling} */
579     {
580         .outputBaudrate = 115200,
581         .inputClockFreq = 12000000,
582         .prescalar = 6,
583         .hwRegUCBRFx = 8,
584         .hwRegUCBRSx = 32,
585         .oversampling = 1
586     },
587     {115200, 6000000,   3,  4,   2, 1},
588     {115200, 3000000,   1, 10,   0, 1},
589     {9600,   12000000, 78,  2,   0, 1},
590     {9600,   6000000,  39,  1,   0, 1},
591     {9600,   3000000,  19,  8,  85, 1},
592     {9600,   32768,     3,  0, 146, 0}
593 };
595 const UARTMSP432_HWAttrs uartMSP432HWAttrs[MSP_I3MSP432P401R_UARTCOUNT] = {
596     {
597         .baseAddr = EUSCI_A0_BASE,
598         .intNum = INT_EUSCIA0,
599         .intPriority = (~0),
600         .clockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK,
601         .bitOrder = EUSCI_A_UART_LSB_FIRST,
602         .numBaudrateEntries = sizeof(uartMSP432Baudrates) /
603             sizeof(UARTMSP432_BaudrateConfig),
604         .baudrateLUT = uartMSP432Baudrates,
605         .ringBufPtr  = uartMSP432RingBuffer[0],
606         .ringBufSize = sizeof(uartMSP432RingBuffer[0])
607     },
608     {
609         .baseAddr = EUSCI_A2_BASE,
610         .intNum = INT_EUSCIA2,
611         .intPriority = (~0),
612         .clockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK,
613         .bitOrder = EUSCI_A_UART_LSB_FIRST,
614         .numBaudrateEntries = sizeof(uartMSP432Baudrates) /
615             sizeof(UARTMSP432_BaudrateConfig),
616         .baudrateLUT = uartMSP432Baudrates,
617         .ringBufPtr  = uartMSP432RingBuffer[1],
618         .ringBufSize = sizeof(uartMSP432RingBuffer[1])
619     }
620 };
622 const UART_Config UART_config[] = {
623     {
624         .fxnTablePtr = &UARTMSP432_fxnTable,
625         .object = &uartMSP432Objects[0],
626         .hwAttrs = &uartMSP432HWAttrs[0]
627     },
628     {
629         .fxnTablePtr = &UARTMSP432_fxnTable,
630         .object = &uartMSP432Objects[1],
631         .hwAttrs = &uartMSP432HWAttrs[1]
632     },
633     {NULL, NULL, NULL}
634 };
636 /*
637  *  ======== MSP_I3MSP432P401R_initUART ========
638  */
639 void MSP_I3MSP432P401R_initUART(void)
641     /* Set P1.2 & P1.3 in UART mode */
642     MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
643         GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
645     /* Set P3.2 & P3.3 in UART mode */
646     MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3,
647         GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
649     /* Initialize the UART driver */
650     UART_init();
653 /*
654  *  =============================== Watchdog ===============================
655  */
656 /* Place into subsections to allow the TI linker to remove items properly */
657 #if defined(__TI_COMPILER_VERSION__)
658 #pragma DATA_SECTION(Watchdog_config, ".const:Watchdog_config")
659 #pragma DATA_SECTION(watchdogMSP432HWAttrs, ".const:watchdogMSP432HWAttrs")
660 #endif
662 #include <ti/drivers/Watchdog.h>
663 #include <ti/drivers/watchdog/WatchdogMSP432.h>
665 WatchdogMSP432_Object watchdogMSP432Objects[MSP_I3MSP432P401R_WATCHDOGCOUNT];
667 const WatchdogMSP432_HWAttrs
668     watchdogMSP432HWAttrs[MSP_I3MSP432P401R_WATCHDOGCOUNT] = {
669     {
670         .baseAddr = WDT_A_BASE,
671         .intNum = INT_WDT_A,
672         .intPriority = (~0),
673         .clockSource = WDT_A_CLOCKSOURCE_SMCLK,
674         .clockDivider = WDT_A_CLOCKDIVIDER_8192K
675     },
676 };
678 const Watchdog_Config Watchdog_config[] = {
679     {
680         .fxnTablePtr = &WatchdogMSP432_fxnTable,
681         .object = &watchdogMSP432Objects[0],
682         .hwAttrs = &watchdogMSP432HWAttrs[0]
683     },
684     {NULL, NULL, NULL}
685 };
687 /*
688  *  ======== MSP_I3MSP432P401R_initWatchdog ========
689  */
690 void MSP_I3MSP432P401R_initWatchdog(void)
692     /* Initialize the Watchdog driver */
693     Watchdog_init();
696 /*
697  *  =============================== WiFi ===============================
698  */
699 /* Place into subsections to allow the TI linker to remove items properly */
700 #if defined(__TI_COMPILER_VERSION__)
701 #pragma DATA_SECTION(WiFi_config, ".const:WiFi_config")
702 #pragma DATA_SECTION(wiFiCC3100HWAttrs, ".const:wiFiCC3100HWAttrs")
703 #endif
705 #include <ti/drivers/WiFi.h>
706 #include <ti/drivers/wifi/WiFiCC3100.h>
708 WiFiCC3100_Object wiFiCC3100Objects[MSP_I3MSP432P401R_WIFICOUNT];
710 const WiFiCC3100_HWAttrs wiFiCC3100HWAttrs[MSP_I3MSP432P401R_WIFICOUNT] = {
711     {
712         .irqPort = GPIO_PORT_P2,
713         .irqPin = GPIO_PIN5,
714         .irqIntNum = INT_PORT2,
716         .csPort = GPIO_PORT_P3,
717         .csPin = GPIO_PIN0,
719         .enPort = GPIO_PORT_P4,
720         .enPin = GPIO_PIN1
721     }
722 };
724 const WiFi_Config WiFi_config[] = {
725     {
726         .fxnTablePtr = &WiFiCC3100_fxnTable,
727         .object = &wiFiCC3100Objects[0],
728         .hwAttrs = &wiFiCC3100HWAttrs[0]
729     },
730     {NULL, NULL, NULL},
731 };
733 /*
734  *  ======== MSP_I3MSP432P401R_initWiFi ========
735  */
736 void MSP_I3MSP432P401R_initWiFi(void)
738     /* Configure EN & CS pins to disable CC3100 */
739     MAP_GPIO_setAsOutputPin(GPIO_PORT_P3, GPIO_PIN0);
740     MAP_GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN1);
741     MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P3, GPIO_PIN0);
742     MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN1);
744     /* Configure CLK, MOSI & MISO for SPI0 (EUSCI_B0) */
745     MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1,
746         GPIO_PIN5 | GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION);
747     MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN7,
748         GPIO_PRIMARY_MODULE_FUNCTION);
750     /* Configure IRQ pin */
751     MAP_GPIO_setAsInputPinWithPullDownResistor(GPIO_PORT_P2, GPIO_PIN5);
752     MAP_GPIO_interruptEdgeSelect(GPIO_PORT_P2, GPIO_PIN5,
753         GPIO_LOW_TO_HIGH_TRANSITION);
755     /* Initialize SPI and WiFi drivers */
756     SPI_init();
757     WiFi_init();