2016-10-04 20:02:44 +00:00
|
|
|
|
|
|
|
/** \addtogroup hal */
|
|
|
|
/** @{*/
|
2013-02-18 15:32:11 +00:00
|
|
|
/* mbed Microcontroller Library
|
2016-02-01 09:13:29 +00:00
|
|
|
* Copyright (c) 2006-2016 ARM Limited
|
2018-11-09 11:27:45 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2013-02-18 15:32:11 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#ifndef MBED_CAN_API_H
|
|
|
|
#define MBED_CAN_API_H
|
|
|
|
|
|
|
|
#include "device.h"
|
2019-01-24 03:53:06 +00:00
|
|
|
#include "pinmap.h"
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
#if DEVICE_CAN
|
|
|
|
|
|
|
|
#include "PinNames.h"
|
|
|
|
#include "PeripheralNames.h"
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "hal/can_helper.h"
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-07-31 14:23:21 +00:00
|
|
|
typedef enum {
|
|
|
|
IRQ_RX,
|
|
|
|
IRQ_TX,
|
|
|
|
IRQ_ERROR,
|
|
|
|
IRQ_OVERRUN,
|
|
|
|
IRQ_WAKEUP,
|
|
|
|
IRQ_PASSIVE,
|
|
|
|
IRQ_ARB,
|
|
|
|
IRQ_BUS,
|
2016-02-22 14:24:42 +00:00
|
|
|
IRQ_READY
|
2013-08-06 00:28:27 +00:00
|
|
|
} CanIrqType;
|
2013-07-31 14:23:21 +00:00
|
|
|
|
2013-08-06 00:28:27 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MODE_RESET,
|
|
|
|
MODE_NORMAL,
|
|
|
|
MODE_SILENT,
|
|
|
|
MODE_TEST_LOCAL,
|
2015-04-07 07:33:26 +00:00
|
|
|
MODE_TEST_GLOBAL,
|
2013-08-06 00:28:27 +00:00
|
|
|
MODE_TEST_SILENT
|
|
|
|
} CanMode;
|
|
|
|
|
2019-09-23 12:32:43 +00:00
|
|
|
typedef struct {
|
|
|
|
int peripheral;
|
|
|
|
PinName rd_pin;
|
|
|
|
int rd_function;
|
|
|
|
PinName td_pin;
|
|
|
|
int td_function;
|
|
|
|
} can_pinmap_t;
|
|
|
|
|
2013-08-06 00:28:27 +00:00
|
|
|
typedef void (*can_irq_handler)(uint32_t id, CanIrqType type);
|
2013-07-31 14:23:21 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
typedef struct can_s can_t;
|
|
|
|
|
2018-06-20 10:24:18 +00:00
|
|
|
void can_init(can_t *obj, PinName rd, PinName td);
|
2019-09-23 12:32:43 +00:00
|
|
|
void can_init_direct(can_t *obj, const can_pinmap_t *pinmap);
|
2018-06-20 10:24:18 +00:00
|
|
|
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz);
|
2019-09-23 12:32:43 +00:00
|
|
|
void can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz);
|
2018-06-20 10:24:18 +00:00
|
|
|
void can_free(can_t *obj);
|
|
|
|
int can_frequency(can_t *obj, int hz);
|
|
|
|
|
|
|
|
void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id);
|
|
|
|
void can_irq_free(can_t *obj);
|
|
|
|
void can_irq_set(can_t *obj, CanIrqType irq, uint32_t enable);
|
|
|
|
|
|
|
|
int can_write(can_t *obj, CAN_Message, int cc);
|
|
|
|
int can_read(can_t *obj, CAN_Message *msg, int handle);
|
|
|
|
int can_mode(can_t *obj, CanMode mode);
|
2013-10-26 15:02:29 +00:00
|
|
|
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle);
|
2018-06-20 10:24:18 +00:00
|
|
|
void can_reset(can_t *obj);
|
|
|
|
unsigned char can_rderror(can_t *obj);
|
|
|
|
unsigned char can_tderror(can_t *obj);
|
|
|
|
void can_monitor(can_t *obj, int silent);
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2019-01-24 03:53:06 +00:00
|
|
|
/** Get the pins that support CAN RD
|
|
|
|
*
|
|
|
|
* Return a PinMap array of pins that support CAN RD. The
|
|
|
|
* array is terminated with {NC, NC, 0}.
|
|
|
|
*
|
|
|
|
* @return PinMap array
|
|
|
|
*/
|
|
|
|
const PinMap *can_rd_pinmap(void);
|
|
|
|
|
|
|
|
/** Get the pins that support CAN TD
|
|
|
|
*
|
|
|
|
* Return a PinMap array of pins that support CAN TD. The
|
|
|
|
* array is terminated with {NC, NC, 0}.
|
|
|
|
*
|
|
|
|
* @return PinMap array
|
|
|
|
*/
|
|
|
|
const PinMap *can_td_pinmap(void);
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
#ifdef __cplusplus
|
2019-12-26 22:08:22 +00:00
|
|
|
}
|
2013-02-18 15:32:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // MBED_CAN_API_H
|
|
|
|
|
|
|
|
#endif
|
2016-10-04 20:02:44 +00:00
|
|
|
|
|
|
|
/** @}*/
|