Esempio n. 1
0
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    unsigned role = role_get();
    unsigned group = role >> ROLE_GR_SHIFT;
    rtc_initialize(rtc_dummy_handler);
    uart_init();
    stat_init(group);
 
    radio_configure(
            &g_report_packet, sizeof(g_report_packet),
            group ? GR1_CH : GR0_CH
        );

    receiver_on(on_packet_received);
    receive_start();

    while (true)
    {
        __WFI();
        if (g_stat_request) {
            g_stat_request = 0;
            stat_dump();
        }
    }
}
Esempio n. 2
0
void run_rtc_test(void)
{
    hal_initialize();

    gfx_init();
    backlight_init();
    backlight_set_brightness(90);
    tty_enable_view(bTrue);

    rtc_initialize();
    rtc_set(&setupTime);

#ifdef TEST_FOREVER
    for(;;)
#endif
    {
        tty_enable_view(bFalse);
        tty_reset();
        rtc_now(&nowTime);
        rtc_format_time(&nowTime, RTC_FMT_DATE | RTC_FMT_TIME | RTC_FMT_SECONDS | RTC_FMT_WEEK, tty_outchar);
        tty_enable_view(bTrue);

        delay_ms(200);
    }
} 
Esempio n. 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;
}
Esempio n. 4
0
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    rtc_initialize(rtc_dummy_handler);
    radio_configure(&g_pkt, 0, PROTOCOL_CHANNEL);
    uart_init();
    hf_osc_start();

#ifdef USE_DISPLAY
    displ_init();
    show_startup_screen();
