Refactoring a lot of the P5 stuff.
[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 #define MOSI BIT1
15 #define MISO BIT2
16 #define SCK  BIT3
17
18 #define SETMOSI SPIOUT|=MOSI
19 #define CLRMOSI SPIOUT&=~MOSI
20 #define SETCLK SPIOUT|=SCK
21 #define CLRCLK SPIOUT&=~SCK
22 #define READMISO (SPIIN&MISO?1:0)
23
24 //FIXME this should be defined by the platform.
25 #define SETTST P4OUT|=TST
26 #define CLRTST P4OUT&=~TST
27 #define SETRST P2OUT|=RST
28 #define CLRRST P2OUT&=~RST
29
30 //! Set up the pins for SPI mode.
31 void spisetup();
32
33 //! Read and write an SPI byte.
34 unsigned char spitrans8(unsigned char byte);
35
36 //! Read a block to a buffer.
37 void spiflash_peekblock(unsigned long adr,
38                         unsigned char *buf,
39                         unsigned int len);
40
41
42 //! Write many blocks to the SPI Flash.
43 void spiflash_pokeblocks(unsigned long adr,
44                          unsigned char *buf,
45                          unsigned int len);
46
47
48 //! Enable SPI writing
49 void spiflash_wrten();
50
51 //! Read and write an SPI byte.
52 unsigned char spitrans8(unsigned char byte);
53 //! Grab the SPI flash status byte.
54 unsigned char spiflash_status();
55 //! Erase a sector.
56 void spiflash_erasesector(unsigned long adr);
57
58 extern app_t const spi_app;
59
60 #endif