Modified mbed library sources only for STM32F030K6, LQFP32 (0.8mm pitch) package, 32K Flash, 4K SRAM. Compiler target: Nucleo 32F030R8

Fork of mbed-src by mbed official

Committer:
bogdanm
Date:
Wed Aug 07 16:43:59 2013 +0300
Revision:
15:4892fe388435
Parent:
13:0645d8841f51
Child:
41:e8b66477f5bf
Added LPC4088 target and interrupt chaining code

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() {
bogdanm 13:0645d8841f51 30 can_free(&_can);
bogdanm 15:4892fe388435 31 can_irq_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
bogdanm 13:0645d8841f51 42 int CAN::read(CANMessage &msg) {
bogdanm 13:0645d8841f51 43 return can_read(&_can, &msg);
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
bogdanm 15:4892fe388435 66 void CAN::attach(void (*fptr)(void), IrqType type) {
bogdanm 15:4892fe388435 67 if (fptr) {
bogdanm 15:4892fe388435 68 _irq[(CanIrqType)type].attach(fptr);
bogdanm 15:4892fe388435 69 can_irq_set(&_can, (CanIrqType)type, 1);
bogdanm 15:4892fe388435 70 } else {
bogdanm 15:4892fe388435 71 can_irq_set(&_can, (CanIrqType)type, 0);
bogdanm 13:0645d8841f51 72 }
bogdanm 13:0645d8841f51 73 }
bogdanm 13:0645d8841f51 74
bogdanm 15:4892fe388435 75 void CAN::_irq_handler(uint32_t id, CanIrqType type) {
bogdanm 15:4892fe388435 76 CAN *handler = (CAN*)id;
bogdanm 15:4892fe388435 77 handler->_irq[type].call();
bogdanm 13:0645d8841f51 78 }
bogdanm 13:0645d8841f51 79
bogdanm 13:0645d8841f51 80 } // namespace mbed
bogdanm 13:0645d8841f51 81
bogdanm 13:0645d8841f51 82 #endif