Beispiel #1
0
void em4x05_read(uint8_t addr) {
  debug_write("?BEGIN em4x05_read: 0x");
  debug_write_u16(addr, 16);
  debug_write_line("");

  debug_led_set(1);
  delay_ms(1);
  eeworkbench_begin_tx();
  delay_us(US_PER_RF_TICK * 5);

  _em4x05_tx_first_stop();
  _em4x05_tx(0);
  _em4x05_tx_command(COMMAND_READ);
  _em4x05_tx_addr(addr);

  debug_led_set(0);
  debug_write_line("?END em4x05_read");
}
Beispiel #2
0
void assert_failed(uint8_t* file, uint32_t line) {
  debug_write("-assert_failed: file ");
  debug_write((const char*) file);
  debug_write(" on line ");
  debug_write_u32(line, 10);
  debug_write_line("");

  /* Infinite loop */
  while (1) {
  }
}
Beispiel #3
0
void setup() {
  // Configure the NVIC Preemption Priority Bits
  // 2 bit for pre-emption priority, 2 bits for subpriority
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

  debug_setup();
  debug_led_set(1);
  debug_write_line("?BEGIN setup");

  ring_buffer_u8_init(&g_usartInputRingBuffer, g_usartInputBuffer, INPUT_BUFFER_SIZE);

  ir_code_setup();
  time_setup();
  ir_tx_setup();
  ir_rx_setup();

  //cc3000_setup(0, 0);
  //wifi_connect();

  debug_led_set(0);
  debug_write_line("?END setup");
}
Beispiel #4
0
void loop() {
  IrRecv* irRecv = ir_rx_recv();
  if(irRecv != NULL) {
    IrCode* code = ir_code_decode(irRecv->buffer, irRecv->bufferLength);
    debug_write("?rx: ");
    if(code != NULL) {
      debug_write_u16(code->brand, 16);
      debug_write_u16(code->key, 16);
    } else {
      debug_write("(");
      debug_write_u16(irRecv->bufferLength, 10);
      debug_write("): ");
      for(int i = 0; i < irRecv->bufferLength; i++) {
        debug_write_u16(irRecv->buffer[i], 10);
        debug_write(",");
      }
    }
    debug_write_line("");
  }
}
Beispiel #5
0
int main( void )
{
    uint8_t d = 0x34,rxbuf = 0X23;
    mInit();
    // I2C_config();
    SPI_config();
    debug_setup();
    ADC_A_config();
    GPIO_InitTypeDef  GPIO_InitStructure;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //M4 DIRECTION
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; //M3 DIRECTION
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
    TIMA_config(100, 20,10); // timer1 channel 1 PA8
    TIMB_config(100, 20,10); // timer2 channel 3 PA9
    TIMC_config(100, 20,10); // timer15 channel 1 PB14
    TIMD_config(100, 20,10); // timer2 channel 2 PA1 // first 2 numbers
    //                          // in this function are not doing anything   
    while(1)
    {
        GPIO_ResetBits(GPIOA, GPIO_Pin_0);
        GPIO_ResetBits(GPIOB, GPIO_Pin_15);
        // debug_write_ch(0XAB);
        mBlueTOGGLE;
        mGreenTOGGLE;
        mRedTOGGLE;
        mWaitms(300);
        GPIO_SetBits(GPIOA, GPIO_Pin_0);
        GPIO_SetBits(GPIOB, GPIO_Pin_15);
            /* Test EOC flag */
        while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
    
        /* Get ADC1 converted data */
        ADC1ConvertedValue =ADC_GetConversionValue(ADC1);
        debug_write_u16(ADC1ConvertedValue,10);
        debug_write_line("  ");

        // mWaitms(300);
        // I2C_write_1byte(SLAVE_ADDR2,254,22);
        // rxbuf = I2C_read_1byte(SLAVE_ADDR,254);
        // debug_write_ch(rxbuf);
        // rxbuf = I2C_read_1byte(SLAVE_ADDR1,254);
        // debug_write_ch(rxbuf);
        // rxbuf = I2C_read_1byte(SLAVE_ADDR2,254);
        // debug_write_ch(rxbuf);
    // TIM_SetCompare2 ( TIM2,1);
    // mWaitms(300);
    // TIM_SetCompare2 ( TIM2,0);
    // mWaitms(1000);
        // SPI_SendData8(SPI1, d);
        // while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
        // while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
        // rxbuf =  SPI_ReceiveData8(SPI1);
    }

}
Beispiel #6
0
void on_usart1_irq() {
  char line[MAX_LINE_LENGTH];

  if (USART_GetITStatus(DEBUG_USART, USART_IT_RXNE) != RESET) {
    uint8_t data[1];
    data[0] = USART_ReceiveData(DEBUG_USART);

    ring_buffer_u8_write(&g_usartInputRingBuffer, data, 1);
    while (ring_buffer_u8_readline(&g_usartInputRingBuffer, line, MAX_LINE_LENGTH) > 0) {
      if(strcmp(line, "!CONNECT\n") == 0) {
        debug_write_line("+OK");
        debug_write_line("!clear");
        debug_write_line("!set name,stm32-wifi-ir");
        debug_write_line("!set description,'IR TX/RX over WiFi'");

        debug_write_line("?add widgets");
        debug_write_line("!add label,code,1,0,1,1");

        debug_write_line("!code.set minWidth,150");
        debug_write_line("!code.set title,'Code'");
        debug_write_line("!code.set text,'xxxxxxxxxxxxxxxxxxxx'");
      } else if(strncmp(line, "!TX", 3) == 0) {
        debug_write_line("+OK");
        IrCode* code = ir_code_getByIndex(0);
        ir_tx_send(code);
      } else {
        debug_write("?Unknown command: ");
        debug_write_line(line);
      }
    }
  }
}
Beispiel #7
0
void wifi_connect() {
  uint8_t cc3000MajorFirmwareVersion, cc3000MinorFirmwareVersion;

  cc3000_get_firmware_version(&cc3000MajorFirmwareVersion, &cc3000MinorFirmwareVersion);
  debug_write("?major: 0x");
  debug_write_u8(cc3000MajorFirmwareVersion, 16);
  debug_write_line("");
  debug_write("?minor: 0x");
  debug_write_u8(cc3000MinorFirmwareVersion, 16);
  debug_write_line("");
  if (cc3000MajorFirmwareVersion != 0x01 || cc3000MinorFirmwareVersion != 0x18) {
    debug_write_line("?Wrong firmware version!");
    while (1);
  }

  cc3000_display_mac_address();

  debug_write_line("?Deleting old connection profiles");
  if (cc3000_delete_profiles() != 0) {
    debug_write_line("?Failed!");
    while (1);
  }

#ifdef STATIC_IP_ADDRESS
  unsigned long aucIP = STATIC_IP_ADDRESS;
  unsigned long aucSubnetMask = STATIC_SUBNET_MASK;
  unsigned long aucDefaultGateway = STATIC_DEFAULT_GATEWAY;
  unsigned long aucDNSServer = STATIC_DNS_SERVER;
  if (netapp_dhcp(&aucIP, &aucSubnetMask, &aucDefaultGateway, &aucDNSServer) != 0) {
    debug_write_line("?netapp_dhcp Failed!");
    while (1);
  }
#else
  unsigned long aucIP = 0;
  unsigned long aucSubnetMask = 0;
  unsigned long aucDefaultGateway = 0;
  unsigned long aucDNSServer = 0;
  if (netapp_dhcp(&aucIP, &aucSubnetMask, &aucDefaultGateway, &aucDNSServer) != 0) {
    debug_write_line("?netapp_dhcp Failed!");
    while (1);
  }
#endif

  // Attempt to connect to an access point
  char *ssid = WLAN_SSID; /* Max 32 chars */
  debug_write("?Attempting to connect to ");
  debug_write_line(ssid);

  // NOTE: Secure connections are not available in 'Tiny' mode!
  if (cc3000_connect_to_ap(WLAN_SSID, WLAN_PASS, WLAN_SECURITY) != 0) {
    debug_write_line("?Connect Failed!");
    while (1);
  }

  debug_write_line("?Connected!");

#ifndef STATIC_IP_ADDRESS
  // Wait for DHCP to complete
  debug_write_line("?Request DHCP");
  while (cc3000_check_dhcp() != 0) {
    delay_ms(100);
  }
#endif

  while (!cc3000_is_connected()) {
    delay_ms(100);
  }

  cc3000_display_ipconfig();
}
void dc_electronic_load_setup() {
  setCurrentMilliamps = 0;
  readCurrentMilliamps = 0;
  readMilliVolts = 0;
  setRateIndex = 0;
  readCurrentMilliampsDisplay = DISPLAY_MILLI;
  gfxState = GFX_STATE_MEASURE;

  dma_ring_buffer_init(&g_debugUsartDmaInputRingBuffer, DEBUG_USART_RX_DMA_CH, g_debugUsartRxBuffer, DEBUG_USART_RX_BUFFER_SIZE);

  debug_setup();
  debug_write_line("?BEGIN setup");

  process_init();
  process_start(&etimer_process, NULL);

  process_start(&debug_process, NULL);
#ifdef DISP6800_ENABLE
  process_start(&gfx_update_process, NULL);
  process_poll(&gfx_update_process);
#endif

  spi_setup();

#ifdef DISP6800_ENABLE
  disp6800_setup();
  gfx_setup();
#endif

#ifdef ENCODER_ENABLE
  encoder_setup();
#endif

#ifdef FLASH_ENABLE
  flashsst25_setup();
#endif

#ifdef MAC_ENABLE
  mac25aa02e48_setup();
  mac25aa02e48_read_eui48();
#endif

#ifdef ADC_ENABLE
  adc_setup();
#endif

#ifdef DAC_ENABLE
  dac_setup();
  dac_set(0);
#endif

#ifdef NETWORK_ENABLE
  network_setup(EUI48);
#endif

#ifdef FAN_ENABLE
  fan_setup();
#endif

#ifdef BUTTONS_ENABLE
  buttons_setup();
#endif

  time_setup();
  recorder_setup();

  debug_write_line("?END setup");
}
PROCESS_THREAD(debug_process, ev, data) {
  char line[MAX_LINE_LENGTH];
  uint16_t read;
  uint8_t b;
  uint32_t flashAddress = 0;
  uint32_t flashCount = 0;
  uint32_t t = 0;

  PROCESS_BEGIN();

  while (1) {
    PROCESS_YIELD();

    while (dma_ring_buffer_readline(&g_debugUsartDmaInputRingBuffer, line, MAX_LINE_LENGTH)) {
      if (strcmp(line, "!CONNECT\n") == 0) {
        debug_write_line("+OK");
        debug_write_line("!clear");
        debug_write_line("!set name,dc-electronic-load");
        debug_write_line("!set description,'DC Electonic Load'");
      }
      
      else if (strcmp(line, "!RESET\n") == 0) {
        debug_write_line("+OK");
        NVIC_SystemReset();
      }

#ifdef ADC_ENABLE
      else if (strcmp(line, "!ADCLAST\n") == 0) {
        debug_write("+OK ");
        debug_write_u16(lastAdcValue[0], 10);
        debug_write(",");
        debug_write_u16(lastAdcValue[1], 10);
        debug_write(",");
        debug_write_u16(lastAdcValue[2], 10);
        debug_write(",");
        debug_write_u16(lastAdcValue[3], 10);
        debug_write(",");
        debug_write_u16(setCurrentMilliamps, 10);
        debug_write_line("");
      } else if (strcmp(line, "!ADCRAW\n") == 0) {
        debug_write("+OK ");
        debug_write_u16(adc_sample(ADC_CH0_SINGLE), 10);
        debug_write(",");
        debug_write_u16(adc_sample(ADC_CH1_SINGLE), 10);
        debug_write(",");
        debug_write_u16(adc_sample(ADC_CH2_SINGLE), 10);
        debug_write(",");
        debug_write_u16(adc_sample(ADC_CH3_SINGLE), 10);
        debug_write_line("");
      }
#endif

#ifdef FAN_ENABLE
      else if (strncmp(line, "!FANSET ", 8) == 0) {
        uint8_t fanSetOverride = atoi(line + 8);
        fan_set(fanSetOverride);
        debug_write_line("+OK");
      } else if (strcmp(line, "!FANGET\n") == 0) {
        debug_write("+OK ");
        debug_write_u8(fan_get(), 10);
        debug_write_line("");
      }
#endif

#ifdef DISP6800_ENABLE
      else if (strcmp(line, "!DISPON\n") == 0) {
        disp6800_set_display_onoff(DISP6800_DISPLAY_ON);
        debug_write_line("+OK");
      } else if (strcmp(line, "!DISPOFF\n") == 0) {
        disp6800_set_display_onoff(DISP6800_DISPLAY_OFF);
        debug_write_line("+OK");
      }
#endif

#ifdef FLASH_ENABLE
      else if (strcmp(line, "!FLASHCLEAR\n") == 0) {
        flashsst25_erase_chip();
        debug_write_line("+OK");
      } else if (strncmp(line, "!FLASHWRITE ", 12) == 0) {
        flashAddress = atoi(line + 12);
        flashCount = FLASH_BLOCK_SIZE;

        debug_write_line("+READY");
        t = time_ms();
        while (1) {
          if (flashCount <= 0) {
            debug_write("+OK ");
            debug_write_u32(flashAddress, 10);
            debug_write_line("");
            break;
          }
          if ((time_ms() - t) > 5000) {
            debug_write_line("-FAIL");
            break;
          }
          if ((read = dma_ring_buffer_read(&g_debugUsartDmaInputRingBuffer, (uint8_t*)line, MIN(flashCount, sizeof(line)))) <= 0) {
            continue;
          }
          flashsst25_write(flashAddress, (uint8_t*)line, read);
          flashAddress += read;
          flashCount -= read;
          t = time_ms();
        }
      } else if (strncmp(line, "!FLASHREAD ", 11) == 0) {
        flashAddress = atoi(line + 11);
        flashCount = FLASH_BLOCK_SIZE;
        debug_write_line("+OK");
        flashsst25_read_begin(flashAddress);
        while (flashCount > 0) {
          b = flashsst25_read();
          debug_write_bytes(&b, 1);
          flashCount--;
        }
        flashsst25_read_end();
      }
#endif

      else {
        debug_write("?Unknown command: ");
        debug_write_line(line);
      }
    }
  }

  PROCESS_END();
}