Esempio n. 1
0
void get_ready(void)
{
	menu_init();
#if DEBUG	
	uart_puts_p(PSTR("menu_init() Completed! \n"));
#endif

	LED_on(LED_0);
	LED_on(LED_1);
	LED_on(LED_2);
	LED_on(LED_3);
	
	set_screen(SPLASH_SCN);
	_delay_ms(2000);
	
	gps_set_arg();
	
	LED_off(LED_0);
	LED_off(LED_1);
	LED_off(LED_2);
	LED_off(LED_3);
	
	set_screen(READY_SCN);
	menu_start();	
}
Esempio n. 2
0
/*..........................................................................*/
QState Bomb_timing(Bomb *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            QActive_arm((QActive *)me, BSP_TICKS_PER_SEC/4);
            return Q_HANDLED();
        }
        case Q_TIMEOUT_SIG: {
            QActive_arm((QActive *)me, BSP_TICKS_PER_SEC/4);
            if (me->ctr > (uint8_t)0) {
                if ((me->ctr & 0x01) != 0) {
                    LED_on();
                }
                else {
                    LED_off();
                }
                --me->ctr;
            }
            else {                                       /* timeout expired */
                return Q_TRAN(&Bomb_blast);
            }
            return Q_HANDLED();
        }
    }
    return Q_IGNORED();
}
Esempio n. 3
0
static void FA_NOINLINE( Flash_LED_12MS ) ( void )
{
    LED_on() ;
    Delay_1024( T0DEL4MS ) ;
    LED_off() ;
    Delay_1024( T0DEL8MS ) ;
}
Esempio n. 4
0
uint8_t rf_dngl_recv(__xdata void* buff, uint8_t buff_size)
{
	uint8_t ret_val = 0;
	
	// check if there's data in the RX FIFO
	nRF_ReadReg(FIFO_STATUS);
	if ((nRF_data[1] & vRX_EMPTY) == 0)
	{
		LED_on();
		
		// read the payload
		nRF_ReadRxPayloadWidth();
		ret_val = nRF_data[1];

		// the nRF specs state I have to drop the packet if the length is > 32
		if (ret_val > 32)
		{
			nRF_FlushRX();
			ret_val = 0;
		} else {
			nRF_ReadRxPayload(ret_val);
			memcpy_X(buff, nRF_data + 1, ret_val > buff_size ? buff_size : ret_val);
		}

		// reset the TX_DS
		if (nRF_data[0] & vTX_DS)
			nRF_WriteReg(STATUS, vTX_DS);

		LED_off();
	}
	
	return ret_val;
}
Esempio n. 5
0
void enableProgramMode( ) {
	// drive reset high initially to stop flickering
	drivePin( B, AVRISP_PIN_RESET, high );
	output_init( B, AVRISP_PIN_RESET );
	
	// initialize SPI
	spiMaster_init( spiMaster_clockDiv64 );
	
	// sink device into reset state
	delay_ms( 50 );
	drivePin( B, AVRISP_PIN_RESET, low );
	
	// enter prog mode (manually to check)
	spiMaster_transmit( 0xAC );
	spiMaster_transmit( 0x53 );
	spiMaster_transmit( 0x00 );
	ubyte verify = spiMaster_receive( );
	spiMaster_transmit( 0x00 );
	if ( verify != 0x53 ) {
		statusLed_red( );
		uart_putc( AVRISP_RESP_UNKNOWN );
		return;
	}
	
	LED_on( );
	
	uart_putc( BYTE_CR ); // done!
}
Esempio n. 6
0
static void led_display(){
	alt_16 switch_value = 0;
	int i = 0;
	switch_value = ReadSwitches();
	_Bool press_flag = true;
	edge_capture = 0;
	init_button_pio();
	while(1 == 1){
		if(edge_capture && press_flag){
			press_flag = false;
			edge_capture = 0;
			switch_value = ReadSwitches();
			/*displaying switches' value to LED or seven-segment*/
			for(i = 0; i < 8; i ++){
				if (edge_capture && !press_flag){//get interruption from button release
					edge_capture = 0;
					press_flag = true;
				}else if(edge_capture)//get interruption from reseting the switches
					break;
				/*If the next bit is 1 then turn on the led*/
				if (switch_value & 1)
					LED_on();
				else
				/*If the next bit is 0 then turn off the led*/
					LED_off();
				switch_value >>=  1;
			}
			LED_off();
		}else if(edge_capture){//get interruption from button release
Esempio n. 7
0
void LCD_task(void)
{
	if(gps_avlb)
	{
		if(gps_msg_ready)
		{
			gps_msg_ready++;
#if DEBUG				
			print_gps_msg();
#endif
			//if(1)
			if(gps_state == 'A')
			{
				if(timer1_flag)
				{
					timer1_flag++;
					switch_scn_flag(0);
				}
					
				set_screen(GPS_MAIN_SCN);
			}
			else
			{
				LED_on(LED_3);
				set_screen(GPS_UPDATE_SCN);
			}
		}
	}
}
Esempio n. 8
0
int main(void)
{
	char ch;
	serial_init(51);
	LED_init();
	
	while(1)
	{
		//print messages on the screen
		printf("Press 1 to turn LED on. \r");
		printf("Press 0 to turn LED off. \r\r");
		//get the input char from keyboard
		ch = serial_getchar();
		
		switch(ch)
		{
			case '0':
				//turn off LED
				printf("LED off!\r");
				LED_off();
				break;
			case '1':
				//turn on LED
				printf("LED on!\r");
				LED_on();
				break;
			default:
				printf("Wrong key!\r");
				break;
		}
	}
}
Esempio n. 9
0
/*----------------------------------------------------------------------------
  Thread 1 'phaseA': Phase A output
 *---------------------------------------------------------------------------*/
void phaseA (void const *argument) {
  for (;;) {
    osSignalWait(0x0001, osWaitForever);    /* wait for an event flag 0x0001 */
    LED_on (LED_A);
    signal_func (tid_phaseB);               /* call common signal function   */
    LED_off(LED_A);
  }
}
Esempio n. 10
0
/*----------------------------------------------------------------------------
 * switch LED on
 *---------------------------------------------------------------------------*/
void LED_On  (unsigned char led) {
  LED_on (led);
  os_mut_wait(mut_GLCD, 0xffff);
  GLCD_SetBackColor(White);                         /* Set the Back Color */
  GLCD_SetTextColor(Green);                         /* Set the Text Color */
  GLCD_DisplayChar(4, 5+led, 1, 0x80+1);            /* Circle Full        */
  os_mut_release(mut_GLCD);
}
Esempio n. 11
0
/*----------------------------------------------------------------------------
  Thread 5 'clock': Signal Clock
 *---------------------------------------------------------------------------*/
void clock (void const *argument) {
  for (;;) {
    osSignalWait(0x0100, osWaitForever);    /* wait for an event flag 0x0100 */
    LED_on (LED_CLK);
    osDelay(80);                            /* delay 80ms                    */
    LED_off(LED_CLK);
  }
}
Esempio n. 12
0
void blink_LED(int n){
	int i;
	for(i=0;i<n;i++){
		LED_on();
		_delay_ms(500);
		LED_off();
		_delay_ms(500);
	}
}
Esempio n. 13
0
/** Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed.
 *
 *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface configuration structure being referenced
 */
bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
{
	bool CommandSuccess;

	LED_off();
	CommandSuccess = SCSI_DecodeSCSICommand(MSInterfaceInfo);
	LED_on();

	return CommandSuccess;
}
Esempio n. 14
0
// This routine is called once to allow you to set up any other variables in your
//program
// You can use 'clock' function here.
// The loopStart parameter has the current clock value in ìS
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){

    LED_off(&RightRed); 
    LED_off(&LeftRed); 
    LED_off(&SpotLightWhite); 
    LED_on(&PowerGreen);

    sonyPS2_setAnalogMode(&controller1);
    sonyPS2_calibrate(&controller1, 25);

return 0; // dont pause after
}
Esempio n. 15
0
int main(void) {
	uint16_t status;

	WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
	LED_init();
	LED_on();
    /* configure the Basic Clock Module */
    DCOCTL = CALDCO_1MHZ;
    BCSCTL1 = CALBC1_1MHZ;

    BCSCTL2 = SELM_3 + DIVM_0;//MCLK = LFXTCLK/1
#ifdef NECESSARY
    do {
    	int i;
        IFG1 &= ~OFIFG;                           // Clear OSCFault flag
        for (i = 0xFF; i > 0; i--);               // Time for flag to set
    } while ((IFG1 & OFIFG)); // OSCFault flag still set?
#endif
    TACTL = TASSEL_2 | MC_1; /* SMCLK, upmode */
    TACCR0 = TIMER_CLK_HZ/SYSTICK_HZ;
	TACCTL0 = CCIE; /*Enable timer A0 interrupt*/

	//Enable SCLK, SDI, SDO, master
	USICTL0 |= USIPE7 | USIPE6 | USIPE5 | USIMST | USIOE;
	USICKCTL |= USIDIV_0 //this actually means divide by 1
			  | USISSEL_2//Use SMCLK to drive the SPI clk
			  //| USICKPL
			  ;
	USICTL1 |= USICKPH;//delay?
	//USICTL1 |= USIIE;//interrupt enable
	//		;
	P1OUT = BIT4;//Pull up nCS at first
	P1DIR |= BIT4;//nCS is P1.4
	//P1REN |= 0x10;?

	_enable_interrupts();//vs. _BIS_SR(LPM0_bits + GIE);
	LED_off();

	dSPIN_Soft_Stop();
	dSPIN_Reset_Device();

	status = dSPIN_Get_Status();
   	if(status & dSPIN_STATUS_SW_EVN
   		|| (status & dSPIN_STATUS_MOT_STATUS) != dSPIN_STATUS_MOT_STATUS_STOPPED
   		|| status & dSPIN_STATUS_NOTPERF_CMD
   		|| status & dSPIN_STATUS_WRONG_CMD
   		// !(status & dSPIN_STATUS_UVLO)
   		|| !(status & dSPIN_STATUS_TH_SD)
   		|| !(status & dSPIN_STATUS_OCD))
		Q_ERROR();
    if(dSPIN_Busy_HW()) Q_ERROR();
    return 0;
}
Esempio n. 16
0
/*..........................................................................*/
QState Bomb_blast(Bomb *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            QActive_arm((QActive *)me, 2 * BSP_TICKS_PER_SEC);
            LED_on();
            return Q_HANDLED();
        }
        case Q_TIMEOUT_SIG: {
            return Q_TRAN(&Bomb_off);
        }
    }
    return Q_IGNORED();
}
Esempio n. 17
0
File: main.c Progetto: Ntkrell/brain
// kill function for field debug.  flash n times forever
void kill(int n) {

    int i;
    while (1) {
        for (i = 0; i < n; i++) {
            LED_on();
            _delay_ms(100);

            LED_off();
            _delay_ms(200);
        }
        _delay_ms(2000);
    }
}
Esempio n. 18
0
/** Event handler for the library USB Configuration Changed event. */
void EVENT_USB_Device_ConfigurationChanged(void)
{
	bool ConfigSuccess = true;

	ConfigSuccess &= MS_Device_ConfigureEndpoints(&Disk_MS_Interface);

    if (ConfigSuccess)
    {
        LED_on();
    }
    else
    {
        LED_off();
    }
}
Esempio n. 19
0
/**
 * \ingroup sd_raw
 * Send a command to the memory card which responses with a R1 response (and possibly others).
 *
 * \param[in] command The command to send.
 * \param[in] arg The argument for command.
 * \returns The command answer.
 */
