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_TSC_MASK NO_OS_GENMASK(7, 6)
111#define OA_DATA_HEADER_P_MASK NO_OS_BIT(0)
112
113/* Standard control and status registers (MMS 0) */
114
115#define OA_TC6_IDVER_REG OA_MMS_REG(0x0, 0x0000)
116#define OA_TC6_PHYID_REG OA_MMS_REG(0x0, 0x0001)
117#define OA_TC6_STDCAP_REG OA_MMS_REG(0x0, 0x0002)
118#define OA_TC6_RESET_REG OA_MMS_REG(0x0, 0x0003)
119#define OA_TC6_CONFIG0_REG OA_MMS_REG(0x0, 0x0004)
120#define OA_TC6_CONFIG1_REG OA_MMS_REG(0x0, 0x0005)
121#define OA_TC6_CONFIG2_REG OA_MMS_REG(0x0, 0x0006)
122#define OA_TC6_STATUS0_REG OA_MMS_REG(0x0, 0x0008)
123#define OA_TC6_STATUS1_REG OA_MMS_REG(0x0, 0x0009)
124#define OA_TC6_BUFST_REG OA_MMS_REG(0x0, 0x000B)
125#define OA_TC6_IMSK0_REG OA_MMS_REG(0x0, 0x000C)
126#define OA_TC6_IMSK1_REG OA_MMS_REG(0x0, 0x000D)
127
128#define OA_TC6_TTSCAH_REG OA_MMS_REG(0x0, 0x0010)
129#define OA_TC6_TTSCAL_REG OA_MMS_REG(0x0, 0x0011)
130#define OA_TC6_TTSCBH_REG OA_MMS_REG(0x0, 0x0012)
131#define OA_TC6_TTSCBL_REG OA_MMS_REG(0x0, 0x0013)
132#define OA_TC6_TTSCCH_REG OA_MMS_REG(0x0, 0x0014)
133#define OA_TC6_TTSCCL_REG OA_MMS_REG(0x0, 0x0015)
134#define OA_TC6_MDIOACC0_REG OA_MMS_REG(0x0, 0x0020)
135#define OA_TC6_MDIOACC1_REG OA_MMS_REG(0x0, 0x0021)
136#define OA_TC6_MDIOACC2_REG OA_MMS_REG(0x0, 0x0022)
137#define OA_TC6_MDIOACC3_REG OA_MMS_REG(0x0, 0x0023)
138#define OA_TC6_MDIOACC4_REG OA_MMS_REG(0x0, 0x0024)
139#define OA_TC6_MDIOACC5_REG OA_MMS_REG(0x0, 0x0025)
140#define OA_TC6_MDIOACC6_REG OA_MMS_REG(0x0, 0x0026)
141#define OA_TC6_MDIOACC7_REG OA_MMS_REG(0x0, 0x0027)
142
143#define OA_TC6_CONFIG0_ZARFE_MASK NO_OS_BIT(12)
144
145#define OA_TC6_BUFSTS_TXC_MASK NO_OS_GENMASK(15, 8)
146#define OA_TC6_BUFSTS_RCA_MASK NO_OS_GENMASK(7, 0)
147
152 /*
153 * Neither the OA nor the user application doesn't currently
154 * use this buffer. OA can start writing it.
155 */
157
158 /*
159 * The buffer is currently written by OA, but it doesn't yet
160 * contain a complete frame. The user application cannot reference
161 * the data yet.
162 */
164
165 /*
166 * The buffer has a complete frame, and is no longer accessed by OA.
167 * The user application could use this.
168 */
170
171 /* The buffer is accessed by the user application. OA will not overwrite it */
173
174 /* The user writes to this buffer. OA doesn't access it. */
176
177 /* The buffer is ready to be transmitted. The user won't access it anymore. */
179};
180
197
205 bool exst;
206 bool hdrb;
207 bool sync;
208};
209
230
236
237 /* The OASPI device uses Protected SPI for control transactions */
239};
240
241/* Read a register from the MAC device */
242int oa_tc6_reg_read(struct oa_tc6_desc *, uint32_t, uint32_t *);
243
244/* Write a register of the MAC device */
245int oa_tc6_reg_write(struct oa_tc6_desc *, uint32_t, uint32_t);
246
247/* Update a register field */
248int oa_tc6_reg_update(struct oa_tc6_desc *, uint32_t, uint32_t, uint32_t);
249
250/* Get a received frame with a matching VS field (in the RX chunks) */
252 struct oa_tc6_frame_buffer **,
253 uint8_t, uint8_t);
254
255/* Get the first frame in the RX queue */
257
258/* Mark the frame buffer as ready to be reused for a new frame. */
260
261/* Get a frame buffer which can be filled and submitted for transmission */
263
264/* Mark the frame buffer as filled and ready for transmission */
266
267/* Gets the latched transfer flags, and optionally clears the latch */
268int oa_tc6_get_xfer_flags(struct oa_tc6_desc *, struct oa_tc6_flags *, bool);
269
270/*
271 * Transmit all the frames in the OA_BUFF_TX_READY state and receive the
272 * available chunks.
273 */
274int oa_tc6_thread(struct oa_tc6_desc *);
275
276/* Initialize the OA TC6 SPI driver */
277int oa_tc6_init(struct oa_tc6_desc **, struct oa_tc6_init_param *);
278
279/* Free the resources allocated by the oa_tc6_init() function */
280int oa_tc6_remove(struct oa_tc6_desc *);
281
282#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:151
@ OA_BUFF_RX_IN_PROGRESS
Definition oa_tc6.h:163
@ OA_BUFF_TX_READY
Definition oa_tc6.h:178
@ OA_BUFF_FREE
Definition oa_tc6.h:156
@ OA_BUFF_RX_COMPLETE
Definition oa_tc6.h:169
@ OA_BUFF_RX_USER_OWNED
Definition oa_tc6.h:172
@ OA_BUFF_TX_BUSY
Definition oa_tc6.h:175
#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:731
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:637
int oa_tc6_remove(struct oa_tc6_desc *)
Free a device descriptor.
Definition oa_tc6.c:764
#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:657
#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:213
uint32_t data_rx_credit
Definition oa_tc6.h:222
struct oa_tc6_flags xfer_flags
Definition oa_tc6.h:227
struct oa_tc6_frame_buffer user_rx_frame_buffer[OA_RX_FRAME_BUFF_NUM]
Definition oa_tc6.h:218
uint32_t ctrl_rx_credit
Definition oa_tc6.h:225
uint8_t ctrl_chunks[OA_SPI_CTRL_LEN]
Definition oa_tc6.h:215
bool prote_spi
Definition oa_tc6.h:228
struct no_os_spi_desc * comm_desc
Definition oa_tc6.h:214
uint8_t data_chunks[OA_SPI_BUFF_LEN]
Definition oa_tc6.h:216
uint32_t ctrl_tx_credit
Definition oa_tc6.h:224
struct oa_tc6_frame_buffer user_tx_frame_buffer[OA_TX_FRAME_BUFF_NUM]
Definition oa_tc6.h:219
uint32_t data_tx_credit
Definition oa_tc6.h:221
Stores the status flags which are provided as part of the footer during data transfers....
Definition oa_tc6.h:203
bool exst
Definition oa_tc6.h:205
bool flags_valid
Definition oa_tc6.h:204
bool hdrb
Definition oa_tc6.h:206
bool sync
Definition oa_tc6.h:207
Stores an Ethernet frame along with metadata needed for parsing. The MAC driver or the user applicati...
Definition oa_tc6.h:186
enum oa_tc6_user_buffer_state state
Definition oa_tc6.h:190
uint8_t data[CONFIG_OA_CHUNK_BUFFER_SIZE]
Definition oa_tc6.h:189
uint8_t vs
Definition oa_tc6.h:191
bool rtsp
Definition oa_tc6.h:195
uint8_t tsc
Definition oa_tc6.h:192
bool rtsa
Definition oa_tc6.h:194
bool frame_drop
Definition oa_tc6.h:193
uint32_t index
Definition oa_tc6.h:187
uint32_t len
Definition oa_tc6.h:188
Holds the initialization parameters for the OA TC6 driver.
Definition oa_tc6.h:234
bool prote_spi
Definition oa_tc6.h:238
struct no_os_spi_desc * comm_desc
Definition oa_tc6.h:235