mbed library sources, include can_api for nucleo-f091rc
Dependents: CanNucleoF0_example
Fork of mbed-src by
common/CAN.cpp@636:03b10be137bf, 2015-12-14 (annotated)
- Committer:
- ptpaterson
- Date:
- Mon Dec 14 06:28:46 2015 +0000
- Revision:
- 636:03b10be137bf
- Parent:
- 212:34d62c0b2af6
- Child:
- 637:909ea77f86f8
implement nucleo-f091rc can_api
Who changed what in which revision?
User | Revision | Line number | New 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 | |
ptpaterson | 636:03b10be137bf | 24 | Can::Can(PinName rd, PinName td) : _can(), _irq() { |
bogdanm | 13:0645d8841f51 | 25 | can_init(&_can, rd, td); |
ptpaterson | 636:03b10be137bf | 26 | can_irq_init(&_can, (&Can::_irq_handler), (uint32_t)this); |
bogdanm | 13:0645d8841f51 | 27 | } |
bogdanm | 13:0645d8841f51 | 28 | |
ptpaterson | 636:03b10be137bf | 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 | |
ptpaterson | 636:03b10be137bf | 34 | void Can::dummy(void){} |
ptpaterson | 636:03b10be137bf | 35 | |
ptpaterson | 636:03b10be137bf | 36 | int Can::frequency(int f) { |
bogdanm | 13:0645d8841f51 | 37 | return can_frequency(&_can, f); |
bogdanm | 13:0645d8841f51 | 38 | } |
bogdanm | 13:0645d8841f51 | 39 | |
ptpaterson | 636:03b10be137bf | 40 | int Can::write(CANMessage msg) { |
bogdanm | 13:0645d8841f51 | 41 | return can_write(&_can, msg, 0); |
bogdanm | 13:0645d8841f51 | 42 | } |
bogdanm | 13:0645d8841f51 | 43 | |
ptpaterson | 636:03b10be137bf | 44 | int Can::read(CANMessage &msg, int handle) { |
mbed_official | 41:e8b66477f5bf | 45 | return can_read(&_can, &msg, handle); |
bogdanm | 13:0645d8841f51 | 46 | } |
bogdanm | 13:0645d8841f51 | 47 | |
ptpaterson | 636:03b10be137bf | 48 | void Can::reset() { |
bogdanm | 13:0645d8841f51 | 49 | can_reset(&_can); |
bogdanm | 13:0645d8841f51 | 50 | } |
bogdanm | 13:0645d8841f51 | 51 | |
ptpaterson | 636:03b10be137bf | 52 | unsigned char Can::rderror() { |
bogdanm | 13:0645d8841f51 | 53 | return can_rderror(&_can); |
bogdanm | 13:0645d8841f51 | 54 | } |
bogdanm | 13:0645d8841f51 | 55 | |
ptpaterson | 636:03b10be137bf | 56 | unsigned char Can::tderror() { |
bogdanm | 13:0645d8841f51 | 57 | return can_tderror(&_can); |
bogdanm | 13:0645d8841f51 | 58 | } |
bogdanm | 13:0645d8841f51 | 59 | |
ptpaterson | 636:03b10be137bf | 60 | void Can::monitor(bool silent) { |
bogdanm | 13:0645d8841f51 | 61 | can_monitor(&_can, (silent) ? 1 : 0); |
bogdanm | 13:0645d8841f51 | 62 | } |
bogdanm | 13:0645d8841f51 | 63 | |
ptpaterson | 636:03b10be137bf | 64 | int Can::mode(Mode mode) { |
bogdanm | 15:4892fe388435 | 65 | return can_mode(&_can, (CanMode)mode); |
bogdanm | 15:4892fe388435 | 66 | } |
bogdanm | 13:0645d8841f51 | 67 | |
ptpaterson | 636:03b10be137bf | 68 | int Can::filter(unsigned int id, unsigned int mask, CANFormat format, int handle) { |
mbed_official | 41:e8b66477f5bf | 69 | return can_filter(&_can, id, mask, format, handle); |
mbed_official | 41:e8b66477f5bf | 70 | } |
mbed_official | 41:e8b66477f5bf | 71 | |
ptpaterson | 636:03b10be137bf | 72 | void Can::attach(void (*fptr)(void), IrqType type) { |
mbed_official | 41:e8b66477f5bf | 73 | if (fptr) { |
mbed_official | 41:e8b66477f5bf | 74 | _irq[(CanIrqType)type].attach(fptr); |
mbed_official | 41:e8b66477f5bf | 75 | can_irq_set(&_can, (CanIrqType)type, 1); |
mbed_official | 41:e8b66477f5bf | 76 | } else { |
mbed_official | 41:e8b66477f5bf | 77 | can_irq_set(&_can, (CanIrqType)type, 0); |
bogdanm | 13:0645d8841f51 | 78 | } |
mbed_official | 41:e8b66477f5bf | 79 | } |
bogdanm | 13:0645d8841f51 | 80 | |
ptpaterson | 636:03b10be137bf | 81 | void Can::_irq_handler(uint32_t id, CanIrqType type) { |
ptpaterson | 636:03b10be137bf | 82 | Can *handler = (Can*)id; |
ptpaterson | 636:03b10be137bf | 83 | if (handler->_irq[type] != NULL) |
ptpaterson | 636:03b10be137bf | 84 | { |
ptpaterson | 636:03b10be137bf | 85 | handler->_irq[type].call(); |
ptpaterson | 636:03b10be137bf | 86 | } |
mbed_official | 41:e8b66477f5bf | 87 | } |
bogdanm | 13:0645d8841f51 | 88 | |
bogdanm | 13:0645d8841f51 | 89 | } // namespace mbed |
bogdanm | 13:0645d8841f51 | 90 | |
bogdanm | 13:0645d8841f51 | 91 | #endif |