Subversion Repositories NaviCtrl

Rev

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

Rev 196 Rev 360
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
-
 
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
-
 
7
// + FOR NON COMMERCIAL USE ONLY
-
 
8
// + www.MikroKopter.com
5
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
7
// + Software Nutzungsbedingungen (english version: see below)
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
15
// + Verkauf von Luftbildaufnahmen, usw.
-
 
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
22
// + eindeutig als Ursprung verlinkt werden
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
25
// + Benutzung auf eigene Gefahr
22
// + des Mitverschuldens offen.
-
 
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
-
 
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
-
 
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + mit unserer Zustimmung zulässig
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
-
 
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// + Software LICENSING TERMS
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
34
// + this list of conditions and the following disclaimer.
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
36
// +     from this software without specific prior written permission.
37
// + The Software may only be used with the Licensor's products.
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted 
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
38
// +     for non-commercial use (directly or indirectly)
-
 
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// +     with our written permission
40
// + agreement shall be the property of the Licensor.
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// +     clearly linked as origin 
-
 
43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
44
//
-
 
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43
// + The customer shall be responsible for taking reasonable precautions
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
55
// +  POSSIBILITY OF SUCH DAMAGE. 
53
// + #### END OF LICENSING TERMS ####
-
 
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
#include "91x_lib.h"
56
#include "91x_lib.h"
58
#include "config.h"
57
#include "config.h"
59
 
58
 
60
//________________________________________________________________________________________________________________________________________
59
//________________________________________________________________________________________________________________________________________
61
// Module name:                 ssc.c 
60
// Module name:                 ssc.c 
62
// Compiler used:               avr-gcc 3.4.5
61
// Compiler used:               avr-gcc 3.4.5
63
// Last Modifikation:   24.07.2007
62
// Last Modifikation:   24.07.2007
64
// Version:                             1.02
63
// Version:                             1.02
65
// Authors:                             Stephan Busker  
64
// Authors:                             Stephan Busker  
66
// Description:                 Source files for access to the synchrnous serial channel.
65
// Description:                 Source files for access to the synchrnous serial channel.
67
//                                              Copyright (C) 2007 Stephan Busker
66
//                                              Copyright (C) 2007 Stephan Busker
68
//........................................................................................................................................
67
//........................................................................................................................................
69
// ext. Functions:              extern void                     SSC_Init(void);         
68
// ext. Functions:              extern void                     SSC_Init(void);         
70
//                                              extern u8                               SSC_GetChar (void);
69
//                                              extern u8                               SSC_GetChar (void);
71
//                                              extern void                     SSC_PutChar (u8 Byte);
70
//                                              extern void                     SSC_PutChar (u8 Byte);
72
//                                              extern void                     SSC_Disable(void); 
71
//                                              extern void                     SSC_Disable(void); 
73
//                                              extern void                     SSC_Enable(void); 
72
//                                              extern void                     SSC_Enable(void); 
74
//                                              extern void                             SSC_ClearRxFifo();
73
//                                              extern void                             SSC_ClearRxFifo();
75
//........................................................................................................................................
74
//........................................................................................................................................
76
// URL:                                 www.Mikro-Control.de
75
// URL:                                 www.Mikro-Control.de
77
// mailto:                              stephan.busker@mikro-control.de
76
// mailto:                              stephan.busker@mikro-control.de
78
//________________________________________________________________________________________________________________________________________
77
//________________________________________________________________________________________________________________________________________
79
 
78
 
80
 
79
 
81
 
80
 
82
//________________________________________________________________________________________________________________________________________
81
//________________________________________________________________________________________________________________________________________
83
// Function:    SSC_Enable(void);
82
// Function:    SSC_Enable(void);
84
// 
83
// 
85
// Description: This function enables chipselect of the sdcard (active low) 
84
// Description: This function enables chipselect of the sdcard (active low) 
86
//                              
85
//                              
87
//
86
//
88
// Returnvalue: none
87
// Returnvalue: none
89
//________________________________________________________________________________________________________________________________________
88
//________________________________________________________________________________________________________________________________________
90
 
89
 
91
void SSC_Enable(void)
90
void SSC_Enable(void)
92
{
91
{
93
        // enable chipselect of the sd-card (P5.4 -> SD-CS, active low). 
92
        // enable chipselect of the sd-card (P5.4 -> SD-CS, active low). 
94
        GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_RESET);
93
        GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_RESET);
95
}
94
}
96
 
