Example #1
0
int main(void) {
  firmware_signature = FIRMWARE_SIGNATURE;

  initialize_board();

#if defined(BUSPIRATEV4)
  BP_LEDUSB_DIR = OUTPUT;
  BP_USBLED_ON();

#ifdef USB_INTERRUPTS
  EnableUsbPerifInterrupts(USB_TRN | USB_SOF | USB_UERR | USB_URST);
  EnableUsbGlobalInterrupt();
#endif /* USB_INTERRUPTS */

  /* Wait until the USB interface is configured. */

  do {
#ifndef USB_INTERRUPTS
    usb_handler();
#endif /* !USB_INTERRUPTS */
  } while (usb_device_state < CONFIGURED_STATE);
  BP_USBLED_OFF();
  usb_register_sof_handler(CDCFlushOnTimeout);

#endif /* BUSPIRATEV4 */

  /* Starts processing user requests. */
  serviceuser();

  return 0;
}
Example #2
0
int main(void) {

    Initialize(); //setup bus pirate

    //wait for the USB connection to enumerate
#if defined (BUSPIRATEV4) && !defined (BPV4_DEBUG)
    BP_LEDUSB_DIR = 0;
    //BP_LEDUSB = 1;
    BP_USBLED_ON();
    //BP_VREGEN_DIR = 0;
   // BP_VREGEN = 1;
    //BP_LEDMODE_DIR = 0;
    //BP_LEDMODE = 1;
#ifdef USB_INTERRUPTS
    EnableUsbPerifInterrupts(USB_TRN + USB_SOF + USB_UERR + USB_URST);
    EnableUsbGlobalInterrupt();
#endif    

    do {
#ifndef USB_INTERRUPTS
//        if (!TestGlobalUsbInterruptEnable()) //JTR3 added
            usb_handler(); ////service USB tasks Guaranteed one pass in polling mode even when usb_device_state == CONFIGURED_STATE
#endif 
        //        if ((usb_device_state < DEFAULT_STATE)) { // JTR2 no suspendControl available yet || (USBSuspendControl==1) ){
        //        } else if (usb_device_state < CONFIGURED_STATE) {
        //        }
    } while (usb_device_state < CONFIGURED_STATE); // JTR addition. Do not proceed until device is configured.
    BP_USBLED_OFF();
    usb_register_sof_handler(CDCFlushOnTimeout); // For timeout value see: cdc_config.h -> BPv4 -> CDC_FLUSH_MS

#endif
    serviceuser();
    return 0;
}
Example #3
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