Skip to content

Commit 2c10779

Browse files
committed
[sam] integrating Wilfredo CAN driver function and bringing sn65hvd234
driver into CAN library
1 parent fd16c12 commit 2c10779

File tree

4 files changed

+248
-0
lines changed

4 files changed

+248
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/* ----------------------------------------------------------------------------
2+
* ATMEL Microcontroller Software Support
3+
* ----------------------------------------------------------------------------
4+
* Copyright (c) 2010, 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+
* \file
31+
*
32+
* Implementation of the SN65HVD234 drivers.
33+
*
34+
*/
35+
36+
#include "board.h"
37+
38+
#include <string.h>
39+
40+
/**
41+
* \brief Initialize SN65HVD234 component data
42+
*
43+
* \param pComponent pointer on SSN65HVD234_Data
44+
*
45+
* \return 0 if OK
46+
*/
47+
extern uint32_t SN65HVD234_Init( SSN65HVD234_Data* pComponent )
48+
{
49+
pComponent->pPIO_Rs=NULL ;
50+
pComponent->dwPin_Rs=0u ;
51+
52+
pComponent->pPIO_EN=NULL ;
53+
pComponent->dwPin_EN=0u ;
54+
55+
return 0u ;
56+
}
57+
58+
/**
59+
* \brief Initialize Rs pin of transceiver
60+
*
61+
* \param pComponent pointer on SSN65HVD234_Data
62+
* \param pPIO_Rs pointer on PIOx base for transceiver Rs pin
63+
* \param dwPin_Rs PIO pin index for transceiver Rs pin
64+
*
65+
* \return 0 if OK
66+
*/
67+
extern uint32_t SN65HVD234_SetRs( SSN65HVD234_Data* pComponent, Pio* pPIO_Rs, uint32_t dwPin_Rs )
68+
{
69+
pComponent->pPIO_Rs=pPIO_Rs ;
70+
pComponent->dwPin_Rs=dwPin_Rs ;
71+
72+
PIO_SetOutput( pPIO_Rs, dwPin_Rs, PIO_PULLUP|PIO_OUTPUT_LOW ) ;
73+
74+
return 0u ;
75+
}
76+
77+
/**
78+
* \brief Initialize EN pin of transceiver
79+
*
80+
* \param pComponent pointer on SSN65HVD234_Data
81+
* \param pPIO_EN pointer on PIOx base for transceiver EN pin
82+
* \param dwPin_EN PIO pin index for transceiver EN pin
83+
*
84+
* \return 0 if OK
85+
*/
86+
extern uint32_t SN65HVD234_SetEN( SSN65HVD234_Data* pComponent, Pio* pPIO_EN, uint32_t dwPin_EN )
87+
{
88+
pComponent->pPIO_EN=pPIO_EN ;
89+
pComponent->dwPin_EN=dwPin_EN ;
90+
91+
PIO_SetOutput( pPIO_EN, dwPin_EN, PIO_PULLUP|PIO_OUTPUT_LOW ) ;
92+
93+
return 0u ;
94+
}
95+
96+
/**
97+
* \brief Enable transceiver
98+
*
99+
* \param pComponent pointer on SSN65HVD234_Data
100+
*
101+
* \return 0 if OK
102+
*/
103+
extern uint32_t SN65HVD234_Enable( SSN65HVD234_Data* pComponent )
104+
{
105+
// Raise EN of SN65HVD234 to High Level (Vcc)
106+
pComponent->pPIO_EN->PIO_SODR=pComponent->dwPin_EN ;
107+
108+
return 0u ;
109+
}
110+
111+
/**
112+
* \brief Disable transceiver
113+
*
114+
* \param pComponent pointer on SSN65HVD234_Data
115+
*
116+
* \return 0 if OK
117+
*/
118+
extern uint32_t SN65HVD234_Disable( SSN65HVD234_Data* pComponent )
119+
{
120+
// Lower EN of SN65HVD234 to Low Level (0.0v)
121+
pComponent->pPIO_EN->PIO_CODR=pComponent->dwPin_EN ;
122+
123+
return 0u ;
124+
}
125+
126+
/**
127+
* \brief Turn component into lowpower mode
128+
*
129+
* \param pComponent pointer on SSN65HVD234_Data
130+
*
131+
* \return 0 if OK
132+
*/
133+
extern uint32_t SN65HVD234_EnableLowPower( SSN65HVD234_Data* pComponent )
134+
{
135+
// Raise Rs of SN65HVD234 to more than 0.75v
136+
pComponent->pPIO_Rs->PIO_SODR=pComponent->dwPin_Rs ;
137+
138+
// Now, SN65HVD234 is only listening
139+
140+
return 0u ;
141+
}
142+
143+
/**
144+
* \brief Restore Normal mode by leaving lowpower mode
145+
*
146+
* \param pComponent pointer on SSN65HVD234_Data
147+
*
148+
* \return 0 if OK
149+
*/
150+
extern uint32_t SN65HVD234_DisableLowPower( SSN65HVD234_Data* pComponent )
151+
{
152+
// Lower Rs of SN65HVD234 to 0.0v < 0.33v
153+
pComponent->pPIO_Rs->PIO_CODR=pComponent->dwPin_Rs ;
154+
155+
return 0u ;
156+
}
157+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* ----------------------------------------------------------------------------
2+
* ATMEL Microcontroller Software Support
3+
* ----------------------------------------------------------------------------
4+
* Copyright (c) 2010, 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+
* \file
31+
*
32+
* Include Defines & macros for the SN65HVD234.
33+
*/
34+
35+
#ifndef _CAN_SN65HVD234_
36+
#define _CAN_SN65HVD234_
37+
38+
#include "board.h"
39+
40+
#ifdef __cplusplus
41+
extern "C" {
42+
#endif
43+
44+
45+
typedef struct _SSN65HVD234_Data
46+
{
47+
/** PIO dedicated to Rs pin */
48+
Pio* pPIO_Rs ;
49+
/** Rs Pin on PIO */
50+
uint32_t dwPin_Rs ;
51+
52+
/** PIO dedicated to EN pin */
53+
Pio* pPIO_EN ;
54+
/** EN Pin on PIO */
55+
uint32_t dwPin_EN ;
56+
} SSN65HVD234_Data ;
57+
58+
extern uint32_t SN65HVD234_Init( SSN65HVD234_Data* pComponent ) ;
59+
extern uint32_t SN65HVD234_SetRs( SSN65HVD234_Data* pComponent, Pio* pPIO_Rs, uint32_t dwPin_Rs ) ;
60+
extern uint32_t SN65HVD234_SetEN( SSN65HVD234_Data* pComponent, Pio* pPIO_EN, uint32_t dwPin_EN ) ;
61+
62+
extern uint32_t SN65HVD234_Enable( SSN65HVD234_Data* pComponent ) ;
63+
extern uint32_t SN65HVD234_Disable( SSN65HVD234_Data* pComponent ) ;
64+
65+
extern uint32_t SN65HVD234_EnableLowPower( SSN65HVD234_Data* pComponent ) ;
66+
extern uint32_t SN65HVD234_DisableLowPower( SSN65HVD234_Data* pComponent ) ;
67+
68+
#ifdef __cplusplus
69+
}
70+
#endif
71+
72+
#endif /* _CAN_SN65HVD234_ */

