GRBL-Advanced/grbl/Nvm.c

105 wiersze
2.2 KiB
C

2019-03-26 18:54:58 +00:00
/*
Nvm.c - Non-volatile-memory interface.
Part of Grbl-Advanced
Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
Copyright (c) 2009-2011 Simen Svale Skogsrud
Copyright (c) 2019-2024 Patrick F.
2019-03-26 18:54:58 +00:00
Grbl-Advanced is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl-Advanced is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl-Advanced. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Nvm.h"
#include "Config.h"
#include "M24C0X.h"
#include "System32.h"
#include "eeprom.h"
2019-03-26 18:54:58 +00:00
void Nvm_Init(void)
{
#if (USE_EXT_EEPROM)
2021-01-19 08:45:27 +00:00
M24C0X_Init();
2019-03-26 18:54:58 +00:00
#else
2021-01-19 08:45:27 +00:00
EE_Init();
2019-03-26 18:54:58 +00:00
#endif
}
2019-03-26 18:54:58 +00:00
uint8_t Nvm_ReadByte(uint16_t Address)
{
#if (USE_EXT_EEPROM)
2021-01-19 08:45:27 +00:00
return M24C0X_ReadByte(Address);
2019-03-26 18:54:58 +00:00
#else
2021-01-19 08:45:27 +00:00
return EE_ReadByte(Address);
2019-03-26 18:54:58 +00:00
#endif
}
2019-03-26 18:54:58 +00:00
void Nvm_WriteByte(uint16_t Address, uint8_t Data)
{
#if (USE_EXT_EEPROM)
uint8_t ret = 1;
uint8_t timeout = 8;
while (ret > 0 && timeout > 0)
{
ret = M24C0X_WriteByte(Address, Data);
timeout--;
Delay_ms(1);
}
2019-03-26 18:54:58 +00:00
#else
2021-01-19 08:45:27 +00:00
EE_WriteByte(Address, Data);
2019-03-26 18:54:58 +00:00
#endif
}
2019-03-26 18:54:58 +00:00
uint8_t Nvm_Read(uint8_t *DataOut, uint16_t Address, uint16_t size)
{
#if (USE_EXT_EEPROM)
2021-01-19 08:45:27 +00:00
return M24C0X_ReadByteArray(Address, DataOut, size);
2019-03-26 18:54:58 +00:00
#else
2021-01-19 08:45:27 +00:00
return EE_ReadByteArray(DataOut, Address, size);
2019-03-26 18:54:58 +00:00
#endif
}
uint8_t Nvm_Write(uint16_t Address, const uint8_t *DataIn, uint16_t size)
2019-03-26 18:54:58 +00:00
{
#if (USE_EXT_EEPROM)
uint8_t ret = 1;
uint8_t timeout = 8;
while(ret > 0 && timeout > 0)
{
ret = M24C0X_WriteByteArray(Address, (uint8_t*)DataIn, size);
timeout--;
Delay_ms(1);
}
return ret;
2019-03-26 18:54:58 +00:00
#else
2021-01-19 08:45:27 +00:00
EE_WriteByteArray(Address, DataIn, size);
return 0;
2019-03-26 18:54:58 +00:00
#endif
}
2019-03-26 18:54:58 +00:00
void Nvm_Update(void)
{
#if (USE_EXT_EEPROM)
2021-01-19 08:45:27 +00:00
// Do nothing
2019-03-26 18:54:58 +00:00
#else
2021-01-19 08:45:27 +00:00
EE_Program();
2019-03-26 18:54:58 +00:00
#endif
}