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