aboutsummaryrefslogtreecommitdiff
path: root/lib/stm32/crc.c
diff options
context:
space:
mode:
authorKarl Palsson2012-06-18 18:57:45 +0000
committerPiotr Esden-Tempski2012-06-29 02:08:53 -0700
commit450c3e00a16c3d8bf1a9282d2ca4b45e8b4d9045 (patch)
treeda45045396bf1b6ef19bce1b8d1c95984bf4dab4 /lib/stm32/crc.c
parent98174e4a0c6acfe5e427c58fdccbe0f8652d9214 (diff)
Basic helper routines for CRC
Note, the CRC block is pretty useless for interoperability. It only operates on 32bit chunks, and in a different bit order. No attempt to make full helpers for compatibility with other implementations has been done. https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FCRC%20computation&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=2006
Diffstat (limited to 'lib/stm32/crc.c')
-rw-r--r--lib/stm32/crc.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/stm32/crc.c b/lib/stm32/crc.c
new file mode 100644
index 0000000..bbbe1fd
--- /dev/null
+++ b/lib/stm32/crc.c
@@ -0,0 +1,44 @@
+/*
+ * This file is part of the libopencm3 project.
+ *
+ * Copyright (C) 2012 Karl Palsson <karlp@remake.is>
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libopencm3/stm32/crc.h>
+
+void crc_reset(void)
+{
+ CRC_CR |= CRC_CR_RESET;
+}
+
+u32 crc_calculate(u32 data)
+{
+ CRC_DR = data;
+ // Data sheet says this blocks until it's ready....
+ return CRC_DR;
+}
+
+u32 crc_calculate_block(u32 *datap, int size)
+{
+ int i;
+ for (i = 0; i < size; i++) {
+ CRC_DR = datap[i];
+ }
+ return CRC_DR;
+}
+
+
+