Rev 379 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 379 | Rev 450 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
22 | // + des Mitverschuldens offen. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
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. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
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 |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
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 | // + 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. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
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 | // + 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 |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + The Software may only be used with the Licensor's products. |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + agreement shall be the property of the Licensor. |
40 | // + agreement shall be the property of the Licensor. |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
43 | // + The customer shall be responsible for taking reasonable precautions |
43 | // + The customer shall be responsible for taking reasonable precautions |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include "91x_lib.h" |
56 | #include "91x_lib.h" |
57 | #include "config.h" |
57 | #include "config.h" |
58 | #include "main.h" |
58 | #include "main.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 | u16 SPI_Speed = 2000; |
|
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_Speed(u32 speed) |
122 | void SSC_Speed(u32 speed) |
123 | { |
123 | { |
124 | SSP_InitTypeDef SSP_InitStructure; |
124 | SSP_InitTypeDef SSP_InitStructure; |
- | 125 | ||
- | 126 | SPI_Speed = speed; |
|
125 | 127 | ||
126 | SSP_Cmd(SSP1, DISABLE); |
128 | SSP_Cmd(SSP1, DISABLE); |
127 | SSP_DeInit(SSP1); |
129 | SSP_DeInit(SSP1); |
128 | SSP_StructInit(&SSP_InitStructure); |
130 | SSP_StructInit(&SSP_InitStructure); |
129 | SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; |
131 | SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; |
130 | SSP_InitStructure.SSP_Mode = SSP_Mode_Master; |
132 | SSP_InitStructure.SSP_Mode = SSP_Mode_Master; |
131 | SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; |
133 | SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; |
132 | SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; |
134 | SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; |
133 | // Set Baud Rate (Prescaler) |
135 | // Set Baud Rate (Prescaler) |
134 | // bit rate is BRCLK/SSP_ClockPrescaler/(1+SSP_ClockRate)) |
136 | // bit rate is BRCLK/SSP_ClockPrescaler/(1+SSP_ClockRate)) |
135 | // With MSCLK = 48MHz = BRCLK we get for the SPICLK = 48Mhz / 20 / (1+5) = 400 kHz |
137 | // With MSCLK = 48MHz = BRCLK we get for the SPICLK = 48Mhz / 20 / (1+5) = 400 kHz |
136 | SSP_InitStructure.SSP_ClockRate = 5; //5 |
138 | SSP_InitStructure.SSP_ClockRate = 5; //5 |
137 | SSP_InitStructure.SSP_ClockPrescaler = (48000 / (5+1)) / speed; |
139 | SSP_InitStructure.SSP_ClockPrescaler = (48000 / (5+1)) / speed; |
138 | SSP_Init(SSP1, &SSP_InitStructure); |
140 | SSP_Init(SSP1, &SSP_InitStructure); |
139 | SSP_Cmd(SSP1, ENABLE); |
141 | SSP_Cmd(SSP1, ENABLE); |
140 | } |
142 | } |
141 | 143 | ||
142 | 144 | ||
143 | void SSC_Init(void) |
145 | void SSC_Init(void) |
144 | { |
146 | { |
145 | GPIO_InitTypeDef GPIO_InitStructure; |
147 | GPIO_InitTypeDef GPIO_InitStructure; |
146 | // WIU_InitTypeDef WIU_InitStructure; |
148 | // WIU_InitTypeDef WIU_InitStructure; |
147 | // enable APB clock for SPI1 |
149 | // enable APB clock for SPI1 |
148 | SCU_APBPeriphClockConfig(__SSP1 ,ENABLE); |
150 | SCU_APBPeriphClockConfig(__SSP1 ,ENABLE); |
149 | // configure P5.4 -> SD-CS as an output pin |
151 | // configure P5.4 -> SD-CS as an output pin |
150 | GPIO_StructInit(&GPIO_InitStructure); |
152 | GPIO_StructInit(&GPIO_InitStructure); |
151 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
153 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
152 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; |
154 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; |
153 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
155 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
154 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
156 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
155 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1; |
157 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1; |
156 | GPIO_Init (GPIO5, &GPIO_InitStructure); |
158 | GPIO_Init (GPIO5, &GPIO_InitStructure); |
157 | // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an output pin |
159 | // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an output pin |
158 | GPIO_StructInit(&GPIO_InitStructure); |
160 | GPIO_StructInit(&GPIO_InitStructure); |
159 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
161 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
160 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6; |
162 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6; |
161 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
163 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
162 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
164 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
163 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; |
165 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; |
164 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
166 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
165 | // configure P3.5 <- MISO1 as an input pin |
167 | // configure P3.5 <- MISO1 as an input pin |
166 | GPIO_StructInit(&GPIO_InitStructure); |
168 | GPIO_StructInit(&GPIO_InitStructure); |
167 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
169 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
168 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; |
170 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; |
169 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
171 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
170 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
172 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
171 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
173 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
172 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
174 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
173 | // configure SPI1 |
175 | // configure SPI1 |
174 | SSC_Speed(400); |
176 | SSC_Speed(400); |
175 | SSC_Disable(); |
177 | SSC_Disable(); |
176 | SSP_Cmd(SSP1, ENABLE); |
178 | SSP_Cmd(SSP1, ENABLE); |
177 | 179 | ||
178 | // Configure SD_SWITCH at pin GPIO5.3 as an external irq 11 |
180 | // Configure SD_SWITCH at pin GPIO5.3 as an external irq 11 |
179 | 181 | ||
180 | // configure the port |
182 | // configure the port |
181 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock |
183 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock |
182 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
184 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
183 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
185 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
184 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
186 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
185 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
187 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
186 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
188 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
187 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
189 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
188 | 190 | ||
189 | /* |
191 | /* |
190 | // configure the EXT11 interrupt line (P5.3) as an IRQ with the lowest priority |
192 | // configure the EXT11 interrupt line (P5.3) as an IRQ with the lowest priority |
191 | SCU_APBPeriphClockConfig(__WIU, ENABLE); |
193 | SCU_APBPeriphClockConfig(__WIU, ENABLE); |
192 | WIU_Cmd(ENABLE); |
194 | WIU_Cmd(ENABLE); |
193 | WIU_ClearITPendingBit(WIU_Line11); |
195 | WIU_ClearITPendingBit(WIU_Line11); |
194 | //WIU_DeInit(); |
196 | //WIU_DeInit(); |
195 | WIU_InitStructure.WIU_TriggerEdge = WIU_FallingEdge; |
197 | WIU_InitStructure.WIU_TriggerEdge = WIU_FallingEdge; |
196 | WIU_InitStructure.WIU_Line = WIU_Line11; |
198 | WIU_InitStructure.WIU_Line = WIU_Line11; |
197 | WIU_Init(&WIU_InitStructure); |
199 | WIU_Init(&WIU_InitStructure); |
198 | // The EXTIT1_IRQHandler() is called every time the SD-Switch is activated (falling edge) |
200 | // The EXTIT1_IRQHandler() is called every time the SD-Switch is activated (falling edge) |
199 | // by inserting an sd-card |
201 | // by inserting an sd-card |
200 | SCU_WakeUpLineConfig(11); |
202 | SCU_WakeUpLineConfig(11); |
201 | VIC_Config(EXTIT1_ITLine, VIC_IRQ, PRIORITY_SDSWITCH); |
203 | VIC_Config(EXTIT1_ITLine, VIC_IRQ, PRIORITY_SDSWITCH); |
202 | VIC_ITCmd(EXTIT1_ITLine, ENABLE); |
204 | VIC_ITCmd(EXTIT1_ITLine, ENABLE); |
203 | */ |
205 | */ |
204 | } |
206 | } |
205 | 207 | ||
206 | void SSC_Deinit(void) |
208 | void SSC_Deinit(void) |
207 | { |
209 | { |
208 | GPIO_InitTypeDef GPIO_InitStructure; |
210 | GPIO_InitTypeDef GPIO_InitStructure; |
209 | 211 | ||
210 | SSP_Cmd(SSP1, DISABLE); |
212 | SSP_Cmd(SSP1, DISABLE); |
211 | SSP_DeInit(SSP1); |
213 | SSP_DeInit(SSP1); |
212 | 214 | ||
213 | // configure P5.4 -> SD-CS as an input pin |
215 | // configure P5.4 -> SD-CS as an input pin |
214 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
216 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
215 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; |
217 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; |
216 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
218 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
217 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
219 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
218 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
220 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
219 | GPIO_Init (GPIO5, &GPIO_InitStructure); |
221 | GPIO_Init (GPIO5, &GPIO_InitStructure); |
220 | // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an input pin |
222 | // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an input pin |
221 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
223 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
222 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6; |
224 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6; |
223 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
225 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
224 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
226 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
225 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
227 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
226 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
228 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
227 | // configure P3.5 <- MISO1 as an input pin |
229 | // configure P3.5 <- MISO1 as an input pin |
228 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
230 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
229 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; |
231 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; |
230 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
232 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
231 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
233 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
232 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
234 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
233 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
235 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
234 | 236 | ||
235 | // disable APB clock for SPI1 |
237 | // disable APB clock for SPI1 |
236 | SCU_APBPeriphClockConfig(__SSP1 ,DISABLE); |
238 | SCU_APBPeriphClockConfig(__SSP1 ,DISABLE); |
237 | 239 | ||
238 | // configure the port of the SDC-Switch |
240 | // configure the port of the SDC-Switch |
239 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock |
241 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock |
240 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
242 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
241 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
243 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
242 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
244 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
243 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
245 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
244 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
246 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
245 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
247 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
246 | } |
248 | } |
247 | 249 | ||
248 | 250 | ||
249 | //________________________________________________________________________________________________________________________________________ |
251 | //________________________________________________________________________________________________________________________________________ |
250 | // Function: SSC_GetChar(void); |
252 | // Function: SSC_GetChar(void); |
251 | // |
253 | // |
252 | // Description: This function reads one byte from the SSC |
254 | // Description: This function reads one byte from the SSC |
253 | // |
255 | // |
254 | // |
256 | // |
255 | // Returnvalue: the byte received. |
257 | // Returnvalue: the byte received. |
256 | //________________________________________________________________________________________________________________________________________ |
258 | //________________________________________________________________________________________________________________________________________ |
257 | 259 | ||
258 | u8 SSC_GetChar (void) |
260 | u8 SSC_GetChar (void) |
259 | { |
261 | { |
260 | u8 Byte = 0; |
262 | u8 Byte = 0; |
261 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET); // wait for space in the tx fifo |
263 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET); // wait for space in the tx fifo |
262 | SSP_SendData(SSP1, 0xFF);// send dymmy byte (0xFF) as master to receive a byte from the slave |
264 | SSP_SendData(SSP1, 0xFF);// send dymmy byte (0xFF) as master to receive a byte from the slave |
263 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET); // wait for the byte to be sent |
265 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET); // wait for the byte to be sent |
264 | Byte = SSP_ReceiveData(SSP1); // read the byte transmitted from the slave |
266 | Byte = SSP_ReceiveData(SSP1); // read the byte transmitted from the slave |
265 | return (Byte); |
267 | return (Byte); |
266 | } |
268 | } |
267 | 269 | ||
268 | //________________________________________________________________________________________________________________________________________ |
270 | //________________________________________________________________________________________________________________________________________ |
269 | void SSC_ClearRxFifo (void) |
271 | void SSC_ClearRxFifo (void) |
270 | { |
272 | { |
271 | // wait that the tx fifo is empty |
273 | // wait that the tx fifo is empty |
272 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET); |
274 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET); |
273 | // then empty the rx fifo by reading all the bytes that are available |
275 | // then empty the rx fifo by reading all the bytes that are available |
274 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RxFifoNotEmpty) == SET) SSP_ReceiveData(SSP1); |
276 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RxFifoNotEmpty) == SET) SSP_ReceiveData(SSP1); |
275 | } |
277 | } |
276 | //________________________________________________________________________________________________________________________________________ |
278 | //________________________________________________________________________________________________________________________________________ |
277 | // Function: SSC_PutChar(u8 Byte); |
279 | // Function: SSC_PutChar(u8 Byte); |
278 | // |
280 | // |
279 | // Description: This function writes one byte to the SSC |
281 | // Description: This function writes one byte to the SSC |
280 | // |
282 | // |
281 | // |
283 | // |
282 | // Returnvalue: none |
284 | // Returnvalue: none |
283 | //________________________________________________________________________________________________________________________________________ |
285 | //________________________________________________________________________________________________________________________________________ |
284 | 286 | ||
285 | void SSC_PutChar (u8 Byte) |
287 | void SSC_PutChar (u8 Byte) |
286 | { |
288 | { |
287 | // wait for some space in the tx fifo |
289 | // wait for some space in the tx fifo |
288 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET); |
290 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET); |
289 | // put the byte to send in the tx fifo |
291 | // put the byte to send in the tx fifo |
290 | SSP_SendData(SSP1, Byte); |
292 | SSP_SendData(SSP1, Byte); |
291 | } |
293 | } |
292 | 294 | ||
293 | 295 | ||
294 | 296 | ||
295 | 297 | ||
296 | 298 | ||
297 | 299 | ||
298 | 300 | ||
299 | 301 | ||
300 | 302 |