int check_private_part(int keyvalue)
{
	int ret;

	ret = wBoot_part_info("DISK", "private", &part_info);
	if(!ret)
	{
//		int  buffer[1024/4];
//		int  i;

		__inf("find private part\n");
//		if(!wBoot_block_read(part_info.addr + 1024 * 1024/512, 2, buffer))
//		{
//			for(i=0;i<1024/4;i++)
//			{
//				if(!(buffer[i] == -1))
//				{
//					__inf("value is bad\n");
//					return -1;
//				}
//			}
//		}
		if(!usb_decect_key(keyvalue))
		{
			usb_start(1);
    		usb_run();
		}
	}

	return 0;
}
Пример #2
0
static void usbtest_entry(const struct app_descriptor *app, void *args)
{
    LTRACE_ENTRY;

    TRACEF("starting usb stack\n");
    usb_start();

    // XXX get callback from stack
    thread_sleep(2000);

    TRACEF("queuing transfers\n");
    queue_rx_transfer();
    queue_tx_transfer();

    while (event_wait(&testevent) == NO_ERROR) {
        if (!rxqueued) {
            /* dump the state of the transfer */
            LTRACEF("rx transfer completed\n");
            usbc_dump_transfer(&rx);
            hexdump8(rx.buf, MIN(128, rx.bufpos));

            queue_rx_transfer();
        }
        if (!txqueued) {
            /* dump the state of the transfer */
            LTRACEF("tx transfer completed\n");
            usbc_dump_transfer(&tx);

            queue_tx_transfer();
        }
    }

    LTRACE_EXIT;
}
Пример #3
0
static void startUSB()
{
	usb_setup();
	usb_install_ep_handler(4, USBOut, controlReceived, 0);
	usb_install_ep_handler(2, USBOut, dataReceived, 0);
	usb_install_ep_handler(3, USBIn, controlSent, 0);
	usb_install_ep_handler(1, USBIn, dataSent, 0);
	usb_start(enumerateHandler, startHandler);
}
Пример #4
0
static EFI_STATUS fastboot_usb_start(start_callback_t start_cb,
				     data_callback_t rx_cb,
				     data_callback_t tx_cb)
{
	return usb_start(FASTBOOT_IF_SUBCLASS, FASTBOOT_IF_PROTOCOL,
			 FASTBOOT_STR_CONFIGURATION,
			 FASTBOOT_STR_INTERFACE,
			 start_cb, rx_cb, tx_cb);
}
Пример #5
0
Файл: usb.c Проект: 0xBADCA7/lk
void target_usb_setup(void)
{
    usb_setup(&config);

    append_usb_interfaces();

    usb_add_string("LK", 1);
    usb_add_string("LK Industries", 2);

    usb_start();
}
Пример #6
0
// MAIN TASK INITIALIZATIOON
result_t Task_SmartPHTApp_Init(void)
{
    result_t result;

    adc_init();

    rtc_initialize();
    rtc_set(&statusBarData.time);

    RESULT_CHECK( ioexp_initialize(), result);
    RESULT_CHECK( touch_initialize(), result);

    battery_init();
    battery_enable_usb_charger(bTrue);
    battery_enable_ac_charger(bTrue);
    
    install_event_handlers();
    gui_set_current_view(&view_dashboard);

    // Initialize USB
    initCDC(); // setup the CDC state machine
    usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS); // initialize USB. TODO: Remove magic with macro
    usb_start(); //start the USB peripheral
    EnableUsbPerifInterrupts(USB_TRN + USB_SOF + USB_UERR + USB_URST);
    EnableUsbGlobalInterrupt(); // Only enables global USB interrupt. Chip interrupts must be enabled by the user (PIC18)

    sensor_init();

    reset_minmax();
    reset_alarms();

    // Reset waveforms
    wfrm_clear(&wfrmPressure);
    wfrm_clear(&wfrmHumidity);
    wfrm_clear(&wfrmTemperature);

    // Set plot scale
    lineplot_set_sample_per(&lineplot, &supportedSamplingPeriods[sliderSampPeriodData.value]);

    // Default sensor
    checkable_set_checked(&btnSelInterface0, bTrue);

    return RV_OK;
}
int main(void)
#endif
{
    BYTE RecvdByte;

    initCDC(); // setup the CDC state machine
    SetupBoard(); //setup the hardware, customize for your hardware
    usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS); // initialize USB. TODO: Remove magic with macro
    usb_start(); //start the USB peripheral

// PIC18 INTERRUPTS
// It is the users resposibility to set up high, low or legacy mode
// interrupt operation. The following macros for high and low interrupt
// setup have been removed:

//#define EnableUsbHighPriInterrupt()             do { RCONbits.IPEN = 1; IPR2bits.USBIP = 1; INTCONbits.GIEH = 1;} while(0) // JTR new
//#define EnableUsbLowPriInterrupt()              do { RCONbits.IPEN = 1; IPR2bits.USBIP = 0; INTCONbits.GIEL = 1;} while(0)  // JTR new

