1 /* 2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 /*******************************************************************************************************************//** 8 * @addtogroup ETHER 9 * @{ 10 **********************************************************************************************************************/ 11 12 #ifndef R_ETHER_H 13 #define R_ETHER_H 14 15 #include "bsp_api.h" 16 17 /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ 18 FSP_HEADER 19 20 /*********************************************************************************************************************** 21 * Includes 22 **********************************************************************************************************************/ 23 #include "r_ether_cfg.h" 24 #include "r_ether_api.h" 25 26 /*********************************************************************************************************************** 27 * Macro definitions 28 **********************************************************************************************************************/ 29 30 /*********************************************************************************************************************** 31 * Typedef definitions 32 **********************************************************************************************************************/ 33 typedef enum e_ether_previous_link_status 34 { 35 ETHER_PREVIOUS_LINK_STATUS_DOWN = 0, ///< Previous link status is down 36 ETHER_PREVIOUS_LINK_STATUS_UP = 1, ///< Previous link status is up 37 } ether_previous_link_status_t; 38 39 typedef enum e_ether_link_change 40 { 41 ETHER_LINK_CHANGE_NO_CHANGE = 0, ///< Link status is no change 42 ETHER_LINK_CHANGE_LINK_DOWN = 1, ///< Link status changes to down 43 ETHER_LINK_CHANGE_LINK_UP = 2, ///< Link status changes to up 44 } ether_link_change_t; 45 46 typedef enum e_ether_magic_packet 47 { 48 ETHER_MAGIC_PACKET_NOT_DETECTED = 0, ///< Magic packet is not detected 49 ETHER_MAGIC_PACKET_DETECTED = 1, ///< Magic packet is detected 50 } ether_magic_packet_t; 51 52 typedef enum e_ether_link_establish_status 53 { 54 ETHER_LINK_ESTABLISH_STATUS_DOWN = 0, ///< Link establish status is down 55 ETHER_LINK_ESTABLISH_STATUS_UP = 1, ///< Link establish status is up 56 } ether_link_establish_status_t; 57 58 /** EDMAC descriptor as defined in the hardware manual. 59 * Structure must be packed at 1 byte. 60 */ 61 typedef struct st_ether_instance_descriptor 62 { 63 volatile uint32_t status; 64 #if ((defined(__GNUC__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || (defined(__ARMCC_VERSION) && \ 65 !defined(__ARM_BIG_ENDIAN)) || (defined(__ICCARM__) && (__LITTLE_ENDIAN__))) 66 67 /* Little endian */ 68 volatile uint16_t size; 69 volatile uint16_t buffer_size; 70 #else 71 72 /* Big endian */ 73 volatile uint16_t buffer_size; 74 volatile uint16_t size; 75 #endif 76 uint8_t * p_buffer; 77 struct st_ether_instance_descriptor * p_next; 78 } ether_instance_descriptor_t; 79 80 /** ETHER extension configures the buffer descriptor for ETHER. */ 81 typedef struct st_ether_extended_cfg 82 { 83 ether_instance_descriptor_t * p_rx_descriptors; ///< Receive descriptor buffer pool 84 ether_instance_descriptor_t * p_tx_descriptors; ///< Transmit descriptor buffer pool 85 } ether_extended_cfg_t; 86 87 /** ETHER control block. DO NOT INITIALIZE. Initialization occurs when @ref ether_api_t::open is called. */ 88 typedef struct st_ether_instance_ctrl 89 { 90 uint32_t open; ///< Used to determine if the channel is configured 91 92 /* Configuration of ethernet module. */ 93 ether_cfg_t const * p_ether_cfg; ///< Pointer to initial configurations. 94 95 /* Buffer of ethernet module. */ 96 ether_instance_descriptor_t * p_rx_descriptor; ///< Pointer to the currently referenced transmit descriptor 97 ether_instance_descriptor_t * p_tx_descriptor; ///< Pointer to the currently referenced receive descriptor 98 99 /* Interface for PHY-LSI chip. */ 100 void * p_reg_etherc; ///< Base register of ethernet controller for this channel 101 void * p_reg_edmac; ///< Base register of EDMA controller for this channel 102 103 /* Status of ethernet driver. */ 104 ether_previous_link_status_t previous_link_status; ///< Previous link status 105 ether_link_change_t link_change; ///< status of link change 106 ether_magic_packet_t magic_packet; ///< status of magic packet detection 107 ether_link_establish_status_t link_establish_status; ///< Current Link status 108 uint32_t link_speed_duplex; ///< Current Link speed and duplex status 109 110 /* Pointer to callback and optional working memory */ 111 void (* p_callback)(ether_callback_args_t *); 112 ether_callback_args_t * p_callback_memory; 113 114 /* Pointer to context to be passed into callback function */ 115 void const * p_context; 116 } ether_instance_ctrl_t; 117 118 /* 119 * PauseMaskE, PauseValE and pause_resolutionS are use to create 120 * PAUSE resolution Table 28B-3 in IEEE 802.3-2008 standard. 121 */ 122 typedef enum e_ether_pause_mask 123 { 124 ETHER_PAUSE_MASK0, 125 ETHER_PAUSE_MASK1, 126 ETHER_PAUSE_MASK2, 127 ETHER_PAUSE_MASK3, 128 ETHER_PAUSE_MASK4, 129 ETHER_PAUSE_MASK5, 130 ETHER_PAUSE_MASK6, 131 ETHER_PAUSE_MASK7, 132 ETHER_PAUSE_MASK8, 133 ETHER_PAUSE_MASK9, 134 ETHER_PAUSE_MASKA, 135 ETHER_PAUSE_MASKB, 136 ETHER_PAUSE_MASKC, 137 ETHER_PAUSE_MASKD, 138 ETHER_PAUSE_MASKE, 139 ETHER_PAUSE_MASKF 140 } ether_pause_mask_t; 141 142 typedef enum e_ether_pause_val 143 { 144 ETHER_PAUSE_VAL0, 145 ETHER_PAUSE_VAL1, 146 ETHER_PAUSE_VAL2, 147 ETHER_PAUSE_VAL3, 148 ETHER_PAUSE_VAL4, 149 ETHER_PAUSE_VAL5, 150 ETHER_PAUSE_VAL6, 151 ETHER_PAUSE_VAL7, 152 ETHER_PAUSE_VAL8, 153 ETHER_PAUSE_VAL9, 154 ETHER_PAUSE_VALA, 155 ETHER_PAUSE_VALB, 156 ETHER_PAUSE_VALC, 157 ETHER_PAUSE_VALD, 158 ETHER_PAUSE_VALE, 159 ETHER_PAUSE_VALF 160 } ether_pause_val_t; 161 162 typedef struct st_ether_pause_resolution 163 { 164 ether_pause_mask_t mask; 165 ether_pause_val_t value; 166 uint8_t transmit; 167 uint8_t receive; 168 } ether_pause_resolution_t; 169 170 /********************************************************************************************************************** 171 * Exported global variables 172 **********************************************************************************************************************/ 173 174 /** @cond INC_HEADER_DEFS_SEC */ 175 /** Filled in Interface API structure for this Instance. */ 176 extern const ether_api_t g_ether_on_ether; 177 178 /** @endcond */ 179 180 /********************************************************************************************************************** 181 * Public Function Prototypes 182 **********************************************************************************************************************/ 183 fsp_err_t R_ETHER_Open(ether_ctrl_t * const p_ctrl, ether_cfg_t const * const p_cfg); 184 185 fsp_err_t R_ETHER_Close(ether_ctrl_t * const p_ctrl); 186 187 fsp_err_t R_ETHER_Read(ether_ctrl_t * const p_ctrl, void * const p_buffer, uint32_t * const length_bytes); 188 189 fsp_err_t R_ETHER_BufferRelease(ether_ctrl_t * const p_ctrl); 190 191 fsp_err_t R_ETHER_RxBufferUpdate(ether_ctrl_t * const p_ctrl, void * const p_buffer); 192 193 fsp_err_t R_ETHER_Write(ether_ctrl_t * const p_ctrl, void * const p_buffer, uint32_t const frame_length); 194 195 fsp_err_t R_ETHER_LinkProcess(ether_ctrl_t * const p_ctrl); 196 197 fsp_err_t R_ETHER_WakeOnLANEnable(ether_ctrl_t * const p_ctrl); 198 199 fsp_err_t R_ETHER_TxStatusGet(ether_ctrl_t * const p_ctrl, void * const p_buffer_address); 200 201 fsp_err_t R_ETHER_CallbackSet(ether_ctrl_t * const p_api_ctrl, 202 void ( * p_callback)(ether_callback_args_t *), 203 void const * const p_context, 204 ether_callback_args_t * const p_callback_memory); 205 206 /*******************************************************************************************************************//** 207 * @} (end addtogroup ETHER) 208 **********************************************************************************************************************/ 209 210 /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ 211 FSP_FOOTER 212 213 #endif // R_ETHER_H 214