Other Parts Discussed in Thread: C2000WARE
Tool/software:
Hi Team,
This function is from C:\ti\c2000\C2000Ware_5_02_00_00\driverlib\f280013x\driverlib\adc.c
It declared a pointer offset. But we found it maybe have risk when all conditions are not met. it will run Line 88: *offset = 0U;, but before that there is no initalize offset pointer. So we think the offset pointer a random address, it very dangerous and maybe cause program crash.
Do you have any comments on this issue? Does CCS have any optimize on a no-init pointer?
//*****************************************************************************
//
// ADC_setOffsetTrim
//
//*****************************************************************************
void
ADC_setOffsetTrim(uint32_t base)
{
uint16_t *offset;
uint32_t moduleShiftVal;
uint16_t offsetShiftVal;
uint16_t analogRefRegVal;
ADC_ReferenceMode refMode;
ADC_ReferenceVoltage refVoltage;
//
// Check the arguments.
//
ASSERT(ADC_isBaseValid(base));
//
// Assign a shift amount corresponding to which ADC module is being
// configured.
//
switch(base)
{
case ADCA_BASE:
moduleShiftVal = 0U;
break;
case ADCC_BASE:
moduleShiftVal = 1U;
break;
default:
//
// Invalid base address!!
//
moduleShiftVal = 0U;
break;
}
//
// Read the Analog Reference Control Register value to determine the
// ADC reference mode and reference voltage value.
//
analogRefRegVal = HWREGH(ANALOGSUBSYS_BASE + ASYSCTL_O_ANAREFCTL);
//
// Calculate refMode and refVoltage based on input ADC base
//
refMode = (ADC_ReferenceMode)((analogRefRegVal >> moduleShiftVal) & 1U);
refVoltage = (ADC_ReferenceVoltage)((analogRefRegVal >>
(ADC_VOLTAGE_REF_REG_OFFSET + moduleShiftVal)) & 1U);
//
// Offset trim for internal VREF 3.3V is unique and stored in upper byte.
//
if((refMode == ADC_REFERENCE_INTERNAL) &&
(refVoltage == ADC_REFERENCE_3_3V))
{
offsetShiftVal = 8U;
}
else
{
offsetShiftVal = 0U;
}
//
// Set up pointer to offset trim in OTP.
//
uint32_t *offsetKey;
offsetKey = (uint32_t *)ADC_OFFSET_TRIM_KEY_OTP_MP3;
if(*offsetKey == TI_OTP_DEV_KEY)
{
offset = (uint16_t *)(ADC_OFFSET_TRIM_OTP_ADCA_MP3 + moduleShiftVal);
}
else
{
offsetKey = (uint32_t *)ADC_OFFSET_TRIM_KEY_OTP_MP1;
if(*offsetKey == TI_OTP_DEV_KEY)
{
offset = (uint16_t *)(ADC_OFFSET_TRIM_OTP_ADCA_MP1 +
moduleShiftVal);
}
else
{
*offset = 0U;
}
}
//
// Get offset trim from OTP and write it to the register.
//
EALLOW;
HWREGH(base + ADC_O_OFFTRIM) = (*offset >> offsetShiftVal) & 0xFFU;
EDIS;
}
Best Regards,
Zane