initial

Dependencies:   mbed

Committer:
yihui
Date:
Mon Jan 11 02:32:24 2016 +0000
Revision:
0:638edba3adf6
initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:638edba3adf6 1 /* mbed Microcontroller Library
yihui 0:638edba3adf6 2 * Copyright (c) 2006-2013 ARM Limited
yihui 0:638edba3adf6 3 *
yihui 0:638edba3adf6 4 * Licensed under the Apache License, Version 2.0 (the "License");
yihui 0:638edba3adf6 5 * you may not use this file except in compliance with the License.
yihui 0:638edba3adf6 6 * You may obtain a copy of the License at
yihui 0:638edba3adf6 7 *
yihui 0:638edba3adf6 8 * http://www.apache.org/licenses/LICENSE-2.0
yihui 0:638edba3adf6 9 *
yihui 0:638edba3adf6 10 * Unless required by applicable law or agreed to in writing, software
yihui 0:638edba3adf6 11 * distributed under the License is distributed on an "AS IS" BASIS,
yihui 0:638edba3adf6 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
yihui 0:638edba3adf6 13 * See the License for the specific language governing permissions and
yihui 0:638edba3adf6 14 * limitations under the License.
yihui 0:638edba3adf6 15 */
yihui 0:638edba3adf6 16 #ifndef MBED_CAN_API_H
yihui 0:638edba3adf6 17 #define MBED_CAN_API_H
yihui 0:638edba3adf6 18
yihui 0:638edba3adf6 19 #include "device.h"
yihui 0:638edba3adf6 20
yihui 0:638edba3adf6 21 #if DEVICE_CAN
yihui 0:638edba3adf6 22
yihui 0:638edba3adf6 23 #include "PinNames.h"
yihui 0:638edba3adf6 24 #include "PeripheralNames.h"
yihui 0:638edba3adf6 25 #include "can_helper.h"
yihui 0:638edba3adf6 26
yihui 0:638edba3adf6 27 #ifdef __cplusplus
yihui 0:638edba3adf6 28 extern "C" {
yihui 0:638edba3adf6 29 #endif
yihui 0:638edba3adf6 30
yihui 0:638edba3adf6 31 typedef enum {
yihui 0:638edba3adf6 32 IRQ_RX,
yihui 0:638edba3adf6 33 IRQ_TX,
yihui 0:638edba3adf6 34 IRQ_ERROR,
yihui 0:638edba3adf6 35 IRQ_OVERRUN,
yihui 0:638edba3adf6 36 IRQ_WAKEUP,
yihui 0:638edba3adf6 37 IRQ_PASSIVE,
yihui 0:638edba3adf6 38 IRQ_ARB,
yihui 0:638edba3adf6 39 IRQ_BUS,
yihui 0:638edba3adf6 40 IRQ_READY
yihui 0:638edba3adf6 41 } CanIrqType;
yihui 0:638edba3adf6 42
yihui 0:638edba3adf6 43
yihui 0:638edba3adf6 44 typedef enum {
yihui 0:638edba3adf6 45 MODE_RESET,
yihui 0:638edba3adf6 46 MODE_NORMAL,
yihui 0:638edba3adf6 47 MODE_SILENT,
yihui 0:638edba3adf6 48 MODE_TEST_LOCAL,
yihui 0:638edba3adf6 49 MODE_TEST_GLOBAL,
yihui 0:638edba3adf6 50 MODE_TEST_SILENT
yihui 0:638edba3adf6 51 } CanMode;
yihui 0:638edba3adf6 52
yihui 0:638edba3adf6 53 typedef void (*can_irq_handler)(uint32_t id, CanIrqType type);
yihui 0:638edba3adf6 54
yihui 0:638edba3adf6 55 typedef struct can_s can_t;
yihui 0:638edba3adf6 56
yihui 0:638edba3adf6 57 void can_init (can_t *obj, PinName rd, PinName td);
yihui 0:638edba3adf6 58 void can_free (can_t *obj);
yihui 0:638edba3adf6 59 int can_frequency(can_t *obj, int hz);
yihui 0:638edba3adf6 60
yihui 0:638edba3adf6 61 void can_irq_init (can_t *obj, can_irq_handler handler, uint32_t id);
yihui 0:638edba3adf6 62 void can_irq_free (can_t *obj);
yihui 0:638edba3adf6 63 void can_irq_set (can_t *obj, CanIrqType irq, uint32_t enable);
yihui 0:638edba3adf6 64
yihui 0:638edba3adf6 65 int can_write (can_t *obj, CAN_Message, int cc);
yihui 0:638edba3adf6 66 int can_read (can_t *obj, CAN_Message *msg, int handle);
yihui 0:638edba3adf6 67 int can_mode (can_t *obj, CanMode mode);
yihui 0:638edba3adf6 68 int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle);
yihui 0:638edba3adf6 69 void can_reset (can_t *obj);
yihui 0:638edba3adf6 70 unsigned char can_rderror (can_t *obj);
yihui 0:638edba3adf6 71 unsigned char can_tderror (can_t *obj);
yihui 0:638edba3adf6 72 void can_monitor (can_t *obj, int silent);
yihui 0:638edba3adf6 73
yihui 0:638edba3adf6 74 #ifdef __cplusplus
yihui 0:638edba3adf6 75 };
yihui 0:638edba3adf6 76 #endif
yihui 0:638edba3adf6 77
yihui 0:638edba3adf6 78 #endif // MBED_CAN_API_H
yihui 0:638edba3adf6 79
yihui 0:638edba3adf6 80 #endif