uint8_t sd_raw_send_command(uint8_t command, uint32_t arg)
{
  uint8_t response;
  uint8_t n_try = 0;

  do
  {
    n_try++;

    // wait before retrying
    if (n_try > 1)
    {
      delay(50);
      printf("Retry ");
    }
    //printf("C %hd %ld\r\n", command, arg);

    LED_on();

    /* interrupt request */
    irq_high();

    /* send command via SPI */
    sd_raw_send_byte(0x40 | command);
    sd_raw_send_byte((arg >> 24) & 0xff);
    sd_raw_send_byte((arg >> 16) & 0xff);
    sd_raw_send_byte((arg >> 8) & 0xff);
    sd_raw_send_byte((arg >> 0) & 0xff);

    /* receive response */
    response = sd_raw_rec_byte();

    /* finish interrupt request */
    irq_low();

    LED_off();

    // after 255 trials, fail
    if (n_try == 0xff)
    {
      response = R1_FAILURE;
      break;
    }
  }
  while (response == R1_WAIT_RETRY);

  return response;
}
Esempio n. 20
0
int main(void) {
	configure_ports(); 
    a2dInit();  
	a2dSetPrescaler(ADC_PRESCALE_DIV32);  
	a2dSetReference(ADC_REFERENCE_AVCC); 
    
    init_servos();
	LED_on();
    
    neutral();
    hold_pos();
    
    while (1) {
        move_forward();
    //    sustain_pos();
    }
    
	return 0;
}
Esempio n. 21
0
void pulse_led(int8_t speed) {
  // blink D13
  pulse_tick++;
  if (pulse_tick==BOOT_PULSE_MAX) {
    pulse_tick = 0;
    pulse_pwm += pulse_dir * speed;
    if (pulse_pwm > 255) {
      pulse_pwm = 255;
      pulse_dir = -1;
    }
    if (pulse_pwm < 0) {
      pulse_pwm = 0;
      pulse_dir = +1;
    }
    LED_on();
  }
  if (pulse_tick==pulse_pwm) 
    LED_off();
}
Esempio n. 22
0
//enter your code in control here
//photovore is just a default sample program and can be deleted
void control(void)
	{
	//photovore();//run photovore algorithm, or comment out for your own code

	for(int x = 0; x < 10000; x++)
	{
		LED_on();
	}

	for(int x = 0; x < 10000; x++)
	{
		LED_off();
	}






	}