#endif

    receiver_on_(0);
    receive_start();

    while (true)
    {
        if (radio_tx_end()) {
            on_packet_received();
            receive_start();
        }
    }
}
Esempio n. 5
0
int main(void)
{
  // Stop watchdog timer for now
  WDTCTL = WDTPW | WDTHOLD;

  // Enable JTAG (keep this line here)
  SYSCTL |= SYSJTAGPIN;

  // Initialize state variables
//floatswitch_active = 0;
  floatswitches = 0;
  battery_charge = 0;
  solarpanel_voltage = 0;
  pump_active = 0;
  tryagain_timeelapsed = 0;
  last_sent_warningtext = 0;

  // Read in the saved phone number from memory, if it is there
  memset(phone_number, '\0', MAX_PHONE_LENGTH);
  if(strncmp(PHONE_ADDRESS, "+1", 2) == 0) // Phone numbers start with +1
    strncpy(phone_number, PHONE_ADDRESS, MAX_PHONE_LENGTH); // copy from flash into ram

  // Set up float switches
  FLOAT_PORT_DIR &= ~(FLOATSWITCH_0 | FLOATSWITCH_1 | FLOATSWITCH_2 | FLOATSWITCH_3 | FLOATSWITCH_4);
  FLOAT_PORT_REN |= FLOATSWITCH_0 | FLOATSWITCH_1 | FLOATSWITCH_2 | FLOATSWITCH_3 | FLOATSWITCH_4;
  FLOAT_PORT_OUT |= FLOATSWITCH_0 | FLOATSWITCH_1 | FLOATSWITCH_2 | FLOATSWITCH_3 | FLOATSWITCH_4;

  // Set up water pump and solarpanel on/off
  PUMPSOLAR_PORT_DIR |= PUMP_CONTROL | SOLARPANEL_CONTROL;
  PUMPSOLAR_PORT_OUT &= ~(PUMP_CONTROL | SOLARPANEL_CONTROL);

  // Set up msp430 LEDs
  LED_PORT_DIR |= (LED_MSP | LED_MSP_2);
  LED_PORT_OUT &= ~(LED_MSP | LED_MSP_2);
//  P1DIR |= LED_MSP;
//    P4DIR |= LED_MSP_2;
//  P1OUT &= ~LED_MSP;
//    P4OUT &= ~LED_MSP_2;

  // Set up gsm 'power button' (not used now)
//  P1DIR &= ~POWER_BUTTON;
//  P1REN |= POWER_BUTTON;
//  P1OUT |= POWER_BUTTON;
//  P1IE |= POWER_BUTTON; // interrupts
//  P1IES |= POWER_BUTTON; // high->low transition

  // Set up gsm power status input
  GSM_PORT_DIR &= ~GSM_POWER_STATUS; // input

  // Power on the voltage regulator for the gsm
  GSMPOWER_PORT_DIR |= GSMPOWER_ENABLE_PIN; // output mode
  GSMPOWER_PORT_OUT |= GSMPOWER_ENABLE_PIN;

  // Initialize the uart and ADC, start ADC conversion
  uart_initialize();
  adc_initialize();

  // Wait a bit
  __delay_cycles(1048576); // 1 second

  // Enable watchdog interrupts and interrupts in general
  SFRIE1 |= WDTIE;
  _BIS_SR(GIE);

  // Start conversion
  adc_start_conversion();

  // Check if GSM module is on
  while(!(GSM_PORT_IN & GSM_POWER_STATUS)) // is off
  {
    toggle_gsm_power();
    __delay_cycles(20000000); // wait
  }

  // Send an AT first
	LED_PORT_OUT |= LED_MSP;

	tx_buffer_reset();
  strcpy(tx_buffer, "AT\r\n");
  uart_send_command();

  // Start up Timer A0
  TA0CTL = TACLR; // clear first
  TA0CTL = TASSEL__ACLK | ID__8 | MC__STOP; // auxiliary clock (32.768 kHz), divide by 8 (4096 Hz), interrupt enable, stop mode
  TA0CCTL0 = CCIE; // enable capture/compare interrupt
  TA0CCR0 = 4096; // reduces rate to 1 times/sec
  TA0CTL |= MC__UP; // start the timer in up mode (counts to TA0CCR0 then resets to 0)

  // start the clock
  rtc_initialize();

  // Turn CPU off
  LPM0;

  // Main loop
  while(1)
  {
    // Check if a UART command has finished and respond accordingly
    if(uart_command_has_completed)
    {
      switch(uart_command_state)
      {
      case CommandStateSendingAT:
      {
        if(uart_command_result == UartResultOK)
        {
          // Send ATE0 because we do not need a copy of what we send
            uart_command_state = CommandStateTurnOffEcho;
            tx_buffer_reset();
            strcpy(tx_buffer, "ATE0\r\n");
            uart_send_command();
        }
        break;
      }
      case CommandStateTurnOffEcho: // Got a response after sending AT
      {
        if(uart_command_result == UartResultOK)
        {
          // Send cmgf
          // This puts the cell module into SMS mode, as opposed to data mode
          uart_command_state = CommandStateGoToSMSMode;
          tx_buffer_reset();
          strcpy(tx_buffer, "AT+CMGF=1\r\n");
          uart_send_command();
        }
        break;
      }

      case CommandStateGoToSMSMode: // Got a response after sending CMGF
      {
        if(uart_command_result == UartResultOK)
        {
          LED_PORT_OUT &= ~(LED_MSP | LED_MSP_2); // leds off

          // We are now ready to send a text whenever the system needs to
          uart_enter_idle_mode();
        }
        else
          uart_enter_idle_mode();
        break;
      }

      case CommandStatePrepareWarningSMS: // Got a response after sending CMGS
      {
        if(uart_command_result == UartResultInput)
        {
          // Send the text now
          uart_command_state = CommandStateSendWarningSMS;
          tx_buffer_reset();
          strcpy(tx_buffer, "Msg from Sol-Mate: Check your boat; water level is getting high.\r\n\x1A");
          uart_send_command();
        }
        break;
      }

      case CommandStateSendWarningSMS: // Got a response after sending the text
      {
        if(uart_command_result == UartResultOK)
        {
          LED_PORT_OUT &= ~LED_MSP; // red LED off
          sent_text = 1; // Do not send the text again (this is for testing purposes--to send another text you have to restart the MSP)

          // Delete all stored messages.
          uart_command_state = CommandStateDeleteSMS;
          tx_buffer_reset();
          strcpy(tx_buffer, "AT+CMGD=1,4\r\n");
          uart_send_command();
        }
        else if(uart_command_result == UartResultError) // sms failed to send
        {
          LED_PORT_OUT |= LED_MSP;

          // Set up timer to try again
          TA2CTL = TACLR;
          TA2CTL = TASSEL__ACLK | ID__8 | MC__STOP;
          TA2CCTL0 = CCIE;
          TA2CCR0 = TIMEOUT_SMS;

          // Prepare again
          uart_command_state = CommandStatePrepareWarningSMS;
          tx_buffer_reset();
          strcpy(tx_buffer, "AT+CMGS=\"");
          strcat(tx_buffer, phone_number);
          strcat(tx_buffer, "\"\r\n");

          // Enable timer, go to sleep (uart will be disabled too because LPM2)
          TA2CTL |= MC__UP;
          LPM2;
        }
        else
          uart_enter_idle_mode();

        break;
      }

      case CommandStateUnsolicitedMsg: // Received a message from the cell module
      {
        LED_PORT_OUT |= LED_MSP; // red LED on

        // Check what kind of code this is..
        // --SMS--
        // +CMTI: "SM",3\r\n
        if(strstr(rx_buffer, "+CMTI")) // strstr returns null/0 if not found
        {
          // Find the comma
          char *begin_ptr = strchr(rx_buffer, ',');
          if(!begin_ptr) {
            uart_enter_idle_mode();
            break;
          }
          begin_ptr++; // should point to the beginning of the SMS index we need

          // Find the '\r' which is directly following the last character of the SMS index
          char *end_ptr = strchr(begin_ptr, '\r');
          if(!end_ptr) {
            uart_enter_idle_mode();
            break;
          }

          // Create the command to read the sms
          tx_buffer_reset();
          strcat(tx_buffer, "AT+CMGR=");
          strncat(tx_buffer, begin_ptr, end_ptr - begin_ptr); // SMS index
          strcat(tx_buffer, "\r\n");

          // Send the command
          LED_PORT_OUT &= ~LED_MSP; // red LED on
          uart_command_state = CommandStateReadSMS;
          uart_send_command();
        }
        else // unrecognized
        {
          LED_PORT_OUT &= ~LED_MSP;
          uart_enter_idle_mode();
        }

        break;
      }

      case CommandStateReadSMS:
      {
        LED_PORT_OUT |= LED_MSP; // red LED on
        if(uart_command_result == UartResultOK)
        {
          // +CMGR: "<status>","<origin number>","<??>","<timestamp>"\r\n
          // text contents here\r\n
          // \r\n
          // OK\r\n

          // find the 1st comma
          char *begin_ptr_phone = strchr(rx_buffer, ',');
          if(!begin_ptr_phone || *(begin_ptr_phone+1) != '"') {
            uart_enter_idle_mode();
            break;
          }
          begin_ptr_phone += 2; // Move to the beginning of the number

          // find the ending quotation mark
          char *end_ptr_phone = strchr(begin_ptr_phone, '"');
          if(!end_ptr_phone) {
            uart_enter_idle_mode();
            break;
          }

          // Check if it's too long
          if(end_ptr_phone - begin_ptr_phone > MAX_PHONE_LENGTH) {
            uart_enter_idle_mode();
            break;
          }

          // Look at the contents of the text - it starts right after the first \r\n
          char *begin_ptr_sms = strchr(rx_buffer, '\n');
          if(!begin_ptr_sms) {
            uart_enter_idle_mode();
            break;
          }
          begin_ptr_sms++; // Move to the beginning of the text

          // The text ends right before the next \r\n
          char *end_ptr_sms = strchr(begin_ptr_sms, '\r');
          if(!end_ptr_sms) {
            uart_enter_idle_mode();
            break;
          }

          // Check for the "password"
          if(strstr(begin_ptr_sms, "978SolMate"))
          {
            // copy the phone number into ram
            memset(phone_number, '\0', MAX_PHONE_LENGTH);
            strncpy(phone_number, begin_ptr_phone, end_ptr_phone - begin_ptr_phone);

            // Now copy it into flash memory
            flash_erase(PHONE_ADDRESS);
            flash_write_phone_number(phone_number, MAX_PHONE_LENGTH);

            // Send the user an acknowledgement
            LED_PORT_OUT &= ~LED_MSP; // red LED off
            uart_command_state = CommandStatePreparePhoneSMS;
            tx_buffer_reset();
            strcpy(tx_buffer, "AT+CMGS=\"");
            strncat(tx_buffer, phone_number, MAX_PHONE_LENGTH);
            strcat(tx_buffer, "\"\r\n");
            uart_send_command();
          }
          // Status report?
          else if(strstr(begin_ptr_sms, "What's up"))
          {
            // Send user the status report
            LED_PORT_OUT &= ~LED_MSP;
            uart_command_state = CommandStatePrepareStatusSMS;
            tx_buffer_reset();
            strcpy(tx_buffer, "AT+CMGS=\"");
            strncat(tx_buffer, phone_number, MAX_PHONE_LENGTH);
            strcat(tx_buffer, "\"\r\n");
            uart_send_command();
          }
          else // Unrecognized text
          {
            LED_PORT_OUT &= ~LED_MSP;

            // Delete all stored messages.
            uart_command_state = CommandStateDeleteSMS;
            tx_buffer_reset();
            strcpy(tx_buffer, "AT+CMGD=1,4\r\n");
            uart_send_command();
          }
        }
        else
          uart_enter_idle_mode();

        break;
      }

      case CommandStatePreparePhoneSMS:
      {
        LED_PORT_OUT |= LED_MSP; // red LED on

        if(uart_command_result == UartResultInput)
        {
          // Send the text now
          uart_command_state = CommandStateSendPhoneSMS;
          tx_buffer_reset();
          strcpy(tx_buffer, "Msg from Sol-Mate: Your phone number has been successfully changed.\r\n\x1A");
          uart_send_command();
        }
        break;
      }

      case CommandStatePrepareStatusSMS:
      {
        LED_PORT_OUT |= LED_MSP; // red led
        if(uart_command_result == UartResultInput)
        {
          // Put together the status text
          uart_command_state = CommandStateSendStatusSMS;
          tx_buffer_reset();
          strcpy(tx_buffer, "Msg from Sol-Mate: Here's your status report.\r\n");

          // Battery status
          if(battery_charge > 228) // 12.9V
            strcat(tx_buffer, "Battery level: Full\r\n");
          else if(battery_charge > 210) // About 50% - 12.55V
            strcat(tx_buffer, "Battery level: Medium\r\n");
          else if(battery_charge > 190) // 12.2V
            strcat(tx_buffer, "Battery level: Low\r\n");
          else
            strcat(tx_buffer, "Battery level: Very Low\r\n");

          // Solar panel charge
          if(solarpanel_voltage > 186)
            strcat(tx_buffer, "Charge rate: High\r\n");
          else if(solarpanel_voltage > 113)
            strcat(tx_buffer, "Charge rate: Medium\r\n");
          else if(solarpanel_voltage > 39)
            strcat(tx_buffer, "Charge rate: Low\r\n");
          else
            strcat(tx_buffer, "Charge rate: None\r\n");

          // Water depth
          int water_level = get_water_level(floatswitches, 5);
          switch(water_level)
          {
            case 0: // No floatswitches are active.
              strcat(tx_buffer, "Water level: None\r\n");
              break;
            case 1: // Lowest floatswitch is active.
              strcat(tx_buffer, "Water level: Very low\r\n");
              break;
            case 2: // Two lowest floatswitches are active.
              strcat(tx_buffer, "Water level: Low\r\n");
              break;
            case 3: // All three floatswitches are active.
              strcat(tx_buffer, "Water level: Medium\r\n");
              break;
            case 4:
              strcat(tx_buffer, "Water level: High\r\n");
              break;
            case 5:
              strcat(tx_buffer, "Water level: Very high\r\n");
              break;
            default: // Any other combination.
              strcat(tx_buffer, "Water level: ERR INVALID READING\r\n");
              break;
          }

          // Bailer
          if(pump_active)
            strcat(tx_buffer, "Water pump: On");
          else
            strcat(tx_buffer, "Water pump: Off");

          strcat(tx_buffer, "\r\n\x1A");
          uart_send_command();
        }
        break;
      }

      case CommandStateSendPhoneSMS:
      {
        if(uart_command_result == UartResultOK)
        {
          // Delete all stored messages.
          uart_command_state = CommandStateDeleteSMS;
          tx_buffer_reset();
          strcpy(tx_buffer, "AT+CMGD=1,4\r\n");
          uart_send_command();
        }
        else if(uart_command_result == UartResultError) // sms failed to send
        {
          LED_PORT_OUT |= LED_MSP;

          // Set up timer to try again
          TA2CTL = TACLR;
          TA2CTL = TASSEL__ACLK | ID__8 | MC__STOP;
          TA2CCTL0 = CCIE;
          TA2CCR0 = TIMEOUT_SMS; // 4096 times 10 -> 10 seconds

          // Prepare again
          uart_command_state = CommandStatePreparePhoneSMS;
          tx_buffer_reset();
          strcpy(tx_buffer, "AT+CMGS=\"");
          strcat(tx_buffer, phone_number);
          strcat(tx_buffer, "\"\r\n");

          // Enable timer, go to sleep (uart will be disabled too because LPM2)
          TA2CTL |= MC__UP;
          LPM2;
        }

        break;
      }
      case CommandStateSendStatusSMS:
      {
        if(uart_command_result == UartResultOK)
        {
          // Delete all stored messages.
          uart_command_state = CommandStateDeleteSMS;
          tx_buffer_reset();
          strcpy(tx_buffer, "AT+CMGD=1,4\r\n");
          uart_send_command();
        }
        else if(uart_command_result == UartResultError) // sms failed to send
        {
          LED_PORT_OUT |= LED_MSP;

          // Set up timer to try again
          TA2CTL = TACLR;
          TA2CTL = TASSEL__ACLK | ID__8 | MC__STOP;
          TA2CCTL0 = CCIE;
          TA2CCR0 = TIMEOUT_SMS; // 4096 times 10 -> 10 seconds

          // Prepare again
          uart_command_state = CommandStatePrepareStatusSMS;
          tx_buffer_reset();
          strcpy(tx_buffer, "AT+CMGS=\"");
          strcat(tx_buffer, phone_number);
          strcat(tx_buffer, "\"\r\n");

          // Enable timer, go to sleep (uart will be disabled too because LPM2)
          TA2CTL |= MC__UP;
          LPM2;
        }

        break;
      }

      case CommandStateDeleteSMS:
      {
        if(uart_command_result == UartResultOK)
          LED_PORT_OUT &= ~LED_MSP; // red LED off

        uart_enter_idle_mode();
        break;
      }
    }

    // Turn CPU off until someone calls LPM0_EXIT (uart interrupt handler will)
    LPM0;
    }
  }
}
Esempio n. 6
0
int stm32_bringup(void)
{
#ifdef HAVE_RTC_DRIVER
  FAR struct rtc_lowerhalf_s *lower;
#endif
  int ret = OK;

#ifdef CONFIG_ZEROCROSS
  /* Configure the zero-crossing driver */

  stm32_zerocross_initialize();
#endif

#ifdef CONFIG_RGBLED
  /* Configure the RGB LED driver */

  stm32_rgbled_setup();
#endif

#if defined(CONFIG_PCA9635PW)
  /* Initialize the PCA9635 chip */

  ret = stm32_pca9635_initialize();
  if (ret < 0)
    {
      sdbg("ERROR: stm32_pca9635_initialize failed: %d\n", ret);
    }
#endif

#ifdef HAVE_SDIO
  /* Initialize the SDIO block driver */

  ret = stm32_sdio_initialize();
  if (ret != OK)
    {
      fdbg("ERROR: Failed to initialize MMC/SD driver: %d\n", ret);
      return ret;
    }
#endif

#ifdef HAVE_USBHOST
  /* Initialize USB host operation.  stm32_usbhost_initialize() starts a thread
   * will monitor for USB connection and disconnection events.
   */

  ret = stm32_usbhost_initialize();
  if (ret != OK)
    {
      udbg("ERROR: Failed to initialize USB host: %d\n", ret);
      return ret;
    }
#endif

#ifdef HAVE_USBMONITOR
  /* Start the USB Monitor */

  ret = usbmonitor_start(0, NULL);
  if (ret != OK)
    {
      udbg("ERROR: Failed to start USB monitor: %d\n", ret);
      return ret;
    }
#endif

#ifdef HAVE_RTC_DRIVER
  /* Instantiate the STM32 lower-half RTC driver */

  lower = stm32_rtc_lowerhalf();
  if (!lower)
    {
      sdbg("ERROR: Failed to instantiate the RTC lower-half driver\n");
      return -ENOMEM;
    }
  else
    {
      /* Bind the lower half driver and register the combined RTC driver
       * as /dev/rtc0
       */

      ret = rtc_initialize(0, lower);
      if (ret < 0)
        {
          sdbg("ERROR: Failed to bind/register the RTC driver: %d\n", ret);
          return ret;
        }
    }
#endif

#ifdef HAVE_ELF
  /* Initialize the ELF binary loader */

  ret = elf_initialize();
  if (ret < 0)
    {
      sdbg("ERROR: Initialization of the ELF loader failed: %d\n", ret);
    }
#endif

#ifdef CONFIG_MAX31855
  ret = stm32_max31855initialize("/dev/temp0");
#endif

#ifdef CONFIG_MAX6675
  ret = stm32_max6675initialize("/dev/temp0");
#endif

#ifdef CONFIG_FS_PROCFS
  /* Mount the procfs file system */

  ret = mount(NULL, STM32_PROCFS_MOUNTPOINT, "procfs", 0, NULL);
  if (ret < 0)
    {
      sdbg("ERROR: Failed to mount procfs at %s: %d\n",
           STM32_PROCFS_MOUNTPOINT, ret);
    }
#endif

  return ret;
}
Esempio n. 7
0
int lpc54_bringup(void)
{
#ifdef HAVE_MMCSD
  struct sdio_dev_s *sdmmc;
#endif
#ifdef HAVE_RTC_DRIVER
  struct rtc_lowerhalf_s *rtc;
#endif
  int ret;

#ifdef CONFIG_FS_PROCFS
  /* Mount the procfs file system */

  ret = mount(NULL, "/proc", "procfs", 0, NULL);
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", ret);
    }
