source: soft/giet_vm/giet_drivers/spi_driver.h @ 541

Last change on this file since 541 was 320, checked in by alain, 10 years ago

All drivers have been modified to use only the information
contained in the hard_config.h file

File size: 3.5 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : spi_driver.h
3// Date     : 31/08/2012
4// Author   : cesar fuguet
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7#ifndef _GIET_SPI_DRIVER_H_
8#define _GIET_SPI_DRIVER_H_
9
10#include <io.h>
11#include <mapping_info.h>
12
13///////////////////////////////////////////////////////////////////////////////
14// SPI structure definition
15///////////////////////////////////////////////////////////////////////////////
16struct spi_dev
17{
18    // RX/TX registers of the SPI controller
19    unsigned int rx_tx[4];
20
21    // control register of the SPI controller
22    unsigned int ctrl;
23
24    // divider register for the SPI controller generated clock signal
25    unsigned int divider;
26
27    // slave select register of the SPI controller
28    unsigned int ss;
29
30    // SPI-DMA registers
31    unsigned int dma_base;
32    unsigned int dma_baseh;
33    unsigned int dma_count;
34};
35
36void spi_put_tx(struct spi_dev * spi, unsigned char byte, int index);
37
38inline volatile unsigned char spi_get_rx(struct spi_dev * spi, int index);
39
40unsigned int spi_get_data(struct spi_dev * spi, paddr_t buffer, unsigned int count);
41
42inline void spi_ss_assert(struct spi_dev * spi, int index);
43
44inline void spi_ss_deassert(struct spi_dev * spi, int index);
45
46void _spi_init ( struct spi_dev * spi,
47                 int spi_freq        ,
48                 int sys_freq        ,
49                 int char_len        ,
50                 int tx_edge         ,
51                 int rx_edge         );
52
53extern void _spi_isr( unsigned int irq_type,
54                      unsigned int irq_id,
55                      unsigned int channel );
56
57///////////////////////////////////////////////////////////////////////////////
58// SPI macros and constants
59///////////////////////////////////////////////////////////////////////////////
60#define SPI_TX_POSEDGE         1           // MOSI is changed on neg edge
61#define SPI_TX_NEGEDGE         0           // MOSI is changed on pos edge
62#define SPI_RX_POSEDGE         1           // MISO is latched on pos edge
63#define SPI_RX_NEGEDGE         0           // MISO is latched on neg edge
64
65#define SPI_CTRL_ASS_EN        ( 1 << 13 ) // Auto Slave Sel Assertion
66#define SPI_CTRL_IE_EN         ( 1 << 12 ) // Interrupt Enable
67#define SPI_CTRL_LSB_EN        ( 1 << 11 ) // LSB are sent first
68#define SPI_CTRL_TXN_EN        ( 1 << 10 ) // MOSI is changed on neg edge
69#define SPI_CTRL_RXN_EN        ( 1 << 9  ) // MISO is latched on neg edge
70#define SPI_CTRL_GO_BSY        ( 1 << 8  ) // Start the transfer
71#define SPI_CTRL_DMA_BSY       ( 1 << 16 ) // DMA in progress
72#define SPI_CTRL_CHAR_LEN_MASK (  0xFF   ) // Bits transmited in 1 transfer
73#define SPI_RXTX_MASK          (  0xFF   ) // Mask for the an RX/TX value
74
75#define SPI_DMA_COUNT_READ     ( 1 << 0  ) // operation is a read (else write)
76
77///////////////////////////////////////////////////////////////////////////////
78//      SPI_IS_BUSY()
79// This macro checks the GO_BSY and DMA_BSY bits of the SPI controller which
80// indicates an ongoing transfer.
81//
82// Returns 1 if there is an unfinished transfer
83///////////////////////////////////////////////////////////////////////////////
84#define SPI_IS_BUSY(x) \
85    ((ioread32(&x->ctrl) & (SPI_CTRL_GO_BSY|SPI_CTRL_DMA_BSY)) != 0) ? 1 : 0
86
87#endif
88
89// Local Variables:
90// tab-width: 4
91// c-basic-offset: 4
92// c-file-offsets:((innamespace . 0)(inline-open . 0))
93// indent-tabs-mode: nil
94// End:
95// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracBrowser for help on using the repository browser.