From 2c107798a267d14b73d8b5185ec393479e53dc27 Mon Sep 17 00:00:00 2001 From: Thibaut VIARD Date: Thu, 20 Dec 2012 11:20:01 +0100 Subject: [PATCH] [sam] integrating Wilfredo CAN driver function and bringing sn65hvd234 driver into CAN library --- .../arduino/sam/libraries/CAN/sn65hvd234.c | 157 ++++++++++++++++++ .../arduino/sam/libraries/CAN/sn65hvd234.h | 72 ++++++++ .../arduino/sam/system/libsam/include/can.h | 3 + .../arduino/sam/system/libsam/source/can.c | 16 ++ 4 files changed, 248 insertions(+) create mode 100644 hardware/arduino/sam/libraries/CAN/sn65hvd234.c create mode 100644 hardware/arduino/sam/libraries/CAN/sn65hvd234.h diff --git a/hardware/arduino/sam/libraries/CAN/sn65hvd234.c b/hardware/arduino/sam/libraries/CAN/sn65hvd234.c new file mode 100644 index 000000000..e4001fe2e --- /dev/null +++ b/hardware/arduino/sam/libraries/CAN/sn65hvd234.c @@ -0,0 +1,157 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2010, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ +/** + * \file + * + * Implementation of the SN65HVD234 drivers. + * + */ + +#include "board.h" + +#include + +/** + * \brief Initialize SN65HVD234 component data + * + * \param pComponent pointer on SSN65HVD234_Data + * + * \return 0 if OK + */ +extern uint32_t SN65HVD234_Init( SSN65HVD234_Data* pComponent ) +{ + pComponent->pPIO_Rs=NULL ; + pComponent->dwPin_Rs=0u ; + + pComponent->pPIO_EN=NULL ; + pComponent->dwPin_EN=0u ; + + return 0u ; +} + +/** + * \brief Initialize Rs pin of transceiver + * + * \param pComponent pointer on SSN65HVD234_Data + * \param pPIO_Rs pointer on PIOx base for transceiver Rs pin + * \param dwPin_Rs PIO pin index for transceiver Rs pin + * + * \return 0 if OK + */ +extern uint32_t SN65HVD234_SetRs( SSN65HVD234_Data* pComponent, Pio* pPIO_Rs, uint32_t dwPin_Rs ) +{ + pComponent->pPIO_Rs=pPIO_Rs ; + pComponent->dwPin_Rs=dwPin_Rs ; + + PIO_SetOutput( pPIO_Rs, dwPin_Rs, PIO_PULLUP|PIO_OUTPUT_LOW ) ; + + return 0u ; +} + +/** + * \brief Initialize EN pin of transceiver + * + * \param pComponent pointer on SSN65HVD234_Data + * \param pPIO_EN pointer on PIOx base for transceiver EN pin + * \param dwPin_EN PIO pin index for transceiver EN pin + * + * \return 0 if OK + */ +extern uint32_t SN65HVD234_SetEN( SSN65HVD234_Data* pComponent, Pio* pPIO_EN, uint32_t dwPin_EN ) +{ + pComponent->pPIO_EN=pPIO_EN ; + pComponent->dwPin_EN=dwPin_EN ; + + PIO_SetOutput( pPIO_EN, dwPin_EN, PIO_PULLUP|PIO_OUTPUT_LOW ) ; + + return 0u ; +} + +/** + * \brief Enable transceiver + * + * \param pComponent pointer on SSN65HVD234_Data + * + * \return 0 if OK + */ +extern uint32_t SN65HVD234_Enable( SSN65HVD234_Data* pComponent ) +{ + // Raise EN of SN65HVD234 to High Level (Vcc) + pComponent->pPIO_EN->PIO_SODR=pComponent->dwPin_EN ; + + return 0u ; +} + +/** + * \brief Disable transceiver + * + * \param pComponent pointer on SSN65HVD234_Data + * + * \return 0 if OK + */ +extern uint32_t SN65HVD234_Disable( SSN65HVD234_Data* pComponent ) +{ + // Lower EN of SN65HVD234 to Low Level (0.0v) + pComponent->pPIO_EN->PIO_CODR=pComponent->dwPin_EN ; + + return 0u ; +} + +/** + * \brief Turn component into lowpower mode + * + * \param pComponent pointer on SSN65HVD234_Data + * + * \return 0 if OK + */ +extern uint32_t SN65HVD234_EnableLowPower( SSN65HVD234_Data* pComponent ) +{ + // Raise Rs of SN65HVD234 to more than 0.75v + pComponent->pPIO_Rs->PIO_SODR=pComponent->dwPin_Rs ; + + // Now, SN65HVD234 is only listening + + return 0u ; +} + +/** + * \brief Restore Normal mode by leaving lowpower mode + * + * \param pComponent pointer on SSN65HVD234_Data + * + * \return 0 if OK + */ +extern uint32_t SN65HVD234_DisableLowPower( SSN65HVD234_Data* pComponent ) +{ + // Lower Rs of SN65HVD234 to 0.0v < 0.33v + pComponent->pPIO_Rs->PIO_CODR=pComponent->dwPin_Rs ; + + return 0u ; +} + diff --git a/hardware/arduino/sam/libraries/CAN/sn65hvd234.h b/hardware/arduino/sam/libraries/CAN/sn65hvd234.h new file mode 100644 index 000000000..5da912660 --- /dev/null +++ b/hardware/arduino/sam/libraries/CAN/sn65hvd234.h @@ -0,0 +1,72 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2010, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + /** + * \file + * + * Include Defines & macros for the SN65HVD234. + */ + +#ifndef _CAN_SN65HVD234_ +#define _CAN_SN65HVD234_ + +#include "board.h" + +#ifdef __cplusplus + extern "C" { +#endif + + +typedef struct _SSN65HVD234_Data +{ + /** PIO dedicated to Rs pin */ + Pio* pPIO_Rs ; + /** Rs Pin on PIO */ + uint32_t dwPin_Rs ; + + /** PIO dedicated to EN pin */ + Pio* pPIO_EN ; + /** EN Pin on PIO */ + uint32_t dwPin_EN ; +} SSN65HVD234_Data ; + +extern uint32_t SN65HVD234_Init( SSN65HVD234_Data* pComponent ) ; +extern uint32_t SN65HVD234_SetRs( SSN65HVD234_Data* pComponent, Pio* pPIO_Rs, uint32_t dwPin_Rs ) ; +extern uint32_t SN65HVD234_SetEN( SSN65HVD234_Data* pComponent, Pio* pPIO_EN, uint32_t dwPin_EN ) ; + +extern uint32_t SN65HVD234_Enable( SSN65HVD234_Data* pComponent ) ; +extern uint32_t SN65HVD234_Disable( SSN65HVD234_Data* pComponent ) ; + +extern uint32_t SN65HVD234_EnableLowPower( SSN65HVD234_Data* pComponent ) ; +extern uint32_t SN65HVD234_DisableLowPower( SSN65HVD234_Data* pComponent ) ; + +#ifdef __cplusplus +} +#endif + +#endif /* _CAN_SN65HVD234_ */ diff --git a/hardware/arduino/sam/system/libsam/include/can.h b/hardware/arduino/sam/system/libsam/include/can.h index 66d4c1a60..6a6d06d80 100644 --- a/hardware/arduino/sam/system/libsam/include/can.h +++ b/hardware/arduino/sam/system/libsam/include/can.h @@ -153,6 +153,9 @@ uint32_t can_mailbox_write(Can *p_can, can_mb_conf_t *p_mailbox); uint32_t can_mailbox_tx_remote_frame(Can *p_can, can_mb_conf_t *p_mailbox); void can_reset_all_mailbox(Can *p_can); +// from wilfredo +void reset_mailbox_conf(can_mb_conf_t *p_mailbox); + /** @} */ /** @cond 0 */ diff --git a/hardware/arduino/sam/system/libsam/source/can.c b/hardware/arduino/sam/system/libsam/source/can.c index b31562dee..7553e6ed7 100644 --- a/hardware/arduino/sam/system/libsam/source/can.c +++ b/hardware/arduino/sam/system/libsam/source/can.c @@ -764,6 +764,22 @@ void can_reset_all_mailbox(Can *p_can) } } +// from wilfredo +void reset_mailbox_conf(can_mb_conf_t *p_mailbox) +{ + p_mailbox->ul_mb_idx = 0; + p_mailbox->uc_obj_type = 0; + p_mailbox->uc_id_ver = 0; + p_mailbox->uc_length = 0; + p_mailbox->uc_tx_prio = 0; + p_mailbox->ul_status = 0; + p_mailbox->ul_id_msk = 0; + p_mailbox->ul_id = 0; + p_mailbox->ul_fid = 0; + p_mailbox->ul_datal = 0; + p_mailbox->ul_datah = 0; +} + #endif // SAM3XA_SERIES