Esempio n. 23
0
/*..........................................................................*/
void BSP_init(void) {
	int i;
    WDTCTL = (WDTPW | WDTHOLD);                               /* Stop WDT */

    //P1DIR = 0; P2DIR = 0; P3DIR = 0; P4DIR = 0; P5DIR = 0;
    P6DIR = 0x20;
    //P1OUT = 0; P2OUT = 0; P3OUT = 0; P4OUT = 0; P5OUT = 0; P6OUT = 0;

    LED_on();//begin startup

    /* configure the Basic Clock Module */
#ifdef CALDCO_8MHZ//feature available on MSP430F2xxxx
    DCOCTL   = CALDCO_8MHZ;                              /* Set DCO to 8MHz */
    BCSCTL1  = CALBC1_8MHZ;
#else
    DCOCTL = 0x7 << 5 //frequency; looks like 8 MHz: the fastest for this chip
    	   + 0x00;// modulation; useless (set to 0) when DCO = 7
    BCSCTL1 = XT2OFF + XTS /* LFXTCLK 0:Low Freq. / 1: High Freq. */
    		+ DIVA_0 /* Auxiliary Clock Divider; ACLK Divider 0: /1 */
    		+ 0x7;//RSEL: the value of the resistor defines the nominal frequency
#endif
    do {
        IFG1 &= ~OFIFG;                           // Clear OSCFault flag
        for (i = 0xFF; i > 0; i--);               // Time for flag to set
    } while ((IFG1 & OFIFG)); // OSCFault flag still set?

    BCSCTL2 = SELM_3 + DIVM_0;//MCLK = LFXTCLK/1
    //Configure timer
    //The up mode is used if the timer period must be different from TBR(max)
    //counts. The timer repeatedly counts up to the value of compare latch
    //TBCL0, which defines the period.
    TBCTL = ID_3 | // DIV_8
    		TASSEL_2 | MC_1;//SMCLK, upmode
    TBCCR0 = TIMER_VAL;
    //TBCCR0 = ((BSP_SMCLK)//divide by 1 since we use ID_0 mode (DIV1)
    //          + BSP_TICKS_PER_SEC/2)
    //       / BSP_TICKS_PER_SEC;

    LED_off();//end startup
}
Esempio n. 24
0
//*****************************************************************************
//
// Print "Hello World!" to the UART on the evaluation board.
//
//*****************************************************************************
int
main(void)
{

	//Configure all the hardware
	HW_Configure();

	//volatile uint32_t ui32Loop;


    UARTprintf("\r\nTimerTest\r\n");

    //
    // We are finished.  Hang around doing nothing.
    //
    while(1)
    {
        LED_on(LED_GREEN);
        SysCtlDelay(SysCtlClockGet() / 10 / 10);
        LED_off(LED_GREEN);
        SysCtlDelay(SysCtlClockGet() / 10 / 1);
        UARTprintf(".");
    }
}
Esempio n. 25
0
void LEDTask( void * Parameters )
{
    uint8_t cycle = 0;
    LED_activity_desc_t new_cfg;
    LED_state_rec_t* pLED;
    uint8_t led_id;
    /* Task will run every 50ms */
    TickType_t xFrequency = 100 / portTICK_PERIOD_MS;
    TickType_t xLastWakeTime;

    /* Initialise the xLastWakeTime variable with the current time. */
    xLastWakeTime = xTaskGetTickCount();

    for (;;) {
        for (led_id = 0; led_id < LED_CNT; led_id++) {
            pLED = &LEDstate[led_id];
            /* Update the led configuration only after perfoming a full cycle on each action */
            if (cycle == 0) {
                if (xQueueReceive( pLED->queue, &new_cfg, 0 ) == pdTRUE) {
                    /* Save the last config */
                    memcpy(&(pLED->last_cfg), &(pLED->cur_cfg), sizeof(LED_activity_desc_t));

                    /* Update the config struct */
                    memcpy(&(pLED->cur_cfg), &new_cfg, sizeof(LED_activity_desc_t));
                    LED_set_state(pLED->pin_cfg, pLED->cur_cfg.initstate);
                    pLED->counter = pLED->cur_cfg.delay_init;
                }
            }

            switch (pLED->cur_cfg.action) {
            case LED_ACTV_ON:
                LED_on(pLED->pin_cfg);
                break;

            case LED_ACTV_OFF:
                LED_off(pLED->pin_cfg);
                break;

            case LED_ACTV_BLINK:
                if (pLED->counter == 0) {
                    if (pLED->cur_cfg.initstate == LED_get_state(pLED->pin_cfg)) {
                        /* LED is in initial state */
                        pLED->counter = pLED->cur_cfg.delay_tog;
                    } else {
                        /* LED is in toggled state */
                        pLED->counter = pLED->cur_cfg.delay_init;
                    }

                    LED_toggle(pLED->pin_cfg);

                    if ( pLED->counter == 0 ) {
                        /* Loaded a zero prescale value--means the activity descriptor is a single-shot descriptor
                         * that has expired--like a lamp test or a pulse.
                         * Revert the LED to the last know state and stay in toggled state until next cycle
                         */
                        pLED->counter = cycle;
                        memcpy(&(pLED->cur_cfg), &(pLED->last_cfg), sizeof(LED_activity_desc_t));
                    }
                } else {
                    (pLED->counter)--;
                }
                break;
            }
        }
        if (cycle == 0) {
            /* Reload the cycle counter */
            cycle = LED_CYCLE_COUNTER;
        } else {
            cycle--;
        }
        vTaskDelayUntil( &xLastWakeTime, xFrequency );
    }

}
Esempio n. 26
0
/**
 *  \brief SAMD21 SAM-BA Main loop.
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
  P_USB_CDC pCdc;
#endif
  DEBUG_PIN_HIGH;

  /* Jump in application if condition is satisfied */
  check_start_application();

  /* We have determined we should stay in the monitor. */

  /* System initialization */
  board_init();
  __enable_irq();

  /* Initialize LEDs */
  LED_init();
  #if !defined(BOARD_LED_FADE_ENABLED)
  LED_on();
  #endif
  LEDRX_init();
  LEDRX_off();
  LEDTX_init();
  LEDTX_off();

  /* Start the sys tick (20 us) */
  SysTick_Config(VARIANT_MCK / 50000);