#endif

#ifdef HAVE_RTC_DRIVER
  /* Instantiate the STM32 lower-half RTC driver */

  rtc = lpc54_rtc_lowerhalf();
  if (rtc == NULL)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to instantiate the RTC lower-half driver\n");
    }
  else
    {
      /* Bind the lower half driver and register the combined RTC driver
       * as /dev/rtc0
       */

      ret = rtc_initialize(0, rtc);
      if (ret < 0)
        {
          syslog(LOG_ERR,
                 "ERROR: Failed to bind/register the RTC driver: %d\n",
                 ret);
        }
    }
#endif

#ifdef HAVE_I2CTOOL
  /* Register I2C drivers on behalf of the I2C tool */

  lpc54_i2ctool();
#endif

#ifdef CONFIG_VIDEO_FB
  /* Initialize and register the framebuffer driver */

  ret = fb_register(0, 0);
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: fb_register() failed: %d\n", ret);
    }
#endif

#ifdef HAVE_FT5x06
  /* Register the FT5x06 touch panel driver */

  ret = lpc54_ft5x06_register();
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: lpc54_ft5x06_register() failed: %d\n", ret);
    }
#endif

#ifdef HAVE_MMCSD
  /* Get an instance of the SDIO interface */

  sdmmc = lpc54_sdmmc_initialize(0);
  if (!sdmmc)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SD/MMC\n");
    }
  else
    {
      /* Dind the SDIO interface to the MMC/SD driver */

      ret = mmcsd_slotinitialize(MMCSD_MINOR, sdmmc);
      if (ret != OK)
        {
          syslog(LOG_ERR,
                 "ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n",
                 ret);
        }
    }
