Subversion Repositories NaviCtrl

Rev

Rev 378 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*#######################################################################################*/
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
/*#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Software Nutzungsbedingungen (english version: see below)
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
// + des Mitverschuldens offen.
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
// +  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.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Software LICENSING TERMS
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
// + 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
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
// + The Software may only be used with the Licensor's products.
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
// + agreement shall be the property of the Licensor.
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
// + features that can be used to identify the program may not be altered or defaced by the customer.
// + The customer shall be responsible for taking reasonable precautions
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
// + #### END OF LICENSING TERMS ####
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "91x_lib.h"
#include "uart1.h"
#include "analog.h"
#include "timer1.h"
#include "config.h"

AnalogData_t AnalogData;

void ADC_IRQHandler(void)
{
        IENABLE;

        if(ADC_GetFlagStatus(ADC_FLAG_ECV) == SET)
        {
                ADC_ClearFlag(ADC_FLAG_ECV);
                AnalogData.Ch1 = ADC_GetConversionValue(ADC_Channel_1);
                AnalogData.Ch2 = ADC_GetConversionValue(ADC_Channel_2);
                AnalogData.Ch3 = ADC_GetConversionValue(ADC_Channel_3);
                AnalogData.Ch4 = ADC_GetConversionValue(ADC_Channel_4);
                AnalogData.Ch5 = ADC_GetConversionValue(ADC_Channel_5);
                AnalogData.Ch6 = ADC_GetConversionValue(ADC_Channel_6);
                AnalogData.Ch7 = ADC_GetConversionValue(ADC_Channel_7);
        }
        IDISABLE;
        VIC0->VAR = 0xFF; // write any value to VIC0 Vector address register
}

void Analog_Init(void)
{
        ADC_InitTypeDef   ADC_InitStructure;

        UART1_PutString("\r\n ADC init...");

        SCU_APBPeriphClockConfig(__GPIO4, ENABLE); // Enable the GPIO4 Clock

        ADC_DeInit(); // reset register to default values

        // configure port 4 pins as analog inputs
        GPIO_ANAPinConfig(GPIO_ANAChannel1, ENABLE);
        GPIO_ANAPinConfig(GPIO_ANAChannel2, ENABLE);
        GPIO_ANAPinConfig(GPIO_ANAChannel3, ENABLE);
        GPIO_ANAPinConfig(GPIO_ANAChannel4, ENABLE);
        GPIO_ANAPinConfig(GPIO_ANAChannel5, ENABLE);
        GPIO_ANAPinConfig(GPIO_ANAChannel6, ENABLE);
        GPIO_ANAPinConfig(GPIO_ANAChannel7, ENABLE);

        ADC_Cmd(ENABLE); // power on the ADC
        ADC_StandbyModeCmd(DISABLE); // disable Standby Mode
        ADC_StructInit(&ADC_InitStructure);
        ADC_InitStructure.ADC_Channel_1_Mode = ADC_NoThreshold_Conversion;
        ADC_InitStructure.ADC_Channel_2_Mode = ADC_NoThreshold_Conversion;
        ADC_InitStructure.ADC_Channel_3_Mode = ADC_NoThreshold_Conversion;
        ADC_InitStructure.ADC_Channel_4_Mode = ADC_NoThreshold_Conversion;
        ADC_InitStructure.ADC_Channel_5_Mode = ADC_NoThreshold_Conversion;
        ADC_InitStructure.ADC_Channel_6_Mode = ADC_NoThreshold_Conversion;
        ADC_InitStructure.ADC_Channel_7_Mode = ADC_NoThreshold_Conversion;
        ADC_InitStructure.ADC_Select_Channel = ADC_Channel_1;
        ADC_InitStructure.ADC_Scan_Mode = ENABLE; // convert all selected channels
        ADC_InitStructure.ADC_Conversion_Mode = ADC_Single_Mode;
        ADC_Init(&ADC_InitStructure);

        ADC_PrescalerConfig(255);  // PCLK/255  (24MHz/255 = 94.1kHZ )
        ADC_ITConfig(ADC_IT_ECV, ENABLE); // enable end of conversion IRQ

        VIC_Config(ADC_ITLine, VIC_IRQ, PRIORITY_ADC);


        VIC_ITCmd(ADC_ITLine, ENABLE);

        UART1_PutString("ok");
}

void Analog_Deinit(void)
{
        VIC_ITCmd(ADC_ITLine, DISABLE);
        ADC_ConversionCmd(ADC_Conversion_Stop);
        ADC_ITConfig(ADC_IT_ECV, DISABLE); // disable end of conversion IRQ
        ADC_Cmd(DISABLE); // power down the ADC
        ADC_DeInit(); // reset register to default values
}

void Analog_Update(void)
{
        static u32 AnalogTimer = 0;

        if(CheckDelay(AnalogTimer))
        {
                AnalogTimer = SetDelay(25);
                ADC_ConversionCmd(ADC_Conversion_Start);
        }
}