CC13xx Driver Library
ssi.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: ssi.h
3 * Revised: 2015-09-21 15:19:36 +0200 (Mon, 21 Sep 2015)
4 * Revision: 44629
5 *
6 * Description: Defines and macros for the SSI.
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * 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, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 #ifndef __SSI_H__
49 #define __SSI_H__
50 
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inc/hw_ints.h>
65 #include <inc/hw_memmap.h>
66 #include <inc/hw_types.h>
67 #include <inc/hw_ssi.h>
68 #include <driverlib/debug.h>
69 #include <driverlib/interrupt.h>
70 
71 //*****************************************************************************
72 //
73 // Support for DriverLib in ROM:
74 // This section renames all functions that are not "static inline", so that
75 // calling these functions will default to implementation in flash. At the end
76 // of this file a second renaming will change the defaults to implementation in
77 // ROM for available functions.
78 //
79 // To force use of the implementation in flash, e.g. for debugging:
80 // - Globally: Define DRIVERLIB_NOROM at project level
81 // - Per function: Use prefix "NOROM_" when calling the function
82 //
83 //*****************************************************************************
84 #if !defined(DOXYGEN)
85  #define SSIConfigSetExpClk NOROM_SSIConfigSetExpClk
86  #define SSIDataPut NOROM_SSIDataPut
87  #define SSIDataPutNonBlocking NOROM_SSIDataPutNonBlocking
88  #define SSIDataGet NOROM_SSIDataGet
89  #define SSIDataGetNonBlocking NOROM_SSIDataGetNonBlocking
90  #define SSIIntRegister NOROM_SSIIntRegister
91  #define SSIIntUnregister NOROM_SSIIntUnregister
92 #endif
93 
94 //*****************************************************************************
95 //
96 // Values that can be passed to SSIIntEnable, SSIIntDisable, and SSIIntClear
97 // as the ui32IntFlags parameter, and returned by SSIIntStatus.
98 //
99 //*****************************************************************************
100 #define SSI_TXFF 0x00000008 // TX FIFO half full or less
101 #define SSI_RXFF 0x00000004 // RX FIFO half full or more
102 #define SSI_RXTO 0x00000002 // RX timeout
103 #define SSI_RXOR 0x00000001 // RX overrun
104 
105 //*****************************************************************************
106 //
107 // Values that are returned from SSIStatus
108 //
109 //*****************************************************************************
110 #define SSI_RX_FULL 0x00000008 // Receive FIFO full
111 #define SSI_RX_NOT_EMPTY 0x00000004 // Receive FIFO not empty
112 #define SSI_TX_NOT_FULL 0x00000002 // Transmit FIFO not full
113 #define SSI_TX_EMPTY 0x00000001 // Transmit FIFO empty
114 #define SSI_STATUS_MASK 0x0000000F
115 
116 //*****************************************************************************
117 //
118 // Values that can be passed to SSIConfigSetExpClk.
119 //
120 //*****************************************************************************
121 #define SSI_FRF_MOTO_MODE_0 0x00000000 // Moto fmt, polarity 0, phase 0
122 #define SSI_FRF_MOTO_MODE_1 0x00000002 // Moto fmt, polarity 0, phase 1
123 #define SSI_FRF_MOTO_MODE_2 0x00000001 // Moto fmt, polarity 1, phase 0
124 #define SSI_FRF_MOTO_MODE_3 0x00000003 // Moto fmt, polarity 1, phase 1
125 #define SSI_FRF_TI 0x00000010 // TI frame format
126 #define SSI_FRF_NMW 0x00000020 // National MicroWire frame format
127 
128 #define SSI_MODE_MASTER 0x00000000 // SSI master
129 #define SSI_MODE_SLAVE 0x00000001 // SSI slave
130 #define SSI_MODE_SLAVE_OD 0x00000002 // SSI slave with output disabled
131 
132 //*****************************************************************************
133 //
134 // Values that can be passed to SSIDMAEnable() and SSIDMADisable().
135 //
136 //*****************************************************************************
137 #define SSI_DMA_TX 0x00000002 // Enable DMA for transmit
138 #define SSI_DMA_RX 0x00000001 // Enable DMA for receive
139 
140 //*****************************************************************************
141 //
142 // API Functions and prototypes
143 //
144 //*****************************************************************************
145 
146 #ifdef DRIVERLIB_DEBUG
147 //*****************************************************************************
148 //
159 //
160 //*****************************************************************************
161 static bool
162 SSIBaseValid(uint32_t ui32Base)
163 {
164  return(ui32Base == SSI0_BASE || ui32Base == SSI1_BASE);
165 }
166 #endif
167 
168 //*****************************************************************************
169 //
223 //
224 //*****************************************************************************
225 extern void SSIConfigSetExpClk(uint32_t ui32Base, uint32_t ui32SSIClk,
226  uint32_t ui32Protocol, uint32_t ui32Mode,
227  uint32_t ui32BitRate, uint32_t ui32DataWidth);
228 
229 //*****************************************************************************
230 //
239 //
240 //*****************************************************************************
241 __STATIC_INLINE void
242 SSIEnable(uint32_t ui32Base)
243 {
244  //
245  // Check the arguments.
246  //
247  ASSERT(SSIBaseValid(ui32Base));
248 
249  //
250  // Read-modify-write the enable bit.
251  //
252  HWREG(ui32Base + SSI_O_CR1) |= SSI_CR1_SSE;
253 }
254 
255 //*****************************************************************************
256 //
264 //
265 //*****************************************************************************
266 __STATIC_INLINE void
267 SSIDisable(uint32_t ui32Base)
268 {
269  //
270  // Check the arguments.
271  //
272  ASSERT(SSIBaseValid(ui32Base));
273 
274  //
275  // Read-modify-write the enable bit.
276  //
277  HWREG(ui32Base + SSI_O_CR1) &= ~(SSI_CR1_SSE);
278 }
279 
280 //*****************************************************************************
281 //
296 //
297 //*****************************************************************************
298 extern void SSIDataPut(uint32_t ui32Base, uint32_t ui32Data);
299 
300 //*****************************************************************************
301 //
317 //
318 //*****************************************************************************
319 extern int32_t SSIDataPutNonBlocking(uint32_t ui32Base, uint32_t ui32Data);
320 
321 //*****************************************************************************
322 //
340 //
341 //*****************************************************************************
342 extern void SSIDataGet(uint32_t ui32Base, uint32_t *pui32Data);
343 
344 //*****************************************************************************
345 //
364 //
365 //*****************************************************************************
366 extern int32_t SSIDataGetNonBlocking(uint32_t ui32Base, uint32_t *pui32Data);
367 
368 //*****************************************************************************
369 //
382 //
383 //*****************************************************************************
384 __STATIC_INLINE bool
385 SSIBusy(uint32_t ui32Base)
386 {
387  //
388  // Check the arguments.
389  //
390  ASSERT(SSIBaseValid(ui32Base));
391 
392  //
393  // Determine if the SSI is busy.
394  //
395  return((HWREG(ui32Base + SSI_O_SR) & SSI_SR_BSY) ? true : false);
396 }
397 
398 //*****************************************************************************
399 //
413 //
414 //*****************************************************************************
415 __STATIC_INLINE uint32_t
416 SSIStatus(uint32_t ui32Base)
417 {
418  //
419  // Check the arguments.
420  //
421  ASSERT(SSIBaseValid(ui32Base));
422 
423  //
424  // Return the status
425  //
426  return (HWREG(ui32Base + SSI_O_SR) & SSI_STATUS_MASK);
427 }
428 
429 //*****************************************************************************
430 //
447 //
448 //*****************************************************************************
449 extern void SSIIntRegister(uint32_t ui32Base, void (*pfnHandler)(void));
450 
451 //*****************************************************************************
452 //
465 //
466 //*****************************************************************************
467 extern void SSIIntUnregister(uint32_t ui32Base);
468 
469 //*****************************************************************************
470 //
485 //
486 //*****************************************************************************
487 __STATIC_INLINE void
488 SSIIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
489 {
490  //
491  // Check the arguments.
492  //
493  ASSERT(SSIBaseValid(ui32Base));
494 
495  //
496  // Enable the specified interrupts.
497  //
498  HWREG(ui32Base + SSI_O_IMSC) |= ui32IntFlags;
499 }
500 
501 //*****************************************************************************
502 //
515 //
516 //*****************************************************************************
517 __STATIC_INLINE void
518 SSIIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
519 {
520  //
521  // Check the arguments.
522  //
523  ASSERT(SSIBaseValid(ui32Base));
524 
525  //
526  // Disable the specified interrupts.
527  //
528  HWREG(ui32Base + SSI_O_IMSC) &= ~(ui32IntFlags);
529 }
530 
531 //*****************************************************************************
532 //
561 //
562 //*****************************************************************************
563 __STATIC_INLINE void
564 SSIIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
565 {
566  //
567  // Check the arguments.
568  //
569  ASSERT(SSIBaseValid(ui32Base));
570 
571  //
572  // Clear the requested interrupt sources.
573  //
574  HWREG(ui32Base + SSI_O_ICR) = ui32IntFlags;
575 }
576 
577 //*****************************************************************************
578 //
595 //
596 //*****************************************************************************
597 __STATIC_INLINE uint32_t
598 SSIIntStatus(uint32_t ui32Base, bool bMasked)
599 {
600  //
601  // Check the arguments.
602  //
603  ASSERT(SSIBaseValid(ui32Base));
604 
605  //
606  // Return either the interrupt status or the raw interrupt status as
607  // requested.
608  //
609  if(bMasked)
610  {
611  return(HWREG(ui32Base + SSI_O_MIS));
612  }
613  else
614  {
615  return(HWREG(ui32Base + SSI_O_RIS));
616  }
617 }
618 
619 //*****************************************************************************
620 //
636 //
637 //*****************************************************************************
638 __STATIC_INLINE void
639 SSIDMAEnable(uint32_t ui32Base, uint32_t ui32DMAFlags)
640 {
641  //
642  // Check the arguments.
643  //
644  ASSERT(SSIBaseValid(ui32Base));
645 
646  //
647  // Set the requested bits in the SSI DMA control register.
648  //
649  HWREG(ui32Base + SSI_O_DMACR) |= ui32DMAFlags;
650 }
651 
652 //*****************************************************************************
653 //
666 //
667 //*****************************************************************************
668 __STATIC_INLINE void
669 SSIDMADisable(uint32_t ui32Base, uint32_t ui32DMAFlags)
670 {
671  //
672  // Check the arguments.
673  //
674  ASSERT(SSIBaseValid(ui32Base));
675 
676  //
677  // Clear the requested bits in the SSI DMA control register.
678  //
679  HWREG(ui32Base + SSI_O_DMACR) &= ~ui32DMAFlags;
680 }
681 
682 //*****************************************************************************
683 //
684 // Support for DriverLib in ROM:
685 // Redirect to implementation in ROM when available.
686 //
687 //*****************************************************************************
688 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
689  #include <driverlib/rom.h>
690  #ifdef ROM_SSIConfigSetExpClk
691  #undef SSIConfigSetExpClk
692  #define SSIConfigSetExpClk ROM_SSIConfigSetExpClk
693  #endif
694  #ifdef ROM_SSIDataPut
695  #undef SSIDataPut
696  #define SSIDataPut ROM_SSIDataPut
697  #endif
698  #ifdef ROM_SSIDataPutNonBlocking
699  #undef SSIDataPutNonBlocking
700  #define SSIDataPutNonBlocking ROM_SSIDataPutNonBlocking
701  #endif
702  #ifdef ROM_SSIDataGet
703  #undef SSIDataGet
704  #define SSIDataGet ROM_SSIDataGet
705  #endif
706  #ifdef ROM_SSIDataGetNonBlocking
707  #undef SSIDataGetNonBlocking
708  #define SSIDataGetNonBlocking ROM_SSIDataGetNonBlocking
709  #endif
710  #ifdef ROM_SSIIntRegister
711  #undef SSIIntRegister
712  #define SSIIntRegister ROM_SSIIntRegister
713  #endif
714  #ifdef ROM_SSIIntUnregister
715  #undef SSIIntUnregister
716  #define SSIIntUnregister ROM_SSIIntUnregister
717  #endif
718 #endif
719 
720 //*****************************************************************************
721 //
722 // Mark the end of the C bindings section for C++ compilers.
723 //
724 //*****************************************************************************
725 #ifdef __cplusplus
726 }
727 #endif
728 
729 #endif // __SSI_H__
730 
731 //*****************************************************************************
732 //
736 //
737 //*****************************************************************************
static void SSIIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
Clears SSI interrupt sources.
Definition: ssi.h:564
static void SSIIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
Enables individual SSI interrupt sources.
Definition: ssi.h:488
void SSIDataGet(uint32_t ui32Base, uint32_t *pui32Data)
Gets a data element from the SSI receive FIFO.
Definition: ssi.c:191
static void SSIDMAEnable(uint32_t ui32Base, uint32_t ui32DMAFlags)
Enable SSI DMA operation.
Definition: ssi.h:639
int32_t SSIDataPutNonBlocking(uint32_t ui32Base, uint32_t ui32Data)
Puts a data element into the SSI transmit FIFO.
Definition: ssi.c:133
static uint32_t SSIIntStatus(uint32_t ui32Base, bool bMasked)
Gets the current interrupt status.
Definition: ssi.h:598
#define ASSERT(expr)
Definition: debug.h:74
static uint32_t SSIStatus(uint32_t ui32Base)
Get the status of the SSI data buffers.
Definition: ssi.h:416
int32_t SSIDataGetNonBlocking(uint32_t ui32Base, uint32_t *pui32Data)
Gets a data element from the SSI receive FIFO.
Definition: ssi.c:234
void SSIDataPut(uint32_t ui32Base, uint32_t ui32Data)
Puts a data element into the SSI transmit FIFO.
Definition: ssi.c:163
void SSIIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
Registers an interrupt handler for the synchronous serial port.
Definition: ssi.c:276
static void SSIIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
Disables individual SSI interrupt sources.
Definition: ssi.h:518
static void SSIDMADisable(uint32_t ui32Base, uint32_t ui32DMAFlags)
Disable SSI DMA operation.
Definition: ssi.h:669
void SSIIntUnregister(uint32_t ui32Base)
Unregisters an interrupt handler for the synchronous serial port.
Definition: ssi.c:318
static bool SSIBusy(uint32_t ui32Base)
Determines whether the SSI transmitter is busy or not.
Definition: ssi.h:385
static void SSIDisable(uint32_t ui32Base)
Disables the synchronous serial port.
Definition: ssi.h:267
static void SSIEnable(uint32_t ui32Base)
Enables the synchronous serial port.
Definition: ssi.h:242
void SSIConfigSetExpClk(uint32_t ui32Base, uint32_t ui32SSIClk, uint32_t ui32Protocol, uint32_t ui32Mode, uint32_t ui32BitRate, uint32_t ui32DataWidth)
Configures the synchronous serial port.
Definition: ssi.c:70
#define SSI_STATUS_MASK
Definition: ssi.h:114