#endif

#ifdef CONFIG_BUTTONS_LOWER
  /* Register the BUTTON driver */

  ret = btn_lower_initialize("/dev/buttons");
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret);
    }
#endif

  UNUSED(ret);
  return OK;
}
Esempio n. 8
0
void xrCore::_initialize	(LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs, LPCSTR fs_fname)
{
	strcpy_s					(ApplicationName,_ApplicationName);
	if (0==init_counter) {
#ifdef XRCORE_STATIC	
		_clear87	();
		_control87	( _PC_53,   MCW_PC );
		_control87	( _RC_CHOP, MCW_RC );
		_control87	( _RC_NEAR, MCW_RC );
		_control87	( _MCW_EM,  MCW_EM );
#endif
		// Init COM so we can use CoCreateInstance
//		HRESULT co_res = 
			CoInitializeEx (NULL, COINIT_MULTITHREADED);

		strcpy_s			(Params,sizeof(Params),GetCommandLine());
		_strlwr_s			(Params,sizeof(Params));

		string_path		fn,dr,di;

		// application path
        GetModuleFileName(GetModuleHandle(MODULE_NAME),fn,sizeof(fn));
        _splitpath		(fn,dr,di,0,0);
        strconcat		(sizeof(ApplicationPath),ApplicationPath,dr,di);
#ifndef _EDITOR
		strcpy_s		(g_application_path,sizeof(g_application_path),ApplicationPath);
#endif

		// working path
        if( strstr(Params,"-wf") )
        {
            string_path				c_name;
            sscanf					(strstr(Core.Params,"-wf ")+4,"%[^ ] ",c_name);
            SetCurrentDirectory     (c_name);

        }
		GetCurrentDirectory(sizeof(WorkingPath),WorkingPath);
		// User/Comp Name
		DWORD	sz_user		= sizeof(UserName);
		GetUserName			(UserName,&sz_user);

		DWORD	sz_comp		= sizeof(CompName);
		GetComputerName		(CompName,&sz_comp);

		// Mathematics & PSI detection
		CPU::Detect			();
		
		Memory._initialize	(strstr(Params,"-mem_debug") ? TRUE : FALSE);
		
		DUMP_PHASE;

		InitLog				();
		_initialize_cpu		();

#ifdef DEBUG
	#ifndef DEDICATED_SERVER
		Debug._initialize	(FALSE);
	#else
		Debug._initialize	(TRUE);
	#endif
#endif
		rtc_initialize		();

		xr_FS				= xr_new<CLocatorAPI>	();

		xr_EFS				= xr_new<EFS_Utils>		();
//.		R_ASSERT			(co_res==S_OK);
	}
	if (init_fs){
		u32 flags			= 0;
		if (0!=strstr(Params,"-build"))	 flags |= CLocatorAPI::flBuildCopy;
		if (0!=strstr(Params,"-ebuild")) flags |= CLocatorAPI::flBuildCopy|CLocatorAPI::flEBuildCopy;
#ifdef DEBUG
		if (strstr(Params,"-cache"))  flags |= CLocatorAPI::flCacheFiles;
		else flags &= ~CLocatorAPI::flCacheFiles;
#endif // DEBUG
#ifdef _EDITOR // for EDITORS - no cache
		flags 				&=~ CLocatorAPI::flCacheFiles;
#endif // _EDITOR
		flags |= CLocatorAPI::flScanAppRoot;

#ifndef	_EDITOR
	#ifndef ELocatorAPIH
		if (0!=strstr(Params,"-file_activity"))	 flags |= CLocatorAPI::flDumpFileActivity;
	#endif
#endif
		FS._initialize		(flags,0,fs_fname);
		Msg					("'%s' build %d, %s\n","xrCore",build_id, build_date);
		EFS._initialize		();
#ifdef DEBUG
    #ifndef	_EDITOR
		Msg					("CRT heap 0x%08x",_get_heap_handle());
		Msg					("Process heap 0x%08x",GetProcessHeap());
    #endif
#endif // DEBUG
	}
	
	SetLogCB				(cb);

	LPAPI_VERSION ver = ImagehlpApiVersion();
	if ( NULL == GetProcAddress ( GetModuleHandle("dbghelp.dll"), "EnumerateLoadedModulesEx") )
	{
		string256 msg;		
		DWORD dwVer[2];
		WORD *v4 = (WORD*) &dwVer;
		CSymbolEngine SE;
		SE.GetInMemoryFileVersion("dbghelp.dll", dwVer[0], dwVer[1]);

		sprintf_s(msg, 256, "”старевший файл dbghelp.dll (%d.%d.%d.%d), его рекомендуетс¤ удалить.", 
								v4[1], v4[0], v4[3], v4[2]);
		MessageBox(NULL, msg, "DebugHlp Warning", MB_OK);
	}

	init_counter++;
}
Esempio n. 9
0
int board_app_initialize(uintptr_t arg)
{
#ifdef HAVE_RTC_DRIVER
  FAR struct rtc_lowerhalf_s *rtclower;
#endif
#ifdef CONFIG_SENSORS_QENCODER
  int index;
  char buf[9];
#endif
  int ret;

  (void)ret;

#ifdef HAVE_PROC
  /* Mount the proc filesystem */

  syslog(LOG_INFO, "Mounting procfs to /proc\n");

  ret = mount(NULL, CONFIG_NSH_PROC_MOUNTPOINT, "procfs", 0, NULL);
  if (ret < 0)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to mount the PROC filesystem: %d (%d)\n",
             ret, errno);
      return ret;
    }
