1 |
580 |
jeremybenn |
/* ----------------------------------------------------------------------------
|
2 |
|
|
* ATMEL Microcontroller Software Support
|
3 |
|
|
* ----------------------------------------------------------------------------
|
4 |
|
|
* Copyright (c) 2008, Atmel Corporation
|
5 |
|
|
*
|
6 |
|
|
* All rights reserved.
|
7 |
|
|
*
|
8 |
|
|
* Redistribution and use in source and binary forms, with or without
|
9 |
|
|
* modification, are permitted provided that the following conditions are met:
|
10 |
|
|
*
|
11 |
|
|
* - Redistributions of source code must retain the above copyright notice,
|
12 |
|
|
* this list of conditions and the disclaimer below.
|
13 |
|
|
*
|
14 |
|
|
* Atmel's name may not be used to endorse or promote products derived from
|
15 |
|
|
* this software without specific prior written permission.
|
16 |
|
|
*
|
17 |
|
|
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
18 |
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
19 |
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
20 |
|
|
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
23 |
|
|
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24 |
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25 |
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
26 |
|
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
|
|
* ----------------------------------------------------------------------------
|
28 |
|
|
*/
|
29 |
|
|
|
30 |
|
|
#ifndef _CAN_H
|
31 |
|
|
#define _CAN_H
|
32 |
|
|
|
33 |
|
|
//------------------------------------------------------------------------------
|
34 |
|
|
// Definitions
|
35 |
|
|
//------------------------------------------------------------------------------
|
36 |
|
|
#define AT91C_CAN_TIMEOUT 100000
|
37 |
|
|
|
38 |
|
|
#define AT91C_TEST_NOK 0
|
39 |
|
|
#define AT91C_TEST_OK 1
|
40 |
|
|
|
41 |
|
|
#define CAN_STATUS_SUCCESS 0
|
42 |
|
|
#define CAN_STATUS_LOCKED 1
|
43 |
|
|
#define CAN_STATUS_ABORTED 2
|
44 |
|
|
#define CAN_STATUS_RESET 3
|
45 |
|
|
|
46 |
|
|
#if defined (AT91C_BASE_CAN)
|
47 |
|
|
#define AT91C_BASE_CAN0 AT91C_BASE_CAN
|
48 |
|
|
#endif
|
49 |
|
|
#if defined (AT91C_ID_CAN)
|
50 |
|
|
#define AT91C_ID_CAN0 AT91C_ID_CAN
|
51 |
|
|
#endif
|
52 |
|
|
#if defined (AT91C_BASE_CAN_MB0)
|
53 |
|
|
#define AT91C_BASE_CAN0_MB0 AT91C_BASE_CAN_MB0
|
54 |
|
|
#define AT91C_BASE_CAN0_MB1 AT91C_BASE_CAN_MB1
|
55 |
|
|
#define AT91C_BASE_CAN0_MB2 AT91C_BASE_CAN_MB2
|
56 |
|
|
#define AT91C_BASE_CAN0_MB3 AT91C_BASE_CAN_MB3
|
57 |
|
|
#define AT91C_BASE_CAN0_MB4 AT91C_BASE_CAN_MB4
|
58 |
|
|
#define AT91C_BASE_CAN0_MB5 AT91C_BASE_CAN_MB5
|
59 |
|
|
#define AT91C_BASE_CAN0_MB6 AT91C_BASE_CAN_MB6
|
60 |
|
|
#define AT91C_BASE_CAN0_MB7 AT91C_BASE_CAN_MB7
|
61 |
|
|
#endif
|
62 |
|
|
#if defined (AT91C_BASE_CAN_MB8)
|
63 |
|
|
#define AT91C_BASE_CAN0_MB8 AT91C_BASE_CAN_MB8
|
64 |
|
|
#define AT91C_BASE_CAN0_MB9 AT91C_BASE_CAN_MB9
|
65 |
|
|
#define AT91C_BASE_CAN0_MB10 AT91C_BASE_CAN_MB10
|
66 |
|
|
#define AT91C_BASE_CAN0_MB11 AT91C_BASE_CAN_MB11
|
67 |
|
|
#define AT91C_BASE_CAN0_MB12 AT91C_BASE_CAN_MB12
|
68 |
|
|
#define AT91C_BASE_CAN0_MB13 AT91C_BASE_CAN_MB13
|
69 |
|
|
#define AT91C_BASE_CAN0_MB14 AT91C_BASE_CAN_MB14
|
70 |
|
|
#define AT91C_BASE_CAN0_MB15 AT91C_BASE_CAN_MB15
|
71 |
|
|
#endif
|
72 |
|
|
|
73 |
|
|
#define NUM_MAILBOX_MAX 16
|
74 |
|
|
|
75 |
|
|
//------------------------------------------------------------------------------
|
76 |
|
|
// Types
|
77 |
|
|
//------------------------------------------------------------------------------
|
78 |
|
|
typedef struct
|
79 |
|
|
{
|
80 |
|
|
volatile unsigned char state;
|
81 |
|
|
volatile unsigned char can_number;
|
82 |
|
|
volatile unsigned char mailbox_number;
|
83 |
|
|
volatile unsigned char test_can;
|
84 |
|
|
volatile unsigned int mode_reg;
|
85 |
|
|
volatile unsigned int acceptance_mask_reg;
|
86 |
|
|
volatile unsigned int identifier;
|
87 |
|
|
volatile unsigned int data_low_reg;
|
88 |
|
|
volatile unsigned int data_high_reg;
|
89 |
|
|
volatile unsigned int control_reg;
|
90 |
|
|
volatile unsigned int mailbox_in_use;
|
91 |
|
|
volatile int size;
|
92 |
|
|
} CanTransfer;
|
93 |
|
|
|
94 |
|
|
//------------------------------------------------------------------------------
|
95 |
|
|
// Exported functions
|
96 |
|
|
//------------------------------------------------------------------------------
|
97 |
|
|
extern unsigned char CAN_Init( unsigned int baudrate,
|
98 |
|
|
CanTransfer *canTransferRead,
|
99 |
|
|
CanTransfer *canTransferWrite );
|
100 |
|
|
extern void CAN_BasicTestSuite(void);
|
101 |
|
|
extern void CAN_disable( void );
|
102 |
|
|
extern void CAN_ResetAllMailbox( void );
|
103 |
|
|
extern void CAN_ResetTransfer( CanTransfer *pTransfer );
|
104 |
|
|
extern void CAN_InitMailboxRegisters( CanTransfer *pTransfer );
|
105 |
|
|
extern unsigned char CAN_IsInIdle( CanTransfer *pTransfer );
|
106 |
|
|
|
107 |
|
|
extern unsigned char CAN_Write( CanTransfer *pTransfer );
|
108 |
|
|
extern unsigned char CAN_Read( CanTransfer *pTransfer );
|
109 |
|
|
|
110 |
|
|
extern void CAN_BasicTestSuiteWithoutInterrupt( void );
|
111 |
|
|
extern unsigned char CAN_IsInIdle( CanTransfer *pTransfer );
|
112 |
|
|
#endif // _CAN_H
|
113 |
|
|
|