Subversion Repositories NaviCtrl

Rev

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

Rev 136 Rev 154
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
6
// + Nur für den privaten Gebrauch
6
// + Nur für den privaten Gebrauch
7
// + FOR NON COMMERCIAL USE ONLY
7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
22
// + eindeutig als Ursprung verlinkt werden
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
28
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
29
// + mit unserer Zustimmung zulässig
29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
34
// + this list of conditions and the following disclaimer.
34
// + this list of conditions and the following disclaimer.
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
36
// +     from this software without specific prior written permission.
36
// +     from this software without specific prior written permission.
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted 
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted 
38
// +     for non-commercial use (directly or indirectly)
38
// +     for non-commercial use (directly or indirectly)
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
40
// +     with our written permission
40
// +     with our written permission
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
42
// +     clearly linked as origin 
42
// +     clearly linked as origin 
43
// +   * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed
43
// +   * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed
44
//
44
//
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55
// +  POSSIBILITY OF SUCH DAMAGE. 
55
// +  POSSIBILITY OF SUCH DAMAGE. 
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
#include "91x_lib.h"
57
#include "91x_lib.h"
58
#include "config.h"
58
#include "config.h"
59
 
59
 
60
//________________________________________________________________________________________________________________________________________
60
//________________________________________________________________________________________________________________________________________
61
// Module name:                 ssc.c 
61
// Module name:                 ssc.c 
62
// Compiler used:               avr-gcc 3.4.5
62
// Compiler used:               avr-gcc 3.4.5
63
// Last Modifikation:   24.07.2007
63
// Last Modifikation:   24.07.2007
64
// Version:                             1.02
64
// Version:                             1.02
65
// Authors:                             Stephan Busker  
65
// Authors:                             Stephan Busker  
66
// Description:                 Source files for access to the synchrnous serial channel.
66
// Description:                 Source files for access to the synchrnous serial channel.
67
//                                              Copyright (C) 2007 Stephan Busker
67
//                                              Copyright (C) 2007 Stephan Busker
68
//........................................................................................................................................
68
//........................................................................................................................................
69
// ext. Functions:              extern void                     SSC_Init(void);         
69
// ext. Functions:              extern void                     SSC_Init(void);         
70
//                                              extern u8                               SSC_GetChar (void);
70
//                                              extern u8                               SSC_GetChar (void);
71
//                                              extern void                     SSC_PutChar (u8 Byte);
71
//                                              extern void                     SSC_PutChar (u8 Byte);
72
//                                              extern void                     SSC_Disable(void); 
72
//                                              extern void                     SSC_Disable(void); 
73
//                                              extern void                     SSC_Enable(void); 
73
//                                              extern void                     SSC_Enable(void); 
74
//                                              extern void                             SSC_ClearRxFifo();
74
//                                              extern void                             SSC_ClearRxFifo();
75
//........................................................................................................................................
75
//........................................................................................................................................
76
// URL:                                 www.Mikro-Control.de
76
// URL:                                 www.Mikro-Control.de
77
// mailto:                              stephan.busker@mikro-control.de
77
// mailto:                              stephan.busker@mikro-control.de
78
//________________________________________________________________________________________________________________________________________
78
//________________________________________________________________________________________________________________________________________
79
 
79
 
80
 
80
 
81
 
81
 
82
//________________________________________________________________________________________________________________________________________
82
//________________________________________________________________________________________________________________________________________
83
// Function:    SSC_Enable(void);
83
// Function:    SSC_Enable(void);
84
// 
84
// 
85
// Description: This function enables chipselect of the sdcard (active low) 
85
// Description: This function enables chipselect of the sdcard (active low) 
86
//                              
86
//                              
87
//
87
//
88
// Returnvalue: none
88
// Returnvalue: none
89
//________________________________________________________________________________________________________________________________________
89
//________________________________________________________________________________________________________________________________________
90
 
90
 
91
void SSC_Enable(void)
91
void SSC_Enable(void)
92
{
92
{
93
        // enable chipselect of the sd-card (P5.4 -> SD-CS, active low). 
93
        // enable chipselect of the sd-card (P5.4 -> SD-CS, active low). 
94
        GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_RESET);
94
        GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_RESET);
95
}
95
}
96
 
96
 
97
//________________________________________________________________________________________________________________________________________
97
//________________________________________________________________________________________________________________________________________
98
// Function:    SSC_Disable(void);
98
// Function:    SSC_Disable(void);
99
// 
99
// 
100
// Description: This function disables chipselect of the sdcard (active low) 
100
// Description: This function disables chipselect of the sdcard (active low) 
101
//                              
101
//                              
102
//
102
//
103
// Returnvalue: none
103
// Returnvalue: none
104
//________________________________________________________________________________________________________________________________________
104
//________________________________________________________________________________________________________________________________________
105
 
