38 #include <oc_gpio_mslld.h> 48 #define _________________________________________MACROS_SECTION_____________________________________________________________________________ 50 #define DESCRIPTOR_LIST_SIZE 5 51 #define TIMEOUT ms(200) 52 #define MAX_PHY_ADDRESS 0x1F 53 #define MAX_PHY_REGISTER_ADDRESS 0x1F 54 #define MAX_PHY_REGISTER_DATA_VALUE 0xFFFF 55 #define ETH_Channel oC_Channel_ETH 56 #define IsRam(Address) (oC_LSF_IsRamAddress(Address) || oC_LSF_IsExternalAddress(Address)) 57 #define IsRom(Address) oC_LSF_IsRomAddress(Address) 58 #define IsDma(Address) oC_LSF_IsDmaAddress(Address) 59 #define ETH_MACCR oC_Register(ETHERNET_MAC,ETH_MACCR) 60 #define ETH_MACFFR oC_Register(ETHERNET_MAC,ETH_MACFFR) 61 #define ETH_MACHTHR oC_Register(ETHERNET_MAC,ETH_MACHTHR) 62 #define ETH_MACHTLR oC_Register(ETHERNET_MAC,ETH_MACHTLR) 63 #define ETH_MACMIIAR oC_Register(ETHERNET_MAC,ETH_MACMIIAR) 64 #define ETH_MACMIIDR oC_Register(ETHERNET_MAC,ETH_MACMIIDR) 65 #define ETH_MACFCR oC_Register(ETHERNET_MAC,ETH_MACFCR) 66 #define ETH_MACVLANTR oC_Register(ETHERNET_MAC,ETH_MACVLANTR) 67 #define ETH_MACRWUFFR oC_Register(ETHERNET_MAC,ETH_MACRWUFFR) 68 #define ETH_MACPMTCSR oC_Register(ETHERNET_MAC,ETH_MACPMTCSR) 69 #define ETH_MACDBGR oC_Register(ETHERNET_MAC,ETH_MACDBGR) 70 #define ETH_MACSR oC_Register(ETHERNET_MAC,ETH_MACSR) 71 #define ETH_MACIMR oC_Register(ETHERNET_MAC,ETH_MACIMR) 72 #define ETH_MACA0HR oC_Register(ETHERNET_MAC,ETH_MACA0HR) 73 #define ETH_MACA0LR oC_Register(ETHERNET_MAC,ETH_MACA0LR) 74 #define ETH_MACA1HR oC_Register(ETHERNET_MAC,ETH_MACA1HR) 75 #define ETH_MACA1LR oC_Register(ETHERNET_MAC,ETH_MACA1LR) 76 #define ETH_MACA2HR oC_Register(ETHERNET_MAC,ETH_MACA2HR) 77 #define ETH_MACA2LR oC_Register(ETHERNET_MAC,ETH_MACA2LR) 78 #define ETH_MACA3HR oC_Register(ETHERNET_MAC,ETH_MACA3HR) 79 #define ETH_MACA3LR oC_Register(ETHERNET_MAC,ETH_MACA3LR) 80 #define ETH_MMCCR oC_Register(ETHERNET_MAC,ETH_MMCCR) 81 #define ETH_MMCRIR oC_Register(ETHERNET_MAC,ETH_MMCRIR) 82 #define ETH_MMCTIR oC_Register(ETHERNET_MAC,ETH_MMCTIR) 83 #define ETH_MMCRIMR oC_Register(ETHERNET_MAC,ETH_MMCRIMR ) 84 #define ETH_MMCTIMR oC_Register(ETHERNET_MAC,ETH_MMCTIMR ) 85 #define ETH_MMCTGFSCCR oC_Register(ETHERNET_MAC,ETH_MMCTGFSCCR ) 86 #define ETH_MMCTGFMSCCR oC_Register(ETHERNET_MAC,ETH_MMCTGFMSCCR) 87 #define ETH_MMCTGFCR oC_Register(ETHERNET_MAC,ETH_MMCTGFCR ) 88 #define ETH_MMCRFCECR oC_Register(ETHERNET_MAC,ETH_MMCRFCECR ) 89 #define ETH_MMCRFAECR oC_Register(ETHERNET_MAC,ETH_MMCRFAECR ) 90 #define ETH_MMCRGUFCR oC_Register(ETHERNET_MAC,ETH_MMCRGUFCR ) 91 #define ETH_PTPTSCR oC_Register(ETHERNET_MAC,ETH_PTPTSCR ) 92 #define ETH_PTPSSIR oC_Register(ETHERNET_MAC,ETH_PTPSSIR ) 93 #define ETH_PTPTSHR oC_Register(ETHERNET_MAC,ETH_PTPTSHR ) 94 #define ETH_PTPTSLR oC_Register(ETHERNET_MAC,ETH_PTPTSLR ) 95 #define ETH_PTPTSHUR oC_Register(ETHERNET_MAC,ETH_PTPTSHUR ) 96 #define ETH_PTPTSLIR oC_Register(ETHERNET_MAC,ETH_PTPTSLIR ) 97 #define ETH_PTPTSAR oC_Register(ETHERNET_MAC,ETH_PTPTSAR ) 98 #define ETH_PTPTTHR oC_Register(ETHERNET_MAC,ETH_PTPTTHR ) 99 #define ETH_PTPTTLR oC_Register(ETHERNET_MAC,ETH_PTPTTLR ) 100 #define ETH_PTPTSSR oC_Register(ETHERNET_MAC,ETH_PTPTSSR ) 101 #define ETH_DMABMR oC_Register(ETHERNET_MAC,ETH_DMABMR ) 102 #define ETH_DMATPDR oC_Register(ETHERNET_MAC,ETH_DMATPDR ) 103 #define ETH_DMARPDR oC_Register(ETHERNET_MAC,ETH_DMARPDR ) 104 #define ETH_DMARDLAR oC_Register(ETHERNET_MAC,ETH_DMARDLAR ) 105 #define ETH_DMATDLAR oC_Register(ETHERNET_MAC,ETH_DMATDLAR ) 106 #define ETH_DMASR oC_Register(ETHERNET_MAC,ETH_DMASR ) 107 #define ETH_DMAOMR oC_Register(ETHERNET_MAC,ETH_DMAOMR ) 108 #define ETH_DMAIER oC_Register(ETHERNET_MAC,ETH_DMAIER ) 109 #define ETH_DMAMFBOCR oC_Register(ETHERNET_MAC,ETH_DMAMFBOCR ) 110 #define ETH_DMARSWTR oC_Register(ETHERNET_MAC,ETH_DMARSWTR ) 111 #define ETH_DMACHTDR oC_Register(ETHERNET_MAC,ETH_DMACHTDR ) 112 #define ETH_DMACHRDR oC_Register(ETHERNET_MAC,ETH_DMACHRDR ) 113 #define ETH_DMACHTBAR oC_Register(ETHERNET_MAC,ETH_DMACHTBAR ) 114 #define ETH_DMACHRBAR oC_Register(ETHERNET_MAC,ETH_DMACHRBAR ) 115 #define SYSCFG_PMC oC_Register(SYSCFG,SYSCFG_PMC) 116 #define RCC_AHB1ENR oC_Register(RCC,RCC_AHB1ENR) 118 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________ 125 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 135 ReceiveProcessState_Stopped = 0 ,
136 ReceiveProcessState_FetchingReceiveTransferDescriptor = 0x01 ,
137 ReceiveProcessState_WaitingForReceivePacket = 0x03 ,
138 ReceiveProcessState_SuspendedReceiveDescriptorUnavailable = 0x04 ,
139 ReceiveProcessState_ClosingReceiveDescriptor = 0x05 ,
140 ReceiveProcessState_TransferingReceivedPacketToHostMemory = 0x07 ,
141 } ReceiveProcessState_t;
145 TransmitProcessState_Stopped = 0 ,
146 TransmitProcessState_FetchingTransmitTransferDescriptor = 0x01 ,
147 TransmitProcessState_WaitingForStatus = 0x02 ,
148 TransmitProcessState_ReadingDataFromHostToFifo = 0x03 ,
149 TransmitProcessState_SuspendedTransmitDescriptorUnavailable = 0x06 ,
150 TransmitProcessState_ClosingTransmitDescriptor = 0x07 ,
151 } TransmitProcessState_t;
155 uint8_t TransmissionFinished:1;
156 uint8_t TransmissionStopped:1;
157 uint8_t TransmitBufferUnavailable:1;
158 uint8_t TransmitJabberTimeout:1;
159 uint8_t ReceiveOverflow:1;
160 uint8_t TransmitUnderflow:1;
161 uint8_t ReceiveFinished:1;
162 uint8_t ReceiveBufferUnavailable:1;
163 uint8_t ReceiveStopped:1;
164 uint8_t ReceiveWatchdogTimeout:1;
165 uint8_t DataTransferredToFifo:1;
167 uint8_t FatalBusError:1;
168 uint8_t FirstDataReceived:1;
169 uint8_t AbnormalInterruptSummary:1;
170 uint8_t NormalInterruptSummary:1;
171 ReceiveProcessState_t ReceiveProcessState:3;
172 TransmitProcessState_t TransmitProcessState:3;
173 uint8_t ErrorDuringTransferDataByTx:1;
174 uint8_t ErrorDuringReadTransfer:1;
175 uint8_t ErrorDuringDescriptorAccess:1;
179 uint8_t TimeStampTriggerStatus:1;
208 uint32_t Reserved24:1;
248 uint32_t Buffer1ByteCount:13;
249 uint32_t Reserved1315:3;
250 uint32_t Buffer2ByteCount:13;
251 uint32_t Reserved3129:3;
256 uint32_t Reserved1313:1;
260 uint32_t Reserved2930:2;
269 oC_ETH_LLD_Frame_t* Frame;
270 uint32_t TimestampLow;
276 uint32_t TimestampHigh;
278 uint32_t Buffer2Address;
288 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 296 #define _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 298 static oC_ErrorCode_t ConnectPins (
const oC_ETH_LLD_Config_t * Config , oC_ETH_LLD_PHY_CommunicationInterface_t CommunicationInterface , oC_ETH_LLD_Result_t * outResult );
299 static oC_ErrorCode_t DisconnectPins ( oC_Pin_t * ConnectedPins , uint16_t ArraySize );
300 static oC_ErrorCode_t ConnectPin ( oC_Pin_t Pin , oC_PinFunction_t PinFunction , oC_Pin_t * outConnectedPinReference );
301 static oC_ErrorCode_t DisconnectPin ( oC_Pin_t Pin );
302 static oC_ErrorCode_t EnableClock ( oC_ETH_LLD_PHY_CommunicationInterface_t CommunicationInterface );
303 static oC_ErrorCode_t DisableClock (
void );
304 static oC_ErrorCode_t CheckPhyCommunicationInterface ( oC_ETH_LLD_PHY_CommunicationInterface_t CommunicationInterface );
306 static oC_ErrorCode_t PerformMacRegisterAccessTest (
oC_Diag_t * Diag ,
void * Context );
308 #undef _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 315 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________ 317 static oC_ETH_LLD_PHY_CommunicationInterface_t ConfiguredPhyCommunicationInterface = oC_ETH_LLD_PHY_CommunicationInterface_None;
318 static uint32_t NumberOfConfiguredPhys = 0;
319 static oC_ETH_LLD_Descriptor_t TxDescriptor =
NULL;
320 static oC_ETH_LLD_Descriptor_t RxDescriptor =
NULL;
325 { .Name =
"MAC register access test" , .PerformFunction = PerformMacRegisterAccessTest } ,
328 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________ 335 #define _________________________________________FUNCTIONS_SECTION__________________________________________________________________________ 343 oC_ErrorCode_t oC_ETH_LLD_TurnOnDriver(
void )
345 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
353 ConfiguredPhyCommunicationInterface = oC_ETH_LLD_PHY_CommunicationInterface_None;
354 NumberOfConfiguredPhys = 0;
358 errorCode = oC_ErrorCode_None;
372 oC_ErrorCode_t oC_ETH_LLD_TurnOffDriver(
void )
374 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
381 errorCode = oC_ErrorCode_None;
395 oC_ErrorCode_t oC_ETH_LLD_SetInterruptHandler( oC_ETH_LLD_InterruptFunction_t Function )
397 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
404 ErrorCondition( IsRam(Function) || IsRom(Function) , oC_ErrorCode_WrongAddress )
409 errorCode = oC_ErrorCode_None;
424 bool oC_ETH_LLD_IsAutoPadGenerationSupported(
void )
435 bool oC_ETH_LLD_IsAutoCalculateCrcSupported(
void )
446 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 )
448 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
453 ErrorCondition( IsRam(Config) || IsRom(Config) , oC_ErrorCode_WrongConfigAddress )
454 && ErrorCondition( IsRam(ChipInfo) || IsRom(ChipInfo) , oC_ErrorCode_WrongAddress )
455 && ErrorCondition( IsRam(outResult) , oC_ErrorCode_OutputAddressNotInRAM )
456 && ErrorCode( CheckPhyCommunicationInterface( ChipInfo->CommunicationInterface ))
457 && ErrorCode( ConnectPins( Config, ChipInfo->CommunicationInterface, outResult ))
458 && ErrorCode( EnableClock( ChipInfo->CommunicationInterface ))
461 outResult->RxData.Alignment = 16;
462 outResult->RxData.DescriptorSize =
sizeof(
struct Descriptor_t) + sizeof(oC_ETH_LLD_Frame_t);
463 outResult->RxData.RingSize = DESCRIPTOR_LIST_SIZE;
464 outResult->TxData.Alignment = 16;
465 outResult->TxData.DescriptorSize =
sizeof(
struct Descriptor_t) + sizeof(oC_ETH_LLD_Frame_t);
466 outResult->TxData.RingSize = DESCRIPTOR_LIST_SIZE;
467 outResult->NumberOfMacAddresses = 4;
468 ConfiguredPhyCommunicationInterface = ChipInfo->CommunicationInterface;
475 oC_RegisterType_ETH_MACCR_t maccr = { .Value = ETH_MACCR->Value };
481 maccr.FES = Config->BaudRate == oC_BaudRate_MBd(100) ? 1 : 0;
484 maccr.DM = Config->OperationMode == oC_ETH_LLD_OperationMode_FullDuplex ? 1 : 0;
491 ETH_MACCR->Value = maccr.Value;
494 maccr.Value = ETH_MACCR->Value;
496 ETH_MACCR->Value = maccr.Value;
499 oC_RegisterType_ETH_MACFFR_t macffr = { .Value = ETH_MACFFR->Value };
510 macffr.Value = ETH_MACFFR->Value;
512 ETH_MACFFR->Value = macffr.Value;
514 errorCode = oC_ErrorCode_None;
527 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 )
529 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
534 ErrorCondition( IsRam(Config) || IsRom(Config) , oC_ErrorCode_WrongConfigAddress )
535 && ErrorCondition( IsRam(ChipInfo) , oC_ErrorCode_WrongAddress )
536 && ErrorCondition( IsRam(Result) , oC_ErrorCode_WrongAddress )
537 && oC_AssignErrorCode( &errorCode , DisconnectPins(Result->ConnectedPins,
oC_ARRAY_SIZE(Result->ConnectedPins) ) )
538 && oC_AssignErrorCode( &errorCode , DisableClock() )
541 memset(Result,0,
sizeof(oC_ETH_LLD_Result_t));
546 errorCode = oC_ErrorCode_None;
560 oC_ErrorCode_t oC_ETH_LLD_ReadPhyRegister( oC_ETH_LLD_PHY_Address_t PhyAddress , oC_ETH_LLD_PHY_RegisterAddress_t RegisterAddress , uint32_t * outValue )
562 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
568 && ErrorCondition( PhyAddress <= MAX_PHY_ADDRESS , oC_ErrorCode_PhyAddressNotCorrect )
569 && ErrorCondition( RegisterAddress <= MAX_PHY_REGISTER_ADDRESS , oC_ErrorCode_RegisterAddressNotCorrect )
570 && ErrorCondition( IsRam(outValue) , oC_ErrorCode_OutputAddressNotInRAM )
575 oC_RegisterType_ETH_MACMIIAR_t macMiiAr = { .Value = ETH_MACMIIAR->Value };
580 macMiiAr.MR = RegisterAddress;
581 macMiiAr.PA = PhyAddress;
583 ETH_MACMIIAR->Value = macMiiAr.Value;
585 while(ETH_MACMIIAR->MB == 1 && time < TIMEOUT)
591 if(ETH_MACMIIAR->MB == 0)
593 *outValue = ETH_MACMIIDR->Value;
594 errorCode = oC_ErrorCode_None;
598 errorCode = oC_ErrorCode_Timeout;
615 oC_ErrorCode_t oC_ETH_LLD_WritePhyRegister( oC_ETH_LLD_PHY_Address_t PhyAddress , oC_ETH_LLD_PHY_RegisterAddress_t RegisterAddress , uint32_t Value )
617 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
623 && ErrorCondition( PhyAddress <= MAX_PHY_ADDRESS , oC_ErrorCode_PhyAddressNotCorrect )
624 && ErrorCondition( RegisterAddress <= MAX_PHY_REGISTER_ADDRESS , oC_ErrorCode_RegisterAddressNotCorrect )
625 && ErrorCondition( Value <= MAX_PHY_REGISTER_DATA_VALUE , oC_ErrorCode_ValueTooBig )
630 oC_RegisterType_ETH_MACMIIAR_t macMiiAr = { .Value = ETH_MACMIIAR->Value };
635 macMiiAr.MR = RegisterAddress;
636 macMiiAr.PA = PhyAddress;
638 ETH_MACMIIDR->Value = Value;
639 ETH_MACMIIAR->Value = macMiiAr.Value;
641 while(ETH_MACMIIAR->MB == 1 && time < TIMEOUT)
647 if(ETH_MACMIIAR->MB == 0)
649 errorCode = oC_ErrorCode_None;
653 errorCode = oC_ErrorCode_Timeout;
670 oC_ErrorCode_t oC_ETH_LLD_SetMacLoopback(
bool Enabled )
672 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
678 ETH_MACCR->LM = Enabled ? 1 : 0;
679 errorCode = oC_ErrorCode_None;
692 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 )
694 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
699 ErrorCondition( IsRam(Config) || IsRom(Config) , oC_ErrorCode_WrongConfigAddress )
700 && ErrorCondition( IsDma(Tx) , oC_ErrorCode_NotDmaAddress )
701 && ErrorCondition( IsDma(Rx) , oC_ErrorCode_NotDmaAddress )
702 && ErrorCondition( IsRam(Result) , oC_ErrorCode_OutputAddressNotInRAM )
705 oC_ETH_LLD_Frame_t* txFramesArray = (oC_ETH_LLD_Frame_t*)&Tx[Result->TxData.RingSize];
706 oC_ETH_LLD_Frame_t* rxFramesArray = (oC_ETH_LLD_Frame_t*)&Rx[Result->RxData.RingSize];
711 oC_STATIC_ASSERT( (
sizeof(
struct Descriptor_t) % (
sizeof(uint32_t) * 4 )) == 0 ,
"Size of descriptor is not multiple of 4 words!" );
714 ETH_DMATDLAR->Value = (uint32_t)TxDescriptor;
715 ETH_DMARDLAR->Value = (uint32_t)RxDescriptor;
717 for( uint32_t i = 0 ; i < DESCRIPTOR_LIST_SIZE ; i++ )
725 Tx[i].Tx1.Buffer1ByteCount = 1524;
726 Rx[i].Rx1.RBS = 1524;
728 Tx[i].Frame = &txFramesArray[i];
729 Rx[i].Frame = &rxFramesArray[i];
731 if(i < (DESCRIPTOR_LIST_SIZE - 1))
733 Tx[i].NextDescriptorAddress = &Tx[i+1];
734 Rx[i].NextDescriptorAddress = &Rx[i+1];
739 Tx[i].NextDescriptorAddress = &Tx[0];
740 Rx[i].NextDescriptorAddress = &Rx[0];
744 Result->TxData.NextDescriptor = &Tx[0];
745 Result->TxData.SegmentStarted =
false;
746 Result->RxData.NextDescriptor = &Rx[0];
747 Result->RxData.SegmentStarted =
false;
748 errorCode = oC_ErrorCode_None;
761 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 )
763 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
768 ErrorCondition( IsRam(Result) , oC_ErrorCode_OutputAddressNotInRAM )
769 && ErrorCondition( IsRam(Config) || IsRom(Config) , oC_ErrorCode_WrongAddress )
770 && ErrorCondition( IsDma(Tx) && IsDma(Rx) , oC_ErrorCode_OutputAddressNotInRAM )
773 oC_RegisterType_ETH_DMABMR_t dmabmr = { .Value = ETH_DMABMR->Value };
774 oC_RegisterType_ETH_DMAOMR_t dmaomr = { .Value = ETH_DMAOMR->Value };
786 ETH_DMAOMR->Value = dmaomr.Value;
789 dmaomr.Value = ETH_DMAOMR->Value;
791 ETH_DMAOMR->Value = dmaomr.Value;
803 ETH_DMABMR->Value = dmabmr.Value;
806 dmabmr.Value = ETH_DMABMR->Value;
808 ETH_DMABMR->Value = dmabmr.Value;
811 ETH_DMAIER->NISE = 1;
815 errorCode = oC_ErrorCode_None;
828 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 )
830 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
835 ErrorCondition( IsRam(Source) || IsRom(Source) , oC_ErrorCode_WrongAddress )
836 && ErrorCondition( IsRam(Destination) || IsRom(Destination) , oC_ErrorCode_WrongAddress )
837 && ErrorCondition( IsRam(Data) || IsRom(Data) , oC_ErrorCode_WrongAddress )
838 && ErrorCondition( IsRam(Result) , oC_ErrorCode_OutputAddressNotInRAM )
839 && ErrorCondition( Size > 0 , oC_ErrorCode_SizeNotCorrect )
840 && ErrorCondition( Size <= oC_ETH_LLD_ETHERNET_MTU , oC_ErrorCode_FrameWidthNotSupported )
841 && ErrorCondition( IsDma(TxDescriptor) , oC_ErrorCode_DescriptorListNotInitialized )
842 && ErrorCondition( IsDma(Result->TxData.NextDescriptor) , oC_ErrorCode_InternalDataAreDamaged )
843 && ErrorCondition( FrameSegment < oC_ETH_LLD_FrameSegment_NumberOfFrameSegments , oC_ErrorCode_SegmentTypeNotSupported )
844 && ErrorCondition( EtherType > 0 , oC_ErrorCode_FrameTypeNotSupported )
848 oC_ETH_LLD_Descriptor_t descriptor = Result->TxData.NextDescriptor->Tx0.OWN == 0 ? Result->TxData.NextDescriptor :
NULL;
851 ErrorCondition( descriptor !=
NULL , oC_ErrorCode_NoFreeSlots )
852 && ErrorCondition( Result->TxData.SegmentStarted ==
false || FrameSegment > oC_ETH_LLD_FrameSegment_First , oC_ErrorCode_ModuleIsBusy )
855 uint8_t * destination = (uint8_t*)descriptor->Frame->Data;
856 const uint8_t * source = Data;
859 memset( descriptor->Frame , 0 ,
sizeof(oC_ETH_LLD_Frame_t) );
861 if(FrameSegment & oC_ETH_LLD_FrameSegment_First)
863 memcpy( descriptor->Frame->SourceAddress , Source ,
sizeof(oC_ETH_LLD_MacAddress_t));
864 memcpy( descriptor->Frame->DestinationAddress , Destination ,
sizeof(oC_ETH_LLD_MacAddress_t));
866 descriptor->Frame->DataLengthEtherType = EtherType;
867 descriptor->Tx1.Buffer1ByteCount = Size + 14;
872 descriptor->Tx1.Buffer1ByteCount = Size;
873 destination = (uint8_t*)descriptor->Frame;
880 for(uint32_t offset = 0 ; offset < Size ; offset ++)
882 destination[offset] = source[offset];
885 descriptor->Tx0.CIC = 0x0;
887 if(FrameSegment == oC_ETH_LLD_FrameSegment_First)
889 descriptor->Tx0.LS = 0;
890 descriptor->Tx0.FS = 1;
892 else if(FrameSegment == oC_ETH_LLD_FrameSegment_Last)
894 descriptor->Tx0.LS = 1;
895 descriptor->Tx0.FS = 0;
899 descriptor->Tx0.LS = 1;
900 descriptor->Tx0.FS = 1;
903 descriptor->Tx0.OWN = 1;
905 descriptor->Tx0.DC = 0;
906 descriptor->Tx0.DP = 0;
907 Result->TxData.NextDescriptor = Result->TxData.NextDescriptor->NextDescriptorAddress;
910 if(DmaStatus->TransmitProcessState == TransmitProcessState_SuspendedTransmitDescriptorUnavailable)
913 ETH_DMATPDR->Value = 0xFFFF;
916 Result->TxData.NextDescriptor = descriptor->NextDescriptorAddress;
917 errorCode = oC_ErrorCode_None;
932 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 )
934 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
939 ErrorCondition( IsRam(Result) , oC_ErrorCode_OutputAddressNotInRAM )
940 && ErrorCondition( IsRam(outDestination) , oC_ErrorCode_OutputAddressNotInRAM )
941 && ErrorCondition( IsRam(Data) , oC_ErrorCode_OutputAddressNotInRAM )
942 && ErrorCondition( IsRam(Size) , oC_ErrorCode_OutputAddressNotInRAM )
943 && ErrorCondition( (*Size) > 0 , oC_ErrorCode_SizeNotCorrect )
944 && ErrorCondition( IsRam(outFrameSegment) , oC_ErrorCode_OutputAddressNotInRAM )
945 && ErrorCondition( IsRam(outEtherType) , oC_ErrorCode_OutputAddressNotInRAM )
946 && ErrorCondition( IsDma(RxDescriptor) , oC_ErrorCode_DescriptorListNotInitialized )
947 && ErrorCondition( IsDma(Result->RxData.NextDescriptor) , oC_ErrorCode_InternalDataAreDamaged )
948 && ErrorCondition( IsRam(Result->RxData.NextDescriptor->Frame) ||
949 IsDma(Result->RxData.NextDescriptor->Frame) , oC_ErrorCode_InternalDataAreDamaged )
952 oC_ETH_LLD_Descriptor_t descriptor = Result->RxData.NextDescriptor;
953 uint16_t dataSize = descriptor->Rx0.FL -
sizeof(uint32_t);
957 ErrorCondition( descriptor->Rx0.OWN == 0 , oC_ErrorCode_DataNotAvailable )
958 && ErrorCondition( dataSize <= (*Size) , oC_ErrorCode_OutputBufferTooSmall )
961 uint8_t * destination = Data;
962 const uint8_t * source = (
const uint8_t*)descriptor->Frame->Data;
965 descriptor->Rx0.OWN = 1;
966 *outEtherType = descriptor->Frame->DataLengthEtherType;
968 memcpy(outSource , descriptor->Frame->SourceAddress ,
sizeof(oC_ETH_LLD_MacAddress_t) );
969 memcpy(outDestination , descriptor->Frame->DestinationAddress ,
sizeof(oC_ETH_LLD_MacAddress_t) );
974 for(uint32_t offset = 0 ; offset < dataSize ; offset ++)
976 destination[offset] = source[offset];
979 if(Result->RxData.SegmentStarted ==
false && descriptor->Rx0.FS == 1 && descriptor->Rx0.LS == 1)
981 *outFrameSegment = oC_ETH_LLD_FrameSegment_Single;
982 errorCode = oC_ErrorCode_None;
984 else if(Result->RxData.SegmentStarted ==
false && descriptor->Rx0.FS == 1 && descriptor->Rx0.LS == 0)
986 Result->RxData.SegmentStarted =
true;
987 *outFrameSegment = oC_ETH_LLD_FrameSegment_First;
988 errorCode = oC_ErrorCode_None;
990 else if(Result->RxData.SegmentStarted ==
true && descriptor->Rx0.FS == 0 && descriptor->Rx0.LS == 1)
992 Result->RxData.SegmentStarted =
false;
993 *outFrameSegment = oC_ETH_LLD_FrameSegment_Last;
994 errorCode = oC_ErrorCode_None;
996 else if(Result->RxData.SegmentStarted ==
true && descriptor->Rx0.FS == 0 && descriptor->Rx0.LS == 0)
998 *outFrameSegment = oC_ETH_LLD_FrameSegment_Middle;
999 errorCode = oC_ErrorCode_None;
1003 errorCode = oC_ErrorCode_InternalDataAreDamaged;
1006 Result->RxData.NextDescriptor = (
void*)descriptor->NextDescriptorAddress;
1009 if(DmaStatus->ReceiveProcessState == ReceiveProcessState_SuspendedReceiveDescriptorUnavailable)
1011 ETH_DMASR->RBUS = 1;
1012 ETH_DMATPDR->Value = 0xFFFF;
1028 oC_ErrorCode_t oC_ETH_LLD_Start(
const oC_ETH_LLD_Config_t * Config )
1030 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1035 ErrorCondition( IsRam(Config) || IsRom(Config) , oC_ErrorCode_WrongAddress )
1036 && ErrorCondition( Config->BaudRate == oC_BaudRate_MBd(10) || Config->BaudRate == oC_BaudRate_MBd(100) , oC_ErrorCode_BaudRateNotSupported )
1037 && ErrorCondition( Config->OperationMode == oC_ETH_LLD_OperationMode_FullDuplex
1038 || Config->OperationMode == oC_ETH_LLD_OperationMode_HalfDuplex , oC_ErrorCode_OperationModeNotCorrect )
1042 oC_RegisterType_ETH_MACCR_t maccr = { .Value = ETH_MACCR->Value };
1043 oC_RegisterType_ETH_MACFFR_t macffr = { .Value = ETH_MACFFR->Value };
1044 oC_RegisterType_ETH_DMAOMR_t dmaomr = { .Value = ETH_DMAOMR->Value };
1048 ETH_MACCR->Value = maccr.Value;
1049 maccr.Value = ETH_MACCR->Value;
1051 ETH_MACCR->Value = maccr.Value;
1055 ETH_MACCR->Value = maccr.Value;
1056 maccr.Value = ETH_MACCR->Value;
1058 ETH_MACCR->Value = maccr.Value;
1062 ETH_DMAOMR->Value = dmaomr.Value;
1063 dmaomr.Value = ETH_DMAOMR->Value;
1065 ETH_DMAOMR->Value = dmaomr.Value;
1069 ETH_DMAOMR->Value = dmaomr.Value;
1070 dmaomr.Value = ETH_DMAOMR->Value;
1072 ETH_DMAOMR->Value = dmaomr.Value;
1076 ETH_DMAOMR->Value = dmaomr.Value;
1077 dmaomr.Value = ETH_DMAOMR->Value;
1079 ETH_DMAOMR->Value = dmaomr.Value;
1083 ETH_MACFFR->Value = macffr.Value;
1084 macffr.Value = ETH_MACFFR->Value;
1086 ETH_MACFFR->Value = macffr.Value;
1088 errorCode = oC_ErrorCode_None;
1101 oC_ErrorCode_t oC_ETH_LLD_SetMacAddress( oC_ETH_LLD_Result_t * Result , uint32_t MacAddressIndex,
const oC_ETH_LLD_MacAddress_t Address )
1103 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1108 ErrorCondition( IsRam(Result) || IsRom(Result) , oC_ErrorCode_WrongAddress )
1109 && ErrorCondition( IsRam(Address) || IsRom(Address) , oC_ErrorCode_WrongAddress )
1110 && ErrorCondition( MacAddressIndex >= 0 && MacAddressIndex < 4 , oC_ErrorCode_WrongMacAddressIndex )
1113 switch(MacAddressIndex)
1116 ETH_MACA0LR->MACA0LR = (((uint32_t)Address[0]) << 0)
1117 | (((uint32_t)Address[1]) << 8)
1118 | (((uint32_t)Address[2]) << 16)
1119 | (((uint32_t)Address[3]) << 24);
1120 ETH_MACA0HR->MACA0H = (((uint32_t)Address[4]) << 0)
1121 | (((uint32_t)Address[5]) << 8);
1122 errorCode = oC_ErrorCode_None;
1125 ETH_MACA1LR->MACA1LR = (((uint32_t)Address[0]) << 0)
1126 | (((uint32_t)Address[1]) << 8)
1127 | (((uint32_t)Address[2]) << 16)
1128 | (((uint32_t)Address[3]) << 24);
1129 ETH_MACA1HR->MACA1H = (((uint32_t)Address[4]) << 0)
1130 | (((uint32_t)Address[5]) << 8);
1131 errorCode = oC_ErrorCode_None;
1134 ETH_MACA2LR->MACA2LR = (((uint32_t)Address[0]) << 0)
1135 | (((uint32_t)Address[1]) << 8)
1136 | (((uint32_t)Address[2]) << 16)
1137 | (((uint32_t)Address[3]) << 24);
1138 ETH_MACA2HR->MACA2H = (((uint32_t)Address[4]) << 0)
1139 | (((uint32_t)Address[5]) << 8);
1140 errorCode = oC_ErrorCode_None;
1143 ETH_MACA3LR->MACA3LR = (((uint32_t)Address[0]) << 0)
1144 | (((uint32_t)Address[1]) << 8)
1145 | (((uint32_t)Address[2]) << 16)
1146 | (((uint32_t)Address[3]) << 24);
1147 ETH_MACA3HR->MACA3H = (((uint32_t)Address[4]) << 0)
1148 | (((uint32_t)Address[5]) << 8);
1149 errorCode = oC_ErrorCode_None;
1152 errorCode = oC_ErrorCode_WrongMacAddressIndex;
1167 oC_ErrorCode_t oC_ETH_LLD_ReadMacAddress( oC_ETH_LLD_Result_t * Result , uint32_t MacAddressIndex, oC_ETH_LLD_MacAddress_t outAddress )
1169 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1174 ErrorCondition( IsRam(Result) || IsRom(Result) , oC_ErrorCode_WrongAddress )
1175 && ErrorCondition( IsRam(outAddress) , oC_ErrorCode_WrongAddress )
1176 && ErrorCondition( MacAddressIndex >= 0 && MacAddressIndex < 4 , oC_ErrorCode_WrongMacAddressIndex )
1179 switch(MacAddressIndex)
1182 outAddress[0] = (uint8_t)(ETH_MACA0LR->MACA0LR >> 0);
1183 outAddress[1] = (uint8_t)(ETH_MACA0LR->MACA0LR >> 8);
1184 outAddress[2] = (uint8_t)(ETH_MACA0LR->MACA0LR >> 16);
1185 outAddress[3] = (uint8_t)(ETH_MACA0LR->MACA0LR >> 24);
1186 outAddress[4] = (uint8_t)(ETH_MACA0HR->MACA0H >> 0);
1187 outAddress[5] = (uint8_t)(ETH_MACA0HR->MACA0H >> 8);
1188 errorCode = oC_ErrorCode_None;
1191 outAddress[0] = (uint8_t)(ETH_MACA1LR->MACA1LR >> 0);
1192 outAddress[1] = (uint8_t)(ETH_MACA1LR->MACA1LR >> 8);
1193 outAddress[2] = (uint8_t)(ETH_MACA1LR->MACA1LR >> 16);
1194 outAddress[3] = (uint8_t)(ETH_MACA1LR->MACA1LR >> 24);
1195 outAddress[4] = (uint8_t)(ETH_MACA1HR->MACA1H >> 0);
1196 outAddress[5] = (uint8_t)(ETH_MACA1HR->MACA1H >> 8);
1197 errorCode = oC_ErrorCode_None;
1200 outAddress[0] = (uint8_t)(ETH_MACA2LR->MACA2LR >> 0);
1201 outAddress[1] = (uint8_t)(ETH_MACA2LR->MACA2LR >> 8);
1202 outAddress[2] = (uint8_t)(ETH_MACA2LR->MACA2LR >> 16);
1203 outAddress[3] = (uint8_t)(ETH_MACA2LR->MACA2LR >> 24);
1204 outAddress[4] = (uint8_t)(ETH_MACA2HR->MACA2H >> 0);
1205 outAddress[5] = (uint8_t)(ETH_MACA2HR->MACA2H >> 8);
1206 errorCode = oC_ErrorCode_None;
1209 outAddress[0] = (uint8_t)(ETH_MACA3LR->MACA3LR >> 0);
1210 outAddress[1] = (uint8_t)(ETH_MACA3LR->MACA3LR >> 8);
1211 outAddress[2] = (uint8_t)(ETH_MACA3LR->MACA3LR >> 16);
1212 outAddress[3] = (uint8_t)(ETH_MACA3LR->MACA3LR >> 24);
1213 outAddress[4] = (uint8_t)(ETH_MACA3HR->MACA3H >> 0);
1214 outAddress[5] = (uint8_t)(ETH_MACA3HR->MACA3H >> 8);
1215 errorCode = oC_ErrorCode_None;
1218 errorCode = oC_ErrorCode_WrongMacAddressIndex;
1232 bool oC_ETH_LLD_IsTransmitQueueFull( oC_ETH_LLD_Result_t * Result )
1239 full = Result->TxData.NextDescriptor->Tx0.OWN == 1;
1253 bool oC_ETH_LLD_IsDataReadyToReceive( oC_ETH_LLD_Result_t * Result )
1260 full = Result->RxData.NextDescriptor->Rx0.OWN == 0;
1274 oC_ErrorCode_t oC_ETH_LLD_PerformDiagnostics( oC_ETH_LLD_Result_t * Result ,
oC_Diag_t * Diag , uint32_t * NumberOfDiags )
1276 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1281 ErrorCondition( IsRam(Result) , oC_ErrorCode_OutputAddressNotInRAM )
1282 && ErrorCondition( IsRam(Diag) || Diag ==
NULL , oC_ErrorCode_OutputAddressNotInRAM )
1283 && ErrorCondition( IsRam(NumberOfDiags) , oC_ErrorCode_OutputAddressNotInRAM )
1289 errorCode = oC_Diag_PerformDiagnostics(
SupportedDiagsArray,Diag,*NumberOfDiags,
"ETH-LLD",Result);
1295 errorCode = oC_ErrorCode_None;
1303 #undef _________________________________________FUNCTIONS_SECTION__________________________________________________________________________ 1310 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 1317 static oC_ErrorCode_t ConnectPins(
const oC_ETH_LLD_Config_t * Config , oC_ETH_LLD_PHY_CommunicationInterface_t CommunicationInterface , oC_ETH_LLD_Result_t * outResult )
1319 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1320 uint32_t pinIndex = 0;
1322 memset(outResult->ConnectedPins,0,
sizeof(outResult->ConnectedPins));
1324 if(CommunicationInterface == oC_ETH_LLD_PHY_CommunicationInterface_MII)
1327 oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.Mdc , oC_ETH_PinFunction_ETH_MDC , &outResult->ConnectedPins[pinIndex++] ) )
1328 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.Mdio , oC_ETH_PinFunction_ETH_MDIO , &outResult->ConnectedPins[pinIndex++] ) )
1329 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.Col , oC_ETH_PinFunction_ETH_MII_COL , &outResult->ConnectedPins[pinIndex++] ) )
1330 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.Crs , oC_ETH_PinFunction_ETH_MII_CRS , &outResult->ConnectedPins[pinIndex++] ) )
1331 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.RxClk , oC_ETH_PinFunction_ETH_MII_RX_CLK , &outResult->ConnectedPins[pinIndex++] ) )
1332 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.RxD0 , oC_ETH_PinFunction_ETH_MII_RXD0 , &outResult->ConnectedPins[pinIndex++] ) )
1333 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.RxD1 , oC_ETH_PinFunction_ETH_MII_RXD1 , &outResult->ConnectedPins[pinIndex++] ) )
1334 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.RxD2 , oC_ETH_PinFunction_ETH_MII_RXD2 , &outResult->ConnectedPins[pinIndex++] ) )
1335 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.RxD3 , oC_ETH_PinFunction_ETH_MII_RXD3 , &outResult->ConnectedPins[pinIndex++] ) )
1336 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.RxDv , oC_ETH_PinFunction_ETH_MII_RX_DV , &outResult->ConnectedPins[pinIndex++] ) )
1337 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.RxEr , oC_ETH_PinFunction_ETH_MII_RX_ER , &outResult->ConnectedPins[pinIndex++] ) )
1338 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.TxClk , oC_ETH_PinFunction_ETH_MII_TX_CLK , &outResult->ConnectedPins[pinIndex++] ) )
1339 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.TxD0 , oC_ETH_PinFunction_ETH_MII_TXD0 , &outResult->ConnectedPins[pinIndex++] ) )
1340 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.TxD1 , oC_ETH_PinFunction_ETH_MII_TXD1 , &outResult->ConnectedPins[pinIndex++] ) )
1341 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.TxD2 , oC_ETH_PinFunction_ETH_MII_TXD2 , &outResult->ConnectedPins[pinIndex++] ) )
1342 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.TxD3 , oC_ETH_PinFunction_ETH_MII_TXD3 , &outResult->ConnectedPins[pinIndex++] ) )
1343 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Mii.TxEn , oC_ETH_PinFunction_ETH_MII_TX_EN , &outResult->ConnectedPins[pinIndex++] ) )
1346 errorCode = oC_ErrorCode_None;
1350 oC_SaveIfErrorOccur(
"ETH-LLD: Disconnect error - " , DisconnectPins(outResult->ConnectedPins,
oC_ARRAY_SIZE(outResult->ConnectedPins)));
1353 else if(CommunicationInterface == oC_ETH_LLD_PHY_CommunicationInterface_RMII)
1356 oC_AssignErrorCode(&errorCode , ConnectPin( Config->Rmii.Mdc , oC_ETH_PinFunction_ETH_MDC , &outResult->ConnectedPins[pinIndex++] ) )
1357 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Rmii.Mdio , oC_ETH_PinFunction_ETH_MDIO , &outResult->ConnectedPins[pinIndex++] ) )
1358 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Rmii.RcsDv , oC_ETH_PinFunction_ETH_RMII_CRS_DV , &outResult->ConnectedPins[pinIndex++] ) )
1359 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Rmii.RefClk , oC_ETH_PinFunction_ETH_RMII_REF_CLK , &outResult->ConnectedPins[pinIndex++] ) )
1360 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Rmii.RxD0 , oC_ETH_PinFunction_ETH_RMII_RXD0 , &outResult->ConnectedPins[pinIndex++] ) )
1361 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Rmii.RxD1 , oC_ETH_PinFunction_ETH_RMII_RXD1 , &outResult->ConnectedPins[pinIndex++] ) )
1362 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Rmii.TxD0 , oC_ETH_PinFunction_ETH_RMII_TXD0 , &outResult->ConnectedPins[pinIndex++] ) )
1363 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Rmii.TxD1 , oC_ETH_PinFunction_ETH_RMII_TXD1 , &outResult->ConnectedPins[pinIndex++] ) )
1364 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Rmii.TxEn , oC_ETH_PinFunction_ETH_RMII_TX_EN , &outResult->ConnectedPins[pinIndex++] ) )
1365 && oC_AssignErrorCode(&errorCode , ConnectPin( Config->Rmii.RxEr , oC_ETH_PinFunction_ETH_RMII_RX_ER , &outResult->ConnectedPins[pinIndex++] ) )
1368 errorCode = oC_ErrorCode_None;
1372 oC_SaveIfErrorOccur(
"ETH-LLD: Disconnect error - " , DisconnectPins(outResult->ConnectedPins,
oC_ARRAY_SIZE(outResult->ConnectedPins)));
1377 errorCode = oC_ErrorCode_CommunicationInterfaceNotCorrect;
1388 static oC_ErrorCode_t DisconnectPins( oC_Pin_t * ConnectedPins , uint16_t ArraySize )
1390 oC_ErrorCode_t errorCode = oC_ErrorCode_None;
1392 for(uint16_t pinIndex = 0; pinIndex < ArraySize ; pinIndex++)
1394 if(ConnectedPins[pinIndex] != oC_Pin_NotUsed)
1396 oC_AssignErrorCode(&errorCode, DisconnectPin(ConnectedPins[pinIndex]));
1408 static oC_ErrorCode_t ConnectPin( oC_Pin_t Pin , oC_PinFunction_t PinFunction , oC_Pin_t * outConnectedPinReference )
1410 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1413 ErrorCondition( Pin != oC_Pin_NotUsed , oC_ErrorCode_PinNotSet )
1414 && ErrorCondition( oC_GPIO_LLD_IsPinDefined(Pin) , oC_ErrorCode_PinNotDefined )
1417 bool pinUsed =
false;
1418 oC_ModulePinIndex_t modulePin = 0;
1423 oC_AssignErrorCode( &errorCode , oC_GPIO_MSLLD_FindModulePin( Pin, ETH_Channel, PinFunction, &modulePin ) )
1424 && oC_AssignErrorCode( &errorCode , oC_GPIO_LLD_CheckIsPinUsed( Pin, &pinUsed ) )
1425 && ErrorCondition( pinUsed ==
false , oC_ErrorCode_PinIsUsed )
1426 && oC_AssignErrorCode( &errorCode , oC_GPIO_MSLLD_ConnectModulePin( modulePin ) )
1427 && oC_AssignErrorCode( &errorCode , oC_GPIO_LLD_SetPinsUsed( Pin ) )
1430 *outConnectedPinReference = Pin;
1431 errorCode = oC_ErrorCode_None;
1446 static oC_ErrorCode_t DisconnectPin( oC_Pin_t Pin )
1448 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1451 oC_AssignErrorCode(&errorCode , oC_GPIO_MSLLD_DisconnectPin(Pin,0) )
1452 && oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetPinsUnused(Pin) )
1455 errorCode = oC_ErrorCode_None;
1466 static oC_ErrorCode_t EnableClock( oC_ETH_LLD_PHY_CommunicationInterface_t CommunicationInterface )
1468 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1477 RCC_AHB1ENR->ETHMACRXEN = 1;
1478 RCC_AHB1ENR->ETHMACTXEN = 1;
1481 CommunicationInterface == oC_ETH_LLD_PHY_CommunicationInterface_MII
1482 || CommunicationInterface == oC_ETH_LLD_PHY_CommunicationInterface_RMII
1485 oC_RegisterType_SYSCFG_PMC_t pmc;
1487 oC_RegisterType_ETH_DMABMR_t dmabmr;
1489 pmc.Value = SYSCFG_PMC->Value;
1490 pmc.MII_RMII_SEL = CommunicationInterface == oC_ETH_LLD_PHY_CommunicationInterface_RMII;
1491 dmabmr.Value = ETH_DMABMR->Value;
1493 SYSCFG_PMC->Value = pmc.Value;
1494 ETH_DMABMR->Value = dmabmr.Value;
1496 while(ETH_DMABMR->SR == 1 && time < TIMEOUT)
1502 if(ETH_DMABMR->SR == 0)
1506 { .Min =
MHz(60) , .Max =
MHz(100) },
1507 { .Min =
MHz(100) , .Max =
MHz(150) },
1508 { .Min =
MHz(20) , .Max =
MHz(35) },
1509 { .Min =
MHz(35) , .Max =
MHz(60) },
1513 bool foundRange =
false;
1515 for(uint8_t rangeIndex = 0; rangeIndex <
oC_ARRAY_SIZE(ranges); rangeIndex++)
1517 if(clockFrequency >= ranges[rangeIndex].Min && clockFrequency <= ranges[rangeIndex].Max)
1519 ETH_MACMIIAR->CR = rangeIndex;
1527 NumberOfConfiguredPhys++;
1528 errorCode = oC_ErrorCode_None;
1532 errorCode = oC_ErrorCode_ClockConfigurationError;
1537 oC_SaveError(
"ETH-LLD: Cannot enable MII/RMII interface - " , errorCode);
1538 errorCode = oC_ErrorCode_Timeout;
1543 errorCode = oC_ErrorCode_CommunicationInterfaceNotCorrect;
1557 static oC_ErrorCode_t DisableClock(
void )
1559 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1563 if(ErrorCondition( NumberOfConfiguredPhys > 0 , oC_ErrorCode_ChannelNotConfigured ))
1565 NumberOfConfiguredPhys--;
1567 if(NumberOfConfiguredPhys == 0)
1570 RCC_AHB1ENR->ETHMACRXEN = 0;
1571 RCC_AHB1ENR->ETHMACTXEN = 0;
1575 errorCode = oC_ErrorCode_None;
1580 errorCode = oC_ErrorCode_None;
1595 static oC_ErrorCode_t CheckPhyCommunicationInterface( oC_ETH_LLD_PHY_CommunicationInterface_t CommunicationInterface )
1597 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1599 if(ConfiguredPhyCommunicationInterface == oC_ETH_LLD_PHY_CommunicationInterface_None)
1602 CommunicationInterface == oC_ETH_LLD_PHY_CommunicationInterface_MII
1603 || CommunicationInterface == oC_ETH_LLD_PHY_CommunicationInterface_RMII
1606 errorCode = oC_ErrorCode_None;
1610 errorCode = oC_ErrorCode_CommunicationInterfaceNotCorrect;
1615 if(CommunicationInterface == ConfiguredPhyCommunicationInterface)
1617 errorCode = oC_ErrorCode_None;
1621 errorCode = oC_ErrorCode_OtherCommunicationInterfaceInUse;
1633 static oC_ErrorCode_t PerformMacRegisterAccessTest(
oC_Diag_t * Diag ,
void * Context )
1635 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1638 ErrorCondition( IsRam(Context) , oC_ErrorCode_OutputAddressNotInRAM )
1649 if(!ErrorCondition( ETH_MACCR->LM == 1 , oC_ErrorCode_CannotAccessRegister ))
1651 Diag->ResultDescription =
"Cannot access ETH_MACCR register! ETH_MACCR->LM != 1";
1659 if(!ErrorCondition( ETH_MACCR->LM == 0 , oC_ErrorCode_CannotAccessRegister ))
1661 Diag->ResultDescription =
"Cannot access ETH_MACCR register! ETH_MACCR->LM != 0";
1665 errorCode = oC_ErrorCode_None;
1677 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 1684 #define _________________________________________INTERRUPTS_SECTION_________________________________________________________________________ 1693 oC_ETH_LLD_InterruptSource_t interruptSource = 0;
1698 if(DmaStatus->ReceiveFinished)
1700 interruptSource |= oC_ETH_LLD_InterruptSource_DataReceived;
1702 if(DmaStatus->TransmissionFinished)
1704 interruptSource |= oC_ETH_LLD_InterruptSource_TransmissionSlotsAvailable;
1707 if(DmaStatus->TransmissionStopped)
1709 interruptSource |= oC_ETH_LLD_InterruptSource_TransmitProcessStopped | oC_ETH_LLD_InterruptSource_TransmitError;
1712 if(DmaStatus->ReceiveStopped)
1714 interruptSource |= oC_ETH_LLD_InterruptSource_ReceiveProcessStopped | oC_ETH_LLD_InterruptSource_ReceiveError;
1717 if(DmaStatus->ReceiveWatchdogTimeout)
1719 interruptSource |= oC_ETH_LLD_InterruptSource_ReceiveTimeout | oC_ETH_LLD_InterruptSource_ReceiveError;
1722 if(DmaStatus->TransmitJabberTimeout)
1724 interruptSource |= oC_ETH_LLD_InterruptSource_TransmitJabberTimeout | oC_ETH_LLD_InterruptSource_TransmitError;
1727 if(DmaStatus->ReceiveOverflow)
1729 interruptSource |= oC_ETH_LLD_InterruptSource_ReceiveOverflowError | oC_ETH_LLD_InterruptSource_ReceiveError;
1732 if(DmaStatus->TransmitUnderflow)
1734 interruptSource |= oC_ETH_LLD_InterruptSource_TransmitUnderflowError | oC_ETH_LLD_InterruptSource_TransmitError;
1737 if(DmaStatus->TransmitBufferUnavailable)
1739 interruptSource |= oC_ETH_LLD_InterruptSource_TransmitDescriptorError | oC_ETH_LLD_InterruptSource_TransmitError;
1741 ETH_DMASR->TBUS = 1;
1742 ETH_DMATPDR->Value = 0xFFFF;
1745 if(DmaStatus->ReceiveBufferUnavailable)
1747 interruptSource |= oC_ETH_LLD_InterruptSource_ReceiveDescriptorError | oC_ETH_LLD_InterruptSource_ReceiveError;
1750 if(DmaStatus->FatalBusError)
1752 interruptSource |= oC_ETH_LLD_InterruptSource_FatalBusError;
1758 ETH_DMASR->Value = 0x1FFFF;
1762 #undef _________________________________________INTERRUPTS_SECTION_________________________________________________________________________ The file with interface for registers module.
#define oC_InterruptHandler(BASE_NAME, TYPE_NAME)
Define handler for interrupt.
#define oC_ARRAY_SIZE(ARRAY)
returns size of static array
double oC_Frequency_t
type to store frequency
The file with LLD interface for the ETH driver.
#define MHz(Freq)
Number of MHz.
The file with interface for LSF module.
The file with LLD interface for the MEM driver.
The file with LLD interface for the GPIO driver.
#define ms(time)
Number of ms.
static const oC_Diag_SupportedDiagData_t SupportedDiagsArray[]
void(* PrintFunction)(struct oC_Diag_t *Diag)
prints state of the diagnostic
#define oC_MACHINE_MAXIMUM_FREQUENCY
void oC_MCS_Delay(register oC_UInt_t Cycles)
delays operations for cycles
The file with interface for the module library.
oC_Frequency_t oC_CLOCK_LLD_GetClockFrequency(void)
returns frequency of the system clock
static bool oC_Module_IsTurnedOn(oC_Module_t Module)
checks if the module is turned on
Something is powered off.
The file with LLD interface for the CLOCK driver.
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
The file with functions for the bits operation.
static void oC_MCS_EnterCriticalSection(void)
Enters to critical section.
static bool oC_Machine_IsChannelPoweredOn(oC_Channel_t Channel)
checks if channel is powered on
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
static bool oC_MCS_ExitCriticalSection(void)
Exits from critical section.
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
static void InterruptHandler(oC_ETH_LLD_InterruptSource_t Source)
handler for interrupts
bool oC_CLOCK_LLD_DelayForMicroseconds(oC_UInt_t Microseconds)
perform a delay for us
static bool oC_Machine_SetPowerStateForChannel(oC_Channel_t Channel, oC_Power_t Power)
configures power state for machine channel
The file with interface for Channel module.
bool oC_Channel_EnableInterruptFunction(oC_Channel_t Channel, oC_InterruptType_t InterruptType)
enables interrupt according to channel and type
#define NULL
pointer to a zero
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off
Interface for Machine Base Addresses (BA) module.