// By default, the interrupt mode will be LEGACY (ISR Vector 0x08)
// (Same as high priority vector wise but the operation (latency) is
// not the same. Consult the data sheet for details.)

// If a priority mode is enabled then this affects ALL other interrupt
// sources therefore it does not belong to the usb stack to be
// doing this. It is a global, user application choice.

#if defined USB_INTERRUPTS // See the prj_usb_config.h file.
    EnableUsbPerifInterrupts(USB_TRN + USB_SOF + USB_UERR + USB_URST);
#if defined __18CXX //turn on interrupts for PIC18
    INTCONbits.PEIE = 1;
    INTCONbits.GIE = 1;
#endif
    EnableUsbGlobalInterrupt(); // Only enables global USB interrupt. Chip interrupts must be enabled by the user (PIC18)
#endif


// Wait for USB to connect
    do {
#ifndef USB_INTERRUPTS
        usb_handler();
#endif
    } while (usb_device_state < CONFIGURED_STATE);

    usb_register_sof_handler(CDCFlushOnTimeout); // Register our CDC timeout handler after device configured

// Main echo loop
    do {

// If USB_INTERRUPT is not defined each loop should have at least one additional call to the usb handler to allow for control transfers.
#ifndef USB_INTERRUPTS
        usb_handler();
#endif

// Receive and send method 1
// The CDC module will call usb_handler each time a BULK CDC packet is sent or received.
// If there is a byte ready will return with the number of bytes available and received byte in RecvdByte
        if (poll_getc_cdc(&RecvdByte)) 
            putc_cdc(RecvdByte+1); //

// Receive and send method 2
// Same as poll_getc_cdc except that byte is NOT removed from queue.
// This function will wait for a byte and return and remove it from the queue when it arrives.
        if (peek_getc_cdc(&RecvdByte)) { 
            RecvdByte = getc_cdc(); 
            putc_cdc(RecvdByte+1);
        }

// Receive and send method 3
// If there is a byte ready will return with the number of bytes available and received byte in RecvdByte
// use CDC_Flush_In_Now(); when it has to be sent immediately and not wait for a timeout condition.
        if (poll_getc_cdc(&RecvdByte)) { 
            putc_cdc(RecvdByte+1); //
            CDC_Flush_In_Now(); 
        }
    } while (1);

} //end main
Пример #8
0
void Initialize(void) {
#if defined (BUSPIRATEV2)
	unsigned char i;
#endif

    volatile unsigned long delay = 0xffff;

    //   volatile unsigned long delay = 0xffff;
    // TBLPAG = 0; // we need to be in page 0 (somehow this isn't set)
#if defined (BUSPIRATEV2) || defined (BUSPIRATEV1A)
    CLKDIVbits.RCDIV0 = 0; //clock divider to 0
    AD1PCFG = 0xFFFF; // Default all pins to digital
#elif defined (BUSPIRATEV4)
    INTCON1bits.NSTDIS = 1;
    CLKDIV = 0x0000; // Set PLL prescaler (1:1)
    BP_LEDUSB_DIR = 0; // output
    CORCONbits.PSV = 1; // JTR PIC24 fixup ?? PSV not being initialized. May have been done by c_init though.
    PSVPAG = 0; //
    OSCCONbits.SOSCEN = 0;
    AD1PCFGL = 0x7FD8; //BUSPIRATEV4 has five analog pins b0, b1, b2, b5, b15
    AD1PCFGH = 0x2;
    // usb_register_sof_handler(0);
#endif

    OSCCONbits.SOSCEN = 0;


    while (delay--);
    //set pin configuration using peripheral pin select
#if defined (BUSPIRATEV2) || defined (BUSPIRATEV1A)
    BP_TERM_RX = BP_TERM_RX_RP; //Inputs UART1 RX RPINR18bits.U1RXR=4;
    BP_TERM_TX_RP = BP_TERM_TX; // Outputs UART1 TX RPOR1bits.RP3R=U1TX_IO;
#elif defined (BUSPIRATEV4) && defined (BPV4_DEBUG)
    BP_TERM_RX = BP_TERM_RX_RP; //Inputs UART1 RX RPINR18bits.U1RXR=11;//AUX2
    BP_TERM_TX_RP = BP_TERM_TX; // Outputs UART1 TX RPOR1bits.RP2R=U1TX_IO;//AUX1
#endif

    //put startup values in config (do first)
    bpConfig.termSpeed = 8; //default PC side port speed, startup in 115200, or saved state (later)....
    bpConfig.displayMode = HEX;

    bpInit(); //put startup values in config (do first)clean up, exit in HI-Z

#if defined (BUSPIRATEV2) || defined (BUSPIRATEV1A)
    InitializeUART1(); //init the PC side serial port
#endif

#if defined (BUSPIRATEV4) && !defined (BPV4_DEBUG)
    initCDC();
    usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS);
    usb_start();