/* If SDCARD_ENABLED defined, read optional external pins and run SD Card bootloader (if enabled).
 */
  #if defined(SDCARD_ENABLED)
    uint8_t bootloaderMode = SD_BOOTLOADER_MODE_NO_UPDATE;
    #if defined(SAM_BA_INTERFACE_USE_PIN)
      uint8_t sdcardStatus = SD_BOOTLOADER_NOT_CALLED;
    #endif

    #if defined(SDCARD_USE_PIN1)
      pinConfig(SDCARD_PIN1_PORT, SDCARD_PIN1_PIN, SDCARD_PIN1_CONFIG);
    #endif
    #if defined(SDCARD_USE_PIN2)
      #if !defined(SDCARD_USE_PIN1)
        #error "main.c: When SDCARD_USE_PIN2 is defined, SDCARD_USE_PIN1 must also be defined"
      #endif
      pinConfig(SDCARD_PIN2_PORT, SDCARD_PIN2_PIN, SDCARD_PIN2_CONFIG);
    #endif

    #if (defined(SDCARD_USE_PIN1) && defined(SDCARD_USE_PIN2))
      bool pin1 = isPinActive(SDCARD_PIN1_PORT, SDCARD_PIN1_PIN, SDCARD_PIN1_POLARITY);
      bool pin2 = isPinActive(SDCARD_PIN2_PORT, SDCARD_PIN2_PIN, SDCARD_PIN2_POLARITY);
      if (pin1) {
        bootloaderMode = SD_BOOTLOADER_MODE_UPDATE;
      } else if (pin2) {
        bootloaderMode = SD_BOOTLOADER_MODE_UPDATE2;
      }
    #elif defined(SDCARD_USE_PIN1)
      if (isPinActive(SDCARD_PIN1_PORT, SDCARD_PIN1_PIN, SDCARD_PIN1_POLARITY)) {
        bootloaderMode = SD_BOOTLOADER_MODE_UPDATE;
      }
    #else
      bootloaderMode = SD_BOOTLOADER_MODE_UPDATE;
    #endif

    if (bootloaderMode != SD_BOOTLOADER_MODE_NO_UPDATE) {
    #if defined(SAM_BA_INTERFACE_USE_PIN)
      sdcardStatus = sdBootloader(bootloaderMode);
    #else
      sdBootloader(bootloaderMode);
    #endif
    }
  #endif