105
 
106
void SSC_Disable(void)
106
void SSC_Disable(void)
107
{
107
{
108
        // disable chipselect of the sd-card (P5.4 -> SD-CS, active low). 
108
        // disable chipselect of the sd-card (P5.4 -> SD-CS, active low). 
109
        GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_SET);
109
        GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_SET);
110
}
110
}
111
 
111
 
112
 
112
 
113
//________________________________________________________________________________________________________________________________________
113
//________________________________________________________________________________________________________________________________________
114
// Function:    SSC_Init(void);
114
// Function:    SSC_Init(void);
115
// 
115
// 
116
// Description: This function initialises the synchronus serial channel to the sdcard. 
116
// Description: This function initialises the synchronus serial channel to the sdcard. 
117
//                              
117
//                              
118
//
118
//
119
// Returnvalue: none
119
// Returnvalue: none
120
//________________________________________________________________________________________________________________________________________
120
//________________________________________________________________________________________________________________________________________
121
 
121
 
122
void SSC_Init(void)
122
void SSC_Init(void)
123
{
123
{
124
        GPIO_InitTypeDef        GPIO_InitStructure;
124
        GPIO_InitTypeDef        GPIO_InitStructure;
125
        SSP_InitTypeDef         SSP_InitStructure;
125
        SSP_InitTypeDef         SSP_InitStructure;
126
        WIU_InitTypeDef         WIU_InitStructure;
126
        WIU_InitTypeDef         WIU_InitStructure;
127
        // enable APB clock for SPI1
127
        // enable APB clock for SPI1
128
        SCU_APBPeriphClockConfig(__SSP1 ,ENABLE);
128
        SCU_APBPeriphClockConfig(__SSP1 ,ENABLE);
129
        // configure P5.4 -> SD-CS as an output pin
129
        // configure P5.4 -> SD-CS as an output pin
130
        GPIO_StructInit(&GPIO_InitStructure);
130
        GPIO_StructInit(&GPIO_InitStructure);
131
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
131
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
132
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
132
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
133
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
133
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
134
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
134
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
135
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
135
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
136
        GPIO_Init (GPIO5, &GPIO_InitStructure);
136
        GPIO_Init (GPIO5, &GPIO_InitStructure);
137
        // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an output pin
137
        // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an output pin
138
        GPIO_StructInit(&GPIO_InitStructure);
138
        GPIO_StructInit(&GPIO_InitStructure);
139
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
139
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
140
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
140
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
141
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
141
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
142
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
142
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
143
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;
143
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;
144
        GPIO_Init (GPIO3, &GPIO_InitStructure);
144
        GPIO_Init (GPIO3, &GPIO_InitStructure);
145
        // configure P3.5 <- MISO1 as an input pin
145
        // configure P3.5 <- MISO1 as an input pin
146
        GPIO_StructInit(&GPIO_InitStructure);
146
        GPIO_StructInit(&GPIO_InitStructure);
147
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
147
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
148
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
148
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
149
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
149
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
150
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
150
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
151
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
151
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
152
        GPIO_Init (GPIO3, &GPIO_InitStructure);
152
        GPIO_Init (GPIO3, &GPIO_InitStructure);
153
        // configure SPI1
153
        // configure SPI1
154
        SSP_DeInit(SSP1);
154
        SSP_DeInit(SSP1);
155
        SSP_StructInit(&SSP_InitStructure);
155
        SSP_StructInit(&SSP_InitStructure);
156
        SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;
156
        SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;
157
        SSP_InitStructure.SSP_Mode = SSP_Mode_Master;
157
        SSP_InitStructure.SSP_Mode = SSP_Mode_Master;
158
        SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge;
158
        SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge;
159
        SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low;
159
        SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low;
160
        // Set Baud Rate (Prescaler)
160
        // Set Baud Rate (Prescaler)
161
        // bit rate is BRCLK/SSP_ClockPrescaler/(1+SSP_ClockRate))
161
        // bit rate is BRCLK/SSP_ClockPrescaler/(1+SSP_ClockRate))
162
        // With MSCLK = 48MHz/2 = BRCLK we get for the SPICLK = 24Mhz / 8 / (1+5) = 500 kHz
162
        // With MSCLK = 48MHz/2 = BRCLK we get for the SPICLK = 24Mhz / 8 / (1+5) = 500 kHz
163
        SSP_InitStructure.SSP_ClockRate = 5; //5
163
        SSP_InitStructure.SSP_ClockRate = 5; //5
164
        SSP_InitStructure.SSP_ClockPrescaler = 8;
164
        SSP_InitStructure.SSP_ClockPrescaler = 8;
165
        SSP_Init(SSP1, &SSP_InitStructure);
165
        SSP_Init(SSP1, &SSP_InitStructure);
166
        SSC_Disable();
166
        SSC_Disable();
167
        SSP_Cmd(SSP1, ENABLE);
167
        SSP_Cmd(SSP1, ENABLE);
168
 
168
 
169
        // Configure SD_SWITCH at pin GPIO5.3 as an external irq 11
169
        // Configure SD_SWITCH at pin GPIO5.3 as an external irq 11
170
 
170
 
171
        // configure the port
171
        // configure the port
172
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock    
172
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock    
173
    GPIO_InitStructure.GPIO_Direction =         GPIO_PinInput;
173
    GPIO_InitStructure.GPIO_Direction =         GPIO_PinInput;
174
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_3;
174
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_3;
175
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull ;
175
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull ;
176
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Disable;
176
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Disable;
177
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1;
177
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1;
178
    GPIO_Init(GPIO5, &GPIO_InitStructure);
178
    GPIO_Init(GPIO5, &GPIO_InitStructure);
179
       
179
       
180
        // configure the EXT11 interrupt line (P5.3) as an IRQ with the lowest priority
180
        // configure the EXT11 interrupt line (P5.3) as an IRQ with the lowest priority
181
        SCU_APBPeriphClockConfig(__WIU, ENABLE);
181
        SCU_APBPeriphClockConfig(__WIU, ENABLE);
182
        WIU_Cmd(ENABLE );
182
        WIU_Cmd(ENABLE);
183
        WIU_ClearITPendingBit(WIU_Line11);
183
        WIU_ClearITPendingBit(WIU_Line11);
184
        WIU_DeInit();
184
        //WIU_DeInit();
185
        WIU_InitStructure.WIU_TriggerEdge = WIU_FallingEdge;
185
        WIU_InitStructure.WIU_TriggerEdge = WIU_FallingEdge;
186
        WIU_InitStructure.WIU_Line = WIU_Line11;
186
        WIU_InitStructure.WIU_Line = WIU_Line11;
187
        WIU_Init(&WIU_InitStructure);
187
        WIU_Init(&WIU_InitStructure);
188
        // The  EXTIT1_IRQHandler() is called every time the SD-Switch is activated (falling edge)
188
        // The  EXTIT1_IRQHandler() is called every time the SD-Switch is activated (falling edge)
189
        // by inserting an sd-card
189
        // by inserting an sd-card
190
        SCU_WakeUpLineConfig(11);
190
        SCU_WakeUpLineConfig(11);
191
    VIC_Config(EXTIT1_ITLine, VIC_IRQ, PRIORITY_SDSWITCH);
191
    VIC_Config(EXTIT1_ITLine, VIC_IRQ, PRIORITY_SDSWITCH);
192
    VIC_ITCmd(EXTIT1_ITLine, ENABLE);
192
    VIC_ITCmd(EXTIT1_ITLine, ENABLE);
193
}
193
}
194
 
