Skip to content

Commit 24c9b24

Browse files
committed
hal: renesas: rzn: Add SPI support for RZ/N series
Add SPI FSP HAL driver to support Zephyr SPI driver for RZ/N2L Signed-off-by: Nhut Nguyen <[email protected]> Signed-off-by: Quang Le <[email protected]>
1 parent bf5b30d commit 24c9b24

File tree

3 files changed

+1625
-0
lines changed

3 files changed

+1625
-0
lines changed
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
/*
2+
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef R_SPI_H
8+
#define R_SPI_H
9+
10+
/*******************************************************************************************************************//**
11+
* @addtogroup SPI
12+
* @{
13+
**********************************************************************************************************************/
14+
15+
/***********************************************************************************************************************
16+
* Includes
17+
**********************************************************************************************************************/
18+
#include "r_spi_api.h"
19+
20+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
21+
FSP_HEADER
22+
23+
/***********************************************************************************************************************
24+
* Macro definitions
25+
**********************************************************************************************************************/
26+
27+
/*************************************************************************************************
28+
* Type defines for the SPI interface API
29+
*************************************************************************************************/
30+
31+
/** 3-Wire or 4-Wire mode. */
32+
typedef enum e_spi_ssl_mode
33+
{
34+
SPI_SSL_MODE_SPI, ///< SPI operation (4-wire method)
35+
SPI_SSL_MODE_CLK_SYN ///< Clock Synchronous operation (3-wire method)
36+
} spi_ssl_mode_t;
37+
38+
/** Transmit Only (Half Duplex), or Full Duplex. */
39+
typedef enum e_spi_communication
40+
{
41+
SPI_COMMUNICATION_FULL_DUPLEX, ///< Full-Duplex synchronous serial communication
42+
SPI_COMMUNICATION_TRANSMIT_ONLY ///< Transit only serial communication
43+
} spi_communication_t;
44+
45+
/** Slave Select Polarity. */
46+
typedef enum e_spi_sslp
47+
{
48+
SPI_SSLP_LOW, ///< SSLP signal polarity active low
49+
SPI_SSLP_HIGH ///< SSLP signal polarity active high
50+
} spi_ssl_polarity_t;
51+
52+
/** The Slave Select Line */
53+
typedef enum e_spi_ssl_select
54+
{
55+
SPI_SSL_SELECT_SSL0, ///< Select SSL0
56+
SPI_SSL_SELECT_SSL1, ///< Select SSL1
57+
SPI_SSL_SELECT_SSL2, ///< Select SSL2
58+
SPI_SSL_SELECT_SSL3 ///< Select SSL3
59+
} spi_ssl_select_t;
60+
61+
/** MOSI Idle Behavior. */
62+
typedef enum e_spi_mosi_idle_value_fixing
63+
{
64+
SPI_MOSI_IDLE_VALUE_FIXING_DISABLE, ///< MOSI output value=value set in MOIFV bit
65+
SPI_MOSI_IDLE_VALUE_FIXING_LOW, ///< MOSIn level low during MOSI idling
66+
SPI_MOSI_IDLE_VALUE_FIXING_HIGH ///< MOSIn level high during MOSI idling
67+
} spi_mosi_idle_value_fixing_t;
68+
69+
/** Parity Mode */
70+
typedef enum e_spi_parity_mode
71+
{
72+
SPI_PARITY_MODE_DISABLE, ///< Disable parity
73+
SPI_PARITY_MODE_ODD, ///< Select even parity
74+
SPI_PARITY_MODE_EVEN ///< Select odd parity
75+
} spi_parity_t;
76+
77+
/** Byte Swapping Enable/Disable. */
78+
typedef enum
79+
{
80+
SPI_BYTE_SWAP_DISABLE = 0, ///< Disable Byte swapping for 16/32-Bit transfers
81+
SPI_BYTE_SWAP_ENABLE ///< Enable Byte swapping for 16/32-Bit transfers
82+
} spi_byte_swap_t;
83+
84+
/** Delay count for SPI delay settings. */
85+
typedef enum e_spi_clock_delay_count
86+
{
87+
SPI_DELAY_COUNT_1, ///< Set RSPCK delay count to 1 RSPCK
88+
SPI_DELAY_COUNT_2, ///< Set RSPCK delay count to 2 RSPCK
89+
SPI_DELAY_COUNT_3, ///< Set RSPCK delay count to 3 RSPCK
90+
SPI_DELAY_COUNT_4, ///< Set RSPCK delay count to 4 RSPCK
91+
SPI_DELAY_COUNT_5, ///< Set RSPCK delay count to 5 RSPCK
92+
SPI_DELAY_COUNT_6, ///< Set RSPCK delay count to 6 RSPCK
93+
SPI_DELAY_COUNT_7, ///< Set RSPCK delay count to 7 RSPCK
94+
SPI_DELAY_COUNT_8 ///< Set RSPCK delay count to 8 RSPCK
95+
} spi_delay_count_t;
96+
97+
/** SPI communication clock source. */
98+
typedef enum e_spi_clock_source
99+
{
100+
SPI_CLOCK_SOURCE_SPI0ASYNCCLK,
101+
SPI_CLOCK_SOURCE_SPI1ASYNCCLK,
102+
SPI_CLOCK_SOURCE_SPI2ASYNCCLK,
103+
SPI_CLOCK_SOURCE_SPI3ASYNCCLK,
104+
SPI_CLOCK_SOURCE_PCLKM
105+
} spi_clock_source_t;
106+
107+
/** SPI master receive clock. */
108+
typedef enum e_spi_master_receive_clock
109+
{
110+
SPI_MASTER_RECEIVE_CLOCK_MRIOCLK, ///< MRIOCLK
111+
SPI_MASTER_RECEIVE_CLOCK_MRCLK, ///< MRCLK
112+
} spi_master_receive_clock_t;
113+
114+
/** SPI max analog delay for MRIOCLK. */
115+
typedef enum e_spi_mrioclk_analog_delay
116+
{
117+
SPI_MRIOCLK_ANALOG_DELAY_NODELAY, ///< No delay
118+
SPI_MRIOCLK_ANALOG_DELAY_1_1_NS, ///< 1.1 ns
119+
SPI_MRIOCLK_ANALOG_DELAY_2_2_NS, ///< 2.2 ns
120+
SPI_MRIOCLK_ANALOG_DELAY_3_3_NS, ///< 3.3 ns
121+
SPI_MRIOCLK_ANALOG_DELAY_4_4_NS, ///< 4.4 ns
122+
SPI_MRIOCLK_ANALOG_DELAY_5_5_NS, ///< 5.5 ns
123+
SPI_MRIOCLK_ANALOG_DELAY_6_6_NS, ///< 6.6 ns
124+
SPI_MRIOCLK_ANALOG_DELAY_7_7_NS, ///< 7.7 ns
125+
} spi_mrioclk_analog_delay_t;
126+
127+
/** SPI digital delay for MRCLK. */
128+
typedef enum e_spi_mrclk_digital_delay
129+
{
130+
SPI_MRCLK_DIGITAL_DELAY_CLOCK_0, ///< 0 PCLKSPIn
131+
SPI_MRCLK_DIGITAL_DELAY_CLOCK_1, ///< 1 PCLKSPIn
132+
SPI_MRCLK_DIGITAL_DELAY_CLOCK_2, ///< 2 PCLKSPIn
133+
SPI_MRCLK_DIGITAL_DELAY_CLOCK_3, ///< 3 PCLKSPIn
134+
SPI_MRCLK_DIGITAL_DELAY_CLOCK_4, ///< 4 PCLKSPIn
135+
SPI_MRCLK_DIGITAL_DELAY_CLOCK_5, ///< 5 PCLKSPIn
136+
SPI_MRCLK_DIGITAL_DELAY_CLOCK_6, ///< 6 PCLKSPIn
137+
SPI_MRCLK_DIGITAL_DELAY_CLOCK_7, ///< 7 PCLKSPIn
138+
} spi_mrclk_digital_delay_t;
139+
140+
/** SPI Clock Divider settings. */
141+
typedef struct
142+
{
143+
uint8_t spbr; ///< SPBR register setting
144+
uint8_t brdv : 2; ///< BRDV setting in SPCMD0
145+
} rspck_div_setting_t;
146+
147+
/** Extended SPI interface configuration */
148+
typedef struct st_spi_extended_cfg
149+
{
150+
spi_ssl_mode_t spi_clksyn; ///< Select spi or clock syn mode operation
151+
spi_communication_t spi_comm; ///< Select full-duplex or transmit-only communication
152+
spi_ssl_polarity_t ssl_polarity; ///< Select SSLn signal polarity
153+
spi_ssl_select_t ssl_select; ///< Select which slave to use: 0-SSL0, 1-SSL1, 2-SSL2, 3-SSL3
154+
spi_mosi_idle_value_fixing_t mosi_idle; ///< Select MOSI idle fixed value and selection
155+
spi_parity_t parity; ///< Select parity and enable/disable parity
156+
spi_byte_swap_t byte_swap; ///< Select byte swap mode
157+
spi_clock_source_t clock_source; ///< Communication clock source (PCLKSPI)
158+
rspck_div_setting_t spck_div; ///< Register values for configuring the SPI Clock Divider.
159+
spi_delay_count_t spck_delay; ///< SPI Clock Delay Register Setting
160+
spi_delay_count_t ssl_negation_delay; ///< SPI Slave Select Negation Delay Register Setting
161+
spi_delay_count_t next_access_delay; ///< SPI Next-Access Delay Register Setting
162+
uint8_t transmit_fifo_threshold; ///< Transmit FIFO threshold (0~3)
163+
uint8_t receive_fifo_threshold; ///< Receive FIFO threshold (0~3)
164+
uint8_t receive_data_ready_detect_adjustment; ///< Receive data ready detect timing(0~255PCLKSPIn)
165+
spi_master_receive_clock_t master_receive_clock; ///< SPI master receive clock
166+
spi_mrioclk_analog_delay_t mrioclk_analog_delay; ///< SPI max analog delay for MRIOCLK
167+
spi_mrclk_digital_delay_t mrclk_digital_delay; ///< SPI digital delay for MRCLK
168+
} spi_extended_cfg_t;
169+
170+
/** Channel control block. DO NOT INITIALIZE. Initialization occurs when @ref spi_api_t::open is called. */
171+
typedef struct st_spi_instance_ctrl
172+
{
173+
uint32_t open; ///< Indicates whether the open API has been successfully called.
174+
spi_cfg_t const * p_cfg; ///< Pointer to instance configuration
175+
R_SPI0_Type * p_regs; ///< Base register for this channel
176+
void const * p_tx_data; ///< Buffer to transmit
177+
void * p_rx_data; ///< Buffer to receive
178+
uint32_t tx_count; ///< Number of Data Frames to transfer (4 to 32 bits)
179+
uint32_t rx_count; ///< Number of Data Frames to transfer (4 to 32 bits)
180+
uint32_t count; ///< Number of Data Frames to transfer (4 to 32 bits)
181+
spi_bit_width_t bit_width; ///< Bits per Data frame (4 to 32 bits)
182+
183+
/* Pointer to callback and optional working memory */
184+
void (* p_callback)(spi_callback_args_t *);
185+
spi_callback_args_t * p_callback_memory;
186+
187+
/* Pointer to context to be passed into callback function */
188+
void const * p_context;
189+
} spi_instance_ctrl_t;
190+
191+
/**********************************************************************************************************************
192+
* Exported global variables
193+
**********************************************************************************************************************/
194+
195+
/** @cond INC_HEADER_DEFS_SEC */
196+
/** Filled in Interface API structure for this Instance. */
197+
extern const spi_api_t g_spi_on_spi;
198+
199+
/** @endcond */
200+
201+
/***********************************************************************************************************************
202+
* Public APIs
203+
**********************************************************************************************************************/
204+
fsp_err_t R_SPI_Open(spi_ctrl_t * p_ctrl, spi_cfg_t const * const p_cfg);
205+
206+
fsp_err_t R_SPI_Read(spi_ctrl_t * const p_ctrl, void * p_dest, uint32_t const length, spi_bit_width_t const bit_width);
207+
208+
fsp_err_t R_SPI_Write(spi_ctrl_t * const p_ctrl,
209+
void const * p_src,
210+
uint32_t const length,
211+
spi_bit_width_t const bit_width);
212+
213+
fsp_err_t R_SPI_WriteRead(spi_ctrl_t * const p_ctrl,
214+
void const * p_src,
215+
void * p_dest,
216+
uint32_t const length,
217+
spi_bit_width_t const bit_width);
218+
219+
fsp_err_t R_SPI_Close(spi_ctrl_t * const p_ctrl);
220+
221+
fsp_err_t R_SPI_CalculateBitrate(uint32_t bitrate, spi_clock_source_t clock_source, rspck_div_setting_t * spck_div);
222+
223+
fsp_err_t R_SPI_CallbackSet(spi_ctrl_t * const p_ctrl,
224+
void ( * p_callback)(spi_callback_args_t *),
225+
void const * const p_context,
226+
spi_callback_args_t * const p_callback_memory);
227+
228+
/*******************************************************************************************************************//**
229+
* @} (end ingroup SPI)
230+
**********************************************************************************************************************/
231+
232+
/** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
233+
FSP_FOOTER
234+
235+
#endif

0 commit comments

Comments
 (0)