]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/common/CAN.cpp
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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);
34 int CAN::frequency(int f
) {
35 return can_frequency(&_can
, f
);
38 int CAN::write(CANMessage msg
) {
39 return can_write(&_can
, msg
, 0);
42 int CAN::read(CANMessage
&msg
, int handle
) {
43 return can_read(&_can
, &msg
, handle
);
50 unsigned char CAN::rderror() {
51 return can_rderror(&_can
);
54 unsigned char CAN::tderror() {
55 return can_tderror(&_can
);
58 void CAN::monitor(bool silent
) {
59 can_monitor(&_can
, (silent
) ? 1 : 0);
62 int CAN::mode(Mode mode
) {
63 return can_mode(&_can
, (CanMode
)mode
);
66 int CAN::filter(unsigned int id
, unsigned int mask
, CANFormat format
, int handle
) {
67 return can_filter(&_can
, id
, mask
, format
, handle
);
70 void CAN::attach(void (*fptr
)(void), IrqType type
) {
72 _irq
[(CanIrqType
)type
].attach(fptr
);
73 can_irq_set(&_can
, (CanIrqType
)type
, 1);
75 can_irq_set(&_can
, (CanIrqType
)type
, 0);
79 void CAN::_irq_handler(uint32_t id
, CanIrqType type
) {
80 CAN
*handler
= (CAN
*)id
;
81 handler
->_irq
[type
].call();