summaryrefslogtreecommitdiff
path: root/bsp/n32/libraries/n32_drivers/drv_can.h
blob: 4f73e68cca048b83ab18ace3020c099fd82f9324 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-10-19     Nations      first version
 */

#ifndef __DRV_CAN_H__
#define __DRV_CAN_H__

#include <rtdevice.h>
#include <rtthread.h>
#include <board.h>

#ifdef __cplusplus
extern "C" {
#endif

struct n32_baud_rate_tab
{
    uint32_t baud_rate;
    uint16_t PRESCALE;
    uint8_t  RSJW;
    uint8_t  TBS1;
    uint8_t  TBS2;
    uint8_t  Reserved;
};

#define N32_CAN_BAUD_DEF(rate, rsjw, tbs1, tbs2, prescale) \
{                                                          \
    .baud_rate = rate,                                     \
    .RSJW = rsjw,                                          \
    .TBS1 = tbs1,                                          \
    .TBS2 = tbs2,                                          \
    .PRESCALE = prescale                                   \
}

/* n32 can device */
struct n32_can
{
    char *name;
    CAN_Module *CANx;
    CAN_InitType can_init;
    CAN_FilterInitType FilterConfig;
    struct rt_can_device device;     /* inherit from can device */
};

int rt_hw_can_init(void);

#ifdef __cplusplus
}
#endif

#endif /* __DRV_CAN_H__ */