Example #1
0
void main() {
   BYTE i, j, address, value;

   int16 q,q1;
   float p;

   q1=0;
   
   setup_adc_ports(AN0|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);

   usb_cdc_init();
   usb_init();

//      while(!usb_cdc_connected()) {}

   do {
      usb_task();
      if (usb_enumerated()) {

      delay_ms(500);
      q = read_adc();
      if (q!=q1){
      p = 5.0 * q / 1024.0;
      printf(usb_cdc_putc,"\r Voltage=%01.2fV", p);
      }
      q1=q;
   }
      } while (TRUE);
}
Example #2
0
File: main.c Project: Mazetti/asf
/*! \brief Main function. Execution starts here. */
int main(void)
{
	/* System clock is initialized. */
	sysclk_init();

	/* Board related init such as SPI and GPIO. */
	board_init();

	/* IRQs init. */
	irq_initialize_vectors();

	/* Transceiver init. */
	if (at86rfx_init() != AT86RFX_SUCCESS) {
		Assert("Transceiver initialization failed" == 0);
	}

	/* Interrupt enabled before USB init as it uses IRQ for enumeration. */
	cpu_irq_enable();

	/* Start USB stack */
	udc_start();

	/* Continuous looping of available tasks, starts here. */
	while (true) {
		usb_task();
		app_task();
		at86rfx_task();
	}
}
Example #3
0
/*! \brief Main function. Execution starts here.
 *
 * \retval No return value.
 */
int main(void)
{
#ifdef __GNUC__
	// Initialize the INTC sw driver.
	INTC_init_interrupts();
#endif

	// Configure system clocks.
	if (pcl_configure_clocks(&pcl_freq_param) != PASS)
		while (true);

	// Initialize USB clock (on PLL1)
	pcl_configure_usb_clock();

	// Initialize USB task
	usb_task_init();

#if USB_DEVICE_FEATURE == true
	// Initialize device generic USB task
	device_generic_hid_task_init();
#endif

	// No OS here. Need to call each task in round-robin mode.
	while (true) {
		usb_task();
	#if USB_DEVICE_FEATURE == true
		device_generic_hid_task();
	#endif
	}
}
/*! \brief Main function. Execution starts here.
 *
 * \retval 42 Fatal error.
 */
int main(void)
{
#ifndef FREERTOS_USED
  Enable_global_exception();
  INTC_init_interrupts();
#endif
  pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
  init_dbg_rs232(FOSC0);
  pcl_configure_usb_clock();
  usb_task_init();
#if USB_DEVICE_FEATURE == true
  device_template_task_init();
#endif
#if USB_HOST_FEATURE == true
  host_template_task_init();
#endif

#ifdef FREERTOS_USED
  vTaskStartScheduler();
  portDBG_TRACE("FreeRTOS returned.");
  return 42;
#else
  while (true)
  {
    usb_task();
  #if USB_DEVICE_FEATURE == true
    device_template_task();
  #endif
  #if USB_HOST_FEATURE == true
    host_template_task();
  #endif
  }
#endif  // FREERTOS_USED
}
Example #5
0
File: app.c Project: FoxVK/DFMT
inline void app_task()
{    
    debug_uart_task();
    usb_task();
    tuner_audio_task();
    tuner_control_task();
    tunnel_task();
    
    
    if(usb_audio_can_play(audio_if))
    {
        static AudioFrame *to_send = NULL;
        
        if(to_send == NULL)
            to_send = tuner_audio_get_buf(0);
    
        if(to_send)
        { 
            if(Usb_audio_send(audio_if, USB_EP01, to_send, to_send->size)==USB_RW_REQ_OK)
            {
                //debughalt();
                to_send = NULL;
            }
        }
    }
}
Example #6
0
// main programm
void main(void)
{
   // Hardware initialization
   HW_init();
   // setup interrupts
   setup_timer1(TMR_INTERNAL|TMR_DIV_BY_256);   
   
   // Command buffer initialization
   init_ESPBuffer();

   while(true)
   {
      // usb for debug
      usb_task();
      
      // wi-fi esp8266
      wifi_task();
      
      /*******************************
      * *****************************
      * User code must be situated here!
      * *****************************
      *******************************/

   }//while(true)
}
Example #7
0
/*! \brief Main function. Execution starts here.
 *
 * \retval 42 Fatal error.
 */
int main(void)
{
  // Configure system clocks.
  if (pcl_configure_clocks(&pcl_freq_param) != PASS)
    return 42;

  // Initialize USB clock (on PLL1)
  pcl_configure_usb_clock();

  // Initialize usart comm
  init_dbg_rs232(pcl_freq_param.pba_f);

  // Initialize USB task
  usb_task_init();

#if USB_DEVICE_FEATURE == true
  // Initialize device generic USB task
  device_generic_hid_task_init();
#endif

  // No OS here. Need to call each task in round-robin mode.
  while (true)
  {
    usb_task();
  #if USB_DEVICE_FEATURE == true
    device_generic_hid_task();
  #endif
  }

}
Example #8
0
void start_dfu()
{
	DFU_init();
	usb_init();
	usb_connect();
	while (DFU_complete() == 0)
		usb_task();
	usb_disconnect();
}
Example #9
0
// see usb_hw_layer.h for documentation
void usb_init(void) 
{
   usb_init_cs();

   do 
   {
      usb_task();
   } while (usb_state != USB_STATE_POWERED);
}
Example #10
0
/*! \brief Main function. Execution starts here.
 *
 * \retval 42 Fatal error.
 */
