Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
231 | killagreg | 1 | #include <avr/io.h> |
2 | #include "fat16.h" |
||
3 | #include "ssc.h" |
||
4 | |||
5 | //________________________________________________________________________________________________________________________________________ |
||
6 | // Module name: fat16.c |
||
7 | // Compiler used: avr-gcc 3.4.5 |
||
8 | // Last Modifikation: 24.07.2007 |
||
9 | // Version: 1.03 |
||
10 | // Authors: Stephan Busker |
||
11 | // Description: Source files for access to the synchrnous serial channel. |
||
12 | // Copyright (C) 2007 Stephan Busker |
||
13 | //........................................................................................................................................ |
||
14 | // Functions: extern void SSC_Init(void); |
||
15 | // extern u8 SSC_GetChar (void); |
||
16 | // extern void SSC_PutChar (u8 Byte); |
||
17 | // extern void SSC_Disable(void); |
||
18 | // extern void SSC_Enable(void); |
||
19 | //........................................................................................................................................ |
||
20 | // ext. functions: extern u8 SDC_GetSector (u32,u8*); |
||
21 | // extern u8 SDC_PutSector (u32,u8*); |
||
22 | //........................................................................................................................................ |
||
23 | // |
||
24 | // URL: www.Mikro-Control.de |
||
25 | // mailto: stephan.busker@mikro-control.de |
||
26 | //________________________________________________________________________________________________________________________________________ |
||
27 | |||
28 | |||
29 | |||
30 | |||
31 | //________________________________________________________________________________________________________________________________________ |
||
32 | // Funtion: SSC_Init(void); |
||
33 | // |
||
34 | // Description: This function initialises the synchronus serial channel to the sdcard. |
||
35 | // |
||
36 | // |
||
37 | // Returnvalue: none |
||
38 | //________________________________________________________________________________________________________________________________________ |
||
39 | |||
40 | void SSC_Init(void) |
||
41 | { |
||
42 | MMC_Direction_REG &=~(1<<SPI_DI); // Set the direction of the ssc-port |
||
43 | MMC_Direction_REG |= (1<<SPI_Clock); // _______ _______ |
||
44 | MMC_Direction_REG |= (1<<SPI_DO); // CS \________________________/ |
||
45 | MMC_Direction_REG |= (1<<MMC_Chip_Select); // |
||
46 | MMC_Direction_REG |= (1<<SPI_SS); // ___ ___ ___ |
||
47 | // clk __________/ \___/ \___/ \_________ |
||
48 | // |
||
49 | SSC_Disable(); // ___ ___ |
||
50 | // data_________/ \___________/ \___________ |
||
51 | |||
52 | // initialise ssc, clock = Idel low |
||
53 | // devide clock by 32 |
||
54 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<CPOL); // Enable SSC in mastermode, invert clockpolarity (idle high) |
||
55 | SPSR = SPSR|(1<<SPI2X); |
||
56 | } |
||
57 | |||
58 | |||
59 | |||
60 | |||
61 | //________________________________________________________________________________________________________________________________________ |
||
62 | // Funtion: void SSC_ClearRxFifo(void); |
||
63 | // |
||
64 | // Description: Clears the fifo of the ssc if the controller used has a builtin fifo. |
||
65 | // |
||
66 | // |
||
67 | // Returnvalue: none |
||
68 | //________________________________________________________________________________________________________________________________________ |
||
69 | |||
70 | |||
71 | void SSC_ClearRxFifo(void) |
||
72 | { |
||
73 | // enter your code here to clear the rx-fifo of the ssc. |
||
74 | } |
||
75 | |||
76 | |||
77 | |||
78 | //________________________________________________________________________________________________________________________________________ |
||
79 | // Funtion: SSC_GetChar(void); |
||
80 | // |
||
81 | // Description: This function reads one byte from the SSC |
||
82 | // |
||
83 | // |
||
84 | // Returnvalue: the byte received. |
||
85 | //________________________________________________________________________________________________________________________________________ |
||
86 | |||
87 | u8 SSC_GetChar (void) |
||
88 | { |
||
89 | u8 Byte = 0; |
||
90 | |||
91 | SPDR = 0x00; // read one byte of data from the SSC |
||
92 | while(!(SPSR & (1<<SPIF))){}; // wait until the data has been read. |
||
93 | Byte = SPDR; |
||
94 | |||
95 | #ifdef __MMC_INTERFACE_INVERTED |
||
96 | return (~Byte); |
||
97 | #else |
||
98 | return (Byte); // the byte received |
||
99 | #endif |
||
100 | |||
101 | |||
102 | } |
||
103 | |||
104 | |||
105 | //________________________________________________________________________________________________________________________________________ |
||
106 | // Funtion: SSC_PutChar(u8 Byte); |
||
107 | // |
||
108 | // Description: This function writes one byte to the SSC |
||
109 | // |
||
110 | // |
||
111 | // Returnvalue: none |
||
112 | //________________________________________________________________________________________________________________________________________ |
||
113 | |||
114 | void SSC_PutChar (u8 Byte) |
||
115 | { |
||
116 | #ifdef __MMC_INTERFACE_INVERTED |
||
117 | SPDR = ~Byte; // send one byte of data to the SSC |
||
118 | #else |
||
119 | SPDR = Byte; // send one byte of data to the SSC |
||
120 | #endif |
||
121 | SPDR = ~Byte; // send one byte of data to the SSC |
||
122 | while(!(SPSR & (1<<SPIF))) // wait until data was send. |
||
123 | { |
||
124 | } |
||
125 | } |
||
126 | |||
127 | |||
128 | //________________________________________________________________________________________________________________________________________ |
||
129 | // Funtion: SSC_Disable(void); |
||
130 | // |
||
131 | // Description: This function enables chipselect of the sdcard (active low) |
||
132 | // |
||
133 | // |
||
134 | // Returnvalue: none |
||
135 | //________________________________________________________________________________________________________________________________________ |
||
136 | |||
137 | void SSC_Disable(void) |
||
138 | { |
||
139 | #ifdef __MMC_INTERFACE_INVERTED |
||
140 | MMC_Write &= ~(1<<MMC_Chip_Select); // disable chipselect of the sdcard (active low). |
||
141 | #else |
||
142 | MMC_Write |= (1<<MMC_Chip_Select); // enable chipselect of the sdcard (active low). |
||
143 | #endif |
||
144 | } |
||
145 | |||
146 | |||
147 | |||
148 | |||
149 | //________________________________________________________________________________________________________________________________________ |
||
150 | // Funtion: SSC_Enable(void); |
||
151 | // |
||
152 | // Description: This function disables chipselect of the sdcard (active low) |
||
153 | // |
||
154 | // |
||
155 | // Returnvalue: none |
||
156 | //________________________________________________________________________________________________________________________________________ |
||
157 | |||
158 | void SSC_Enable(void) |
||
159 | { |
||
160 | #ifdef __MMC_INTERFACE_INVERTED |
||
161 | MMC_Write |= (1<<MMC_Chip_Select); // enable chipselect of the sdcard (active low). |
||
162 | #else |
||
163 | MMC_Write &= ~(1<<MMC_Chip_Select); // disable chipselect of the sdcard (active low). |
||
164 | #endif |
||
165 | } |
||
166 |