|
| 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 | + |
0 commit comments