CC26xx Driver Library
ssi.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: ssi.h
3 * Revised: 2015-07-16 12:12:04 +0200 (Thu, 16 Jul 2015)
4 * Revision: 44151
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 //
555 //
556 //*****************************************************************************
557 __STATIC_INLINE void
558 SSIIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
559 {
560  //
561  // Check the arguments.
562  //
563  ASSERT(SSIBaseValid(ui32Base));
564 
565  //
566  // Clear the requested interrupt sources.
567  //
568  HWREG(ui32Base + SSI_O_ICR) = ui32IntFlags;
569 }
570 
571 //*****************************************************************************
572 //
589 //
590 //*****************************************************************************
591 __STATIC_INLINE uint32_t
592 SSIIntStatus(uint32_t ui32Base, bool bMasked)
593 {
594  //
595  // Check the arguments.
596  //
597  ASSERT(SSIBaseValid(ui32Base));
598 
599  //
600  // Return either the interrupt status or the raw interrupt status as
601  // requested.
602  //
603  if(bMasked)
604  {
605  return(HWREG(ui32Base + SSI_O_MIS));
606  }
607  else
608  {
609  return(HWREG(ui32Base + SSI_O_RIS));
610  }
611 }
612 
613 //*****************************************************************************
614 //
630 //
631 //*****************************************************************************
632 __STATIC_INLINE void
633 SSIDMAEnable(uint32_t ui32Base, uint32_t ui32DMAFlags)
634 {
635  //
636  // Check the arguments.
637  //
638  ASSERT(SSIBaseValid(ui32Base));
639 
640  //
641  // Set the requested bits in the SSI DMA control register.
642  //
643  HWREG(ui32Base + SSI_O_DMACR) |= ui32DMAFlags;
644 }
645 
646 //*****************************************************************************
647 //
660 //
661 //*****************************************************************************
662 __STATIC_INLINE void
663 SSIDMADisable(uint32_t ui32Base, uint32_t ui32DMAFlags)
664 {
665  //
666  // Check the arguments.
667  //
668  ASSERT(SSIBaseValid(ui32Base));
669 
670  //
671  // Clear the requested bits in the SSI DMA control register.
672  //
673  HWREG(ui32Base + SSI_O_DMACR) &= ~ui32DMAFlags;
674 }
675 
676 //*****************************************************************************
677 //
678 // Support for DriverLib in ROM:
679 // Redirect to implementation in ROM when available.
680 //
681 //*****************************************************************************
682 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
683  #include <driverlib/rom.h>
684  #ifdef ROM_SSIConfigSetExpClk
685  #undef SSIConfigSetExpClk
686  #define SSIConfigSetExpClk ROM_SSIConfigSetExpClk
687  #endif
688  #ifdef ROM_SSIDataPut
689  #undef SSIDataPut
690  #define SSIDataPut ROM_SSIDataPut
691  #endif
692  #ifdef ROM_SSIDataPutNonBlocking
693  #undef SSIDataPutNonBlocking
694  #define SSIDataPutNonBlocking ROM_SSIDataPutNonBlocking
695  #endif
696  #ifdef ROM_SSIDataGet
697  #undef SSIDataGet
698  #define SSIDataGet ROM_SSIDataGet
699  #endif
700  #ifdef ROM_SSIDataGetNonBlocking
701  #undef SSIDataGetNonBlocking
702  #define SSIDataGetNonBlocking ROM_SSIDataGetNonBlocking
703  #endif
704  #ifdef ROM_SSIIntRegister
705  #undef SSIIntRegister
706  #define SSIIntRegister ROM_SSIIntRegister
707  #endif
708  #ifdef ROM_SSIIntUnregister
709  #undef SSIIntUnregister
710  #define SSIIntUnregister ROM_SSIIntUnregister
711  #endif
712 #endif
713 
714 //*****************************************************************************
715 //
716 // Mark the end of the C bindings section for C++ compilers.
717 //
718 //*****************************************************************************
719 #ifdef __cplusplus
720 }
721 #endif
722 
723 #endif // __SSI_H__
724 
725 //*****************************************************************************
726 //
730 //
731 //*****************************************************************************
static void SSIIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
Clears SSI interrupt sources.
Definition: ssi.h:558
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:633
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:592
#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:663
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