ZHDU116G January 2018 – June 2024 CC1312PSIP , CC1312R , CC1352P , CC1352R , CC2642R , CC2642R-Q1 , CC2652P , CC2652PSIP , CC2652R , CC2652RB , CC2652RSIP , CC2662R-Q1
伪代码中的以下软件示例描述了通常由主机软件执行的操作。该示例使用一个新的哈希会话启动哈希引擎,该会话通过 DMA 接口接收输入数据。最后,中间摘要(非最终哈希操作)或最终的哈希摘要(最终哈希操作)通过从接口作为结果摘要被读取。
// configure master control module
write CTRL_ALG_SEL 0x0000_0008 // enable DMA path to the SHA-2 engine
write CTRL_INT_CLR 0x0000_0001 // clear any outstanding events
// configure hash engine
write HASH_MODE = 0x0000_0021 // indicate the start of a new hash session and SHA512
write HASH_LENGTH_L// write the length of the message (lo)
write HASH_LENGTH_H// write the length of the message (hi)
// if the final digest is required (pad the input DMA data), write the following register
write HASH_IO_BUF_CTRL = 0x80 // pad the data that is transferred via DMA
// configure DMAC
write DMAC_CH0_CTRL 0x0000_00001 // enable DMA channel 0 for message data
write DMAC_CH0_EXTADDR <ext_memory_address> // base address of the data in ext. memory
write DMAC_CH0_DMALENGTH <length> // input data in bytes, equal to
// the message length
wait CTRL_INT_STAT[0] = '1' // wait for operation done (hash and DMAC are ready)
check CTRL_INT_STAT[31] == '0' // check for the absence of errors
// read digest
read HASH_DIGEST_A
...
read HASH_DIGEST_P
// acknowledge result and clear interrupts
write HASH_IO_BUF_CTRL = 0x0000_0001// acknowledge reading of the digest
write CTRL_INT_CLR 0x0000_0001// clear the interrupt
write CTRL_ALG_SEL 0x0000_0000// disable the master control/DMA clock
// end of algorithm