1.5wuling_zhuanjietou/UDS/uds_nvm.c
2024-10-17 09:06:51 +08:00

38 lines
768 B
C

#include "uds_nvm.h"
NvmImage_t NvmImage;
int32_t nvm_write(uint8_t *pImage, const uint8_t *pData, uint32_t Len, void (*pCbFn)(uint32_t))
{
uint32_t i;
uint32_t addr;
if (!Len || (&pImage[Len] > (uint8_t*)NVM_ADDR_END) || (pImage < (uint8_t*)NVM_ADDR_STR)) {
return -1;
}
if (pData) {
for (i = 0; i < Len; ++i) {
pImage[i] = pData[i];
}
}
addr = pImage - (uint8_t *)&NvmImage + NVM_ADDRESS_START;
UdsApi_EE_WriteBytes(pImage, addr, Len);
return 0;
}
int32_t uds_service_nvm_write(uint8_t *pImage, const uint8_t *pData, uint32_t Len, void (*pCbFn)(uint32_t))
{
int32_t result;
result = nvm_write(pImage, pData, Len, pCbFn);
return result;
}
void NVM_Init(void)
{
UdsApi_EE_ReadBytes((uint8_t *)&NvmImage, NVM_ADDRESS_START, NVM_SIZE);
}