#endif

#if defined (BUSPIRATEV4) && defined (BPV4_DEBUG)
    InitializeUART1(); //init the PC side serial port
#endif

#if defined (BUSPIRATEV2)
    //find the Bus Pirate revision
    //pullup on, do it now so it can settle during the next operations
    CNPU1bits.CN6PUE = 1;
    CNPU1bits.CN7PUE = 1;
#endif
    //#ifndef BUSPIRATEV4
    // Get the chip type and revision
    bpConfig.dev_type = bpReadFlash(DEV_ADDR_UPPER, DEV_ADDR_TYPE);
    bpConfig.dev_rev = bpReadFlash(DEV_ADDR_UPPER, DEV_ADDR_REV);
    //#endif

#if defined (BUSPIRATEV2)
    //now check the revision
	//Version | RB3 | RB2
	//2go, 3a | 1   |  1
	//v3b     | 1   |  0
	//v3.5    | 0   |  0
	i=PORTB; //get settings
	i=i>>2; //remove unused
	i&=(~0b11111100); //clear others
    if (i==0b11) {
        bpConfig.HWversion = 'a';
    } else if(i==0b10){
        bpConfig.HWversion = 'b';
    }else if(i==0){
        bpConfig.HWversion = '5';
	}
    //pullup off
    CNPU1bits.CN6PUE = 0;
    CNPU1bits.CN7PUE = 0;
#else
    bpConfig.HWversion = 0;
#endif

    bpConfig.quiet = 0; // turn output on (default)
    modeConfig.numbits = 8;
#ifdef BP_USE_BASIC
    initpgmspace();
#endif

    TBLPAG = 0; // we need to be in page 0 (somehow this isn't set)

#ifndef BUSPIRATEV4
    bpWBR; //send a line feed
    versionInfo(); //prints hardware and firmware version info (base.c)
#endif

}
Пример #9
0
int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
			    int (*bind)(struct usb_gadget *))
{
	struct usb_info *ui = the_usb_info;
	int			retval, n;

	if (!driver
			|| driver->speed < USB_SPEED_FULL
			|| !bind
			|| !driver->disconnect
			|| !driver->setup)
		return -EINVAL;
	if (!ui)
		return -ENODEV;
	if (ui->driver)
		return -EBUSY;

	/* first hook up the driver ... */
	ui->driver = driver;
	ui->gadget.dev.driver = &driver->driver;
	ui->gadget.name = driver_name;
	INIT_LIST_HEAD(&ui->gadget.ep_list);
	ui->gadget.ep0 = &ui->ep0in.ep;
	INIT_LIST_HEAD(&ui->gadget.ep0->ep_list);
	ui->gadget.speed = USB_SPEED_UNKNOWN;

	for (n = 1; n < 16; n++) {
		struct msm_endpoint *ept = ui->ept + n;
		list_add_tail(&ept->ep.ep_list, &ui->gadget.ep_list);
		ept->ep.maxpacket = 512;
	}
	for (n = 17; n < 32; n++) {
		struct msm_endpoint *ept = ui->ept + n;
		list_add_tail(&ept->ep.ep_list, &ui->gadget.ep_list);
		ept->ep.maxpacket = 512;
	}

	retval = device_add(&ui->gadget.dev);
	if (retval)
		goto fail;

	retval = bind(&ui->gadget);
	if (retval) {
		INFO("bind to driver %s --> error %d\n",
				driver->driver.name, retval);
		device_del(&ui->gadget.dev);
		goto fail;
	}

#ifdef CONFIG_USB_HTC_SWITCH_STUB
	retval = device_create_file(ui->gadget.dev.parent,
			&dev_attr_usb_function_switch);
#endif

	/* create sysfs node for remote wakeup */
	retval = device_create_file(&ui->gadget.dev, &dev_attr_wakeup);
	if (retval != 0)
		INFO("failed to create sysfs entry: (wakeup) error: (%d)\n",
					retval);
	INFO("msm72k_udc: registered gadget driver '%s'\n",
			driver->driver.name);
	usb_start(ui);

	return 0;

fail:
	ui->driver = NULL;
	ui->gadget.dev.driver = NULL;
	return retval;
}
Пример #10
0
void initialize_board(void) {
  volatile unsigned long delay = 0xFFFF;

#ifdef BUSPIRATEV3
  /* Set clock divider to 0. */
  CLKDIVbits.RCDIV0 = 0;

  /* All pins are digital. */
  AD1PCFG = 0xFFFF;
#elif defined(BUSPIRATEV4)

  /* Disable nested interrupts. */
  INTCON1bits.NSTDIS = ON;

  /* Set PLL prescaler to 1:1 ratio. */
  CLKDIV = 0x0000;
  BP_LEDUSB_DIR = OUTPUT;

  /* Initialize program space visibility. */
  CORCONbits.PSV = ON;

  /* Map top part of the firmware. */
  PSVPAG = 0;

  /* Disable secondary oscillator. */
  OSCCONbits.SOSCEN = OFF;

  /* Set pins B0, B1, B2, B5, and B15 as analog, rest are digital. */
  AD1PCFGL = 0x7FD8;

  /* Only enable Vbg/2 channel for input scan. */
  AD1PCFGH = 0x0002;
#endif /* BUSPIRATEV3 || BUSPIRATEV4 */

  /* Disable secondary oscillator. */
  OSCCONbits.SOSCEN = OFF;

  /* Wait a bit. */
  while (delay--) {
  }

/* Set up the UART port pins. */

#ifdef BUSPIRATEV3
  BP_TERM_RX = BP_TERM_RX_RP;
  BP_TERM_TX_RP = BP_TERM_TX;
#endif /* BUSPIRATEV3 */

  /* Set the UART port speed to 115200 bps. */
  bus_pirate_configuration.terminal_speed = 8;

  /* Default to print numbers in hexadecimal format. */
  bus_pirate_configuration.display_mode = HEX;

  /* Start from a known, clear state. */
  bp_reset_board_state();

#ifdef BUSPIRATEV3
  /* Initialize the internal UART port. */
  user_serial_initialise();
#endif /* BUSPIRATEV3 */

#if defined(BUSPIRATEV4)

  /* Initialize the USB-based serial port. */

  initCDC();
  usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs,
           USB_NUM_STRINGS);
  usb_start();
