工具与软件:
以下初始化代码不起作用、但如果将 TRNG_POST_TEST_CMD_DELAY 增加到520、则会起作用(返回 true)。
但是、如果使用以下代码段、以及稍后使用 CCS 将调试器附加到 while (1)并检查寄存器 TRNG->TEST_RESULTS、结果为0xFF (PASS)。
您能否提供一种方法来检查数字测试是否已完成?
MCLK= 32MHz
//See mspm0g1507 datasheet 7.23.2
#define TRNG_STARTUP_DELAY_US 520
//Weird, why do we need this
#define TRNG_POST_TEST_CMD_DELAY 400
static bool rng_init(void) {
DL_TRNG_reset(TRNG);
DL_TRNG_enablePower(TRNG);
hal_delay_us(TRNG_STARTUP_DELAY_US);
DL_TRNG_setClockDivider(TRNG, DL_TRNG_CLOCK_DIVIDE_2); //Make sure in 9.6MHz - 20MHz range
DL_TRNG_sendCommand(TRNG, DL_TRNG_CMD_NORM_FUNC);
while (!DL_TRNG_isCommandDone(TRNG));
DL_TRNG_sendCommand(TRNG, DL_TRNG_CMD_TEST_DIG);
while (!DL_TRNG_isCommandDone(TRNG));
hal_delay_us(TRNG_POST_TEST_CMD_DELAY);
if (DL_TRNG_DIGITAL_HEALTH_TEST_SUCCESS != DL_TRNG_getDigitalHealthTestResults(TRNG)) {
////////code fall to here.
// set_led_operation(LED_AMBER, LED_OP_ON);
while(1);
return false;
}
DL_TRNG_sendCommand(TRNG, DL_TRNG_CMD_TEST_ANA);
while (!DL_TRNG_isCommandDone(TRNG));
hal_delay_us(TRNG_POST_TEST_CMD_DELAY);
if (DL_TRNG_ANALOG_HEALTH_TEST_SUCCESS != DL_TRNG_getAnalogHealthTestResults(TRNG)) {
// set_led_operation(LED_GREEN, LED_OP_ON);
while(1);
return false;
}
DL_TRNG_sendCommand(TRNG, DL_TRNG_CMD_NORM_FUNC);
while (!DL_TRNG_isCommandDone(TRNG));
DL_TRNG_clearInterruptStatus(TRNG, DL_TRNG_INTERRUPT_CMD_DONE_EVENT);
DL_TRNG_setDecimationRate(TRNG, DL_TRNG_DECIMATION_RATE_8);
DL_TRNG_clearInterruptStatus(TRNG, (DL_TRNG_INTERRUPT_CAPTURE_RDY_EVENT));
// DL_TRNG_enableInterrupt(TRNG, (DL_TRNG_INTERRUPT_CAPTURE_RDY_EVENT));
//Discard the 1st output
while (!DL_TRNG_isCaptureReady(TRNG));
DL_TRNG_getCapture(TRNG);
return true;
}