Exemple #1
0
void binBB(void) {
  static unsigned char inByte;
  unsigned int i;

  BP_LEDMODE = 1; // light MODE LED
  binReset();
  send_binary_io_mode_identifier();

  while (1) {

    inByte = getRXbyte();

    if ((inByte & 0b10000000) == 0) { // if command bit cleared, process command
      if (inByte == 0) {              // reset, send BB version
        send_binary_io_mode_identifier();
      } else if (inByte == 1) { // goto SPI mode
        binReset();
#ifdef BP_ENABLE_SPI_SUPPORT
        spi_enter_binary_io(); // go into rawSPI loop
#endif            /* BP_ENABLE_SPI_SUPPORT */
        binReset();
        send_binary_io_mode_identifier();
      } else if (inByte == 2) { // goto I2C mode
        binReset();
#ifdef BP_ENABLE_I2C_SUPPORT
        binary_io_enter_i2c_mode();
#endif /* BP_ENABLE_I2C_SUPPORT */
        binReset();
        send_binary_io_mode_identifier();
      } else if (inByte == 3) { // goto UART mode
        binReset();
#ifdef BP_ENABLE_UART_SUPPORT
        binUART();
#endif
        binReset();
        send_binary_io_mode_identifier();
      } else if (inByte == 4) { // goto 1WIRE mode
        binReset();
#ifdef BP_ENABLE_1WIRE_SUPPORT
        binary_io_enter_1wire_mode();
#endif /* BP_ENABLE_1WIRE_SUPPORT */
        binReset();
        send_binary_io_mode_identifier();
      } else if (inByte == 5) { // goto RAW WIRE mode
        binReset();
        binwire();
        binReset();
        send_binary_io_mode_identifier();
      } else if (inByte == 6) { // goto OpenOCD mode
        binReset();
#ifdef BP_JTAG_OPENOCD_SUPPORT
        binOpenOCD();
#endif /* BP_JTAG_OPENOCD_SUPPORT */
        binReset();
        send_binary_io_mode_identifier();
      } else if (inByte == 7) { // goto pic mode
        binReset();
#ifdef BP_ENABLE_PIC_SUPPORT
        binpic();
#endif /* BP_ENABLE_PIC_SUPPORT */
        binReset();
        send_binary_io_mode_identifier();
      } else if (inByte == 0b1111) { // return to terminal
        user_serial_transmit_character(1);
        BP_LEDMODE = 0; // light MODE LED
        user_serial_wait_transmission_done();  // wait untill TX finishes
#ifndef BUSPIRATEV4
        asm("RESET");
#endif
#ifdef BUSPIRATEV4 // cannot use ASM reset on BPv4
        binReset();
        return;
#endif
        // self test is only for v2go and v3
      } else if (inByte == 0b10000) { // short self test
        binSelfTest(0);
      } else if (inByte == 0b10001) { // full self test with jumpers
        binSelfTest(1);
      } else if (inByte == 0b10010) { // setup PWM

        // cleanup timers from FREQ measure
        T2CON = 0; // 16 bit mode
        T4CON = 0;
        OC5CON = 0; // clear PWM settings

        BP_AUX_RPOUT = OC5_IO; // setup pin

        // get one byte
        i = getRXbyte();
        if (i & 0b10)
          T2CONbits.TCKPS1 = 1; // set prescalers
        if (i & 0b1)
          T2CONbits.TCKPS0 = 1;

        // get two bytes
        i = (getRXbyte() << 8);
        i |= getRXbyte();
        OC5R = i; // Write duty cycle to both registers
        OC5RS = i;
        OC5CON = 0x6; // PWM mode on OC, Fault pin disabled

        // get two bytes
        i = (getRXbyte() << 8);
        i |= getRXbyte();
        PR2 = i; // write period

        T2CONbits.TON = 1; // Start Timer2
        user_serial_transmit_character(1);
      } else if (inByte == 0b10011) { // clear PWM
        T2CON = 0;                    // stop Timer2
        OC5CON = 0;
        BP_AUX_RPOUT = 0; // remove output from AUX pin
        user_serial_transmit_character(1);
        // ADC only for v1, v2, v3
      } else if (inByte == 0b10100) {  // ADC reading (x/1024)*6.6volts
        AD1CON1bits.ADON = 1;          // turn ADC ON
        i = bp_read_adc(BP_ADC_PROBE); // take measurement
        AD1CON1bits.ADON = 0;          // turn ADC OFF
        user_serial_transmit_character((i >> 8));             // send upper 8 bits
        user_serial_transmit_character(i);                    // send lower 8 bits
      } else if (inByte == 0b10101) {  // ADC reading (x/1024)*6.6volts
        AD1CON1bits.ADON = 1;          // turn ADC ON
        while (1) {
          i = bp_read_adc(BP_ADC_PROBE); // take measurement
          user_serial_wait_transmission_done();
          user_serial_transmit_character((i >> 8)); // send upper 8 bits
          // while(UART1TXRdy==0);
          user_serial_transmit_character(i); // send lower 8 bits

          if (user_serial_ready_to_read() == 1) { // any key pressed, exit
            i = user_serial_read_byte();         // /* JTR usb port; */;
            break;
          }
        }
        AD1CON1bits.ADON = 0;         // turn ADC OFF
      } else if (inByte == 0b10110) { // binary frequency count access
Exemple #2
0
void binBB(void) {
    static unsigned char inByte;
    unsigned int i;

    BP_LEDMODE = 1; //light MODE LED
    binReset();
    binBBversion(); //send mode name and version

    while (1) {

        inByte = getRXbyte();

        if ((inByte & 0b10000000) == 0) {//if command bit cleared, process command
            if (inByte == 0) {//reset, send BB version
                binBBversion();
            } else if (inByte == 1) {//goto SPI mode
                binReset();
#ifdef BP_USE_HWSPI
                binSPI(); //go into rawSPI loop
#endif
                binReset();
                binBBversion(); //say name on return
            } else if (inByte == 2) {//goto I2C mode
                binReset();
#ifdef BP_USE_I2C
                binI2C();
#endif
                binReset();
                binBBversion(); //say name on return
            } else if (inByte == 3) {//goto UART mode
                binReset();
#ifdef BP_USE_HWUART
                binUART();
#endif
                binReset();
                binBBversion(); //say name on return
            } else if (inByte == 4) {//goto 1WIRE mode
                binReset();
#ifdef BP_USE_1WIRE
                bin1WIRE();
#endif
                binReset();
                binBBversion(); //say name on return
            } else if (inByte == 5) {//goto RAW WIRE mode
                binReset();
                binwire();
                binReset();
                binBBversion(); //say name on return
            } else if (inByte == 6) {//goto OpenOCD mode
                binReset();
#ifndef BUSPIRATEV4
                binOpenOCD();
#endif
                binReset();
                binBBversion(); //say name on return
            } else if (inByte == 7) {//goto pic mode
                binReset();
#ifdef BP_USE_PIC
                binpic();
#endif
                binReset();
                binBBversion(); //say name on return
            } else if (inByte == 0b1111) {//return to terminal
                UART1TX(1);
                BP_LEDMODE = 0; //light MODE LED
                WAITTXEmpty(); //wait untill TX finishes
#ifndef BUSPIRATEV4
                asm("RESET");
#endif
#ifdef BUSPIRATEV4 //cannot use ASM reset on BPv4
                binReset();
				return;
#endif
                //self test is only for v2go and v3
#ifndef BUSPIRATEV1A 
            } else if (inByte == 0b10000) {//short self test
                binSelfTest(0);
            } else if (inByte == 0b10001) {//full self test with jumpers
                binSelfTest(1);
#endif
            } else if (inByte == 0b10010) {//setup PWM

                //cleanup timers from FREQ measure
                T2CON = 0; //16 bit mode
                T4CON = 0;
                OC5CON = 0; //clear PWM settings

                BP_AUX_RPOUT = OC5_IO; //setup pin

                //get one byte
                i = getRXbyte();
                if (i & 0b10) T2CONbits.TCKPS1 = 1; //set prescalers
                if (i & 0b1) T2CONbits.TCKPS0 = 1;

                //get two bytes
                i = (getRXbyte() << 8);
                i |= getRXbyte();
                OC5R = i; //Write duty cycle to both registers
                OC5RS = i;
                OC5CON = 0x6; // PWM mode on OC, Fault pin disabled

                //get two bytes
                i = (getRXbyte() << 8);
                i |= getRXbyte();
                PR2 = i; // write period

                T2CONbits.TON = 1; // Start Timer2
                UART1TX(1);
            } else if (inByte == 0b10011) {//clear PWM
                T2CON = 0; // stop Timer2
                OC5CON = 0;
                BP_AUX_RPOUT = 0; //remove output from AUX pin
                UART1TX(1);
                //ADC only for v1, v2, v3
            } else if (inByte == 0b10100) {//ADC reading (x/1024)*6.6volts
                AD1CON1bits.ADON = 1; // turn ADC ON
                i = bpADC(BP_ADC_PROBE); //take measurement
                AD1CON1bits.ADON = 0; // turn ADC OFF
                UART1TX((i >> 8)); //send upper 8 bits
                UART1TX(i); //send lower 8 bits
            } else if (inByte == 0b10101) {//ADC reading (x/1024)*6.6volts
                AD1CON1bits.ADON = 1; // turn ADC ON
                while (1) {
                    i = bpADC(BP_ADC_PROBE); //take measurement
                    WAITTXEmpty();
                    UART1TX((i >> 8)); //send upper 8 bits
                    //while(UART1TXRdy==0);
                    UART1TX(i); //send lower 8 bits

                    if (UART1RXRdy() == 1) {//any key pressed, exit
                        i = UART1RX(); // /* JTR usb port; */;
                        break;
                    }
                }
                AD1CON1bits.ADON = 0; // turn ADC OFF
			}else if (inByte==0b10110){ //binary frequency count access