Пример #1
0
void loop()
{
    static int value = 0;

    Serial.print("Writing value=");
    Serial.println(value);
    analogWrite(analogOutPin, value);

    if (waveState == W_RISING)
    {
	if (++value >= 256)
	{
	    value = 255;
	    waveState = W_FALLING;
	}
    }
    else
    {
	if (--value <= 0)
	{
	    value = 0;
	    waveState = W_RISING;
	    blinkLED();
	}
    }
    delay(100);
}
Пример #2
0
void writeEEPROM(uint8_t b, uint8_t updateProfile)
{
    FLASH_Status status;
    uint32_t i;
    uint8_t chk = 0;
    const uint8_t *p;
    int tries = 0;

    // prepare checksum/version constants
    mcfg.version = EEPROM_CONF_VERSION;
    mcfg.size = sizeof(master_t);
    mcfg.magic_be = 0xBE;
    mcfg.magic_ef = 0xEF;
    mcfg.chk = 0;

    // when updateProfile = true, we copy contents of cfg to global configuration. when false, only profile number is updated, and then that profile is loaded on readEEPROM()
    if (updateProfile) {
        // copy current in-memory profile to stored configuration
        memcpy(&mcfg.profile[mcfg.current_profile], &cfg, sizeof(config_t));
    }

    // recalculate checksum before writing
    for (p = (const uint8_t *)&mcfg; p < ((const uint8_t *)&mcfg + sizeof(master_t)); p++)
        chk ^= *p;
    mcfg.chk = chk;

//taskENTER_CRITICAL();

    // write it
retry:
    FLASH_Unlock();
    FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);

    if (FLASH_ErasePage(FLASH_WRITE_ADDR) == FLASH_COMPLETE) {
        for (i = 0; i < sizeof(master_t); i += 4) {
            status = FLASH_ProgramWord(FLASH_WRITE_ADDR + i, *(uint32_t *) ((char *)&mcfg + i));
            if (status != FLASH_COMPLETE) {
                FLASH_Lock();
                tries++;
                if (tries < 3)
                    goto retry;
                else
                    break;
            }
        }
    }
    FLASH_Lock();

