@@ -29,7 +29,8 @@ static CAN_HandleTypeDef CanHandle;
29
29
static uint32_t can_irq_ids [CAN_NUM ] = {0 };
30
30
static can_irq_handler irq_handler ;
31
31
32
- void can_init (can_t * obj , PinName rd , PinName td ) {
32
+ void can_init (can_t * obj , PinName rd , PinName td )
33
+ {
33
34
CANName can_rd = (CANName )pinmap_peripheral (rd , PinMap_CAN_RD );
34
35
CANName can_td = (CANName )pinmap_peripheral (td , PinMap_CAN_TD );
35
36
@@ -85,20 +86,23 @@ void can_init(can_t *obj, PinName rd, PinName td) {
85
86
can_filter (obj , 0 , 0 , CANStandard , filter_number );
86
87
}
87
88
88
- void can_irq_init (can_t * obj , can_irq_handler handler , uint32_t id ) {
89
+ void can_irq_init (can_t * obj , can_irq_handler handler , uint32_t id )
90
+ {
89
91
irq_handler = handler ;
90
92
can_irq_ids [obj -> index ] = id ;
91
93
}
92
94
93
- void can_irq_free (can_t * obj ) {
95
+ void can_irq_free (can_t * obj )
96
+ {
94
97
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
95
98
96
99
can -> IER &= ~(CAN_IT_FMP0 | CAN_IT_FMP1 | CAN_IT_TME | \
97
100
CAN_IT_ERR | CAN_IT_EPV | CAN_IT_BOF );
98
101
can_irq_ids [obj -> can ] = 0 ;
99
102
}
100
103
101
- void can_free (can_t * obj ) {
104
+ void can_free (can_t * obj )
105
+ {
102
106
// Reset CAN and disable clock
103
107
if (obj -> can == CAN_1 ) {
104
108
__HAL_RCC_CAN1_FORCE_RESET ();
@@ -144,7 +148,8 @@ static const int timing_pts[23][2] = {
144
148
{0xF , 0x7 }, // 24, 67%
145
149
};
146
150
147
- static unsigned int can_speed (unsigned int pclk , unsigned int cclk , unsigned char psjw ) {
151
+ static unsigned int can_speed (unsigned int pclk , unsigned int cclk , unsigned char psjw )
152
+ {
148
153
uint32_t btr ;
149
154
uint16_t brp = 0 ;
150
155
uint32_t calcbit ;
@@ -179,7 +184,8 @@ static unsigned int can_speed(unsigned int pclk, unsigned int cclk, unsigned cha
179
184
180
185
}
181
186
182
- int can_frequency (can_t * obj , int f ) {
187
+ int can_frequency (can_t * obj , int f )
188
+ {
183
189
int pclk = HAL_RCC_GetPCLK1Freq ();
184
190
int btr = can_speed (pclk , (unsigned int )f , 1 );
185
191
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
@@ -198,7 +204,8 @@ int can_frequency(can_t *obj, int f) {
198
204
}
199
205
}
200
206
201
- int can_write (can_t * obj , CAN_Message msg , int cc ) {
207
+ int can_write (can_t * obj , CAN_Message msg , int cc )
208
+ {
202
209
uint32_t transmitmailbox = 5 ;
203
210
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
204
211
@@ -241,7 +248,8 @@ int can_write(can_t *obj, CAN_Message msg, int cc) {
241
248
return 1 ;
242
249
}
243
250
244
- int can_read (can_t * obj , CAN_Message * msg , int handle ) {
251
+ int can_read (can_t * obj , CAN_Message * msg , int handle )
252
+ {
245
253
//handle is the FIFO number
246
254
247
255
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
@@ -287,23 +295,27 @@ int can_read(can_t *obj, CAN_Message *msg, int handle) {
287
295
return 1 ;
288
296
}
289
297
290
- void can_reset (can_t * obj ) {
298
+ void can_reset (can_t * obj )
299
+ {
291
300
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
292
301
can -> MCR |= CAN_MCR_RESET ;
293
302
can -> ESR = 0x0 ;
294
303
}
295
304
296
- unsigned char can_rderror (can_t * obj ) {
305
+ unsigned char can_rderror (can_t * obj )
306
+ {
297
307
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
298
308
return (can -> ESR >> 24 ) & 0xFF ;
299
309
}
300
310
301
- unsigned char can_tderror (can_t * obj ) {
311
+ unsigned char can_tderror (can_t * obj )
312
+ {
302
313
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
303
314
return (can -> ESR >> 16 ) & 0xFF ;
304
315
}
305
316
306
- void can_monitor (can_t * obj , int silent ) {
317
+ void can_monitor (can_t * obj , int silent )
318
+ {
307
319
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
308
320
309
321
can -> MCR |= CAN_MCR_INRQ ;
@@ -321,7 +333,8 @@ void can_monitor(can_t *obj, int silent) {
321
333
}
322
334
}
323
335
324
- int can_mode (can_t * obj , CanMode mode ) {
336
+ int can_mode (can_t * obj , CanMode mode )
337
+ {
325
338
int success = 0 ;
326
339
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
327
340
@@ -361,7 +374,8 @@ int can_mode(can_t *obj, CanMode mode) {
361
374
return success ;
362
375
}
363
376
364
- int can_filter (can_t * obj , uint32_t id , uint32_t mask , CANFormat format , int32_t handle ) {
377
+ int can_filter (can_t * obj , uint32_t id , uint32_t mask , CANFormat format , int32_t handle )
378
+ {
365
379
int retval = 0 ;
366
380
367
381
// filter for CANAny format cannot be configured for STM32
@@ -394,7 +408,8 @@ int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t
394
408
return retval ;
395
409
}
396
410
397
- static void can_irq (CANName name , int id ) {
411
+ static void can_irq (CANName name , int id )
412
+ {
398
413
uint32_t tmp1 = 0 , tmp2 = 0 , tmp3 = 0 ;
399
414
CanHandle .Instance = (CAN_TypeDef * )name ;
400
415
@@ -481,7 +496,8 @@ void CAN2_SCE_IRQHandler(void) {
481
496
#endif // defined(CAN2_BASE) && (CAN_NUM == 2)
482
497
#endif // else
483
498
484
- void can_irq_set (can_t * obj , CanIrqType type , uint32_t enable ) {
499
+ void can_irq_set (can_t * obj , CanIrqType type , uint32_t enable )
500
+ {
485
501
486
502
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
487
503
IRQn_Type irq_n = (IRQn_Type )0 ;
@@ -567,3 +583,4 @@ void can_irq_set(can_t *obj, CanIrqType type, uint32_t enable) {
567
583
}
568
584
569
585
#endif // DEVICE_CAN
586
+
0 commit comments