/* Calculate the crc value of data by byte.  */
uint32_t ald_crc_calculate(ald_crc_handle_t *hperh, uint8_t *buf, uint32_t size)
/* Calculate the crc value of data by byte.  */
uint32_t ald_crc_calculate(ald_crc_handle_t *hperh, uint8_t *buf, uint32_t size)
{
    uint32_t i;
    uint32_t ret;
    assert_param(IS_CRC(hperh->perh));
    if (buf == NULL || size == 0)
        return 0;
    __LOCK(hperh);
    MODIFY_REG(hperh->perh->CR, CRC_CR_DATLEN_MSK, ALD_CRC_DATASIZE_8 << CRC_CR_DATLEN_POSS);
    hperh->state = ALD_CRC_STATE_BUSY;
    for (i = 0; i < size; i++)
        *((volatile uint8_t *)&(hperh->perh->DATA)) = buf[i];
    ret          = CRC->CHECKSUM;
    hperh->state = ALD_CRC_STATE_READY;
    __UNLOCK(hperh);
    return ret;
}