#endif

#if !defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER)
  /* Register the LED driver */

  ret = userled_lower_initialize(LED_DRIVER_PATH);
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret);
    }
#endif

#ifdef HAVE_RTC_DRIVER
  /* Instantiate the STM32L4 lower-half RTC driver */

  rtclower = stm32l4_rtc_lowerhalf();
  if (!rtclower)
    {
      serr("ERROR: Failed to instantiate the RTC lower-half driver\n");
      return -ENOMEM;
    }
  else
    {
      /* Bind the lower half driver and register the combined RTC driver
       * as /dev/rtc0
       */

      ret = rtc_initialize(0, rtclower);
      if (ret < 0)
        {
          serr("ERROR: Failed to bind/register the RTC driver: %d\n", ret);
          return ret;
        }
    }
#endif

#ifdef HAVE_MMCSD
  /* First, get an instance of the SDIO interface */

  g_sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO);
  if (!g_sdio)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SDIO slot %d\n",
             CONFIG_NSH_MMCSDSLOTNO);
      return -ENODEV;
    }

  /* Now bind the SDIO interface to the MMC/SD driver */

  ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, g_sdio);
  if (ret != OK)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n",
             ret);
      return ret;
    }

  /* Then let's guess and say that there is a card in the slot. There is no
   * card detect GPIO.
   */

  sdio_mediachange(g_sdio, true);

  syslog(LOG_INFO, "[boot] Initialized SDIO\n");
#endif

#ifdef CONFIG_PWM
  /* Initialize PWM and register the PWM device. */

  ret = stm32l4_pwm_setup();
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: stm32l4_pwm_setup() failed: %d\n", ret);
    }
#endif

#ifdef CONFIG_ADC
  /* Initialize ADC and register the ADC driver. */

  ret = stm32l4_adc_setup();
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: stm32l4_adc_setup failed: %d\n", ret);
    }
#endif

#ifdef CONFIG_TIMER
  /* Initialize and register the timer driver */

  ret = board_timer_driver_initialize("/dev/timer0", 2);
  if (ret != OK)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to register the timer driver: %d\n",
             ret);
      return ret;
    }
#endif

#ifdef CONFIG_SENSORS_QENCODER

  /* Initialize and register the qencoder driver */

  index = 0;

#ifdef CONFIG_STM32L4_TIM1_QE
  sprintf(buf, "/dev/qe%d", index++);
  ret = stm32l4_qencoder_initialize(buf, 1);
  if (ret != OK)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to register the qencoder: %d\n",
             ret);
      return ret;
    }
#endif

#ifdef CONFIG_STM32L4_TIM2_QE
  sprintf(buf, "/dev/qe%d", index++);
  ret = stm32l4_qencoder_initialize(buf, 2);
  if (ret != OK)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to register the qencoder: %d\n",
             ret);
      return ret;
    }
#endif

#ifdef CONFIG_STM32L4_TIM3_QE
  sprintf(buf, "/dev/qe%d", index++);
  ret = stm32l4_qencoder_initialize(buf, 3);
  if (ret != OK)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to register the qencoder: %d\n",
             ret);
      return ret;
    }
#endif

#ifdef CONFIG_STM32L4_TIM4_QE
  sprintf(buf, "/dev/qe%d", index++);
  ret = stm32l4_qencoder_initialize(buf, 4);
  if (ret != OK)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to register the qencoder: %d\n",
             ret);
      return ret;
    }
#endif

#ifdef CONFIG_STM32L4_TIM5_QE
  sprintf(buf, "/dev/qe%d", index++);
  ret = stm32l4_qencoder_initialize(buf, 5);
  if (ret != OK)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to register the qencoder: %d\n",
             ret);
      return ret;
    }