194
 
195
void SSC_Deinit(void)
195
void SSC_Deinit(void)
196
{
196
{
197
        GPIO_InitTypeDef        GPIO_InitStructure;
197
        GPIO_InitTypeDef        GPIO_InitStructure;
198
 
198
 
199
        SSP_Cmd(SSP1, DISABLE);
199
        SSP_Cmd(SSP1, DISABLE);
200
        SSP_DeInit(SSP1);
200
        SSP_DeInit(SSP1);
201
 
201
 
202
        // configure P5.4 -> SD-CS as an input pin
202
        // configure P5.4 -> SD-CS as an input pin
203
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
203
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
204
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
204
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
205
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
205
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
206
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
206
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
207
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
207
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
208
        GPIO_Init (GPIO5, &GPIO_InitStructure);
208
        GPIO_Init (GPIO5, &GPIO_InitStructure);
209
        // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an input pin
209
        // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an input pin
210
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
210
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
211
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
211
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
212
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
212
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
213
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
213
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
214
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
214
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
215
        GPIO_Init (GPIO3, &GPIO_InitStructure);
215
        GPIO_Init (GPIO3, &GPIO_InitStructure);
216
        // configure P3.5 <- MISO1 as an input pin
216
        // configure P3.5 <- MISO1 as an input pin
217
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
217
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
218
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
218
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
219
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
219
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
220
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
220
        GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
221
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
221
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
222
        GPIO_Init (GPIO3, &GPIO_InitStructure);
222
        GPIO_Init (GPIO3, &GPIO_InitStructure);
223
 
223
 
224
        // disable APB clock for SPI1
224
        // disable APB clock for SPI1
225
        SCU_APBPeriphClockConfig(__SSP1 ,DISABLE);
225
        SCU_APBPeriphClockConfig(__SSP1 ,DISABLE);
226
 
226
 
227
        // configure the port of the SDC-Switch
227
        // configure the port of the SDC-Switch
228
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock    
228
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock    
229
    GPIO_InitStructure.GPIO_Direction =         GPIO_PinInput;
229
    GPIO_InitStructure.GPIO_Direction =         GPIO_PinInput;
230
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_3;
230
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_3;
231
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull ;
231
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull ;
232
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Disable;
232
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Disable;
233
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1;
233
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1;
234
    GPIO_Init(GPIO5, &GPIO_InitStructure);
234
    GPIO_Init(GPIO5, &GPIO_InitStructure);
235
}
235
}
236
 