95
 
97
//________________________________________________________________________________________________________________________________________
96
//________________________________________________________________________________________________________________________________________
98
// Function:    SSC_Disable(void);
97
// Function:    SSC_Disable(void);
99
// 
98
// 
100
// Description: This function disables chipselect of the sdcard (active low) 
99
// Description: This function disables chipselect of the sdcard (active low) 
101
//                              
100
//                              
102
//
101
//
103
// Returnvalue: none
102
// Returnvalue: none
104
//________________________________________________________________________________________________________________________________________
103
//________________________________________________________________________________________________________________________________________
105
 
104
 
106
void SSC_Disable(void)
105
void SSC_Disable(void)
107
{
106
{
108
        // disable chipselect of the sd-card (P5.4 -> SD-CS, active low). 
107
        // disable chipselect of the sd-card (P5.4 -> SD-CS, active low). 
109
        GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_SET);
108
        GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_SET);
110
}
109
}
111
 
110
 
112
 
111
 
113
//________________________________________________________________________________________________________________________________________
112
//________________________________________________________________________________________________________________________________________
114
// Function:    SSC_Init(void);
113
// Function:    SSC_Init(void);
115
// 
114
// 
116
// Description: This function initialises the synchronus serial channel to the sdcard. 
115
// Description: This function initialises the synchronus serial channel to the sdcard. 
117
//                              
116
//                              
118
//
117
//
119
// Returnvalue: none
118
// Returnvalue: none
120
//________________________________________________________________________________________________________________________________________
119
//________________________________________________________________________________________________________________________________________
121
 
120
 
