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
) {
25 can_init(&_can
, rd
, td
);
32 int CAN::frequency(int f
) {
33 return can_frequency(&_can
, f
);
36 int CAN::write(CANMessage msg
) {
37 return can_write(&_can
, msg
, 0);
40 int CAN::read(CANMessage
&msg
) {
41 return can_read(&_can
, &msg
);
48 unsigned char CAN::rderror() {
49 return can_rderror(&_can
);
52 unsigned char CAN::tderror() {
53 return can_tderror(&_can
);
56 void CAN::monitor(bool silent
) {
57 can_monitor(&_can
, (silent
) ? 1 : 0);
60 static FunctionPointer
* can_obj
[2] = { NULL
};
62 // Have to check that the CAN block is active before reading the Interrupt
63 // Control Register, or the mbed hangs
67 if(LPC_SC
->PCONP
& (1 << 13)) {
70 if(icr
&& (can_obj
[0] != NULL
)) {
75 if(LPC_SC
->PCONP
& (1 << 14)) {
77 if(icr
&& (can_obj
[1] != NULL
)) {
84 void CAN::setup_interrupt(void) {
85 switch ((int)_can
.dev
) {
86 case CAN_1
: can_obj
[0] = &_rxirq
; break;
87 case CAN_2
: can_obj
[1] = &_rxirq
; break;
92 NVIC_SetVector(CAN_IRQn
, (uint32_t) &can_irq
);
93 NVIC_EnableIRQ(CAN_IRQn
);
96 void CAN::remove_interrupt(void) {
97 switch ((int)_can
.dev
) {
98 case CAN_1
: can_obj
[0] = NULL
; break;
99 case CAN_2
: can_obj
[1] = NULL
; break;
102 _can
.dev
->IER
&= ~(1);
103 if ((can_obj
[0] == NULL
) && (can_obj
[1] == NULL
)) {
104 NVIC_DisableIRQ(CAN_IRQn
);
108 void CAN::attach(void (*fptr
)(void)) {