#endif /* BUSPIRATEV4 */

#ifdef BUSPIRATEV3
  /* Turn pull-ups ON. */
  CNPU1bits.CN6PUE = ON;
  CNPU1bits.CN7PUE = ON;
#endif /* BUSPIRATEV3 */

  /* Read device type and revision. */

  bus_pirate_configuration.device_type =
      bp_read_from_flash(DEV_ADDR_UPPER, DEV_ADDR_TYPE);
  bus_pirate_configuration.device_revision =
      bp_read_from_flash(DEV_ADDR_UPPER, DEV_ADDR_REV);

#ifdef BUSPIRATEV3
  /* Get the revision identifier. */
  bus_pirate_configuration.hardware_version =
      BPV3_HARDWARE_VERSION_TABLE[(PORTB >> 2) & 0b00000011];

  /* Turn pull-ups OFF. */
  CNPU1bits.CN6PUE = OFF;
  CNPU1bits.CN7PUE = OFF;
#else
  bus_pirate_configuration.hardware_version = 0;
#endif /* BUSPIRATEV3 */

  bus_pirate_configuration.quiet = OFF;
  mode_configuration.numbits = 8;

#ifdef BP_ENABLE_BASIC_SUPPORT
  bp_basic_initialize();
#endif /* BP_ENABLE_BASIC_SUPPORT */

  /* Move to page #0. */
  TBLPAG = 0;

#ifndef BUSPIRATEV4
  bpBR;
  print_version_info();
