Esempio n. 1
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;
}
Esempio n. 2
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;
}
Esempio n. 3
0
//get bus pirate ready after first start
//or clean up after any dirty modules
//modules MUST teardown any PPS functions on the CMD_CLEANUP command
void bpInit(void){
	//do this manually so there aren't problems with hardware
	//that has I/O on different ports
	BP_MOSI_DIR=1;
	BP_CLK_DIR=1; 
	BP_MISO_DIR=1;
	BP_CS_DIR=1; 
	BP_AUX0_DIR=1;
	BP_LEDMODE=0; //mode LED OFF
	BP_LEDMODE_DIR=0;
	#ifdef BUSPIRATEV4
		BP_USBLED_OFF();
		BPV4_HWI2CPINS_SETUP();
		BP_BUTTON_SETUP();
		BP_3V3PU_OFF();
		//BP_5VPU_OFF();
		BP_EEPROM_SETUP();
	#endif
	#ifdef BUSPIRATEV1A
		BP_PIN6_DIR=1; //AUX2... unused
		BP_LEDPWR=1; //light power led
		BP_LEDPWR_DIR=0;
	#endif

	BP_AUX_RPOUT = 0;    //remove output from AUX pin (PWM/servo modes)

	bpConfig.busMode=HIZ;

	clearModeConfig(); //reset the mode settings structure
	
	#ifndef BUSPIRATEV1A
		BP_PULLUP_OFF();
	#endif

	BP_VREG_OFF();//disable the VREG

	//setup voltage monitoring on ADC. see hardwarevx.h!
	BP_ADC_PINSETUP();

	//configure the ADC
	AD1CON1bits.SSRC  = 0b111;// SSRC<3:0> = 111 implies internal
								// counter ends sampling and starts
								// converting.
	AD1CSSL = 0;
	AD1CON3 = 0x1F02; // Sample time = 31Tad,
						// Tad = 2 Tcy
	AD1CON2 = 0;
}
Esempio n. 4
0
void bp_reset_board_state(void) {
  BP_MOSI_DIR = INPUT;
  BP_CLK_DIR = INPUT;
  BP_MISO_DIR = INPUT;
  BP_CS_DIR = INPUT;
  BP_AUX0_DIR = INPUT;
  BP_LEDMODE = OFF;
  BP_LEDMODE_DIR = OUTPUT;
#ifdef BUSPIRATEV4
  BP_USBLED_OFF();
  BPV4_HWI2CPINS_SETUP();
  BP_BUTTON_SETUP();
  BP_3V3PU_OFF();
  eeprom_initialize();
#endif /* BUSPIRATEv4 */

  /* Detach source from the currently-set AUX pin. */
  BP_AUX_RPOUT = OFF;

  bus_pirate_configuration.bus_mode = BP_HIZ;
  clear_mode_configuration();
  BP_PULLUP_OFF();
  BP_VREG_OFF();
  BP_ADC_PINSETUP();

  /* Configure the ADC. */

  /* Enable automatic sample conversion. */
  AD1CON1bits.SSRC = 0b111;

  /*
   * AD1CSSL : A/D INPUT SCAN SELECT REGISTER
   *
   * MSB
   * 0--0000000000000
   * |  |||||||||||||
   * |  +++++++++++++-- CSSL{12:0}: Omit A/D input pins from scan.
   * +----------------- CSSL15:     Band gap voltage reference not scanned.
   */
  AD1CSSL = 0x0000;

  /*
   * AD1CON3 : A/D CONTROL REGISTER 3
   *
   * MSB
   * 0--1111100000010
   * |  |||||||||||||
   * |  |||||++++++++-- ADCS: A/D conversion clock is 3 * Tcy.
   * |  +++++---------- SAMC: Sample time is 31 * Tad (Tad = 3 * Tcy).
   * +----------------- ADRC: Clock is derived from system clock.
   */
  AD1CON3 = 0x1F02;

  /*
   * AD1CON2 : A/D CONTROL REGISTER 2
   *
   * MSB
   * 000--0--x-000000
   * |||  |    ||||||
   * |||  |    |||||+-- ALTS:  Use MUX A input settings.
   * |||  |    ||||+--- BUFM:  Buffer is one single 16-bits word.
   * |||  |    ++++---- SMPI:  Interrupt on each sample conversion completion.
   * |||  +------------ CSCNA: Do not scan inputs.
   * +++--------------- VCFG:  VR+ is AVdd and VR- is AVss.
   */
  AD1CON2 = 0x0000;
}
Esempio n. 5
0
//self test, showProgress=1 displays the test results in the terminal, set to 0 for silent mode
//errors are counted in the global errors variable
//returns number of errors
unsigned char selfTest(unsigned char showProgress, unsigned char jumperTest){
//toggle display of test results with show Progress variable
	errors=0;
	if(!showProgress) bpConfig.quiet=1;
	
//instructions (skip pause if no display output)
	if(showProgress && jumperTest){
		//bpPOSTWline("Disconnect any devices");
		//bpPOSTWline("Connect (Vpu to +5V) and (ADC to +3.3V)");
		BPMSG1163;
		BPMSG1251; // //bpPOSTWline("Press a key to start");
		//JTR Not required while(!UART1RXRdy()); //wait for key
		UART1RX();//discard byte
	}

	//bpPOSTWline("Ctrl");
	BPMSG1164;
	BP_AUX0=1;
	BP_AUX0_DIR=0;
	//bpPOSTWstring("AUX");
	BPMSG1165;
	bpTest(BP_AUX0,1);
	BP_AUX0=0;
	BP_AUX0_DIR=1;
				
	BP_LEDMODE=1;
	BP_LEDMODE_DIR=0;	
	//bpPOSTWstring("MODE LED");
	BPMSG1166;
	bpTest(BP_LEDMODE,1);
	BP_LEDMODE=0;
	
	BP_PULLUP_ON();
	//bpPOSTWstring("PULLUP H");
	BPMSG1167;
	bpTest(BP_PULLUP,1);
	BP_PULLUP_OFF();
	//bpPOSTWstring("PULLUP L");
	BPMSG1168;
	bpTest(BP_PULLUP,0);
	
	BP_VREG_ON();
	bpDelayMS(2);//in silent mode there's not enought delay for the power supplied to come on
	//bpPOSTWstring("VREG");
	BPMSG1169;
	bpTest(BP_VREGEN,1);

#if defined (BUSPIRATEV4)
	BPMSG1265; //bpWline("EEPROM");
	BPMSG1266; //bpWstring("SCL");
	bpTest(BP_EE_SCL, 1);
	BPMSG1267; //bpWstring("SDA");
	bpTest(BP_EE_SDA, 1);
	BPMSG1268; //bpWstring("WP");
	bpTest(BP_EE_WP, 1);
	BPMSG1269; //bpWstring("ACK");
    bpTest(eetest(), 0);
#endif

	//ADC check
	//bpPOSTWline("ADC and supply");
	BPMSG1170;
	ADCON(); // turn ADC ON

#if defined (BUSPIRATEV4)
	BPMSG1270; //bpWstring("Vusb");
	bpADCPinTest(BP_ADC_USB,V5L, V5H);

	//bpPOSTWstring("5V");
	BPMSG1171;
	bpADCPinTest(BP_ADC_5V0,V5L, V5H);

	//enable 5v0 pullup and test
	BP_5VPU_ON();
	BPMSG1171; //bpWstring("5V0 VPU");
	bpWstring(" ");
	BPMSG1172; //VPU 
	
	bpDelayMS(2);
	bpADCPinTest(BP_ADC_VPU,V5L, V5H);
	BP_5VPU_OFF();

	//ADC test (3.3 volts)
	if(jumperTest){
		//ADC is connected to 3.3 volts
		//bpPOSTWstring("ADC");
		BPMSG1174;
		bpADCPinTest(BP_ADC_PROBE,V33L, V33H);
	}	

	//bpPOSTWstring("3.3V");
	BPMSG1173;
	bpADCPinTest(BP_ADC_3V3,V33L, V33H);

	//enable 3v3 pullup and test
	BP_3V3PU_ON();
	BPMSG1173; //bpWstring("3V3 VPU");
	bpWstring(" ");
	BPMSG1172; //VPU 
	
	bpDelayMS(2);
	bpADCPinTest(BP_ADC_VPU,V33L, V33H);
	BP_3V3PU_OFF();

#elif defined (BUSPIRATEV3)
	 //v3 test
	//0x030F is 5volts
	//bpPOSTWstring("5V");
	BPMSG1171;
	bpADCPinTest(BP_ADC_5V0,V5L, V5H);
	
	if(jumperTest){
		//Vpullup is connected to 5volts
		//bpPOSTWstring("VPU");
		BPMSG1172;
		bpADCPinTest(BP_ADC_VPU,V5L, V5H);
	}

	//0x0208 is 3.3volts
	//bpPOSTWstring("3.3V");
	BPMSG1173;
	bpADCPinTest(BP_ADC_3V3,V33L, V33H);

	if(jumperTest){
		//ADC is connected to 3.3volts
		//bpPOSTWstring("ADC");
		BPMSG1174;
		bpADCPinTest(BP_ADC_PROBE,V33L, V33H);
	}
#endif

	ADCOFF(); // turn ADC OFF 

//*************
//
//  Test bus pins three ways, also tests on-board pullup resistors:
//	1. normal/high, 2. open collector ground, 3. open collector high.
//
//***************

	//pullup off, pins=output & high, read input, high?
	//bpPOSTWline("Bus high");
	BPMSG1175;
	IODIR&= ~(ALLIO);//output
	IOLAT|=ALLIO; //high	
	bpDelayMS(100);
	bpBusPinsTest(1);

	//pullup on, pins=output & low, read input, low?
	//bpPOSTWline("Bus Hi-Z 0");
	BPMSG1176;
	IOLAT&= ~(ALLIO); //low
	if(jumperTest){
		#if defined	(BUSPIRATEV4)	
		BP_3V3PU_ON();
		#endif
		BP_PULLUP_ON();
	}
	bpDelayMS(100);
	bpBusPinsTest(0);

	if(jumperTest){
	//pullup on, pins=input & low, read input, high?
		//bpPOSTWline("Bus Hi-Z 1");
		BPMSG1177;
		IODIR|=ALLIO;//output
		bpDelayMS(100);
		bpBusPinsTest(1);
		#if defined	(BUSPIRATEV4)	
		BP_3V3PU_OFF();
		#endif
	}

//instructions (skip pause if no display output)
	if(showProgress && jumperTest){
		BP_VREG_ON();
		BP_MODELED_ON();
		//bpPOSTWline("MODE and VREG LEDs should be on! Any key exits.");
		#if defined (BUSPIRATEV4)
			BP_USBLED_ON();
		#endif
		BPMSG1178;
		BPMSG1250;
		//JTR Not required while(!UART1RXRdy());
		UART1RX();
		#ifdef BUSPIRATEV4
			BP_USBLED_OFF();
		#endif
		BP_MODELED_OFF();
		BP_VREG_OFF();
	}

	bpInit();//clean up

	BPMSG1179;
	bpWdec(errors);
	BPMSG1180;
	bpConfig.quiet=0;


	return errors;

}
Esempio n. 6
0
uint8_t perform_selftest(bool show_progress, bool jumper_test) {

  errors = 0;
  if (!show_progress) {
    bus_pirate_configuration.quiet = true;
  }

  /* Alert the user to perform the required manual operations if needed. */

  if (show_progress && jumper_test) {

    /* Print alert. */
    BPMSG1163;
    BPMSG1251;

    /* Wait for a character to come in. */
    user_serial_read_byte();
  }

  /* Start the test procedure. */

  BPMSG1164;

  /* Check whether AUX0 goes HIGH when requested. */

  BP_AUX0 = HIGH;
  BP_AUX0_DIR = OUTPUT;
  BPMSG1165;
  check_result(BP_AUX0, HIGH);
  BP_AUX0 = LOW;
  BP_AUX0_DIR = INPUT;

  /* Check whether the LED line goes HIGH when requested. */

  BP_LEDMODE = HIGH;
  BP_LEDMODE_DIR = OUTPUT;
  BPMSG1166;
  check_result(BP_LEDMODE, HIGH);
  BP_LEDMODE = LOW;

  /* Check whether the pull-up line goes HIGH when requested. */

  BP_PULLUP_ON();
  BPMSG1167;
  check_result(BP_PULLUP, HIGH);

  /* Check whether the pull-up line goes LOW when requested. */

  BP_PULLUP_OFF();
  BPMSG1168;
  check_result(BP_PULLUP, LOW);

  /* Check whether the regulated voltage line goes HIGH when requested. */

  BP_VREG_ON();
  bp_delay_ms(PWR_STATE_TEST_DELAY);
  BPMSG1169;
  check_result(BP_VREGEN, HIGH);

#ifdef BUSPIRATEV4

  /* Test the internal EEPROM. */

  BPMSG1265;

  /* Check the I2C flash clock line. */
  BPMSG1266;
  check_result(BP_EE_SCL, HIGH);

  /* Check the I2C flash data line. */
  BPMSG1267;
  check_result(BP_EE_SDA, HIGH);

  /* Check the I2C flash WRITE PROTECT line. */
  BPMSG1268;
  check_result(BP_EE_WP, HIGH);

  /* Performs a more complete EEPROM test. */

  BPMSG1269;
  check_result(eeprom_test(), true);

#endif /* BUSPIRATEV4 */

  /* ADC check. */

  BPMSG1170;

  /* Turn ADC on. */
  ADCON();

#ifdef BUSPIRATEV4

  /* Check whether the voltage coming in from the USB port is within range. */

  BPMSG1270;
  perform_adc_test(BP_ADC_USB, V5L, V5H);

#endif /* BUSPIRATEV4 */

  /* Check whether the +5v rail output is within range. */

  BPMSG1171;
  perform_adc_test(BP_ADC_5V0, V5L, V5H);

#ifdef BUSPIRATEV4

  /* Test the +5v pull-up line. */

  BP_5VPU_ON();
  BPMSG1171;
  bpSP;
  BPMSG1172;
  bp_delay_ms(PWR_STATE_TEST_DELAY);
  perform_adc_test(BP_ADC_VPU, V5L, V5H);
  BP_5VPU_OFF();

  if (jumper_test) {

    /*
     * Check whether the +3.3v rail output is within range when measured from
     * outside the board circuitry, once a jumper wire is manually placed
     * between the +3.3v rail pin and the ADC input pin.
     */

    BPMSG1174;
    perform_adc_test(BP_ADC_PROBE, V33L, V33H);
  }

  /*
   * Check whether the +3.3v rail output is within range when measured from
   * inside the board circuitry.
   */

  BPMSG1173;
  perform_adc_test(BP_ADC_3V3, V33L, V33H);

  /* Test the +3.3v pull-up line. */

  BP_3V3PU_ON();
  BPMSG1173;
  bpSP;
  BPMSG1172;
  bp_delay_ms(PWR_STATE_TEST_DELAY);
  perform_adc_test(BP_ADC_VPU, V33L, V33H);
  BP_3V3PU_OFF();

#elif defined(BUSPIRATEV3)

  if (jumper_test) {

    /*
     * Check whether the +5v pull-up output is within range when measured from
     * outside the board circuitry, once a jumper wire is manually placed
     * between the +5v pull-up pin and the ADC input pin.
     */

    BPMSG1172;
    perform_adc_test(BP_ADC_VPU, V5L, V5H);
  }

  /* Check whether the +3.3v rail output is within range. */

  BPMSG1173;
  perform_adc_test(BP_ADC_3V3, V33L, V33H);

  if (jumper_test) {

    /*
     * Check whether the +3.3v rail output is within range when measured from
     * outside the board circuitry, once a jumper wire is manually placed
     * between the +3.3v rail pin and the ADC input pin.
     */

    BPMSG1174;
    perform_adc_test(BP_ADC_PROBE, V33L, V33H);
  }

#endif /* BUSPIRATEV4 || BUSPIRATEV3 */

  /* Turn ADC off. */
  ADCOFF();

  /*
   * Pull all I/O pins HIGH with pull-ups deactivated, and check the pins
   * state afterwards.
   */

  BPMSG1175;
  IODIR &= ~ALLIO;
  IOLAT |= ALLIO;
  bp_delay_ms(PIN_STATE_TEST_DELAY);
  perform_pins_state_test(HIGH);

  /*
   * Pull all I/O pins LOW with pull-ups active and check the pins state
   * afterwards.
   */

  BPMSG1176;
  IOLAT &= ~ALLIO;
  if (jumper_test) {
#ifdef BUSPIRATEV4
    BP_3V3PU_ON();
#endif /* BUSPIRATEV4 */
    BP_PULLUP_ON();
  }
  bp_delay_ms(PIN_STATE_TEST_DELAY);
  perform_pins_state_test(LOW);

  if (jumper_test) {
    /*
     * Pull all I/O pins HIGH with pull-ups active and check the pins state
     * afterwards.
     */

    /* TODO: should this be done without jumpers too? */

    BPMSG1177;
    IODIR |= ALLIO;
    bp_delay_ms(PIN_STATE_TEST_DELAY);
    perform_pins_state_test(HIGH);
#ifdef BUSPIRATEV4
    BP_3V3PU_OFF();
#endif /* BUSPIRATEV4 */
  }

  if (show_progress && jumper_test) {

    /*
     * Alert the user to check the LED on/off states, and prompt for a key
     * to be pressed to continue.
     */

    BP_VREG_ON();
    BP_MODELED_ON();
#ifdef BUSPIRATEV4
    BP_USBLED_ON();
#endif /* BUSPIRATEV4 */
    BPMSG1178;
    MSG_ANY_KEY_TO_EXIT_PROMPT;
    user_serial_read_byte();
#ifdef BUSPIRATEV4
    BP_USBLED_OFF();
#endif /* BUSPIRATEV4 */
    BP_MODELED_OFF();
    BP_VREG_OFF();
  }

  bp_reset_board_state();

  BPMSG1179;
  bp_write_dec_byte(errors);
  BPMSG1180;
  bus_pirate_configuration.quiet = false;

  return errors;
}