Beispiel #1
0
int main (void)
{
    int ticks = 0;
    int count = 0;
    usb_cdc_t usb_cdc;

    usb_cdc = usb_cdc_init ();
    
    sys_redirect_stdin ((void *)usb_cdc_read, usb_cdc);
    sys_redirect_stdout ((void *)usb_cdc_write, usb_cdc);
    sys_redirect_stderr ((void *)usb_cdc_write, usb_cdc);


    /* Wait until USB configured.  */
    while (! usb_cdc_update ())
        continue;

    pacer_init (PACER_RATE);

    while (1)
    {
        pacer_wait ();

        ticks++;
        if (ticks > PACER_RATE / SPAM_RATE)
        {
            ticks = 0;
            printf ("Hello world %u!\n\r", count++);
        }
    }
}
Beispiel #2
0
int main(int argc, char ** argv)
{
	struct vcom vcom;
	int i = 0;

	DCC_LOG_CONNECT();
	DCC_LOG_INIT();

	thinkos_init(THINKOS_OPT_PRIORITY(0) | THINKOS_OPT_ID(0));

	vcom.usb = usb_cdc_init();
	vcom.serial = serial_init(stm32f_uart5);

	thinkos_thread_create((void *)usb_recv_task, (void *)&vcom,
						  usb_recv_stack, STACK_SIZE, 0);

	thinkos_thread_create((void *)usb_ctrl_task, (void *)&vcom,
						  usb_ctrl_stack, STACK_SIZE, 0);

	thinkos_thread_create((void *)serial_recv_task, (void *)&vcom,
						  serial_recv_stack, STACK_SIZE, 0);

	thinkos_thread_create((void *)serial_ctrl_task, (void *)&vcom,
						  serial_ctrl_stack, STACK_SIZE, 0);

	for (i = 0; ;i++) {
		thinkos_sleep(10000);
	}

	return 0;
}
Beispiel #3
0
int main(int argc, char ** argv)
{
	usb_cdc_class_t * cdc;
	FILE * f_tty;
	FILE * f_raw;
	struct tty_dev * tty;
	int i;

	DCC_LOG_INIT();
	DCC_LOG_CONNECT();

	DCC_LOG(LOG_TRACE, "1. cm3_udelay_calibrate()");
	cm3_udelay_calibrate();

	DCC_LOG(LOG_TRACE, "2. thinkos_init()");
	thinkos_init(THINKOS_OPT_PRIORITY(8) | THINKOS_OPT_ID(7));

	DCC_LOG(LOG_TRACE, "usb_cdc_init()");
	cdc = usb_cdc_init(&stm32f_otg_fs_dev, *((uint64_t *)STM32F_UID));

	DCC_LOG(LOG_TRACE, "usb_cdc_fopen()");
	f_raw = usb_cdc_fopen(cdc);

	tty = tty_attach(f_raw);
	f_tty = tty_fopen(tty);

	for (i = 0; ;i++) {
//		usb_xmodem_recv(cdc);
		thinkos_sleep(2000);
		fprintf(f_tty, "[%d] hello world...\n", i);
	}


	return 0;
}
Beispiel #4
0
void main(void) 
{
  //we use PIN_C2 as an event to determine if we should start the USB CDC
  //bootloader.  if it is not low (button is not pressed) then goto the 
  //application, else if is low (button is pressed) then do the bootloader.
  output_bit(PIN_C2, 1);

  if(!input(PIN_C2))
  {
    setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);

    //Max7219 Initialized
    initLedDriver();

    g_InBootloader = TRUE;
    usb_cdc_init();
    usb_init();
    while(!usb_enumerated());
    load_program();
  }

  g_InBootloader = FALSE;
#ASM
  goto APPLICATION_START
