Adding some information that is missing from the DSP checksum calculation documentation page
The DSP Wiki page at https://wiki.analog.com/resources/tools-software/sigmastudio/toolbox/basicdsp/checksum discusses how to calculate the checksum for a running DSP but some important information was omitted. This information applies to the ADAU145x and ADAU146x IC families.
The relationship between PM, DM0, and DM1 to the generated header file with the programming data (DM1_DATA_Data_IC_1[DM1_DATA_SIZE_IC_1], Program_Data_IC_1[PROGRAM_SIZE_IC_1], and Param_Data_IC_1[PARAM_SIZE_IC_1]) is not provided.
The uC code snippet is unclear about the data it is working on.
The checksum for DM0 has a trick to it.
After finally figuring this out I though I would share with the community and hopefully save someone else the time it took me to figure this out.
Answer to 1:
So the relationships that are not documented are as follows:
PM is for the checksum of Program_Data_IC_1[PROGRAM_SIZE_IC_1].
DM0 is for the checksum of Param_Data_IC_1[PARAM_SIZE_IC_1.
DM1 is for DM1_DATA_Data_IC_1[DM1_DATA_SIZE_IC_1], as expected.
Answer to 2:
The code snippet for uC in the Wiki post refers to spidata and datalength but is not clear on the source of this data. Also, for those not using SPI, it may be confusing.
Below, after Answer to 3, I am providing a C function that takes the parameters as arguments. These parameters come directly from the generated header file.
So, for example, to calculate PM, include the generated header file and then use the following line of code:
PM = drv_DSP_calc_FrameWork_checksum(Program_Data_IC_1, PROGRAM_SIZE_IC_1);
Answer to 3:
The trick that was the hardest part to figure out is that, in order to calculate DM0 from the generated header file data, you must skip the first four bytes (the first word). Apparently it is not included in the checksum calculation for DM0. I suppose you could alternatively pre-initialize the sum with the first value of Param_Data_IC_1[ ] and expect the result to equal 0, but that would be unique to calculating DM0.
I chose to read the values PM, DM0, and DM1 directly into int32_t variables. My platform endianness requires the resultant value to by byte swapped. I chose to use the built in htonl() function.
Here is the complete working implementation in C except for the functions logMsg() and SIGMA_READ_REGISTER(). I have provided a byte swap implementation for completeness:
#include "YOUR_ADAU145x_GENERATED_DSP_DATA.h"
typedef enum
{
MSG_PENDING,
MSG_COMPLETE,
MSG_ADDRESS_NO_ACK,
MSG_DATA_NO_ACK,
} I2C_MSG_STATUS;
uint32_t _swapU32(uint32_t u)
{
uint32_t r = 0;
uint8_t *src = (uint8_t*) &u;
uint8_t *dst = (uint8_t*) &r;
dst[0] = src[3];
dst[1] = src[2];
dst[2] = src[1];
dst[3] = src[0];
return r;
}
int32_t drv_DSP_calc_FrameWork_checksum(ADI_REG_TYPE DataArray[], uint32_tdatalength)
{
int64_t sum = 0;
for(uint32_t i = 0; i < datalength/4; i++)
{
int32_t data = 0;
data = DataArray[4 * i + 3];
data = data | (DataArray[4 * i + 2] << 8);
data = data | (DataArray[4 * i + 1] << 16);
data = data | (DataArray[4 * i] << 24);
sum += data;
}
return -sum;
}
bool drv_DSP_ValidateChecksum(void)
{
bool result = false;
bool bChecksumCalcComplete = false;
uint8_t status_retries = 5;
uint32_t chksum_calc_status;
// Loop 5 times waiting for the checksum calculation to complete
while (status_retries-- > 0)
{
// Read the register MOD_FRAMEWORK_CHECKSUMCALCULATIONDONE_ADDR directly into chksum_calc_status - little Endian will equal 1 for success
I2C_MSG_STATUS read_response = SIGMA_READ_REGISTER(DEVICE_ADDR_IC_1, MOD_FRAMEWORK_CHECKSUMCALCULATIONDONE_ADDR, sizeof(chksum_calc_status), &chksum_calc_status);
if (read_response != MSG_COMPLETE)
{
// I2C failure - Log the error
charlogMessage[50] = {0};
snprintf(logMessage, sizeof(logMessage), "DSP Checksum Status: read status failure: %u", read_response);
logMsg(logMessage);
}
else
{
if (1 == chksum_calc_status)
{
break;
}
else
{
// I2C failure - Log the error
charlogMessage[50] = {0};
snprintf(logMessage, sizeof(logMessage), "DSP Checksum Status: checksum calculation did not complete: %u", chksum_calc_status);
logMsg(logMessage);
return result;
}
delay(10);
}
}
// Get checksum data
int32_t PM = 0, DM0 = 0, DM1 = 0;
// Read the register MOD_FRAMEWORK_PMCHECKSUM_ADDR
I2C_MSG_STATUS read_response = SIGMA_READ_REGISTER(DEVICE_ADDR_IC_1, MOD_FRAMEWORK_PMCHECKSUM_ADDR, sizeof(PM), &PM);
if (read_response != MSG_COMPLETE)
{
// I2C failure - Log the error
charlogMessage[50] = {0};
snprintf(logMessage, sizeof(logMessage), "DSP Checksum Status: read PM failure: %u", read_response);
logMsg(logMessage);
}
else
{
if ( drv_DSP_calc_FrameWork_checksum(Program_Data_IC_1, PROGRAM_SIZE_IC_1) == _swapU32(PM) )
{
// Read the register MOD_FRAMEWORK_DM1CHECKSUM_ADDR
I2C_MSG_STATUS read_response = SIGMA_READ_REGISTER(DEVICE_ADDR_IC_1, MOD_FRAMEWORK_DM1CHECKSUM_ADDR, sizeof(DM1), &DM1);
if (read_response != MSG_COMPLETE)
{
// I2C failure - Log the error
charlogMessage[50] = {0};
snprintf(logMessage, sizeof(logMessage), "DSP Checksum Status: read DM1 failure: %u", read_response);
logMsg(logMessage);
}
else
{
if ( drv_DSP_calc_FrameWork_checksum(DM1_DATA_Data_IC_1, DM1_DATA_SIZE_IC_1) == _swapU32(DM1) )
{
// Read the register MOD_FRAMEWORK_DM0CHECKSUM_ADDR
I2C_MSG_STATUS read_response = SIGMA_READ_REGISTER(DEVICE_ADDR_IC_1, MOD_FRAMEWORK_DM0CHECKSUM_ADDR, sizeof(DM0), &DM0);
if (read_response != MSG_COMPLETE)
{
// I2C failure - Log the error
charlogMessage[50] = {0};
snprintf(logMessage, sizeof(logMessage), "DSP Checksum Status: read DM0 failure: %u", read_response);
logMsg(logMessage);
}
else
{
if ( drv_DSP_calc_FrameWork_checksum(&Param_Data_IC_1[4], PARAM_SIZE_IC_1 - 4) == _swapU32(DM0) )
{
result = true;
}
}
}
}
}
}
return result;
}
Hopefully this will help someone trying to figure out the DSP checksum and maybe https://ez.analog.com/members SReddy2 will add this information to the Wiki page.
Edit Notes
Trying to clean up the source code formatting
[edited by: patcou at 5:48 PM (GMT -4) on 30 May 2025]
Audio Signal Processors
adau1452
Datasheet/Specs
checksum
adau145x
SigmaDSP Audio Processors
adau146x
Show More
Hello patcou,
Thanks for your contribution to the forum. We really appreciate your time and effort.
We will review this once and add this.
Regards,
Harish
Please log in to reply.