/* When using SAM_BA_INTERFACE_USE_PIN, check the pin to determine which SAM-BA interface to use.
 */
#if defined(SAM_BA_INTERFACE_USE_PIN)
  uint8_t sambaInterface = SAM_BA_NONE;
  pinConfig(SAM_BA_INTERFACE_PIN_PORT, SAM_BA_INTERFACE_PIN_PIN, SAM_BA_INTERFACE_PIN_CONFIG);

  if (isPinActive(SAM_BA_INTERFACE_PIN_PORT, SAM_BA_INTERFACE_PIN_PIN, PIN_POLARITY_ACTIVE_LOW)) {      // pin is low
  #if ((SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES) && (SAM_BA_INTERFACE_PIN_POLARITY == PIN_POLARITY_USBCDC_LOW))
    sambaInterface = SAM_BA_USBCDC_ONLY;
  #elif ((SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY) && (SAM_BA_INTERFACE_PIN_POLARITY == PIN_POLARITY_ACTIVE_LOW))
    sambaInterface = SAM_BA_USBCDC_ONLY;
  #elif ((SAM_BA_INTERFACE == SAM_BA_UART_ONLY) && (SAM_BA_INTERFACE_PIN_POLARITY == PIN_POLARITY_ACTIVE_LOW))
    sambaInterface = SAM_BA_UART_ONLY;
  #endif
  } else {      // pin is high
  #if ((SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES) && (SAM_BA_INTERFACE_PIN_POLARITY == PIN_POLARITY_USBCDC_HIGH))
    sambaInterface = SAM_BA_USBCDC_ONLY;
  #elif ((SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY) && (SAM_BA_INTERFACE_PIN_POLARITY == PIN_POLARITY_ACTIVE_HIGH))
    sambaInterface = SAM_BA_USBCDC_ONLY;
  #elif ((SAM_BA_INTERFACE == SAM_BA_UART_ONLY) && (SAM_BA_INTERFACE_PIN_POLARITY == PIN_POLARITY_ACTIVE_HIGH))
    sambaInterface = SAM_BA_UART_ONLY;
  #endif
  }
