Choco OS  V.0.16.9.0
Join to the chocolate world
oc_eth_lld.h
Go to the documentation of this file.
1 
32 #ifndef _OC_ETH_LLD_H
33 #define _OC_ETH_LLD_H
34 
35 #include <oc_machine.h>
36 #include <oc_errors.h>
37 #include <oc_frequency.h>
38 #include <oc_pins.h>
39 #include <oc_channels.h>
40 #include <oc_baudrate.h>
41 #include <oc_diag.h>
42 
43 #if oC_Channel_IsModuleDefined(ETH) && oC_ModulePinFunctions_IsModuleDefined(ETH) && oC_ModulePin_IsModuleDefined(ETH)
44 #define oC_ETH_LLD_AVAILABLE
45 
51 #define _________________________________________DEFINITIONS_SECTION________________________________________________________________________
52 
53 #define oC_ETH_LLD_ETHERNET_MTU 1500
54 #define oC_ETH_LLD_MAC_ADDRESS_LENGTH 6
55 
56 #undef _________________________________________DEFINITIONS_SECTION________________________________________________________________________
57 
58 
64 #define _________________________________________TYPES_SECTION______________________________________________________________________________
65 #define MODULE_NAME ETH
68 
69 
70 //==========================================================================================================================================
77 //==========================================================================================================================================
79 
80 //==========================================================================================================================================
87 //==========================================================================================================================================
88 oC_ModulePinFunction_DefineType;
89 
90 //==========================================================================================================================================
97 //==========================================================================================================================================
98 oC_ModulePin_DefineType;
99 //==========================================================================================================================================
105 //==========================================================================================================================================
106 typedef oC_ChannelIndex_t oC_ETH_LLD_ChannelIndex_t;
107 
108 //==========================================================================================================================================
112 //==========================================================================================================================================
113 typedef enum
114 {
115  oC_ETH_LLD_FrameSegment_First = (1<<0) ,
116  oC_ETH_LLD_FrameSegment_Last = (1<<1) ,
117  oC_ETH_LLD_FrameSegment_Single = (1<<0) | (1<<1),
118  oC_ETH_LLD_FrameSegment_Middle = 0,
119  oC_ETH_LLD_FrameSegment_NumberOfFrameSegments = 4,
120 } oC_ETH_LLD_FrameSegment_t;
121 
122 //==========================================================================================================================================
128 //==========================================================================================================================================
129 typedef enum
130 {
131  oC_ETH_LLD_PHY_CommunicationInterface_None ,
132  oC_ETH_LLD_PHY_CommunicationInterface_MII ,
133  oC_ETH_LLD_PHY_CommunicationInterface_RMII
134 } oC_ETH_LLD_PHY_CommunicationInterface_t;
135 
136 //==========================================================================================================================================
142 //==========================================================================================================================================
143 typedef enum
144 {
145  oC_ETH_LLD_AccessProtocol_CSMA_CD ,
146  oC_ETH_LLD_AccessProtocol_CSMA_CA ,
147  oC_ETH_LLD_AccessProtocol_ALOHA ,
148 } oC_ETH_LLD_AccessProtocol_t;
149 
150 //==========================================================================================================================================
156 //==========================================================================================================================================
157 typedef enum
158 {
159  oC_ETH_LLD_OperationMode_HalfDuplex ,
160  oC_ETH_LLD_OperationMode_FullDuplex ,
161 } oC_ETH_LLD_OperationMode_t;
162 
163 //==========================================================================================================================================
169 //==========================================================================================================================================
170 typedef struct
171 {
172  oC_ETH_LLD_PHY_CommunicationInterface_t CommunicationInterface;
173  oC_BaudRate_t PossibleBaudRates[5];
174 } oC_ETH_LLD_PHY_ChipInfo_t;
175 
176 //==========================================================================================================================================
180 //==========================================================================================================================================
181 typedef uint16_t oC_ETH_LLD_PHY_Address_t;
182 
183 //==========================================================================================================================================
187 //==========================================================================================================================================
188 typedef uint16_t oC_ETH_LLD_PHY_RegisterAddress_t;
189 
190 //==========================================================================================================================================
194 //==========================================================================================================================================
195 typedef struct
196 {
197  bool AutoGeneratePad;
198  bool AutoCalculateCrc;
199  oC_ETH_LLD_PHY_Address_t PhyAddress;
200  oC_BaudRate_t BaudRate;
201  oC_ETH_LLD_OperationMode_t OperationMode;
202  union
203  {
204  //==================================================================================================================================
208  //==================================================================================================================================
209  struct
210  {
211  oC_Pin_t Mdc;
212  oC_Pin_t Mdio;
213  oC_Pin_t RefClk;
214  oC_Pin_t RcsDv;
215  oC_Pin_t RxD0;
216  oC_Pin_t RxD1;
217  oC_Pin_t TxEn;
218  oC_Pin_t TxD0;
219  oC_Pin_t TxD1;
220  oC_Pin_t RxEr;
221  } Rmii;
222 
223  //==================================================================================================================================
227  //==================================================================================================================================
228  struct
229  {
230  oC_Pin_t Mdc;
231  oC_Pin_t Mdio;
232  oC_Pin_t Crs;
233  oC_Pin_t Col;
234  oC_Pin_t RxClk;
235  oC_Pin_t RxDv;
236  oC_Pin_t RxD0;
237  oC_Pin_t RxD1;
238  oC_Pin_t RxD2;
239  oC_Pin_t RxD3;
240  oC_Pin_t RxEr;
241  oC_Pin_t TxEn;
242  oC_Pin_t TxD0;
243  oC_Pin_t TxD1;
244  oC_Pin_t TxD2;
245  oC_Pin_t TxD3;
246  oC_Pin_t TxClk;
247  } Mii;
248  //==================================================================================================================================
252  //==================================================================================================================================
253  oC_Pin_t Pins[17];
254  };
255 
256 } oC_ETH_LLD_Config_t;
257 
258 //==========================================================================================================================================
262 //==========================================================================================================================================
263 typedef uint8_t oC_ETH_LLD_Payload_t[oC_ETH_LLD_ETHERNET_MTU];
264 
265 //==========================================================================================================================================
269 //==========================================================================================================================================
270 typedef uint8_t oC_ETH_LLD_MacAddress_t[oC_ETH_LLD_MAC_ADDRESS_LENGTH];
271 
272 
273 //==========================================================================================================================================
277 //==========================================================================================================================================
278 typedef struct
279 {
280 #if 0
281  uint8_t Preamble[7];
282  uint8_t StartOfFrameDelimiter;
283 #endif
284  oC_ETH_LLD_MacAddress_t DestinationAddress;
285  oC_ETH_LLD_MacAddress_t SourceAddress;
286  uint16_t DataLengthEtherType;
287  oC_ETH_LLD_Payload_t Data;
288  uint32_t CRC;
289 } oC_ETH_LLD_Frame_t;
290 
291 //==========================================================================================================================================
295 //==========================================================================================================================================
296 typedef struct Descriptor_t * oC_ETH_LLD_Descriptor_t;
297 
298 //==========================================================================================================================================
302 //==========================================================================================================================================
303 typedef enum
304 {
305  oC_ETH_LLD_InterruptSource_DataReceived = (1<<0) ,
306  oC_ETH_LLD_InterruptSource_ReceiveError = (1<<1) ,
307  oC_ETH_LLD_InterruptSource_TransmitError = (1<<2) ,
308  oC_ETH_LLD_InterruptSource_TransmissionSlotsAvailable = (1<<3) ,
309  oC_ETH_LLD_InterruptSource_FatalBusError = (1<<4) ,
310  oC_ETH_LLD_InterruptSource_ReceiveTimeout = (1<<5) ,
311  oC_ETH_LLD_InterruptSource_ReceiveProcessStopped = (1<<6) ,
312  oC_ETH_LLD_InterruptSource_ReceiveDescriptorError = (1<<7) ,
313  oC_ETH_LLD_InterruptSource_TransmitJabberTimeout = (1<<8) ,
314  oC_ETH_LLD_InterruptSource_TransmitDescriptorError = (1<<9) ,
315  oC_ETH_LLD_InterruptSource_TransmitProcessStopped = (1<<10) ,
316  oC_ETH_LLD_InterruptSource_ReceiveOverflowError = (1<<11) ,
317  oC_ETH_LLD_InterruptSource_TransmitUnderflowError = (1<<12) ,
318 } oC_ETH_LLD_InterruptSource_t;
319 
320 //==========================================================================================================================================
324 //==========================================================================================================================================
325 typedef void (*oC_ETH_LLD_InterruptFunction_t)( oC_ETH_LLD_InterruptSource_t Source );
326 
327 //==========================================================================================================================================
333 //==========================================================================================================================================
334 typedef struct
335 {
336  oC_Pin_t ConnectedPins[17];
337  uint32_t NumberOfMacAddresses;
338  struct
339  {
340  oC_MemorySize_t DescriptorSize;
341  uint32_t RingSize;
342  oC_MemorySize_t Alignment;
343  oC_ETH_LLD_Descriptor_t NextDescriptor;
344  uint32_t SegmentStarted;
345  } TxData, RxData;
346 } oC_ETH_LLD_Result_t;
347 
348 #undef MODULE_NAME
349 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
350 
357 #define _________________________________________MACROS_SECTION_____________________________________________________________________________
358 
359 
360 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________
361 
362 
368 #define _________________________________________FUNCTIONS_SECTION__________________________________________________________________________
369 
372 //==========================================================================================================================================
390 //==========================================================================================================================================
391 extern oC_ErrorCode_t oC_ETH_LLD_TurnOnDriver( void );
392 //==========================================================================================================================================
411 //==========================================================================================================================================
412 extern oC_ErrorCode_t oC_ETH_LLD_TurnOffDriver( void );
413 
414 //==========================================================================================================================================
434 //==========================================================================================================================================
435 extern oC_ErrorCode_t oC_ETH_LLD_SetInterruptHandler( oC_ETH_LLD_InterruptFunction_t Function );
436 
437 //==========================================================================================================================================
446 //==========================================================================================================================================
447 extern bool oC_ETH_LLD_IsAutoPadGenerationSupported( void );
448 
449 //==========================================================================================================================================
456 //==========================================================================================================================================
457 extern bool oC_ETH_LLD_IsAutoCalculateCrcSupported( void );
458 
459 //==========================================================================================================================================
471 //==========================================================================================================================================
472 extern oC_ErrorCode_t oC_ETH_LLD_InitializeMac( const oC_ETH_LLD_Config_t * Config , const oC_ETH_LLD_PHY_ChipInfo_t * ChipInfo , oC_ETH_LLD_Result_t * outResult );
473 
474 //==========================================================================================================================================
486 //==========================================================================================================================================
487 extern oC_ErrorCode_t oC_ETH_LLD_ReleaseMac( const oC_ETH_LLD_Config_t * Config , const oC_ETH_LLD_PHY_ChipInfo_t * ChipInfo , oC_ETH_LLD_Result_t * Result );
488 
489 //==========================================================================================================================================
501 //==========================================================================================================================================
502 extern oC_ErrorCode_t oC_ETH_LLD_ReadPhyRegister( oC_ETH_LLD_PHY_Address_t PhyAddress , oC_ETH_LLD_PHY_RegisterAddress_t RegisterAddress , uint32_t * outValue );
503 
504 //==========================================================================================================================================
516 //==========================================================================================================================================
517 extern oC_ErrorCode_t oC_ETH_LLD_WritePhyRegister( oC_ETH_LLD_PHY_Address_t PhyAddress , oC_ETH_LLD_PHY_RegisterAddress_t RegisterAddress , uint32_t Value );
518 
519 //==========================================================================================================================================
530 //==========================================================================================================================================
531 extern oC_ErrorCode_t oC_ETH_LLD_SetMacLoopback( bool Enabled );
532 
533 //==========================================================================================================================================
546 //==========================================================================================================================================
547 extern oC_ErrorCode_t oC_ETH_LLD_InitializeDescriptors( oC_ETH_LLD_Result_t * Result , const oC_ETH_LLD_Config_t * Config , oC_ETH_LLD_Descriptor_t Tx , oC_ETH_LLD_Descriptor_t Rx );
548 
549 //==========================================================================================================================================
560 //==========================================================================================================================================
561 extern oC_ErrorCode_t oC_ETH_LLD_InitializeDma( oC_ETH_LLD_Result_t * Result , const oC_ETH_LLD_Config_t * Config , oC_ETH_LLD_Descriptor_t Tx , oC_ETH_LLD_Descriptor_t Rx );
562 
563 //==========================================================================================================================================
573 //==========================================================================================================================================
574 extern oC_ErrorCode_t oC_ETH_LLD_Start( const oC_ETH_LLD_Config_t * Config );
575 // TODO: Interface for sending a pause frame
576 
577 // TODO: WoL support
578 
579 //==========================================================================================================================================
596 //==========================================================================================================================================
597 extern oC_ErrorCode_t oC_ETH_LLD_SendFrame( oC_ETH_LLD_Result_t * Result , const oC_ETH_LLD_MacAddress_t Source, const oC_ETH_LLD_MacAddress_t Destination, const void * Data , uint16_t Size , oC_ETH_LLD_FrameSegment_t FrameSegment , uint16_t EtherType );
598 
599 //==========================================================================================================================================
616 //==========================================================================================================================================
617 extern oC_ErrorCode_t oC_ETH_LLD_ReceiveFrame( oC_ETH_LLD_Result_t * Result , oC_ETH_LLD_MacAddress_t outSource, oC_ETH_LLD_MacAddress_t outDestination, void * Data , uint16_t * Size , oC_ETH_LLD_FrameSegment_t * outFrameSegment , uint16_t * outEtherType );
618 
619 //==========================================================================================================================================
632 //==========================================================================================================================================
633 extern oC_ErrorCode_t oC_ETH_LLD_SetMacAddress( oC_ETH_LLD_Result_t * Result , uint32_t MacAddressIndex, const oC_ETH_LLD_MacAddress_t Address );
634 
635 //==========================================================================================================================================
648 //==========================================================================================================================================
649 extern oC_ErrorCode_t oC_ETH_LLD_ReadMacAddress( oC_ETH_LLD_Result_t * Result , uint32_t MacAddressIndex, oC_ETH_LLD_MacAddress_t outAddress );
650 
651 //==========================================================================================================================================
655 //==========================================================================================================================================
656 extern bool oC_ETH_LLD_IsTransmitQueueFull( oC_ETH_LLD_Result_t * Result );
657 
658 //==========================================================================================================================================
662 //==========================================================================================================================================
663 extern bool oC_ETH_LLD_IsDataReadyToReceive( oC_ETH_LLD_Result_t * Result );
664 
665 //==========================================================================================================================================
677 //==========================================================================================================================================
678 extern oC_ErrorCode_t oC_ETH_LLD_PerformDiagnostics( oC_ETH_LLD_Result_t * Result , oC_Diag_t * Diag , uint32_t * NumberOfDiags );
679 
680 #undef _________________________________________FUNCTIONS_SECTION__________________________________________________________________________
681 
683 
684 #endif /* _OC_ETH_LLD_H */
685 #endif
The file with frequency definitions.
#define oC_ModuleChannel_DefineType
defines module channel type
Definition: oc_channels.h:541
oC_Channel_t
stores machine channel
Definition: oc_channels.h:573
The file with interface for the machine module.
Contains interface of the pins module.
The file with interface for Channel module.