Crc::Crc(const Config &config) : m_seed(config.seed), m_is_init(true) { Sim::SetEnableClockGate(Sim::ClockGate::kCrc, true); NewInstance(config.seed); CRC0->CTRL = 0 | CRC_CTRL_TCRC_MASK | CRC_CTRL_TOT(1) | CRC_CTRL_TOTR(1) | CRC_CTRL_FXOR_MASK; CRC0->GPOLY = config.polynomial; }
/*! * @brief Starts checksum computation. * * Configures the CRC module for the specified CRC protocol. @n * Starts the checksum computation by writing the seed value * * @param base CRC peripheral address. * @param config Pointer to protocol configuration structure. */ static void crc_ConfigureAndStart(CRC_Type *base, const crc_module_config_t *config) { uint32_t crcControl; /* pre-compute value for CRC control registger based on user configuraton without WAS field */ crcControl = 0 | CRC_CTRL_TOT(config->writeTranspose) | CRC_CTRL_TOTR(config->readTranspose) | CRC_CTRL_FXOR(config->complementChecksum) | CRC_CTRL_TCRC(config->crcBits); /* make sure the control register is clear - WAS is deasserted, and protocol is set */ base->CTRL = crcControl; /* write polynomial register */ base->GPOLY = config->polynomial; /* write pre-computed control register value along with WAS to start checksum computation */ base->CTRL = crcControl | CRC_CTRL_WAS(true); /* write seed (initial checksum) */ base->DATA = config->seed; /* deassert WAS by writing pre-computed CRC control register value */ base->CTRL = crcControl; }