Skip to content

Commit 1fe20b2

Browse files
committed
Add can_init_frequency for NXP platforms
1 parent a912d05 commit 1fe20b2

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

targets/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/can_api.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,26 +268,30 @@ int can_config_rxmsgobj(can_t *obj) {
268268
}
269269

270270

271-
void can_init(can_t *obj, PinName rd, PinName td) {
271+
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) {
272272
// Enable power and clock
273273
LPC_SYSCON->PRESETCTRL |= PRESETCTRL_CAN_RST_N;
274274
LPC_SYSCON->SYSAHBCLKCTRL |= SYSAHBCLKCTRL_CAN;
275-
275+
276276
// Enable Initialization mode
277277
if (!(LPC_CAN->CNTL & CANCNTL_INIT)) {
278278
LPC_CAN->CNTL |= CANCNTL_INIT;
279279
}
280-
281-
can_frequency(obj, 125000);
282-
280+
281+
can_frequency(obj, hz);
282+
283283
// Resume operation
284284
LPC_CAN->CNTL &= ~CANCNTL_INIT;
285285
while ( LPC_CAN->CNTL & CANCNTL_INIT );
286-
286+
287287
// Initialize RX message object
288288
can_config_rxmsgobj(obj);
289289
}
290290

291+
void can_init(can_t *obj, PinName rd, PinName td) {
292+
can_init_freq(obj, rd, td, 125000);
293+
}
294+
291295
void can_free(can_t *obj) {
292296
LPC_SYSCON->SYSAHBCLKCTRL &= ~(SYSAHBCLKCTRL_CAN);
293297
LPC_SYSCON->PRESETCTRL &= ~(PRESETCTRL_CAN_RST_N);

targets/TARGET_NXP/TARGET_LPC15XX/can_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,7 @@ int can_config_txmsgobj(can_t *obj) {
415415
return 1;
416416
}
417417

418-
419-
void can_init(can_t *obj, PinName rd, PinName td) {
418+
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) {
420419
// Enable power and clock
421420
LPC_SYSCON->SYSAHBCLKCTRL1 |= (1UL << 7);
422421
LPC_SYSCON->PRESETCTRL1 |= (1UL << 7);
@@ -430,7 +429,7 @@ void can_init(can_t *obj, PinName rd, PinName td) {
430429
LPC_SWM->PINASSIGN[6] &= ~(0x00FFFF00L);
431430
LPC_SWM->PINASSIGN[6] |= (rd << 16) | (td << 8);
432431

433-
can_frequency(obj, 100000);
432+
can_frequency(obj, hz);
434433

435434
// Resume operation
436435
LPC_C_CAN0->CANCNTL &= ~(1UL << 0);
@@ -442,6 +441,10 @@ void can_init(can_t *obj, PinName rd, PinName td) {
442441
can_config_txmsgobj(obj);
443442
}
444443

444+
void can_init(can_t *obj, PinName rd, PinName td) {
445+
can_init_freq(obj, rd, td, 100000);
446+
}
447+
445448
void can_free(can_t *obj) {
446449
LPC_SYSCON->SYSAHBCLKCTRL1 &= ~(1UL << 7);
447450
LPC_SYSCON->PRESETCTRL1 &= ~(1UL << 7);

targets/TARGET_NXP/TARGET_LPC176X/can_api.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static unsigned int can_speed(unsigned int sclk, unsigned int pclk, unsigned int
292292

293293
}
294294

295-
void can_init(can_t *obj, PinName rd, PinName td) {
295+
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) {
296296
CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
297297
CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
298298
obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td);
@@ -313,11 +313,15 @@ void can_init(can_t *obj, PinName rd, PinName td) {
313313

314314
can_reset(obj);
315315
obj->dev->IER = 0; // Disable Interrupts
316-
can_frequency(obj, 100000);
316+
can_frequency(obj, hz);
317317

318318
LPC_CANAF->AFMR = ACCF_BYPASS; // Bypass Filter
319319
}
320320

321+
void can_init(can_t *obj, PinName rd, PinName td) {
322+
can_init_freq(obj, rd, td, 100000);
323+
}
324+
321325
void can_free(can_t *obj) {
322326
switch ((int)obj->dev) {
323327
case CAN_1: LPC_SC->PCONP &= ~(1 << 13); break;

targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088/can_api.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static unsigned int can_speed(unsigned int pclk, unsigned int cclk, unsigned cha
239239

240240
}
241241

242-
void can_init(can_t *obj, PinName rd, PinName td) {
242+
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) {
243243
CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
244244
CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
245245
obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td);
@@ -252,19 +252,23 @@ void can_init(can_t *obj, PinName rd, PinName td) {
252252

253253
pinmap_pinout(rd, PinMap_CAN_RD);
254254
pinmap_pinout(td, PinMap_CAN_TD);
255-
255+
256256
switch ((int)obj->dev) {
257257
case CAN_1: obj->index = 0; break;
258258
case CAN_2: obj->index = 1; break;
259259
}
260-
260+
261261
can_reset(obj);
262262
obj->dev->IER = 0; // Disable Interrupts
263-
can_frequency(obj, 100000);
263+
can_frequency(obj, hz);
264264

265265
LPC_CANAF->AFMR = ACCF_BYPASS; // Bypass Filter
266266
}
267267

268+
void can_init(can_t *obj, PinName rd, PinName td) {
269+
can_init_freq(obj, rd, td, 100000);
270+
}
271+
268272
void can_free(can_t *obj) {
269273
switch ((int)obj->dev) {
270274
case CAN_1: LPC_SC->PCONP &= ~(1 << 13); break;

targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088_DM/can_api.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static unsigned int can_speed(unsigned int pclk, unsigned int cclk, unsigned cha
236236

237237
}
238238

239-
void can_init(can_t *obj, PinName rd, PinName td) {
239+
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) {
240240
CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
241241
CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
242242
obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td);
@@ -257,11 +257,15 @@ void can_init(can_t *obj, PinName rd, PinName td) {
257257

258258
can_reset(obj);
259259
obj->dev->IER = 0; // Disable Interrupts
260-
can_frequency(obj, 100000);
260+
can_frequency(obj, hz);
261261

262262
LPC_CANAF->AFMR = ACCF_BYPASS; // Bypass Filter
263263
}
264264

265+
void can_init(can_t *obj, PinName rd, PinName td) {
266+
can_init_freq(obj, rd, td, 100000);
267+
}
268+
265269
void can_free(can_t *obj) {
266270
switch ((int)obj->dev) {
267271
case CAN_1: LPC_SC->PCONP &= ~(1 << 13); break;

0 commit comments

Comments
 (0)