canTiva.h 3.38 KB
Newer Older
Matthias Wenzl's avatar
Matthias Wenzl committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*!
 *
 * Hardware module specific CAN driver implementation for the TM4C1294NCPDT MCU
 *
 * canTiva.h
 *
 *  Created on: Aug 14, 2017
 *      Author: wenzl
 */

#ifndef CANTIVA_H_
#define CANTIVA_H_

#include "EK_TM4C1294XL.h"


#include <stdbool.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include <ti/sysbios/knl/Swi.h>
Matthias Wenzl's avatar
Matthias Wenzl committed
20
21
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Mailbox.h>
Matthias Wenzl's avatar
Matthias Wenzl committed
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
#include <xdc/cfg/global.h>
#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
#include <string.h>

#include <driverlib/can.h>
#include "can_driver.h"

/*originally defined in inc/tm4c1294ncpdt.h*/
#define CAN_INT_INTID_STATUS    0x00008000  // Status Interrupt

extern const CAN_FxnTable CANTiva_FxnTable;

/*! \brief Hardware specific CAN attributes block
 */
typedef struct CANTiva_HWAttrs{
    uint32_t base_addr;//!< Base address of device
    uint32_t clock;//!< System clock rate
    uint32_t irq;//!< IRQ number
    uint32_t brp;
    uint8_t prop;
    uint8_t ph1;
    uint8_t ph2;
    uint8_t sjw;
}CANTiva_HWAttrs;


/*! \brief Administrative CAN object
 *
 */
typedef struct CANTiva_Object{
    bool isOpen;//!< Check if device has been opened
    CAN_Stats stats;//!< Statistics block of this device
56
    Mailbox_Handle canMb;//!< Mailbox Handle
Matthias Wenzl's avatar
Matthias Wenzl committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
}CANTiva_Object;



/*! \brief Initialize, but do not start, or enable the interrupts of all available CAN devices (register isr, set bitrate,..)
 *
 * \param handle Pointer to CAN_Config structure
 * \return CAN_SUCCESS on success, negative value otherwise
 *
 */
int canTivaInit(CAN_Handle handle);

/*! \brief Enable interrupts and start transmission and reception of frames
 *
 * \param handle Pointer to CAN_Config structure
 * \return CAN_SUCCESS on success, negative value otherwise
 *
 */
int canTivaOpen(CAN_Handle handle);


/*! \brief Stop CAN interrupts and cease transmission and reception of frames
 *
 * \param handle Pointer to CAN_Config structure
 * \return CAN_SUCCESS on success, negative value otherwise
 *
 */
int canTivaClose(CAN_Handle handle);



/*! \brief Initialize, but do not start all available CAN devices
 *
 * \param handle Pointer to CAN_Config structure
 * \param objId Index of transfer block in CAN module memory
 * \param *msg Pointer to CAN message block
 * \param msgType Be it a transfer, receive, or remote message block
 * \return CAN_SUCCESS on success, negative value otherwise
 *
 */
int canTivaRegisterMsgObject(CAN_Handle handle,uint32_t objId, CAN_Msg *msg, uint32_t msgType);

99
100

/*! \brief Retreive MailBox handle set up during CAN device initialization
Matthias Wenzl's avatar
Matthias Wenzl committed
101
102
 *
 * \param handle Pointer to CAN_Config structure
103
 * \param Address of pointer to MailBox
Matthias Wenzl's avatar
Matthias Wenzl committed
104
105
106
 * \return CAN_SUCCESS on success, negative value otherwise
 *
 */
107
108
int canTivaGetMbHandle (CAN_Handle handle, void **mb);

Matthias Wenzl's avatar
Matthias Wenzl committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

/*! \brief Get pointer to statistics block
 *
 * \param handle Pointer to CAN_Config structure
 * \param *stats Pointer to statistics block
 * \return CAN_SUCCESS on success, negative value otherwise
 *
 */
int canTivaGetStats(CAN_Handle handle, CAN_Stats *stats);

/*! \brief CAN module interrupt handler
 *
 * \param uarg pointer to entry of CAN_Config structure
 *
 */
void CANIntHandler(UArg uarg);

/*! \brief Software interrupt called upon interrupt detect as bus off condition
 *
 * \param arg0 Pointer to correct entry in the CAN_config structure
 * \param arg1 unused
 *
 */
void CANBusOffSwiHandler(UArg arg0, UArg arg1);

134
#endif /*CANTIVA_H_*/
Matthias Wenzl's avatar
Matthias Wenzl committed
135