int main(void)
{
  // Configure system clocks.
  if (pcl_configure_clocks(&pcl_freq_param) != PASS)
    return 42;

  // Initialize USB clock (on PLL1)
  pcl_configure_usb_clock();

  // Initialize usart comm
  init_dbg_rs232(pcl_freq_param.pba_f);

#if BOARD == EVK1105
  Disable_global_interrupt();
  /* Register interrupt handler to the interrupt controller
   * up, down buttons on PB22, PB23 -> GPIO_IRQ_6
   */
  INTC_register_interrupt(&touch_button_isr, AVR32_GPIO_IRQ_6, 0);
  /* all gpios between PB23 - PB31) */
  INTC_register_interrupt(&touch_button_isr, AVR32_GPIO_IRQ_7, 0);
  Enable_global_interrupt();
#endif

  // Initialize USB task
  usb_task_init();

#if USB_DEVICE_FEATURE == true
  // Initialize device mouse USB task
  device_mouse_hid_task_init();
#endif
#if USB_HOST_FEATURE == true
  //host_keyboard_hid_task_init();

  // Initialize host mouse USB task
  host_mouse_hid_task_init();
#endif

#ifdef FREERTOS_USED
  // Start OS scheduler
  vTaskStartScheduler();
  portDBG_TRACE("FreeRTOS returned.");
  return 42;
#else
  // No OS here. Need to call each task in round-robin mode.
  while (true)
  {
    usb_task();
  #if USB_DEVICE_FEATURE == true
    device_mouse_hid_task();
  #endif
  #if USB_HOST_FEATURE == true
    //host_keyboard_hid_task();
    host_mouse_hid_task();
  #endif
  }
#endif  // FREERTOS_USED
}
//------------------------------------------------------------------------------
//    Main Function:                                                          
//------------------------------------------------------------------------------
void main()
{
    //--------------------------------------------------------------------------
    //  PIC Initialization Section
    //--------------------------------------------------------------------------
    Disable_Interrupts(GLOBAL);                 // all interrupts OFF
    Setup_adc(ADC_OFF);                         // ADC not needed
    Setup_adc_ports(NO_ANALOGS);                // No ADC ports needed 
    Setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);  // Timer 0 set for  42.6us, 
    Setup_timer_1(T1_DISABLED);                 // Timer 1  

    Set_Tris_A(TRISA_Enabled);          // SPI Disabled
    Set_Tris_B(TRISB_Disable);          // Flash SPI Disabled 
    Set_Tris_C(TRISC_Disable);          // Flash SPI Disabled

    Output_high(FLASH_SELECT);          // Slash Select High
    Output_high(FLASH_CLOCK);           // Pulse the clock
    Output_low(RTC_RST);                // Disable RTC
    Output_High(FPGALoad);              // FPGA Upload pin
    Output_High(FPGAReset);             // FPGA reset off
    Output_High(TestLED);               // indication of boot up

    spi_enabled   = False;              // ZBC to PIC SPI disabled initially
    spi_write     = False;              // ZBC to PIC SPI disabled initially
    
    Refresh_RTCSPI();                   // Refresh data from RTC into SPI buffer

    //--------------------------------------------------------------------------
    //  USB Initialization Section            
    //--------------------------------------------------------------------------
    usb_init_cs();                      // Initialize the USB Connection
    if(read_eeprom(BOOT_TYPE) > 0) {    // We want boot from FLASH
        FlashToFPGA();                  // If not hooked up to USB then try to init
        Output_Low(FPGAReset);          // FPGA reset off
        Output_High(FPGAReset);         // FPGA reset off
        Output_Low(TestLED);            // Turn off Test LED
    }
    else {
        FGPA_SPI_Init();                // Put PIC in SPI Slave mode 
    }
    
    //--------------------------------------------------------------------------
    //  Main Command Loop:            
    //--------------------------------------------------------------------------
    do {                                // Always do USB Task
        usb_task();                     // so it will detect USB pluging in 
        if(usb_enumerated()) {          // Are we plugged into the USB port ?
            usb_rcvdata_task();         // If so, check for data 
        }
        if(spi_enabled) {               // if ZBC to PIC SPI enabled, then check 
            if(SSP_HAS_DATA()) {
                Handle_SPI();           // Handle SPI request from ZBC
            }
        }                               // Otherwise... just
    } while(True);                      // Continue forever, what else can we do ?
}
Example #12
0
void main() {
   
   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
   set_tris_b(0x00);                
   output_b(0x00);
   LED_ON(LEDR);
   LED_OFF(LEDV); 
   usb_init();                      
   usb_task();   //Monitorea el estado de la coneccion conectandose y desconectandose automaticamente
   usb_wait_for_enumeration();  //espera infinitamente hasta que el dispositivo fue enumerado    
   LED_ON(LEDV);
   LED_OFF(LEDR); 
   
   while (TRUE) 
   {
      usb_task();
      if (usb_enumerated()) 
      {
        
            Salida[0]=read_adc();
            usb_put_packet(1, Salida, 1, USB_DTS_TOGGLE);

         if (usb_kbhit(1)) 
         {
         
           usb_get_packet(1, Entrada, 1);
           if (Entrada[0]==1)
            {      
             LED_ON(PIN_B0);
              
            }

            else 
            LED_OFF(PIN_B0);

         }
         
      }
   }
   }