122
void SSC_Init(void)
121
void SSC_Init(void)
123
{
122
{
124
        GPIO_InitTypeDef        GPIO_InitStructure;
123
        GPIO_InitTypeDef        GPIO_InitStructure;
125
        SSP_InitTypeDef         SSP_InitStructure;
124
        SSP_InitTypeDef         SSP_InitStructure;
126
        WIU_InitTypeDef         WIU_InitStructure;
125
        WIU_InitTypeDef         WIU_InitStructure;
127
        // enable APB clock for SPI1
126
        // enable APB clock for SPI1
128
        SCU_APBPeriphClockConfig(__SSP1 ,ENABLE);
127
        SCU_APBPeriphClockConfig(__SSP1 ,ENABLE);
129
        // configure P5.4 -> SD-CS as an output pin
128
        // configure P5.4 -> SD-CS as an output pin
130
        GPIO_StructInit(&GPIO_InitStructure);
129
        GPIO_StructInit(&GPIO_InitStructure);
131
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
130
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
132
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
131
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
133
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
132
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
134
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
133
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
135
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
134
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
136
        GPIO_Init (GPIO5, &GPIO_InitStructure);
135
        GPIO_Init (GPIO5, &GPIO_InitStructure);
137
        // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an output pin
136
        // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an output pin
138
        GPIO_StructInit(&GPIO_InitStructure);
137
        GPIO_StructInit(&GPIO_InitStructure);
139
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
138
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
140
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
139
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
141
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
140
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
142
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
141
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
143
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;
142
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;
144
        GPIO_Init (GPIO3, &GPIO_InitStructure);
143
        GPIO_Init (GPIO3, &GPIO_InitStructure);
145
        // configure P3.5 <- MISO1 as an input pin
144
        // configure P3.5 <- MISO1 as an input pin
146
        GPIO_StructInit(&GPIO_InitStructure);
145
        GPIO_StructInit(&GPIO_InitStructure);
147
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
146
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
148
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
147
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
149
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
148
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
150
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
149
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
151
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
150
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
152
        GPIO_Init (GPIO3, &GPIO_InitStructure);
151
        GPIO_Init (GPIO3, &GPIO_InitStructure);
153
        // configure SPI1
152
        // configure SPI1
154
        SSP_DeInit(SSP1);
153
        SSP_DeInit(SSP1);
155
        SSP_StructInit(&SSP_InitStructure);
154
        SSP_StructInit(&SSP_InitStructure);
156
        SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;
155
        SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;
157
        SSP_InitStructure.SSP_Mode = SSP_Mode_Master;
156
        SSP_InitStructure.SSP_Mode = SSP_Mode_Master;
158
        SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge;
157
        SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge;
159
        SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low;
158
        SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low;
160
        // Set Baud Rate (Prescaler)
159
        // Set Baud Rate (Prescaler)
161
        // bit rate is BRCLK/SSP_ClockPrescaler/(1+SSP_ClockRate))
160
        // 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
161
        // With MSCLK = 48MHz/2 = BRCLK we get for the SPICLK = 24Mhz / 8 / (1+5) = 500 kHz
163
        SSP_InitStructure.SSP_ClockRate = 5; //5
162
        SSP_InitStructure.SSP_ClockRate = 5; //5
164
        SSP_InitStructure.SSP_ClockPrescaler = 8;
163
        SSP_InitStructure.SSP_ClockPrescaler = 8;
165
        SSP_Init(SSP1, &SSP_InitStructure);
164
        SSP_Init(SSP1, &SSP_InitStructure);
166
        SSC_Disable();
165
        SSC_Disable();
167
        SSP_Cmd(SSP1, ENABLE);
166
        SSP_Cmd(SSP1, ENABLE);
168
 
167
 
169
        // Configure SD_SWITCH at pin GPIO5.3 as an external irq 11
168
        // Configure SD_SWITCH at pin GPIO5.3 as an external irq 11
170
 
169
 
171
        // configure the port
170
        // configure the port
172
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock    
171
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock    
173
    GPIO_InitStructure.GPIO_Direction =         GPIO_PinInput;
172
    GPIO_InitStructure.GPIO_Direction =         GPIO_PinInput;
174
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_3;
173
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_3;
175
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull ;
174
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull ;
176
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Disable;
175
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Disable;
177
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1;
176
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1;
178
    GPIO_Init(GPIO5, &GPIO_InitStructure);
177
    GPIO_Init(GPIO5, &GPIO_InitStructure);
179
       
178
       
180
        // configure the EXT11 interrupt line (P5.3) as an IRQ with the lowest priority
179
        // configure the EXT11 interrupt line (P5.3) as an IRQ with the lowest priority
181
        SCU_APBPeriphClockConfig(__WIU, ENABLE);
180
        SCU_APBPeriphClockConfig(__WIU, ENABLE);
182
        WIU_Cmd(ENABLE);
181
        WIU_Cmd(ENABLE);
183
        WIU_ClearITPendingBit(WIU_Line11);
182
        WIU_ClearITPendingBit(WIU_Line11);
184
        //WIU_DeInit();
183
        //WIU_DeInit();
185
        WIU_InitStructure.WIU_TriggerEdge = WIU_FallingEdge;
184
        WIU_InitStructure.WIU_TriggerEdge = WIU_FallingEdge;
186
        WIU_InitStructure.WIU_Line = WIU_Line11;
185
        WIU_InitStructure.WIU_Line = WIU_Line11;
187
        WIU_Init(&WIU_InitStructure);
186
        WIU_Init(&WIU_InitStructure);
188
        // The  EXTIT1_IRQHandler() is called every time the SD-Switch is activated (falling edge)
187
        // The  EXTIT1_IRQHandler() is called every time the SD-Switch is activated (falling edge)
189
        // by inserting an sd-card
188
        // by inserting an sd-card
190
        SCU_WakeUpLineConfig(11);
189
        SCU_WakeUpLineConfig(11);
191
    VIC_Config(EXTIT1_ITLine, VIC_IRQ, PRIORITY_SDSWITCH);
190
    VIC_Config(EXTIT1_ITLine, VIC_IRQ, PRIORITY_SDSWITCH);
192
    VIC_ITCmd(EXTIT1_ITLine, ENABLE);
191
    VIC_ITCmd(EXTIT1_ITLine, ENABLE);
193
}
192
}
194
 
193
 