#endif /* !BUSPIRATEV4 */
}
Пример #11
0
void main(void) {
    static BYTE ledtrig;
    BYTE OutByte;

    SetupBoard(); //setup the hardware, USB
    SetupRC5();
    usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS); // TODO: Remove magic with macro
    initCDC(); // JTR this function has been highly modified It no longer sets up CDC endpoints.
    usb_start();
    //usbbufflush(); //flush USB input buffer system

    ledtrig = 1; //only shut LED off once
    //	Never ending loop services each task in small increments
    while (1) {
        do {
           // if (!TestGlobalUsbInterruptEnabled()) //JTR3 added
                usb_handler(); ////service USB tasks Guaranteed one pass in polling mode even when usb_device_state == CONFIGURED_STATE
            if ((usb_device_state < DEFAULT_STATE)) { // JTR2 no suspendControl available yet || (USBSuspendControl==1) ){
                LedOff();
            } else if (usb_device_state < CONFIGURED_STATE) {
                LedOff();
            } else if ((ledtrig == 1) && (usb_device_state == CONFIGURED_STATE)) {
               // LedOn();
                ledtrig = 0;
            }
        } while(usb_device_state < CONFIGURED_STATE);

        //TRISB &= 0x7f;
        //TRISB |= 0x40;
        //LATB |= 0x40;

        //mode = IRWIDGET;
        //irWidgetservice();

#ifdef UARTONLY
        //mode = USB_UART;
        Usb2UartService(); // Never returns
#endif

        // Test for commands: 0, 1, 2 (Entry to SUMP MODE.)
        // Do not remove from input buffer, just take a PEEK.
        // SUMPLogicCommand will remove from input buffer
        // (Standardized coding)

        if (peek_getc_cdc(&OutByte)) {
            switch (OutByte) {
                case 0: //SUMP clear
                case 1: //SUMP run
                case 2: //SUMP ID
                    mode = IR_SUMP; //put IR Toy in IR_SUMP mode
                    irSUMPservice(); // Fully self contained, does not return until exited via 0x00 command.
                    cdc_In_len = 0;
                    mode = IR_DECODER;
                    SetupRC5();
                    break;

                case 'r': //IRMAN decoder mode
                case 'R':
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    SetupRC5();
                    mode = IR_DECODER;
                    putc_cdc('O');
                    putc_cdc('K');
                    CDC_Flush_In_Now();
                    break;
                case 'S': //IRs Sampling Mode
                case 's':
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    mode = IR_S;
                    irsService(); // Fully self contained, does not return until exited via 0x00 command.
                    cdc_In_len = 0;
                    mode = IR_DECODER;
                    SetupRC5();
                    break;
                case 'U':
                case 'u':
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    mode = USB_UART;
                    Usb2UartService();
                    break;
                case 'P':
                case 'p':// IR Widget mode
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    mode = IRWIDGET;
                    GetPulseFreq(); // Never returns
                    //GetPulseTime();
                    break;

                case 'T':
                case 't'://self test
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    SelfTest(); //run the self-test
                    break;
                case 'V':
                case 'v':// Acquire Version
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    GetUsbIrToyVersion();
                    break;
                case '$'://bootloader jump
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    BootloaderJump();
                    break;

                default:
                    OutByte = getc_cdc();

            }//switch(OutByte
        } // if peek OutByte == 1
        ProcessIR(); //increment IR decoder state machine
    }//end while(1)
}//end main
Пример #12
0
int usb_gadget_register_driver(struct usb_gadget_driver *driver)
{
	struct usb_info *ui = the_usb_info;
	int			retval, n;

	if (!driver
			|| driver->speed < USB_SPEED_FULL
			|| !driver->bind
			|| !driver->disconnect
			|| !driver->setup)
		return -EINVAL;
	if (!ui)
		return -ENODEV;
	if (ui->driver)
		return -EBUSY;

	/* first hook up the driver ... */
	ui->driver = driver;
	ui->gadget.dev.driver = &driver->driver;
	ui->gadget.name = driver_name;
	INIT_LIST_HEAD(&ui->gadget.ep_list);
	ui->gadget.ep0 = &ui->ep0in.ep;
	INIT_LIST_HEAD(&ui->gadget.ep0->ep_list);
	ui->gadget.speed = USB_SPEED_UNKNOWN;

	for (n = 1; n < 16; n++) {
		struct msm_endpoint *ept = ui->ept + n;
		list_add_tail(&ept->ep.ep_list, &ui->gadget.ep_list);
		ept->ep.maxpacket = 512;
	}
	for (n = 17; n < 32; n++) {
		struct msm_endpoint *ept = ui->ept + n;
		list_add_tail(&ept->ep.ep_list, &ui->gadget.ep_list);
		ept->ep.maxpacket = 512;
	}

	retval = device_add(&ui->gadget.dev);
	if (retval)
		goto fail;

	retval = driver->bind(&ui->gadget);
	if (retval) {
		INFO("bind to driver %s --> error %d\n",
				driver->driver.name, retval);
		device_del(&ui->gadget.dev);
		goto fail;
	}

	/* create sysfs node for remote wakeup */
	retval = device_create_file(&ui->gadget.dev, &dev_attr_wakeup);
	if (retval != 0)
		INFO("failed to create sysfs entry: (wakeup) error: (%d)\n",
					retval);
	retval = device_create_file(&ui->gadget.dev, &dev_attr_usb_state);
	if (retval != 0)
		INFO("failed to create sysfs entry: (usb_state) error: (%d)\n",
					retval);
	retval = device_create_file(&ui->gadget.dev, &dev_attr_usb_speed);
	if (retval != 0)
		INFO("failed to create sysfs entry: (usb_speed) error: (%d)\n",
					retval);
	INFO("msm72k_udc: registered gadget driver '%s'\n",
			driver->driver.name);

	retval = device_create_file(&ui->gadget.dev, &dev_attr_chg_type);
	if (retval != 0)
		dev_err(&ui->pdev->dev,
			"failed to create sysfs entry(chg_type): err:(%d)\n",
					retval);
	retval = device_create_file(&ui->gadget.dev, &dev_attr_chg_current);
	if (retval != 0)
		dev_err(&ui->pdev->dev,
			"failed to create sysfs entry(chg_current):"
			"err:(%d)\n", retval);
	usb_start(ui);

	return 0;

fail:
	ui->driver = NULL;
	ui->gadget.dev.driver = NULL;
	return retval;
}
Пример #13
0
void main(void)
{
    unsigned char c,x,y,led;
    unsigned long l;
    
	  // Default all pins to digital
    ADCON1 |= 0x0F;

    // Disable USB external transceiver to allow RB1/RB2
    UCFGbits.UTRDIS = 0;
    
    // set pin to output
    TRISBbits.TRISB0 = 0;
    TRISBbits.TRISB1 = 0;
    TRISBbits.TRISB2 = 0;
    TRISBbits.TRISB3 = 0;

    LED0 = 1;
    LED1 = LED2 = LED3 = 0;
    
    // TODO: Remove magic with macro
    usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS);
    usb_start();
    
    initCDC();
    usbbufflush();
    
    do {
        if (!TestUsbInterruptEnabled())
            USBDeviceTasks();

        switch(usb_device_state){
            case DETACHED_STATE:
                LED1 = 0; LED2 = 0; LED3 = 0;
            case ATTACHED_STATE:
                LED1 = 0; LED2 = 0; LED3 = 1;
            case POWERED_STATE:
                LED1 = 0; LED2 = 1; LED3 = 0;
            case DEFAULT_STATE:
                LED1 = 0; LED2 = 1; LED3 = 1;
            case ADR_PENDING_STATE:
                LED1 = 1; LED2 = 0; LED3 = 0;
            case ADDRESS_STATE:
                LED1 = 1; LED2 = 0; LED3 = 1;
            case CONFIGURED_STATE:
                LED1 = 1; LED2 = 1; LED3 = 0;
        }
    } while (usb_device_state < CONFIGURED_STATE);

    while(1);