#endif

#ifdef CONFIG_STM32L4_TIM8_QE
  sprintf(buf, "/dev/qe%d", index++);
  ret = stm32l4_qencoder_initialize(buf, 8);
  if (ret != OK)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to register the qencoder: %d\n",
             ret);
      return ret;
    }
#endif

#endif

  UNUSED(ret);
  return OK;
}
Esempio n. 10
0
int board_app_initialize(uintptr_t arg)
{
#ifdef HAVE_RTC_DRIVER
  FAR struct rtc_lowerhalf_s *lower;
#endif
#ifdef CONFIG_STM32_SPI1
  FAR struct spi_dev_s *spi;
  FAR struct mtd_dev_s *mtd;
#endif
#ifdef HAVE_MMCSD
  FAR struct sdio_dev_s *sdio;
#endif
  int ret;

  /* Register I2C drivers on behalf of the I2C tool */

  stm32_i2ctool();

#ifdef HAVE_RTC_DRIVER
  /* Instantiate the STM32 lower-half RTC driver */

  lower = stm32_rtc_lowerhalf();
  if (!lower)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to instantiate the RTC lower-half driver\n");
      return -ENOMEM;
    }
  else
    {
      /* Bind the lower half driver and register the combined RTC driver
       * as /dev/rtc0
       */

      ret = rtc_initialize(0, lower);
      if (ret < 0)
        {
          syslog(LOG_ERR,
                 "ERROR: Failed to bind/register the RTC driver: %d\n",
                 ret);
          return ret;
        }
    }
#endif

  /* Configure SPI-based devices */

#ifdef CONFIG_STM32_SPI1
  /* Get the SPI port */

  spi = stm32_spibus_initialize(1);
  if (!spi)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SPI port 0\n");
      return -ENODEV;
    }

  /* Now bind the SPI interface to the M25P64/128 SPI FLASH driver */

  mtd = m25p_initialize(spi);
  if (!mtd)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to bind SPI port 0 to the SPI FLASH driver\n");
      return -ENODEV;
    }
#warning "Now what are we going to do with this SPI FLASH driver?"
#endif

  /* Mount the SDIO-based MMC/SD block driver */

#ifdef HAVE_MMCSD
  /* First, get an instance of the SDIO interface */

  sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO);
  if (!sdio)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to initialize SDIO slot %d\n",
             CONFIG_NSH_MMCSDSLOTNO);
      return -ENODEV;
    }

  /* Now bind the SDIO interface to the MMC/SD driver */

  ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio);
  if (ret != OK)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n",
             ret);
      return ret;
    }

  /* Then let's guess and say that there is a card in the slot.  I need to check to
   * see if the STM3240G-EVAL board supports a GPIO to detect if there is a card in
   * the slot.
   */

   sdio_mediachange(sdio, true);
#endif

#ifdef HAVE_USBHOST
  /* Initialize USB host operation.  stm32_usbhost_initialize() starts a thread
   * will monitor for USB connection and disconnection events.
   */

  ret = stm32_usbhost_initialize();
  if (ret != OK)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize USB host: %d\n", ret);
      return ret;
    }
#endif

#ifdef CONFIG_PWM
  /* Initialize PWM and register the PWM device. */

  ret = stm32_pwm_setup();
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: stm32_pwm_setup() failed: %d\n", ret);
    }
#endif

#ifdef CONFIG_ADC
  /* Initialize ADC and register the ADC driver. */

  ret = stm32_adc_setup();
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: stm32_adc_setup failed: %d\n", ret);
    }
#endif

#ifdef CONFIG_CAN
  /* Initialize CAN and register the CAN driver. */

  ret = stm32_can_setup();
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
    }
#endif

  UNUSED(ret);
  return OK;
}
Esempio n. 11
0
int board_app_initialize(uintptr_t arg)
{
#ifdef HAVE_RTC_DRIVER
  FAR struct rtc_lowerhalf_s *rtclower;
#endif
#if defined(HAVE_N25QXXX)
FAR struct mtd_dev_s *mtd_temp;
#endif
#if defined(HAVE_N25QXXX_CHARDEV)
  char blockdev[18];
  char chardev[12];
#endif
  int ret;

  (void)ret;

#ifdef HAVE_PROC
  /* mount the proc filesystem */

  syslog(LOG_INFO, "Mounting procfs to /proc\n");

  ret = mount(NULL, CONFIG_NSH_PROC_MOUNTPOINT, "procfs", 0, NULL);
  if (ret < 0)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to mount the PROC filesystem: %d (%d)\n",
             ret, errno);
      return ret;
    }
#endif

#ifdef HAVE_RTC_DRIVER
  /* Instantiate the STM32 lower-half RTC driver */

  rtclower = stm32l4_rtc_lowerhalf();
  if (!rtclower)
    {
      serr("ERROR: Failed to instantiate the RTC lower-half driver\n");
      return -ENOMEM;
    }
  else
    {
      /* Bind the lower half driver and register the combined RTC driver
       * as /dev/rtc0
       */

      ret = rtc_initialize(0, rtclower);
      if (ret < 0)
        {
          serr("ERROR: Failed to bind/register the RTC driver: %d\n", ret);
          return ret;
        }
    }
#endif