236
 
237
 
237
 
238
//________________________________________________________________________________________________________________________________________
238
//________________________________________________________________________________________________________________________________________
239
// Function:    SSC_GetChar(void);
239
// Function:    SSC_GetChar(void);
240
// 
240
// 
241
// Description: This function reads one byte from the SSC
241
// Description: This function reads one byte from the SSC
242
//                              
242
//                              
243
//
243
//
244
// Returnvalue: the byte received.
244
// Returnvalue: the byte received.
245
//________________________________________________________________________________________________________________________________________
245
//________________________________________________________________________________________________________________________________________
246
 
246
 
247
u8 SSC_GetChar (void)
247
u8 SSC_GetChar (void)
248
{
248
{
249
        u8 Byte = 0;
249
        u8 Byte = 0;
250
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET);  // wait for space in the tx fifo
250
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET);  // wait for space in the tx fifo
251
        SSP_SendData(SSP1, 0xFF);// send dymmy byte (0xFF) as master to receive a byte from the slave
251
        SSP_SendData(SSP1, 0xFF);// send dymmy byte (0xFF) as master to receive a byte from the slave
252
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET); // wait for the byte to be sent
252
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET); // wait for the byte to be sent
253
        Byte = SSP_ReceiveData(SSP1); // read the byte transmitted from the slave
253
        Byte = SSP_ReceiveData(SSP1); // read the byte transmitted from the slave
254
        return (Byte);
254
        return (Byte);
255
}
255
}
256
 
256
 
257
//________________________________________________________________________________________________________________________________________
257
//________________________________________________________________________________________________________________________________________
258
void SSC_ClearRxFifo (void)
258
void SSC_ClearRxFifo (void)
259
{
259
{
260
        // wait that the tx fifo is empty
260
        // wait that the tx fifo is empty
261
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET);
261
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET);
262
        // then empty the rx fifo by reading all the bytes that are available
262
        // then empty the rx fifo by reading all the bytes that are available
263
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RxFifoNotEmpty) == SET) SSP_ReceiveData(SSP1);
263
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RxFifoNotEmpty) == SET) SSP_ReceiveData(SSP1);
264
}
264
}
265
//________________________________________________________________________________________________________________________________________
265
//________________________________________________________________________________________________________________________________________
266
// Function:    SSC_PutChar(u8 Byte);
266
// Function:    SSC_PutChar(u8 Byte);
267
// 
267
// 
268
// Description: This function writes one byte to the SSC 
268
// Description: This function writes one byte to the SSC 
269
//                              
269
//                              
270
//
270
//
271
// Returnvalue: none
271
// Returnvalue: none
272
//________________________________________________________________________________________________________________________________________
272
//________________________________________________________________________________________________________________________________________
273
 
273
 
274
void SSC_PutChar (u8 Byte)
274
void SSC_PutChar (u8 Byte)
275
{
275
{
276
        // wait for some space in the tx fifo
276
        // wait for some space in the tx fifo
277
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET);
277
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET);
278
        // put the byte to send in the tx fifo
278
        // put the byte to send in the tx fifo
279
        SSP_SendData(SSP1, Byte);
279
        SSP_SendData(SSP1, Byte);
280
}
280
}
281
 
281
 
282
 
282
 
283
 
283
 
284
 
284
 
285
 
285
 
286
 
286
 
287
 
287
 
288
 
288
 
289
 
289