hardware/arduino/sam/system/libsam/include/can.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ uint32_t can_mailbox_write(Can *p_can, can_mb_conf_t *p_mailbox);
153153
uint32_t can_mailbox_tx_remote_frame(Can *p_can, can_mb_conf_t *p_mailbox);
154154
void can_reset_all_mailbox(Can *p_can);
155155

156+
// from wilfredo
157+
void reset_mailbox_conf(can_mb_conf_t *p_mailbox);
158+
156159
/** @} */
157160

158161
/** @cond 0 */

hardware/arduino/sam/system/libsam/source/can.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,22 @@ void can_reset_all_mailbox(Can *p_can)
764764
}
765765
}
766766

767+
// from wilfredo
768+
void reset_mailbox_conf(can_mb_conf_t *p_mailbox)
769+
{
770+
p_mailbox->ul_mb_idx = 0;
771+
p_mailbox->uc_obj_type = 0;
772+
p_mailbox->uc_id_ver = 0;
773+
p_mailbox->uc_length = 0;
774+
p_mailbox->uc_tx_prio = 0;
775+
p_mailbox->ul_status = 0;
776+
p_mailbox->ul_id_msk = 0;
777+
p_mailbox->ul_id = 0;
778+
p_mailbox->ul_fid = 0;
779+
p_mailbox->ul_datal = 0;
780+
p_mailbox->ul_datah = 0;
781+
}
782+
767783
#endif // SAM3XA_SERIES
768784

769785

0 commit comments

Comments
 (0)