mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu Nov 21 16:45:05 2013 +0000
Revision:
49:a1af374b4197
Parent:
41:e8b66477f5bf
Child:
212:34d62c0b2af6
Synchronized with git revision 64952d4f7eba2fb44b86ba5e727da2ef03d5710d

Full URL: https://github.com/mbedmicro/mbed/commit/64952d4f7eba2fb44b86ba5e727da2ef03d5710d/

Avoid hardfault when CAN object is destructed.

Who changed what in which revision?

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