]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/driverlib/spi.h
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / driverlib / spi.h
1 /*
2  * -------------------------------------------
3  *    MSP432 DriverLib - v01_04_00_18 
4  * -------------------------------------------
5  *
6  * --COPYRIGHT--,BSD,BSD
7  * Copyright (c) 2015, Texas Instruments Incorporated
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * *  Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  *
17  * *  Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * *  Neither the name of Texas Instruments Incorporated nor the names of
22  *    its contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  * --/COPYRIGHT--*/
37 #ifndef SPI_H_
38 #define SPI_H_
39
40 //*****************************************************************************
41 //
42 //! \addtogroup spi_api
43 //! @{
44 //
45 //*****************************************************************************
46
47 //*****************************************************************************
48 //
49 // If building with a C++ compiler, make all of the definitions in this header
50 // have a C binding.
51 //
52 //*****************************************************************************
53 #ifdef __cplusplus
54 extern "C"
55 {
56 #endif
57
58 #include <stdbool.h>
59 #include <stdint.h>
60 #include <msp.h>
61 #include "eusci.h"
62
63 /* Configuration Defines */
64 #define EUSCI_SPI_CLOCKSOURCE_ACLK    UCSSEL__ACLK
65 #define EUSCI_SPI_CLOCKSOURCE_SMCLK   UCSSEL__SMCLK
66
67 #define EUSCI_SPI_MSB_FIRST    UCMSB
68 #define EUSCI_SPI_LSB_FIRST    0x00
69
70 #define EUSCI_SPI_BUSY        UCBUSY
71 #define EUSCI_SPI_NOT_BUSY    0x00
72
73 #define EUSCI_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT    0x00
74 #define EUSCI_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT    UCCKPH
75
76 #define EUSCI_SPI_3PIN                      UCMODE_0
77 #define EUSCI_SPI_4PIN_UCxSTE_ACTIVE_HIGH   UCMODE_1
78 #define EUSCI_SPI_4PIN_UCxSTE_ACTIVE_LOW    UCMODE_2
79
80 #define EUSCI_SPI_CLOCKPOLARITY_INACTIVITY_HIGH    UCCKPL
81 #define EUSCI_SPI_CLOCKPOLARITY_INACTIVITY_LOW     0x00
82
83 #define EUSCI_SPI_TRANSMIT_INTERRUPT    UCTXIE
84 #define EUSCI_SPI_RECEIVE_INTERRUPT     UCRXIE
85
86 #define EUSCI_SPI_ENABLE_SIGNAL_FOR_4WIRE_SLAVE           UCSTEM
87 #define EUSCI_SPI_PREVENT_CONFLICTS_WITH_OTHER_MASTERS    0x00
88
89 //*****************************************************************************
90 //
91 //! \typedef eUSCI_SPI_MasterConfig
92 //! \brief Type definition for \link _eUSCI_SPI_MasterConfig \endlink structure
93 //!
94 //! \struct _eUSCI_SPI_MasterConfig
95 //! \brief Configuration structure for master mode in the \b SPI module. See
96 //!          \link SPI_initMaster \endlink for parameter documentation.
97 //
98 //*****************************************************************************
99 typedef struct _eUSCI_SPI_MasterConfig
100 {
101     uint_fast8_t selectClockSource;
102     uint32_t clockSourceFrequency;
103     uint32_t desiredSpiClock;
104     uint_fast16_t msbFirst;
105     uint_fast16_t clockPhase;
106     uint_fast16_t clockPolarity;
107     uint_fast16_t spiMode;
108 } eUSCI_SPI_MasterConfig;
109
110 //*****************************************************************************
111 //
112 //! \typedef eUSCI_SPI_SlaveConfig
113 //! \brief Type definition for \link _eUSCI_SPI_SlaveConfig \endlink structure
114 //!
115 //! \struct _eUSCI_SPI_SlaveConfig
116 //! \brief Configuration structure for slave mode in the \b SPI module. See
117 //!          \link SPI_initSlave \endlink for parameter documentation.
118 //
119 //*****************************************************************************
120 typedef struct _eUSCI_SPI_SlaveConfig
121 {
122     uint_fast16_t msbFirst;
123     uint_fast16_t clockPhase;
124     uint_fast16_t clockPolarity;
125     uint_fast16_t spiMode;
126 } eUSCI_SPI_SlaveConfig;
127
128 //*****************************************************************************
129 //
130 //! Initializes the SPI Master block.
131 //!
132 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
133 //! parameters vary from part to part, but can include:
134 //!         - \b EUSCI_A0_MODULE
135 //!         - \b EUSCI_A1_MODULE
136 //!         - \b EUSCI_A2_MODULE
137 //!         - \b EUSCI_A3_MODULE
138 //!         - \b EUSCI_B0_MODULE
139 //!         - \b EUSCI_B1_MODULE
140 //!         - \b EUSCI_B2_MODULE
141 //!         - \b EUSCI_B3_MODULE
142 //! \param config Configuration structure for SPI master mode
143 //!
144 //! <hr>
145 //! <b>Configuration options for \link eUSCI_SPI_MasterConfig \endlink structure.</b>
146 //! <hr>
147 //!
148 //! \param selectClockSource selects clock source. Valid values are
149 //!         - \b  EUSCI_SPI_CLOCKSOURCE_ACLK
150 //!         - \b  EUSCI_SPI_CLOCKSOURCE_SMCLK
151 //! \param clockSourceFrequency is the frequency of the selected clock source
152 //! \param desiredSpiClock is the desired clock rate for SPI communication
153 //! \param msbFirst controls the direction of the receive and transmit shift
154 //!      register. Valid values are
155 //!         - \b  EUSCI_SPI_MSB_FIRST
156 //!         - \b  EUSCI_SPI_LSB_FIRST [Default Value]
157 //! \param clockPhase is clock phase select.
158 //!         Valid values are
159 //!         - \b  EUSCI_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
160 //!                                                          [Default Value]
161 //!         - \b  EUSCI_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
162 //! \param clockPolarity is clock polarity select.
163 //!         Valid values are
164 //!         - \b  EUSCI_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
165 //!         - \b  EUSCI_SPI_CLOCKPOLARITY_INACTIVITY_LOW  [Default Value]
166 //! \param spiMode is SPI mode select.
167 //!         Valid values are
168 //!         - \b  EUSCI_SPI_3PIN [Default Value]
169 //!         - \b  EUSCI_SPI_4PIN_UCxSTE_ACTIVE_HIGH
170 //!         - \b  EUSCI_SPI_4PIN_UCxSTE_ACTIVE_LOW
171 //! Upon successful initialization of the SPI master block, this function
172 //! will have set the bus speed for the master, but the SPI Master block
173 //! still remains disabled and must be enabled with SPI_enableModule()
174 //!
175 //! Modified bits are \b UCCKPH, \b UCCKPL, \b UC7BIT, \b UCMSB,\b UCSSELx,
176 //! \b UCSWRST bits of \b UCAxCTLW0 register
177 //!
178 //! \return true
179 //
180 //*****************************************************************************
181 extern bool SPI_initMaster(uint32_t moduleInstance,
182         const eUSCI_SPI_MasterConfig *config);
183
184 //*****************************************************************************
185 //
186 //! Selects 4Pin Functionality
187 //!
188 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
189 //! parameters vary from part to part, but can include:
190 //!         - \b EUSCI_A0_MODULE
191 //!         - \b EUSCI_A1_MODULE
192 //!         - \b EUSCI_A2_MODULE
193 //!         - \b EUSCI_A3_MODULE
194 //!         - \b EUSCI_B0_MODULE
195 //!         - \b EUSCI_B1_MODULE
196 //!         - \b EUSCI_B2_MODULE
197 //!         - \b EUSCI_B3_MODULE
198 //!
199 //! \param select4PinFunctionality selects Clock source. Valid values are
200 //!         - \b EUSCI_SPI_PREVENT_CONFLICTS_WITH_OTHER_MASTERS
201 //!         - \b EUSCI_SPI_ENABLE_SIGNAL_FOR_4WIRE_SLAVE
202 //! This function should be invoked only in 4-wire mode. Invoking this function
203 //! has no effect in 3-wire mode.
204 //!
205 //! Modified bits are \b UCSTEM bit of \b UCAxCTLW0 register
206 //!
207 //! \return true
208 //
209 //*****************************************************************************
210 extern void SPI_selectFourPinFunctionality(uint32_t moduleInstance,
211         uint_fast8_t select4PinFunctionality);
212
213 //*****************************************************************************
214 //
215 //! Initializes the SPI Master clock.At the end of this function call, SPI
216 //! module is left enabled.
217 //!
218 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
219 //! parameters vary from part to part, but can include:
220 //!         - \b EUSCI_A0_MODULE
221 //!         - \b EUSCI_A1_MODULE
222 //!         - \b EUSCI_A2_MODULE
223 //!         - \b EUSCI_A3_MODULE
224 //!         - \b EUSCI_B0_MODULE
225 //!         - \b EUSCI_B1_MODULE
226 //!         - \b EUSCI_B2_MODULE
227 //!         - \b EUSCI_B3_MODULE
228 //!
229 //! \param clockSourceFrequency is the frequency of the selected clock source
230 //! \param desiredSpiClock is the desired clock rate for SPI communication.
231 //!
232 //! Modified bits are \b UCSWRST bit of \b UCAxCTLW0 register and
233 //! \b UCAxBRW register
234 //!
235 //! \return None
236 //
237 //*****************************************************************************
238 extern void SPI_changeMasterClock(uint32_t moduleInstance,
239         uint32_t clockSourceFrequency, uint32_t desiredSpiClock);
240
241 //*****************************************************************************
242 //
243 //! Initializes the SPI Slave block.
244 //!
245 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
246 //! parameters vary from part to part, but can include:
247 //!         - \b EUSCI_A0_MODULE
248 //!         - \b EUSCI_A1_MODULE
249 //!         - \b EUSCI_A2_MODULE
250 //!         - \b EUSCI_A3_MODULE
251 //!         - \b EUSCI_B0_MODULE
252 //!         - \b EUSCI_B1_MODULE
253 //!         - \b EUSCI_B2_MODULE
254 //!         - \b EUSCI_B3_MODULE
255 //! \param config Configuration structure for SPI slave mode
256 //!
257 //! <hr>
258 //! <b>Configuration options for \link eUSCI_SPI_SlaveConfig \endlink structure.</b>
259 //! <hr>
260 //!
261 //! \param msbFirst controls the direction of the receive and transmit shift
262 //!      register. Valid values are
263 //!         - \b  EUSCI_SPI_MSB_FIRST
264 //!         - \b  EUSCI_SPI_LSB_FIRST [Default Value]
265 //! \param clockPhase is clock phase select.
266 //!         Valid values are
267 //!         - \b  EUSCI_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
268 //!                                                          [Default Value]
269 //!         - \b  EUSCI_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
270 //! \param clockPolarity is clock polarity select.
271 //!         Valid values are
272 //!         - \b  EUSCI_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
273 //!         - \b  EUSCI_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default Value]
274 //! \param spiMode is SPI mode select.
275 //!         Valid values are
276 //!         - \b  EUSCI_SPI_3PIN [Default Value]
277 //!         - \b  EUSCI_SPI_4PIN_UCxSTE_ACTIVE_HIGH
278 //!         - \b  EUSCI_SPI_4PIN_UCxSTE_ACTIVE_LOW
279 //! Upon successful initialization of the SPI slave block, this function
280 //! will have initialized the slave block, but the SPI Slave block
281 //! still remains disabled and must be enabled with SPI_enableModule()
282 //!
283 //! Modified bits are \b UCMSB, \b UC7BIT, \b UCMST, \b UCCKPL, \b UCCKPH,
284 //! \b UCMODE, \b UCSWRST bits of \b UCAxCTLW0
285 //!
286 //! \return true
287 //*****************************************************************************
288 extern bool SPI_initSlave(uint32_t moduleInstance,
289         const eUSCI_SPI_SlaveConfig *config);
290
291 //*****************************************************************************
292 //
293 //! Changes the SPI clock phase and polarity.At the end of this function call,
294 //! SPI module is left enabled.
295 //!
296 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
297 //! parameters vary from part to part, but can include:
298 //!         - \b EUSCI_A0_MODULE
299 //!         - \b EUSCI_A1_MODULE
300 //!         - \b EUSCI_A2_MODULE
301 //!         - \b EUSCI_A3_MODULE
302 //!         - \b EUSCI_B0_MODULE
303 //!         - \b EUSCI_B1_MODULE
304 //!         - \b EUSCI_B2_MODULE
305 //!         - \b EUSCI_B3_MODULE
306 //!
307 //! \param clockPhase is clock phase select.
308 //!         Valid values are:
309 //!             - \b EUSCI_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
310 //!                                                          [Default Value]
311 //!             - \b EUSCI_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
312 //! \param clockPolarity is clock polarity select.
313 //!         Valid values are:
314 //!             - \b EUSCI_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
315 //!             - \b EUSCI_SPI_CLOCKPOLARITY_INACTIVITY_LOW  [Default Value]
316 //!
317 //! Modified bits are \b UCSWRST, \b UCCKPH, \b UCCKPL, \b UCSWRST bits of
318 //! \b UCAxCTLW0
319 //!
320 //! \return None
321 //
322 //*****************************************************************************
323 extern void SPI_changeClockPhasePolarity(uint32_t moduleInstance,
324         uint_fast16_t clockPhase, uint_fast16_t clockPolarity);
325
326 //*****************************************************************************
327 //
328 //! Transmits a byte from the SPI Module.
329 //!
330 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
331 //! parameters vary from part to part, but can include:
332 //!         - \b EUSCI_A0_MODULE
333 //!         - \b EUSCI_A1_MODULE
334 //!         - \b EUSCI_A2_MODULE
335 //!         - \b EUSCI_A3_MODULE
336 //!         - \b EUSCI_B0_MODULE
337 //!         - \b EUSCI_B1_MODULE
338 //!         - \b EUSCI_B2_MODULE
339 //!         - \b EUSCI_B3_MODULE
340 //!
341 //! \param transmitData data to be transmitted from the SPI module
342 //!
343 //! This function will place the supplied data into SPI transmit data register
344 //! to start transmission
345 //!
346 //! Modified register is \b UCAxTXBUF
347 //!
348 //! \return None.
349 //
350 //*****************************************************************************
351 extern void SPI_transmitData(uint32_t moduleInstance,
352         uint_fast8_t transmitData);
353
354 //*****************************************************************************
355 //
356 //! Receives a byte that has been sent to the SPI Module.
357 //!
358 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
359 //! parameters vary from part to part, but can include:
360 //!         - \b EUSCI_A0_MODULE
361 //!         - \b EUSCI_A1_MODULE
362 //!         - \b EUSCI_A2_MODULE
363 //!         - \b EUSCI_A3_MODULE
364 //!         - \b EUSCI_B0_MODULE
365 //!         - \b EUSCI_B1_MODULE
366 //!         - \b EUSCI_B2_MODULE
367 //!         - \b EUSCI_B3_MODULE
368 //!
369 //!
370 //! This function reads a byte of data from the SPI receive data Register.
371 //!
372 //! \return Returns the byte received from by the SPI module, cast as an
373 //! uint8_t.
374 //
375 //*****************************************************************************
376 extern uint8_t SPI_receiveData(uint32_t moduleInstance);
377
378 //*****************************************************************************
379 //
380 //! Enables the SPI block.
381 //!
382 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
383 //! parameters vary from part to part, but can include:
384 //!         - \b EUSCI_A0_MODULE
385 //!         - \b EUSCI_A1_MODULE
386 //!         - \b EUSCI_A2_MODULE
387 //!         - \b EUSCI_A3_MODULE
388 //!         - \b EUSCI_B0_MODULE
389 //!         - \b EUSCI_B1_MODULE
390 //!         - \b EUSCI_B2_MODULE
391 //!         - \b EUSCI_B3_MODULE
392 //!
393 //!
394 //! This will enable operation of the SPI block.
395 //! Modified bits are \b UCSWRST bit of \b UCAxCTLW0 register.
396 //!
397 //! \return None.
398 //
399 //*****************************************************************************
400 extern void SPI_enableModule(uint32_t moduleInstance);
401
402 //*****************************************************************************
403 //
404 //! Disables the SPI block.
405 //!
406 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
407 //! parameters vary from part to part, but can include:
408 //!         - \b EUSCI_A0_MODULE
409 //!         - \b EUSCI_A1_MODULE
410 //!         - \b EUSCI_A2_MODULE
411 //!         - \b EUSCI_A3_MODULE
412 //!         - \b EUSCI_B0_MODULE
413 //!         - \b EUSCI_B1_MODULE
414 //!         - \b EUSCI_B2_MODULE
415 //!         - \b EUSCI_B3_MODULE
416 //!
417 //!
418 //! This will disable operation of the SPI block.
419 //!
420 //! Modified bits are \b UCSWRST bit of \b UCAxCTLW0 register.
421 //!
422 //! \return None.
423 //
424 //*****************************************************************************
425 extern void SPI_disableModule(uint32_t moduleInstance);
426
427 //*****************************************************************************
428 //
429 //! Returns the address of the RX Buffer of the SPI for the DMA module.
430 //!
431 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
432 //! parameters vary from part to part, but can include:
433 //!         - \b EUSCI_A0_MODULE
434 //!         - \b EUSCI_A1_MODULE
435 //!         - \b EUSCI_A2_MODULE
436 //!         - \b EUSCI_A3_MODULE
437 //!         - \b EUSCI_B0_MODULE
438 //!         - \b EUSCI_B1_MODULE
439 //!         - \b EUSCI_B2_MODULE
440 //!         - \b EUSCI_B3_MODULE
441 //!
442 //!
443 //! Returns the address of the SPI RX Buffer. This can be used in conjunction
444 //! with the DMA to store the received data directly to memory.
445 //!
446 //! \return NONE
447 //
448 //*****************************************************************************
449 extern uint32_t SPI_getReceiveBufferAddressForDMA(uint32_t moduleInstance);
450
451 //*****************************************************************************
452 //
453 //! Returns the address of the TX Buffer of the SPI for the DMA module.
454 //!
455 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
456 //! parameters vary from part to part, but can include:
457 //!         - \b EUSCI_A0_MODULE
458 //!         - \b EUSCI_A1_MODULE
459 //!         - \b EUSCI_A2_MODULE
460 //!         - \b EUSCI_A3_MODULE
461 //!         - \b EUSCI_B0_MODULE
462 //!         - \b EUSCI_B1_MODULE
463 //!         - \b EUSCI_B2_MODULE
464 //!         - \b EUSCI_B3_MODULE
465 //!
466 //!
467 //! Returns the address of the SPI TX Buffer. This can be used in conjunction
468 //! with the DMA to obtain transmitted data directly from memory.
469 //!
470 //! \return NONE
471 //
472 //*****************************************************************************
473 extern uint32_t SPI_getTransmitBufferAddressForDMA(uint32_t moduleInstance);
474
475 //*****************************************************************************
476 //
477 //! Indicates whether or not the SPI bus is busy.
478 //!
479 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
480 //! parameters vary from part to part, but can include:
481 //!         - \b EUSCI_A0_MODULE
482 //!         - \b EUSCI_A1_MODULE
483 //!         - \b EUSCI_A2_MODULE
484 //!         - \b EUSCI_A3_MODULE
485 //!         - \b EUSCI_B0_MODULE
486 //!         - \b EUSCI_B1_MODULE
487 //!         - \b EUSCI_B2_MODULE
488 //!         - \b EUSCI_B3_MODULE
489 //!
490 //!
491 //! This function returns an indication of whether or not the SPI bus is
492 //! busy.This function checks the status of the bus via UCBBUSY bit
493 //!
494 //! \return EUSCI_SPI_BUSY if the SPI module transmitting or receiving
495 //! is busy; otherwise, returns EUSCI_SPI_NOT_BUSY.
496 //
497 //*****************************************************************************
498 extern uint_fast8_t SPI_isBusy(uint32_t moduleInstance);
499
500 //*****************************************************************************
501 //
502 //! Enables individual SPI interrupt sources.
503 //!
504 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
505 //! parameters vary from part to part, but can include:
506 //!         - \b EUSCI_A0_MODULE
507 //!         - \b EUSCI_A1_MODULE
508 //!         - \b EUSCI_A2_MODULE
509 //!         - \b EUSCI_A3_MODULE
510 //!         - \b EUSCI_B0_MODULE
511 //!         - \b EUSCI_B1_MODULE
512 //!         - \b EUSCI_B2_MODULE
513 //!         - \b EUSCI_B3_MODULE
514 //!
515 //! \param mask is the bit mask of the interrupt sources to be enabled.
516 //!
517 //! Enables the indicated SPI interrupt sources.  Only the sources that
518 //! are enabled can be reflected to the processor interrupt; disabled sources
519 //! have no effect on the processor.
520 //!
521 //! The mask parameter is the logical OR of any of the following:
522 //!       - \b EUSCI_SPI_RECEIVE_INTERRUPT Receive interrupt
523 //!       - \b EUSCI_SPI_TRANSMIT_INTERRUPT Transmit interrupt
524 //!
525 //! Modified registers are \b UCAxIFG and \b UCAxIE
526 //!
527 //! \return None.
528 //
529 //*****************************************************************************
530 extern void SPI_enableInterrupt(uint32_t moduleInstance, uint_fast8_t mask);
531
532 //*****************************************************************************
533 //
534 //! Disables individual SPI interrupt sources.
535 //!
536 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
537 //! parameters vary from part to part, but can include:
538 //!         - \b EUSCI_A0_MODULE
539 //!         - \b EUSCI_A1_MODULE
540 //!         - \b EUSCI_A2_MODULE
541 //!         - \b EUSCI_A3_MODULE
542 //!         - \b EUSCI_B0_MODULE
543 //!         - \b EUSCI_B1_MODULE
544 //!         - \b EUSCI_B2_MODULE
545 //!         - \b EUSCI_B3_MODULE
546 //!
547 //! \param mask is the bit mask of the interrupt sources to be
548 //! disabled.
549 //!
550 //! Disables the indicated SPI interrupt sources.  Only the sources that
551 //! are enabled can be reflected to the processor interrupt; disabled sources
552 //! have no effect on the processor.
553 //!
554 //! The mask parameter is the logical OR of any of the following:
555 //!       - \b EUSCI_SPI_RECEIVE_INTERRUPT Receive interrupt
556 //!       - \b EUSCI_SPI_TRANSMIT_INTERRUPT Transmit interrupt
557 //!
558 //! Modified register is \b UCAxIE
559 //!
560 //! \return None.
561 //
562 //*****************************************************************************
563 extern void SPI_disableInterrupt(uint32_t moduleInstance, uint_fast8_t mask);
564
565 //*****************************************************************************
566 //
567 //! Gets the current SPI interrupt status.
568 //!
569 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
570 //! parameters vary from part to part, but can include:
571 //!         - \b EUSCI_A0_MODULE
572 //!         - \b EUSCI_A1_MODULE
573 //!         - \b EUSCI_A2_MODULE
574 //!         - \b EUSCI_A3_MODULE
575 //!         - \b EUSCI_B0_MODULE
576 //!         - \b EUSCI_B1_MODULE
577 //!         - \b EUSCI_B2_MODULE
578 //!         - \b EUSCI_B3_MODULE
579 //! \param mask Mask of interrupt to filter. This can include:
580 //!          - \b EUSCI_SPI_RECEIVE_INTERRUPT -Receive interrupt
581 //!          - \b EUSCI_SPI_TRANSMIT_INTERRUPT - Transmit interrupt
582 //!
583 //! Modified registers are \b UCAxIFG.
584 //!
585 //! \return The current interrupt status as the mask of the set flags
586 //! Mask parameter can be either any of the following selection:
587 //! - \b EUSCI_SPI_RECEIVE_INTERRUPT -Receive interrupt
588 //! - \b EUSCI_SPI_TRANSMIT_INTERRUPT - Transmit interrupt
589 //
590 //*****************************************************************************
591 extern uint_fast8_t SPI_getInterruptStatus(uint32_t moduleInstance,
592         uint16_t mask);
593
594 //*****************************************************************************
595 //
596 //! Gets the current SPI interrupt status masked with the enabled interrupts.
597 //! This function is useful to call in ISRs to get a list of pending
598 //! interrupts that are actually enabled and could have caused
599 //! the ISR.
600 //!
601 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
602 //! parameters vary from part to part, but can include:
603 //!         - \b EUSCI_A0_MODULE
604 //!         - \b EUSCI_A1_MODULE
605 //!         - \b EUSCI_A2_MODULE
606 //!         - \b EUSCI_A3_MODULE
607 //!         - \b EUSCI_B0_MODULE
608 //!         - \b EUSCI_B1_MODULE
609 //!         - \b EUSCI_B2_MODULE
610 //!         - \b EUSCI_B3_MODULE
611 //!
612 //! Modified registers are \b UCAxIFG.
613 //!
614 //! \return The current interrupt status as the mask of the set flags
615 //! Mask parameter can be either any of the following selection:
616 //! - \b EUSCI_SPI_RECEIVE_INTERRUPT -Receive interrupt
617 //! - \b EUSCI_SPI_TRANSMIT_INTERRUPT - Transmit interrupt
618 //
619 //*****************************************************************************
620 extern uint_fast8_t SPI_getEnabledInterruptStatus(uint32_t moduleInstance);
621
622 //*****************************************************************************
623 //
624 //! Clears the selected SPI interrupt status flag.
625 //!
626 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
627 //! parameters vary from part to part, but can include:
628 //!         - \b EUSCI_A0_MODULE
629 //!         - \b EUSCI_A1_MODULE
630 //!         - \b EUSCI_A2_MODULE
631 //!         - \b EUSCI_A3_MODULE
632 //!         - \b EUSCI_B0_MODULE
633 //!         - \b EUSCI_B1_MODULE
634 //!         - \b EUSCI_B2_MODULE
635 //!         - \b EUSCI_B3_MODULE
636 //!
637 //! \param mask is the masked interrupt flag to be cleared.
638 //!
639 //! The mask parameter is the logical OR of any of the following:
640 //! - \b EUSCI_SPI_RECEIVE_INTERRUPT -Receive interrupt
641 //! - \b EUSCI_SPI_TRANSMIT_INTERRUPT - Transmit interrupt
642 //! Modified registers are \b UCAxIFG.
643 //!
644 //! \return None
645 //
646 //*****************************************************************************
647 extern void SPI_clearInterruptFlag(uint32_t moduleInstance, uint_fast8_t mask);
648
649 //*****************************************************************************
650 //
651 //! Registers an interrupt handler for the timer capture compare interrupt.
652 //!
653 //! \param moduleInstance is the instance of the eUSCI (SPI) module. Valid
654 //! parameters vary from part to part, but can include:
655 //!         - \b EUSCI_A0_MODULE
656 //!         - \b EUSCI_A1_MODULE
657 //!         - \b EUSCI_A2_MODULE
658 //!         - \b EUSCI_A3_MODULE
659 //!         - \b EUSCI_B0_MODULE
660 //!         - \b EUSCI_B1_MODULE
661 //!         - \b EUSCI_B2_MODULE
662 //!         - \b EUSCI_B3_MODULE
663 //!  It is important to note that for eUSCI modules, only "B" modules such as
664 //!  EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the
665 //!  I2C mode.
666 //!
667 //! \param intHandler is a pointer to the function to be called when the
668 //! timer capture compare interrupt occurs.
669 //!
670 //! This function registers the handler to be called when a timer
671 //! interrupt occurs. This function enables the global interrupt in the
672 //! interrupt controller; specific SPI interrupts must be enabled
673 //! via SPI_enableInterrupt().  It is the interrupt handler's responsibility to
674 //! clear the interrupt source via SPI_clearInterruptFlag().
675 //!
676 //! \return None.
677 //
678 //*****************************************************************************
679 extern void SPI_registerInterrupt(uint32_t moduleInstance,
680         void (*intHandler)(void));
681
682 //*****************************************************************************
683 //
684 //! Unregisters the interrupt handler for the timer
685 //!
686 //! \param moduleInstance is the instance of the eUSCI A/B module. Valid
687 //! parameters vary from part to part, but can include:
688 //!         - \b EUSCI_A0_MODULE
689 //!         - \b EUSCI_A1_MODULE
690 //!         - \b EUSCI_A2_MODULE
691 //!         - \b EUSCI_A3_MODULE
692 //!         - \b EUSCI_B0_MODULE
693 //!         - \b EUSCI_B1_MODULE
694 //!         - \b EUSCI_B2_MODULE
695 //!         - \b EUSCI_B3_MODULE
696 //!
697 //! This function unregisters the handler to be called when timer
698 //! interrupt occurs.  This function also masks off the interrupt in the
699 //! interrupt controller so that the interrupt handler no longer is called.
700 //!
701 //! \sa Interrupt_registerInterrupt() for important information about
702 //! registering interrupt handlers.
703 //!
704 //! \return None.
705 //
706 //*****************************************************************************
707 extern void SPI_unregisterInterrupt(uint32_t moduleInstance);
708
709 /* Backwards Compatibility Layer */
710 #define EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT            0x00
711 #define EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT          UCCKPH
712
713 #define EUSCI_B_SPI_MSB_FIRST                                             UCMSB
714 #define EUSCI_B_SPI_LSB_FIRST                                              0x00
715
716 #define EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH                        UCCKPL
717 #define EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW                           0x00
718
719 #define EUSCI_B_SPI_CLOCKSOURCE_ACLK                               UCSSEL__ACLK
720 #define EUSCI_B_SPI_CLOCKSOURCE_SMCLK                             UCSSEL__SMCLK
721
722 #define EUSCI_B_SPI_3PIN                                               UCMODE_0
723 #define EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_HIGH                            UCMODE_1
724 #define EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_LOW                             UCMODE_2
725
726 #define EUSCI_B_SPI_PREVENT_CONFLICTS_WITH_OTHER_MASTERS                   0x00
727 #define EUSCI_B_SPI_ENABLE_SIGNAL_FOR_4WIRE_SLAVE                        UCSTEM
728
729 #define EUSCI_B_SPI_TRANSMIT_INTERRUPT                                   UCTXIE
730 #define EUSCI_B_SPI_RECEIVE_INTERRUPT                                    UCRXIE
731
732 #define EUSCI_B_SPI_BUSY                                                 UCBUSY
733 #define EUSCI_B_SPI_NOT_BUSY                                               0x00
734
735 #define EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT            0x00
736 #define EUSCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT          UCCKPH
737
738 #define EUSCI_A_SPI_MSB_FIRST                                             UCMSB
739 #define EUSCI_A_SPI_LSB_FIRST                                              0x00
740
741 #define EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH                        UCCKPL
742 #define EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW                           0x00
743
744 #define EUSCI_A_SPI_CLOCKSOURCE_ACLK                               UCSSEL__ACLK
745 #define EUSCI_A_SPI_CLOCKSOURCE_SMCLK                             UCSSEL__SMCLK
746
747 #define EUSCI_A_SPI_3PIN                                               UCMODE_0
748 #define EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_HIGH                            UCMODE_1
749 #define EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_LOW                             UCMODE_2
750
751 #define EUSCI_A_SPI_PREVENT_CONFLICTS_WITH_OTHER_MASTERS                   0x00
752 #define EUSCI_A_SPI_ENABLE_SIGNAL_FOR_4WIRE_SLAVE                        UCSTEM
753
754 #define EUSCI_A_SPI_TRANSMIT_INTERRUPT                                   UCTXIE
755 #define EUSCI_A_SPI_RECEIVE_INTERRUPT                                    UCRXIE
756
757 #define EUSCI_A_SPI_BUSY                                                 UCBUSY
758 #define EUSCI_A_SPI_NOT_BUSY                                               0x00
759
760 extern void EUSCI_A_SPI_select4PinFunctionality(uint32_t baseAddress,
761         uint8_t select4PinFunctionality);
762 extern void EUSCI_A_SPI_masterChangeClock(uint32_t baseAddress,
763         uint32_t clockSourceFrequency, uint32_t desiredSpiClock);
764 extern bool EUSCI_A_SPI_slaveInit(uint32_t baseAddress, uint16_t msbFirst,
765         uint16_t clockPhase, uint16_t clockPolarity, uint16_t spiMode);
766 extern void EUSCI_A_SPI_changeClockPhasePolarity(uint32_t baseAddress,
767         uint16_t clockPhase, uint16_t clockPolarity);
768 extern void EUSCI_A_SPI_transmitData(uint32_t baseAddress,
769         uint8_t transmitData);
770 extern uint8_t EUSCI_A_SPI_receiveData(uint32_t baseAddress);
771 extern void EUSCI_A_SPI_enableInterrupt(uint32_t baseAddress, uint8_t mask);
772 extern void EUSCI_A_SPI_disableInterrupt(uint32_t baseAddress, uint8_t mask);
773 extern uint8_t EUSCI_A_SPI_getInterruptStatus(uint32_t baseAddress,
774         uint8_t mask);
775 extern void EUSCI_A_SPI_clearInterruptFlag(uint32_t baseAddress, uint8_t mask);
776 extern void EUSCI_A_SPI_enable(uint32_t baseAddress);
777 extern void EUSCI_A_SPI_disable(uint32_t baseAddress);
778 extern uint32_t EUSCI_A_SPI_getReceiveBufferAddressForDMA(uint32_t baseAddress);
779 extern uint32_t EUSCI_A_SPI_getTransmitBufferAddressForDMA(
780         uint32_t baseAddress);
781 extern bool EUSCI_A_SPI_isBusy(uint32_t baseAddress);
782 extern void EUSCI_B_SPI_select4PinFunctionality(uint32_t baseAddress,
783         uint8_t select4PinFunctionality);
784 extern void EUSCI_B_SPI_masterChangeClock(uint32_t baseAddress,
785         uint32_t clockSourceFrequency, uint32_t desiredSpiClock);
786 extern bool EUSCI_B_SPI_slaveInit(uint32_t baseAddress, uint16_t msbFirst,
787         uint16_t clockPhase, uint16_t clockPolarity, uint16_t spiMode);
788 extern void EUSCI_B_SPI_changeClockPhasePolarity(uint32_t baseAddress,
789         uint16_t clockPhase, uint16_t clockPolarity);
790 extern void EUSCI_B_SPI_transmitData(uint32_t baseAddress,
791         uint8_t transmitData);
792 extern uint8_t EUSCI_B_SPI_receiveData(uint32_t baseAddress);
793 extern void EUSCI_B_SPI_enableInterrupt(uint32_t baseAddress, uint8_t mask);
794 extern void EUSCI_B_SPI_disableInterrupt(uint32_t baseAddress, uint8_t mask);
795 extern uint8_t EUSCI_B_SPI_getInterruptStatus(uint32_t baseAddress,
796         uint8_t mask);
797 extern void EUSCI_B_SPI_clearInterruptFlag(uint32_t baseAddress, uint8_t mask);
798 extern void EUSCI_B_SPI_enable(uint32_t baseAddress);
799 extern void EUSCI_B_SPI_disable(uint32_t baseAddress);
800 extern uint32_t EUSCI_B_SPI_getReceiveBufferAddressForDMA(uint32_t baseAddress);
801 extern uint32_t EUSCI_B_SPI_getTransmitBufferAddressForDMA(
802         uint32_t baseAddress);
803 extern bool EUSCI_B_SPI_isBusy(uint32_t baseAddress);
804
805 //*****************************************************************************
806 //
807 // Mark the end of the C bindings section for C++ compilers.
808 //
809 //*****************************************************************************
810 #ifdef __cplusplus
811 }
812 #endif
813
814 //*****************************************************************************
815 //
816 // Close the Doxygen group.
817 //! @}
818 //
819 //*****************************************************************************
820
821 #endif /* SPI_H_ */
822