Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 759 → Rev 760

/trunk/eeprom.c
62,9 → 62,10
#include "eeprom.h"
#include "led.h"
#include "crc16.h"
#include "main.h"
#include "spi_slave.h"
 
 
 
// The EEPROM M24C64 (64k) ist connected via I2C1 interface to the controller.
#define EEPROM_I2C I2C1
 
223,11 → 224,62
return(retval);
}
 
void WriteOemNameToEEPROM(void)
{
char msg[100];
u16 crc,crc2;
EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN;
memcpy(OEM_String,&LicensePtr[OEM_IN_LICENSE], OEM_NAME_LENGHT);
if(LicensePtr[OEM_IN_LICENSE] == 0)
{
OEM_String[0] = 255; // that is a command to erease the OEM-string
LicensePtr[OEM_IN_LICENSE] = 255;
UART1_PutString("\r\n Erase OEM-String\n\r ");
}
else
{
if(UART_VersionInfo.HWMajor >= 30) SendOemName = 1;
UART1_PutString("\r\n Write OEM-String: ");sprintf(msg, "(%s)\n\r",OEM_String);UART1_PutString(msg);
//sprintf(msg, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x \n\r",OEM_String[0],OEM_String[1],OEM_String[2],OEM_String[3],OEM_String[4],OEM_String[5],OEM_String[6],OEM_String[7],OEM_String[8],OEM_String[9],OEM_String[10],OEM_String[11],OEM_String[12],OEM_String[13],OEM_String[14],OEM_String[15]); UART1_PutString(msg);
}
crc = 2; // Kompatibliaet
crc += CRC16(OEM_String,16);
EEPROM_ReadBlock(EEPROM_ADR_OEM_Name_CRC,(u8 *)&crc2,2);
if((crc != crc2) || (crc == 0xffff))
{
retval = EEPROM_WriteBlock(EEPROM_ADR_OEM_Name,OEM_String,OEM_NAME_LENGHT);
if(retval == EEPROM_SUCCESS) EEPROM_WriteBlock(EEPROM_ADR_OEM_Name_CRC,(u8 *)&crc,2);
}
}
 
u8 ReadOemNameFromEEPROM(void)
{
u8 retval = 0, tmp;
u16 crc, crc2;
tmp = EEPROM_ReadBlock(EEPROM_ADR_OEM_Name,OEM_String,OEM_NAME_LENGHT);
if(EEPROM_SUCCESS == tmp) retval = 1;
crc = 2;
crc += CRC16(OEM_String,16);
EEPROM_ReadBlock(EEPROM_ADR_OEM_Name_CRC,(u8 *)&crc2,2);
if((crc == crc2) && OEM_String[0] != 0 && OEM_String[0] != 0xff)
{
memcpy(&LicensePtr[OEM_IN_LICENSE],OEM_String, OEM_NAME_LENGHT);
SendOemName = 1;
return(1);
}
else
{
OEM_String[0] = 255; // delete
return(0);
}
}
 
 
void WriteLicenseToEEPROM(u8 kompatibel)
{
u16 crc,crc2;
EEPROM_Result_t retval = EEPROM_ERROR_UNKNOWN;
if(LicensePtr[OEM_IN_LICENSE] != 255) WriteOemNameToEEPROM(); // then we have a OEM name to write
crc = kompatibel;
crc += CRC16(LicensePtr,LICENSE_SIZE_TEXT);
EEPROM_ReadBlock(EEPROM_ADR_LICENSE_DATA_CRC,(u8 *)&crc2,2);
261,7 → 313,6
crc = EEPROM_LICENSE_DATA_KOMPATIBEL;
crc += CRC16(LicensePtr,LICENSE_SIZE_TEXT);
EEPROM_ReadBlock(EEPROM_ADR_LICENSE_DATA_CRC,(u8 *)&crc2,2);
 
if(crc != crc2) retval++;
if(retval && LicensePtr[0] != 0 && LicensePtr[0] != 0xff)
{
/trunk/eeprom.h
6,9 → 6,14
#define EEPROM_ADR_MAG_CALIBRATION_EXTERN 70
#define EEPROM_ADR_LICENSE_DATA_CRC 124// - 600
#define EEPROM_ADR_LICENSE_DATA 128// - 600
#define EEPROM_ADR_OEM_Name_CRC 601// 2 bytes
#define EEPROM_ADR_OEM_Name 603// 603 - 619
 
#define EEPROM_LICENSE_DATA_KOMPATIBEL 1
 
// points into the license struct
#define OEM_IN_LICENSE 460
 
typedef enum
{
EEPROM_SUCCESS = 0,
29,6 → 34,8
extern u8 ReadLicenseFromEEPROM(void);
extern void DeleteLicenseInEEPROM(void);
extern void ClearLicenseText(void);
extern u8 ReadOemNameFromEEPROM(void);
extern void WriteOemNameToEEPROM(void);
 
#endif // EEPROM_H