195
void SSC_Deinit(void)
194
void SSC_Deinit(void)
196
{
195
{
197
        GPIO_InitTypeDef        GPIO_InitStructure;
196
        GPIO_InitTypeDef        GPIO_InitStructure;
198
 
197
 
199
        SSP_Cmd(SSP1, DISABLE);
198
        SSP_Cmd(SSP1, DISABLE);
200
        SSP_DeInit(SSP1);
199
        SSP_DeInit(SSP1);
201
 
200
 
202
        // configure P5.4 -> SD-CS as an input pin
201
        // configure P5.4 -> SD-CS as an input pin
203
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
202
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
204
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
203
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
205
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
204
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
206
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
205
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
207
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
206
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
208
        GPIO_Init (GPIO5, &GPIO_InitStructure);
207
        GPIO_Init (GPIO5, &GPIO_InitStructure);
209
        // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an input pin
208
        // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an input pin
210
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
209
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
211
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
210
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
212
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
211
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
213
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
212
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
214
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
213
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
215
        GPIO_Init (GPIO3, &GPIO_InitStructure);
214
        GPIO_Init (GPIO3, &GPIO_InitStructure);
216
        // configure P3.5 <- MISO1 as an input pin
215
        // configure P3.5 <- MISO1 as an input pin
217
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
216
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
218
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
217
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
219
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
218
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
220
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
219
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
221
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
220
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
222
        GPIO_Init (GPIO3, &GPIO_InitStructure);
221
        GPIO_Init (GPIO3, &GPIO_InitStructure);
223
 
222
 
224
        // disable APB clock for SPI1
223
        // disable APB clock for SPI1
225
        SCU_APBPeriphClockConfig(__SSP1 ,DISABLE);
224
        SCU_APBPeriphClockConfig(__SSP1 ,DISABLE);
226
 
225
 
227
        // configure the port of the SDC-Switch
226
        // configure the port of the SDC-Switch
228
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock    
227
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock    
229
    GPIO_InitStructure.GPIO_Direction =         GPIO_PinInput;
228
    GPIO_InitStructure.GPIO_Direction =         GPIO_PinInput;
230
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_3;
229
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_3;
231
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull ;
230
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull ;
232
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Disable;
231
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Disable;
233
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1;
232
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1;
234
    GPIO_Init(GPIO5, &GPIO_InitStructure);
233
    GPIO_Init(GPIO5, &GPIO_InitStructure);
235
}
234
}
236
 
235
 
237
 
236
 
238
//________________________________________________________________________________________________________________________________________
237
//________________________________________________________________________________________________________________________________________
239
// Function:    SSC_GetChar(void);
238
// Function:    SSC_GetChar(void);
240
// 
239
// 
241
// Description: This function reads one byte from the SSC
240
// Description: This function reads one byte from the SSC
242
//                              
241
//                              
243
//
242
//
244
// Returnvalue: the byte received.
243
// Returnvalue: the byte received.
245
//________________________________________________________________________________________________________________________________________
244
//________________________________________________________________________________________________________________________________________
246
 
245
 
247
u8 SSC_GetChar (void)
246
u8 SSC_GetChar (void)
248
{
247
{
249
        u8 Byte = 0;
248
        u8 Byte = 0;
250
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET);  // wait for space in the tx fifo
249
        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
250
        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
251
        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
252
        Byte = SSP_ReceiveData(SSP1); // read the byte transmitted from the slave
254
        return (Byte);
253
        return (Byte);
255
}
254
}
256
 
255
 
257
//________________________________________________________________________________________________________________________________________
256
//________________________________________________________________________________________________________________________________________
258
void SSC_ClearRxFifo (void)
257
void SSC_ClearRxFifo (void)
259
{
258
{
260
        // wait that the tx fifo is empty
259
        // wait that the tx fifo is empty
261
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET);
260
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET);
262
        // then empty the rx fifo by reading all the bytes that are available
261
        // 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);
262
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RxFifoNotEmpty) == SET) SSP_ReceiveData(SSP1);
264
}
263
}
265
//________________________________________________________________________________________________________________________________________
264
//________________________________________________________________________________________________________________________________________
266
// Function:    SSC_PutChar(u8 Byte);
265
// Function:    SSC_PutChar(u8 Byte);
267
// 
266
// 
268
// Description: This function writes one byte to the SSC 
267
// Description: This function writes one byte to the SSC 
269
//                              
268
//                              
270
//
269
//
271
// Returnvalue: none
270
// Returnvalue: none
272
//________________________________________________________________________________________________________________________________________
271
//________________________________________________________________________________________________________________________________________
273
 
272
 
274
void SSC_PutChar (u8 Byte)
273
void SSC_PutChar (u8 Byte)
275
{
274
{
276
        // wait for some space in the tx fifo
275
        // wait for some space in the tx fifo
277
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET);
276
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET);
278
        // put the byte to send in the tx fifo
277
        // put the byte to send in the tx fifo
279
        SSP_SendData(SSP1, Byte);
278
        SSP_SendData(SSP1, Byte);
280
}
279
}
281
 
280
 
282
 
281
 
283
 
282
 
284
 
283
 
285
 
284
 
286
 
285
 
287
 
286
 
288
 
287
 
289
 
288