#endif

/* Check if we should continue with a SAM-BA interface (if compiled and enabled).
 * Only show LED_STATUS_FILE_NOT_FOUND if a SAM-BA interface is not available.
 * LED_STATUS_FILE_NOT_FOUND occurs if there is no SD Card, no FAT16/FAT32
 * filesystem, or no file (UPDATE.BIN or UPDATE2.BIN) in the root directory.
 */
#if defined(SAM_BA_INTERFACE_USE_PIN)
  #if defined(SDCARD_ENABLED)
  if (sambaInterface == SAM_BA_NONE) {
    if (sdcardStatus == SD_BOOTLOADER_FILE_NOT_FOUND) {
      LED_status(LED_STATUS_FILE_NOT_FOUND);
    } else if (sdcardStatus == SD_BOOTLOADER_NOT_CALLED) {
      LED_status(LED_STATUS_NO_SAM_BA_INTERFACE);
    }
  }
  #else
    #if (SAM_BA_INTERFACE == SAM_BA_NONE)
      LED_status(LED_STATUS_NO_SAM_BA_INTERFACE);
    #else
    if (sambaInterface == SAM_BA_NONE) {
      LED_status(LED_STATUS_NO_SAM_BA_INTERFACE);
    }
    #endif
  #endif
#else
  #if (SAM_BA_INTERFACE == SAM_BA_NONE)
    LED_status(LED_STATUS_NO_SAM_BA_INTERFACE);
  #endif
#endif

/* Enable the appropriate SAM-BA interfaces. When using SAM_BA_INTERFACE_USE_PIN,
 * the peripheral and pins are only setup for the selected/enabled interface.
 */
#if defined(SAM_BA_INTERFACE_USE_PIN)
  if (sambaInterface == SAM_BA_UART_ONLY) {
#endif

#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
  /* UART is enabled in all cases */
    serial_open();
#endif

#if defined(SAM_BA_INTERFACE_USE_PIN)
  } else if (sambaInterface == SAM_BA_USBCDC_ONLY) {
#endif

#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
    pCdc = usb_init();
#endif

#if defined(SAM_BA_INTERFACE_USE_PIN)
  }
