|
| 1 | +/* |
| 2 | + Copyright (c) 2013 Arduino. All right reserved. |
| 3 | +
|
| 4 | + This library is free software; you can redistribute it and/or |
| 5 | + modify it under the terms of the GNU Lesser General Public |
| 6 | + License as published by the Free Software Foundation; either |
| 7 | + version 2.1 of the License, or (at your option) any later version. |
| 8 | +
|
| 9 | + This library is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | + See the GNU Lesser General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU Lesser General Public |
| 15 | + License along with this library; if not, write to the Free Software |
| 16 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | +*/ |
| 18 | + |
| 19 | + |
| 20 | +#ifndef _CAN_LIBRARY_ |
| 21 | +#define _CAN_LIBRARY_ |
| 22 | + |
| 23 | +#include "sn65hvd234.h" |
| 24 | + |
| 25 | + |
| 26 | +/** Define the Mailbox mask for eight mailboxes. */ |
| 27 | +#define GLOBAL_MAILBOX_MASK 0x000000ff |
| 28 | + |
| 29 | +/** Disable all interrupt mask */ |
| 30 | +#define CAN_DISABLE_ALL_INTERRUPT_MASK 0xffffffff |
| 31 | + |
| 32 | +/** Define the typical baudrate for CAN communication in KHz. */ |
| 33 | +#define CAN_BPS_1000K 1000 |
| 34 | +#define CAN_BPS_800K 800 |
| 35 | +#define CAN_BPS_500K 500 |
| 36 | +#define CAN_BPS_250K 250 |
| 37 | +#define CAN_BPS_125K 125 |
| 38 | +#define CAN_BPS_50K 50 |
| 39 | +#define CAN_BPS_25K 25 |
| 40 | +#define CAN_BPS_10K 10 |
| 41 | +#define CAN_BPS_5K 5 |
| 42 | + |
| 43 | +/** Define the mailbox mode. */ |
| 44 | +#define CAN_MB_DISABLE_MODE 0 |
| 45 | +#define CAN_MB_RX_MODE 1 |
| 46 | +#define CAN_MB_RX_OVER_WR_MODE 2 |
| 47 | +#define CAN_MB_TX_MODE 3 |
| 48 | +#define CAN_MB_CONSUMER_MODE 4 |
| 49 | +#define CAN_MB_PRODUCER_MODE 5 |
| 50 | + |
| 51 | +/** Define CAN mailbox transfer status code. */ |
| 52 | +#define CAN_MAILBOX_TRANSFER_OK 0 //! Read from or write into mailbox successfully. |
| 53 | +#define CAN_MAILBOX_NOT_READY 0x01 //! Receiver is empty or transmitter is busy. |
| 54 | +#define CAN_MAILBOX_RX_OVER 0x02 //! Message overwriting happens or there're messages lost in different receive modes. |
| 55 | +#define CAN_MAILBOX_RX_NEED_RD_AGAIN 0x04 //! Application needs to re-read the data register in Receive with Overwrite mode. |
| 56 | + |
| 57 | +class CANRaw |
| 58 | +{ |
| 59 | + protected: |
| 60 | + /* CAN peripheral, set by constructor */ |
| 61 | + //Can* m_pCan ; |
| 62 | + |
| 63 | + /* CAN Transceiver */ |
| 64 | + SSN65HVD234_Data m_Transceiver ; |
| 65 | + |
| 66 | + /** CAN Transfer */ |
| 67 | + //can_mb_conf_t m_Mailbox; |
| 68 | + |
| 69 | + private: |
| 70 | + |
| 71 | + public: |
| 72 | + // Constructor |
| 73 | + //CANRawClass( Can* pCan ) ; |
| 74 | + |
| 75 | + /** |
| 76 | + * \defgroup sam_driver_can_group Controller Area Network (CAN) Driver |
| 77 | + * |
| 78 | + * See \ref sam_can_quickstart. |
| 79 | + * |
| 80 | + * \par Purpose |
| 81 | + * |
| 82 | + * The CAN controller provides all the features required to implement |
| 83 | + * the serial communication protocol CAN defined by Robert Bosch GmbH, |
| 84 | + * the CAN specification. This is a driver for configuration, enabling, |
| 85 | + * disabling and use of the CAN peripheral. |
| 86 | + * |
| 87 | + * @{ |
| 88 | + */ |
| 89 | + |
| 90 | +uint32_t set_baudrate(Can *p_can, uint32_t ul_mck, uint32_t ul_baudrate); |
| 91 | +uint32_t init(Can *p_can, uint32_t ul_mck, uint32_t ul_baudrate); |
| 92 | +void enable(Can *p_can); |
| 93 | +void disable(Can *p_can); |
| 94 | +void disable_low_power_mode(Can *p_can); |
| 95 | +void enable_low_power_mode(Can *p_can); |
| 96 | +void disable_autobaud_listen_mode(Can *p_can); |
| 97 | +void enable_autobaud_listen_mode(Can *p_can); |
| 98 | +void disable_overload_frame(Can *p_can); |
| 99 | +void enable_overload_frame(Can *p_can); |
| 100 | +void set_timestamp_capture_point(Can *p_can, uint32_t ul_flag); |
| 101 | +void disable_time_triggered_mode(Can *p_can); |
| 102 | +void enable_time_triggered_mode(Can *p_can); |
| 103 | +void disable_timer_freeze(Can *p_can); |
| 104 | +void enable_timer_freeze(Can *p_can); |
| 105 | +void disable_tx_repeat(Can *p_can); |
| 106 | +void enable_tx_repeat(Can *p_can); |
| 107 | +void set_rx_sync_stage(Can *p_can, uint32_t ul_stage); |
| 108 | +void enable_interrupt(Can *p_can, uint32_t dw_mask); |
| 109 | +void disable_interrupt(Can *p_can, uint32_t dw_mask); |
| 110 | +uint32_t get_interrupt_mask(Can *p_can); |
| 111 | +uint32_t get_status(Can *p_can); |
| 112 | +uint32_t get_internal_timer_value(Can *p_can); |
| 113 | +uint32_t get_timestamp_value(Can *p_can); |
| 114 | +uint8_t get_tx_error_cnt(Can *p_can); |
| 115 | +uint8_t get_rx_error_cnt(Can *p_can); |
| 116 | +void reset_internal_timer(Can *p_can); |
| 117 | +void global_send_transfer_cmd(Can *p_can, uint8_t uc_mask); |
| 118 | +void global_send_abort_cmd(Can *p_can, uint8_t uc_mask); |
| 119 | +void mailbox_set_timemark(Can *p_can, uint8_t uc_index, uint16_t us_cnt); |
| 120 | +uint32_t mailbox_get_status(Can *p_can, uint8_t uc_index); |
| 121 | +void mailbox_send_transfer_cmd(Can *p_can, uint8_t uc_index); |
| 122 | +void mailbox_send_abort_cmd(Can *p_can, uint8_t uc_index); |
| 123 | +void mailbox_init(Can *p_can, can_mb_conf_t *p_mailbox); |
| 124 | +uint32_t mailbox_read(Can *p_can, can_mb_conf_t *p_mailbox); |
| 125 | +uint32_t mailbox_write(Can *p_can, can_mb_conf_t *p_mailbox); |
| 126 | +uint32_t mailbox_tx_remote_frame(Can *p_can, can_mb_conf_t *p_mailbox); |
| 127 | +void reset_all_mailbox(Can *p_can); |
| 128 | +} ; |
| 129 | + |
| 130 | + |
| 131 | +#endif // _CAN_LIBRARY_ |
0 commit comments