Subversion Repositories NaviCtrl

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 7
// + Software Nutzungsbedingungen (english version: see below)
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
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.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
1 ingob 13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 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.
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.
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.
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 
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.
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
// + 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.
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.
1 ingob 31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 32
// + Software LICENSING TERMS
1 ingob 33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 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 
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.
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
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
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
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
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.
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.
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.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
1 ingob 55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 StephanB 56
#include "91x_lib.h"
136 killagreg 57
#include "config.h"
362 holgerb 58
#include "main.h"
1 ingob 59
 
60
//________________________________________________________________________________________________________________________________________
24 StephanB 61
// Module name:                 ssc.c 
1 ingob 62
// Compiler used:               avr-gcc 3.4.5
63
// Last Modifikation:   24.07.2007
64
// Version:                             1.02
65
// Authors:                             Stephan Busker  
66
// Description:                 Source files for access to the synchrnous serial channel.
67
//                                              Copyright (C) 2007 Stephan Busker
68
//........................................................................................................................................
24 StephanB 69
// ext. Functions:              extern void                     SSC_Init(void);         
70
//                                              extern u8                               SSC_GetChar (void);
1 ingob 71
//                                              extern void                     SSC_PutChar (u8 Byte);
72
//                                              extern void                     SSC_Disable(void); 
73
//                                              extern void                     SSC_Enable(void); 
24 StephanB 74
//                                              extern void                             SSC_ClearRxFifo();
1 ingob 75
//........................................................................................................................................
76
// URL:                                 www.Mikro-Control.de
77
// mailto:                              stephan.busker@mikro-control.de
78
//________________________________________________________________________________________________________________________________________
79
 
80
 
450 holgerb 81
u16 SPI_Speed = 2000;
24 StephanB 82
//________________________________________________________________________________________________________________________________________
83
// Function:    SSC_Enable(void);
84
// 
85
// Description: This function enables chipselect of the sdcard (active low) 
86
//                              
87
//
88
// Returnvalue: none
89
//________________________________________________________________________________________________________________________________________
1 ingob 90
 
24 StephanB 91
void SSC_Enable(void)
92
{
93
        // enable chipselect of the sd-card (P5.4 -> SD-CS, active low). 
94
        GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_RESET);
95
}
96
 
1 ingob 97
//________________________________________________________________________________________________________________________________________
24 StephanB 98
// Function:    SSC_Disable(void);
1 ingob 99
// 
24 StephanB 100
// Description: This function disables chipselect of the sdcard (active low) 
101
//                              
102
//
103
// Returnvalue: none
104
//________________________________________________________________________________________________________________________________________
105
 
106
void SSC_Disable(void)
107
{
108
        // disable chipselect of the sd-card (P5.4 -> SD-CS, active low). 
109
        GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_SET);
110
}
111
 
112
 
113
//________________________________________________________________________________________________________________________________________
114
// Function:    SSC_Init(void);
115
// 
1 ingob 116
// Description: This function initialises the synchronus serial channel to the sdcard. 
117
//                              
118
//
119
// Returnvalue: none
120
//________________________________________________________________________________________________________________________________________
121
 
379 holgerb 122
void SSC_Speed(u32 speed)
123
{
124
        SSP_InitTypeDef         SSP_InitStructure;
125
 
450 holgerb 126
        SPI_Speed = speed;
127
 
379 holgerb 128
    SSP_Cmd(SSP1, DISABLE);
129
        SSP_DeInit(SSP1);
130
        SSP_StructInit(&SSP_InitStructure);
131
        SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;
132
        SSP_InitStructure.SSP_Mode = SSP_Mode_Master;
133
        SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge;
134
        SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low;
135
        // Set Baud Rate (Prescaler)
136
        // bit rate is BRCLK/SSP_ClockPrescaler/(1+SSP_ClockRate))
137
        // With MSCLK = 48MHz = BRCLK we get for the SPICLK = 48Mhz / 20 / (1+5) = 400 kHz 
138
        SSP_InitStructure.SSP_ClockRate = 5; //5
139
        SSP_InitStructure.SSP_ClockPrescaler = (48000 / (5+1)) / speed;
140
        SSP_Init(SSP1, &SSP_InitStructure);
141
        SSP_Cmd(SSP1, ENABLE);
142
}
143
 
144
 