Example #13
0
void main(void)
{
   int i;

   set_tris_b(0x10000000);
   
   output_high(PIN_B0);
   delay_ms(500);
   output_low(PIN_B0);
   
   fprintf(A, "rs232 init...\n\r");
   
   usb_init_cs();

   while(1)
   {
      if(input(PIN_B7))
      {
         output_high(PIN_B0);

         usb_task();

         while(input(PIN_B7))
         {
            if (usb_enumerated())
            {
               if (usb_kbhit(1))
               {
                  receive_msg();
                  //usb_get_packet(1, rdata, 1);
               
                  //fprintf(A, "%u", rdata[0]);
                  //switch(rdata[0])
                  //{
                  //   case 0x01: output_high(PIN_B0); break;
                  //   case 0x02: output_low(PIN_B0); break;
                  //}
               }
            }
         }
      
         usb_detach();
         
         output_low(PIN_B0);
      }
   }
}
Example #14
0
void main()
{
    setup_timer_3 (T3_DISABLED|T3_DIV_BY_1);
    usb_init ();
    lcd_init ();
    lcd_putc ('\f');
    delay_ms (1);
    while (TRUE) {
        lcd_refresh ();
        usb_task ();
        if (usb_enumerated ()) {
            if (usb_kbhit (1))
                rxdata_len = usb_get_packet (1, rxdata, sizeof (rxdata));
        }
        delay_ms (100);
    }
}
Example #15
0
void main(void) {
   char c;

   LED_OFF(LED1);
   LED_OFF(LED2);
   LED_OFF(LED3);

   printf("\r\n\nCCS CDC (Virtual RS232) Example\r\n");

  #ifdef __PCH__
   printf("PCH: v");
   printf(__PCH__);
  #else
   printf("PCM: v");
   printf(__PCM__);
  #endif
   printf("\r\n");

   usb_init();

  #if !(__USB_PIC_PERIF__)
   printf("USBN: 0x%X", usbn_get_version());
   printf("\r\n\n");
  #endif


   while (TRUE) {
      usb_task();
      usb_debug_task();

      if (kbhit()) {
         c=getc();
         if (c=='\n') {usb_cdc_putc('\r'); usb_cdc_putc('\n');}
         if (c=='\r') {usb_cdc_putc('\r'); usb_cdc_putc('\n');}
         else {usb_cdc_putc(c);}
      }
      if (usb_cdc_kbhit()) {
         c=usb_cdc_getc();
         if (c=='\n') {putc('\r'); putc('\n');}
         if (c=='\r') {putc('\r'); putc('\n');}
         else {putc(c);}
      }
   }
}
//**** Funciones genericas ***************************************************
void Inicio(void){ 
   //--- ini: mPaP -----------------------------------------------------------
   numPulsosX=numPulsosY=numPulsosZ=numPulsosE=0;
   periodoPulsosX=periodoPulsosY=periodoPulsosZ=periodoPulsosE=0;
   //--- ini: PID ------------------------------------------------------------
   min=0.0; max=1023 ; //valor Anti-windup    
   i1=0;e1=0;d1=0;   
   Kd=8; Kp=8; Ki=0.02915;
   T=5;       //Tiempo de muestreo  tr/6 < T < tr/20
   Kpz=Kp; Kiz=Ki*T/2; Kdz=Kd/T;
   
   //--- ini: CCP ---------------------------------------------------------
   //--- Pre=16 PR2=249 Pos=1, PWMF=3kHz,PWMT=300us con Fosc(clock)=48MHz
   setup_timer_2(T2_DIV_BY_16,249,1); 
   setup_ccp1(ccp_pwm);               //Configurar modulo CCP1 en modo PWM
   set_pwm1_duty(0);  
   
   //--- ini: ADC ---------------------------------------------------------  
   setup_adc_ports(AN0|VSS_VDD );     
   setup_adc(ADC_CLOCK_INTERNAL); 
   //setup_adc(ADC_CLOCK_DIV_8); //respetar el Tad>1.6us 
                                 //Tad=8/Fosc=8/20Mhz=400ns
   set_adc_channel(0);           //Seleccionar Canal(0)=AN0=A0 para ADC
   
   //--- ini: TIMER0 for OS_Timer() ---------------------------------------                                  
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);  //config Timer0, Pre=1=RTCC_DIV_1
   //set_timer0(0xF63B);   //carga del Timer0, clock=20MHz, Fout=1kHz=0xF63B
   set_timer0(0xE88F);     //carga del Timer0, clock=48MHz, Fout=1kHz=0xE88F
   
   //--- ini: Interrupts --------------------------------------------------
   //enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER0);            //habilita interrupcion Timer0
   //enable_interrupts(INT_TIMER2);
   
   //--- ini: USB ------------------------------------------------------------
   usb_init();                   //inicializamos el USB
   usb_task();                   //habilita periferico usb e interrupciones
   usb_wait_for_enumeration();   //esperamos hasta que el PicUSB 
                                 //sea configurado por el host
   delay_ms(50);   
}
Example #17
0
void main(void) {
#else
int main(void) {
#endif
    /* Ensure that the Watchdog is not running. */
    wdt_disable();
    
	/* Initialize system. */
	if (true != avr_init()) {
		error_handler();
	} else if (true != eep_init()) {
        eep_deinit();
        error_handler();
    } else if (true != cmd_if_init()) {
        cmd_if_deinit();
        error_handler();
    }
	
    /* Disable modules that are not needed any more. */
    eep_deinit();
    
    LED_ORANGE_ON();
        
    /* Enable interrupts. */
    sei();
    
	/* Endless application loop. */
	for(;;) {
        /* Dispatch events from the event queue. */
		vrt_dispatch_event();
        
        /* Poll modules that require this. */
        vrt_timer_task();
        usb_task();
        air_capture_task();
        cmd_if_task();
	}
}
Example #18
0
void main ()
{
    setup_timer_3 (T3_DISABLED|T3_DIV_BY_1);
    pwm_init (0);
    pwm_duty (0, 50);
    usb_init ();
    lcd_init ();
    lcd_putc ('\f');
    delay_ms (1);
    lcd_refresh ();

    while (TRUE) {
        usb_task ();
        if (usb_enumerated ()) {
            if (usb_kbhit (1)) {
                rx_msg_len = usb_get_packet (1, &rx_msg, sizeof (rx_msg));
                process_usb_data ();
            }
        }
        lcd_refresh ();
        delay_ms (100);
    }
}
Example #19
0
void cdc_receiving(void) {		// return: Anzahl empfangener Bytes im Fifo
  int bytes_rx, bytes_left;
#if USB_DEVICE_FEATURE == ENABLED && USB_HOST_FEATURE == ENABLED
   usb_task();
#elif USB_DEVICE_FEATURE == ENABLED
   usb_device_task();
#elif USB_HOST_FEATURE == ENABLED
   usb_host_task();
#endif
  if ( usb_connected && Is_usb_out_received(RX_EP) ) {
    bytes_rx = Usb_byte_count(RX_EP);
    if ((bytes_rx > 0)&&(bytes_rx < cdc_rxleft)) {
      bytes_left = CDC_RXBUFFERSIZE-cdc_wrpos;
      Usb_reset_endpoint_fifo_access(RX_EP);
      if (bytes_rx <= bytes_left) {	// Normalfall: kein Wrap
        usb_read_ep_rxpacket(RX_EP, (void *)cdc_rxbuffer+cdc_wrpos, bytes_rx, NULL);
      } else {
        usb_read_ep_rxpacket(RX_EP, (void *)cdc_rxbuffer+cdc_wrpos, bytes_left, NULL);
        usb_read_ep_rxpacket(RX_EP, (void *)cdc_rxbuffer, bytes_rx-bytes_left, NULL);
      }
      cdc_wrpos = (cdc_wrpos+bytes_rx)%CDC_RXBUFFERSIZE;
      // End copy in own fifo
      cdc_rxidle_pos = cdc_sof_counter + cdc_timeoutval;
      cdc_timeout_enabled = (cdc_timeoutval>0)&&(cdc_timeout_fct!=NULL);
    } // fi copy received
    Usb_ack_out_received_free(RX_EP);	// moved outside of if-con
  } else if (cdc_timeout_enabled) {
    if ((int)(cdc_sof_counter - cdc_rxidle_pos) >= 0) {
      cdc_timeout_fct(cdc_rxlen);
      cdc_timeout_enabled = FALSE;
    }
  } // esle fi to
  // chain-tx (>64 byte):
  if (cdc_txbuffer_len > 0) {
    cdc_transmit(cdc_txbuffer, cdc_txbuffer_len);
  } // fi
}
Example #20
0
void load_program(void)
{
  int1  do_ACKLOD, done=FALSE;
  int8  checksum, line_type;
  int16 l_addr,h_addr=0;
  int8 to;
  int32 addr;
  int8  dataidx, i, count;
  int8  data[32];
  int  buffidx;
  char buffer[BUFFER_LEN_LOD];
   
  while (!done)  // Loop until the entire program is downloaded
  {
    usb_task();

    if(!usb_cdc_kbhit())
      continue;
         
    buffidx = 0;  // Read into the buffer until 0x0D ('\r') is received or the buffer is full
    to = 250;   //250 milliseconds
    do 
    {
      if(!usb_cdc_kbhit())
      {
	delay_ms(1);
	to--;
	if(!to)
	  break;
      }
      else
	to = 250;
      i = usb_cdc_getc();
      buffer[buffidx++] = i;
    }while((i != 0x0D) && (i != 0x0A) && (buffidx <= BUFFER_LEN_LOD));
            
    if(!to)
      continue;

    usb_cdc_putc(XOFF);  // Suspend sender

    do_ACKLOD = TRUE;

    // Only process data blocks that start with ':'
    if(buffer[0] == ':')
    {
      count = atoi_b16 (&buffer[1]);  // Get the number of bytes from the buffer

      // Get the lower 16 bits of address
      l_addr = make16(atoi_b16(&buffer[3]),atoi_b16(&buffer[5]));

      line_type = atoi_b16 (&buffer[7]);

      addr = make32(h_addr,l_addr);

      // If the line type is 1, then data is done being sent
      if(line_type == 1) 
      {
	done = TRUE;
      }
      else if((addr >= (int32)APPLICATION_START) && (addr < ((int32)0x300000)))
      {
	checksum = 0;  // Sum the bytes to find the check sum value
	for(i=1; i<(buffidx-3); i+=2)
	  checksum += atoi_b16 (&buffer[i]);
	checksum = 0xFF - checksum + 1;

	if(checksum != atoi_b16 (&buffer[buffidx-3]))
	  do_ACKLOD = FALSE;
	else   
	{
	  if(line_type == 0) {
	    // Loops through all of the data and stores it in data
	    // The last 2 bytes are the check sum, hence buffidx-3
	    for(i = 9,dataidx=0; i < buffidx-3; i += 2)
	      data[dataidx++]=atoi_b16(&buffer[i]);
                    
	    rom_w(addr, data, count);
	  }
	  else if(line_type == 4)
	    h_addr = make16(atoi_b16(&buffer[9]), atoi_b16(&buffer[11]));
	}
      }
    }

    if(do_ACKLOD)
      usb_cdc_putc (ACKLOD);

    usb_cdc_putc(XON);
  }

  usb_cdc_putc(ACKLOD);
  usb_cdc_putc(XON);
  delay_ms(2000);   //give time for packet to flush
  reset_cpu();
}
Example #21
0
/*! \brief Main function. Execution starts here.
 *
 * \retval 42 Fatal error.
 */
int main(void)
{
  // Configure system clocks.
  if (pcl_configure_clocks(&pcl_freq_param) != PASS)
    return 42;

  // Initialize usart comm
  init_dbg_rs232(pcl_freq_param.pba_f);

#ifndef FREERTOS_USED
# if (defined __GNUC__)
  // Give the used CPU clock frequency to Newlib, so it can work properly.
  set_cpu_hz(pcl_freq_param.pba_f);
# endif
#endif

  // Initialize USB clock.
  pcl_configure_usb_clock();

  // Initialize USB task
  usb_task_init();

  // Display a welcome banner on USART
  printf("                                                       ......       ......     \r\n");
  printf("       IIIIII  IIIII        IIII   IIIIIIIIIII      IIIIIIIIIII. .IIIIIIIIII.  \r\n");
  printf("      IIIIIII   IIIII      IIIII  IIIIIIIIIIIII     IIIIIIIIIIII..IIIIIIIIIII. \r\n");
  printf("     IIIIIIIII  IIIII     IIIII   IIIII   IIIII     I.      IIIII.:.     IIIII \r\n");
  printf("     IIII IIIII  IIIII    IIII   IIIII    IIIII            .IIII.        IIIII \r\n");
  printf("    IIIII  IIII   IIII   IIIII  IIIIIIIIIIIIII         IIIIIIII          IIII. \r\n");
  printf("    IIII   IIIII  IIIII IIIII   IIIIIIIIIIIII          IIIIIIII.       .IIII:  \r\n");
  printf("   IIIII    IIIII  IIIIIIIII   IIIIIIIIIII                 .IIIII     IIIII.   \r\n");
  printf("  IIIIIIIIIIIIIII   IIIIIIII   IIIII IIIII                  .IIII   .IIII:     \r\n");
  printf("  IIIIIIIIIIIIIIII  IIIIIII   IIIII   IIII         II:.    .IIIII .IIIII.      \r\n");
  printf(" IIIII        IIIII  IIIIII  IIIII    IIIII        IIIIIIIIIIIII.IIIIIIIIIIIIII\r\n");
  printf(" IIIII        IIIII  IIIII   IIIII    IIIII        :IIIIIIIIII.  IIIIIIIIIIIIII\r\n");
  printf("                      III                                                      \r\n");
  printf("                       II                                                      \r\n");

#if USB_DEVICE_FEATURE == true
  // Initialize device CDC USB task
  device_cdc_task_init();
#endif
#if USB_HOST_FEATURE == true
  // Initialize host CDC USB task
  host_cdc_task_init();
#endif

#ifdef FREERTOS_USED
  // Start OS scheduler
  vTaskStartScheduler();
  portDBG_TRACE("FreeRTOS returned.");
  return 42;
#else
  // No OS here. Need to call each task in round-robin mode.
  while (true)
  {
    usb_task();
  #if USB_DEVICE_FEATURE == true
    device_cdc_task();
  #endif
  #if USB_HOST_FEATURE == true
    host_cdc_task();
  #endif
  }
#endif  // FREERTOS_USED
}
void main()
{
   int1 flag = 0;
   
   porta = 0;//all ports are zero
   portb = 0;
   portc = 0;

   setup_adc_ports(no_analogs|vss_vdd); //digital functions selected
   setup_adc(adc_off); //internal rc oscillator disabled for adc
   setup_wdt(wdt_off); //watch dog timer disabled
   setup_timer_0(rtcc_off); //all timers disabled
   setup_timer_1(t1_disabled);
   setup_timer_2(t2_disabled,0,1);
   setup_timer_3(t3_disabled|t3_div_by_1);
   setup_comparator(nc_nc_nc_nc); //comparators disabled
   setup_vref(false); //no reference voltage in ra2
   setup_ccp1(ccp_off); //disable ccp1
   setup_ccp2(ccp_off); //disable ccp2
   enable_interrupts(int_rda); //uart rx interruption enabled
   enable_interrupts(global); //global interruptions enabled
   usb_cdc_init();
   usb_init(); //initialize hardware usb and wait for PC conection
 
   set_tris_a(0b00111111);
   set_tris_b(0b11111011);//rb2 output mclr dspic
   
   port_b_pullups(false);
   set_tris_c(0b10111111);
   
   stateDspic = running;
   counterReset = 0;  
   delay_ms(500);//wait for supply stabilization

   while(true)
   {
      usb_task();
      manage_conection();
 
      if (usb_cdc_kbhit())
      {
         data_rx_usb=usb_cdc_getc();//read buffer and save in data_rx
         printf("%c",data_rx_usb);//send through uart
         
         if (data_rx_usb == rstKeyword[0])
         {
            if (counterReset == 0)
               counterReset++;
         }
         else if (data_rx_usb == rstKeyword[1])
         {
            if (counterReset == 1)
               counterReset++;
            else
               counterReset = 0;
         }
         else if (data_rx_usb == rstKeyword[2])
         {
            if (counterReset == 2)
               counterReset++;
            else
               counterReset = 0;
         }
         else if (data_rx_usb == rstKeyword[3])
         {
            if (counterReset == 3)
               counterReset++;
            else
               counterReset = 0;
         }
         else if (data_rx_usb == rstKeyword[4] && counterReset == 4)//here, all requirements were met
         {
            counterReset = 0;
            flag = 0; //reset flag
            for(i = 0; i < 10000; i++) //wait for the next byte
            {
               if (usb_cdc_kbhit()) //if a new byte is received
               {
                  data_rx_usb = usb_cdc_getc();//read buffer and save in data_rx
                  printf("%c",data_rx_usb);//send through uart 
                  flag = 0;
                  break;
               }
               flag = 1;                            
            }
            if (flag == 1) //apply reset when no characters were received
            {
               stateDspic = stop;
               delay_ms(50);
               stateDspic = running;    
            }
         }
         else
            counterReset = 0;
         
      }
   }
}
Example #23
0
int main(void)
{

  /* USER CODE BEGIN 1 */


  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_CRC_Init();
  MX_I2C1_Init();
  MX_SPI2_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM4_Init();
  MX_USART2_UART_Init();

  /* USER CODE BEGIN 2 */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);

  // reinitialize uart with speed from config
  huart2.Init.BaudRate = USART_DEBUG_SPEED;
  HAL_UART_Init(&huart2);

  DEBUG_PRINTF("Hello, Lepton!\n\r");
  fflush(stdout);

  lepton_init();

  HAL_Delay(1000);

  init_lepton_command_interface();
#ifdef ENABLE_LEPTON_AGC
  enable_lepton_agc();
#endif

#ifdef Y16
  enable_telemetry();
#else
  enable_rgb888(PSUEDOCOLOR_LUT);
#endif

  DEBUG_PRINTF("reading_tmp007_regs...\n\r");

  read_tmp007_regs();

  DEBUG_PRINTF("Initialized...\n\r");

  HAL_Delay(250);

  MX_USB_DEVICE_Init();

  PT_INIT(&lepton_task_pt);
  PT_INIT(&usb_task_pt);
  PT_INIT(&uart_task_pt);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

	  PT_SCHEDULE(lepton_task(&lepton_task_pt));
	  PT_SCHEDULE(usb_task(&usb_task_pt));
	  PT_SCHEDULE(uart_task(&uart_task_pt));
	  PT_SCHEDULE(button_task(&button_task_pt));

  }
  /* USER CODE END 3 */

}
void main(void) {
     
   int8 recibe[5];                  //declaramos variables
   int8 send2[1];

   LED_OFF(LED_OK);                   //encendemos led rojo
   LED_ON(LED_FAIL);
            
   usb_init();                      //inicializamos el USB  
   
   setup_adc_ports(AN0);         //Configura canais analógico
   setup_adc(ADC_CLOCK_INTERNAL);    //De acordo com relógio interno.
   
   /*SETUP_TIMER_1 (T1_INTERNAL|T1_DIV_BY_2);       //Configurar timer1 para clock iterno/8
   enable_interrupts (INT_TIMER1);                //Habilitar Interrupções
   enable_interrupts (global);*/

   usb_task();                      //habilita periferico usb e interrupciones
   usb_wait_for_enumeration();      //esperamos hasta que el PicUSB sea configurado por el host
   
   enable_interrupts (global);

   LED_OFF(LED_FAIL);                 //desligo o LED vermelho
   LED_ON(LED_OK);                    //acendo o LED verde
   
   move_x('S');
   move_y('S');
         
   while (true)
   {
      if(usb_enumerated())          //si el PicUSB está configurado
      {  
         if (usb_kbhit(1))          //si el endpoint de salida contiene datos del host
         {            
            LED_ON(LED_DATA);
            usb_get_packet(1, recibe, 5); //cojemos el paquete de tamaño 3bytes del EP1 y almacenamos en recibe            
            
            if(modo == 1)
            {               
                  if(dir_x == 1 && value_x == 1){
                     move_x('R');
                  }
                  if(dir_x == 2 && value_x == 1){
                     move_x('L');
                  }                  
                  if(dir_y == 1 && value_y == 1){
                     move_y('F');
                  }
                  if(dir_y == 2 && value_y == 1){
                     move_y('B');
                  }
                  
                  delay_ms(20);               
            }
            
            if (modo == 4)
            {
               status = 1;
               usb_put_packet(1, send2, 1, USB_DTS_TOGGLE); //enviada a informação para o PC com o status
            }    
            LED_OFF(LED_DATA);
         }
      }
   }
}
void main(void) {
#else
int main(void) {
#endif
    /* Ensure that the watchdog is not running. */
    wdt_disable();
        
    /* Initialize AVR peripheral modules. */
    (bool)avr_init();
    
    /* Check if the RX and TX pins are shorted. If they are shorted, the RZUSBSTICK
     * shall start the bootloader. If not, continue to verify if the application
     * requested to enter the bootloader.
     */
    
    /* Check if the application has requested to enter the bootloader. */
    if ((BOOT_PIN & (1 << BOOT_RX)) != (1 << BOOT_RX)) {
        /* Check that RX goes high when TX is pulled high. */
        BOOT_PORT |= (1 << BOOT_TX);
        
        nop();
        nop();
        nop();
        nop();
        
        if ((BOOT_PIN & (1 << BOOT_RX)) != (1 << BOOT_RX)) {
            start_application();
        }
    } else {
        /* Check if the application has requested to enter the bootloader. */
        uint8_t volatile magic_value = 0xAA;
        EEGET(magic_value, EE_BOOT_MAGIC_ADR);
   
        if (EE_BOOT_MAGIC_VALUE != magic_value) {
            start_application();
        } else {
            EEPUT(EE_BOOT_MAGIC_ADR, 0xFF);
        }
    }
    
    /* Set the interrupt vectors to the bootloader, initialize the LEDs and the
     * VRT kernel.
     */
    ENTER_CRITICAL_REGION();
    uint8_t temp_mcucr = MCUCR;
    MCUCR = (1 << IVCE);
    MCUCR = (1 << IVSEL);
    MCUCR = temp_mcucr;
    LEAVE_CRITICAL_REGION();

    LED_INIT();
    vrt_init();
    
    if (true != eep_init()) {
        error_handler();
    } else if (true != cmd_if_init()) {
        error_handler();
    }
    
    LED_ORANGE_ON();
    
    /* Enable Interrupts. */
    sei();
    
    /* Enter the endless application loop. */
    for (;;) {
        vrt_dispatch_event();
        usb_task();
    }
}
Example #26
0
void main() {
	// mod, added to patch config bits
	patch_config();

	output_high(LEDR);
	output_low(LEDG);
   
	usb_init();
   
	setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
	set_timer0(0x8ad0);

	enable_interrupts(GLOBAL);
	enable_interrupts(INT_TIMER0);

	while(1) {
	
	#if defined (BOARD_AVRUSB12_32)
		  //Mod here we check pin status to see if we must reset device
	  if(!input(PIN_B7)) {
					delay_ms(25);	//debounce
					if(!input(PIN_B7)) {	//its a press
						output_bit(LEDG,1);					
						delay_ms(500);	//for long press detection, 
						if(!input(PIN_B7)) {	//its still a press after 1 sec
							PINRST_BTL();			//reset device
						}						
						output_bit(LEDG,0);			
					}					
		}
	#endif
		
		usb_task();
		usb_isr();

		if(DelayCount) continue;

		if(Connect) {
			if(UADDR != HubAddress) {
				usb_set_address(HubAddress);
			}

			DevicePort = Connect;
			port_status[Connect - 1] = PORT_FULL;
			port_change[Connect - 1] = C_PORT_CONN;

			TxBuf[0] = 1 << Connect;
			if(Force0DTS)
				usb_put_packet(1, TxBuf, 1, 0);
			else
				usb_put_packet(1, TxBuf, 1, USB_DTS_TOGGLE);
			Connect = 0;
			Force0DTS = 0;
		}

		if(Reset) {
			TxBuf[0] = 1 << Reset;
			usb_put_packet(1, TxBuf, 1, USB_DTS_TOGGLE);
			Reset = 0;
		}

		if(Disconnect) {
			if(UADDR != HubAddress)
				usb_set_address(HubAddress);
			DevicePort = Disconnect;
			port_status[Disconnect - 1] = PORT_EMPTY;
			port_change[Disconnect - 1] = C_PORT_CONN;
			TxBuf[0] = 1 << Disconnect;
			usb_put_packet(1, TxBuf, 1, USB_DTS_TOGGLE);
			Disconnecting = Disconnect;
			Disconnect = 0;
		}

		if(WaitJig) {
			if(WaitJig == 1) {
				if(usb_kbhit(2)) {
					unsigned char c;
					Chirp();
					c = usb_get_packet(2, TxBuf, 8);
					nJigs++;
					EP_BDxST_I(1) = 0x40;   //Clear IN endpoint
					if(nJigs == 8) {
						nJigs = 0;
						WaitJig = 2;
						Delay10ms(50);
					}
				}
			}
			else {
				int n = 0;
				for(n = 0; n < 8; ++n) {
					TxBuf[n] = jig_response[8 * nJigs + n];
				}
				if(usb_put_packet(1, TxBuf, 8, nJigs == 0 ? 0 : USB_DTS_TOGGLE)) {
					Delay10ms(1);
					nJigs++;
					Chirp();
					if(nJigs == 8) {
						nJigs = 0;
						WaitJig = 0;
						Delay10ms(15);
						Disconnect = 3;
					}
				}
			}
		}

		if(Address != -1) {
			delay_ms(1);
			usb_set_address(Address);
			Address = -1;
		}
	}
}
Example #27
0
void housekeep() {
    usb_task(); 	// service periodic usb functions
    while (usb_cdc_kbhit() && (nqueue(&rxque0) < HIBUF)) {
	enqueue(&rxque0, usb_cdc_getc());
    }
}
/**
 *  \brief UOTGHS Library Example Application entry point.
 *
 *  \return 42 Fatal error.
 */
extern int main( void )
{
    /* Disable watchdog */
    WDT_Disable( WDT ) ;

    /* UTMI parallel mode, High/Full/Low Speed */
    /* UOTGCK not used in this configuration (High Speed) */
    PMC->PMC_SCDR = PMC_SCDR_UOTGCK;
    /* USB clock register: USB Clock Input is UTMI PLL */
    PMC->PMC_USB = PMC_USB_USBS;
    /* USBS: USB Input Clock Selection: USB Clock Input is PLLA */
    /* Enable peripheral clock for UOTGHS */
    PMC_EnablePeripheral(UOTGHS_IRQn);
    UOTGHS->UOTGHS_CTRL = 0x0;
    /* Enable PLL 480 MHz */
    PMC->CKGR_UCKR = CKGR_UCKR_UPLLEN | CKGR_UCKR_UPLLCOUNT(0xF);
    /* Wait that PLL is considered locked by the PMC */
    while( !(PMC->PMC_SR & PMC_SR_LOCKU) );
    /* Enable peripheral clock for UOTGHS */
    PMC_EnablePeripheral(UOTGHS_IRQn);

    /* Output example information */
    printf( "-- UOTGHS Library Example %s --\n\r", SOFTPACK_VERSION ) ;
    printf( "-- %s\n\r", BOARD_NAME ) ;
    printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ;

    /* UOTGHS pins */
    PIO_PinConfigure( pUOTGHSPins, PIO_LISTSIZE( pUOTGHSPins ) );
    if ( PIO_PinGet(&pUOTGHS_Fault) == 0 )
    {
        TRACE_OTG("UOTGHS_Fault = 0 (active low  ERROR FLAG !\r\n");
        TRACE_OTG("Undervoltage, Soft Start, Overcurrent, or Overtemperature\r\n");
        while(1);
    }

    /* Enable interrupt */
    NVIC_EnableIRQ(UOTGHS_IRQn);

    /* Initialize USB task */
    usb_task_init();

#if USB_DEVICE_FEATURE == ENABLED
  device_template_task_init();
#endif

#if USB_HOST_FEATURE == ENABLED
  host_template_task_init();
#endif

#ifdef FREERTOS_USED
    /* Start OS scheduler */
  vTaskStartScheduler();
  TRACE_OTG("FreeRTOS returned\n\r");
  return 42;
#else
    /* No OS here. Need to call each task in round-robin mode. */
  while (TRUE)
  {
    usb_task();

  #if USB_DEVICE_FEATURE == ENABLED
    device_template_task();
  #endif

  #if USB_HOST_FEATURE == ENABLED
    host_template_task();
  #endif
  }
#endif  /* FREERTOS_USED */
}
Example #29
0
/*! \brief Main function. Execution starts here.
 *
 * \retval 42 Fatal error.
 */
int main(void)
{
    init_hmatrix();

    // Configure standard I/O streams as unbuffered.
#if (defined __GNUC__) && (defined __AVR32__)
    setbuf(stdin, NULL);
#endif
    setbuf(stdout, NULL);

#if (defined USB_RESYNC_METHOD) && (USB_RESYNC_METHOD == USB_RESYNC_METHOD_EXT_CLOCK_SYNTHESIZER)
    // Initialize the TWI using the internal RCOSC
    init_twi_CS2200(AVR32_PM_RCOSC_FREQUENCY);

    // Initialize the CS2200 and produce a default 11.2896 MHz frequency
    cs2200_setup(11289600, FOSC0);
#endif

    // Initializes the MCU system clocks
    init_sys_clocks();

    // Initialize the TWI
    init_twi(FPBA_HZ);

    audio_mixer_enable_dacs(DEFAULT_DACS);
    audio_mixer_dacs_start(DEFAULT_DAC_SAMPLE_RATE_HZ,
                           DEFAULT_DAC_NUM_CHANNELS,
                           DEFAULT_DAC_BITS_PER_SAMPLE,
                           DEFAULT_DAC_SWAP_CHANNELS);

    // Initialize the display
    et024006_Init(  FCPU_HZ, FHSB_HZ);

    // Set Backlight
    gpio_set_gpio_pin(ET024006DHU_BL_PIN);

    // Clear the display
    et024006_DrawFilledRect(0, 0, ET024006_WIDTH, ET024006_HEIGHT, WHITE );

    // Display a logo.
    et024006_PutPixmap(avr32_logo, AVR32_LOGO_WIDTH, 0, 0
                       ,(ET024006_WIDTH - AVR32_LOGO_WIDTH)/2
                       ,(ET024006_HEIGHT - AVR32_LOGO_HEIGHT)/2, AVR32_LOGO_WIDTH, AVR32_LOGO_HEIGHT);

    et024006_PrintString(AUDIO_DEMO_STRING, (const unsigned char *)&FONT8x16, 30, 5, BLACK, -1);
    et024006_PrintString("Please plug the USB.", (const unsigned char *)&FONT8x8, 30, 30, BLACK, -1);

    // Initialize USB task
    usb_task_init();

    // Initialize Controller
    controller_init(FCPU_HZ, FHSB_HZ, FPBB_HZ, FPBA_HZ);

#if USB_DEVICE_FEATURE == true
    // Initialize device audio USB task
    device_audio_task_init();

    // Initialize the HID USB task
    device_hid_task_init();
#endif
#if USB_HOST_FEATURE == true
    // Initialize host audio USB task
    host_audio_task_init();
#endif

#ifdef FREERTOS_USED
    // Start OS scheduler
    vTaskStartScheduler();
    portDBG_TRACE("FreeRTOS returned.");
    return 42;
#else
    // No OS here. Need to call each task in round-robin mode.
    while (true)
    {
        usb_task();
#if USB_DEVICE_FEATURE == true
        device_audio_task();
        device_hid_task();
#endif
#if USB_HOST_FEATURE == true
        host_audio_task();
#endif
    }
#endif  // FREERTOS_USED
}
void main(void) {

   int8 recibe[3];                  //declaramos variables
   int8 envia[1];

   setup_adc_ports( ALL_ANALOG );		//Configuramos el puerto a como analogo
   setup_adc( ADC_CLOCK_INTERNAL );
   set_adc_channel( 0 );  

   LED_OFF(LEDV);                   //encendemos led rojo
   LED_ON(LEDR);

   usb_init();                      //inicializamos el USB

   usb_task();                      //habilita periferico usb e interrupciones
   usb_wait_for_enumeration();      //esperamos hasta que el PicUSB sea configurado por el host

  LED_OFF(LEDR);
  LED_ON(LEDV);                    //encendemos led verde
    
  /* while(TRUE){
       envia[0] = (int8)Read_ADC();
       if (envia[0] > 0x7F){
              LED_ON(LEDR);
              LED_ON(LEDV);                    //encendemos led verde
         }else{
              LED_OFF(LEDR);
              LED_OFF(LEDV);  //otra acción
        }
   } 
*/
   while (TRUE)
   {
      if(usb_enumerated())          //si el PicUSB está configurado
      {
         if (usb_kbhit(1))          //si el endpoint de salida contiene datos del host
         {
            usb_get_packet(1, recibe, 3); //cojemos el paquete de tamaño 3bytes del EP1 y almacenamos en recibe

            if (modo == 0) // Modo_Suma
            {
              envia[0] = (int8)Read_ADC();
              usb_put_packet(1, envia, 1, USB_DTS_TOGGLE); //enviamos el paquete de tamaño 1byte del EP1 al PC
				if (envia[0] > 0x7F){
              LED_ON(LEDR);
              LED_ON(LEDV);                    //encendemos led verde
         	}else{
              LED_OFF(LEDR);
              LED_OFF(LEDV);  //otra acción
        }
            }

            if (modo == 1) // Modo_Led
            {
               if (param1 == 0) {LED_OFF(LEDV); LED_OFF(LEDR);} //apagamos los leds
               if (param1 == 1) {LED_ON(LEDV); LED_OFF(LEDR);} //encendemos led verde
               if (param1 == 2) {LED_OFF(LEDV); LED_ON(LEDR);} //encendemos led rojo
            }
         }
      }
   }
}