]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/common/CAN.cpp
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / common / CAN.cpp
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "CAN.h"
17
18 #if DEVICE_CAN
19
20 #include "cmsis.h"
21
22 namespace mbed {
23
24 CAN::CAN(PinName rd, PinName td) : _can(), _irq() {
25 can_init(&_can, rd, td);
26 can_irq_init(&_can, (&CAN::_irq_handler), (uint32_t)this);
27 }
28
29 CAN::~CAN() {
30 can_irq_free(&_can);
31 can_free(&_can);
32 }
33
34 int CAN::frequency(int f) {
35 return can_frequency(&_can, f);
36 }
37
38 int CAN::write(CANMessage msg) {
39 return can_write(&_can, msg, 0);
40 }
41
42 int CAN::read(CANMessage &msg, int handle) {
43 return can_read(&_can, &msg, handle);
44 }
45
46 void CAN::reset() {
47 can_reset(&_can);
48 }
49
50 unsigned char CAN::rderror() {
51 return can_rderror(&_can);
52 }
53
54 unsigned char CAN::tderror() {
55 return can_tderror(&_can);
56 }
57
58 void CAN::monitor(bool silent) {
59 can_monitor(&_can, (silent) ? 1 : 0);
60 }
61
62 int CAN::mode(Mode mode) {
63 return can_mode(&_can, (CanMode)mode);
64 }
65
66 int CAN::filter(unsigned int id, unsigned int mask, CANFormat format, int handle) {
67 return can_filter(&_can, id, mask, format, handle);
68 }
69
70 void CAN::attach(void (*fptr)(void), IrqType type) {
71 if (fptr) {
72 _irq[(CanIrqType)type].attach(fptr);
73 can_irq_set(&_can, (CanIrqType)type, 1);
74 } else {
75 can_irq_set(&_can, (CanIrqType)type, 0);
76 }
77 }
78
79 void CAN::_irq_handler(uint32_t id, CanIrqType type) {
80 CAN *handler = (CAN*)id;
81 handler->_irq[type].call();
82 }
83
84 } // namespace mbed
85
86 #endif
Imprint / Impressum