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