示例#1
0
bool_t gadcLowSpeedStart(uint32_t physdev, adcsample_t *buffer, GADCCallbackFunction fn, void *param) {
	struct lsdev *p;

	DoInit();

	/* Start the Low Speed Timer */
	chMtxLock(&gadcmutex);
	if (!gtimerIsActive(&LowSpeedGTimer))
		gtimerStart(&LowSpeedGTimer, LowSpeedGTimerCallback, NULL, TRUE, TIME_INFINITE);

	/* Find a slot */
	for(p = ls; p < &ls[GADC_MAX_LOWSPEED_DEVICES]; p++) {
		if (!(p->flags & GADC_FLG_ISACTIVE)) {
			/* We know we have a slot - this should never wait anyway */
			chSemWaitTimeout(&gadcsem, TIME_IMMEDIATE);
			p->lld.physdev = physdev;
			p->lld.buffer = buffer;
			p->fn = fn;
			p->param = param;
			p->flags = GADC_FLG_ISACTIVE;
			chMtxUnlock();
			StartADC(FALSE);
			return TRUE;
		}
	}
	chMtxUnlock();
	return FALSE;
}
示例#2
0
static void LowSpeedGTimerCallback(void *param) {
	(void) param;
	GADCCallbackFunction	fn;
	void					*prm;
	adcsample_t				*buffer;
	struct lsdev			*p;

	#if ADC_ISR_FULL_CODE_BUG
		/* Ensure the ADC is running if it needs to be - Bugfix HACK */
		StartADC(FALSE);
	#endif

	/**
	 * Look for completed low speed timers.
	 * We don't need to take the mutex as we are the only place that things are freed and we
	 * do that atomically.
	 */
	for(p=ls; p < &ls[GADC_MAX_LOWSPEED_DEVICES]; p++) {
		if ((p->flags & (GADC_FLG_ISACTIVE|GADC_FLG_ISDONE)) == (GADC_FLG_ISACTIVE|GADC_FLG_ISDONE)) {
			/* This item is done - perform its callback */
			fn = p->fn;				// Save the callback details
			prm = p->param;
			buffer = p->lld.buffer;
			p->fn = 0;				// Needed to prevent the compiler removing the local variables
			p->param = 0;			// Needed to prevent the compiler removing the local variables
			p->lld.buffer = 0;		// Needed to prevent the compiler removing the local variables
			p->flags = 0;			// The slot is available (indivisible operation)
			chSemSignal(&gadcsem);	// Tell everyone
			fn(buffer, prm);		// Perform the callback
		}
	}

}
示例#3
0
void Analog_scan(void)
{
	StartADC();
	adc[0] += (REG_AD_CH0_BUF - adc[0] + 4) / 8;
	adc[1] += (REG_AD_CH1_BUF - adc[1] + 4) / 8;
	adc[2] += (REG_AD_CH2_BUF - adc[2] + 4) / 8;
	StopADC();
}
示例#4
0
void gadcHighSpeedStart(void) {
	DoInit();

	/* If its already going we don't need to do anything */
	if (hs.flags & GADC_FLG_ISACTIVE)
		return;

	gadc_lld_start_timer(hs.lld.physdev, hs.frequency);
	hs.flags = GADC_FLG_ISACTIVE;
	StartADC(FALSE);
}
示例#5
0
void gadcHighSpeedStop(void) {
	DoInit();

	if (hs.flags & GADC_FLG_ISACTIVE) {
		/* No more from us */
		hs.flags = 0;
		gadc_lld_stop_timer(hs.lld.physdev);
		/*
		 * We have to pass TRUE to StartADC() as we might have the ADC marked as active when it isn't
		 * due to stopping the timer while it was converting.
		 */
		StartADC(TRUE);
	}
}
示例#6
0
void Analog_initialise(void)
{
	static bool initialised = false;
	if (!initialised) {
		initialised = true;
		StartADC();
		adc[0] = REG_AD_CH0_BUF;
		adc[1] = REG_AD_CH1_BUF;
		adc[2] = REG_AD_CH2_BUF;
		StopADC();
	}
	int i;
	for (i = 0; i < 12; ++i) {
		Analog_scan();
	}
}
示例#7
0
void gadcLowSpeedGet(uint32_t physdev, adcsample_t *buffer) {
	struct lsdev *p;
	BSEMAPHORE_DECL(mysem, TRUE);

	/* Start the Low Speed Timer */
	chMtxLock(&gadcmutex);
	if (!gtimerIsActive(&LowSpeedGTimer))
		gtimerStart(&LowSpeedGTimer, LowSpeedGTimerCallback, NULL, TRUE, TIME_INFINITE);
	chMtxUnlock();

	while(1) {
		/* Wait for an available slot */
		chSemWait(&gadcsem);

		/* Find a slot */
		chMtxLock(&gadcmutex);
		for(p = ls; p < &ls[GADC_MAX_LOWSPEED_DEVICES]; p++) {
			if (!(p->flags & GADC_FLG_ISACTIVE)) {
				p->lld.physdev = physdev;
				p->lld.buffer = buffer;
				p->fn = BSemSignalCallback;
				p->param = &mysem;
				p->flags = GADC_FLG_ISACTIVE;
				chMtxUnlock();
				StartADC(FALSE);
				chBSemWait(&mysem);
				return;
			}
		}
		chMtxUnlock();

		/**
		 *  We should never get here - the count semaphore must be wrong.
		 *  Decrement it and try again.
		 */
	}
}
示例#8
0
int main(void)
{
	unsigned char dev1_access, dev2_access, dev3_access, dev4_access, dev5_access, dev6_access, dev7_access, dev8_access;						// Indique si les informations ont bien été prise du capteur

	init();									// Initialisations globales
	
	dev1_access = initDS7505(ADD1_DS7505);	// Initialiser le capteur de T° n°1
	dev2_access = initDS7505(ADD2_DS7505);	// Initialiser le capteur de T° n°2
	dev3_access = initDS7505(ADD3_DS7505);	// Initialiser le capteur de T° n°3
	dev4_access = initDS7505(ADD4_DS7505);	// Initialiser le capteur de T° n°4
	dev5_access = initDS7505(ADD5_DS7505);	// Initialiser le capteur de T° n°5
	dev6_access = initDS7505(ADD6_DS7505);	// Initialiser le capteur de T° n°6
	dev7_access = initDS7505(ADD7_DS7505);	// Initialiser le capteur de T° n°7
	dev8_access = initDS7505(ADD8_DS7505);	// Initialiser le capteur de T° n°8


	/* boucle infinie */
	for(;;)
	{	
		if( data[0] != 0x00 ) // Envoie des informations à la foxboard
		{
			switch(data[0])
			{
				case CMD_INCLINAISON : // Envoie les informations d'inclinaisons du sous-marin
					transmission(CMD_INCLINAISON, ACCL, ACCH);
					break;

				case CMD_HYGROMETRE1 : // Envoie les informations d'humidité du premier capteur hygrométrique
					transmission(CMD_HYGROMETRE1, HUM1L, HUM1H);
					break;

				case CMD_HYGROMETRE2 : // Envoie les informations d'humidité du deuxième capteur hygrométrique
					transmission(CMD_HYGROMETRE2, HUM2L, HUM2H);
					break;

				case CMD_BALLAST : // Envoie les informations de la position du ballast
					transmission(CMD_BALLAST, IMP1L, IMP1H);
					break;

				case CMD_SYSTEME_BALLAST : // Envoie les informations de la position du chariot portant le ballast
					transmission(CMD_SYSTEME_BALLAST, IMP2L, IMP2H);
					break;

				case CMD_TEMP1 : // Envoie les informations de température du premier capteur
					dev1_access = get_DS7505_Devices(ADD1_DS7505, listTemp); // Récupérer T° capteur n°1
					convertTemp(listTemp, tempResult);

					TEMP1H = tempResult[0];
					TEMP1L = tempResult[1];

					transmission(CMD_TEMP1, TEMP1L, TEMP1H);
					break;

				case CMD_TEMP2 : // Envoie les informations de température du deuxième capteur
					dev2_access = get_DS7505_Devices(ADD3_DS7505, listTemp); // Récupérer T° capteur n°2
					
					convertTemp(listTemp, tempResult);

					TEMP2H = tempResult[0];
					TEMP2L = tempResult[1];

					transmission(CMD_TEMP2, TEMP2L, TEMP2H);
					break;

				case CMD_TEMP3 : // Envoie les informations de température du troisième capteur
					dev3_access = get_DS7505_Devices(ADD3_DS7505, listTemp); // Récupérer T° capteur n°3
					
					convertTemp(listTemp, tempResult);

					TEMP3H = tempResult[0];
					TEMP3L = tempResult[1];

					transmission(CMD_TEMP3, TEMP3L, TEMP3H);
					break;

				case CMD_TEMP4 : // Envoie les informations de température du quatrième capteur
					dev4_access = get_DS7505_Devices(ADD4_DS7505, listTemp); // Récupérer T° capteur n°3
					
					convertTemp(listTemp, tempResult);

					TEMP4H = tempResult[0];
					TEMP4L = tempResult[1];

					transmission(CMD_TEMP4,TEMP4L, TEMP4H);
					break;

				case CMD_TEMP5 : // Envoie les informations de température du cinquième capteur
					dev5_access = get_DS7505_Devices(ADD5_DS7505, listTemp); // Récupérer T° capteur n°3
					
					convertTemp(listTemp, tempResult);

					TEMP5H = tempResult[0];
					TEMP5L = tempResult[1];

					transmission(CMD_TEMP5, TEMP5L, TEMP5H);
					break;

				case CMD_TEMP6 : // Envoie les informations de température du sixième capteur
					dev6_access = get_DS7505_Devices(ADD6_DS7505, listTemp); // Récupérer T° capteur n°3
					
					convertTemp(listTemp, tempResult);

					TEMP6H = tempResult[0];
					TEMP6L = tempResult[1];

					transmission(CMD_TEMP6, TEMP6L, TEMP6H);
					break;

				case CMD_TEMP7 : // Envoie les informations de température du septième capteur
					dev7_access = get_DS7505_Devices(ADD7_DS7505, listTemp); // Récupérer T° capteur n°3
					
					convertTemp(listTemp, tempResult);

					TEMP7H = tempResult[0];
					TEMP7L = tempResult[1];

					transmission(CMD_TEMP7, TEMP7L, TEMP7H);
					break;

				case CMD_TEMP8 :  // Envoie les informations de température du huitième capteur
					dev8_access = get_DS7505_Devices(ADD8_DS7505, listTemp); // Récupérer T° capteur n°3
					
					convertTemp(listTemp, tempResult);

					TEMP8H = tempResult[0];
					TEMP8L = tempResult[1];

					transmission(CMD_TEMP8, TEMP8L, TEMP8H);
					break;
				
				case CMD_PROFONDEUR : // Envoie les informations de pression reçue par le capteur de pression comme indicatif de la profondeur
					StartADC(0);
					ReadADC(listTemp);
					ADC1L = listTemp[0];
					ADC1H = listTemp[1];
					transmission(CMD_PROFONDEUR, ADC1L, ADC1H);
					cbiBF(PORTD,2);
					cbiBF(PORTD,3);
					sbiBF(PORTD,4);
					break;

				case CMD_ADC2 : // Envoie les informations du deuxième convertisseur ADC
					StartADC(1);
					ReadADC(listTemp);
					ADC2L = listTemp[0];
					ADC2H = listTemp[1];
					transmission(CMD_ADC2, ADC2L, ADC2H);
					sbiBF(PORTD,2);
					cbiBF(PORTD,3);
					sbiBF(PORTD,4);
					break;

				case CMD_ADC3 : // Envoie les informations du troisième convertisseur ADC
					StartADC(2);
					ReadADC(listTemp);
					ADC3L = listTemp[0];
					ADC3H = listTemp[1];
					transmission(CMD_ADC3, ADC3L, ADC3H);
					cbiBF(PORTD,2);
					sbiBF(PORTD,3);
					sbiBF(PORTD,4);
					break;

				case CMD_ADC4 : // Envoie les informations du quatrième convertisseur ADC
					StartADC(3);
					ReadADC(listTemp);
					ADC4L = listTemp[0];
					ADC4H = listTemp[1];
					transmission(CMD_ADC4, ADC4L, ADC4H);
					sbiBF(PORTD,2);
					sbiBF(PORTD,3);
					sbiBF(PORTD,4);
					break;

				case CMD_SENS_0_POSITIF :
					Sens_0 = 1 ;
					transmission(CMD_SENS_0_POSITIF,Conf_sens0p, 0x00 );
					break;

				case CMD_SENS_0_NEGATIF :
					Sens_0 = 0 ;
					transmission(CMD_SENS_0_NEGATIF,Conf_sens0n, 0x00 );
					break;

				case CMD_SENS_1_POSITIF :
					Sens_1 = 1 ;
					transmission(CMD_SENS_1_POSITIF,Conf_sens1p, 0x00 );
					break;

				case CMD_SENS_1_NEGATIF :
					Sens_1 = 0 ;
					transmission(CMD_SENS_1_NEGATIF, Conf_sens1n, 0x00 );
					break;

				default :
					asm("nop");
			}

			for(decalage=0;decalage<=4;decalage++) // Décale les demandes pour supprimer la première et passer au traitement de la demande suivante
			{
				data[decalage]=data[decalage+1];	
			}
			data[4] = 0x00 ;
		}
		else
		{
			asm("nop");
		}
	}
	return 0;	
}
示例#9
0
int main(void)
{
    /* Configure the oscillator both devices */
    
    ConfigureOscillator();
    
    /* Initialize IO ports and peripherals for both devices */
   
    InitGPIO(); 
    InitUART();
    InitI2c();
    InitI2cCompass();
  
    /* Program for the bracelet */
    
#ifdef PROTECTED
    
    /* Initialize IO ports and peripherals */

      InitTimerUS();
 
    /* The values of the magnetic field will be save in x and y */
    s16 x = 0;
    s16 y = 0;   
    
    while(1)
    {
       I2cReadData(&x, &y);
       ComputeAngle(&angle, x, y);
       PutData16(angle);
       __delay_ms(500);
    }
    
#endif
    
    /* Program for the bodyguard*/
    
#ifdef BODY_GUARD
    

    /* Initialize IO ports and peripherals */
    InitADC();
    InitPWM();
    InitLcd();
    InitTimerServo();
    
    /* TODO <INSERT USER APPLICATION CODE HERE> */
    
    u16 ADC_values[NMB_SENSORS];
    u16 average[NMB_SENSORS];
    u8 i;
    u8 j;
    
    /* The values of the magnetic field will be save in x and y */
    s16 x = 0;
    s16 y = 0;
    
    u16 angle2=0;
    
    char T[5];
    
    
    memset(ADC_values,0x00,sizeof(ADC_values));
    memset(average, 0x00,sizeof(average));

    /*
    for(i=0; i<NMB_SENSORS; i++) 
    {
        ADC_values[i]=0;
    }*/
    LcdClear();
    
#if MAGNETIC_SENSOR    
    while(1)
    {
       I2cReadData(&x, &y);
       angle2=((-atan2(x,y)*180)/3.14)+180;
        /* Computes the angle using the arctan2 which provides an angle
        * between -180° and 180°, then converts the result that is in radian
        * into degree (*180/pi) and in the end add 180° so the angle is between
        * 0° and 360° */
       //LcdPutFloat(angle2,0);
       LcdPutFloat(angle2,0);
       LcdGoto(1,2);
       LcdPutFloat(angle,0);
       __delay_ms(500);
       LcdClear();
        
    }
#endif

#ifdef BODY_GUARD_MODE
   while(1)
    { 
        
        for(j=0; j<NMB_MEASURES; j++)
        {
            /* SENSORS SAMPLING */
            for(i=0; i<NMB_SENSORS; i++)
            {
                StartADC(ADC_values);
            }
            ObjectDetection(ADC_values, average);
        }
        LcdClear();
        
        LcdPutFloat(CCP2RB, 0);
       
        //__delay_ms(1000);
        
        LcdClear();
        
        /* Set Flags */       
        ObjectReaction(average);        
        DistanceFlag(average[US]);
        
        /* react */
        
        AutoBodyGuard();

    }
#endif
               
#ifdef AUTO_FLEE
    while(1)
    { 
        
        for(j=0; j<NMB_MEASURES; j++)
        {
            /* SENSORS SAMPLING */
            for(i=0; i<NMB_SENSORS; i++)
            {
                StartADC(ADC_values);
            }
            ObjectDetection(ADC_values, average);
        }
        LcdClear();
        
        /* Set Flags */       
        ObjectReaction(average);        
        //DistanceFlag(average[US]);
        AutoFLee();

    }
    
#endif
#endif
    return 0;
}
示例#10
0
/*********************************************************************
*
*       MainTask
*
**********************************************************************
*/
void MainTask(void) 
{ 
    GUI_Init();
    WM_SetCreateFlags(WM_CF_MEMDEV);  /* Use memory devices on all windows to avoid flicker */
	WM_EnableMemdev(WM_HBKWIN);
	WM_SetCallback(WM_HBKWIN, &_cbBkWin);


	GUI_SetBkColor(GUI_BLUE);
	GUI_SetFont(&GUI_Font16B_1);
	GUI_Clear();


    ahButton[0] = BUTTON_Create(318-52,152,75-21, 20, GUI_ID_ADC,  BUTTON_CF_SHOW );
	BUTTON_SetTextColor(ahButton[0],BUTTON_CI_UNPRESSED,GUI_GREEN);
    BUTTON_SetFont(ahButton[0],&GUI_Font16B_1);
	BUTTON_SetText(ahButton[0],"Inc");
		
	ahButton[1] = BUTTON_Create(318-52,174,75-21, 20,  GUI_ID_DAC,  BUTTON_CF_SHOW );
	BUTTON_SetTextColor(ahButton[1],BUTTON_CI_UNPRESSED,GUI_GREEN);
    BUTTON_SetFont(ahButton[1],&GUI_Font16B_1);
	BUTTON_SetText(ahButton[1],"Dec");

	ahButton[2] = BUTTON_Create(318-52,196,75-21, 20,  GUI_ID_FFT,  BUTTON_CF_SHOW );
	BUTTON_SetTextColor(ahButton[2],BUTTON_CI_UNPRESSED,GUI_GREEN);
    BUTTON_SetFont(ahButton[2],&GUI_Font16B_1);
	BUTTON_SetText(ahButton[2],"Switch");

	ahButton[3] = BUTTON_Create(318-52,218,75-21, 20,  GUI_ID_Spectrum, BUTTON_CF_SHOW );
	BUTTON_SetTextColor(ahButton[3],BUTTON_CI_UNPRESSED,GUI_GREEN);
    BUTTON_SetFont(ahButton[3],&GUI_Font16B_1);
	BUTTON_SetText(ahButton[3],"Spectr");

	
	ahProgbar[0]=PROGBAR_Create(318-52,2,75-21,20,WM_CF_SHOW);
    PROGBAR_SetBarColor(ahProgbar[0],0,GUI_MAGENTA);
    PROGBAR_SetBarColor(ahProgbar[0],1,GUI_RED);
    PROGBAR_SetFont(ahProgbar[0],&GUI_Font16B_1);
	PROGBAR_SetMinMax(ahProgbar[0],0,100);
	WIDGET_SetEffect(ahProgbar[0], &WIDGET_Effect_3D);

	ahScrollbar[0]=SCROLLBAR_Create(0,11,12,217,0,GUI_ID_OSCLevel,WM_CF_SHOW,SCROLLBAR_CF_VERTICAL);
    SCROLLBAR_SetNumItems(ahScrollbar[0],200);
	SCROLLBAR_SetValue(ahScrollbar[0],100);
	
	DispButton();
	DispChInfo();
	ConfigRefresh=0;
	fRefresh =1;
	while(1)
	{ 
	   if(ConfigRefresh == 0) 
	   { 
		  if (fRefresh)
		  {
			  fRefresh = 0;
			  if(g_DSO.HoldEn == 1)
			{		 
			   DispChInfo();	
			}	 
			  
		  }
		  if (g_DSO.HoldEn == 0)
		  {
		    StopADC();	  			 /* 暂停采样 */			 
	 		DispFrame();
			DispChInfo();
			DispCh1Wave();
			FFT_Convert();
		    StartADC();	  			 /* 开始采样 */
		  }
		  PROGBAR_SetValue(ahProgbar[0],OSCPUUsage);
	   }
		GUI_Delay(50); 			 
	}
}