-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrc.c
More file actions
46 lines (34 loc) · 881 Bytes
/
Copy pathcrc.c
File metadata and controls
46 lines (34 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdlib.h>
#include <stdbool.h>
//---------------------------------------------------------
#include "inc/gpio.h"
#include "inc/crc.h"
#include "inc/rcc.h"
#include "crc.h"
//=========================================================
void crc_init(uint32_t init)
{
*CRC_INIT = init;
}
uint32_t crc32_calc(uint8_t* data, size_t size)
{
SET_BIT(REG_RCC_AHBENR, REG_RCC_AHBENR_CRCEN);
SET_CR_REV_IN(CRC_CR_REV_IN_W);
SET_BIT(CRC_CR, CRC_CR_REV_OUT);
CRC_RESET();
uint32_t ind = 0;
uint32_t full_word_bytes = size & 0b11;
while (ind < full_word_bytes)
{
*CRC_DR = *(uint32_t*)&data[ind];
ind += 4;
}
while (ind < size)
{
*(uint8_t*)(CRC_DR) = data[ind];
ind++;
}
uint32_t res = *CRC_DR ^ 0xFFFFFFFF;
CLEAR_BIT(REG_RCC_AHBENR, REG_RCC_AHBENR_CRCEN);
return res;
}