1 ingob 145
void SSC_Init(void)
146
{
24 StephanB 147
        GPIO_InitTypeDef        GPIO_InitStructure;
378 holgerb 148
//      WIU_InitTypeDef         WIU_InitStructure;
24 StephanB 149
        // enable APB clock for SPI1
150
        SCU_APBPeriphClockConfig(__SSP1 ,ENABLE);
151
        // configure P5.4 -> SD-CS as an output pin
41 ingob 152
        GPIO_StructInit(&GPIO_InitStructure);
24 StephanB 153
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
154
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
155
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
196 killagreg 156
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
24 StephanB 157
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
158
        GPIO_Init (GPIO5, &GPIO_InitStructure);
159
        // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an output pin
41 ingob 160
        GPIO_StructInit(&GPIO_InitStructure);
24 StephanB 161
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
162
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
163
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
196 killagreg 164
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
24 StephanB 165
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;
166
        GPIO_Init (GPIO3, &GPIO_InitStructure);
167
        // configure P3.5 <- MISO1 as an input pin
41 ingob 168
        GPIO_StructInit(&GPIO_InitStructure);
24 StephanB 169
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
170
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
171
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
196 killagreg 172
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
24 StephanB 173
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
174
        GPIO_Init (GPIO3, &GPIO_InitStructure);
175
        // configure SPI1
379 holgerb 176
    SSC_Speed(400);
24 StephanB 177
        SSC_Disable();
178
        SSP_Cmd(SSP1, ENABLE);
1 ingob 179
 
24 StephanB 180
        // Configure SD_SWITCH at pin GPIO5.3 as an external irq 11
1 ingob 181
 
24 StephanB 182
        // configure the port
183
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock    
184
    GPIO_InitStructure.GPIO_Direction =         GPIO_PinInput;
185
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_3;
186
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull ;
196 killagreg 187
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Disable;
24 StephanB 188
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1;
189
    GPIO_Init(GPIO5, &GPIO_InitStructure);
190
 
369 holgerb 191
/*
24 StephanB 192
        // configure the EXT11 interrupt line (P5.3) as an IRQ with the lowest priority
193
        SCU_APBPeriphClockConfig(__WIU, ENABLE);
154 killagreg 194
        WIU_Cmd(ENABLE);
24 StephanB 195
        WIU_ClearITPendingBit(WIU_Line11);
154 killagreg 196
        //WIU_DeInit();
24 StephanB 197
        WIU_InitStructure.WIU_TriggerEdge = WIU_FallingEdge;
198
        WIU_InitStructure.WIU_Line = WIU_Line11;
199
        WIU_Init(&WIU_InitStructure);
200
        // The  EXTIT1_IRQHandler() is called every time the SD-Switch is activated (falling edge)
201
        // by inserting an sd-card
202
        SCU_WakeUpLineConfig(11);
136 killagreg 203
    VIC_Config(EXTIT1_ITLine, VIC_IRQ, PRIORITY_SDSWITCH);
24 StephanB 204
    VIC_ITCmd(EXTIT1_ITLine, ENABLE);
369 holgerb 205
*/
24 StephanB 206
}
1 ingob 207
 
24 StephanB 208
void SSC_Deinit(void)
209
{
210
        GPIO_InitTypeDef        GPIO_InitStructure;
1 ingob 211
 
24 StephanB 212
        SSP_Cmd(SSP1, DISABLE);
213
        SSP_DeInit(SSP1);
1 ingob 214
 
24 StephanB 215
        // configure P5.4 -> SD-CS as an input pin
216
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
217
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
218
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
196 killagreg 219
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
24 StephanB 220
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
221
        GPIO_Init (GPIO5, &GPIO_InitStructure);
222
        // configure P3.4 -> SCK1 and P3.6 -> MOSI1 as an input pin
223
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
224
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
225
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
196 killagreg 226
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
24 StephanB 227
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
228
        GPIO_Init (GPIO3, &GPIO_InitStructure);
229
        // configure P3.5 <- MISO1 as an input pin
230
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
231
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
232
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
196 killagreg 233
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
24 StephanB 234
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
235
        GPIO_Init (GPIO3, &GPIO_InitStructure);
236
 
237
        // disable APB clock for SPI1
238
        SCU_APBPeriphClockConfig(__SSP1 ,DISABLE);
239
 
240
        // configure the port of the SDC-Switch
241
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock    
242
    GPIO_InitStructure.GPIO_Direction =         GPIO_PinInput;
243
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_3;
244
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull ;
196 killagreg 245
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Disable;
24 StephanB 246
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1;
247
    GPIO_Init(GPIO5, &GPIO_InitStructure);
1 ingob 248
}
249
 
250
 
251
//________________________________________________________________________________________________________________________________________
24 StephanB 252
// Function:    SSC_GetChar(void);
1 ingob 253
// 
254
// Description: This function reads one byte from the SSC
255
//                              
256
//
257
// Returnvalue: the byte received.
258
//________________________________________________________________________________________________________________________________________
259
 
260
u8 SSC_GetChar (void)
261
{
262
        u8 Byte = 0;
378 holgerb 263
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET);  // wait for space in the tx fifo
24 StephanB 264
        SSP_SendData(SSP1, 0xFF);// send dymmy byte (0xFF) as master to receive a byte from the slave
378 holgerb 265
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET); // wait for the byte to be sent
24 StephanB 266
        Byte = SSP_ReceiveData(SSP1); // read the byte transmitted from the slave
1 ingob 267
        return (Byte);
268
}
269
 
270
//________________________________________________________________________________________________________________________________________
271
void SSC_ClearRxFifo (void)
272
{
24 StephanB 273
        // wait that the tx fifo is empty
378 holgerb 274
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET);
24 StephanB 275
        // then empty the rx fifo by reading all the bytes that are available
378 holgerb 276
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RxFifoNotEmpty) == SET) SSP_ReceiveData(SSP1);
1 ingob 277
}
278
//________________________________________________________________________________________________________________________________________
24 StephanB 279
// Function:    SSC_PutChar(u8 Byte);
1 ingob 280
// 
281
// Description: This function writes one byte to the SSC 
282
//                              
283
//
284
// Returnvalue: none
285
//________________________________________________________________________________________________________________________________________
286
 
287
void SSC_PutChar (u8 Byte)
288
{
24 StephanB 289
        // wait for some space in the tx fifo
378 holgerb 290
        while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET);
24 StephanB 291
        // put the byte to send in the tx fifo
1 ingob 292
        SSP_SendData(SSP1, Byte);
293
}
294
 
295
 
296
 
297
 
298
 
299
 
300
 
301