diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-02-23 01:45:10 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-23 01:45:10 +0100 |
| commit | a6a5d9913cda2ecfe89b63fa0bcf7afaebc2dac0 (patch) | |
| tree | 14124a6f34d351a979cb110a0ce566b588f5d272 /embassy-stm32/src/can/fd/message_ram/txbuffer_element.rs | |
| parent | 5b7e2d88265b5633fa53047961598fbc38bffed0 (diff) | |
| parent | 2855bb69680a42a721fe88168657ea1e634e8766 (diff) | |
Merge branch 'main' into stm32l0-reset-rtc
Diffstat (limited to 'embassy-stm32/src/can/fd/message_ram/txbuffer_element.rs')
| -rw-r--r-- | embassy-stm32/src/can/fd/message_ram/txbuffer_element.rs | 433 |
1 files changed, 433 insertions, 0 deletions
diff --git a/embassy-stm32/src/can/fd/message_ram/txbuffer_element.rs b/embassy-stm32/src/can/fd/message_ram/txbuffer_element.rs new file mode 100644 index 000000000..455406a1c --- /dev/null +++ b/embassy-stm32/src/can/fd/message_ram/txbuffer_element.rs | |||
| @@ -0,0 +1,433 @@ | |||
| 1 | // Note: This file is copied and modified from fdcan crate by Richard Meadows | ||
| 2 | |||
| 3 | #![allow(non_camel_case_types)] | ||
| 4 | #![allow(non_snake_case)] | ||
| 5 | #![allow(unused)] | ||
| 6 | |||
| 7 | use super::common::{BRS_R, DLC_R, ESI_R, FDF_R, ID_R, RTR_R, XTD_R}; | ||
| 8 | use super::enums::{ | ||
| 9 | BitRateSwitching, DataLength, ErrorStateIndicator, Event, EventControl, FrameFormat, IdType, | ||
| 10 | RemoteTransmissionRequest, | ||
| 11 | }; | ||
| 12 | use super::generic; | ||
| 13 | |||
| 14 | #[doc = "Reader of register TxBufferElement"] | ||
| 15 | pub(crate) type R = generic::R<super::TxBufferElementHeaderType, super::TxBufferElementHeader>; | ||
| 16 | #[doc = "Writer for register TxBufferElement"] | ||
| 17 | pub(crate) type W = generic::W<super::TxBufferElementHeaderType, super::TxBufferElementHeader>; | ||
| 18 | impl generic::ResetValue for super::TxBufferElementHeader { | ||
| 19 | type Type = super::TxBufferElementHeaderType; | ||
| 20 | |||
| 21 | #[allow(dead_code)] | ||
| 22 | #[inline(always)] | ||
| 23 | fn reset_value() -> Self::Type { | ||
| 24 | [0; 2] | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | #[doc = "Write proxy for field `ESI`"] | ||
| 29 | pub(crate) struct ESI_W<'a> { | ||
| 30 | w: &'a mut W, | ||
| 31 | } | ||
| 32 | impl<'a> ESI_W<'a> { | ||
| 33 | #[doc = r"Writes `variant` to the field"] | ||
| 34 | #[inline(always)] | ||
| 35 | #[allow(dead_code)] | ||
| 36 | pub fn set_error_indicator(self, esi: ErrorStateIndicator) -> &'a mut W { | ||
| 37 | self.bit(esi as u8 != 0) | ||
| 38 | } | ||
| 39 | |||
| 40 | #[doc = r"Sets the field bit"] | ||
| 41 | #[inline(always)] | ||
| 42 | #[allow(dead_code)] | ||
| 43 | pub fn set_bit(self) -> &'a mut W { | ||
| 44 | self.bit(true) | ||
| 45 | } | ||
| 46 | #[doc = r"Clears the field bit"] | ||
| 47 | #[inline(always)] | ||
| 48 | #[allow(dead_code)] | ||
| 49 | pub fn clear_bit(self) -> &'a mut W { | ||
| 50 | self.bit(false) | ||
| 51 | } | ||
| 52 | #[doc = r"Writes raw bits to the field"] | ||
| 53 | #[inline(always)] | ||
| 54 | #[allow(dead_code)] | ||
| 55 | pub fn bit(self, value: bool) -> &'a mut W { | ||
| 56 | self.w.bits[0] = (self.w.bits[0] & !(0x01 << 31)) | (((value as u32) & 0x01) << 31); | ||
| 57 | self.w | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | #[doc = "Write proxy for field `XTD`"] | ||
| 62 | pub(crate) struct XTD_W<'a> { | ||
| 63 | w: &'a mut W, | ||
| 64 | } | ||
| 65 | impl<'a> XTD_W<'a> { | ||
| 66 | #[doc = r"Writes `variant` to the field"] | ||
| 67 | #[inline(always)] | ||
| 68 | #[allow(dead_code)] | ||
| 69 | pub fn set_id_type(self, idt: IdType) -> &'a mut W { | ||
| 70 | self.bit(idt as u8 != 0) | ||
| 71 | } | ||
| 72 | |||
| 73 | #[doc = r"Sets the field bit"] | ||
| 74 | #[inline(always)] | ||
| 75 | #[allow(dead_code)] | ||
| 76 | pub fn set_bit(self) -> &'a mut W { | ||
| 77 | self.bit(true) | ||
| 78 | } | ||
| 79 | #[doc = r"Clears the field bit"] | ||
| 80 | #[inline(always)] | ||
| 81 | #[allow(dead_code)] | ||
| 82 | pub fn clear_bit(self) -> &'a mut W { | ||
| 83 | self.bit(false) | ||
| 84 | } | ||
| 85 | #[doc = r"Writes raw bits to the field"] | ||
| 86 | #[inline(always)] | ||
| 87 | #[allow(dead_code)] | ||
| 88 | pub fn bit(self, value: bool) -> &'a mut W { | ||
| 89 | self.w.bits[0] = (self.w.bits[0] & !(0x01 << 30)) | (((value as u32) & 0x01) << 30); | ||
| 90 | self.w | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | #[doc = "Write proxy for field `RTR`"] | ||
| 95 | pub(crate) struct RTR_W<'a> { | ||
| 96 | w: &'a mut W, | ||
| 97 | } | ||
| 98 | impl<'a> RTR_W<'a> { | ||
| 99 | #[doc = r"Writes `variant` to the field"] | ||
| 100 | #[inline(always)] | ||
| 101 | #[allow(dead_code)] | ||
| 102 | pub fn set_rtr(self, rtr: RemoteTransmissionRequest) -> &'a mut W { | ||
| 103 | self.bit(rtr as u8 != 0) | ||
| 104 | } | ||
| 105 | |||
| 106 | #[doc = r"Sets the field bit"] | ||
| 107 | #[inline(always)] | ||
| 108 | #[allow(dead_code)] | ||
| 109 | pub fn set_bit(self) -> &'a mut W { | ||
| 110 | self.bit(true) | ||
| 111 | } | ||
| 112 | #[doc = r"Clears the field bit"] | ||
| 113 | #[inline(always)] | ||
| 114 | #[allow(dead_code)] | ||
| 115 | pub fn clear_bit(self) -> &'a mut W { | ||
| 116 | self.bit(false) | ||
| 117 | } | ||
| 118 | #[doc = r"Writes raw bits to the field"] | ||
| 119 | #[inline(always)] | ||
| 120 | #[allow(dead_code)] | ||
| 121 | pub fn bit(self, value: bool) -> &'a mut W { | ||
| 122 | self.w.bits[0] = (self.w.bits[0] & !(0x01 << 29)) | (((value as u32) & 0x01) << 29); | ||
| 123 | self.w | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | #[doc = "Write proxy for field `ID`"] | ||
| 128 | pub(crate) struct ID_W<'a> { | ||
| 129 | w: &'a mut W, | ||
| 130 | } | ||
| 131 | impl<'a> ID_W<'a> { | ||
| 132 | #[doc = r"Writes raw bits to the field"] | ||
| 133 | #[inline(always)] | ||
| 134 | #[allow(dead_code)] | ||
| 135 | pub unsafe fn bits(self, value: u32) -> &'a mut W { | ||
| 136 | self.w.bits[0] = (self.w.bits[0] & !(0x1FFFFFFF)) | ((value as u32) & 0x1FFFFFFF); | ||
| 137 | self.w | ||
| 138 | } | ||
| 139 | } | ||
| 140 | |||
| 141 | #[doc = "Write proxy for field `DLC`"] | ||
| 142 | pub(crate) struct DLC_W<'a> { | ||
| 143 | w: &'a mut W, | ||
| 144 | } | ||
| 145 | impl<'a> DLC_W<'a> { | ||
| 146 | #[doc = r"Writes raw bits to the field"] | ||
| 147 | #[inline(always)] | ||
| 148 | #[allow(dead_code)] | ||
| 149 | pub unsafe fn bits(self, value: u8) -> &'a mut W { | ||
| 150 | self.w.bits[1] = (self.w.bits[1] & !(0x0F << 16)) | (((value as u32) & 0x0F) << 16); | ||
| 151 | self.w | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | #[doc = "Write proxy for field `BRS`"] | ||
| 156 | pub(crate) struct BRS_W<'a> { | ||
| 157 | w: &'a mut W, | ||
| 158 | } | ||
| 159 | impl<'a> BRS_W<'a> { | ||
| 160 | #[doc = r"Writes `variant` to the field"] | ||
| 161 | #[inline(always)] | ||
| 162 | #[allow(dead_code)] | ||
| 163 | pub fn set_brs(self, brs: BitRateSwitching) -> &'a mut W { | ||
| 164 | self.bit(brs as u8 != 0) | ||
| 165 | } | ||
| 166 | |||
| 167 | #[doc = r"Sets the field bit"] | ||
| 168 | #[inline(always)] | ||
| 169 | #[allow(dead_code)] | ||
| 170 | pub fn set_bit(self) -> &'a mut W { | ||
| 171 | self.bit(true) | ||
| 172 | } | ||
| 173 | #[doc = r"Clears the field bit"] | ||
| 174 | #[inline(always)] | ||
| 175 | #[allow(dead_code)] | ||
| 176 | pub fn clear_bit(self) -> &'a mut W { | ||
| 177 | self.bit(false) | ||
| 178 | } | ||
| 179 | #[doc = r"Writes raw bits to the field"] | ||
| 180 | #[inline(always)] | ||
| 181 | #[allow(dead_code)] | ||
| 182 | pub fn bit(self, value: bool) -> &'a mut W { | ||
| 183 | self.w.bits[1] = (self.w.bits[1] & !(0x01 << 20)) | (((value as u32) & 0x01) << 20); | ||
| 184 | self.w | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | #[doc = "Write proxy for field `FDF`"] | ||
| 189 | pub(crate) struct FDF_W<'a> { | ||
| 190 | w: &'a mut W, | ||
| 191 | } | ||
| 192 | impl<'a> FDF_W<'a> { | ||
| 193 | #[doc = r"Writes `variant` to the field"] | ||
| 194 | #[inline(always)] | ||
| 195 | #[allow(dead_code)] | ||
| 196 | pub fn set_format(self, fdf: FrameFormat) -> &'a mut W { | ||
| 197 | self.bit(fdf as u8 != 0) | ||
| 198 | } | ||
| 199 | |||
| 200 | #[doc = r"Sets the field bit"] | ||
| 201 | #[inline(always)] | ||
| 202 | #[allow(dead_code)] | ||
| 203 | pub fn set_bit(self) -> &'a mut W { | ||
| 204 | self.bit(true) | ||
| 205 | } | ||
| 206 | #[doc = r"Clears the field bit"] | ||
| 207 | #[inline(always)] | ||
| 208 | #[allow(dead_code)] | ||
| 209 | pub fn clear_bit(self) -> &'a mut W { | ||
| 210 | self.bit(false) | ||
| 211 | } | ||
| 212 | #[doc = r"Writes raw bits to the field"] | ||
| 213 | #[inline(always)] | ||
| 214 | #[allow(dead_code)] | ||
| 215 | pub fn bit(self, value: bool) -> &'a mut W { | ||
| 216 | self.w.bits[1] = (self.w.bits[1] & !(0x01 << 21)) | (((value as u32) & 0x01) << 21); | ||
| 217 | self.w | ||
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | #[doc = "Reader of field `EFC`"] | ||
| 222 | pub(crate) type EFC_R = generic::R<bool, EventControl>; | ||
| 223 | impl EFC_R { | ||
| 224 | pub fn to_event_control(&self) -> EventControl { | ||
| 225 | match self.bit() { | ||
| 226 | false => EventControl::DoNotStore, | ||
| 227 | true => EventControl::Store, | ||
| 228 | } | ||
| 229 | } | ||
| 230 | } | ||
| 231 | #[doc = "Write proxy for field `EFC`"] | ||
| 232 | pub(crate) struct EFC_W<'a> { | ||
| 233 | w: &'a mut W, | ||
| 234 | } | ||
| 235 | impl<'a> EFC_W<'a> { | ||
| 236 | #[doc = r"Writes `variant` to the field"] | ||
| 237 | #[inline(always)] | ||
| 238 | #[allow(dead_code)] | ||
| 239 | pub fn set_event_control(self, efc: EventControl) -> &'a mut W { | ||
| 240 | self.bit(match efc { | ||
| 241 | EventControl::DoNotStore => false, | ||
| 242 | EventControl::Store => true, | ||
| 243 | }) | ||
| 244 | } | ||
| 245 | |||
| 246 | #[doc = r"Sets the field bit"] | ||
| 247 | #[inline(always)] | ||
| 248 | #[allow(dead_code)] | ||
| 249 | pub fn set_bit(self) -> &'a mut W { | ||
| 250 | self.bit(true) | ||
| 251 | } | ||
| 252 | #[doc = r"Clears the field bit"] | ||
| 253 | #[inline(always)] | ||
| 254 | #[allow(dead_code)] | ||
| 255 | pub fn clear_bit(self) -> &'a mut W { | ||
| 256 | self.bit(false) | ||
| 257 | } | ||
| 258 | #[doc = r"Writes raw bits to the field"] | ||
| 259 | #[inline(always)] | ||
| 260 | #[allow(dead_code)] | ||
| 261 | pub fn bit(self, value: bool) -> &'a mut W { | ||
| 262 | self.w.bits[1] = (self.w.bits[1] & !(0x01 << 23)) | (((value as u32) & 0x01) << 23); | ||
| 263 | self.w | ||
| 264 | } | ||
| 265 | } | ||
| 266 | |||
| 267 | struct Marker(u8); | ||
| 268 | impl From<Event> for Marker { | ||
| 269 | fn from(e: Event) -> Marker { | ||
| 270 | match e { | ||
| 271 | Event::NoEvent => Marker(0), | ||
| 272 | Event::Event(mm) => Marker(mm), | ||
| 273 | } | ||
| 274 | } | ||
| 275 | } | ||
| 276 | |||
| 277 | #[doc = "Reader of field `MM`"] | ||
| 278 | pub(crate) type MM_R = generic::R<u8, u8>; | ||
| 279 | #[doc = "Write proxy for field `MM`"] | ||
| 280 | pub(crate) struct MM_W<'a> { | ||
| 281 | w: &'a mut W, | ||
| 282 | } | ||
| 283 | impl<'a> MM_W<'a> { | ||
| 284 | #[doc = r"Writes raw bits to the field"] | ||
| 285 | #[inline(always)] | ||
| 286 | pub unsafe fn bits(self, value: u8) -> &'a mut W { | ||
| 287 | self.w.bits[1] = (self.w.bits[1] & !(0x7F << 24)) | (((value as u32) & 0x7F) << 24); | ||
| 288 | self.w | ||
| 289 | } | ||
| 290 | |||
| 291 | fn set_message_marker(self, mm: Marker) -> &'a mut W { | ||
| 292 | unsafe { self.bits(mm.0) } | ||
| 293 | } | ||
| 294 | } | ||
| 295 | |||
| 296 | impl R { | ||
| 297 | #[doc = "Byte 0 - Bits 0:28 - ID"] | ||
| 298 | #[inline(always)] | ||
| 299 | pub fn id(&self) -> ID_R { | ||
| 300 | ID_R::new(((self.bits[0]) & 0x1FFFFFFF) as u32) | ||
| 301 | } | ||
| 302 | #[doc = "Byte 0 - Bit 29 - RTR"] | ||
| 303 | #[inline(always)] | ||
| 304 | pub fn rtr(&self) -> RTR_R { | ||
| 305 | RTR_R::new(((self.bits[0] >> 29) & 0x01) != 0) | ||
| 306 | } | ||
| 307 | #[doc = "Byte 0 - Bit 30 - XTD"] | ||
| 308 | #[inline(always)] | ||
| 309 | pub fn xtd(&self) -> XTD_R { | ||
| 310 | XTD_R::new(((self.bits[0] >> 30) & 0x01) != 0) | ||
| 311 | } | ||
| 312 | #[doc = "Byte 0 - Bit 30 - ESI"] | ||
| 313 | #[inline(always)] | ||
| 314 | pub fn esi(&self) -> ESI_R { | ||
| 315 | ESI_R::new(((self.bits[0] >> 31) & 0x01) != 0) | ||
| 316 | } | ||
| 317 | #[doc = "Byte 1 - Bits 16:19 - DLC"] | ||
| 318 | #[inline(always)] | ||
| 319 | pub fn dlc(&self) -> DLC_R { | ||
| 320 | DLC_R::new(((self.bits[1] >> 16) & 0x0F) as u8) | ||
| 321 | } | ||
| 322 | #[doc = "Byte 1 - Bits 20 - BRS"] | ||
| 323 | #[inline(always)] | ||
| 324 | pub fn brs(&self) -> BRS_R { | ||
| 325 | BRS_R::new(((self.bits[1] >> 20) & 0x01) != 0) | ||
| 326 | } | ||
| 327 | #[doc = "Byte 1 - Bits 20 - FDF"] | ||
| 328 | #[inline(always)] | ||
| 329 | pub fn fdf(&self) -> FDF_R { | ||
| 330 | FDF_R::new(((self.bits[1] >> 21) & 0x01) != 0) | ||
| 331 | } | ||
| 332 | #[doc = "Byte 1 - Bits 23 - EFC"] | ||
| 333 | #[inline(always)] | ||
| 334 | pub fn efc(&self) -> EFC_R { | ||
| 335 | EFC_R::new(((self.bits[1] >> 23) & 0x01) != 0) | ||
| 336 | } | ||
| 337 | #[doc = "Byte 1 - Bits 24:31 - MM"] | ||
| 338 | #[inline(always)] | ||
| 339 | pub fn mm(&self) -> MM_R { | ||
| 340 | MM_R::new(((self.bits[1] >> 24) & 0xFF) as u8) | ||
| 341 | } | ||
| 342 | pub fn to_data_length(&self) -> DataLength { | ||
| 343 | let dlc = self.dlc().bits(); | ||
| 344 | let ff = self.fdf().frame_format(); | ||
| 345 | let len = if ff == FrameFormat::Fdcan { | ||
| 346 | // See RM0433 Rev 7 Table 475. DLC coding | ||
| 347 | match dlc { | ||
| 348 | 0..=8 => dlc, | ||
| 349 | 9 => 12, | ||
| 350 | 10 => 16, | ||
| 351 | 11 => 20, | ||
| 352 | 12 => 24, | ||
| 353 | 13 => 32, | ||
| 354 | 14 => 48, | ||
| 355 | 15 => 64, | ||
| 356 | _ => panic!("DLC > 15"), | ||
| 357 | } | ||
| 358 | } else { | ||
| 359 | match dlc { | ||
| 360 | 0..=8 => dlc, | ||
| 361 | 9..=15 => 8, | ||
| 362 | _ => panic!("DLC > 15"), | ||
| 363 | } | ||
| 364 | }; | ||
| 365 | DataLength::new(len, ff) | ||
| 366 | } | ||
| 367 | pub fn to_event(&self) -> Event { | ||
| 368 | let mm = self.mm().bits(); | ||
| 369 | let efc = self.efc().to_event_control(); | ||
| 370 | match efc { | ||
| 371 | EventControl::DoNotStore => Event::NoEvent, | ||
| 372 | EventControl::Store => Event::Event(mm), | ||
| 373 | } | ||
| 374 | } | ||
| 375 | } | ||
| 376 | impl W { | ||
| 377 | #[doc = "Byte 0 - Bits 0:28 - ID"] | ||
| 378 | #[inline(always)] | ||
| 379 | pub fn id(&mut self) -> ID_W { | ||
| 380 | ID_W { w: self } | ||
| 381 | } | ||
| 382 | #[doc = "Byte 0 - Bit 29 - RTR"] | ||
| 383 | #[inline(always)] | ||
| 384 | pub fn rtr(&mut self) -> RTR_W { | ||
| 385 | RTR_W { w: self } | ||
| 386 | } | ||
| 387 | #[doc = "Byte 0 - Bit 30 - XTD"] | ||
| 388 | #[inline(always)] | ||
| 389 | pub fn xtd(&mut self) -> XTD_W { | ||
| 390 | XTD_W { w: self } | ||
| 391 | } | ||
| 392 | #[doc = "Byte 0 - Bit 31 - ESI"] | ||
| 393 | #[inline(always)] | ||
| 394 | pub fn esi(&mut self) -> ESI_W { | ||
| 395 | ESI_W { w: self } | ||
| 396 | } | ||
| 397 | #[doc = "Byte 1 - Bit 16:19 - DLC"] | ||
| 398 | #[inline(always)] | ||
| 399 | pub fn dlc(&mut self) -> DLC_W { | ||
| 400 | DLC_W { w: self } | ||
| 401 | } | ||
| 402 | #[doc = "Byte 1 - Bit 20 - BRS"] | ||
| 403 | #[inline(always)] | ||
| 404 | pub fn brs(&mut self) -> BRS_W { | ||
| 405 | BRS_W { w: self } | ||
| 406 | } | ||
| 407 | #[doc = "Byte 1 - Bit 21 - FDF"] | ||
| 408 | #[inline(always)] | ||
| 409 | pub fn fdf(&mut self) -> FDF_W { | ||
| 410 | FDF_W { w: self } | ||
| 411 | } | ||
| 412 | #[doc = "Byte 1 - Bit 23 - EFC"] | ||
| 413 | #[inline(always)] | ||
| 414 | pub fn efc(&mut self) -> EFC_W { | ||
| 415 | EFC_W { w: self } | ||
| 416 | } | ||
| 417 | #[doc = "Byte 1 - Bit 24:31 - MM"] | ||
| 418 | #[inline(always)] | ||
| 419 | pub fn mm(&mut self) -> MM_W { | ||
| 420 | MM_W { w: self } | ||
| 421 | } | ||
| 422 | #[doc = "Convenience function for setting the data length and frame format"] | ||
| 423 | #[inline(always)] | ||
| 424 | pub fn set_len(&mut self, dl: impl Into<DataLength>) -> &mut Self { | ||
| 425 | let dl: DataLength = dl.into(); | ||
| 426 | self.fdf().set_format(dl.into()); | ||
| 427 | unsafe { self.dlc().bits(dl.dlc()) } | ||
| 428 | } | ||
| 429 | pub fn set_event(&mut self, event: Event) -> &mut Self { | ||
| 430 | self.mm().set_message_marker(event.into()); | ||
| 431 | self.efc().set_event_control(event.into()) | ||
| 432 | } | ||
| 433 | } | ||
