altos/stmf0: Add CRC driver
[fw/altos] / src / stmf0 / ao_crc.h
1 /*
2  * Copyright © 2015 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #ifndef _AO_CRC_H_
19 #define _AO_CRC_H_
20
21 #define AO_CRC_16_CCITT         0x1021
22 #define AO_CRC_16_CDMA2000      0xc867
23 #define AO_CRC_16_DECT          0x0589
24 #define AO_CRC_16_T10_DIF       0x8bb7
25 #define AO_CRC_16_DNP           0x3d65
26 #define AO_CRC_16_ANSI          0x8005
27 #define AO_CRC_16_DEFAULT       AO_CRC_16_ANSI
28
29 #define AO_CRC_32_ANSI          0x04c11db7
30 #define AO_CRC_32_C             0x1edc6f41
31
32 #define AO_CRC_32_DEFAULT       AO_CRC_32_ANSI
33
34 static inline uint16_t
35 ao_crc_in_32_out_16(uint32_t v) {
36         stm_crc.dr.u32 = v;
37         return stm_crc.dr.u16;
38 }
39
40 static inline uint16_t
41 ao_crc_in_16_out_16(uint16_t v) {
42         stm_crc.dr.u16 = v;
43         return stm_crc.dr.u16;
44 }
45
46 static inline uint16_t
47 ao_crc_in_8_out_16(uint8_t v) {
48         stm_crc.dr.u8 = v;
49         return stm_crc.dr.u16;
50 }
51
52 void
53 ao_crc_reset(void);
54
55 void
56 ao_crc_init(void);
57
58 #endif /* _AO_CRC_H_ */