Choco OS  V.0.16.9.0
Join to the chocolate world
oc_eth.c
Go to the documentation of this file.
1 
30 #include <oc_eth.h>
31 #include <oc_eth_lld.h>
32 #include <oc_compiler.h>
33 #include <oc_module.h>
34 #include <oc_intman.h>
35 #include <oc_null.h>
36 #include <oc_gpio.h>
37 #include <oc_stdio.h>
38 #include <oc_string.h>
39 #include <oc_eth_phy.h>
40 #include <oc_debug.h>
41 #include <oc_mutex.h>
42 #include <oc_ktime.h>
43 #include <oc_math.h>
44 
45 #ifdef oC_ETH_LLD_AVAILABLE
46 
52 #define _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________
53 
54 #define DRIVER_SOURCE
55 
56 /* Driver basic definitions */
57 #define DRIVER_NAME ETH
58 #define DRIVER_FILE_NAME "eth"
59 #define DRIVER_TYPE NETWORK_DRIVER
60 #define DRIVER_VERSION oC_Driver_MakeVersion(1,0,0)
61 #define REQUIRED_DRIVERS &GPIO
62 #define REQUIRED_BOOT_LEVEL oC_Boot_Level_RequireMemoryManager | oC_Boot_Level_RequireDriversManager | oC_Boot_Level_RequireNetwork
63 
64 /* Driver interface definitions */
65 #define DRIVER_CONFIGURE oC_ETH_Configure
66 #define DRIVER_UNCONFIGURE oC_ETH_Unconfigure
67 #define DRIVER_TURN_ON oC_ETH_TurnOn
68 #define DRIVER_TURN_OFF oC_ETH_TurnOff
69 #define IS_TURNED_ON oC_ETH_IsTurnedOn
70 #define SEND_FRAME oC_ETH_SendFrame
71 #define RECEIVE_FRAME oC_ETH_ReceiveFrame
72 #define SET_WAKE_ON_LAN_EVENT oC_ETH_SetWakeOnLanEvent
73 #define FLUSH oC_ETH_Flush
74 #define SET_LOOPBACK oC_ETH_SetLoopback
75 #define PERFORM_DIAGNOSTIC oC_ETH_PerformDiagnostics
76 #define READ_NET_INFO oC_ETH_ReadNetInfo
77 
78 #undef _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________
79 
80 /* This header must be always at the end of include list */
81 #include <oc_driver.h>
82 
88 #define _________________________________________TYPES_SECTION______________________________________________________________________________
89 
90 //==========================================================================================================================================
96 //==========================================================================================================================================
97 struct Context_t
98 {
101  oC_ETH_LLD_Result_t Result;
105  oC_MemorySize_t ReceivedBytes;
106  oC_MemorySize_t TransmittedBytes;
108  oC_BaudRate_t BaudRate;
109  oC_ETH_LLD_Descriptor_t RxDescriptorRing;
110  oC_ETH_LLD_Descriptor_t TxDescriptorRing;
113 };
114 
115 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
116 
122 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
123 
124 static inline bool IsContextCorrect ( oC_ETH_Context_t Context );
125 static oC_ErrorCode_t CreateContext ( const oC_ETH_Config_t * Config , oC_ETH_Context_t * outContext );
126 static oC_ErrorCode_t DeleteContext ( oC_ETH_Context_t * outContext );
127 static oC_ErrorCode_t InitializePhy ( const oC_ETH_Config_t * Config , oC_ETH_Context_t Context );
128 static oC_ErrorCode_t ReleasePhy ( const oC_ETH_Config_t * Config , oC_ETH_Context_t Context );
130 static oC_ErrorCode_t AllocateDescriptors ( oC_ETH_Context_t Context );
131 static oC_ErrorCode_t ReleaseDescriptors ( oC_ETH_Context_t Context );
132 static void InterruptHandler ( oC_ETH_LLD_InterruptSource_t Source );
133 static oC_ErrorCode_t SendFrame ( oC_ETH_Context_t Context , const oC_Net_MacAddress_t Source, const oC_Net_MacAddress_t Destination , const void * Data , uint16_t Size , oC_ETH_LLD_FrameSegment_t FrameSegment , oC_Net_FrameType_t FrameType , oC_Time_t Timeout );
134 static oC_ErrorCode_t ReceiveFrame ( oC_ETH_Context_t Context , oC_Net_MacAddress_t outSource, oC_Net_MacAddress_t outDestination, void * Data, uint16_t * Size, oC_ETH_LLD_FrameSegment_t * outFrameSegment , oC_Net_FrameType_t * outFrameType , oC_Time_t Timeout );
135 
136 static oC_ErrorCode_t PerformPhyRegisterAccessTest ( oC_Diag_t * Diag , void * Context );
137 
138 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
139 
145 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________
146 
147 //==========================================================================================================================================
151 //==========================================================================================================================================
152 static const oC_Allocator_t Allocator = {
153  .Name = "eth module"
154 };
155 //==========================================================================================================================================
159 //==========================================================================================================================================
161 //==========================================================================================================================================
165 //==========================================================================================================================================
167 //==========================================================================================================================================
171 //==========================================================================================================================================
173  { .Name = "PHY register access test" , .PerformFunction = PerformPhyRegisterAccessTest } ,
174 };
175 
176 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________
177 
178 
184 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
185 
190 //==========================================================================================================================================
199 //==========================================================================================================================================
200 oC_ErrorCode_t oC_ETH_TurnOn( void )
201 {
202  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
203 
204  if(oC_Module_TurnOffVerification(&errorCode , oC_Module_ETH))
205  {
206 
207  errorCode = oC_ETH_LLD_TurnOnDriver();
208 
209  if(errorCode == oC_ErrorCode_ModuleIsTurnedOn)
210  {
211  errorCode = oC_ErrorCode_None;
212  }
213 
214  if(!oC_ErrorOccur(errorCode))
215  {
216  DataReadyToRead = oC_Event_New(oC_Event_State_Inactive, &Allocator, AllocationFlags_ZeroFill);
217  ModuleReadyToSend = oC_Event_New(oC_Event_State_Active, &Allocator, AllocationFlags_ZeroFill);
218 
219  if(
220  ErrorCode ( oC_ETH_LLD_SetInterruptHandler( InterruptHandler ) )
221  && ErrorCondition ( DataReadyToRead != NULL, oC_ErrorCode_AllocationError )
222  && ErrorCondition ( ModuleReadyToSend != NULL, oC_ErrorCode_AllocationError )
223  )
224  {
225  /* This must be always at the end of the function */
226  oC_Module_TurnOn(oC_Module_ETH);
227  errorCode = oC_ErrorCode_None;
228  }
229  else
230  {
231  oC_SaveIfFalse("ETH:TurnOn - Cannot delete event DataReadyToRead" , oC_Event_Delete(&DataReadyToRead, AllocationFlags_CanWait1Second), oC_ErrorCode_ReleaseError);
232  oC_SaveIfFalse("ETH:TurnOn - Cannot delete event ModuleReadyToSend", oC_Event_Delete(&ModuleReadyToSend, AllocationFlags_CanWait1Second), oC_ErrorCode_ReleaseError);
233  }
234  }
235  }
236 
237  return errorCode;
238 }
239 
240 //==========================================================================================================================================
249 //==========================================================================================================================================
250 oC_ErrorCode_t oC_ETH_TurnOff( void )
251 {
252  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
253 
254  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_ETH))
255  {
256  /* This must be at the start of the function */
257  oC_Module_TurnOff(oC_Module_ETH);
258 
259  errorCode = oC_ETH_LLD_TurnOffDriver();
260 
261  if(
262  errorCode == oC_ErrorCode_ModuleNotStartedYet)
263  {
264 
265  errorCode = oC_ErrorCode_None;
266  }
267 
268  oC_SaveIfFalse("ETH:TurnOn - Cannot delete event DataReadyToRead" , oC_Event_Delete(&DataReadyToRead, AllocationFlags_CanWait1Second), oC_ErrorCode_ReleaseError);
269  oC_SaveIfFalse("ETH:TurnOn - Cannot delete event ModuleReadyToSend", oC_Event_Delete(&ModuleReadyToSend, AllocationFlags_CanWait1Second), oC_ErrorCode_ReleaseError);
270  }
271 
272  return errorCode;
273 }
274 
275 //==========================================================================================================================================
281 //==========================================================================================================================================
282 bool oC_ETH_IsTurnedOn( void )
283 {
284  return oC_Module_IsTurnedOn(oC_Module_ETH);
285 }
286 
287 //==========================================================================================================================================
308 //==========================================================================================================================================
309 oC_ErrorCode_t oC_ETH_Configure( const oC_ETH_Config_t * Config , oC_ETH_Context_t * outContext )
310 {
311  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
312 
313  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_ETH))
314  {
315  oC_ETH_Context_t context = NULL;
316 
317  if(
318  ErrorCondition( isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress )
319  && ErrorCondition( isaddresscorrect(Config->PhyChipInfo) , oC_ErrorCode_ChipNotDefined )
320  && ErrorCondition( isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM )
321  && ErrorCode ( CreateContext(Config,&context) )
322  )
323  {
324  if(
325  ErrorCode( oC_ETH_LLD_InitializeMac ( &Config->LLD , &Config->PhyChipInfo->LLD , &context->Result ))
326  && ErrorCode( InitializePhy ( Config, context ))
327  && ErrorCode( AllocateDescriptors ( context ))
328  && ErrorCode( oC_ETH_LLD_InitializeDescriptors ( &context->Result , &Config->LLD, context->TxDescriptorRing , context->RxDescriptorRing ))
329  && ErrorCode( oC_ETH_LLD_InitializeDma ( &context->Result , &Config->LLD, context->TxDescriptorRing , context->RxDescriptorRing ))
330  && ErrorCode( oC_ETH_LLD_SetMacAddress ( &context->Result , 0 , Config->MacAddress ))
331  && ErrorCode( oC_ETH_LLD_Start ( &Config->LLD ))
332  )
333  {
334  *outContext = context;
335  errorCode = oC_ErrorCode_None;
336  }
337  else
338  {
339  oC_SaveIfErrorOccur("ETH: Cannot release PHY - ", ReleasePhy( Config , context ));
340  oC_SaveIfErrorOccur("ETH: Cannot release MAC - ", oC_ETH_LLD_ReleaseMac( &Config->LLD , &Config->PhyChipInfo->LLD , &context->Result ));
341  oC_SaveIfErrorOccur("ETH: Cannot delete context - ", DeleteContext( &context ));
342  }
343  }
344  }
345 
346  return errorCode;
347 }
348 
349 //==========================================================================================================================================
360 //==========================================================================================================================================
361 oC_ErrorCode_t oC_ETH_Unconfigure( const oC_ETH_Config_t * Config , oC_ETH_Context_t * outContext )
362 {
363  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
364 
365  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_ETH))
366  {
367  if(
368  ErrorCondition( isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress )
369  && ErrorCondition( isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM )
370  && ErrorCondition( IsContextCorrect(*outContext) , oC_ErrorCode_ContextNotCorrect )
371  && ErrorCode ( ReleasePhy(Config,*outContext) )
372  && ErrorCode ( oC_ETH_LLD_ReleaseMac(&Config->LLD, &Config->PhyChipInfo->LLD, &(*outContext)->Result) )
373  && ErrorCode ( ReleaseDescriptors(*outContext) )
374  && ErrorCode ( DeleteContext(outContext) )
375  )
376  {
377  errorCode = oC_ErrorCode_None;
378  }
379  }
380 
381  return errorCode;
382 }
383 
384 //==========================================================================================================================================
407 //==========================================================================================================================================
408 oC_ErrorCode_t oC_ETH_SendFrame( oC_ETH_Context_t Context , const oC_Net_Frame_t * Frame , oC_Time_t Timeout )
409 {
410  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
411 
412  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_ETH))
413  {
414  if(
415  ErrorCondition( IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect )
416  && ErrorCondition( isaddresscorrect(Frame) , oC_ErrorCode_WrongAddress )
417  && ErrorCondition( isaddresscorrect(Frame->Packet) , oC_ErrorCode_WrongAddress )
418  && ErrorCondition( Frame->Size > 0 , oC_ErrorCode_SizeNotCorrect )
419  && ErrorCondition( Timeout >= 0 , oC_ErrorCode_TimeNotCorrect )
420  && ErrorCondition( Frame->FrameType > 0 , oC_ErrorCode_FrameTypeNotSupported )
421  )
422  {
423  uint8_t * data = (uint8_t*)Frame->Packet;
424  uint16_t size = oC_MIN(Frame->Size , IEEE_802_3_ETHERNET_MTU);
425  uint16_t sentBytes = 0;
426  uint16_t bytesToSend = Frame->Size;
427  oC_ETH_LLD_FrameSegment_t frameSegment = Frame->Size > IEEE_802_3_ETHERNET_MTU ? oC_ETH_LLD_FrameSegment_First : oC_ETH_LLD_FrameSegment_Single;
428  oC_Timestamp_t startTimestamp = oC_KTime_GetCurrentTick();
429  oC_Timestamp_t endTimestamp = startTimestamp + Timeout;
430 
431  errorCode = oC_ErrorCode_None;
432 
433  while(
434  bytesToSend > 0
435  && ErrorCode ( SendFrame( Context, Context->MacAddress , Frame->Destination.MacAddress , &data[sentBytes], size, frameSegment, Frame->FrameType, Timeout) )
436  && ErrorCondition( endTimestamp > oC_KTime_GetTimestamp() , oC_ErrorCode_Timeout )
437  )
438  {
439  sentBytes += size;
440  size = oC_MIN(bytesToSend , IEEE_802_3_ETHERNET_MTU);
441  bytesToSend = (bytesToSend > sentBytes) ? bytesToSend - sentBytes : 0;
442  frameSegment = bytesToSend < IEEE_802_3_ETHERNET_MTU ? oC_ETH_LLD_FrameSegment_Last : oC_ETH_LLD_FrameSegment_Middle;
443 
444  Timeout = endTimestamp - oC_KTime_GetCurrentTick();
445  }
446 
447  Context->TransmittedBytes += sentBytes;
448  }
449  }
450 
451  return errorCode;
452 }
453 
454 //==========================================================================================================================================
481 //==========================================================================================================================================
482 oC_ErrorCode_t oC_ETH_ReceiveFrame( oC_ETH_Context_t Context , oC_Net_Frame_t * outFrame , oC_Time_t Timeout )
483 {
484  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
485 
486  if(oC_Module_TurnOnVerification(&errorCode, oC_Module_ETH))
487  {
488  if(
489  ErrorCondition( IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect )
490  && ErrorCondition( isram(outFrame) , oC_ErrorCode_OutputAddressNotInRAM )
491  && ErrorCondition( Timeout >= 0 , oC_ErrorCode_TimeNotCorrect )
492  && ErrorCondition( isram(outFrame->Packet) , oC_ErrorCode_OutputAddressNotInRAM )
493  && ErrorCondition( outFrame->Size > 0 , oC_ErrorCode_SizeNotCorrect )
494  )
495  {
496  if(ErrorCondition( oC_Mutex_Take(Context->ContextBusyMutex,Timeout) , oC_ErrorCode_Timeout ))
497  {
498  uint8_t * buffer = (uint8_t*)outFrame->Packet;
499  uint16_t receivedBytes = 0;
500  oC_Time_t startTimestamp = oC_KTime_GetTimestamp();
501  oC_Time_t endTimestamp = startTimestamp + Timeout;
502  uint16_t leftBufferSize = outFrame->Size;
503  oC_ETH_LLD_FrameSegment_t frameSegment = oC_ETH_LLD_FrameSegment_NumberOfFrameSegments;
504  bool frameStarted = false;
505  oC_Net_FrameType_t frameType = 0;
506 
507  while(
508  ErrorCondition( receivedBytes < outFrame->Size , oC_ErrorCode_OutputBufferTooSmall )
509  && ErrorCondition( oC_KTime_GetTimestamp() <= endTimestamp , oC_ErrorCode_Timeout )
510  )
511  {
512  if( ErrorCode( ReceiveFrame( Context, outFrame->Source.MacAddress, outFrame->Destination.MacAddress, &buffer[receivedBytes], &leftBufferSize, &frameSegment, &frameType, Timeout ) ) )
513  {
514  Context->ReceivedBytes += leftBufferSize;
515 
516  if((frameSegment & oC_ETH_LLD_FrameSegment_First) || frameStarted)
517  {
518  if(frameSegment & oC_ETH_LLD_FrameSegment_First)
519  {
520  outFrame->Source.Filled = true;
521  outFrame->Destination.Filled = true;
522  outFrame->FrameType = frameType;
523  }
524  frameStarted = true;
525  receivedBytes += leftBufferSize;
526 
527  if(frameSegment & oC_ETH_LLD_FrameSegment_Last)
528  {
529  errorCode = oC_ErrorCode_None;
530  break;
531  }
532  }
533  leftBufferSize = outFrame->Size - receivedBytes;
534  kdebuglog( oC_LogType_Info, "ETH: skipping not started frame from 0x%X\n", outFrame->Packet->IPv4.Header.SourceIp );
535  }
536 
537  Timeout = endTimestamp - oC_KTime_GetTimestamp();
538  }
539 
540  oC_Mutex_Give(Context->ContextBusyMutex);
541  }
542  }
543  }
544 
545  return errorCode;
546 }
547 
548 //==========================================================================================================================================
549 //==========================================================================================================================================
550 oC_ErrorCode_t oC_ETH_SetWakeOnLanEvent( oC_ETH_Context_t Context , oC_Event_t WolEvent )
551 {
552  return oC_ErrorCode_NotImplemented;
553 }
554 
555 //==========================================================================================================================================
556 //==========================================================================================================================================
557 oC_ErrorCode_t oC_ETH_Flush( oC_ETH_Context_t Context )
558 {
559  return oC_ErrorCode_NotImplemented;
560 }
561 
562 //==========================================================================================================================================
582 //==========================================================================================================================================
583 oC_ErrorCode_t oC_ETH_SetLoopback( oC_ETH_Context_t Context , oC_Net_Layer_t Layer , bool Enabled )
584 {
585  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
586 
587  if(oC_Module_TurnOnVerification(&errorCode, oC_Module_ETH))
588  {
589  if(
590  ErrorCondition( IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect )
591  && ErrorCondition( oC_Net_IsMainLayer(Layer,oC_Net_Layer_Physical) ||
592  oC_Net_IsMainLayer(Layer,oC_Net_Layer_DataLink) , oC_ErrorCode_WrongLayer )
593  )
594  {
596  {
597  if(
598  ErrorCode( oC_ETH_SetPhyLoopback(Context->PhyAddress,Enabled) )
599  )
600  {
601  Context->LoopbackLayer = (Enabled) ? Layer : 0;
602  errorCode = oC_ErrorCode_None;
603  }
604  }
605  else
606  {
607  if(
608  ErrorCode( oC_ETH_LLD_SetMacLoopback(Enabled) )
609  )
610  {
611  Context->LoopbackLayer = (Enabled) ? Layer : 0;
612  errorCode = oC_ErrorCode_None;
613  }
614  }
615  }
616  }
617 
618  return errorCode;
619 }
620 
621 //==========================================================================================================================================
643 //==========================================================================================================================================
644 oC_ErrorCode_t oC_ETH_PerformDiagnostics( oC_ETH_Context_t Context , oC_Diag_t * Diags , uint32_t * NumberOfDiags )
645 {
646  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
647 
648  if(oC_Module_TurnOnVerification(&errorCode, oC_Module_ETH))
649  {
650  if(
651  ErrorCondition( IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect )
652  && ErrorCondition( isram(NumberOfDiags) , oC_ErrorCode_OutputAddressNotInRAM )
653  && ErrorCondition( Diags == NULL || isram(Diags) , oC_ErrorCode_OutputAddressNotInRAM )
654  && ErrorCondition( Diags == NULL || Diags->PrintFunction == NULL || isaddresscorrect(Diags->PrintFunction) , oC_ErrorCode_WrongAddress )
655  )
656  {
657  if(Diags != NULL)
658  {
659  uint32_t diagsSize = *NumberOfDiags;
660 
661  if( ErrorCondition( oC_Mutex_Take(Context->ContextBusyMutex, s(1)) , oC_ErrorCode_Timeout ) )
662  {
663  if(ErrorCode( oC_ETH_LLD_PerformDiagnostics( &Context->Result, Diags, NumberOfDiags ) ))
664  {
665  errorCode = oC_Diag_PerformDiagnostics( SupportedDiagsArray, &Diags[*NumberOfDiags], diagsSize - (*NumberOfDiags), Context->ChipName, Context );
666  *NumberOfDiags += oC_Diag_GetNumberOfSupportedDiagnostics(SupportedDiagsArray);
667  }
668  oC_Mutex_Give(Context->ContextBusyMutex);
669  }
670 
671  }
672  else
673  {
674  *NumberOfDiags = 0;
675 
676  if( ErrorCode( oC_ETH_LLD_PerformDiagnostics( &Context->Result, NULL, NumberOfDiags) ) )
677  {
678  *NumberOfDiags += oC_Diag_GetNumberOfSupportedDiagnostics(SupportedDiagsArray);
679  errorCode = oC_ErrorCode_None;
680  }
681  }
682  }
683  }
684 
685  return errorCode;
686 }
687 
688 //==========================================================================================================================================
708 //==========================================================================================================================================
709 oC_ErrorCode_t oC_ETH_ReadNetInfo( oC_ETH_Context_t Context , oC_Net_Info_t * outInfo )
710 {
711  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
712 
713  if(oC_Module_TurnOnVerification(&errorCode, oC_Module_ETH))
714  {
715  if(
716  ErrorCondition( IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect )
717  && ErrorCondition( isram(outInfo) , oC_ErrorCode_OutputAddressNotInRAM )
718  )
719  {
720  strncpy(outInfo->InterfaceName, Context->InterfaceName, sizeof(outInfo->InterfaceName ));
721  memcpy( outInfo->HardwareAddress.MacAddress, Context->MacAddress, sizeof(outInfo->HardwareAddress ));
722 
723  oC_Net_MacAddressFromString("FF:FF:FF:FF:FF:FF", outInfo->HardwareBroadcastAddress.MacAddress);
724 
725  outInfo->HardwareBroadcastAddress.Filled = true;
726  outInfo->HardwareAddress.Filled = true;
727  outInfo->DriverName = ETH.FileName;
729  outInfo->LinkStatus = GetLinkStatus(Context);
730  outInfo->ReceivedBytes = Context->ReceivedBytes;
731  outInfo->TransmittedBytes = Context->TransmittedBytes;
732  outInfo->BaudRate = Context->BaudRate;
733  outInfo->HardwareAddressLength = sizeof(oC_Net_MacAddress_t);
735 
736  if(ErrorCode(oC_ETH_ReadLinkStatus(Context->PhyAddress,&outInfo->LinkStatus)))
737  {
738  if(outInfo->LinkStatus == oC_Net_LinkStatus_Up && Context->LoopbackLayer == 0)
739  {
740  errorCode = oC_ETH_SetAutoNegotiation(Context->PhyAddress,true,ms(500));
741  }
742  else
743  {
744  errorCode = oC_ErrorCode_None;
745  }
746  }
747  }
748  }
749 
750  return errorCode;
751 }
752 
753 //==========================================================================================================================================
763 //==========================================================================================================================================
765 {
766  return IsContextCorrect(Context);
767 }
768 
770 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
771 
777 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
778 
779 //==========================================================================================================================================
783 //==========================================================================================================================================
784 static inline bool IsContextCorrect( oC_ETH_Context_t Context )
785 {
786  return isram(Context) && oC_CheckObjectControl(Context,oC_ObjectId_ETHContext,Context->ObjectControl);
787 }
788 
789 //==========================================================================================================================================
793 //==========================================================================================================================================
794 static oC_ErrorCode_t CreateContext( const oC_ETH_Config_t * Config , oC_ETH_Context_t * outContext )
795 {
796  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
797  oC_ETH_Context_t context = kmalloc( sizeof(struct Context_t), &Allocator, AllocationFlags_ZeroFill );
798 
799  if(
800  ErrorCondition( context != NULL , oC_ErrorCode_AllocationError )
801  && ErrorCondition( strlen(Config->PhyChipInfo->Name) > 0 , oC_ErrorCode_ChipNameNotDefined )
802  )
803  {
804  context->ObjectControl = oC_CountObjectControl(context,oC_ObjectId_ETHContext);
805  context->PhyAddress = Config->PhyAddress;
806  context->BaudRate = 0;
807  context->ContextBusyMutex = oC_Mutex_New(oC_Mutex_Type_Normal,&Allocator,AllocationFlags_CanWait1Second);
808  context->LoopbackLayer = 0;
809 
810  if(ErrorCondition( context->ContextBusyMutex != NULL, oC_ErrorCode_AllocationError ))
811  {
812  strcpy(context->ChipName,Config->PhyChipInfo->Name);
813  memcpy(context->MacAddress, Config->MacAddress, sizeof(oC_Net_MacAddress_t));
814 
815  *outContext = context;
816  errorCode = oC_Net_PrepareInterfaceName(&context->InterfaceName,context->ChipName,context->PhyAddress);
817  }
818  else
819  {
820  oC_SaveIfFalse("ETH::CreateContext - Cannot release context memory - ", kfree(context,AllocationFlags_CanWait1Second), oC_ErrorCode_ReleaseError);
821  }
822  }
823 
824  return errorCode;
825 }
826 
827 //==========================================================================================================================================
831 //==========================================================================================================================================
832 static oC_ErrorCode_t DeleteContext( oC_ETH_Context_t * outContext )
833 {
834  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
835  oC_ETH_Context_t context = *outContext;
836 
837  context->ObjectControl = 0;
838 
839  if(
840  ErrorCondition( oC_Mutex_Delete(&context->ContextBusyMutex, AllocationFlags_CanWait1Second) , oC_ErrorCode_ReleaseError )
841  && ErrorCondition( kfree(context, AllocationFlags_CanWait1Second) , oC_ErrorCode_ReleaseError )
842  )
843  {
844  *outContext = NULL;
845  errorCode = oC_ErrorCode_None;
846  }
847 
848  return errorCode;
849 }
850 
851 //==========================================================================================================================================
855 //==========================================================================================================================================
856 static oC_ErrorCode_t InitializePhy( const oC_ETH_Config_t * Config , oC_ETH_Context_t Context )
857 {
858  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
859 
860  if(
861  ErrorCode( oC_ETH_PhyReset ( Context->PhyAddress ) )
862  && ErrorCode( oC_ETH_SetAutoNegotiation ( Context->PhyAddress , true, 0 ) )
863  )
864  {
865  errorCode = oC_ErrorCode_None;
866  }
867 
868  return errorCode;
869 }
870 
871 //==========================================================================================================================================
875 //==========================================================================================================================================
876 static oC_ErrorCode_t ReleasePhy( const oC_ETH_Config_t * Config , oC_ETH_Context_t Context )
877 {
878  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
879 
880 
881 
882  return errorCode;
883 }
884 
885 //==========================================================================================================================================
889 //==========================================================================================================================================
891 {
893 
894  oC_SaveIfErrorOccur( "ETH:Cannot get link status - " , oC_ETH_ReadLinkStatus(Context->PhyAddress,&linkStatus) );
895 
896  return linkStatus;
897 }
898 
899 //==========================================================================================================================================
903 //==========================================================================================================================================
904 static oC_ErrorCode_t AllocateDescriptors( oC_ETH_Context_t Context )
905 {
906  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
907 
908  if(
909  ErrorCondition( Context->Result.RxData.Alignment > 0 , oC_ErrorCode_AlignmentNotCorrect )
910  && ErrorCondition( Context->Result.TxData.Alignment > 0 , oC_ErrorCode_AlignmentNotCorrect )
911  && ErrorCondition( Context->Result.RxData.DescriptorSize > 0 , oC_ErrorCode_SizeNotCorrect )
912  && ErrorCondition( Context->Result.TxData.DescriptorSize > 0 , oC_ErrorCode_SizeNotCorrect )
913  && ErrorCondition( Context->Result.RxData.RingSize > 0 , oC_ErrorCode_SizeNotCorrect )
914  && ErrorCondition( Context->Result.TxData.RingSize > 0 , oC_ErrorCode_SizeNotCorrect )
915  )
916  {
917  AllocationFlags_t allocationFlags = AllocationFlags_ZeroFill
918  | AllocationFlags_UseInternalRam
919  | AllocationFlags_UseDmaRam
920  | AllocationFlags_DmaRamFirst;
921 
922  Context->RxDescriptorRing = kamalloc(Context->Result.RxData.DescriptorSize * Context->Result.RxData.RingSize,
923  &Allocator, allocationFlags, Context->Result.RxData.Alignment);
924  Context->TxDescriptorRing = kamalloc(Context->Result.TxData.DescriptorSize * Context->Result.TxData.RingSize ,
925  &Allocator, allocationFlags, Context->Result.TxData.Alignment);
926  if(
927  ErrorCondition( Context->RxDescriptorRing != NULL , oC_ErrorCode_AllocationError )
928  && ErrorCondition( Context->TxDescriptorRing != NULL , oC_ErrorCode_AllocationError )
929  )
930  {
931  errorCode = oC_ErrorCode_None;
932  }
933  else
934  {
935  kafree(Context->RxDescriptorRing, AllocationFlags_CanWait1Second);
936  kafree(Context->TxDescriptorRing, AllocationFlags_CanWait1Second);
937  }
938  }
939 
940  return errorCode;
941 }
942 
943 //==========================================================================================================================================
947 //==========================================================================================================================================
948 static oC_ErrorCode_t ReleaseDescriptors( oC_ETH_Context_t Context )
949 {
950  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
951 
952  if(
953  ErrorCondition( kafree(Context->RxDescriptorRing, AllocationFlags_CanWait1Second ) , oC_ErrorCode_ReleaseError )
954  && ErrorCondition( kafree(Context->TxDescriptorRing, AllocationFlags_CanWait1Second ) , oC_ErrorCode_ReleaseError )
955  )
956  {
957  errorCode = oC_ErrorCode_None;
958  }
959 
960  return errorCode;
961 }
962 
963 //==========================================================================================================================================
967 //==========================================================================================================================================
968 static oC_ErrorCode_t SendFrame( oC_ETH_Context_t Context , const oC_Net_MacAddress_t Source, const oC_Net_MacAddress_t Destination , const void * Data , uint16_t Size , oC_ETH_LLD_FrameSegment_t FrameSegment, oC_Net_FrameType_t FrameType , oC_Time_t Timeout )
969 {
970  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
971 
972  oC_Procedure_Begin
973  {
974  oC_IntMan_EnterCriticalSection();
975  if(oC_ETH_LLD_IsTransmitQueueFull(&Context->Result))
976  {
977  oC_Event_SetState(ModuleReadyToSend,oC_Event_State_Inactive);
978  }
979  else
980  {
981  oC_Event_SetState(ModuleReadyToSend,oC_Event_State_Active);
982  }
983  oC_IntMan_ExitCriticalSection();
984 
985  oC_Procedure_ExitIfFalse( oC_Event_WaitForState(ModuleReadyToSend, oC_Event_State_Active, oC_Event_StateMask_Full, Timeout), oC_ErrorCode_Timeout );
986 
987  FrameType = oC_Net_ConvertUint16ToNetworkEndianess(FrameType);
988  oC_Procedure_ExitIfError( oC_ETH_LLD_SendFrame( &Context->Result, Source, Destination, Data, Size, FrameSegment , FrameType) );
989 
990  errorCode = oC_ErrorCode_None;
991  }
992  oC_Procedure_End;
993 
994  return errorCode;
995 }
996 
997 //==========================================================================================================================================
1001 //==========================================================================================================================================
1002 static oC_ErrorCode_t ReceiveFrame( oC_ETH_Context_t Context , oC_Net_MacAddress_t outSource, oC_Net_MacAddress_t outDestination, void * Data, uint16_t * Size, oC_ETH_LLD_FrameSegment_t * outFrameSegment , oC_Net_FrameType_t * outFrameType , oC_Time_t Timeout )
1003 {
1004  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1005 
1006  oC_Procedure_Begin
1007  {
1008  oC_IntMan_EnterCriticalSection();
1009  if(oC_ETH_LLD_IsDataReadyToReceive(&Context->Result) == false)
1010  {
1011  oC_Event_SetState(DataReadyToRead,oC_Event_State_Inactive);
1012  }
1013  else
1014  {
1015  oC_Event_SetState(DataReadyToRead,oC_Event_State_Active);
1016  }
1017  oC_IntMan_ExitCriticalSection();
1018 
1019  oC_Procedure_ExitIfFalse( oC_Event_WaitForState(DataReadyToRead, oC_Event_State_Active, oC_Event_StateMask_Full, Timeout), oC_ErrorCode_Timeout );
1020 
1021  oC_Procedure_ExitIfError( oC_ETH_LLD_ReceiveFrame( &Context->Result, outSource, outDestination, Data, Size, outFrameSegment , outFrameType) );
1022 
1023  *outFrameType = oC_Net_ConvertUint16FromNetworkEndianess(*outFrameType);
1024  errorCode = oC_ErrorCode_None;
1025  }
1026  oC_Procedure_End;
1027 
1028  return errorCode;
1029 }
1030 
1031 //==========================================================================================================================================
1035 //==========================================================================================================================================
1036 static oC_ErrorCode_t PerformPhyRegisterAccessTest( oC_Diag_t * Diag , void * Context )
1037 {
1038  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1039  oC_ETH_Context_t context = Context;
1040 
1041  if(ErrorCondition(IsContextCorrect(context), oC_ErrorCode_ContextNotCorrect))
1042  {
1045 
1046  oC_Procedure_Begin
1047  {
1048  BSR.Value = 0;
1049  BCR.Value = 0;
1050 
1051  if( !ErrorCode( oC_ETH_ReadPhyRegister( context->PhyAddress, oC_ETH_PhyRegister_BCR , &BCR.Value)) )
1052  {
1053  Diag->ResultDescription = "Cannot read BCR register";
1054  break;
1055  }
1056 
1057  BCR.Loopback = 1;
1058 
1059  if( !ErrorCode( oC_ETH_WritePhyRegister( context->PhyAddress, oC_ETH_PhyRegister_BCR, BCR.Value ) ) )
1060  {
1061  Diag->ResultDescription = "Cannot write BCR register";
1062  break;
1063  }
1064 
1065  BCR.Value = 0;
1066 
1067  if( !ErrorCode( oC_ETH_ReadPhyRegister( context->PhyAddress, oC_ETH_PhyRegister_BCR , &BCR.Value)) )
1068  {
1069  Diag->ResultDescription = "Cannot read BCR register after write";
1070  break;
1071  }
1072 
1073  if(BCR.Loopback != 1)
1074  {
1075  Diag->ResultDescription = "Value of the BCR register after write `BCR.Loopback = 1` is not correct!";
1076  errorCode = oC_ErrorCode_CannotAccessRegister;
1077  break;
1078  }
1079 
1080  BCR.Loopback = 0;
1081 
1082  if( !ErrorCode( oC_ETH_WritePhyRegister( context->PhyAddress, oC_ETH_PhyRegister_BCR, BCR.Value ) ) )
1083  {
1084  Diag->ResultDescription = "Cannot write BCR register";
1085  break;
1086  }
1087 
1088  BCR.Value = 0;
1089 
1090  if(BCR.Loopback != 0)
1091  {
1092  Diag->ResultDescription = "Value of the BCR register after write `BCR.Loopback = 0` is not correct!";
1093  errorCode = oC_ErrorCode_CannotAccessRegister;
1094  break;
1095  }
1096 
1097  if( !ErrorCode( oC_ETH_ReadPhyRegister( context->PhyAddress, oC_ETH_PhyRegister_BSR , &BSR.Value)) )
1098  {
1099  Diag->ResultDescription = "Cannot read BSR register";
1100  break;
1101  }
1102 
1103 
1104  if(BSR.Value == 0)
1105  {
1106  Diag->ResultDescription = "BSR value is 0! We expect anything else...";
1107  errorCode = oC_ErrorCode_CannotAccessRegister;
1108  break;
1109  }
1110 
1111  errorCode = oC_ErrorCode_None;
1112  }
1113  oC_Procedure_End;
1114  }
1115 
1116  return errorCode;
1117 }
1118 
1119 //==========================================================================================================================================
1123 //==========================================================================================================================================
1124 static void InterruptHandler( oC_ETH_LLD_InterruptSource_t Source )
1125 {
1126  if(Source & oC_ETH_LLD_InterruptSource_DataReceived)
1127  {
1128  oC_Event_SetState(DataReadyToRead,oC_Event_State_Active);
1129  }
1130  if(Source & oC_ETH_LLD_InterruptSource_TransmissionSlotsAvailable)
1131  {
1132  oC_Event_SetState(ModuleReadyToSend,oC_Event_State_Active);
1133  }
1134  if(Source & oC_ETH_LLD_InterruptSource_ReceiveError)
1135  {
1136  oC_SaveError("ETH - Transmission failure - ", oC_ErrorCode_ReceiveError);
1137  }
1138 }
1139 
1140 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
1141 
1142 #endif
1143 
1144 
1145 
1146 
1147 
1148 
1149 
1150 
1151 
1152 
1153 
1154 
1155 
1156 
1157 
1158 
1159 
oC_Net_InterfaceName_t InterfaceName
Name of the interface.
Definition: oc_eth.c:104
oC_Net_Ipv4_t SourceIp
Source IP address.
Definition: oc_net.h:231
oC_ETH_PhyAddress_t PhyAddress
Address of the external PHY.
Definition: oc_eth.h:126
oC_ETH_LLD_Result_t Result
Result of LLD configuration.
Definition: oc_eth.c:101
The data link layer or layer 2 is the second layer of the seven-layer OSI model of computer networkin...
Definition: oc_net.h:336
bool oC_Event_WaitForState(oC_Event_t Event, oC_Event_State_t State, oC_Event_StateMask_t StateMask, oC_Time_t Timeout)
Definition: oc_event.c:245
oC_Net_InterfaceIndex_t InterfaceIndex
Index of the interface in the driver.
Definition: oc_net.h:511
Basic math operations.
FILE__DESCRIPTION
#define s(time)
Number of s.
Definition: oc_cfg.h:133
oC_ErrorCode_t oC_ETH_PerformDiagnostics(oC_ETH_Context_t Context, oC_Diag_t *Diags, uint32_t *NumberOfDiags)
performs diagnostics
Definition: oc_eth.c:644
static oC_Event_t DataReadyToRead
Definition: oc_eth.c:160
static int oC_Net_MacAddressFromString(const char *MacAddressString, oC_Net_MacAddress_t outMacAddress)
reads MAC address from the string
Definition: oc_net.h:677
ETH driver configuration structure.
Definition: oc_eth.h:122
oC_ErrorCode_t oC_ETH_SetPhyLoopback(oC_ETH_PhyAddress_t PhyAddress, bool Enabled)
enables/disables PHY loopback mode
Definition: oc_eth_phy.c:237
oC_ErrorCode_t oC_ETH_SendFrame(oC_ETH_Context_t Context, const oC_Net_Frame_t *Frame, oC_Time_t Timeout)
sends frame via ETH
Definition: oc_eth.c:408
const char * Name
Definition: oc_stdlib.h:161
oC_MemorySize_t TransmittedBytes
Number of transmitted bytes.
Definition: oc_net.h:514
static oC_Event_t ModuleReadyToSend
Definition: oc_eth.c:166
oC_ErrorCode_t oC_ETH_PhyReset(oC_ETH_PhyAddress_t PhyAddress)
resets PHY
Definition: oc_eth_phy.c:121
oC_ErrorCode_t oC_ETH_TurnOn(void)
turns on the module
Definition: oc_eth.c:200
The file with interface for the GPIO driver.
static uint16_t oC_Net_ConvertUint16FromNetworkEndianess(uint16_t v)
converts uint16_t from network byte order
Definition: oc_net.h:579
oC_Net_Ipv4PacketHeader_t Header
Header of the IPv4 packet.
Definition: oc_net.h:276
identifier for allocations
Definition: oc_stdlib.h:159
oC_ErrorCode_t oC_ETH_SetLoopback(oC_ETH_Context_t Context, oC_Net_Layer_t Layer, bool Enabled)
enables or disables loopback-mode at the given layer
Definition: oc_eth.c:583
The file with LLD interface for the ETH driver.
stores value of the BSR register
Definition: oc_eth_phy.h:109
stores network interface informations
Definition: oc_net.h:508
oC_Net_MacAddress_t MacAddress
MAC address.
Definition: oc_net.h:119
oC_ETH_PhyRegister_BasicStatusRegister
Definition: oc_eth_phy.h:64
oC_ETH_ChipName_t ChipName
Name of the used chip.
Definition: oc_eth.c:102
uint32_t HardwareAddressLength
Number of bytes in the HW address.
Definition: oc_net.h:519
uint32_t Value
Stores value of the register.
Definition: oc_eth_phy.h:136
The file contains definitions for the compiler, that helps to manage errors, etc. ...
oC_ETH_LLD_Descriptor_t RxDescriptorRing
Pointer to the RX Descriptor ring (List of DMA descriptors required for receiving packets) ...
Definition: oc_eth.c:109
static oC_ErrorCode_t InitializePhy(const oC_ETH_Config_t *Config, oC_ETH_Context_t Context)
initializes PHY to work
Definition: oc_eth.c:856
oC_Net_LinkStatus_t LinkStatus
Network interface link status (UP/DOWN)
Definition: oc_net.h:513
static oC_ErrorCode_t CreateContext(const oC_ETH_Config_t *Config, oC_ETH_Context_t *outContext)
creates context of the driver
Definition: oc_eth.c:794
oC_ErrorCode_t oC_ETH_Configure(const oC_ETH_Config_t *Config, oC_ETH_Context_t *outContext)
configures ETH pins to work
Definition: oc_eth.c:309
bool Filled
True if the address is filled.
Definition: oc_net.h:121
const char * DriverName
Name of the driver that handles the network interface.
Definition: oc_net.h:512
Header with definitions for PHY handling.
char oC_Net_InterfaceName_t[IFNAMSIZ]
stores name of the network interface
Definition: oc_net.h:384
#define ms(time)
Number of ms.
Definition: oc_cfg.h:128
static const oC_Diag_SupportedDiagData_t SupportedDiagsArray[]
Definition: oc_eth.c:172
oC_ETH_LLD_Config_t LLD
Configuration from the LLD layer (More you can find in the #oC_ETH_LLD_Config_t type description) ...
Definition: oc_eth.h:125
oC_Net_HardwareAddress_t Destination
Hardware Destination Address.
Definition: oc_net.h:316
uint8_t oC_Net_MacAddress_t[MAC_ADDRESS_LENGTH]
stores MAC address
Definition: oc_net.h:106
char oC_ETH_ChipName_t[oC_ETH_CHIP_NAME_MAX_LENGTH]
stores name of the chip
Definition: oc_eth.h:88
oC_MemorySize_t ReceivedBytes
Number of received bytes.
Definition: oc_eth.c:105
void(* PrintFunction)(struct oC_Diag_t *Diag)
prints state of the diagnostic
Definition: oc_diag.h:38
static uint16_t oC_Net_ConvertUint16ToNetworkEndianess(uint16_t v)
converts uint16_t to network byte order
Definition: oc_net.h:545
oC_Net_MacAddress_t MacAddress
MAC address of the interface.
Definition: oc_eth.h:127
oC_Net_HardwareAddress_t HardwareAddress
Hardware address.
Definition: oc_net.h:517
The file with interface for driver creating.
oC_Mutex_t ContextBusyMutex
Pointer to the Mutex available when the Ethernet context is busy.
Definition: oc_eth.c:111
oC_Net_InterfaceName_t InterfaceName
Name of the interface.
Definition: oc_net.h:510
oC_ETH_LLD_PHY_ChipInfo_t LLD
Informations about the chip required by the LLD layer.
Definition: oc_eth.h:109
The file with interface for the module library.
const oC_ETH_PhyChipInfo_t * PhyChipInfo
Pointer to the PHY chip definition (you can find it in the oc_eth_chips.h file)
Definition: oc_eth.h:124
oC_Net_MacAddress_t MacAddress
MAC address of the interface.
Definition: oc_eth.c:107
static bool oC_Module_IsTurnedOn(oC_Module_t Module)
checks if the module is turned on
Definition: oc_module.h:121
oC_ErrorCode_t oC_ETH_TurnOff(void)
Turns off the ETH driver.
Definition: oc_eth.c:250
oC_BaudRate_t BaudRate
Baud rate of the interface.
Definition: oc_net.h:520
uint32_t oC_ObjectControl_t
stores object control value
Definition: oc_object.h:141
oC_ETH_PhyRegister_BasicControlRegister
Definition: oc_eth_phy.h:63
static oC_ErrorCode_t SendFrame(oC_ETH_Context_t Context, const oC_Net_MacAddress_t Source, const oC_Net_MacAddress_t Destination, const void *Data, uint16_t Size, oC_ETH_LLD_FrameSegment_t FrameSegment, oC_Net_FrameType_t FrameType, oC_Time_t Timeout)
sends frame
Definition: oc_eth.c:968
In the seven-layer OSI model of computer networking, the physical layer or layer 1 is the first and l...
Definition: oc_net.h:335
uint16_t Size
Size Data in frame.
Definition: oc_net.h:323
oC_ETH_ChipName_t Name
Name of the PHY chip.
Definition: oc_eth.h:108
The file with interface for interrupt manager.
oC_Net_HardwareType_t HardwareType
Type of the hardware device.
Definition: oc_net.h:516
stores informations about the frame to send
Definition: oc_net.h:314
oC_ErrorCode_t oC_ETH_SetAutoNegotiation(oC_ETH_PhyAddress_t PhyAddress, bool Enabled, oC_Time_t Timeout)
enables/disables AutoNegotiation
Definition: oc_eth_phy.c:189
oC_ErrorCode_t oC_ETH_ReadNetInfo(oC_ETH_Context_t Context, oC_Net_Info_t *outInfo)
returns informations about the interface
Definition: oc_eth.c:709
oC_ErrorCode_t oC_ETH_Unconfigure(const oC_ETH_Config_t *Config, oC_ETH_Context_t *outContext)
Unconfigures the driver.
Definition: oc_eth.c:361
uint32_t oC_Net_InterfaceIndex_t
stores index of the interface
Definition: oc_net.h:374
static oC_ObjectControl_t oC_CountObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId)
counts object control for object
Definition: oc_object.h:168
static bool oC_CheckObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId, oC_ObjectControl_t ObjectControl)
checks if object control is correct
Definition: oc_object.h:203
oC_MemorySize_t ReceivedBytes
Number of received bytes.
Definition: oc_net.h:515
The file with interface for mutex managing.
oC_Net_HardwareAddress_t Source
Hardware Source Address.
Definition: oc_net.h:317
oC_ETH_LLD_Descriptor_t TxDescriptorRing
Pointer to the TX Descriptor ring (List of DMA descriptors required for sending packets) ...
Definition: oc_eth.c:110
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
Definition: oc_module.h:170
static oC_ErrorCode_t ReleasePhy(const oC_ETH_Config_t *Config, oC_ETH_Context_t Context)
releases PHY when it is not needed anymore
Definition: oc_eth.c:876
oC_ObjectControl_t ObjectControl
Definition: oc_eth.c:100
uint32_t Value
Stores value of the register.
Definition: oc_eth_phy.h:98
stores ETH context
Definition: oc_eth.c:97
oC_Net_Ipv4Packet_t IPv4
Packet in format IPv4.
Definition: oc_net.h:304
oC_Net_Packet_t * Packet
Pointer to the packet to send.
Definition: oc_net.h:320
oC_Net_FrameType_t FrameType
Type of the frame.
Definition: oc_net.h:324
static oC_ErrorCode_t AllocateDescriptors(oC_ETH_Context_t Context)
allocates Rx/Tx descriptors
Definition: oc_eth.c:904
oC_BaudRate_t BaudRate
Baud Rate of the interface.
Definition: oc_eth.c:108
static int oC_Net_PrepareInterfaceName(oC_Net_InterfaceName_t *outName, const char *Prefix, oC_Net_InterfaceIndex_t Index)
prepares interface name string
Definition: oc_net.h:659
static bool IsContextCorrect(oC_ETH_Context_t Context)
Checks if the context of the ETH driver is correct.
Definition: oc_eth.c:784
Network interface is DOWN (cable is not connected)
Definition: oc_net.h:363
static bool oC_Net_IsMainLayer(oC_Net_Layer_t Layer, oC_Net_Layer_t MainLayer)
returns true if Layer is part of the MainLayer
Definition: oc_net.h:1353
The file with interface for string library.
oC_ErrorCode_t oC_ETH_ReadPhyRegister(oC_ETH_PhyAddress_t PhyAddress, oC_ETH_PhyRegister_t Register, uint32_t *outValue)
writes PHY register
Definition: oc_eth_phy.c:97
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
Definition: oc_module.h:155
Definition of the null pointer.
static const oC_Allocator_t Allocator
Definition: oc_eth.c:152
stores value of the BCR register
Definition: oc_eth_phy.h:77
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
Definition: oc_module.h:138
oC_ErrorCode_t oC_ETH_ReceiveFrame(oC_ETH_Context_t Context, oC_Net_Frame_t *outFrame, oC_Time_t Timeout)
receives frame via ETH
Definition: oc_eth.c:482
oC_ETH_PhyAddress_t PhyAddress
Address of the external PHY.
Definition: oc_eth.c:103
static oC_Net_LinkStatus_t GetLinkStatus(oC_ETH_Context_t Context)
returns current link status
Definition: oc_eth.c:890
static void InterruptHandler(oC_ETH_LLD_InterruptSource_t Source)
handler for interrupts
Definition: oc_eth.c:1124
static oC_ErrorCode_t ReceiveFrame(oC_ETH_Context_t Context, oC_Net_MacAddress_t outSource, oC_Net_MacAddress_t outDestination, void *Data, uint16_t *Size, oC_ETH_LLD_FrameSegment_t *outFrameSegment, oC_Net_FrameType_t *outFrameType, oC_Time_t Timeout)
receives frame
Definition: oc_eth.c:1002
Network interface is UP (cable is connected)
Definition: oc_net.h:362
oC_Net_HardwareAddress_t HardwareBroadcastAddress
Hardware address that should be used for broadcast.
Definition: oc_net.h:518
static oC_ErrorCode_t DeleteContext(oC_ETH_Context_t *outContext)
deletes context of the driver
Definition: oc_eth.c:832
oC_Net_LinkStatus_t
stores network interface link status
Definition: oc_net.h:360
oC_MemorySize_t TransmittedBytes
Number of transmitted bytes.
Definition: oc_eth.c:106
oC_ETH_LLD_PHY_Address_t oC_ETH_PhyAddress_t
stores address of a PHY
Definition: oc_eth.h:97
bool oC_ETH_IsContextCorrect(oC_ETH_Context_t Context)
checks if the context is correct for ETH driver
Definition: oc_eth.c:764
oC_ErrorCode_t oC_ETH_ReadLinkStatus(oC_ETH_PhyAddress_t PhyAddress, oC_Net_LinkStatus_t *outLinkStatus)
reads link status from the PHY
Definition: oc_eth_phy.c:155
static oC_ErrorCode_t ReleaseDescriptors(oC_ETH_Context_t Context)
releases Rx/Tx descriptors
Definition: oc_eth.c:948
uint32_t Loopback
Loopback mode: 0 = Normal operation, 1 = loopback mode.
Definition: oc_eth_phy.h:89
oC_Net_FrameType_t
stores type of the frame
Definition: oc_net.h:189
The file with interface for ETH driver.
bool oC_ETH_IsTurnedOn(void)
checks if the driver is turned on
Definition: oc_eth.c:282
oC_ErrorCode_t oC_ETH_WritePhyRegister(oC_ETH_PhyAddress_t PhyAddress, oC_ETH_PhyRegister_t Register, uint32_t Value)
writes PHY register
Definition: oc_eth_phy.c:70
static oC_ErrorCode_t PerformPhyRegisterAccessTest(oC_Diag_t *Diag, void *Context)
performs PHY registers access test
Definition: oc_eth.c:1036
oC_Net_Layer_t LoopbackLayer
Layer of enabled loopback or 0 if not enabled.
Definition: oc_eth.c:112
The file with interface of kernel time module.
The file with standard input/output operations.
#define NULL
pointer to a zero
Definition: oc_null.h:37
oC_Net_Layer_t
stores layer of the OSI model
Definition: oc_net.h:333
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off
Definition: oc_module.h:185