Mbed OS Reference
Loading...
Searching...
No Matches
can_api.h
1
2/** \addtogroup hal */
3/** @{*/
4/* mbed Microcontroller Library
5 * Copyright (c) 2006-2016 ARM Limited
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20#ifndef MBED_CAN_API_H
21#define MBED_CAN_API_H
22
23#include "device.h"
24#include "pinmap.h"
25
26#if DEVICE_CAN
27
28#include "PinNames.h"
29#include "PeripheralNames.h"
30#include "hal/can_helper.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36typedef enum {
37 IRQ_RX,
38 IRQ_TX,
39 IRQ_ERROR,
40 IRQ_OVERRUN,
41 IRQ_WAKEUP,
42 IRQ_PASSIVE,
43 IRQ_ARB,
44 IRQ_BUS,
45 IRQ_READY
46} CanIrqType;
47
48
49typedef enum {
50 MODE_RESET,
51 MODE_NORMAL,
52 MODE_SILENT,
53 MODE_TEST_LOCAL,
54 MODE_TEST_GLOBAL,
55 MODE_TEST_SILENT
56} CanMode;
57
58typedef struct {
59 int peripheral;
60 PinName rd_pin;
61 int rd_function;
62 PinName td_pin;
63 int td_function;
65
66typedef void (*can_irq_handler)(uintptr_t context, CanIrqType type);
67
68typedef struct can_s can_t;
69
70void can_init(can_t *obj, PinName rd, PinName td);
71void can_init_direct(can_t *obj, const can_pinmap_t *pinmap);
72void can_init_freq(can_t *obj, PinName rd, PinName td, int hz);
73void can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz);
74void can_free(can_t *obj);
75int can_frequency(can_t *obj, int hz);
76
77void can_irq_init(can_t *obj, can_irq_handler handler, uintptr_t context);
78void can_irq_free(can_t *obj);
79void can_irq_set(can_t *obj, CanIrqType irq, uint32_t enable);
80
81int can_write(can_t *obj, CAN_Message, int cc);
82int can_read(can_t *obj, CAN_Message *msg, int handle);
83int can_mode(can_t *obj, CanMode mode);
84int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle);
85void can_reset(can_t *obj);
86unsigned char can_rderror(can_t *obj);
87unsigned char can_tderror(can_t *obj);
88void can_monitor(can_t *obj, int silent);
89
90/** Get the pins that support CAN RD
91 *
92 * Return a PinMap array of pins that support CAN RD. The
93 * array is terminated with {NC, NC, 0}.
94 *
95 * @return PinMap array
96 */
97const PinMap *can_rd_pinmap(void);
98
99/** Get the pins that support CAN TD
100 *
101 * Return a PinMap array of pins that support CAN TD. The
102 * array is terminated with {NC, NC, 0}.
103 *
104 * @return PinMap array
105 */
107
108#ifdef __cplusplus
109}
110#endif
111
112#endif // MBED_CAN_API_H
113
114#endif
115
116/** @}*/
CANFormat
Values that represent CAN Format.
Definition: can_helper.h:35
const PinMap * can_rd_pinmap(void)
Get the pins that support CAN RD.
const PinMap * can_td_pinmap(void)
Get the pins that support CAN TD.
Holder for single CAN message.
Definition: can_helper.h:61
Definition: pinmap.h:31