From a95d6776dea86cdc4bdc3512505ba7e75365c127 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jan 2015 16:55:27 -0800 Subject: [PATCH] altos/stmf0: Add CRC driver Sets up the stm32f0 CRC hardware, exposing inline functions to access it. DMA access is possible, but usbtrng can't use that. Signed-off-by: Keith Packard --- src/stmf0/ao_crc.h | 58 +++++++++++++++++++++++++++++++++++++++++++++ src/stmf0/stm32f0.h | 32 +++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/stmf0/ao_crc.h diff --git a/src/stmf0/ao_crc.h b/src/stmf0/ao_crc.h new file mode 100644 index 00000000..cd011d3a --- /dev/null +++ b/src/stmf0/ao_crc.h @@ -0,0 +1,58 @@ +/* + * Copyright © 2015 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#ifndef _AO_CRC_H_ +#define _AO_CRC_H_ + +#define AO_CRC_16_CCITT 0x1021 +#define AO_CRC_16_CDMA2000 0xc867 +#define AO_CRC_16_DECT 0x0589 +#define AO_CRC_16_T10_DIF 0x8bb7 +#define AO_CRC_16_DNP 0x3d65 +#define AO_CRC_16_ANSI 0x8005 +#define AO_CRC_16_DEFAULT AO_CRC_16_ANSI + +#define AO_CRC_32_ANSI 0x04c11db7 +#define AO_CRC_32_C 0x1edc6f41 + +#define AO_CRC_32_DEFAULT AO_CRC_32_ANSI + +static inline uint16_t +ao_crc_in_32_out_16(uint32_t v) { + stm_crc.dr.u32 = v; + return stm_crc.dr.u16; +} + +static inline uint16_t +ao_crc_in_16_out_16(uint16_t v) { + stm_crc.dr.u16 = v; + return stm_crc.dr.u16; +} + +static inline uint16_t +ao_crc_in_8_out_16(uint8_t v) { + stm_crc.dr.u8 = v; + return stm_crc.dr.u16; +} + +void +ao_crc_reset(void); + +void +ao_crc_init(void); + +#endif /* _AO_CRC_H_ */ diff --git a/src/stmf0/stm32f0.h b/src/stmf0/stm32f0.h index 32864ced..ce8ca456 100644 --- a/src/stmf0/stm32f0.h +++ b/src/stmf0/stm32f0.h @@ -23,6 +23,7 @@ typedef volatile uint32_t vuint32_t; typedef volatile void * vvoid_t; typedef volatile uint16_t vuint16_t; +typedef volatile uint8_t vuint8_t; struct stm_gpio { vuint32_t moder; @@ -568,6 +569,37 @@ extern struct stm_pwr stm_pwr; #define STM_PWR_CSR_SBF (1) #define STM_PWR_CSR_WUF (0) +struct stm_crc { + union { + vuint32_t u32; + vuint16_t u16; + vuint8_t u8; + } dr; + vuint32_t idr; + vuint32_t cr; + uint32_t _0c; + + vuint32_t init; + vuint32_t pol; +}; + +extern struct stm_crc stm_crc; + +#define stm_crc (*((struct stm_crc *) 0x40023000)) + +#define STM_CRC_CR_REV_OUT 7 +#define STM_CRC_CR_REV_IN 5 +#define STM_CRC_CR_REV_IN_NONE 0 +#define STM_CRC_CR_REV_IN_BY_BYTE 1 +#define STM_CRC_CR_REV_IN_BY_HALF_WORD 2 +#define STM_CRC_CR_REV_IN_BY_WORD 3 +#define STM_CRC_CR_POLYSIZE 3 +#define STM_CRC_CR_POLYSIZE_32 0 +#define STM_CRC_CR_POLYSIZE_16 1 +#define STM_CRC_CR_POLYSIZE_8 2 +#define STM_CRC_CR_POLYSIZE_7 3 +#define STM_CRC_CR_RESET 0 + /* The SYSTICK starts at 0xe000e010 */ struct stm_systick { -- 2.30.2