#endif


  ledDirection = 4;
  DEBUG_PIN_LOW;

  /* Wait for a complete enum on usb or a '#' char on serial line */
  while (1)
  {
#if defined(SAM_BA_INTERFACE_USE_PIN)
    if (sambaInterface == SAM_BA_USBCDC_ONLY) {
#endif

#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
    if (pCdc->IsConfigured(pCdc) != 0)
    {
      main_b_cdc_enable = true;
    }

    /* Check if a USB enumeration has succeeded and if comm port has been opened */
    if (main_b_cdc_enable)
    {
      sam_ba_monitor_init(SAM_BA_INTERFACE_USBCDC);
      /* SAM-BA on USB loop */
      while( 1 )
      {
        sam_ba_monitor_run();
      }
    }
#endif

#if defined(SAM_BA_INTERFACE_USE_PIN)
    } else if (sambaInterface == SAM_BA_UART_ONLY) {
#endif

#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
    /* Check if a '#' has been received */
    if (!main_b_cdc_enable && serial_sharp_received())
    {
      sam_ba_monitor_init(SAM_BA_INTERFACE_USART);
      /* SAM-BA on Serial loop */
      while(1)
      {
        sam_ba_monitor_run();
      }
    }
#endif

#if defined(SAM_BA_INTERFACE_USE_PIN)
    }
#endif
  }
}
Esempio n. 27
0
void processCommand( unsigned char cmd ) {
	
	if ( cmd == CMD_SELECT_DEVICE ) {
		selectedDevice = uart_getc( );
		uart_putc( BYTE_CR );
	} else if ( cmd == CMD_SHOW_ID ) {
		uart_puts( AVRISP_IDENTIFIER );
	} else if ( cmd == CMD_SOFTWARE_VERSION ) {
		uart_puts( AVRISP_SWVER );
	} else if ( cmd == CMD_HARDWARE_VERSION ) {
		uart_puts( AVRISP_HWVER );
	} else if ( cmd == CMD_LIST_SUPPORTED_DEVICES ) {
		uart_puts( AVRISP_SUPPORTED_DEVICES );
		uart_putc( 0 ); // terminating null character needs to be sent
	} else if ( cmd == CMD_PROGRAMMER_TYPE ) {
		uart_putc( AVRISP_PROGRAMMER_TYPE );
	} else if ( cmd == CMD_SUPPORTS_AUTOINCREMENT ) {
		uart_putc( AVRISP_RESP_YES );
	} else if ( cmd == CMD_SET_LED ) {
		LED_on( );
		uart_putc( BYTE_CR );
	} else if ( cmd == CMD_CLEAR_LED ) {
		LED_off( );
		uart_putc( BYTE_CR );
	} else if ( selectedDevice == 0 ) {
		// require a device for the rest of the commands
		uart_putc( AVRISP_RESP_UNKNOWN );
		return;
	}
	
	// command not specified above
	
	if ( cmd == CMD_ENTER_PROGRAM_MODE ) {
		enableProgramMode( );
	} else if ( cmd == CMD_LEAVE_PROGRAM_MODE ) {
		leaveProgramMode( );
	} else if ( cmd == CMD_WRITE_PROG_H ) {
		writeProgH( );
	} else if ( cmd == CMD_WRITE_PROG_L ) {
		writeProgL( );
	} else if ( cmd == CMD_READ_PROG ) {
		readProg( );
	} else if ( cmd == CMD_LOAD_ADDRESS ) {
		loadAddress( );
	} else if ( cmd == CMD_WRITE_DATA ) {
		writeData( );
	} else if ( cmd == CMD_READ_DATA ) {
		readData( );
	} else if ( cmd == CMD_CHIP_ERASE ) {
		chipErase( );
	} else if ( cmd == CMD_WRITE_LOCK_BITS ) {
		writeLockBits( );
	} else if ( cmd == CMD_READ_SIGNATURE ) {
		readSignature( );
	} else if ( cmd == CMD_WRITE_PROGRAM_PAGE ) {
		writeProgramPage( );
	} else if ( cmd == CMD_UNIVERSAL_3 ) {
		universalWrite3( );
	} else if ( cmd == CMD_UNIVERSAL_4 ) {
		universalWrite4( );
	} else if ( cmd == CMD_LOAD_ADDRESS_0 ) {
		currentAddress = 0;
		uart_putc( BYTE_CR );
	}
}
Esempio n. 28
0
File: led.c Progetto: jdkaplan/ASTRO
void blink(unsigned int on, unsigned int off) {
  LED_on(on);
  LED_off(off);
}
Esempio n. 29
0
File: main.c Progetto: Ntkrell/brain
int main(void) {

    //set to 1 MHz (prescalar = 8)
    //CLKPR = 0x80;
    //CLKPR = 0x03;

    // set directions and pullups
    // if a pin isn't being used, set to input with pullup for power savings
    // (unless there are external components to worry about)
    // check schematic if you don't understand this!

    // Note: UART, SPI and TWI pins take care of themselves on initialization

    DDRA = 0xA0; //CS1-4 are unused, so also input high
    DDRB = 0xB1;
    DDRC = 0x03;
    DDRD = 0x10;

    PORTA = 0xFF;
    PORTB = 0xFF;
    PORTC = 0xFF;
    PORTD = 0xFF;
    
    LED_on();

    // do power saving stuff (turn stuff off)
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    wdt_disable();


  #ifdef MAIN_DEBUG
    Debug_init(DEBUG_BAUDRATE);
  #endif

    //Timer3_init();
    i2c_init();
    v_enable();
    sei();

    _delay_ms(1000);
    
    uint32_t clicks;
    float hum;
    uint32_t i = 0;
    uint8_t ret;
    uint32_t value;


    //ret = MLX90614_changeAddress(0x5b, 0x5a);
    //printf("ret: %u\n");

    


    /******************************/
    /******* main loop ************/
    /******************************/
    while (1) {
    

        //ret = LW_readTop( (void *) &value);
        //ret = LW_readBot( (void *) &value);

        ret = SW_readTop( (void *) &value);
        ret = SW_readBot( (void *) &value);

        printf("\n");

        ret = NDVI_getTempTop( (void *) &value);
        ret = NDVI_getTempBot( (void *) &value);

        printf("\n");

        ret = NDVI_getNDVI( (void *) &value);

    
        printf("\n--------------------\n");
        _delay_ms(3000);

    } //while (1)
    return 0;
} //main()
Esempio n. 30
0
/* -----------------------------------------------------------------------------------------------------------*/
int LEDTAFEL_sendblock( char line ) 
{
	char data ;
	int i, block ;
	char * gfx_buffer, * lum_buffer;

	// Zeile setzen und SEL setzen
	DATA_PORT = line + 1;
	CONTROL_PORT |= CONTROL_SEL;

	LED_on(1);
	i = 0 ;
	// auf SYNC gleich HIGH warten oder in den Timeout laufen und abbrechen
	while( !( CONTROL_SYNC & CONTROL_SYNC_PIN ) )
	{
		i++;
		if ( i > TIMEOUTLOOP )
		{
			CONTROL_PORT &= ~CONTROL_SEL;
			LED_off(1);
			return( TAFELSENDERR );
		}
	}

	// SEL auf Low setzen
	CONTROL_PORT &= ~CONTROL_SEL;

	 i = 0;
	// auf SYNC gleich LOW warten oder in den Timeout laufen und abbrechen
	while( ( CONTROL_SYNC & CONTROL_SYNC_PIN ) )
	{
		i++;
		if ( i > TIMEOUTLOOP )
		{
			LED_off(1);
			return( TAFELSENDERR );
		}
	}

	gfx_buffer = &LEDTAFEL_screen_graphic[ line * LEDTAFEL_ROW * 8 ];
	block = LEDTAFEL_ROW;
		
	while( block )
	{
		data = *gfx_buffer;
		gfx_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *gfx_buffer;
		gfx_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		data = *gfx_buffer;
		gfx_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *gfx_buffer;
		gfx_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		data = *gfx_buffer;
		gfx_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *gfx_buffer;
		gfx_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		data = *gfx_buffer;
		gfx_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *gfx_buffer;
		gfx_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		block--;
	}

	lum_buffer = &LEDTAFEL_screenlum[ line * LEDTAFEL_ROW ];
	block = LEDTAFEL_ROW;

	while( block )
	{
		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		block--;
	}

	lum_buffer = &LEDTAFEL_screenlum[ line * LEDTAFEL_ROW ];
	block = LEDTAFEL_ROW;

	while( block )
	{
		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT |= CONTROL_REQ;
		DATA_PORT = data;

		data = *lum_buffer;
		lum_buffer++;
		CONTROL_PORT &= ~CONTROL_REQ;
		DATA_PORT = data;

		block--;
	}

	LED_off(1);

	return( TAFELSENDOK );
}