Mistake on this page?
Report an issue in GitHub or email us
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
33 extern "C" {
34 #endif
35 
36 typedef 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 
49 typedef 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 
58 typedef struct {
59  int peripheral;
60  PinName rd_pin;
61  int rd_function;
62  PinName td_pin;
63  int td_function;
64 } can_pinmap_t;
65 
66 typedef void (*can_irq_handler)(uint32_t id, CanIrqType type);
67 
68 typedef struct can_s can_t;
69 
70 void can_init(can_t *obj, PinName rd, PinName td);
71 void can_init_direct(can_t *obj, const can_pinmap_t *pinmap);
72 void can_init_freq(can_t *obj, PinName rd, PinName td, int hz);
73 void can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz);
74 void can_free(can_t *obj);
75 int can_frequency(can_t *obj, int hz);
76 
77 void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id);
78 void can_irq_free(can_t *obj);
79 void can_irq_set(can_t *obj, CanIrqType irq, uint32_t enable);
80 
81 int can_write(can_t *obj, CAN_Message, int cc);
82 int can_read(can_t *obj, CAN_Message *msg, int handle);
83 int can_mode(can_t *obj, CanMode mode);
84 int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle);
85 void can_reset(can_t *obj);
86 unsigned char can_rderror(can_t *obj);
87 unsigned char can_tderror(can_t *obj);
88 void 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  */
97 const 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  */
106 const PinMap *can_td_pinmap(void);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif // MBED_CAN_API_H
113 
114 #endif
115 
116 /** @}*/
const PinMap * can_rd_pinmap(void)
Get the pins that support CAN RD.
CANFormat
Values that represent CAN Format.
Definition: can_helper.h:35
const PinMap * can_td_pinmap(void)
Get the pins that support CAN TD.
Definition: pinmap.h:31
Holder for single CAN message.
Definition: can_helper.h:61
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.