#if 0

    // Initiate Osc with 8MHz (only relevant if you use the internal oscillator)
    //OSCCON = 0x70;
    
    
    
    initCDC();
    
    
    // TODO: Remove magic with macro
    usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS);

    usb_start();

#if defined (USB_INTERRUPTS)
    //EnableUsbInterrupt(USB_TRN + USB_SOF + USB_UERR + USB_URST);
    EnableUsbInterrupt(USB_STALL + USB_IDLE + USB_TRN + USB_ACTIV + USB_SOF + USB_UERR + USB_URST);
    EnableUsbInterrupts();
#endif

    usbbufflush(); //flush USB input buffer system

    led = UCFGbits.UTRDIS;
    
    
    LED0=0;
    LED1=0;
    LED2=0;
    LED3=0;
    
    while(1){
      LED1 = LED1 ? 0 : 1;
      for(l = 0; l < 10; ++l);
    }
    
    LED0=1;
    LED1=1;
    LED2=1;
    LED3=1;
    delay_ms(500);    
#if 0
    while(1)
    {
        LED0 = 1;
        delay_ms(250);
        LED0 = 0;
        delay_ms(250);
    }
#endif
    LED0 = 0;
    LED1 = 0;
    LED2 = 0;
    LED3 = 0;
    delay_ms(500);
    while(1);
    
    do
    {   LED2=1;
        LED3 = 0;
#ifndef USB_INTERRUPTS
        //service USB tasks
        //Guaranteed one pass in polling mode
        //even when usb_device_state == CONFIGURED_STATE
        if (!TestUsbInterruptEnabled())
        {
            USBDeviceTasks();
            LED3 = 1;
        }
#endif

        if ((usb_device_state < DEFAULT_STATE))
        { // JTR2 no suspendControl available yet || (USBSuspendControl==1) ){
          LED0=1;
          LED1=0;
        } else if (usb_device_state < CONFIGURED_STATE)
        {
          LED0=1;
          LED1=1;
        }else if((usb_device_state == CONFIGURED_STATE))
        {
          LED0=0;
          LED1=1;
        }
        LED2=0;
        delay_ms(1000);
    } while (usb_device_state < CONFIGURED_STATE);

    LED0 = 0;
    LED1 = 0;
    LED2 = 1;
    #if 1

    while(1)
    {
        LED0 = led;
        led = led ? 0 : 1;
#ifndef USB_INTERRUPTS
        //service USB tasks
        //Guaranteed one pass in polling mode
        //even when usb_device_state == CONFIGURED_STATE
        if (!TestUsbInterruptEnabled())
            USBDeviceTasks();
#endif
        usbbufservice(); //service USB buffer system

        if (usbbufgetbyte(&c) == 1)
        {
            WaitInReady();
            cdc_In_buffer[0] = c; //answer OK
            putUnsignedCharArrayUsbUsart(cdc_In_buffer, 1);
        }

    }
    
    #endif
    
    // Disable USB external transceiver to allow RB1/RB2
    UCFGbits.UTRDIS = 0;
    
    // set pin to output
    TRISBbits.TRISB0 = 0;
    TRISBbits.TRISB1 = 0;
    TRISBbits.TRISB2 = 0;
    
    // start a loop blinking the led
    while(1)
    {
        LED0 = 1;
        delay_ms(250);
        LED0 = 0;
        delay_ms(250);
    }
