cede5c4c2424511dc7b270406e7fc50eaee974b0
[goodfet] / firmware / include / spi.h
1 /*! \file spi.h
2   \author Travis Goodspeed
3   \brief Definitions for the SPI application.
4 */
5
6 #ifndef SPI_H
7 #define SPI_H
8
9 #include "app.h"
10
11 #define SPI 0x01
12
13 //Pins and I/O
14 #if (platform == donbfet)
15 # define MOSI (1 << PA2)
16 # define MISO (1 << PA1)
17 # define SCK  (1 << PA0)
18 # define SS   (1 << PA3)
19 # define TST  (1 << PA4)
20 # define XRST (1 << PA5)
21 #else
22 # define MOSI BIT1
23 # define MISO BIT2
24 # define SCK  BIT3
25 #endif
26
27 #define SETMOSI SPIOUT|=MOSI
28 #define CLRMOSI SPIOUT&=~MOSI
29 #define SETCLK SPIOUT|=SCK
30 #define CLRCLK SPIOUT&=~SCK
31 #define READMISO (SPIIN&MISO?1:0)
32
33 //FIXME this should be defined by the platform.
34 #if (platform == donbfet)
35 # define SETTST PORTA|=(1 << PA4);
36 # define CLRTST PORTA&=~(1 << PA4);
37 # define SETRST PORTA|=(1 << PA5);
38 # define CLRRST PORTA&=~(1 << PA5);
39 #else
40 # define SETTST P4OUT|=TST
41 # define CLRTST P4OUT&=~TST
42 # define SETRST P2OUT|=RST
43 # define CLRRST P2OUT&=~RST
44 #endif
45
46 //! Set up the pins for SPI mode.
47 void spisetup();
48
49 //! Read and write an SPI byte.
50 unsigned char spitrans8(unsigned char byte);
51
52 //! Read a block to a buffer.
53 void spiflash_peekblock(unsigned long adr,
54                         unsigned char *buf,
55                         unsigned int len);
56
57
58 //! Write many blocks to the SPI Flash.
59 void spiflash_pokeblocks(unsigned long adr,
60                          unsigned char *buf,
61                          unsigned int len);
62
63
64 //! Enable SPI writing
65 void spiflash_wrten();
66
67 //! Read and write an SPI byte.
68 unsigned char spitrans8(unsigned char byte);
69 //! Grab the SPI flash status byte.
70 unsigned char spiflash_status();
71 //! Erase a sector.
72 void spiflash_erasesector(unsigned long adr);
73
74 extern app_t const spi_app;
75
76 #endif