#include "CRC.h"


	uint8_t CRC8_calc(uint8_t *data, uint8_t cnt)		//CRC for STH31 sencor data check
	{
		CRC->CR 	= CRC_CR_POLYSIZE_1;
		CRC->POL 	= 0x31;
		CRC->INIT = 0xFF;
		CRC->CR |= CRC_CR_RESET;
		while(cnt)
		{
			*(__IO uint8_t*)&CRC->DR = *data++;
			cnt--;
		}
		return (uint8_t)CRC->DR;
	}

		uint16_t CRC16_calc(data_t *data)		//CRC with modbus standard for NB-IoT communication 
	{
		uint16_t *ptr = (uint16_t*)&data->LISX;
		CRC->CR 	= CRC_CR_POLYSIZE_0|CRC_CR_REV_IN_0|CRC_CR_REV_OUT;
		CRC->POL 	= 0x8005;	
		CRC->INIT = 0xFFFF;
		CRC->CR |= CRC_CR_RESET;
	for(uint16_t i=0; i<sizeof(data_t)/2;i++)
		{
		*(__IO uint16_t*)&CRC->DR = *ptr++;
		}
		return (uint16_t)CRC->DR;
	}
