mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Fri Aug 19 15:46:42 2016 +1000
Revision:
17:639ed60ce759
Parent:
1:71204b8406f2
Added tag v1.1 for changeset 076cbe3e55be

Who changed what in which revision?

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