📄 teds.c
字号:
0, // Calib TEDS ext key
0, // NonVolatile Data ext key
0, // Industry TEDS ext key
0, // End User App-Spec ext key
0L, // Writable TEDS length
ACTUATOR, // Channel Type Key
// Physical Units:
0x04,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0.0, // Lower Range Limit
255.0, // Upper Range Limit
0.0, // Worst Case Uncertainty
0, // Self Test Key
0, // Channel Data Model
CH2_DATA_MODEL_LENGTH, // Chan Data Model Length
1, // Chan Model Sig Bits
0, // Chan Data Reps
0.0, // Series Origin
0.0, // Series Increment
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Series Units
0.0025, // Chan Update Time
0.001, // Chan Write Setup Time
0.001, // Chan Read Setup Time
0.005, // Chan Samp Period
0.005, // Chan Warmup Time
0.5, // Chan Agg Hold Off Time
1.0, // Timing Correction
0.5, // Trigger Accuracy
0, // Event Sequence Options
0 // Checksum for this Chan-TEDS
};
// The TEDS Data area must be programmed one byte at a time.
// Therefore, we need to access the TEDS structure as a byte array.
//
unsigned char *pTEDSByteArray = &Ch2TEDS;
// Calculate the Checksum for the Channel 1 TEDS, and fill it into
// the Ch2TEDS data structure.
//
Ch2TEDS.Checksum = DAT_CalcChecksum(pTEDSByteArray);
// Now program the Meta-TEDS structure into the TEDS Flash data area.
//
return TEDS_WriteTEDSToFlash( CH2_TEDS_ADDRESS,
pTEDSByteArray,
Ch2TEDS.Length+sizeof(U32L) );
}
// Storing and Retrieving TEDS to/from the Data Flash:
// --------------------------------------------------
boolean TEDS_WriteTEDSToFlash( unsigned char ucStartAddress,
unsigned char* pTEDSArray,
U32L BytesToWrite)
{
U32L Count=0;
boolean bRet=TRUE;
// Setup the start address for writing to the Data Flash
//
EADRL = ucStartAddress;
// Write all bytes (4-byte pages at a time) into the data flash
//
while(Count < (BytesToWrite-1))
{
EDATA1 = *(pTEDSArray+Count);
EDATA2 = *(pTEDSArray+Count+1);
EDATA3 = *(pTEDSArray+Count+2);
EDATA4 = *(pTEDSArray+Count+3);
// Write the 4 bytes just setup...
//
WRITE_BYTEPAGE;
// ...verify them. If they don't verify, exit false now.
//
VERIFY_BYTEPAGE;
if(ECON != 0x00) {
bRet = FALSE; break;
}
// Incement the 'start address' in flash for writing the next 4-bytes,
// and increment the count pointer to the start of the next byte in
// memory.
//
EADRL += 1;
Count += 4;
}
return bRet;
}
boolean TEDS_ReadTEDSfromFlash( unsigned char ucStartAddress,
unsigned char* pTEDSArray )
{
U32L Count=0, BytesToRead=0;
boolean bRet=TRUE;
union {
U32L TEDSLength;
unsigned char Array[4];
}FourBytes;
// Setup the start address for reading from the Data Flash
//
EADRL = ucStartAddress;
// Read the first 4-bytes from the TEDS specified:
//
READ_BYTEPAGE;
FourBytes.Array[0] = EDATA1;
FourBytes.Array[1] = EDATA2;
FourBytes.Array[2] = EDATA3;
FourBytes.Array[3] = EDATA4;
BytesToRead = FourBytes.TEDSLength + sizeof(U32L);
// Read all bytes, 4-bytes pages at a time, into the buffer provided
//
while(Count < (BytesToRead-1))
{
READ_BYTEPAGE;
*(pTEDSArray+Count) = EDATA1;
*(pTEDSArray+Count+1) = EDATA2;
*(pTEDSArray+Count+2) = EDATA3;
*(pTEDSArray+Count+3) = EDATA4;
// Incement the 'start address' in flash for reading the next 4-bytes,
// and increment the count pointer to the start of the next byte in
// buffer memory.
//
EADRL += 1;
Count += 4;
}
return bRet;
}
boolean TEDS_InitTEDSFlash(void)
{
// Erase the FLASH memory area.
//
ERASE_ALL_BYTEPAGES;
// If the flash was erased, all bytes it should be 0xFF.
// Pick one at random and verify that it is.
//
READ_BYTEPAGE;
if(EDATA3 == 0xFF) return TRUE;
else return FALSE;
}
// Read the information for a TEDS from the data flash into a buffer in
// RAM. The supplied data buffer must be big enough to hold the TEDS data.
//
boolean TEDS_GetTEDSHandle( unsigned char ucTEDS, unsigned char ucChan,
unsigned char *pTEDSBuffer )
{
unsigned char ucTEDSAddress;
boolean bRet=TRUE;
switch(ucTEDS)
{
case(TEDS_META): ucTEDSAddress = META_TEDS_ADDRESS; break;
case(TEDS_CHANNEL):
if (ucChan==1) ucTEDSAddress = CH1_TEDS_ADDRESS;
else if(ucChan==2) ucTEDSAddress = CH2_TEDS_ADDRESS;
//
// All other implemented channels should go in here.
//
else bRet = FALSE;
break;
// There are no other TEDS implemented, so return FALSE if
// they have been requested...
//
case(TEDS_CHANNEL_ID):
case(TEDS_META_ID):
case(TEDS_CALIBRATION):
case(TEDS_CALIB_ID):
case(TEDS_END_USER):
default: bRet = FALSE; break;
}
if(bRet) TEDS_ReadTEDSfromFlash(ucTEDSAddress, pTEDSBuffer);
return bRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -