Changeset 284 for branch/giet_vm_ioc_drivers/giet_drivers/spi_driver.c
- Timestamp:
- Jan 31, 2014, 2:37:38 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branch/giet_vm_ioc_drivers/giet_drivers/spi_driver.c
r283 r284 1 /** 2 * \file spi.c 3 * \date 31 August 2012 4 * \author Cesar Fuguet <cesar.fuguet-tortolero@lip6.fr> 5 */ 1 /////////////////////////////////////////////////////////////////////////////////// 2 // File : spi_driver.c 3 // Date : 31/08/2012 4 // Author : cesar fuguet 5 // Copyright (c) UPMC-LIP6 6 /////////////////////////////////////////////////////////////////////////////////// 6 7 #include <spi_driver.h> 7 8 #include <utils.h> 8 9 9 / **10 * \param x: input value 11 * 12 * \return byte-swapped value 13 * 14 * \brief byte-swap a 32bit word 15 */10 /////////////////////////////////////////////////////////////////////////////// 11 // bswap32() 12 // This function makes a byte swap for a 4 bytes word 13 // Arguments are: 14 // - x : word 15 // Returns the word x swapped 16 /////////////////////////////////////////////////////////////////////////////// 16 17 static unsigned int bswap32(unsigned int x) 17 18 { … … 24 25 } 25 26 26 /** 27 * \param spi : Initialized pointer to the SPI controller 28 * 29 * \brief Wait until the SPI controller has finished a transfer 30 * 31 * Wait until the GO_BUSY bit of the SPI controller be deasserted 32 */ 27 /////////////////////////////////////////////////////////////////////////////// 28 // _spi_wait_if_busy() 29 // This function returns when the SPI controller has finished a transfer 30 // Arguments are: 31 // - spi : initialized pointer to the SPI controller 32 /////////////////////////////////////////////////////////////////////////////// 33 33 static void _spi_wait_if_busy(struct spi_dev * spi) 34 34 { … … 41 41 } 42 42 43 /** 44 * \param spi : Initialized pointer to the SPI controller 45 * 46 * \return void 47 * 48 * \brief Init transfer of the tx registers to the selected slaves 49 */ 43 /////////////////////////////////////////////////////////////////////////////// 44 // _spi_init_transfer() 45 // This function trigger transfer of the tx registers to the selected slaves 46 // Arguments are: 47 // - spi : initialized pointer to the SPI controller 48 /////////////////////////////////////////////////////////////////////////////// 50 49 static void _spi_init_transfer(struct spi_dev * spi) 51 50 { … … 55 54 } 56 55 57 /** 58 * \param spi_freq : Desired frequency for the generated clock from the SPI 59 * controller 60 * \param sys_freq : System clock frequency 61 * 62 * \brief Calculated the value for the divider register in order to obtain the SPI 63 * desired clock frequency 64 */ 56 /////////////////////////////////////////////////////////////////////////////// 57 // _spi_calc_divider_value() 58 // This function computes the value for the divider register in order to obtain 59 // the SPI desired clock frequency 60 // - spi_freq : desired frequency for the generated clock from the SPI 61 // controller 62 // - sys_freq : system clock frequency 63 // Returns the computed frequency 64 /////////////////////////////////////////////////////////////////////////////// 65 65 static unsigned int _spi_calc_divider_value( unsigned int spi_freq , 66 66 unsigned int sys_freq ) … … 69 69 } 70 70 71 /////////////////////////////////////////////////////////////////////////////// 72 // spi_put_tx() 73 // This function writes a byte on the tx register and trigger transfert 74 // - spi : initialized pointer to the SPI controller 75 // - byte : byte to write on tx register 76 // - index: index of the tx register 77 /////////////////////////////////////////////////////////////////////////////// 71 78 void spi_put_tx(struct spi_dev * spi, unsigned char byte, int index) 72 79 { … … 79 86 } 80 87 88 /////////////////////////////////////////////////////////////////////////////// 89 // spi_get_rx() 90 // This function reads a byte on the rx register 91 // - spi : initialized pointer to the SPI controller 92 // - index: index of the rx register 93 // Returns the byte read 94 /////////////////////////////////////////////////////////////////////////////// 81 95 volatile unsigned char spi_get_rx(struct spi_dev * spi, int index) 82 96 { … … 84 98 } 85 99 100 /////////////////////////////////////////////////////////////////////////////// 101 // spi_get_data() 102 // This function reads count bytes and store them on a memory buffer 103 // - spi : initialized pointer to the SPI controller 104 // - buffer: physical address of the buffer containing the read data 105 // - count : number of bytes to get (must be 512 bytes) 106 // Returns 0 if success and other value when failure 107 /////////////////////////////////////////////////////////////////////////////// 86 108 unsigned int spi_get_data( struct spi_dev * spi, 87 109 paddr_t buffer , … … 161 183 } 162 184 163 //reset_ctrl: 185 #if 0 186 reset_ctrl: 187 #endif 164 188 165 189 /* Switch back to original word size */ … … 169 193 } 170 194 195 /////////////////////////////////////////////////////////////////////////////// 196 // spi_ss_assert() 197 // This function enables a SPI slave 198 // - spi : initialized pointer to the SPI controller 199 // - index : slave index 200 /////////////////////////////////////////////////////////////////////////////// 171 201 void spi_ss_assert(struct spi_dev * spi, int index) 172 202 { … … 176 206 } 177 207 208 /////////////////////////////////////////////////////////////////////////////// 209 // spi_ss_deassert() 210 // This function disables a SPI slave 211 // - spi : initialized pointer to the SPI controller 212 // - index : slave index 213 /////////////////////////////////////////////////////////////////////////////// 178 214 void spi_ss_deassert(struct spi_dev * spi, int index) 179 215 { … … 183 219 } 184 220 221 /////////////////////////////////////////////////////////////////////////////// 222 // _spi_init() 223 // This function initializes the configuration register of SPI controller 224 // - spi : initialized pointer to the SPI controller 225 // - spi_freq : SPI desired frequency (Hz) 226 // - sys_freq : system frequency (Hz) 227 // - char_len : bits per transfer 228 // - tx_edge : if 1, transfer on positive edge 229 // - rx_edge : if 1, latch received data on negative edge 230 /////////////////////////////////////////////////////////////////////////////// 185 231 void _spi_init ( struct spi_dev * spi, 186 232 int spi_freq , … … 205 251 } 206 252 207 /* 208 * vim: tabstop=4 : shiftwidth=4 : expandtab : softtabstop=4 209 */ 253 // Local Variables: 254 // tab-width: 4 255 // c-basic-offset: 4 256 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 257 // indent-tabs-mode: nil 258 // End: 259 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracChangeset
for help on using the changeset viewer.