#ifdef HAVE_N25QXXX
  /* Create an instance of the STM32L4 QSPI device driver */

  g_qspi = stm32l4_qspi_initialize(0);
  if (!g_qspi)
    {
      _err("ERROR: stm32l4_qspi_initialize failed\n");
      return ret;
    }
  else
    {
      /* Use the QSPI device instance to initialize the
       * N25QXXX device.
       */

      mtd_temp = n25qxxx_initialize(g_qspi, true);
      if (!mtd_temp)
        {
          _err("ERROR: n25qxxx_initialize failed\n");
          return ret;
        }
      g_mtd_fs = mtd_temp;

#ifdef CONFIG_MTD_PARTITION
      {
        FAR struct mtd_geometry_s geo;
        off_t nblocks;

        /* Setup a partition of 256KiB for our file system. */

        ret = MTD_IOCTL(g_mtd_fs, MTDIOC_GEOMETRY, (unsigned long)(uintptr_t)&geo);
        if (ret < 0)
          {
            _err("ERROR: MTDIOC_GEOMETRY failed\n");
            return ret;
          }

        nblocks = (256*1024) / geo.blocksize;

        mtd_temp = mtd_partition(g_mtd_fs, 0, nblocks);
        if (!mtd_temp)
          {
            _err("ERROR: mtd_partition failed\n");
            return ret;
          }

        g_mtd_fs = mtd_temp;
      }
#endif

#ifdef HAVE_N25QXXX_SMARTFS
      /* Configure the device with no partition support */

      ret = smart_initialize(N25QXXX_SMART_MINOR, g_mtd_fs, NULL);
      if (ret != OK)
        {
          _err("ERROR: Failed to initialize SmartFS: %d\n", ret);
        }

#elif defined(HAVE_N25QXXX_NXFFS)
      /* Initialize to provide NXFFS on the N25QXXX MTD interface */

      ret = nxffs_initialize(g_mtd_fs);
      if (ret < 0)
        {
         _err("ERROR: NXFFS initialization failed: %d\n", ret);
        }

      /* Mount the file system at /mnt/nxffs */

      ret = mount(NULL, "/mnt/nxffs", "nxffs", 0, NULL);
      if (ret < 0)
        {
          _err("ERROR: Failed to mount the NXFFS volume: %d\n", errno);
          return ret;
        }

#else /* if  defined(HAVE_N25QXXX_CHARDEV) */
      /* Use the FTL layer to wrap the MTD driver as a block driver */

      ret = ftl_initialize(N25QXXX_MTD_MINOR, g_mtd_fs);
      if (ret < 0)
        {
          _err("ERROR: Failed to initialize the FTL layer: %d\n", ret);
          return ret;
        }

      /* Use the minor number to create device paths */

      snprintf(blockdev, 18, "/dev/mtdblock%d", N25QXXX_MTD_MINOR);
      snprintf(chardev, 12, "/dev/mtd%d", N25QXXX_MTD_MINOR);

      /* Now create a character device on the block device */

      /* NOTE:  for this to work, you will need to make sure that
       * CONFIG_FS_WRITABLE is set in the config.  It's not a user-
       * visible setting, but you can make it set by selecting an
       * arbitrary writable file system (you don't have to actually
       * use it, just select it so that the block device created via
       * ftl_initialize() will be writable).
       */

      ret = bchdev_register(blockdev, chardev, false);
      if (ret < 0)
        {
          _err("ERROR: bchdev_register %s failed: %d\n", chardev, ret);
          return ret;
        }
#endif
    }
#endif

#ifdef HAVE_USBHOST
  /* Initialize USB host operation.  stm32l4_usbhost_initialize() starts a thread
   * will monitor for USB connection and disconnection events.
   */

  ret = stm32l4_usbhost_initialize();
  if (ret != OK)
    {
      udbg("ERROR: Failed to initialize USB host: %d\n", ret);
      return ret;
    }
#endif

#ifdef HAVE_USBMONITOR
  /* Start the USB Monitor */

  ret = usbmonitor_start(0, NULL);
  if (ret != OK)
    {
      udbg("ERROR: Failed to start USB monitor: %d\n", ret);
      return ret;
    }
#endif

  return OK;
}
Esempio n. 12
0
int board_app_initialize(uintptr_t arg)
{
#ifdef HAVE_RTC_DRIVER
  FAR struct rtc_lowerhalf_s *rtclower;
#endif
  int ret;

  (void)ret;

  /* Configure CPU load estimation */

#ifdef CONFIG_SCHED_INSTRUMENTATION
  cpuload_initialize_once();
#endif

#ifdef HAVE_PROC
  /* Mount the proc filesystem */

  syslog(LOG_INFO, "Mounting procfs to /proc\n");

  ret = mount(NULL, CONFIG_NSH_PROC_MOUNTPOINT, "procfs", 0, NULL);
  if (ret < 0)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to mount the PROC filesystem: %d (%d)\n",
             ret, errno);
      return ret;
    }
#endif

#ifdef HAVE_RTC_DRIVER
  /* Instantiate the STM32L4 lower-half RTC driver */

  rtclower = stm32l4_rtc_lowerhalf();
  if (!rtclower)
    {
      serr("ERROR: Failed to instantiate the RTC lower-half driver\n");
      return -ENOMEM;
    }
  else
    {
      /* Bind the lower half driver and register the combined RTC driver
       * as /dev/rtc0
       */

      ret = rtc_initialize(0, rtclower);
      if (ret < 0)
        {
          serr("ERROR: Failed to bind/register the RTC driver: %d\n", ret);
          return ret;
        }
    }
#endif

#ifdef HAVE_MMCSD
  /* First, get an instance of the SDIO interface */

  g_sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO);
  if (!g_sdio)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SDIO slot %d\n",
             CONFIG_NSH_MMCSDSLOTNO);
      return -ENODEV;
    }

  /* Now bind the SDIO interface to the MMC/SD driver */

  ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, g_sdio);
  if (ret != OK)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n",
             ret);
      return ret;
    }

  /* Then let's guess and say that there is a card in the slot. There is no
   * card detect GPIO.
   */

  sdio_mediachange(g_sdio, true);

  syslog(LOG_INFO, "[boot] Initialized SDIO\n");
#endif

#ifdef CONFIG_AJOYSTICK
  /* Initialize and register the joystick driver */

  ret = board_ajoy_initialize();
  if (ret != OK)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to register the joystick driver: %d\n",
             ret);
      return ret;
    }
#endif

  return OK;
}
Esempio n. 13
0
/* Check if MAGIC is valid and print the Multiboot information structure
   pointed by ADDR. */
