Subversion Repositories Projects

Rev

Rev 231 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 231 Rev 271
-
 
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"
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
25
// mailto:                              stephan.busker@mikro-control.de
26
// mailto:                              stephan.busker@mikro-control.de
26
//________________________________________________________________________________________________________________________________________
27
//________________________________________________________________________________________________________________________________________
27
 
28
 
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
//
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);                                                               //                 ___     ___     ___
47
                                                                                                                                        // clk  __________/   \___/   \___/   \_________
48
                                                                                                                                        // clk  __________/   \___/   \___/   \_________
48
                                                                                                                                        //
49
                                                                                                                                        //
49
        SSC_Disable();                                                                                                  //               ___             ___
50
        SSC_Disable();                                                                                                  //               ___             ___
50
                                                                                                                                        // data_________/   \___________/   \___________
51
                                                                                                                                        // data_________/   \___________/   \___________
51
 
52
 
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
 
60
 
61
 
61
//________________________________________________________________________________________________________________________________________
62
//________________________________________________________________________________________________________________________________________
62
// Funtion:     void SSC_ClearRxFifo(void);
63
// Funtion:     void SSC_ClearRxFifo(void);
63
// 
64
//
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)
72
{
73
{
73
        // enter your code here to clear the rx-fifo of the ssc.                                                                                
74
        // enter your code here to clear the rx-fifo of the ssc.
74
}
75
}
75
 
76
 
76
 
77
 
77
 
78
 
78
//________________________________________________________________________________________________________________________________________
79
//________________________________________________________________________________________________________________________________________
79
// Funtion:     SSC_GetChar(void);
80
// Funtion:     SSC_GetChar(void);
80
// 
81
//
81
// Description: This function reads one byte from the SSC
82
// Description: This function reads one byte from the SSC
82
//                              
83
//
83
//
84
//
84
// Returnvalue: the byte received.
85
// Returnvalue: the byte received.
85
//________________________________________________________________________________________________________________________________________
86
//________________________________________________________________________________________________________________________________________
86
 
87
 
87
u8 SSC_GetChar (void)
88
u8 SSC_GetChar (void)
88
{
89
{
89
        u8 Byte = 0;
90
        u8 Byte = 0;
90
 
91
 
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;
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
100
               
101
 
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
109
//                              
110
//
110
//
111
//
111
// Returnvalue: none
112
// Returnvalue: none
112
//________________________________________________________________________________________________________________________________________
113
//________________________________________________________________________________________________________________________________________
113
 
114
 
114
void SSC_PutChar (u8 Byte)
115
void SSC_PutChar (u8 Byte)
115
{
116
{
116
        #ifdef __MMC_INTERFACE_INVERTED
117
        #ifdef __MMC_INTERFACE_INVERTED
117
        SPDR = ~Byte;                                                                           // send one byte of data to the SSC
118
        SPDR = ~Byte;                                                                           // send one byte of data to the SSC
118
        #else
119
        #else
119
        SPDR =  Byte;                                                                           // send one byte of data to the SSC
120
        SPDR =  Byte;                                                                           // send one byte of data to the SSC
120
        #endif
121
        #endif
121
        SPDR = ~Byte;                                                                           // send one byte of data to the SSC
122
        SPDR = ~Byte;                                                                           // send one byte of data to the SSC
122
        while(!(SPSR & (1<<SPIF)))                                                      // wait until data was send.
123
        while(!(SPSR & (1<<SPIF)))                                                      // wait until data was send.
123
        {
124
        {
124
        }
125
        }
125
}
126
}
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
//
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
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
//________________________________________________________________________________________________________________________________________
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
 
158
void SSC_Enable(void)
159
void SSC_Enable(void)
159
{
160
{
160
        #ifdef __MMC_INTERFACE_INVERTED
161
        #ifdef __MMC_INTERFACE_INVERTED
161
        MMC_Write |= (1<<MMC_Chip_Select);                                      // enable chipselect of the sdcard (active low). 
162
        MMC_Write |= (1<<MMC_Chip_Select);                                      // enable chipselect of the sdcard (active low).
162
        #else
163
        #else
163
        MMC_Write &= ~(1<<MMC_Chip_Select);                                     // disable chipselect of the sdcard (active low). 
164
        MMC_Write &= ~(1<<MMC_Chip_Select);                                     // disable chipselect of the sdcard (active low).
164
        #endif
165
        #endif
165
}
166
}
166
 
167
 
167
 
168