no-OS
Loading...
Searching...
No Matches
oa_tc6.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file oa_tc6.h
3 * @brief Header file for the Open Alliance TC6 SPI driver.
4 * @author Ciprian Regus (ciprian.regus@analog.com)
5 ********************************************************************************
6 * Copyright 2025(c) Analog Devices, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * 3. Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25 * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *******************************************************************************/
33#ifndef _NO_OS_OA_TC6_H
34#define _NO_OS_OA_TC6_H
35
36#include "no_os_spi.h"
37#include "no_os_util.h"
38#include <stdint.h>
39
40#ifndef CONFIG_OA_TX_FRAME_BUFF_NUM
41#define CONFIG_OA_TX_FRAME_BUFF_NUM 2
42#endif
43
44#ifndef CONFIG_OA_RX_FRAME_BUFF_NUM
45#define CONFIG_OA_RX_FRAME_BUFF_NUM 5
46#endif
47
48#ifndef CONFIG_OA_CHUNK_BUFFER_SIZE
49#define CONFIG_OA_CHUNK_BUFFER_SIZE 1514
50#endif
51
52#ifndef CONFIG_OA_THREAD_RX_LIMIT
53#define CONFIG_OA_THREAD_RX_LIMIT 5
54#endif
55
56#ifndef CONFIG_OA_ZERO_SWO_ONLY
57#define CONFIG_OA_ZERO_SWO_ONLY 1
58#endif
59
60#define OA_TX_FRAME_BUFF_NUM CONFIG_OA_TX_FRAME_BUFF_NUM
61#define OA_RX_FRAME_BUFF_NUM CONFIG_OA_RX_FRAME_BUFF_NUM
62
63/* Space for one full frame + 24 chunk headers (68 * 24)*/
64#define OA_SPI_BUFF_LEN 1632
65
66/* Space for 2 Header + Reg Data + Inverse Reg Data (PROTE) */
67#define OA_SPI_CTRL_LEN 16
68
69#define OA_CHUNK_SIZE 64
70#define OA_REG_LEN 4
71#define OA_HEADER_LEN 4
72#define OA_FOOTER_LEN 4
73
74#define OA_MMS_REG(m, r) (((m) << 16) | ((r) & NO_OS_GENMASK(15, 0)))
75#define OA_CTRL_ADDR_MMS_MASK NO_OS_GENMASK(27, 8)
76
77#define OA_CTRL_HDRB_MASK NO_OS_BIT(30)
78#define OA_CTRL_WNR_MASK NO_OS_BIT(29)
79#define OA_CTRL_AID_MASK NO_OS_BIT(28)
80#define OA_CTRL_MMS_MASK NO_OS_GENMASK(27, 24)
81#define OA_CTRL_ADDR_MASK NO_OS_GENMASK(23, 8)
82#define OA_CTRL_LEN_MASK NO_OS_GENMASK(7, 1)
83#define OA_CTRL_P_MASK NO_OS_BIT(0)
84
85#define OA_DATA_FOOTER_EXST_MASK NO_OS_BIT(31)
86#define OA_DATA_FOOTER_HDRB_MASK NO_OS_BIT(30)
87#define OA_DATA_FOOTER_SYNC_MASK NO_OS_BIT(29)
88#define OA_DATA_FOOTER_RCA_MASK NO_OS_GENMASK(28, 24)
89#define OA_DATA_FOOTER_VS_MASK NO_OS_GENMASK(23, 22)
90#define OA_DATA_FOOTER_DV_MASK NO_OS_BIT(21)
91#define OA_DATA_FOOTER_SV_MASK NO_OS_BIT(20)
92#define OA_DATA_FOOTER_SWO_MASK NO_OS_GENMASK(19, 16)
93#define OA_DATA_FOOTER_FD_MASK NO_OS_BIT(15)
94#define OA_DATA_FOOTER_EV_MASK NO_OS_BIT(14)
95#define OA_DATA_FOOTER_EBO_MASK NO_OS_GENMASK(13, 8)
96#define OA_DATA_FOOTER_RTSA_MASK NO_OS_BIT(7)
97#define OA_DATA_FOOTER_RTSP_MASK NO_OS_BIT(6)
98#define OA_DATA_FOOTER_TXC_MASK NO_OS_GENMASK(5, 1)
99#define OA_DATA_FOOTER_P_MASK NO_OS_BIT(0)
100
101#define OA_DATA_HEADER_DNC_MASK NO_OS_BIT(31)
102#define OA_DATA_HEADER_SEQ_MASK NO_OS_BIT(30)
103#define OA_DATA_HEADER_NORX_MASK NO_OS_BIT(29)
104#define OA_DATA_HEADER_VS_MASK NO_OS_GENMASK(23, 22)
105#define OA_DATA_HEADER_DV_MASK NO_OS_BIT(21)
106#define OA_DATA_HEADER_SV_MASK NO_OS_BIT(20)
107#define OA_DATA_HEADER_SWO_MASK NO_OS_GENMASK(19, 16)
108#define OA_DATA_HEADER_EV_MASK NO_OS_BIT(14)
109#define OA_DATA_HEADER_EBO_MASK NO_OS_GENMASK(13, 8)
110#define OA_DATA_HEADER_P_MASK NO_OS_BIT(0)
111
112/* Standard control and status registers (MMS 0) */
113
114#define OA_TC6_IDVER_REG OA_MMS_REG(0x0, 0x0000)
115#define OA_TC6_PHYID_REG OA_MMS_REG(0x0, 0x0001)
116#define OA_TC6_STDCAP_REG OA_MMS_REG(0x0, 0x0002)
117#define OA_TC6_RESET_REG OA_MMS_REG(0x0, 0x0003)
118#define OA_TC6_CONFIG0_REG OA_MMS_REG(0x0, 0x0004)
119#define OA_TC6_CONFIG1_REG OA_MMS_REG(0x0, 0x0005)
120#define OA_TC6_CONFIG2_REG OA_MMS_REG(0x0, 0x0006)
121#define OA_TC6_STATUS0_REG OA_MMS_REG(0x0, 0x0008)
122#define OA_TC6_STATUS1_REG OA_MMS_REG(0x0, 0x0009)
123#define OA_TC6_BUFST_REG OA_MMS_REG(0x0, 0x000B)
124#define OA_TC6_IMSK0_REG OA_MMS_REG(0x0, 0x000C)
125#define OA_TC6_IMSK1_REG OA_MMS_REG(0x0, 0x000D)
126
127#define OA_TC6_TTSCAH_REG OA_MMS_REG(0x0, 0x0010)
128#define OA_TC6_TTSCAL_REG OA_MMS_REG(0x0, 0x0011)
129#define OA_TC6_TTSCBH_REG OA_MMS_REG(0x0, 0x0012)
130#define OA_TC6_TTSCBL_REG OA_MMS_REG(0x0, 0x0013)
131#define OA_TC6_TTSCCH_REG OA_MMS_REG(0x0, 0x0014)
132#define OA_TC6_TTSCCL_REG OA_MMS_REG(0x0, 0x0015)
133#define OA_TC6_MDIOACC0_REG OA_MMS_REG(0x0, 0x0020)
134#define OA_TC6_MDIOACC1_REG OA_MMS_REG(0x0, 0x0021)
135#define OA_TC6_MDIOACC2_REG OA_MMS_REG(0x0, 0x0022)
136#define OA_TC6_MDIOACC3_REG OA_MMS_REG(0x0, 0x0023)
137#define OA_TC6_MDIOACC4_REG OA_MMS_REG(0x0, 0x0024)
138#define OA_TC6_MDIOACC5_REG OA_MMS_REG(0x0, 0x0025)
139#define OA_TC6_MDIOACC6_REG OA_MMS_REG(0x0, 0x0026)
140#define OA_TC6_MDIOACC7_REG OA_MMS_REG(0x0, 0x0027)
141
142#define OA_TC6_CONFIG0_ZARFE_MASK NO_OS_BIT(12)
143
144#define OA_TC6_BUFSTS_TXC_MASK NO_OS_GENMASK(15, 8)
145#define OA_TC6_BUFSTS_RCA_MASK NO_OS_GENMASK(7, 0)
146
151 /*
152 * Neither the OA nor the user application doesn't currently
153 * use this buffer. OA can start writing it.
154 */
156
157 /*
158 * The buffer is currently written by OA, but it doesn't yet
159 * contain a complete frame. The user application cannot reference
160 * the data yet.
161 */
163
164 /*
165 * The buffer has a complete frame, and is no longer accessed by OA.
166 * The user application could use this.
167 */
169
170 /* The buffer is accessed by the user application. OA will not overwrite it */
172
173 /* The user writes to this buffer. OA doesn't access it. */
175
176 /* The buffer is ready to be transmitted. The user won't access it anymore. */
178};
179
196
204 bool exst;
205 bool hdrb;
206 bool sync;
207};
208
229
235
236 /* The OASPI device uses Protected SPI for control transactions */
238};
239
240/* Read a register from the MAC device */
241int oa_tc6_reg_read(struct oa_tc6_desc *, uint32_t, uint32_t *);
242
243/* Write a register of the MAC device */
244int oa_tc6_reg_write(struct oa_tc6_desc *, uint32_t, uint32_t);
245
246/* Update a register field */
247int oa_tc6_reg_update(struct oa_tc6_desc *, uint32_t, uint32_t, uint32_t);
248
249/* Get a received frame with a matching VS field (in the RX chunks) */
251 struct oa_tc6_frame_buffer **,
252 uint8_t, uint8_t);
253
254/* Get the first frame in the RX queue */
256
257/* Mark the frame buffer as ready to be reused for a new frame. */
259
260/* Get a frame buffer which can be filled and submitted for transmission */
262
263/* Mark the frame buffer as filled and ready for transmission */
265
266/* Gets the latched transfer flags, and optionally clears the latch */
267int oa_tc6_get_xfer_flags(struct oa_tc6_desc *, struct oa_tc6_flags *, bool);
268
269/*
270 * Transmit all the frames in the OA_BUFF_TX_READY state and receive the
271 * available chunks.
272 */
273int oa_tc6_thread(struct oa_tc6_desc *);
274
275/* Initialize the OA TC6 SPI driver */
276int oa_tc6_init(struct oa_tc6_desc **, struct oa_tc6_init_param *);
277
278/* Free the resources allocated by the oa_tc6_init() function */
279int oa_tc6_remove(struct oa_tc6_desc *);
280
281#endif /* _NO_OS_OA_TC6_H */
Header file of SPI Interface.
Header file of utility functions.
int oa_tc6_get_tx_frame(struct oa_tc6_desc *, struct oa_tc6_frame_buffer **)
Get a frame buffer that can be filled by user.
Definition oa_tc6.c:192
oa_tc6_user_buffer_state
State for data buffers containing Ethernet frames.
Definition oa_tc6.h:150
@ OA_BUFF_RX_IN_PROGRESS
Definition oa_tc6.h:162
@ OA_BUFF_TX_READY
Definition oa_tc6.h:177
@ OA_BUFF_FREE
Definition oa_tc6.h:155
@ OA_BUFF_RX_COMPLETE
Definition oa_tc6.h:168
@ OA_BUFF_RX_USER_OWNED
Definition oa_tc6.h:171
@ OA_BUFF_TX_BUSY
Definition oa_tc6.h:174
#define OA_SPI_CTRL_LEN
Definition oa_tc6.h:67
int oa_tc6_init(struct oa_tc6_desc **, struct oa_tc6_init_param *)
Allocate resources for the OA TC6 driver.
Definition oa_tc6.c:723
int oa_tc6_get_xfer_flags(struct oa_tc6_desc *, struct oa_tc6_flags *, bool)
Gets the latched transfer flags that are read from the data chunk footer. Optionally clears the latch...
Definition oa_tc6.c:629
int oa_tc6_remove(struct oa_tc6_desc *)
Free a device descriptor.
Definition oa_tc6.c:756
#define OA_TX_FRAME_BUFF_NUM
Definition oa_tc6.h:60
int oa_tc6_get_rx_frame_match_vs(struct oa_tc6_desc *, struct oa_tc6_frame_buffer **, uint8_t, uint8_t)
Get a frame buffer that is ready to be read by the user. The VS field in the chunk footer fields shou...
Definition oa_tc6.c:293
#define OA_RX_FRAME_BUFF_NUM
Definition oa_tc6.h:61
int oa_tc6_reg_update(struct oa_tc6_desc *, uint32_t, uint32_t, uint32_t)
Update a field inside a register.
Definition oa_tc6.c:170
int oa_tc6_reg_read(struct oa_tc6_desc *, uint32_t, uint32_t *)
Read a register value.
Definition oa_tc6.c:113
int oa_tc6_put_rx_frame(struct oa_tc6_desc *, struct oa_tc6_frame_buffer *)
Mark a frame buffer as used and ready to be rewritten.
Definition oa_tc6.c:337
int oa_tc6_put_tx_frame(struct oa_tc6_desc *, struct oa_tc6_frame_buffer *)
Mark a frame buffer as ready to be transmitted.
Definition oa_tc6.c:218
int oa_tc6_get_rx_frame(struct oa_tc6_desc *, struct oa_tc6_frame_buffer **)
Get a frame buffer that is ready to be read by the user.
Definition oa_tc6.c:316
int oa_tc6_reg_write(struct oa_tc6_desc *, uint32_t, uint32_t)
Write a register value.
Definition oa_tc6.c:145
#define OA_SPI_BUFF_LEN
Definition oa_tc6.h:64
int oa_tc6_thread(struct oa_tc6_desc *)
Transmit all the frames in the OA_BUFF_TX_READY state and receive the frames in the OA_BUFF_RX_COMPLE...
Definition oa_tc6.c:649
#define CONFIG_OA_CHUNK_BUFFER_SIZE
Definition oa_tc6.h:49
Structure holding SPI descriptor.
Definition no_os_spi.h:180
Holds the frame buffers and the communication descriptor for the OA TC6 driver.
Definition oa_tc6.h:212
uint32_t data_rx_credit
Definition oa_tc6.h:221
struct oa_tc6_flags xfer_flags
Definition oa_tc6.h:226
struct oa_tc6_frame_buffer user_rx_frame_buffer[OA_RX_FRAME_BUFF_NUM]
Definition oa_tc6.h:217
uint32_t ctrl_rx_credit
Definition oa_tc6.h:224
uint8_t ctrl_chunks[OA_SPI_CTRL_LEN]
Definition oa_tc6.h:214
bool prote_spi
Definition oa_tc6.h:227
struct no_os_spi_desc * comm_desc
Definition oa_tc6.h:213
uint8_t data_chunks[OA_SPI_BUFF_LEN]
Definition oa_tc6.h:215
uint32_t ctrl_tx_credit
Definition oa_tc6.h:223
struct oa_tc6_frame_buffer user_tx_frame_buffer[OA_TX_FRAME_BUFF_NUM]
Definition oa_tc6.h:218
uint32_t data_tx_credit
Definition oa_tc6.h:220
Stores the status flags which are provided as part of the footer during data transfers....
Definition oa_tc6.h:202
bool exst
Definition oa_tc6.h:204
bool flags_valid
Definition oa_tc6.h:203
bool hdrb
Definition oa_tc6.h:205
bool sync
Definition oa_tc6.h:206
Stores an Ethernet frame along with metadata needed for parsing. The MAC driver or the user applicati...
Definition oa_tc6.h:185
enum oa_tc6_user_buffer_state state
Definition oa_tc6.h:189
uint8_t data[CONFIG_OA_CHUNK_BUFFER_SIZE]
Definition oa_tc6.h:188
uint8_t vs
Definition oa_tc6.h:190
bool rtsp
Definition oa_tc6.h:194
bool rtsa
Definition oa_tc6.h:193
bool frame_drop
Definition oa_tc6.h:192
uint32_t index
Definition oa_tc6.h:186
uint32_t len
Definition oa_tc6.h:187
Holds the initialization parameters for the OA TC6 driver.
Definition oa_tc6.h:233
bool prote_spi
Definition oa_tc6.h:237
struct no_os_spi_desc * comm_desc
Definition oa_tc6.h:234