#endif
}
Пример #14
0
/*
*******************************************************************************
*                     BootMain
*
* Description:
*    BOOT主应用程序
*
* Parameters:
*    void
*
* Return value:
*    void
*
* note:
*    void
*
*******************************************************************************
*/
int BootMain(int argc, char **argv)
{
	__s32                 ret;
    int                   erase_flash;
	MBR					  mbr_info;
    boot_global_info_t   *global_info;

    DMSG_INFO("big firmware! here we go !\n");
	DMSG_INFO("Sprite start\n");
	{
		char ch;

		ch = wBoot_getc_delay( 1 );  // 27000000
	    __inf("%d\n", ch);

	    switch(ch)
	   	{
	   		case '1':
	   		{
	   			usb_start();
	    		usb_run();
	    		break;
	   		}
	   		case '2':
	   		{
	   			__inf("Jump to fel\n");
	   			wBoot_jump_fel( );
	   			break;
	   		}
	   		case '-':
	   		{
	   			__u32 dbg = 0x55;

	            __inf("hold\n");
		        while(dbg == 0x55);
		        break;
	   		}
	   		case '+':
	   		{
	   			force_debug = 1;
	        	break;
	   		}
	   		default:
	   			break;
	   	}
	}
	*(volatile unsigned int *)(0x1c20C00 + 0x118) = 0;
	*(volatile unsigned int *)(0x1c20C00 + 0x11C) = 3;
	//数据初始化
	memset(&board_res, 0, sizeof(boot_hardware_res));
    //申请内存,填充第一个启动脚本
    global_info = (boot_global_info_t *)wBoot_malloc(sizeof(boot_global_info_t));
    if(!global_info)
    {
        __wrn("unable to malloc memory for bootini\n");

        return -1;
    }
    //填充启动脚本
    memset(global_info, 0, sizeof(boot_global_info_t));
    ret = script_patch("c:\\boot.ini", global_info, 0);
    if(ret < 0)
    {
        __wrn("unable to parser boot.ini\n");

        return -1;
    }
    //初始化显示设备
    __inf("display init\n");
    cue = -1;
    if(boot_ui_init(global_info->display_device, global_info->display_mode) >= 0)
    {
    	//开启字符显示
    	__inf("char init\n");
    	boot_ui_char_init(0);
    	cue = 0;
    }
    sprite_led_init();
    sprite_wrn_init();
    //获取MBR信息
    __inf("mbr fetch\n");
	ret = card_mbr_info((void *)&mbr_info);
	if(ret < 0)
	{
		__wrn("unable to get mbr info\n");

        return -1;
	}
	boot_ui_check_device_open();
    
	ret = wBoot_script_parser_fetch("platform", "eraseflag", &erase_flash, 1);
	if((!ret) && (erase_flash))
	{
		erase_flash = 1;
	}
	else
	{
		erase_flash = 0;
	}
    
    //开始准备系统数据
    ret = card_sprite((void *)&mbr_info,erase_flash, cue);

	sprite_wrn_exit();
	sprite_led_exit(ret);
	if(!ret)
	{
		char	buffer[512];

		board_res.led_status[0] = CARD_SPRITE_SUCCESSED;
		sprite_wrn("CARD OK\n");

		__inf("get work mode\n");
		memset(buffer, 0, 512);
		wBoot_block_dread(15, 1, buffer);
		if(strcmp(buffer, "1234567890abcdefghijklmnopqrstuvwxyz"))
		{
			__inf("try to close\n");
			wBoot_timer_delay(3000);

			wBoot_power_set_off();
		}
		else
		{
			int ret;

			__inf("try to format\n");
			wBoot_timer_delay(500);
			ret = FormatDisk();
			__inf("format %d\n", ret);
			WATCHDOG_REG_MODE = 0x0;
			wBoot_timer_delay(500);
			WATCHDOG_REG_MODE = 0x3;
		}
	}
	else
	{
		board_res.led_status[0] = CARD_SPRITE_FAIL;
	}
	{
		__u32 dbg = 0x55;

		while(dbg == 0x55);
	}

    return 0;
}
Пример #15
0
int usb_setup(USBEnumerateHandler hEnumerate, USBStartHandler hStart)
{
	usb_shutdown();

	// This is not relevant to the hardware,
	// and usb_setup is called when setting up a new
	// USB protocol. So we should reset the EP
	// handlers here! -- Ricky26
	memset(endpoint_handlers, 0, sizeof(endpoint_handlers));
	startHandler = hStart;
	enumerateHandler = hEnumerate;
	setupHandler = NULL;

	if(usb_inited)
		return 0;

	if(controlSendBuffer == NULL)
		controlSendBuffer = memalign(DMA_ALIGN, CONTROL_SEND_BUFFER_LEN);

	if(controlRecvBuffer == NULL)
		controlRecvBuffer = memalign(DMA_ALIGN, CONTROL_RECV_BUFFER_LEN);

	InEPRegs = (USBEPRegisters*)(USB + USB_INREGS);
	OutEPRegs = (USBEPRegisters*)(USB + USB_OUTREGS);

	change_state(USBStart);

	initializeDescriptors();

	// Initialize our data structures
	memset(usb_message_queue, 0, sizeof(usb_message_queue));

#ifdef USB_PHY_1G
	// Power on hardware
	power_ctrl(POWER_USB, ON);
	udelay(USB_START_DELAYUS);
#else
	// Wait for USB hardware to come alive
	udelay(10000);
#endif

	// Set up the hardware
	clock_gate_switch(USB_OTGCLOCKGATE, ON);
	clock_gate_switch(USB_PHYCLOCKGATE, ON);

#ifdef USB_PHY_1G
	clock_gate_switch(EDRAM_CLOCKGATE, ON);
#endif

	// power on OTG
	SET_REG(USB + PCGCCTL, (GET_REG(USB + PCGCCTL) & (~PCGCCTL_ONOFF_MASK)) | PCGCCTL_ON);
	udelay(USB_ONOFFSTART_DELAYUS);

	// Generate a soft disconnect on host
	//SET_REG(USB + DCTL, GET_REG(USB + DCTL) | DCTL_SFTDISCONNECT);
	//udelay(USB_SFTDISCONNECT_DELAYUS);

	// Initialise PHY
	usb_phy_init();

	bufferPrintf("USB: Hardware Configuration\n"
		"    HWCFG1 = 0x%08x\n"
		"    HWCFG2 = 0x%08x\n"
		"    HWCFG3 = 0x%08x\n"
		"    HWCFG4 = 0x%08x\n",
		GET_REG(USB+GHWCFG1),
		GET_REG(USB+GHWCFG2),
		GET_REG(USB+GHWCFG3),
		GET_REG(USB+GHWCFG4));
	
	usb_inited = TRUE;
	interrupt_install(USB_INTERRUPT, usbIRQHandler, 0);

	// Start USB
	usb_start();
	return 0;
}
void main(void){  
	u8 i,cmd, param[9],c;
	u16 temp; // TODO to be removed later on
	long l;
	signed int x, y, z;
	signed char x8, y8, z8;
	static unsigned char ledtrig;

    initCDC(); // JTR this function has been highly modified It no longer sets up CDC endpoints.

    init();			//setup the crystal, pins
    mma_init();

    usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS); // TODO: Remove magic with macro
    usb_start();
    usbbufflush(); //flush USB input buffer system



    i = mma_read( MMA_I2CAD );
	//if((i&~0b10000000)!=0x1d)while(1);
    mma_write( MMA_I2CAD, 0x1d | MMA_I2CDIS_bit ); // disable I2C

    i = mma_read( MMA_CTL1 );
    mma_write( MMA_CTL1, i |= MMA_DFBW_bit ); // high output data rate

    mma_write( MMA_MCTL, 0b00000101 ); // 2g range; measurement mode

    //mma_calibrate_offset( 0, 0, 0 );


	//LEDs
	//PWM on cathode
	TRISAbits.TRISA0=0;
	LATAbits.LATA0=1; //enable cathode

	//setup LEDs
	LATB=0;
	TRISB=0;


	ledtrig=1; //only shut LED off once
    //	Never ending loop services each task in small increments
    while (1) {
        do {
            if (!TestUsbInterruptEnabled()) //JTR3 added
                USBDeviceTasks(); ////service USB tasks Guaranteed one pass in polling mode even when usb_device_state == CONFIGURED_STATE
            if ((usb_device_state < DEFAULT_STATE)) { // JTR2 no suspendControl available yet || (USBSuspendControl==1) ){
                //LedOff();
            } else if (usb_device_state < CONFIGURED_STATE) {
                //LedOn();
            }else if((ledtrig==1) && (usb_device_state == CONFIGURED_STATE)){
				//LedOff();
				ledtrig=0;
			}
        } while (usb_device_state < CONFIGURED_STATE);

		usbbufservice();//load any USB data into byte buffer

		if(usbbufgetbyte(&inByte) == 1){

			switch(inByte){//switch on the command
				case 0x00:
					WaitInReady();  //it's always ready, but this could be done better
					param[0]='B';
					param[1]='B';
					param[2]='I';
					param[3]='O';
					param[4]='1';
					putUnsignedCharArrayUsbUsart(param,5);
					break;
				case 0x01:
			    	mma_get_average8( 4, &x8, &y8, &z8 );
					param[0]=x8;
					param[1]=y8;
					param[2]=z8;
					WaitInReady();  //it's always ready, but this could be done better
					putUnsignedCharArrayUsbUsart(param,3);
					break;
				default: //error
					break;
			}
	
		}//if data
	}//while
//#endif

}//end main