MAX32665 SDK Documentation  0.2
Software Development Kit Overview and API Documentation
spixfc.h
1 
5 /* *****************************************************************************
6  * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included
16  * in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
22  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24  * OTHER DEALINGS IN THE SOFTWARE.
25  *
26  * Except as contained in this notice, the name of Maxim Integrated
27  * Products, Inc. shall not be used except as stated in the Maxim Integrated
28  * Products, Inc. Branding Policy.
29  *
30  * The mere transfer of this software does not imply any licenses
31  * of trade secrets, proprietary technology, copyrights, patents,
32  * trademarks, maskwork rights, or any other form of intellectual
33  * property whatsoever. Maxim Integrated Products, Inc. retains all
34  * ownership rights.
35  *
36  * $Date: 2018-10-31 10:32:51 -0500 (Wed, 31 Oct 2018) $
37  * $Revision: 38826 $
38  *
39  **************************************************************************** */
40 
41 /* Define to prevent redundant inclusion */
42 #ifndef _SPIXFC_H_
43 #define _SPIXFC_H_
44 
45 /* **** Includes **** */
46 #include "mxc_config.h"
47 #include "mxc_sys.h"
48 #include "spixfc_regs.h"
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
60 /* **** Definitions **** */
61 
65 typedef enum {
66  SPIXFC_SSEL0_HIGH = (0x1 << 0),
67  SPIXFC_SSEL0_LOW = 0,
68  SPIXFC_SSEL1_HIGH = (0x1 << 1),
69  SPIXFC_SSEL1_LOW = 0,
70  SPIXFC_SSEL2_HIGH = (0x1 << 2),
71  SPIXFC_SSEL2_LOW = 0,
72  SPIXFC_SSEL3_HIGH = (0x1 << 3),
73  SPIXFC_SSEL3_LOW = 0
74 }
76 
80 typedef enum {
85 
89 typedef struct {
90  uint8_t mode;
91  uint32_t ssel_pol;
92  uint32_t baud;
93 } spixfc_cfg_t;
94 
98 typedef struct spixfc_req spixfc_req_t;
99 
100 struct spixfc_req {
101  uint8_t ssel;
102  uint8_t deass;
103  uint8_t wait_tx;
104  const uint8_t *tx_data;
105  uint8_t *rx_data;
107  unsigned len;
108  unsigned read_num;
109  unsigned write_num;
115  void (*callback)(spixfc_req_t*, int);
116 };
117 
121 #define SPIXFC_HEADER_DIRECTION_POS 0
122 #define SPIXFC_HEADER_UNITS_POS 2
123 #define SPIXFC_HEADER_SIZE_POS 4
124 #define SPIXFC_HEADER_WIDTH_POS 9
125 #define SPIXFC_HEADER_DEASS_SS_POS 13
126 
127 
132 #define MXC_V_SPIXFC_CONFIG_PAGE_SIZE_4B ((uint32_t)0x00000000UL)
133 #define MXC_V_SPIXFC_CONFIG_PAGE_SIZE_8B ((uint32_t)0x00000001UL)
134 #define MXC_V_SPIXFC_CONFIG_PAGE_SIZE_16B ((uint32_t)0x00000002UL)
135 #define MXC_V_SPIXFC_CONFIG_PAGE_SIZE_32B ((uint32_t)0x00000003UL)
136 
137 #define MXC_S_SPIXFC_CONFIG_PAGE_4B (MXC_V_SPIXFC_CONFIG_PAGE_SIZE_4B << MXC_F_SPIXFC_CONFIG_PAGE_SIZE_POS)
138 #define MXC_S_SPIXFC_CONFIG_PAGE_8B (MXC_V_SPIXFC_CONFIG_PAGE_SIZE_8B << MXC_F_SPIXFC_CONFIG_PAGE_SIZE_POS)
139 #define MXC_S_SPIXFC_CONFIG_PAGE_16B (MXC_V_SPIXFC_CONFIG_PAGE_SIZE_16B << MXC_F_SPIXFC_CONFIG_PAGE_SIZE_POS)
140 #define MXC_S_SPIXFC_CONFIG_PAGE_32B (MXC_V_SPIXFC_CONFIG_PAGE_SIZE_32B << MXC_F_SPIXFC_CONFIG_PAGE_SIZE_POS)
141 
142 
143 
144 typedef enum {
145  SPIXFC_HEADER_DIR_NONE,
146  SPIXFC_HEADER_DIR_TX,
147  SPIXFC_HEADER_DIR_RX,
148  SPIXFC_HEADER_DIR_BOTH,
149 } spixfc_hdr_direction_t;
150 
151 typedef enum {
152  SPIXFC_HEADER_UNITS_BITS,
153  SPIXFC_HEADER_UNITS_BYTES,
154  SPIXFC_HEADER_UNITS_PAGES,
155 } spixfc_hdr_units_t;
156 
157 typedef enum {
158  SPIXFC_HEADER_WIDTH_SINGLE,
159  SPIXFC_HEADER_WIDTH_DUAL,
160  SPIXFC_HEADER_WIDTH_QUAD,
161  SPIXFC_HEADER_WIDTH_INVALID,
162 } spixfc_hdr_width_t;
163 
164 #define SPIXFC_HEADER_DEASS_SS 1
165 #define MAX_SCLK 0x10
166 #define SPIXFC_HEADER_TX_DIR 1
167 #define NOT_HEADER_DATA 0xF000 // 0xF makes sure it is not a header
168 
169 /***** Globals *****/
170 
171 /***** Function Prototypes *****/
172 
180 int SPIXFC_Init(mxc_spixfc_regs_t *spixfc, const spixfc_cfg_t *cfg, const sys_cfg_spixfc_t* sys_cfg);
181 
186 void SPIXFC_Shutdown(mxc_spixfc_regs_t *spixfc);
187 
196 int SPIXFC_Clocks(mxc_spixfc_regs_t *spixfc, uint32_t len, uint8_t ssel, uint8_t deass);
197 
205 int SPIXFC_Trans(mxc_spixfc_regs_t *spixfc, spixfc_req_t *req);
206 
215 int SPIXFC_TransAsync(mxc_spixfc_regs_t *spixfc, spixfc_req_t *req);
216 
225 int SPIXFC_AbortAsync(mxc_spixfc_regs_t *spixfc, spixfc_req_t *req);
226 
235 void SPIXFC_Handler(mxc_spixfc_regs_t *spixfc);
236 
243 
246 #ifdef __cplusplus
247 }
248 #endif
249 
250 #endif /* _SPIXFC_H_ */
spixfc_width_t width
Number of data lines to use.
Definition: spixfc.h:106
uint8_t mode
SPIXFC mode to use, 0-3.
Definition: spixfc.h:90
void(* callback)(spixfc_req_t *, int)
Callback for asynchronous request.
Definition: spixfc.h:115
uint32_t ssel_pol
Mask of active levels for slave select signals, use spixfc_ssel_t.
Definition: spixfc.h:91
uint8_t deass
De-assert slave select at the end of the transaction.
Definition: spixfc.h:102
int SPIXFC_TransAsync(mxc_spixfc_regs_t *spixfc, spixfc_req_t *req)
Asynchronously read/write SPIXFC data.
int SPIXFC_PrepForSleep(mxc_spixfc_regs_t *spixfc)
Attempt to prepare the SPIXFC for sleep.
SPIXFC configuration type.
Definition: spixfc.h:89
unsigned len
Number of bytes to send.
Definition: spixfc.h:107
uint8_t wait_tx
Wait for the TX FIFO to be empty before returning.
Definition: spixfc.h:103
uint8_t ssel
Slave select number.
Definition: spixfc.h:101
uint32_t baud
Baud rate in Hz.
Definition: spixfc.h:92
1 Data Line.
Definition: spixfc.h:81
spixfc_width_t
Number of data lines to use.
Definition: spixfc.h:80
unsigned read_num
Number of bytes read.
Definition: spixfc.h:108
spixfc_ssel_t
Active levels for slave select lines.
Definition: spixfc.h:65
void SPIXFC_Shutdown(mxc_spixfc_regs_t *spixfc)
Shutdown SPIXFC module.
void SPIXFC_Handler(mxc_spixfc_regs_t *spixfc)
SPIXFC interrupt handler.
int SPIXFC_Clocks(mxc_spixfc_regs_t *spixfc, uint32_t len, uint8_t ssel, uint8_t deass)
Send Clock cycles on SCK without reading or writing.
unsigned write_num
Number of bytes written.
Definition: spixfc.h:109
int SPIXFC_Trans(mxc_spixfc_regs_t *spixfc, spixfc_req_t *req)
Read/write SPIXFC data.
int SPIXFC_Init(mxc_spixfc_regs_t *spixfc, const spixfc_cfg_t *cfg, const sys_cfg_spixfc_t *sys_cfg)
Initialize SPIXFC module and setup the GPIO pins.
2 Data Lines (x2).
Definition: spixfc.h:82
int SPIXFC_AbortAsync(mxc_spixfc_regs_t *spixfc, spixfc_req_t *req)
Abort asynchronous request.
SPIXFC Transaction request.
Definition: spixfc.h:100
4 Data Lines (x4).
Definition: spixfc.h:83
uint8_t * rx_data
RX buffer.
Definition: spixfc.h:105
Structure type to access the SPIXFC Registers.
Definition: spixfc_regs.h:88
const uint8_t * tx_data
TX buffer.
Definition: spixfc.h:104