#ENDASM
}
Beispiel #5
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);
}
Beispiel #6
0
void main() {
    unsigned int8 d;	// delay value
    unsigned int8 i;	
    unsigned int8 obyte=0;
    int16 spin;		// pwm 0->1023
    char c;

    // port D (7:0) SW,DW SZ,DZ SY,DY SX,DX

    init();

    usb_cdc_init();
    usb_init();
    usb_wait_for_enumeration();

    while (TRUE) {

	// get chars from usb
	housekeep();

	// now process the input and feed output queue
        if (nqueue(&rxque0) > 0) {
	   c = dequeue(&rxque0);
	   if ((c&0xf0) == 0x90) {		// step code
              obyte &= 0x55;	// zero step bits
	      if (c&XMASK) { obyte|= 0x02; } 
	      if (c&YMASK) { obyte|= 0x08; } 
	      if (c&ZMASK) { obyte|= 0x20; } 
	      if (c&WMASK) { obyte|= 0x80; } 
	      feed(obyte);
	   } else if ((c&0x80)==0) {	 	// delay code
	      d = ((unsigned int8)c)&0x7f;
	      for (i=1; i<=d; i++) {
	         feed(0x00);	// stall
	      }
	   } else if ((c&0xf0) == 0x80) {	// dir code
              obyte &= 0xaa;	// zero dir bits
	      if (c&XMASK) { obyte|= 0x01; } 
	      if (c&YMASK) { obyte|= 0x04; } 
	      if (c&ZMASK) { obyte|= 0x10; } 
	      if (c&WMASK) { obyte|= 0x40; } 
	   } else if ((c&0xf0) == 0xa0) {	
	      if ((c&0x08)) {
		  d = ((unsigned int8)c)&0x07;
		  enable(d);			// state
	      } else {
		  d = ((unsigned int8)c)&0x07;
		  set_step(d);			// mode
	      }
	   } else if ((c&0xc0) == 0xc0) {	// spindle PWM speed	
	       spin=c&0x3f;	// get the bits 
	       spin = spin<<4;
	       set_pwm1_duty(spin);	// duty cycle is val/(4*(255+1))
	   } else {
	      ; // unknown code, silently ignore
	   }
        } 
    }
}
Beispiel #7
0
int main(int argc, char ** argv)
{
	usb_cdc_class_t * cdc;

	DCC_LOG_INIT();
	DCC_LOG_CONNECT();

	DCC_LOG(LOG_TRACE, "1. cm3_udelay_calibrate()");
	cm3_udelay_calibrate();

	DCC_LOG(LOG_TRACE, "2. thinkos_init()");
	thinkos_init(THINKOS_OPT_PRIORITY(8) | THINKOS_OPT_ID(7));

	DCC_LOG(LOG_TRACE, "3. io_init()");
	io_init();

	DCC_LOG(LOG_TRACE, "4. external_bus_init()");
	external_bus_init();

	DCC_LOG(LOG_TRACE, "5. stdio_init()");
	stdio_init();
	printf("\n---\n");

	DCC_LOG(LOG_TRACE, "6. trace_init()");
	trace_init();

	DCC_LOG(LOG_TRACE, "7. env_init()");
	env_init();

	/* create some threads */
	DCC_LOG(LOG_TRACE, "8. monitor_init()");
	monitor_init();

	DCC_LOG(LOG_TRACE, "9. watchdog_init()");
	watchdog_init();

	DCC_LOG(LOG_TRACE, "10. net_init()");
	net_init();

	DCC_LOG(LOG_TRACE, "11. pkt_xmt_init()");
	pkt_xmt_init();
	net_pkt_mode(true);

	DCC_LOG(LOG_TRACE, "12. console_shell_init()");
	console_shell_init();

	DCC_LOG(LOG_TRACE, "13. usb_cdc_init()");
	usb_cdc_sn_set(*((uint64_t *)STM32F_UID));
	cdc = usb_cdc_init(&stm32f_otg_fs_dev, 
					   cdc_acm_def_str, 
					   cdc_acm_def_strcnt);

	DCC_LOG(LOG_TRACE, "14. usb_shell()");
	for (;;) {
		usb_shell(cdc);
	}
}
Beispiel #8
0
int usb_task(void * arg)
{
	uint64_t  esn = *((uint64_t *)STM32F_UID);
	usb_cdc_class_t * cdc;
	struct tty_dev * tty;
	FILE * f_tty;
	FILE * f_raw;

	DCC_LOG(LOG_TRACE, "usb_cdc_init()");
	usb_cdc_sn_set(esn);
	cdc = usb_cdc_init(&stm32f_otg_fs_dev, cdc_acm_str, 
					   cdc_acm_strcnt);

	f_raw = usb_cdc_fopen(cdc);

	tty = tty_attach(f_raw);
	f_tty = tty_fopen(tty);

	for (;;) {
		shell(f_tty, yard_ice_get_prompt, yard_ice_greeting, yard_ice_cmd_tab);
	}
}
Beispiel #9
0
int
main (void)
{
    led_t leds[LEDS_NUM];
    usb_cdc_t usb_cdc;
    int i;

    /* Initialise LEDs.  */
    for (i = 0; i < LEDS_NUM; i++)
	leds[i] = led_init (&leds_cfg[i]);

    led_set (leds[0], 0);
    led_set (leds[1], 0);
    led_set (leds[2], 0);

    usb_cdc = usb_cdc_init ();
    
    sys_redirect_stdin ((void *)usb_cdc_read, usb_cdc);
    sys_redirect_stdout ((void *)usb_cdc_write, usb_cdc);
    sys_redirect_stderr ((void *)usb_cdc_write, usb_cdc);

    tcm8230_init (&cfg);

    /* Wait until USB configured.  */
    while (! usb_cdc_update ())
        continue;

    led_set (leds[0], 1);

    while (1)
    {
        int32_t ret;

        led_set (leds[1], 1);
        while ( tcm8230_frame_ready_p ())
            continue;

        led_set (leds[1], 0);
        while (! tcm8230_frame_ready_p ())
            continue;

        led_set (leds[1], 1);

        ret = tcm8230_capture (image, sizeof(image), 200);

        if (usb_cdc_update ())
        {
            led_set (leds[0], 1);
            led_set (leds[2], 1);

            if (ret < 0)
                fprintf (stderr, "TCM8230 error: %d\r\n", (int)ret);
            else
                image_dump(image, SQCIF_HEIGHT, SQCIF_WIDTH);
            led_set (leds[2], 0);
        }
        else
        {
            /* USB disconnected.  */
            led_set (leds[0], 0);
        }
    }
}
Beispiel #10
0
ErrorCode_t usb_init(void)
{
  uint32_t i;
  uint32_t uid[4];

  /* HARDWARE INIT */

  /* Enable AHB clock to the USB block and USB RAM. */
  LPC_SYSCON->SYSAHBCLKCTRL |= ((0x1<<14) | (0x1<<27));

  /* Pull-down is needed, or internally, VBUS will be floating. This is to
  address the wrong status in VBUSDebouncing bit in CmdStatus register.  */
  LPC_IOCON->PIO0_3   &= ~0x1F;
  LPC_IOCON->PIO0_3   |= (0x01<<0);            /* Secondary function VBUS */
  LPC_IOCON->PIO0_6   &= ~0x07;
  LPC_IOCON->PIO0_6   |= (0x01<<0);            /* Secondary function SoftConn */

  for (i=0; i < strlen(CFG_USB_STRING_MANUFACTURER); i++)
    USB_StringDescriptor.strManufacturer[i] = CFG_USB_STRING_MANUFACTURER[i];

  for (i=0; i < strlen(CFG_USB_STRING_PRODUCT); i++)
    USB_StringDescriptor.strProduct[i] = CFG_USB_STRING_PRODUCT[i];

  /* Use the 128-bit chip ID for USB serial to make sure it's unique */
  iapReadUID(uid);  /* 1st byte is LSB, 4th byte is MSB */
  sprintf((char*)USB_StringDescriptor.strSerial , "%08X%08X%08X%08X", (unsigned int)uid[3], (unsigned int)uid[2], (unsigned int)uid[1], (unsigned int)uid[0]);
  for (i = USB_STRING_SERIAL_LEN-1; i > 0; i--)
  {
    USB_StringDescriptor.strSerial[i] = ((uint8_t*)USB_StringDescriptor.strSerial)[i];
    ((uint8_t*)USB_StringDescriptor.strSerial)[i] = 0;
  }

  /* ROM DRIVER INIT */
  uint32_t membase = (uint32_t) usb_RomDriver_buffer;
  uint32_t memsize = USB_ROM_SIZE;

  USBD_API_INIT_PARAM_T usb_param =
    {
    .usb_reg_base        = LPC_USB_BASE,
    .max_num_ep          = USB_MAX_EP_NUM,
    .mem_base            = membase,
    .mem_size            = memsize,

    .USB_Configure_Event = USB_Configure_Event,
    .USB_Reset_Event     = USB_Reset_Event
  };

  USB_CORE_DESCS_T DeviceDes =
  {
    .device_desc      = (uint8_t*) &USB_DeviceDescriptor,
    .string_desc      = (uint8_t*) &USB_StringDescriptor,
    .full_speed_desc  = (uint8_t*) &USB_FsConfigDescriptor,
    .high_speed_desc  = (uint8_t*) &USB_FsConfigDescriptor,
    .device_qualifier = NULL
  };

  /* Start USB hardware initialisation */
  ASSERT_USB_STATUS(USBD_API->hw->Init(&g_hUsb, &DeviceDes, &usb_param));

  membase += (memsize - usb_param.mem_size);
  memsize = usb_param.mem_size;

  /* Initialise the class driver(s) */
  #ifdef CFG_USB_CDC
    ASSERT_USB_STATUS( usb_cdc_init(g_hUsb, &USB_FsConfigDescriptor.CDC_CCI_Interface,
            &USB_FsConfigDescriptor.CDC_DCI_Interface, &membase, &memsize) );
  #endif

  #ifdef CFG_USB_HID_KEYBOARD
    ASSERT_USB_STATUS( usb_hid_init(g_hUsb , &USB_FsConfigDescriptor.HID_KeyboardInterface ,
            HID_KeyboardReportDescriptor, USB_FsConfigDescriptor.HID_KeyboardHID.DescriptorList[0].wDescriptorLength,
            &membase , &memsize) );
  #endif

  #ifdef CFG_USB_HID_MOUSE
    ASSERT_USB_STATUS( usb_hid_init(g_hUsb , &USB_FsConfigDescriptor.HID_MouseInterface    ,
            HID_MouseReportDescriptor, USB_FsConfigDescriptor.HID_MouseHID.DescriptorList[0].wDescriptorLength,
            &membase , &memsize) );
  #endif

  #ifdef CFG_USB_HID_GENERIC
    ASSERT_USB_STATUS( usb_hid_init(g_hUsb , &USB_FsConfigDescriptor.HID_GenericInterface    ,
            HID_GenericReportDescriptor, USB_FsConfigDescriptor.HID_GenericHID.DescriptorList[0].wDescriptorLength,
            &membase , &memsize) );
  #endif

  #ifdef CFG_USB_MSC
    // there is chance where SD card is not inserted, thus the msc init fails, should continue instead of return
    if ( usb_msc_init(g_hUsb, &USB_FsConfigDescriptor.MSC_Interface, &membase, &memsize) != LPC_OK)
    {
      _PRINTF("MSC class fails to init\n");
    }
  #endif

  #ifdef CFG_USB_CUSTOM_CLASS
    ASSERT_USB_STATUS( usb_custom_init(g_hUsb, &USB_FsConfigDescriptor.Custom_Interface) );
  #endif

  /* Enable the USB interrupt */
  #if defined CFG_MCU_FAMILY_LPC11UXX
    NVIC_EnableIRQ(USB_IRQn);
  #elif defined CFG_MCU_FAMILY_LPC13UXX
    NVIC_EnableIRQ(USB_IRQ_IRQn);
  #else
    #error "No MCU defined"
  #endif

  /* Perform USB soft connect */
  USBD_API->hw->Connect(g_hUsb, 1);

  return LPC_OK;
}

