Subversion Repositories Code-Repo

Rev

Rev 251 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
248 Kevin 1
// *************************************************************************************
2
//
3
// Filename:  hal_SPI.h: 
4
// Declarations for Communication with the MMC (see mmc.c) in unprotected SPI mode.
5
//
6
// Version 1.1
7
//    added ul declaration in macros mmcWriteSector and mmcReadSector
8
// *************************************************************************************
9
 
10
#ifndef _SPILIB_H
11
#define _SPILIB_H
12
 
13
#include "hal_hardware_board.h"
14
 
15
//----------------------------------------------------------------------------
16
//  These constants are used to identify the chosen SPI and UART
17
//  interfaces.
18
//----------------------------------------------------------------------------
19
#define SER_INTF_NULL    0
20
#define SER_INTF_USART0  1
21
#define SER_INTF_USART1  2
22
#define SER_INTF_USCIA0  3
23
#define SER_INTF_USCIA1  4
24
#define SER_INTF_USCIB0  5
25
#define SER_INTF_USCIB1  6
26
#define SER_INTF_USI     7
27
#define SER_INTF_BITBANG 8
28
 
29
 
30
#if SPI_SER_INTF == SER_INTF_USART0
31
 #define halSPIRXBUF  U0RXBUF
32
 #define halSPI_SEND(x) U0TXBUF=x
33
 #define halSPITXREADY  (IFG1&UTXIFG0)         /* Wait for TX to be ready */
34
 #define halSPITXDONE  (U0TCTL&TXEPT)          /* Wait for TX to finish */
35
 #define halSPIRXREADY (IFG1&URXIFG0)          /* Wait for TX to be ready */
36
 #define halSPIRXFG_CLR IFG1 &= ~URXIFG0
37
 #define halSPI_PxIN  SPI_USART0_PxIN
38
 #define halSPI_SOMI  SPI_USART0_SOMI
39
 
40
 #elif SPI_SER_INTF == SER_INTF_USART1
41
 #define halSPIRXBUF  U1RXBUF
42
 #define halSPI_SEND(x) U1TXBUF=x
43
 #define halSPITXREADY  (IFG2&UTXIFG1)         /* Wait for TX to be ready */
44
 #define halSPITXDONE  (U1TCTL&TXEPT)          /* Wait for TX to finish */
45
 #define halSPIRXREADY (IFG2&URXIFG1)          /* Wait for TX to be ready */
46
 #define halSPIRXFG_CLR IFG2 &= ~URXIFG1
47
 #define halSPI_PxIN  SPI_USART1_PxIN
48
 #define halSPI_SOMI  SPI_USART1_SOMI
49
 
50
 #elif SPI_SER_INTF == SER_INTF_USCIA0
51
 #define halSPIRXBUF  UCA0RXBUF
52
 #define halSPI_SEND(x) UCA0TXBUF=x
53
 #define halSPITXREADY  (IFG2&UCA0TXIFG)		/* Wait for TX to be ready */
54
 #define halSPITXDONE  !(UCA0STAT&UCBUSY)		/* Wait for TX to finish */
55
 #define halSPIRXREADY (IFG2&UCB0RXIFG)			/* Wait for TX to be ready */
56
 #define halSPIRXFG_CLR IFG2 &= ~UCA0RXIFG
57
 #define halSPI_PxIN  SPI_USART0_PxIN
58
 #define halSPI_SOMI  SPI_USART0_SOMI
59
 
60
 #elif SPI_SER_INTF == SER_INTF_USCIA1
61
 #define halSPIRXBUF  UCA1RXBUF
62
 #define halSPI_SEND(x) UCA1TXBUF=x
63
 #define halSPITXREADY  (UC1IFG&UCA1TXIFG)		/* Wait for TX to be ready */
64
 #define halSPITXDONE  !(UCA1STAT&UCBUSY)		/* Wait for TX to finish */
65
 #define halSPIRXREADY (UC1IFG&UCA1RXIFG)		/* Wait for TX to be ready */
66
 #define halSPIRXFG_CLR UC1IFG &= ~UCA1RXIFG
67
 #define halSPI_PxIN  SPI_USART0_PxIN
68
 #define halSPI_SOMI  SPI_USART0_SOMI
69
 
70
 #elif SPI_SER_INTF == SER_INTF_USCIB0
71
 #define halSPIRXBUF  UCB0RXBUF
72
 #define halSPI_SEND(x) UCB0TXBUF=x
73
 #define halSPITXREADY  (UC0IFG&UCB0TXIFG)     /* Wait for TX to be ready */
74
 #define halSPITXDONE  !(UCB0STAT&UCBUSY)      /* Wait for TX to finish */
75
 #define halSPIRXREADY (UC0IFG&UCB0RXIFG)      /* Wait for TX to be ready */
76
 #define halSPIRXFG_CLR UC0IFG &= ~UCB0RXIFG
77
 #define halSPI_PxIN  SPI_USART0_PxIN
78
 #define halSPI_SOMI  SPI_USART0_SOMI
79
 
80
 #elif SPI_SER_INTF == SER_INTF_USCIB1
81
 #define halSPIRXBUF  UCB1RXBUF
82
 #define halSPI_SEND(x) UCB1TXBUF=x
83
 #define halSPITXREADY  (UC1IFG&UCB1TXIFG)		/* Wait for TX to be ready */
84
 #define halSPITXDONE  !(UCB1STAT&UCBUSY)		/* Wait for TX to finish */
85
 #define halSPIRXREADY (UC1IFG&UCB1RXIFG)		/* Wait for TX to be ready */
86
 #define halSPIRXFG_CLR UC1IFG &= ~UCB1RXIFG
87
 #define halSPI_PxIN  SPI_USART0_PxIN
88
 #define halSPI_SOMI  SPI_USART0_SOMI
89
 
90
 #elif SPI_SER_INTF == SER_INTF_USI
91
 #define halSPIRXBUF  USISRL
92
 #define halSPI_SEND(x) USISRL = x; USICNT = 8
93
 #define halSPITXREADY (USICTL1&USIIFG)
94
 #define halSPITXDONE  (USICTL1&USIIFG)
95
 #define halSPIRXREADY (USICTL1&USIIFG)
96
 #define halSPIRXFG_CLR
97
 #define halSPI_PxIN  SPI_BITBANG_PxIN
98
 #define halSPI_SOMI  SPI_BITBANG_SOMI
99
 
100
 #elif SPI_SER_INTF == SER_INTF_BITBANG
101
 #define halSPIRXBUF  spi_bitbang_in_data
102
 #define halSPI_SEND(x) spi_bitbang_inout(x)
103
 #define halSPITXREADY  1
104
 #define halSPITXDONE   1
105
 #define halSPIRXREADY  1
106
 #define halSPIRXFG_CLR
107
 #define halSPI_PxIN  SPI_BITBANG_PxIN
108
 #define halSPI_SOMI  SPI_BITBANG_SOMI
109
#endif
110
 
111
// Variables
112
#define DUMMY_CHAR 0xFF
113
 
114
// Function Prototypes
115
void halSPISetup (void);
116
unsigned char spiSendByte(const unsigned char data);
117
unsigned char spiReadFrame(unsigned char* pBuffer, unsigned int size);
118
unsigned char spiSendFrame(unsigned char* pBuffer, unsigned int size);
119
void halSPISetSpeedHigh(void);
120
void halSPISetSpeedLow(void);
251 Kevin 121
void halSPISetPolarityPhase(char polarity, char phase);
248 Kevin 122
 
123
 
124
#endif /* _SPILIB_H */