@@ -20,7 +20,7 @@ use crate::rcc;
20
20
use crate :: stm32:: CRC ;
21
21
use core:: ptr;
22
22
23
- /// Extension trait to constrain the FLASH peripheral
23
+ /// Extension trait to constrain the FLASH peripheral.
24
24
pub trait CrcExt {
25
25
/// Constrains the CRC peripheral to play nicely with the other abstractions
26
26
fn constrain ( self , ahb1 : & mut rcc:: AHB1 ) -> Config ;
@@ -141,19 +141,32 @@ impl Config {
141
141
}
142
142
}
143
143
144
- /// Constrained Crc peripheral.
144
+ /// Constrained CRC peripheral.
145
145
pub struct Crc { }
146
146
147
147
impl Crc {
148
- /// This will reset the Crc to its initial condition.
148
+ /// This will reset the CRC to its initial condition.
149
149
#[ inline]
150
150
pub fn reset ( & mut self ) {
151
151
let crc = unsafe { & ( * CRC :: ptr ( ) ) } ;
152
152
153
153
crc. cr . modify ( |_, w| w. reset ( ) . set_bit ( ) ) ;
154
154
}
155
155
156
- /// Feed the Crc with data, this will internally optimize for word writes.
156
+ /// This will reset the CRC to its initial condition, however with a specific initial value.
157
+ /// This is very useful if many task are sharing the CRC peripheral, as one can read out the
158
+ /// intermediate result, store it until the next time a task runs, and initialize with the
159
+ /// intermediate result to continue where the task left off.
160
+ #[ inline]
161
+ pub fn reset_with_inital_value ( & mut self , initial_value : u32 ) {
162
+ let crc = unsafe { & ( * CRC :: ptr ( ) ) } ;
163
+
164
+ crc. init . write ( |w| unsafe { w. crc_init ( ) . bits ( initial_value) } ) ;
165
+ crc. cr . modify ( |_, w| w. reset ( ) . set_bit ( ) ) ;
166
+ }
167
+
168
+ /// Feed the CRC with data, this will internally optimize for word writes.
169
+ #[ inline]
157
170
pub fn feed ( & mut self , data : & [ u8 ] ) {
158
171
let crc = unsafe { & ( * CRC :: ptr ( ) ) } ;
159
172
for byte in data {
@@ -166,7 +179,7 @@ impl Crc {
166
179
}
167
180
168
181
/// Get the result of the CRC, depending on the polynomial chosen only a certain amount of the
169
- /// bits are the result. This will reset the Crc peripheral after use.
182
+ /// bits are the result. This will reset the CRC peripheral after use.
170
183
#[ inline]
171
184
pub fn result ( & mut self ) -> u32 {
172
185
let ret = self . peek_result ( ) ;
0 commit comments