libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
ssp.h
Go to the documentation of this file.
1/** @defgroup ssp_defines Synchronous Serial Port
2
3@brief <b>Defined Constants and Types for the LPC43xx Synchronous Serial
4Port</b>
5
6@ingroup LPC43xx_defines
7
8@version 1.0.0
9
10@author @htmlonly &copy; @endhtmlonly 2012 Michael Ossmann <mike@ossmann.com>
11
12@date 10 March 2013
13
14LGPL License Terms @ref lgpl_license
15 */
16/*
17* This file is part of the libopencm3 project.
18*
19* Copyright (C) 2012 Michael Ossmann <mike@ossmann.com>
20*
21* This library is free software: you can redistribute it and/or modify
22* it under the terms of the GNU Lesser General Public License as published by
23* the Free Software Foundation, either version 3 of the License, or
24* (at your option) any later version.
25*
26* This library is distributed in the hope that it will be useful,
27* but WITHOUT ANY WARRANTY; without even the implied warranty of
28* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29* GNU Lesser General Public License for more details.
30*
31* You should have received a copy of the GNU Lesser General Public License
32* along with this library. If not, see <http://www.gnu.org/licenses/>.
33*/
34
35#ifndef LPC43XX_SSP_H
36#define LPC43XX_SSP_H
37
38/**@{*/
39
42
43/* --- Convenience macros -------------------------------------------------- */
44
45/* SSP port base addresses (for convenience) */
46#define SSP0 SSP0_BASE
47#define SSP1 SSP1_BASE
48
49
50/* --- SSP registers ------------------------------------------------------- */
51
52/* Control Register 0 */
53#define SSP_CR0(port) MMIO32((port) + 0x000)
54#define SSP0_CR0 SSP_CR0(SSP0)
55#define SSP1_CR0 SSP_CR0(SSP1)
56
57/* Control Register 1 */
58#define SSP_CR1(port) MMIO32((port) + 0x004)
59#define SSP0_CR1 SSP_CR1(SSP0)
60#define SSP1_CR1 SSP_CR1(SSP1)
61
62/* Data Register */
63#define SSP_DR(port) MMIO32((port) + 0x008)
64#define SSP0_DR SSP_DR(SSP0)
65#define SSP1_DR SSP_DR(SSP1)
66
67/* Status Register */
68#define SSP_SR(port) MMIO32((port) + 0x00C)
69#define SSP0_SR SSP_SR(SSP0)
70#define SSP1_SR SSP_SR(SSP1)
71
72#define SSP_SR_TFE BIT0
73#define SSP_SR_TNF BIT1
74#define SSP_SR_RNE BIT2
75#define SSP_SR_RFF BIT3
76#define SSP_SR_BSY BIT4
77
78/* Clock Prescale Register */
79#define SSP_CPSR(port) MMIO32((port) + 0x010)
80#define SSP0_CPSR SSP_CPSR(SSP0)
81#define SSP1_CPSR SSP_CPSR(SSP1)
82
83/* Interrupt Mask Set and Clear Register */
84#define SSP_IMSC(port) MMIO32((port) + 0x014)
85#define SSP0_IMSC SSP_IMSC(SSP0)
86#define SSP1_IMSC SSP_IMSC(SSP1)
87
88/* Raw Interrupt Status Register */
89#define SSP_RIS(port) MMIO32((port) + 0x018)
90#define SSP0_RIS SSP_RIS(SSP0)
91#define SSP1_RIS SSP_RIS(SSP1)
92
93/* Masked Interrupt Status Register */
94#define SSP_MIS(port) MMIO32((port) + 0x01C)
95#define SSP0_MIS SSP_MIS(SSP0)
96#define SSP1_MIS SSP_MIS(SSP1)
97
98/* SSPICR Interrupt Clear Register */
99#define SSP_ICR(port) MMIO32((port) + 0x020)
100#define SSP0_ICR SSP_ICR(SSP0)
101#define SSP1_ICR SSP_ICR(SSP1)
102
103/* SSP1 DMA control register */
104#define SSP_DMACR(port) MMIO32((port) + 0x024)
105#define SSP0_DMACR SSP_DMACR(SSP0)
106#define SSP1_DMACR SSP_DMACR(SSP1)
107
108/* RXDMAE: Receive DMA enable */
109#define SSP_DMACR_RXDMAE 0x1
110
111/* RXDMAE: Transmit DMA enable */
112#define SSP_DMACR_TXDMAE 0x2
113
114typedef enum {
115 SSP0_NUM = 0x0,
116 SSP1_NUM = 0x1
118
119/*
120 * SSP Control Register 0
121 */
122/* SSP Data Size Bits 0 to 3 */
123typedef enum {
136 SSP_DATA_16BITS = 0xF
138
139/* SSP Frame Format/Type Bits 4 & 5 */
140typedef enum {
145
146/* Clock Out Polarity / Clock Out Phase Bits Bits 6 & 7 */
147typedef enum {
153
154/*
155 * SSP Control Register 1
156 */
157/* SSP Mode Bit0 */
158typedef enum {
162
163/* SSP Enable Bit1 */
164#define SSP_ENABLE BIT1
165
166/* SSP Master/Slave Mode Bit2 */
167typedef enum {
171
172/*
173* SSP Slave Output Disable Bit3
174* Slave Output Disable. This bit is relevant only in slave mode
175* (MS = 1). If it is 1, this blocks this SSP controller from driving the
176* transmit data line (MISO).
177*/
178typedef enum {
181} ssp_slave_option_t; /* This option is relevant only in slave mode */
182
184
185void ssp_disable(ssp_num_t ssp_num);
186
187/*
188 * SSP Init
189 * clk_prescale shall be in range 2 to 254 (even number only).
190 * Clock computation: PCLK / (CPSDVSR * [SCR+1]) => CPSDVSR=clk_prescale,
191 * SCR=serial_clock_rate
192 */
193void ssp_init(ssp_num_t ssp_num,
194 ssp_datasize_t data_size,
195 ssp_frame_format_t frame_format,
196 ssp_cpol_cpha_t cpol_cpha_format,
197 uint8_t serial_clock_rate,
198 uint8_t clk_prescale,
199 ssp_mode_t mode,
200 ssp_master_slave_t master_slave,
201 ssp_slave_option_t slave_option);
202
203uint16_t ssp_transfer(ssp_num_t ssp_num, uint16_t data);
204
206
207/**@}*/
208
209#endif
#define END_DECLS
Definition: common.h:34
#define BIT3
Definition: common.h:84
#define BIT2
Definition: common.h:83
#define BIT7
Definition: common.h:88
#define BIT4
Definition: common.h:85
#define BIT6
Definition: common.h:87
#define BEGIN_DECLS
Definition: common.h:33
#define BIT0
Definition: common.h:81
#define BIT5
Definition: common.h:86
ssp_datasize_t
Definition: ssp.h:123
ssp_mode_t
Definition: ssp.h:158
ssp_num_t
Definition: ssp.h:114
void ssp_disable(ssp_num_t ssp_num)
ssp_slave_option_t
Definition: ssp.h:178
uint16_t ssp_transfer(ssp_num_t ssp_num, uint16_t data)
void ssp_init(ssp_num_t ssp_num, ssp_datasize_t data_size, ssp_frame_format_t frame_format, ssp_cpol_cpha_t cpol_cpha_format, uint8_t serial_clock_rate, uint8_t clk_prescale, ssp_mode_t mode, ssp_master_slave_t master_slave, ssp_slave_option_t slave_option)
ssp_cpol_cpha_t
Definition: ssp.h:147
ssp_frame_format_t
Definition: ssp.h:140
ssp_master_slave_t
Definition: ssp.h:167
@ SSP_DATA_14BITS
Definition: ssp.h:134
@ SSP_DATA_4BITS
Definition: ssp.h:124
@ SSP_DATA_9BITS
Definition: ssp.h:129
@ SSP_DATA_6BITS
Definition: ssp.h:126
@ SSP_DATA_12BITS
Definition: ssp.h:132
@ SSP_DATA_8BITS
Definition: ssp.h:128
@ SSP_DATA_10BITS
Definition: ssp.h:130
@ SSP_DATA_15BITS
Definition: ssp.h:135
@ SSP_DATA_13BITS
Definition: ssp.h:133
@ SSP_DATA_11BITS
Definition: ssp.h:131
@ SSP_DATA_16BITS
Definition: ssp.h:136
@ SSP_DATA_7BITS
Definition: ssp.h:127
@ SSP_DATA_5BITS
Definition: ssp.h:125
@ SSP_MODE_NORMAL
Definition: ssp.h:159
@ SSP_MODE_LOOPBACK
Definition: ssp.h:160
@ SSP1_NUM
Definition: ssp.h:116
@ SSP0_NUM
Definition: ssp.h:115
@ SSP_SLAVE_OUT_ENABLE
Definition: ssp.h:179
@ SSP_SLAVE_OUT_DISABLE
Definition: ssp.h:180
@ SSP_CPOL_1_CPHA_0
Definition: ssp.h:149
@ SSP_CPOL_0_CPHA_1
Definition: ssp.h:150
@ SSP_CPOL_0_CPHA_0
Definition: ssp.h:148
@ SSP_CPOL_1_CPHA_1
Definition: ssp.h:151
@ SSP_FRAME_SPI
Definition: ssp.h:141
@ SSP_FRAM_MICROWIRE
Definition: ssp.h:143
@ SSP_FRAME_TI
Definition: ssp.h:142
@ SSP_MASTER
Definition: ssp.h:168
@ SSP_SLAVE
Definition: ssp.h:169