/**************************************************************************/
/*!
    @brief Redirect the USB IRQ handler to the ROM handler
*/
/**************************************************************************/
void USB_IRQHandler(void)
{
  USBD_API->hw->ISR(g_hUsb);
}
Beispiel #11
0
int main(int argc, char ** argv)
{
	struct usb_cdc_class * cdc;
	struct serial_dev * serial;
	struct vcom vcom;
	int i;

	DCC_LOG_INIT();
	DCC_LOG_CONNECT();

	/* calibrate usecond delay loop */
	cm3_udelay_calibrate();

	DCC_LOG(LOG_TRACE, "1. io_init()");
	io_init();

	DCC_LOG(LOG_TRACE, "2. thinkos_init()");
	thinkos_init(THINKOS_OPT_PRIORITY(3) | THINKOS_OPT_ID(3));

	leds_init();

	cdc = usb_cdc_init(&stm32f_usb_fs_dev, cdc_acm_str, 
					   cdc_acm_strcnt);

	serial = serial2_open();

	vcom.serial = serial;
	vcom.cdc = cdc;
	vcom.mode = VCOM_MODE_NONE;

	thinkos_thread_create((void *)led_task, (void *)NULL,
						  led_stack, sizeof(led_stack) |
						  THINKOS_OPT_PRIORITY(1) | THINKOS_OPT_ID(1));


	thinkos_thread_create((void *)serial_recv_task, 
						  (void *)&vcom,
						  serial_recv_stack, sizeof(serial_recv_stack) |
						  THINKOS_OPT_PRIORITY(0) | THINKOS_OPT_ID(0));

	thinkos_thread_create((void *)serial_ctrl_task, 
						  (void *)&vcom,
						  serial_ctrl_stack, sizeof(serial_ctrl_stack) |
						  THINKOS_OPT_PRIORITY(2) | THINKOS_OPT_ID(2));

	usb_vbus(true);

	for (i = 0; i < 5; ++i) {
		led_on(LED_AMBER);
		thinkos_sleep(100);
		led_off(LED_AMBER);
		led_on(LED_RED);
		thinkos_sleep(100);
		led_off(LED_RED);
	}


	for (;;) {
		usb_recv_task(&vcom);
	}
}
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;
         
      }
   }
}