Skip to content

Commit f29dffa

Browse files
author
petroborys
committed
Add can_api.c for efm32: wrap in presence of the base peripheral
1 parent 0a82591 commit f29dffa

File tree

3 files changed

+30
-37
lines changed

3 files changed

+30
-37
lines changed

targets/TARGET_Silicon_Labs/TARGET_EFM32/PeripheralNames.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,12 @@ typedef enum {
138138

139139
#if DEVICE_CAN
140140
typedef enum {
141+
#ifdef CAN0_BASE
141142
CAN_0 = (int)CAN0_BASE,
142-
CAN_1 = (int)CAN1_BASE
143+
#endif
144+
#ifdef CAN1_BASE
145+
CAN_1 = (int)CAN1_BASE,
146+
#endif
143147
} CANName;
144148
#endif
145149

targets/TARGET_Silicon_Labs/TARGET_EFM32/TARGET_EFM32GG11/can_device.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

targets/TARGET_Silicon_Labs/TARGET_EFM32/can_api.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2006-2017 ARM Limited
2+
* Copyright (c) 2019 ToolSense
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
2424
#include "pinmap_function.h"
2525
#include "PeripheralPins.h"
2626
#include "mbed_assert.h"
27-
#include "can_device.h"
2827
#include "em_cmu.h"
2928
#include "em_can.h"
3029

@@ -48,12 +47,16 @@ void can_init_freq(can_t *obj, PinName rd, PinName td, int hz)
4847

4948
CMU_Clock_TypeDef cmuClock_number;
5049
switch ((CANName)obj->instance) {
50+
#ifdef CAN0
5151
case CAN_0:
5252
cmuClock_number = cmuClock_CAN0;
5353
break;
54+
#endif
55+
#ifdef CAN1
5456
case CAN_1:
5557
cmuClock_number = cmuClock_CAN1;
5658
break;
59+
#endif
5760
}
5861

5962
MBED_ASSERT((unsigned int)rd != NC);
@@ -106,12 +109,16 @@ void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id)
106109
int index = 0;
107110

108111
switch ((CANName)obj->instance) {
112+
#ifdef CAN0
109113
case CAN_0:
110114
index = 0;
111115
break;
116+
#endif
117+
#ifdef CAN1
112118
case CAN_1:
113119
index = 1;
114120
break;
121+
#endif
115122
}
116123

117124
irq_handler = handler;
@@ -124,12 +131,16 @@ void can_irq_free(can_t *obj)
124131
CAN_MessageIntClear(obj->instance, 0xFFFFFFFF);
125132

126133
switch ((CANName)obj->instance) {
134+
#ifdef CAN0
127135
case CAN_0:
128136
NVIC_DisableIRQ(CAN0_IRQn);
129137
break;
138+
#endif
139+
#ifdef CAN1
130140
case CAN_1:
131141
NVIC_DisableIRQ(CAN1_IRQn);
132142
break;
143+
#endif
133144
}
134145
}
135146

@@ -149,6 +160,7 @@ int can_frequency(can_t *obj, int f)
149160
CanInit.phaseBufferSegment1,
150161
CanInit.phaseBufferSegment2,
151162
CanInit.synchronisationJumpWidth);
163+
return 0;
152164
}
153165

154166
int can_write(can_t *obj, CAN_Message msg, int cc)
@@ -179,6 +191,8 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
179191
if (CAN_HasNewdata(obj->instance)) {
180192

181193
receiver.msgNum = 2;
194+
receiver.extended = false;
195+
receiver.extendedMask = false;
182196

183197
CAN_ReadMessage(obj->instance, CAN_RX_IF, &receiver);
184198

@@ -259,14 +273,18 @@ void can_irq_set(can_t *obj, CanIrqType type, uint32_t enable)
259273
}
260274

261275
switch ((CANName)obj->instance) {
276+
#ifdef CAN0
262277
case CAN_0:
263278
NVIC_SetVector(CAN0_IRQn, CAN0_IRQHandler);
264279
NVIC_EnableIRQ(CAN0_IRQn);
265280
break;
281+
#endif
282+
#ifdef CAN1
266283
case CAN_1:
267284
NVIC_SetVector(CAN1_IRQn, CAN1_IRQHandler);
268285
NVIC_EnableIRQ(CAN1_IRQn);
269286
break;
287+
#endif
270288
}
271289
}
272290

@@ -286,16 +304,19 @@ static void can_irq(CANName name, int id)
286304
}
287305
}
288306

307+
#ifdef CAN0
289308
void CAN0_IRQHandler(void)
290309
{
291310
can_irq(CAN_0, 0);
292311
}
312+
#endif
293313

314+
#ifdef CAN1
294315
void CAN1_IRQHandler(void)
295316
{
296317
can_irq(CAN_1, 1);
297318
}
298-
319+
#endif
299320

300321
const PinMap *can_rd_pinmap()
301322
{
@@ -307,4 +328,4 @@ const PinMap *can_td_pinmap()
307328
return PinMap_CAN_RX;
308329
}
309330

310-
#endif // DEVICE_CAN
331+
#endif //DEVICE_CAN

0 commit comments

Comments
 (0)