1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141 |
- #include "hal_adapter.h"
- #include "AppGlobalVar.h"
- #include "stdio.h"
- #include "stdarg.h"
- #include "Icu.h"
- #include "Gpt.h"
- uint8_t __attribute__((section(".non_cacheable_data"))) RX_Buffer[3][BUFFER_SIZE];
- uint32_t bufferIdx[3] = {0};
- volatile uint32 VarNotification_0 = 0;
- volatile uint32 VarNotification_1 = 0;
- TP_Value_Type ConvertedBuffer[NUM_RESULTS];
- Adc_ValueGroupType ResultBuffer[NUM_RESULTS];
- volatile Uart_StatusType Uart_TransmitStatus[3] = {UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT};
- QueueHandle_t UartRecvQueue[3];
- QueueHandle_t UartSendQueue[3];
- QueueHandle_t UartHalQueueHandle;
- Std_ReturnType UartStartRecvFunc(uint8 channel);
- Std_ReturnType ADC_Converter(Adc_ValueGroupType *Buffer, TP_Value_Type *ConvertedValueR);
- void create_ringBuffer(ringbuffer_t *ringBuf, uint8_t *buf, uint32_t buf_len);
- void clear_ringBuffer(ringbuffer_t *ringBuf);
- uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
- uint32_t read_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
- uint8 ringBufferforUart[3][BUFFER_SIZE];
- ringbuffer_t uartRingBuffer[3];
- sint8 AtcmdDelayRecvFunc(uint8 recvChannel,char *ResultStrPtr,uint16 delayTime)
- {
- sint8 outValue = -1;
- uint8 delayCnt = 0;
- uint8 UartData[256];
- uint16 ReadLen = 0;
- char *retptr = NULL;
- while (delayCnt<(delayTime/1000)&&outValue!=0)
- {
- UART_Receive_Data(recvChannel,UartData, &ReadLen,1000);
- if(ReadLen>0)
- {
- retptr = (char *)strstr((char *)UartData, ResultStrPtr);
- if (retptr)
- {
- outValue = 0;
- break;
- }
- }
- else
- {
- delayCnt++;
- }
- }
- return outValue;
- }
- #if 0
- uint16 myPrintf(const char *fmt, ...)
- {
- int n;
- uint8 databuffer[512]={0};
- va_list args;
- va_start(args, fmt);
- n = vsprintf((char *)databuffer, fmt, args);
- va_end(args);
- if( (printfRingBuffer.bw + n) <= printfRingBuffer.length )
- {
- memcpy(printfRingBuffer.source + printfRingBuffer.bw, databuffer, n);
- UART_Send_Data(UART_LPUART0, printfRingBuffer.source + printfRingBuffer.bw, n, 10);
- printfRingBuffer.bw = printfRingBuffer.bw + n;
- }
- else
- {
- printfRingBuffer.bw = 0;
- memcpy(printfRingBuffer.source + printfRingBuffer.bw, databuffer, n);
- UART_Send_Data(UART_LPUART0, printfRingBuffer.source + printfRingBuffer.bw, n, 10);
- }
- return n;
- }
- #endif
- void create_ringBuffer(ringbuffer_t *ringBuf, uint8_t *buf, uint32_t buf_len)
- {
- ringBuf->br = 0;
- ringBuf->bw = 0;
- ringBuf->btoRead = 0;
- ringBuf->source = buf;
- ringBuf->length = buf_len;
- }
- void clear_ringBuffer(ringbuffer_t *ringBuf)
- {
- ringBuf->br = 0;
- ringBuf->bw = 0;
- ringBuf->btoRead = 0;
- }
- uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf)
- {
- uint32_t len = 0;
- volatile uint32_t ringBuf_bw = ringBuf->bw;
- uint32_t ringBuf_len = ringBuf->length;
- uint8_t *ringBuf_source = ringBuf->source;
- if( (ringBuf_bw + size) > ringBuf_len )
- {
- ringBuf_bw = 0;
- }
- memcpy(ringBuf_source + ringBuf_bw, buffer, size);
- ringBuf->bw = (ringBuf_bw + size) % ringBuf_len;
- ringBuf->btoRead += size;
- return size;
- }
- uint32_t read_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf)
- {
- uint32_t len = 0;
- volatile uint32_t ringBuf_br = ringBuf->br;
- uint32_t ringBuf_len = ringBuf->length;
- uint8_t *ringBuf_source = ringBuf->source;
- memcpy(buffer, ringBuf_source, size);
- ringBuf->br = size;
- return size;
- }
- Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, uint8 *txBuffer, uint16 sendLength, uint8 *rxBuffer, uint16 *rxlen, uint32 T_timeout)
- {
- UartMsg_t UartRecvMsg;
- UartMsg_t UartSendMsg;
- BaseType_t Sendret = pdFALSE;
- BaseType_t Recvret = pdFALSE;
- uint32 retVal = E_NOT_OK;
- UartSendMsg.DataLen = sendLength;
- UartSendMsg.dataPtr = txBuffer;
- *rxlen = 0;
- Sendret = xQueueSend(UartSendQueue[transChannel],&UartSendMsg,50);
- if(Sendret == pdTRUE)
- {
- Recvret = xQueueReceive(UartRecvQueue[recvChannel],&UartRecvMsg,T_timeout);
- if(Recvret == pdTRUE)
- {
- *rxlen = UartRecvMsg.DataLen;
-
- memcpy(rxBuffer,(uint8 *)(UartRecvMsg.dataAddr),UartRecvMsg.DataLen);
- retVal = E_OK;
- }
- else
- {
- retVal = 3;
- }
- }
- else
- {
- retVal = 2;
- }
- return retVal;
- }
- Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer, uint8 *rxlen, uint32 T_timeout)
- {
- UartMsg_t UartRecvMsg;
- BaseType_t ret = pdFALSE;
- uint32 retVal = E_NOT_OK;
- *rxlen = 0;
- ret = xQueueReceive(UartRecvQueue[recvChannel],&UartRecvMsg,T_timeout);
- if(ret == pdTRUE)
- {
- *rxlen = UartRecvMsg.DataLen;
- memcpy(rxBuffer,(uint8 *)UartRecvMsg.dataAddr,UartRecvMsg.DataLen);
- retVal = E_OK;
- }
- return retVal;
- }
- Std_ReturnType UART_Reset(uint8 recvChannel)
- {
- uint32 retVal = E_NOT_OK;
- retVal = xQueueReset(UartRecvQueue[recvChannel]);
- return retVal;
- }
- Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32 sendLength, uint32 T_timeout)
- {
- UartMsg_t UartSendMsg;
- BaseType_t ret = pdFALSE;
- uint32 retVal = E_NOT_OK;
- UartSendMsg.DataLen = sendLength;
- UartSendMsg.dataPtr = txBuffer;
- ret = xQueueSend(UartSendQueue[transChannel],&UartSendMsg,T_timeout);
- if(ret == pdTRUE)
- {
- retVal = E_OK;
- }
- return retVal;
- }
- void UartInit(void)
- {
- create_ringBuffer(&uartRingBuffer[0],ringBufferforUart[0],sizeof(ringBufferforUart[0]));
- create_ringBuffer(&uartRingBuffer[1],ringBufferforUart[1],sizeof(ringBufferforUart[1]));
- create_ringBuffer(&uartRingBuffer[2],ringBufferforUart[2],sizeof(ringBufferforUart[2]));
- UartRecvQueue[0] = xQueueCreate(6, sizeof(UartMsg_t));
- UartRecvQueue[1] = xQueueCreate(6, sizeof(UartMsg_t));
- UartRecvQueue[2] = xQueueCreate(6, sizeof(UartMsg_t));
- UartSendQueue[0] = xQueueCreate(3, sizeof(UartMsg_t));
- UartSendQueue[1] = xQueueCreate(1, sizeof(UartMsg_t));
- UartSendQueue[2] = xQueueCreate(1, sizeof(UartMsg_t));
- UartHalQueueHandle = xQueueCreate(9, sizeof(UartHalMsg_t));
- xTaskCreate(Uart_Hal_RecvTask, (const char *const)"UartRecv", 256, (void *)0, main_TASK_PRIORITY + 5, &Uart_Hal_RecvTask_Handle);
- xTaskCreate(Uart_Hal_SendTask, (const char *const)"UartSend", 256, (void *)0, main_TASK_PRIORITY + 4, &Uart_Hal_SendTask_Handle);
- }
- Std_ReturnType UartStartRecvFunc(uint8 channel)
- {
- sint8 out = 0;
- volatile Std_ReturnType R_Uart_Status=E_NOT_OK;
- bufferIdx[channel]=0;
- memset(RX_Buffer[channel],0x00,BUFFER_SIZE);
- switch(channel)
- {
- case 0:
- IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
- break;
- case 1:
- IP_LPUART1->CTRL |= LPUART_CTRL_ILIE(1);
- break;
- case 2:
- IP_LPUART2->CTRL |= LPUART_CTRL_ILIE(1);
- break;
- default:
- break;
- }
- Uart_SetBuffer(channel, RX_Buffer[channel], DMA_SIZE, UART_RECEIVE);
- R_Uart_Status = Uart_AsyncReceive(channel, RX_Buffer[channel], DMA_SIZE);
- if (E_OK != R_Uart_Status)
- {
- Uart_Abort(channel, UART_RECEIVE);
- out = E_NOT_OK;
- }
- return out;
- }
- void Uart_Hal_RecvTask(void *pvParameters)
- {
- UartHalMsg_t UartHalMsgRecv;
- UartMsg_t UartRecvMsg;
- uint16 recvSize = 0;
- BaseType_t ret = pdFALSE;
- BaseType_t ret_send = pdFALSE;
- uint32 T_bytesRemaining[3] = {0};
- uint16 T_timeout[3] = {0};
- volatile Uart_StatusType Uart_ReceiveStatus[3] = {UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT};
- uint8 UartIdx = UART_LPUART0;
- uint8 UartState[3] = {UartAbortRecv,UartAbortRecv,UartAbortRecv};
- while(1)
- {
- if((T_timeout[UartIdx]>1000) && (Uart_ReceiveStatus[UartIdx] != UART_STATUS_NO_ERROR) )
- {
- Uart_Abort(UartIdx, UART_RECEIVE);
- UartState[UartIdx] = UartAbortRecv;
- T_timeout[UartIdx] = 0;
- }
- else if(Uart_ReceiveStatus[UartIdx] == UART_STATUS_NO_ERROR)
- {
- UartState[UartIdx] = UartRecvComplete;
- }
- if((UartState[UartIdx] == UartAbortRecv) || (UartState[UartIdx] == UartRecvComplete))
- {
- if(E_OK == UartStartRecvFunc(UartIdx))
- {
- UartState[UartIdx] = UartStartRecv;
- }
- }
- Uart_ReceiveStatus[UartIdx] = Uart_GetStatus(UartIdx, &T_bytesRemaining[UartIdx], UART_RECEIVE);
- T_timeout[UartIdx]++;
- UartIdx = (UartIdx + 1) > 2 ? 1 : (UartIdx + 1);
- ret = xQueueReceive(UartHalQueueHandle,&UartHalMsgRecv,1);
- if(ret==pdTRUE)
- {
- if(UartHalMsgRecv.event==LPUART_UART_IP_EVENT_RECV_IDLE)
- {
- if(UartHalMsgRecv.value>0)
- {
- recvSize = write_ringBuffer(RX_Buffer[UartHalMsgRecv.Channel],UartHalMsgRecv.value,&uartRingBuffer[UartHalMsgRecv.Channel]);
- UartRecvMsg.DataLen = UartHalMsgRecv.value;
- UartRecvMsg.dataAddr = (uint32)(uartRingBuffer[UartHalMsgRecv.Channel].bw + uartRingBuffer[UartHalMsgRecv.Channel].source - UartHalMsgRecv.value);
- ret_send = xQueueSend(UartRecvQueue[UartHalMsgRecv.Channel],&UartRecvMsg,10);
- }
- T_timeout[UartHalMsgRecv.Channel] = 0;
- UartState[UartHalMsgRecv.Channel] = UartRecvComplete;
- }
- }
- }
- }
- void Uart_Hal_SendTask(void *pvParameters)
- {
- UartMsg_t UartSendMsg;
- BaseType_t ret = pdFALSE;
- uint32 T_bytesRemaining[3] = {0};
- uint16 T_timeout[3] = {0};
- volatile Std_ReturnType T_Uart_Status[3];
- uint8 UartIdx = UART_LPUART0;
- uint8 UartSendState[3] = {UartNoDataSend,UartNoDataSend,UartNoDataSend};
- while(1)
- {
- ret = xQueueReceive(UartSendQueue[UartIdx],&UartSendMsg,1);
- if(ret==pdTRUE)
- {
- T_Uart_Status[UartIdx] = Uart_AsyncSend(UartIdx, UartSendMsg.dataPtr, UartSendMsg.DataLen);
- if (E_OK != T_Uart_Status[UartIdx])
- {
- Uart_Abort(UartIdx, UART_SEND);
- UartSendState[UartIdx] = UartAbortSend;
- }
- else
- {
- UartSendState[UartIdx] = UartStartSend;
- }
- }
-
- if(UartSendState[UartIdx] == UartStartSend)
- {
- Uart_TransmitStatus[UartIdx] = Uart_GetStatus(UartIdx, &T_bytesRemaining[UartIdx], UART_SEND);
- T_timeout[UartIdx]++;
- }
- if(T_timeout[UartIdx]>=1000 || ((Uart_TransmitStatus[UartIdx] != UART_STATUS_OPERATION_ONGOING) && (UartSendState[UartIdx] == UartStartSend)))
- {
- if(T_timeout[UartIdx]>=1000)
- {
- Uart_Abort(UartIdx, UART_SEND);
- UartSendState[UartIdx] = UartAbortSend;
- }
- else if(Uart_TransmitStatus[UartIdx] == UART_STATUS_NO_ERROR)
- {
- UartSendState[UartIdx] = UartSendComplete;
- }
- T_timeout[UartIdx] = 0;
- }
- UartIdx = (UartIdx + 1) > 2 ? 0 : (UartIdx + 1);
- }
- }
- extern Lpuart_Uart_Ip_StateStructureType *Lpuart_Uart_Ip_apStateStructuresArray[LPUART_UART_IP_NUMBER_OF_INSTANCES];
- void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event)
- {
-
- Lpuart_Uart_Ip_StateStructureType * UartState;
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[hwInstance];
-
- if (event == LPUART_UART_IP_EVENT_RX_FULL)
- {
-
- if (bufferIdx[hwInstance] <= (BUFFER_SIZE - DMA_SIZE))
- {
-
- bufferIdx[hwInstance] += DMA_SIZE;
- Uart_SetBuffer(hwInstance, &RX_Buffer[hwInstance][bufferIdx[hwInstance]], DMA_SIZE, UART_RECEIVE);
-
- }
- }
- if (event == LPUART_UART_IP_EVENT_ERROR)
- {
-
-
-
-
-
- Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
- Lpuart_Uart_Ip_AbortSendingData(hwInstance);
-
- }
- if (event == LPUART_UART_IP_EVENT_RECV_IDLE)
- {
- uint32_t temp;
- UartHalMsg_t UartHalMsg;
- UartHalMsg.Channel = hwInstance;
- UartHalMsg.event = event;
-
- temp = DMA_SIZE - (uint32_t)IP_DMA->TCD[hwInstance].CITER.ELINKNO;
-
- bufferIdx[hwInstance] += temp;
-
- UartHalMsg.value = bufferIdx[hwInstance];
- xQueueSendFromISR(UartHalQueueHandle,&UartHalMsg,pdFALSE);
- }
- }
- Can_PduType Can_CreatePduInfo(Can_IdType id, CAN_IdFrameType idFrame, PduIdType swPduHandle, uint8 length, uint8 *sdu)
- {
- Can_PduType PduInfo;
- switch (idFrame)
- {
- case CAN_STANDARD_ID_TYPE:
- id = id & 0x7FF;
- break;
- case CANFD_STANDARD_ID_TYPE:
- id = (id & 0x7FF) | 0x40000000;
- break;
- case CAN_EXTENDED_ID_TYPE:
- id = id | 0x80000000;
- break;
- case CANFD_EXTENDED_ID_TYPE:
- id = id | 0xC0000000;
- break;
- default:
- id = id & 0x7FF;
- break;
- }
- PduInfo.id = id;
- PduInfo.swPduHandle = swPduHandle;
- PduInfo.length = length;
- PduInfo.sdu = sdu;
- return PduInfo;
- }
- Std_ReturnType CanIf_SendMessage(uint8 ControllerId, Can_Msg_Type CanMsg)
- {
- volatile Can_PduType Can_PduInfo;
- volatile Std_ReturnType CAN_Write_Status;
- Std_ReturnType retVal = E_NOT_OK;
- uint32 u8TimeOut = 100 * 100;
- Can_HwHandleType Hth = Can0HardwareObject_TX + (Can_HwHandleType)ControllerId;
- Can_PduInfo = Can_CreatePduInfo(CanMsg.id, CanMsg.idFrame, 0, CanMsg.length, CanMsg.sdu);
- CAN_Write_Status = Can_Write(Hth, &Can_PduInfo);
- CanIf_bTxFlag = FALSE;
- if (CAN_Write_Status == E_OK)
- {
- while ((!CanIf_bTxFlag) && (u8TimeOut != 0U))
- {
- Can_MainFunction_Write();
- u8TimeOut--;
- }
- }
- if (CanIf_bTxFlag == TRUE)
- {
- retVal = E_OK;
- }
- else
- {
- retVal = E_NOT_OK;
- }
- return retVal;
- }
- Can_Msg_Type Can_GetMsgInfo(Can_IdType id, uint8 length, uint8 *sdu)
- {
- Can_Msg_Type CanMsgInfo;
- CanMsgInfo.idFrame = (CAN_IdFrameType)((id >> 30) & 0x03);
- if (CanMsgInfo.idFrame & 0x01)
- {
- CanMsgInfo.id = id & 0x7FF;
- }
- else
- {
- CanMsgInfo.id = id & 0x1FFFFFFF;
- }
- CanMsgInfo.length = length;
- CanMsgInfo.sdu = sdu;
- return CanMsgInfo;
- }
- void CanIf_ControllerBusOff(uint8 ControllerId)
- {
- (void)ControllerId;
- }
- void CanIf_ControllerModeIndication(uint8 ControllerId, Can_ControllerStateType ControllerMode)
- {
- (void)ControllerId;
- (void)ControllerMode;
- }
- void CanIf_TxConfirmation(PduIdType CanTxPduId)
- {
- CanIf_u8TxConfirmCnt++;
- CanIf_bTxFlag = TRUE;
- (void)CanTxPduId;
- }
- void CanIf_RxIndication(const Can_HwType *Mailbox, const PduInfoType *PduInfoPtr)
- {
- Can_Msg_Type canRxMsg_Buff;
- Can_Msg_Type_Data canRxMsgQueueData;
- CanIf_bRxFlag = TRUE;
-
- canRxMsg_Buff = Can_GetMsgInfo(Mailbox->CanId, PduInfoPtr->SduLength, PduInfoPtr->SduDataPtr);
- canRxMsgQueueData.id = canRxMsg_Buff.id;
- canRxMsgQueueData.length = canRxMsg_Buff.length;
- memcpy(canRxMsgQueueData.data, canRxMsg_Buff.sdu, canRxMsgQueueData.length);
- switch(Mailbox->Hoh)
- {
- case 0:
- xQueueSend(CanRecvQueueHandle0, &canRxMsgQueueData, 0);
- break;
- case 1:
- xQueueSend(CanRecvQueueHandle1, &canRxMsgQueueData, 0);
- break;
- case 2:
- xQueueSend(CanRecvQueueHandle2, &canRxMsgQueueData, 0);
- break;
- }
- }
- void CanIf_CurrentIcomConfiguration(uint8 ControllerId, IcomConfigIdType ConfigurationId, IcomSwitch_ErrorType Error)
- {
- (void)ControllerId;
- (void)ConfigurationId;
- (void)Error;
- }
- void Notification_0(void)
- {
- ADC_Converter(ResultBuffer, ConvertedBuffer);
- memcpy(BattTempR, &ConvertedBuffer[3], 4 * sizeof(uint32));
- }
- void Notification_1(void)
- {
- VarNotification_1++;
- }
- Std_ReturnType ADC_Converter(Adc_ValueGroupType *Buffer, TP_Value_Type *ConvertedValueR)
- {
- Adc_ValueGroupType REFH, REFL;
- REFH = Buffer[0];
- REFL = Buffer[2];
- for (int i = 3; i < NUM_RESULTS; i++)
- {
- if (Buffer[i] >= REFH)
- {
- ConvertedValueR[i] = 40930000;
- }
- else if (Buffer[i] <= REFL)
- {
- ConvertedValueR[i] = 0x00;
- }
- else
- {
- ConvertedValueR[i] = (TP_Value_Type)((float)(10000 * (Buffer[i] - REFL) / (float)(REFH - REFL)) / (1 - (float)((Buffer[i] - REFL) / (float)(REFH - REFL))));
- }
- }
- return 0;
- }
- Std_ReturnType ADC_ReadValue()
- {
- Std_ReturnType ret = E_NOT_OK;
- for (uint8 i = 0; i < NUM_RESULTS; i++)
- {
- ResultBuffer[i] = 0xFFFF;
- ConvertedBuffer[i] = 0x00;
- }
- Adc_SetupResultBuffer(AdcGroupSoftwareOneShot, ResultBuffer);
- Adc_EnableGroupNotification(AdcGroupSoftwareOneShot);
- VarNotification_0 = 0;
- Adc_StartGroupConversion(AdcGroupSoftwareOneShot);
- return ret;
- }
- static Std_ReturnType TestEep_FlexNvmProgramPartCmd(
- VAR(TestEep_CsecKeySize, AUTOMATIC) eepKeysize,
- VAR(TestEep_SfeType, AUTOMATIC) eepSecurityFlagExtension,
- VAR(TestEep_LoadFlexRamType, AUTOMATIC) eepLoadFlexRamAtReset,
- VAR(TestEep_Eeprom_FlexRamPartitionType, AUTOMATIC) eepFlexRamPartition,
- VAR(TestEep_Eeprom_FlexNvmPartitionType, AUTOMATIC) eepFlexNvmPartition)
- {
- Std_ReturnType u8RetVal = (Std_ReturnType)E_OK;
- uint32 u32FlexNvmPartSize = 0;
- uint32 u32RegSimFcfg1 = 0UL;
- u32RegSimFcfg1 = IP_SIM->FCFG1;
-
- u32FlexNvmPartSize = (uint32)((u32RegSimFcfg1 & SIM_FCFG1_DEPART_MASK) >> SIM_FCFG1_DEPART_SHIFT);
-
- if (u32FlexNvmPartSize == 0xF)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (0U == REG_BIT_GET8(TEST_EEP_EEPROM_FSTAT_ADDR32, TEST_EEP_EEPROM_FSTAT_ACCERR_U8 | TEST_EEP_EEPROM_FSTAT_FPVIOL_U8))
- {
-
- REG_WRITE8(TEST_EEP_EEPROM_FCCOB0_ADDR32, EEPROM_CMD_PROGRAM_PARTITION);
- REG_WRITE8(TEST_EEP_EEPROM_FCCOB1_ADDR32, (uint8)eepKeysize);
- REG_WRITE8(TEST_EEP_EEPROM_FCCOB2_ADDR32, (uint8)eepSecurityFlagExtension);
- REG_WRITE8(TEST_EEP_EEPROM_FCCOB3_ADDR32, (uint8)eepLoadFlexRamAtReset);
- REG_WRITE8(TEST_EEP_EEPROM_FCCOB4_ADDR32, (uint8)eepFlexRamPartition);
- REG_WRITE8(TEST_EEP_EEPROM_FCCOB5_ADDR32, (uint8)eepFlexNvmPartition);
- REG_WRITE8(TEST_EEP_EEPROM_FSTAT_ADDR32, TEST_EEP_EEPROM_FSTAT_CCIF_U8);
- while ((0U == REG_BIT_GET8(TEST_EEP_EEPROM_FSTAT_ADDR32, TEST_EEP_EEPROM_FSTAT_CCIF_U8)))
- {
-
- }
-
- if (REG_BIT_GET8(TEST_EEP_EEPROM_FSTAT_ADDR32, TEST_EEP_EEPROM_FSTAT_ACCERR_U8 | TEST_EEP_EEPROM_FSTAT_FPVIOL_U8))
- {
-
- u8RetVal = (Std_ReturnType)E_NOT_OK;
- }
- }
- else
- {
-
- u8RetVal = (Std_ReturnType)E_NOT_OK;
- }
- }
- else
- {
-
- u8RetVal = (Std_ReturnType)E_NOT_OK;
- }
- return u8RetVal;
- }
- void Eep_DepartParitition(TestEep_Eeprom_FlexNvmPartitionType T_EEP_SIZE)
- {
- uint32 u32FlexNvmPartSize = 0;
- uint32 u32RegSimFcfg1 = 0UL;
- u32RegSimFcfg1 = IP_SIM->FCFG1;
-
- u32FlexNvmPartSize = (uint32)((u32RegSimFcfg1 & SIM_FCFG1_DEPART_MASK) >> SIM_FCFG1_DEPART_SHIFT);
- if (u32FlexNvmPartSize == 0xF)
- {
-
- TestEep_FlexNvmProgramPartCmd(EEP_FTFC_KEY_SIZE_0_BYTES, EEP_FTFC_VERIFY_ONLY_DISABLED,
- EEP_FTFC_LOAD_AT_RESET_ENABLED, EEP_FTFC_EERAM_SIZE_4K, T_EEP_SIZE);
- }
- }
- Std_ReturnType HAL_EEP_Erase(uint32 eepEraseStartAddr, uint32 eepEraseSize)
- {
- Std_ReturnType retReturnType = E_OK;
- MemIf_JobResultType retJobResultType;
- retReturnType = Eep_Erase(eepEraseStartAddr, eepEraseSize);
- if (E_OK != retReturnType)
- {
- return E_NOT_OK;
- }
- while (MEMIF_IDLE != Eep_GetStatus())
- {
- Eep_MainFunction();
- }
- retJobResultType = Eep_GetJobResult();
- if (MEMIF_JOB_OK != retJobResultType)
- {
- return E_NOT_OK;
- }
- return E_OK;
- }
- Std_ReturnType HAL_EEP_Write(uint32 eepWriteStartAddr, uint8 *pDataNeedtoWrite, uint32 dataSize)
- {
- Std_ReturnType retReturnType = E_OK;
- MemIf_JobResultType retJobResultType;
-
- retReturnType = HAL_EEP_Erase(eepWriteStartAddr, dataSize);
- if (E_OK != retReturnType)
- {
- return E_NOT_OK;
- }
- retReturnType = Eep_Write(eepWriteStartAddr, pDataNeedtoWrite, dataSize);
- if (E_OK != retReturnType)
- {
- return E_NOT_OK;
- }
- while (MEMIF_IDLE != Eep_GetStatus())
- {
- Eep_MainFunction();
- }
- retJobResultType = Eep_GetJobResult();
- if (MEMIF_JOB_OK != retJobResultType)
- {
- return E_NOT_OK;
- }
- return E_OK;
- }
- Std_ReturnType HAL_EEP_Read(uint32 eepReadStartAddr, uint8 *pDataBuffer, uint32 dataSize)
- {
- Std_ReturnType retReturnType = E_OK;
- MemIf_JobResultType retJobResultType;
- retReturnType = Eep_Read(eepReadStartAddr, pDataBuffer, dataSize);
- if (E_OK != retReturnType)
- {
- return E_NOT_OK;
- }
- while (MEMIF_IDLE != Eep_GetStatus())
- {
- Eep_MainFunction();
- }
- retJobResultType = Eep_GetJobResult();
- if (MEMIF_JOB_OK != retJobResultType)
- {
- return E_NOT_OK;
- }
- return E_OK;
- }
- Std_ReturnType HAL_EEP_Compare(uint32 eepCompareStartAddr, uint8 *pDataNeedtoCompare, uint32 dataSize)
- {
- Std_ReturnType retReturnType = E_OK;
- MemIf_JobResultType retJobResultType;
- retReturnType = Eep_Compare(eepCompareStartAddr, pDataNeedtoCompare, dataSize);
- if (E_OK != retReturnType)
- {
- return E_NOT_OK;
- }
- while (MEMIF_IDLE != Eep_GetStatus())
- {
- Eep_MainFunction();
- }
- retJobResultType = Eep_GetJobResult();
- if (MEMIF_JOB_OK != retJobResultType)
- {
- return E_NOT_OK;
- }
- return E_OK;
- }
- #define FEATURE_SCB_VECTKEY (0x05FAU)
- void SystemSoftwareReset(void)
- {
- uint32_t regValue;
-
- regValue = S32_SCB->AIRCR;
-
- regValue &= ~( S32_SCB_AIRCR_VECTKEY_MASK);
-
- regValue |= S32_SCB_AIRCR_VECTKEY(FEATURE_SCB_VECTKEY);
- regValue |= S32_SCB_AIRCR_SYSRESETREQ(0x1u);
-
- S32_SCB->AIRCR = regValue;
- }
- void SystemPrepareForSleep(void)
- {
- for(int pinIndex = 0; pinIndex <PortConfigSet_PortContainer_GPIO_PTB4_GPIO_OUT_MCU_RS485_EN; pinIndex++)
- {
- if(pinIndex == PortConfigSet_PortContainer_CAN_PTA12_CAN1_RX_MCU_CAN1_RX )
- {
- continue;
- }
- else
- {
- Port_SetAsUnusedPin(pinIndex);
- }
- }
- Port_SetPinMode(PortConfigSet_PortContainer_CAN_PTA12_CAN1_RX_MCU_CAN1_RX,PORT_GPIO_MODE);
- #if (ICU_PRECOMPILE_SUPPORT == STD_ON)
- Icu_Init(NULL_PTR);
- #elif (ICU_PRECOMPILE_SUPPORT == STD_OFF)
- Icu_Init(&Icu_Config_VS_0);
- #endif
- Mcu_SetMode(McuModeSettingConf_VLPS);
- }
- void SystemPeripheralDeinit(void)
- {
- WdgDeInit();
- Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_OFF);
- vTaskDelay(pdMS_TO_TICKS(3000));
- Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_OFF);
- Dio_WriteChannel(DioConf_DioChannel_PTD1_GPIO_OUT_MCU_GPS_POW_EN, STD_OFF);
- Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_ON);
- Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_ON);
- Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_ON);
- Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_ON);
- Dio_WriteChannel(DioConf_DioChannel_PTE9_GPIO_OUT_MCU_LED5, STD_ON);
- Uart_Deinit();
- Can_SetControllerMode(CanController_0, CAN_CS_STOPPED);
- Can_SetControllerMode(CanController_1, CAN_CS_STOPPED);
- Can_DeInit();
- Adc_DeInit();
- Gpt_DisableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
- Gpt_DeInit();
- Spi_DeInit();
- Mcl_DeInit();
- }
- void coreInit(void)
- {
-
- #if (MCU_PRECOMPILE_SUPPORT == STD_ON)
- Mcu_Init(NULL_PTR);
- #elif (MCU_PRECOMPILE_SUPPORT == STD_OFF)
- Mcu_Init(&Mcu_Config_VS_0);
- #endif
- Mcu_InitClock(McuClockSettingConfig_0);
-
- while (MCU_PLL_LOCKED != Mcu_GetPllStatus())
- {
-
- }
- Mcu_DistributePllClock();
- OsIf_Init(NULL_PTR);
- Platform_Init(NULL_PTR);
- }
- void SystemModulesInit(void)
- {
-
- Mcl_Init(NULL_PTR);
- SEGGER_RTT_Init();
-
- #if (UART_PRECOMPILE_SUPPORT == STD_ON)
- Uart_Init(NULL_PTR);
- #elif (UART_PRECOMPILE_SUPPORT == STD_OFF)
- Uart_Init(&Uart_xConfig_VS_0);
- #endif
- IP_LPUART0->CTRL |= LPUART_CTRL_ILT(1);
- IP_LPUART1->CTRL |= LPUART_CTRL_ILT(1);
- IP_LPUART2->CTRL |= LPUART_CTRL_ILT(1);
- IP_LPUART0->CTRL |= LPUART_CTRL_IDLECFG(5);
- IP_LPUART1->CTRL |= LPUART_CTRL_IDLECFG(3);
- IP_LPUART2->CTRL |= LPUART_CTRL_IDLECFG(3);
- #if 1
- #if (CAN_PRECOMPILE_SUPPORT == STD_ON)
- Can_Init(NULL_PTR);
- #elif (CAN_PRECOMPILE_SUPPORT == STD_OFF)
- Can_Init(&Can_Config_VS_0);
- #endif
- Can_SetControllerMode(CanController_0, CAN_CS_STARTED);
- Can_SetControllerMode(CanController_1, CAN_CS_STARTED);
- #endif
- #if (ADC_PRECOMPILE_SUPPORT == STD_ON)
- Adc_Init(NULL_PTR);
- #else
- Adc_Init(&Adc_Config_VS_0);
- #endif
-
-
- #if defined (EEP_PRECOMPILE_SUPPORT)
- Eep_Init(NULL_PTR);
- #else
- Eep_Init(&Eep_Config_VS_0);
- #endif
-
- #if defined (FLS_PRECOMPILE_SUPPORT)
- Fls_Init(NULL_PTR);
- #else
- Fls_Init(&Fls_Config_VS_0);
- while(MEMIF_IDLE == Fls_GetStatus())
- {
- ;
- }
- #endif
- Spi_Init(NULL_PTR);
-
- Gpt_Init(&Gpt_Config_VS_0);
-
- Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
- Icu_DeInit();
- WdgInit();
- IsFeedWdg = true;
- }
|