//taskEXIT_CRITICAL();

    // Flash write failed - just die now
    if (tries == 3 || !validEEPROM()) {
        failureMode(10);
    }

    // re-read written data
    readEEPROM();
    if (b)
        blinkLED(15, 20, 1);
}
Пример #3
0
void writeParams(uint8_t b) {
  global_conf.currentSet=0;
  conf.checksum = calculate_sum((uint8_t*)&conf, sizeof(conf));
  eeprom_write_block((const void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  readEEPROM();
  if (b == 1) blinkLED(15,20,1);
}
Пример #4
0
void writeParams(uint8_t b)
{
    FLASH_Status status;
    uint32_t i;
    uint8_t chk = 0;
    const uint8_t *p;

    cfg.version    = EEPROM_CONF_VERSION;
    cfg.size       = sizeof(config_t);
    cfg.magic_be   = 0xBE;
    cfg.magic_ef   = 0xEF;
    cfg.chk        = 0;
    for (p = (const uint8_t *)&cfg; p < ((const uint8_t *)&cfg + sizeof(config_t)); p++) chk ^= *p; // recalculate checksum before writing
    cfg.chk = chk;
    FLASH_Unlock();                                                                       // write it
    FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
  
    for (i = 0; i < FLASH_PAGES_FORCONFIG; i++)                                           // Erase the pages here
    {
        while (FLASH_ErasePage(FLASH_WRITE_ADDR + (i * FLASH_PAGE_SIZE)) != FLASH_COMPLETE);
    }

    for (i = 0; i < sizeof(config_t); i += 4)                                             // Write that config now.
    {
        status = FLASH_ProgramWord(FLASH_WRITE_ADDR + i, *(uint32_t *) ((char *) &cfg + i));
        if (status != FLASH_COMPLETE) break;                                              // TODO: fail
    }
    FLASH_Lock();
    readEEPROM();
    if (b) blinkLED(15, 20, 1);
}
Пример #5
0
void rf01_init(void)
{
	unsigned char i;
	GPIO_InitTypeDef  GPIO_InitStructure;




/* GPIOD Periph clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

/* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
  GPIO_InitStructure.GPIO_Pin = SDI | SCK| CS;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = SDO;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

  set_pin(GPIOB,CS);

	for (i=0; i<11; i++)

		/*** !!!!!!!!!!!!!!!!!!!!!!!!! DELAY ******************/
		delay_ms(10);			// wait until POR done

	rf01_trans(0xC2E0);			// AVR CLK: 10MHz
	rf01_trans(0xC42B);			// Data Filter: internal
	rf01_trans(0xCE88);			// FIFO mode
	rf01_trans(0xC6F7);			// AFC settings: autotuning: -10kHz...+7,5kHz
	rf01_trans(0xE000);			// disable wakeuptimer
	rf01_trans(0xCC00);			// disable low duty cycle


	/* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
	  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13;
	  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	  GPIO_Init(GPIOD, &GPIO_InitStructure);

#if RF01_UseIRQ == 1
		// jeœli obs³uga na przerwaniach
		RF01_status.Rx 	= 0;
		RF01_status.New = 0;
		RFM01Irq_Init();
#endif

	blinkLED();

}
Пример #6
0
static void GYRO_Common(void)
{
    static int16_t previousGyroADC[3] = { 0, 0, 0 };
    static int32_t g[3];
    int axis;

    if (calibratingG > 0) {
        for (axis = 0; axis < 3; axis++) {
            // Reset g[axis] at start of calibration
            if (calibratingG == 1000)
                g[axis] = 0;
            // Sum up 1000 readings
            g[axis] += gyroADC[axis];
            // g[axis] += (1000 - calibratingG) >> 1;
            // Clear global variables for next reading
            gyroADC[axis] = 0;
            gyroZero[axis] = 0;
            if (calibratingG == 1) {
                gyroZero[axis] = g[axis] / 1000;
                blinkLED(10, 15, 1);
            }
        }
        calibratingG--;
    }
    for (axis = 0; axis < 3; axis++) {
        gyroADC[axis] -= gyroZero[axis];
        //anti gyro glitch, limit the variation between two consecutive readings
        gyroADC[axis] = constrain(gyroADC[axis], previousGyroADC[axis] - 800, previousGyroADC[axis] + 800);
        previousGyroADC[axis] = gyroADC[axis];
    }
}
Пример #7
0
void loop(){
  blinkLED(13, 3, 500);
  float* readings = updateValues();
  char* units[] = {"degrees C"};
  broadcastReadings(readings, units); 
  delay(250);
}
Пример #8
0
void writeGlobalSet(uint8_t b) {
  global_conf.checksum = calculate_sum((uint8_t*)&global_conf, sizeof(global_conf));
  eeprom_write_block((const void*)&global_conf, (void*)0, sizeof(global_conf));
  if (b == 1) blinkLED(15,20,1);
  SET_ALARM_BUZZER(ALRM_FAC_CONFIRM, ALRM_LVL_CONFIRM_1);

}
Пример #9
0
/* ==============================================
 main task routine
 ============================================== */
int main(void) {
	pool_memadd((uint32_t) pool, sizeof(pool));

#ifdef DEBUG
	dbg.start();
#endif

	// Simple demo Code (removable)
	CPin led(LED1);

	// TODO: insert setup code here
	CPin blinkLED(UNO_13);
	blinkLED.output(NOT_OPEN);

	// Enter an endless loop
	while (1) {
		// Simple demo Code (removable)
		led = !led;
		sleep(200);

		// Your loop code here
		blinkLED = !blinkLED;
	}
	return 0;
}
Пример #10
0
int readIncoming() {
  int incomingByte = 0;
  int receivedEOT = FALSE;
  while (Serial.available() && !receivedEOT) {
    incomingByte = Serial.read();
    char byteBuf[2] = { incomingByte, 0 };
    switch (incomingByte) {
    case HEADER_START:		// start of header.
      memset(commandBuffer, '\0', MAX_CMD_SIZE);
      receivingCommand = TRUE;
      receivingData = FALSE;
      break;
    case DATA_START:		// start of data.
      memset(dataBuffer, '\0', MAX_DATA_SIZE); 
      receivingCommand = FALSE;
      receivingData = TRUE;
      break;
    case DATA_END:		// end of transmission.
      receivingCommand = FALSE;
      receivingData = FALSE;
      receivedEOT = TRUE;
      blinkLED(10);
      break;
    default:			// receiving content.
      if (receivingCommand) {
	strncat(commandBuffer, byteBuf, MAX_CMD_SIZE);
      }
      else if (receivingData) {
	strncat(dataBuffer, byteBuf, MAX_DATA_SIZE);
      }
    }
  }
  return receivedEOT;
}
Пример #11
0
bool readEEPROM() {
  uint8_t i;
  global_conf.currentSet=0;
  eeprom_read_block((void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  print("Calcul Eprom = %d, Read conf = %d \n\r", calculate_sum((uint8_t*)&conf, sizeof(conf)), conf.checksum);
  if(calculate_sum((uint8_t*)&conf, sizeof(conf)) != conf.checksum) {
	print("Loading Defaults\n\r");
    blinkLED(6,100,3);
    LoadDefaults();                 // force load defaults
    return false;                   // defaults loaded, don't reload constants (EEPROM life saving)
  }
  // 500/128 = 3.90625    3.9062 * 3.9062 = 15.259   1526*100/128 = 1192
  for(i=0;i<5;i++) {
    lookupPitchRollRC[i] = (1526+conf.rcExpo8*(i*i-15))*i*(int32_t)conf.rcRate8/1192;
  }
  for(i=0;i<11;i++) {
    int16_t tmp = 10*i-conf.thrMid8;
    uint8_t y = 1;
    if (tmp>0) y = 100-conf.thrMid8;
    if (tmp<0) y = conf.thrMid8;
    lookupThrottleRC[i] = 10*conf.thrMid8 + tmp*( 100-conf.thrExpo8+(int32_t)conf.thrExpo8*(tmp*tmp)/(y*y) )/10; // [0;1000]
    lookupThrottleRC[i] = conf.minthrottle + (int32_t)(MAXTHROTTLE-conf.minthrottle)* lookupThrottleRC[i]/1000;  // [0;1000] -> [conf.minthrottle;MAXTHROTTLE]
  }
  return true;    // setting is OK
}
Пример #12
0
// ****************
// GYRO common part
// ****************
void GYRO_Common() {
	static int16_t previousGyroADC[3] = { 0, 0, 0 };
	static int32_t g[3];
	uint8_t axis = 0;
#if defined(GYROCALIBRATIONFAILSAFE)
	uint8_t tilt = 0;
#endif

#if defined MMGYRO
	// Moving Average Gyros by Magnetron1
	//---------------------------------------------------
	static int16_t mediaMobileGyroADC[3][MMGYROVECTORLENGTH];
	static int32_t mediaMobileGyroADCSum[3];
	static uint8_t mediaMobileGyroIDX;
	//---------------------------------------------------
#endif

	if (calibratingG > 0) {
		for (axis = 0; axis < 3; axis++) {
			// Reset g[axis] at start of calibration
			if (calibratingG == 512) {
				g[axis] = 0;

#if defined(GYROCALIBRATIONFAILSAFE)
				previousGyroADC[axis] = gyroADC[axis];
			}
			if (calibratingG % 10 == 0) {
				if(abs(gyroADC[axis] - previousGyroADC[axis]) > 8) tilt=1;
				previousGyroADC[axis] = gyroADC[axis];
#endif
			}
			// Sum up 512 readings
			g[axis] += gyroADC[axis];
			// Clear global variables for next reading
			gyroADC[axis] = 0;
			gyroZero[axis] = 0;
			if (calibratingG == 1) {
				gyroZero[axis] = g[axis] >> 9;
#if defined(BUZZER)
				alarmArray[7] = 4;
#else
				blinkLED(10,15,1); //the delay causes to beep the buzzer really long
#endif
			}
		}
#if defined(GYROCALIBRATIONFAILSAFE)
		if(tilt) {
			calibratingG=1000;
			LEDPIN_ON;
		} else {
			calibratingG--;
			LEDPIN_OFF;
		}
		return;
#else
		calibratingG--;
#endif

	}
Пример #13
0
void standbyTimerDone(uint32_t avgInputVolt) {	
	if (avgInputVolt > 768) { // high level means NO bat. loading!  now we can really go to sleep
		// shut down everything
		led_fader_disable();
		DIGIWRITE_L(PORTB, PIN_LED);
        DIGIWRITE_L(PORTB, PIN_AUDIO_TRIGGER);  // stop giving signal to audio playback
		DIGIWRITE_L(PORTB, ACCEL_PIN_X);
		
		// prepare going to sleep
		GIMSK |= (1 << INT0);	// enable external interrupt on PB2
		
		// NOTE: only LOW level will wake the MCU up again!
		// this does not work somehow:
//		MCUCR |= (1 << ISC01) | (1 << ISC00);	// The rising edge of INT0 generates an interrupt request.
//		MCUCR |= (1 << ISC00);	// Any logical change on INT0 generates an interrupt request.
//		wdt_disable();
				
		// go to sleep
		sleep_enable();
		sei();
		sleep_bod_disable();
        sleep_cpu();
        
		// woken up!
		cli();
        sleep_disable();
		
		GIMSK &= ~(1 << INT0);	// disable external interrupt on PB2
		
		// test LEDs. 2 times blinking means "woken up"
		blinkLED(&PORTB, PIN_LED, 50);
		long_delay_ms(50);
		blinkLED(&PORTB, PIN_LED, 50);

		// start LED fading again
		startLEDDefaultMode();
		shakeEnded();		// reset states
		
		// wake up watch dog
//		wdt_enable(WTD_TIME);
	} else {
		standby_timer_reset();		// try it again
	}
	
	// standby_timer_enable();
}
Пример #14
0
void writeGlobalSet(uint8_t b) {
  global_conf.checksum = calculate_sum((uint8_t*)&global_conf, sizeof(global_conf));
  eeprom_write_block((const void*)&global_conf, (void*)0, sizeof(global_conf));
  if (b == 1) blinkLED(15,20,1);
  #if defined(BUZZER)
    alarmArray[7] = 1; 
  #endif

}
void setup(){
	PCON |=0x80;		//Achiving 19200 boud rate by doubling 9600
	TMOD |=0x20;		//Timer 1() 8-BIT auto-relod
	TH1=0xFD;		//9600 baud rate
	SCON=0x50;
	TR1=1;			//Start Timer1
	IE |=0x90;		//Enable Serial Interrupt,External Interrupt0
	blinkLED();
}
Пример #16
0
//Erase NRF and blink every 50ms in the process
static void nrf_Emergency_Erase(){
    //make sure SWD is initialized
    if (!swd_init_debug()) {
		return;
	}
    
    blinkLED();    
    
    //Set NVMC->CONFIG on NRF to 2    
    if (!swd_write_ap(AP_TAR, 0x4001E000 + 0x504)) {
		return;
	}
    if (!swd_write_ap(AP_DRW, 2)) {
		return;
	}

    blinkLED();
    blinkLED();
   

    //Set NVMC->ERASEALL on NRF to 1 to start chip erase
    if (!swd_write_ap(AP_TAR, 0x4001E000 + 0x50C)) {
		return;
	}
    if (!swd_write_ap(AP_DRW, 1)) {
		return;
	}
    
    blinkLED();
    blinkLED();
    blinkLED();
    blinkLED();
    
    //Set NVMC->CONFIG on NRF to 0
    if (!swd_write_ap(AP_TAR, 0x4001E000 + 0x504)) {
		return;
	}
    if (!swd_write_ap(AP_DRW, 0)) {
		return;
	}
    
    blinkLED();
    blinkLED();

	//swd_set_target_state(RESET_PROGRAM);
	//target_flash_init(SystemCoreClock);
	//target_flash_program_page(0,(uint8_t *)nrfBlinkyApp,800);

}
Пример #17
0
int main(int argc, char *argv[]) {

  if( argc != 2 ) {
    printf("Usage: open [PIN_NUMBER]");
    return -1;
  }
  int pin = atoi(argv[1]);
  blinkLED(pin, ALLOW_TIME);
  return 0;
}
Пример #18
0
void readPLog(void) {
  eeprom_read_block((void*)&plog, (void*)(E2END - 4 - sizeof(plog)), sizeof(plog));
  if(calculate_sum((uint8_t*)&plog, sizeof(plog)) != plog.checksum) {
    blinkLED(9,100,3);
    SET_ALARM_BUZZER(ALRM_FAC_CONFIRM, ALRM_LVL_CONFIRM_ELSE);
    // force load defaults
    plog.arm = plog.disarm = plog.start = plog.failsafe = plog.i2c = 0;
    plog.running = 1;
    plog.lifetime = plog.armed_time = 0;
    writePLog();
  }
}
Пример #19
0
static void mwArm(void)
{
    if (calibratingG == 0 && f.ACC_CALIBRATED) {
        // TODO: feature(FEATURE_FAILSAFE) && failsafeCnt < 2
        // TODO: && ( !feature || ( feature && ( failsafecnt > 2) )
        if (!f.ARMED) {         // arm now!
            f.ARMED = 1;
            headFreeModeHold = heading;
        }
    } else if (!f.ARMED) {
        blinkLED(2, 255, 1);
    }
}
Пример #20
0
void writeParams(uint8_t b) {
  #ifdef MULTIPLE_CONFIGURATION_PROFILES
    if(global_conf.currentSet>2) global_conf.currentSet=0;
  #else
    global_conf.currentSet=0;
  #endif
  conf.checksum = calculate_sum((uint8_t*)&conf, sizeof(conf));
  eeprom_write_block((const void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  readEEPROM();
  if (b == 1) blinkLED(15,20,1);
  #if defined(BUZZER)
    alarmArray[7] = 1; //beep if loaded from gui or android
  #endif
}
Пример #21
0
void readPLog(void) {
  eeprom_read_block((void*)&plog, (void*)(E2END - 4 - sizeof(plog)), sizeof(plog));
  if(calculate_sum((uint8_t*)&plog, sizeof(plog)) != plog.checksum) {
    blinkLED(9,100,3);
    #if defined(BUZZER)
      alarmArray[7] = 3;
    #endif
    // force load defaults
    plog.arm = plog.disarm = plog.start = plog.failsafe = plog.i2c = 0;
    plog.running = 1;
    plog.lifetime = plog.armed_time = 0;
    writePLog();
  }
}
Пример #22
0
bool readEEPROM() {
  uint8_t i;
  #ifdef MULTIPLE_CONFIGURATION_PROFILES
    if(global_conf.currentSet>2) global_conf.currentSet=0;
  #else
    global_conf.currentSet=0;
  #endif
  eeprom_read_block((void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  if(calculate_sum((uint8_t*)&conf, sizeof(conf)) != conf.checksum) {
    blinkLED(6,100,3);    
    #if defined(BUZZER)
      alarmArray[7] = 3;
    #endif
    LoadDefaults();                 // force load defaults 
    return false;                   // defaults loaded, don't reload constants (EEPROM life saving)
  }
  
  // 500/128 = 3.90625    3.9062 * 3.9062 = 15.259   1526*100/128 = 1192
    conf.rcExpo8 = 0;
    conf.rcRate8 = PITCH_ROLL_RC_RATE_AIR;

  for(i=0;i<5;i++) {
    lookupPitchRollRC[i] = (1526+conf.rcExpo8*(i*i-15))*i*(int32_t)conf.rcRate8/1192;
  }
  
  for(i=0;i<11;i++) {
    //conf.thrExpo8 = 0;
    //conf.thrMid8 = 0;
    int16_t tmp = 10*i-conf.thrMid8;
    uint8_t y = 1;
    if (tmp>0) y = 100-conf.thrMid8;
    if (tmp<0) y = conf.thrMid8;
    lookupThrottleRC[i] = 10*conf.thrMid8 + tmp*( 100-conf.thrExpo8+(int32_t)conf.thrExpo8*(tmp*tmp)/(y*y) )/10; // [0;1000]
    //lookupThrottleRC[i] = conf.minthrottle + (int32_t)(MAXTHROTTLE - conf.minthrottle)* lookupThrottleRC[i]/1000;  // [0;1000] -> [conf.minthrottle;MAXTHROTTLE]
    lookupThrottleRC[i] = conf.minthrottle + (int32_t)(maxThrottle-conf.minthrottle)* lookupThrottleRC[i]/1000;  // [0;1000] -> [conf.minthrottle;MAXTHROTTLE]
  }

  #if defined(POWERMETER)
    pAlarm = (uint32_t) conf.powerTrigger1 * (uint32_t) PLEVELSCALE * (uint32_t) PLEVELDIV; // need to cast before multiplying
  #endif
  #if GPS
    GPS_set_pids();    // at this time we don't have info about GPS init done
  #endif
  #if defined(ARMEDTIMEWARNING)
    ArmedTimeWarningMicroSeconds = (conf.armedtimewarning *1000000);
  #endif
  return true;    // setting is OK
}
Пример #23
0
void setup()
{
    Serial.begin(115200);
    Serial.println("started!");
    strip1.begin();
    strip1.show();
    blinkLED(4, 250);
    
    initMPU();
    
    RGB.control(true);
    RGB.color(0, 0, 0);
    logger.begin();
    
    Spark.function("setskipvalues", setSkipValues);
    Spark.function("setaccllimit", setAccelLimit);
}
void loop(){
  wdt_reset();
  
  blinkLED();
  displayVoltages();
  displayVoltages2();
  displayRelaysState();
  displayUptime();
 
  if (millis() % tempo == 0)
    controlCharging();
    
  securityCheck();
  
  delay(1000/HZ);
  
  //die();
}
Пример #25
0
void writeParams(uint8_t b) {
  #ifdef MULTIPLE_CONFIGURATION_PROFILES
    if(global_conf.currentSet>2) global_conf.currentSet=0;
  #else
    global_conf.currentSet=0;
  #endif
  conf.checksum = calculate_sum((uint8_t*)&conf, sizeof(conf));
  eeprom_write_block((const void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));

#if GPS
  writeGPSconf();  //Write GPS parameters
  recallGPSconf(); //Read it to ensure correct eeprom content
#endif

  readEEPROM();
  if (b == 1) blinkLED(15,20,1);
  SET_ALARM_BUZZER(ALRM_FAC_CONFIRM, ALRM_LVL_CONFIRM_1);
}
Пример #26
0
int main()
{
	const uint32_t sourceVar=0;
	uint32_t bufferSize;
	bufferSize=(&_ebss - &_sbss);
	initGPIO();
	DMA_memcpy(&sourceVar,&_sbss,bufferSize);
	globalVar1=globalVar2+globalVar3;
	globalVar4=globalVar3+globalVar1;
	if( DMA_GetFlagStatus( DMA1_FLAG_TC6) == SET)
	{
	    blinkLED();
	}
	while(1)
	{

	}
	return 0;
}
Пример #27
0
// this routine sets the SPI bus clock freq
// CPU_FREQ is defined in avr.h 
// spifreq is in KHz
int SPI_adjustSpeed(int spifreq)
{
  int clkdiv;
  
  clkdiv = (int)((long)CPU_FREQ / ((long)spifreq*1000));
  switch(clkdiv) {
    case 2:
      SPCR = (1<<SPE) | (1<<MSTR) | (0 << SPR1) | (0 << SPR0);
      SPSR = 1;
      break;
    case 4:
      SPCR = (1<<SPE) | (1<<MSTR) | (0 << SPR1) | (0 << SPR0);
      SPSR = 0;
      break;
    case 8:
      SPCR = (1<<SPE) | (1<<MSTR) | (0 << SPR1) | (1 << SPR0);
      SPSR = 1;
      break;
    case 16:
      SPCR = (1<<SPE) | (1<<MSTR) | (0 << SPR1) | (1 << SPR0);
      SPSR = 0;
      break;
    case 32:
      SPCR = (1<<SPE) | (1<<MSTR) | (1 << SPR1) | (0 << SPR0);
      SPSR = 1;
      break;
    case 64:
      SPCR = (1<<SPE) | (1<<MSTR) | (1 << SPR1) | (0 << SPR0);
      SPSR = 0;
      break;
    case 128:
      SPCR = (1<<SPE) | (1<<MSTR) | (1 << SPR1) | (1 << SPR0);
      SPSR = 0;
      break;
    default:
      blinkLED(10);
      SPCR = (1<<SPE) | (1<<MSTR) | (0 << SPR1) | (1 << SPR0);
      SPSR = 0;
      break;
  }  
  return(clkdiv);
}
Пример #28
0
void loop() 
{

  buttonSense(); //check to see if the button is pressed
  blinkLED(); //blink the LEDs to a predetermined pattern
  delay(1000); //pause for 1 second

  readADCvalue = analogRead(138); //get the raw ADC data. Must use "pin" 138 due to backend coding located in pins_energia.h
  
  //below formulas were taken from the MSP430 user guide for calibrating internal temp sensor
  cal_1 = t85 - t30;
  cal_2 = 85-30;
  cal_3 = cal_1 / cal_2;
  cal_4 = readADCvalue - t30;
  cal_5 = cal_3 * cal_4;
  cal_6 = cal_5 + 30; //final temp result in degC
    
  displayTemp(cal_6, mode); //pass temp info and mode info to be displayed on LEDs
  delay(1000); //pause for 1 second
  
}
Пример #29
0
static void GYRO_Common(void)
{
    int axis;
    static int32_t g[3];
    static stdev_t var[3];

    if (calibratingG > 0) {
        for (axis = 0; axis < 3; axis++) {
            // Reset g[axis] at start of calibration
            if (calibratingG == CALIBRATING_GYRO_CYCLES) {
                g[axis] = 0;
                devClear(&var[axis]);
            }
            // Sum up 1000 readings
            g[axis] += gyroADC[axis];
            devPush(&var[axis], gyroADC[axis]);
            // Clear global variables for next reading
            gyroADC[axis] = 0;
            gyroZero[axis] = 0;
            if (calibratingG == 1) {
                float dev = devStandardDeviation(&var[axis]);
                // check deviation and startover if idiot was moving the model
                if (mcfg.moron_threshold && dev > mcfg.moron_threshold) {
                    calibratingG = CALIBRATING_GYRO_CYCLES;
                    devClear(&var[0]);
                    devClear(&var[1]);
                    devClear(&var[2]);
                    g[0] = g[1] = g[2] = 0;
                    continue;
                }
                //gyroZero[axis] = (g[axis] + (CALIBRATING_GYRO_CYCLES / 2)) / CALIBRATING_GYRO_CYCLES;
                gyroZero[axis] = (g[axis]+1) / CALIBRATING_GYRO_CYCLES;
                blinkLED(10, 15, 1);
            }
        }
        calibratingG--;
    }
    for (axis = 0; axis < 3; axis++)
        gyroADC[axis] -= gyroZero[axis];
}
Пример #30
0
bool readEEPROM() {
  uint8_t i;
  int8_t tmp;
  uint8_t y;

  #ifdef MULTIPLE_CONFIGURATION_PROFILES
    if(global_conf.currentSet>2) global_conf.currentSet=0;
  #else
    global_conf.currentSet=0;
  #endif
  eeprom_read_block((void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  if(calculate_sum((uint8_t*)&conf, sizeof(conf)) != conf.checksum) {
    blinkLED(6,100,3);    
    SET_ALARM_BUZZER(ALRM_FAC_CONFIRM, ALRM_LVL_CONFIRM_ELSE);
    LoadDefaults();                 // force load defaults 
    return false;                   // defaults loaded, don't reload constants (EEPROM life saving)
  }
  // 500/128 = 3.90625    3.9062 * 3.9062 = 15.259   1526*100/128 = 1192
  for(i=0;i<5;i++) {
    lookupPitchRollRC[i] = (1526+conf.rcExpo8*(i*i-15))*i*(int32_t)conf.rcRate8/1192;
  }
  for(i=0;i<11;i++) {
    tmp = 10*i-conf.thrMid8;
    y = conf.thrMid8;
    if (tmp>0) y = 100-y;
    lookupThrottleRC[i] = 100*conf.thrMid8 + tmp*( (int32_t)conf.thrExpo8*(tmp*tmp)/((uint16_t)y*y)+100-conf.thrExpo8 );       // [0;10000]
    lookupThrottleRC[i] = conf.minthrottle + (uint32_t)((uint16_t)(MAXTHROTTLE-conf.minthrottle))* lookupThrottleRC[i]/10000;  // [0;10000] -> [conf.minthrottle;MAXTHROTTLE]
  }
  #if defined(POWERMETER)
    pAlarm = (uint32_t) conf.powerTrigger1 * (uint32_t) PLEVELSCALE * (uint32_t) PLEVELDIV; // need to cast before multiplying
  #endif
  #if GPS
    GPS_set_pids();    // at this time we don't have info about GPS init done
    recallGPSconf();   // Load gps parameters
  #endif
  #if defined(ARMEDTIMEWARNING)
    ArmedTimeWarningMicroSeconds = (conf.armedtimewarning *1000000);
  #endif
  return true;    // setting is OK
}