void
entry (unsigned long magic, unsigned long addr)
{
    /* Initialize the idt */
    init_idt();

    multiboot_info_t *mbi;

    /* Clear the screen. */
    clear();

    /* Am I booted by a Multiboot-compliant boot loader? */
    if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
    {
        printf ("Invalid magic number: 0x%#x\n", (unsigned) magic);
        return;
    }

    /* Set MBI to the address of the Multiboot information structure. */
    mbi = (multiboot_info_t *) addr;

    /* Print out the flags. */
    printf ("flags = 0x%#x\n", (unsigned) mbi->flags);

    /* Are mem_* valid? */
    if (CHECK_FLAG (mbi->flags, 0))
        printf ("mem_lower = %uKB, mem_upper = %uKB\n",
                (unsigned) mbi->mem_lower, (unsigned) mbi->mem_upper);

    /* Is boot_device valid? */
    if (CHECK_FLAG (mbi->flags, 1))
        printf ("boot_device = 0x%#x\n", (unsigned) mbi->boot_device);

    /* Is the command line passed? */
    if (CHECK_FLAG (mbi->flags, 2))
        printf ("cmdline = %s\n", (char *) mbi->cmdline);

    if (CHECK_FLAG (mbi->flags, 3)) {
        int mod_count = 0;
        int i;
        module_t* mod = (module_t*)mbi->mods_addr;

        starting_address = mod->mod_start;

        while(mod_count < mbi->mods_count) {
            printf("Module %d loaded at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_start);
            printf("Module %d ends at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_end);
            printf("First few bytes of module:\n");
            for(i = 0; i<16; i++) {
                printf("0x%x ", *((char*)(mod->mod_start+i)));
            }
            printf("\n");
            mod_count++;
            mod++;
        }
    }
    /* Bits 4 and 5 are mutually exclusive! */
    if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG (mbi->flags, 5))
    {
        printf ("Both bits 4 and 5 are set.\n");
        return;
    }

    /* Is the section header table of ELF valid? */
    if (CHECK_FLAG (mbi->flags, 5))
    {
        elf_section_header_table_t *elf_sec = &(mbi->elf_sec);

        printf ("elf_sec: num = %u, size = 0x%#x,"
                " addr = 0x%#x, shndx = 0x%#x\n",
                (unsigned) elf_sec->num, (unsigned) elf_sec->size,
                (unsigned) elf_sec->addr, (unsigned) elf_sec->shndx);
    }

    /* Are mmap_* valid? */
    if (CHECK_FLAG (mbi->flags, 6))
    {
        memory_map_t *mmap;

        printf ("mmap_addr = 0x%#x, mmap_length = 0x%x\n",
                (unsigned) mbi->mmap_addr, (unsigned) mbi->mmap_length);
        for (mmap = (memory_map_t *) mbi->mmap_addr;
                (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length;
                mmap = (memory_map_t *) ((unsigned long) mmap
                                         + mmap->size + sizeof (mmap->size)))
            printf (" size = 0x%x,     base_addr = 0x%#x%#x\n"
                    "     type = 0x%x,  length    = 0x%#x%#x\n",
                    (unsigned) mmap->size,
                    (unsigned) mmap->base_addr_high,
                    (unsigned) mmap->base_addr_low,
                    (unsigned) mmap->type,
                    (unsigned) mmap->length_high,
                    (unsigned) mmap->length_low);
    }

    /* Construct an LDT entry in the GDT */
    {
        seg_desc_t the_ldt_desc;
        the_ldt_desc.granularity    = 0;
        the_ldt_desc.opsize         = 1;
        the_ldt_desc.reserved       = 0;
        the_ldt_desc.avail          = 0;
        the_ldt_desc.present        = 1;
        the_ldt_desc.dpl            = 0x0;
        the_ldt_desc.sys            = 0;
        the_ldt_desc.type           = 0x2;

        SET_LDT_PARAMS(the_ldt_desc, &ldt, ldt_size);
        ldt_desc_ptr = the_ldt_desc;
        lldt(KERNEL_LDT);
    }

    /* Construct a TSS entry in the GDT */
    {
        seg_desc_t the_tss_desc;
        the_tss_desc.granularity    = 0;
        the_tss_desc.opsize         = 0;
        the_tss_desc.reserved       = 0;
        the_tss_desc.avail          = 0;
        the_tss_desc.seg_lim_19_16  = TSS_SIZE & 0x000F0000;
        the_tss_desc.present        = 1;
        the_tss_desc.dpl            = 0x0;
        the_tss_desc.sys            = 0;
        the_tss_desc.type           = 0x9;
        the_tss_desc.seg_lim_15_00  = TSS_SIZE & 0x0000FFFF;

        SET_TSS_PARAMS(the_tss_desc, &tss, tss_size);

        tss_desc_ptr = the_tss_desc;

        tss.ldt_segment_selector = KERNEL_LDT;
        tss.ss0 = KERNEL_DS;
        tss.esp0 = 0x800000;
        ltr(KERNEL_TSS);
    }

    /* Initialize the PIC */
    i8259_init();

    /* Initialize devices, memory, filesystem, enable device interrupts on the
     * PIC, any other initialization stuff... */
    initialize_paging();

    /* initialize the RTC to 2Hz */
    rtc_initialize();

    /* initialize keyboard */
    initialize_keyboard();
    /* initialize function pointers */
    func_init();
    /* TESTING FILE SYSTEMS */
    init_file_systems(starting_address);

    init_terminals();
    //printf("Init File Systems Done\n");
    //test_file_systems((uint8_t*)"frame0.txt");
    //printf("Done testing\n");
    /* FINISH FILE SYSTEMS TESTING */


    /* Enable interrupts */
    /* Do not enable the following until after you have set up your
     * IDT correctly otherwise QEMU will triple fault and simple close
     * without showing you any output */
    printf("Enabling Interrupts\n");
    sti();



    // testing for changing RTC freq

    /*int32_t * freq;
    int32_t temp = 1024;
    freq = &temp;
    rtc_write(freq, 4);
    int i;
    for(i = 0; i < 10; i ++) {
    	rtc_read();
    	printf("testing");
    }

    temp = 256;
    rtc_write(freq, 4);

    for (i = 0; i < 20; i++) {
    	rtc_read();
    	printf("\n");
    	printf("second_test");
    }*/






    /*while(1) {
    	asm volatile("int $0x28");
    }*/
    //int d = 6 / 0;

    /* Execute the first program (`shell') ... */
    clear();
    execute((uint8_t*)"shell");
    /* Spin (nicely, so we don't chew up cycles) */
    asm volatile(".1: hlt; jmp .1;");
}
Esempio n. 14
0
int board_app_initialize(uintptr_t arg)
{
#ifdef HAVE_RTC_DRIVER
  FAR struct rtc_lowerhalf_s *rtclower;
#endif
  int ret;

#ifdef HAVE_PROC
  /* mount the proc filesystem */

  syslog(LOG_INFO, "Mounting procfs to /proc\n");

  ret = mount(NULL, CONFIG_NSH_PROC_MOUNTPOINT, "procfs", 0, NULL);
  if (ret < 0)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to mount the PROC filesystem: %d (%d)\n",
             ret, errno);
      return ret;
    }
#endif

#ifdef HAVE_RTC_DRIVER
  /* Instantiate the STM32 lower-half RTC driver */

  rtclower = stm32l4_rtc_lowerhalf();
  if (!rtclower)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to instantiate the RTC lower-half driver\n");
      return -ENOMEM;
    }
  else
    {
      /* Bind the lower half driver and register the combined RTC driver
       * as /dev/rtc0
       */

      ret = rtc_initialize(0, rtclower);
      if (ret < 0)
        {
          syslog(LOG_ERR,
                 "ERROR: Failed to bind/register the RTC driver: %d\n",
                 ret);
          return ret;
        }
    }
#endif

#ifdef HAVE_USERLED_DRIVER
  /* Register the LED driver */

  ret = userled_lower_initialize("/dev/userleds");
  if (ret != OK)
    {
      syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n",
             ret);
      return ret;
    }
#endif

  UNUSED(ret);
  return OK;
}