mbed library sources, include can_api for nucleo-f091rc

Dependents:   CanNucleoF0_example

Fork of mbed-src by mbed official

Committer:
ptpaterson
Date:
Thu Jan 07 05:49:05 2016 +0000
Revision:
645:13c87cbecd54
Parent:
644:612d6aa9e717
corrected freeze on CAN_RECEIVE_IT

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
ptpaterson 637:909ea77f86f8 24 CAN::CAN(PinName rd, PinName td) : _can(), _irq() {
bogdanm 13:0645d8841f51 25 can_init(&_can, rd, td);
ptpaterson 637:909ea77f86f8 26 can_irq_init(&_can, (&CAN::_irq_handler), (uint32_t)this);
ptpaterson 644:612d6aa9e717 27
ptpaterson 644:612d6aa9e717 28 printf("CAN::CAN\r\n");
bogdanm 13:0645d8841f51 29 }
bogdanm 13:0645d8841f51 30
ptpaterson 637:909ea77f86f8 31 CAN::~CAN() {
mbed_official 49:a1af374b4197 32 can_irq_free(&_can);
bogdanm 13:0645d8841f51 33 can_free(&_can);
bogdanm 13:0645d8841f51 34 }
bogdanm 13:0645d8841f51 35
ptpaterson 637:909ea77f86f8 36 int CAN::frequency(int f) {
bogdanm 13:0645d8841f51 37 return can_frequency(&_can, f);
bogdanm 13:0645d8841f51 38 }
bogdanm 13:0645d8841f51 39
ptpaterson 637:909ea77f86f8 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 637:909ea77f86f8 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 637:909ea77f86f8 48 void CAN::reset() {
bogdanm 13:0645d8841f51 49 can_reset(&_can);
bogdanm 13:0645d8841f51 50 }
bogdanm 13:0645d8841f51 51
ptpaterson 637:909ea77f86f8 52 unsigned char CAN::rderror() {
bogdanm 13:0645d8841f51 53 return can_rderror(&_can);
bogdanm 13:0645d8841f51 54 }
bogdanm 13:0645d8841f51 55
ptpaterson 637:909ea77f86f8 56 unsigned char CAN::tderror() {
bogdanm 13:0645d8841f51 57 return can_tderror(&_can);
bogdanm 13:0645d8841f51 58 }
bogdanm 13:0645d8841f51 59
ptpaterson 637:909ea77f86f8 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 637:909ea77f86f8 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 637:909ea77f86f8 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 637:909ea77f86f8 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 637:909ea77f86f8 81 void CAN::_irq_handler(uint32_t id, CanIrqType type) {
ptpaterson 637:909ea77f86f8 82 CAN *handler = (CAN*)id;
ptpaterson 637:909ea77f86f8 83 handler->_irq[type].call();
mbed_official 41:e8b66477f5bf 84 }
bogdanm 13:0645d8841f51 85
bogdanm 13:0645d8841f51 86 } // namespace mbed
bogdanm 13:0645d8841f51 87
bogdanm 13:0645d8841f51 88 #endif