예제 #1
0
/* SD Card Initilisation */
static bool microsd_card_init(FATFS* fs) {

    /* File System Return Code */
    FRESULT sderr;

    /* Initialise the SDC interface */
    sdcStart(&SDCD1, &sdccfg);

    /* Attempt to connect to the SD card */
    int i = sdcConnect(&SDCD1);
    if (i) {

        /* SD Card Connection Failure */
        COMPONENT_STATE_UPDATE(avionics_component_sd_card, state_error);
        return false;
    }

    /* Attempt to mount the filesystem */
    sderr = f_mount(fs, "A", 0);
    if(sderr != FR_OK) {

        /* SD Card Mounting Failure */
        COMPONENT_STATE_UPDATE(avionics_component_sd_card, state_error);
    };

    /* Return TRUE */
    return (sderr == FR_OK);
}
예제 #2
0
/*
 * Application entry point.
 */
int main(void) {
	/* HAL&RTOS init */
	halInit();
	chSysInit();

	/* SD/FATFS init */
	sdcStart(&SDCD1, NULL );
	wf_init(NORMALPRIO);

	/* POSIX compatibility layer initialization */
	posix_init();
	posix_init_chstream(STDIN_FILENO, (BaseSequentialStream *) &SDU1);
	posix_init_chstream(STDOUT_FILENO, (BaseSequentialStream *) &SDU1);
	posix_init_chstream(STDERR_FILENO, (BaseSequentialStream *) &SDU1);

	/* Initializes a serial-over-USB CDC driver */
	sduObjectInit(&SDU1);
	sduStart(&SDU1, &serusbcfg);

	usbDisconnectBus(serusbcfg.usbp);
	chThdSleepMilliseconds(1000);
	usbStart(serusbcfg.usbp, &usbcfg);
	usbConnectBus(serusbcfg.usbp);

	ngshell_init(&sh1, sh1_wa, SHELL_WA_SIZE, NORMALPRIO);

	while (TRUE)
		chThdSleepMilliseconds(500);
}
예제 #3
0
파일: sdio.c 프로젝트: 2seasuav/paparuzzi
bool sdioConnect (void)
{
  if (!sdc_lld_is_card_inserted (NULL)) {
    return false;
  }

  if (cnxState == CONNECT) {
    return true;
  }

  /*
   * Initializes the SDIO drivers.
   */
  const uint32_t mode = PAL_MODE_ALTERNATE(12) | PAL_STM32_OTYPE_PUSHPULL |
    PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_FLOATING | PAL_STM32_MODE_ALTERNATE;

  palSetPadMode (GPIOC, GPIOC_SDIO_D0, mode | PAL_STM32_PUDR_PULLUP);
  palSetPadMode (GPIOC, GPIOC_SDIO_D1, mode | PAL_STM32_PUDR_PULLUP);
  palSetPadMode (GPIOC, GPIOC_SDIO_D2, mode | PAL_STM32_PUDR_PULLUP);
  palSetPadMode (GPIOC, GPIOC_SDIO_D3, mode | PAL_STM32_PUDR_PULLUP);
  palSetPadMode (GPIOC, GPIOC_SDIO_CK, mode);
  palSetPadMode (GPIOD, GPIOD_SDIO_CMD, mode | PAL_STM32_PUDR_PULLUP);
  // palSetPadMode (GPIOD, GPIOD_SDIO_CMD, mode);

  chThdSleepMilliseconds(100);


  sdcStart(&SDCD1, NULL);
  while (sdcConnect(&SDCD1) != CH_SUCCESS) {
    chThdSleepMilliseconds(100);
  }

  cnxState = CONNECT;
  return true;
}
예제 #4
0
파일: kl_sd.cpp 프로젝트: Kreyl/nute
void sd_t::Init() {
    IsReady = FALSE;

    // Bus pins
    PinSetupAlterFunc(GPIOC,  8, omPushPull, pudPullUp, AF12, ps50MHz);
    PinSetupAlterFunc(GPIOC,  9, omPushPull, pudPullUp, AF12, ps50MHz);
    PinSetupAlterFunc(GPIOC, 10, omPushPull, pudPullUp, AF12, ps50MHz);
    PinSetupAlterFunc(GPIOC, 11, omPushPull, pudPullUp, AF12, ps50MHz);
    PinSetupAlterFunc(GPIOC, 12, omPushPull, pudNone,   AF12, ps50MHz);
    PinSetupAlterFunc(GPIOD,  2, omPushPull, pudPullUp, AF12, ps50MHz);
    // Power pin
    PinSetupOut(GPIOC, 4, omPushPull, pudNone);
    PinClear(GPIOC, 4); // Power on
    Delay_ms(450);

    FRESULT err;
    sdcInit();
    sdcStart(&SDCD1, NULL);
    if (sdcConnect(&SDCD1)) {
        Uart.Printf("SD connect error\r");
        return;
    }
    else {
        Uart.Printf("SD capacity: %u\r", SDCD1.capacity);
    }

    err = f_mount(0, &SDC_FS);
    if (err != FR_OK) {
        Uart.Printf("SD mount error\r");
        sdcDisconnect(&SDCD1);
        return;
    }
    IsReady = TRUE;
}
예제 #5
0
파일: main.c 프로젝트: GotoHack/ChibiOS
int init_sd(void) {
  BaseSequentialStream *chp = (BaseSequentialStream*)&SD6;

  /* power cycle sd card */
  //palSetPad(GPIOC, GPIOC_SDIO_POWER);
  //chThdSleepMilliseconds(1000);
  /* this is probably longer than needed */
  //palClearPad(GPIOC, GPIOC_SDIO_POWER);
  chThdSleepMilliseconds(100);
  /* let power stabilize */

  /* startup sdc driver */
  sdcStart(&SDCD1, NULL);

  if (sdcConnect(&SDCD1) == CH_FAILED) {
    chprintf(chp, "sdcConnect FAILED\r\n");
    uint32_t errors = sdcGetAndClearErrors(&SDCD1);
    chprintf(chp, "error flags %d\r\n", errors);
    /*FIXME: handle error*/
    return (1);
  } else {
    chprintf(chp, "sdcConnect SUCCEEDED\r\n");
  }

  return (0);
}
예제 #6
0
int main( void )
{
  uint8_t i;

  halInit();
  chSysInit();

  //  Mount the SD card
  sdcStart( &SDCD1, NULL );
  sdcConnect( &SDCD1 );
  f_mount( 0, & SDC_FS );

  //  Creates the blinker thread.
  chThdCreateStatic( waThread1, sizeof( waThread1 ), NORMALPRIO, Thread1, NULL );

  //  Creates the LWIP threads (it changes priority internally).
  chThdCreateStatic( wa_lwip_thread, LWIP_THREAD_STACK_SIZE, NORMALPRIO + 3,
                     lwip_thread, NULL );

  // Initialize web server
  http_server();

   //  Normal main() thread activity
  while( TRUE )
  {
    chThdSleepMilliseconds( 1000 );
  }
}
예제 #7
0
/*
 * Application entry point.
 */
int main(void) {
  static const evhandler_t evhndl[] = {
    InsertHandler,
    RemoveHandler
  };
  Thread *shelltp = NULL;
  struct EventListener el0, el1;

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Activates the serial driver 1 and SDC driver 1 using default
   * configuration.
   */
  sdStart(&SD1, NULL);
  sdcStart(&SDCD1, NULL);

  /*
   * Shell manager initialization.
   */
  shellInit();

  /*
   * Activates the card insertion monitor.
   */
  tmr_init(&SDCD1);

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  /*
   * Normal main() thread activity, in this demo it does nothing except
   * sleeping in a loop and listen for events.
   */
  chEvtRegister(&inserted_event, &el0, 0);
  chEvtRegister(&removed_event, &el1, 1);
  while (TRUE) {
    if (!shelltp)
      shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
    else if (chThdTerminated(shelltp)) {
      chThdRelease(shelltp);    /* Recovers memory of the previous shell.   */
      shelltp = NULL;           /* Triggers spawning of a new shell.        */
    }
    chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS));
  }
}
void init_fatfs( void )
{
    // Activates the SDC driver 1 using default configuration.
    sdcStart( &SDCD1, NULL );
    
    // Activates the card insertion monitor.
    tmr_init( &SDCD1 );
    
    chEvtRegister( &inserted_event, &el0, 0 );
    chEvtRegister( &removed_event, &el1, 1 );
}
예제 #9
0
/*
 * Application entry point.
 */
int main(void) {
  thread_t *shelltp = NULL;

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Shell manager initialization.
   */
  shellInit();

  /*
   * Activates the serial driver 6 using the driver default configuration.
   */
  sdStart(&SD6, NULL);

  /*
   * Initializes the SDIO drivers.
   */
  sdcStart(&SDCD1, &sdccfg);

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  /*
   * Normal main() thread activity, in this demo it does nothing.
   */
  while (true) {
    if (!shelltp)
      shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
    else if (chThdTerminatedX(shelltp)) {
      chThdRelease(shelltp);    /* Recovers memory of the previous shell.   */
      shelltp = NULL;           /* Triggers spawning of a new shell.        */
    }
    chThdSleepMilliseconds(1000);
  }
}
예제 #10
0
파일: microsd.cpp 프로젝트: barthess/u
/*
 * SD card insertion event.
 */
static void insert_handler(void) {
  FRESULT err;

  sdcStart(&SDCD1, &sdccfg);
  /*
   * On insertion SDC initialization and FS mount.
   */
  if (sdcConnect(&SDCD1))
    return;

  err = f_mount(0, &SDC_FS);
  if (err != FR_OK) {
    sdcDisconnect(&SDCD1);
    sdcStop(&SDCD1);
    return;
  }
  fs_ready = TRUE;
}
예제 #11
0
파일: main.c 프로젝트: AlexShiLucky/ChibiOS
/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Shell manager initialization.
   */
  shellInit();

  /*
   * Activates the serial driver 6 using the driver default configuration.
   */
  sdStart(&SD6, NULL);

  /*
   * Initializes the SDIO drivers.
   */
  sdcStart(&SDCD1, &sdccfg);

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  /*
   * Normal main() thread activity, spawning shells.
   */
  while (true) {
    thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
                                            "shell", NORMALPRIO + 1,
                                            shellThread, (void *)&shell_cfg1);
    chThdWait(shelltp);               /* Waiting termination.             */
    chThdSleepMilliseconds(1000);
  }
}
예제 #12
0
파일: sdcard.c 프로젝트: MaxPayne86/axoloti
void sdcardInit(void) {
  /*
   static const evhandler_t evhndl[] = {
   InsertHandler,
   RemoveHandler
   };
   struct EventListener el0, el1;
   */
  palSetPadMode(GPIOC, 8, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
  palSetPadMode(GPIOC, 9, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
  palSetPadMode(GPIOC, 10, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
  palSetPadMode(GPIOC, 11, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
  palSetPadMode(GPIOC, 12, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
  palSetPadMode(GPIOD, 2, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
  chThdSleepMilliseconds(50);
  sdcStart(&SDCD1, NULL);
  chThdSleepMilliseconds(50);

  InsertHandler(0);

  FRESULT err;
  uint32_t clusters;
  FATFS *fsp;

  err = f_getfree("/", &clusters, &fsp);
  int retries = 3;
  while (err != FR_OK) {
    InsertHandler(0);
    chThdSleepMilliseconds(20);
    err = f_getfree("/", &clusters, &fsp);
    chThdSleepMilliseconds(50);
    retries--;
    if (!retries)
      break;
  }
}
예제 #13
0
파일: main.c 프로젝트: 0x00f/ChibiOS
/*
 * Application entry point.
 */
int main(void) {
  halInit();
  chSysInit();

  /* start debugging serial link */
  sdStart(&SD2, &ser_cfg);
  shellInit();
  static WORKING_AREA(waShell, 4096);
  shellCreateStatic(&shell_cfg1, waShell, sizeof(waShell), NORMALPRIO);

  /*
   * Initializes the SDIO drivers.
   */
  sdcStart(&SDCD1, &sdccfg);

  /*
   * Normal main() thread activity.
   * Blinking signaling about successful passing.
   */
  while (TRUE) {
    palTogglePad(GPIOB, GPIOB_LED_R);
    chThdSleepMilliseconds(100);
  }
}
예제 #14
0
파일: main.c 프로젝트: pfhnr/stm32
int main(void) {
  static Thread *shelltp = NULL;
  static const evhandler_t evhndl[] = {
    InsertHandler,
    RemoveHandler,
	 packetReceivedHandler
  };
  struct EventListener el0, el1, el2;
	chEvtRegister(&packet_event, &el2, 0);
	chEvtInit(&packet_event);

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Initializes a serial-over-USB CDC driver.
   */
  sduObjectInit(&SDU1);
  sduStart(&SDU1, &serusbcfg);

  /*
   * Activates the USB driver and then the USB bus pull-up on D+.
   * Note, a delay is inserted in order to not have to disconnect the cable
   * after a reset.
   */
  usbDisconnectBus(serusbcfg.usbp);
  chThdSleepMilliseconds(1000);
  usbStart(serusbcfg.usbp, &usbcfg);
  usbConnectBus(serusbcfg.usbp);

  /*
   * Shell manager initialization.
   */
  shellInit();

  /*
   * Activates the serial driver 6 and SDC driver 1 using default
   * configuration.
   */
  sdStart(&SD6, NULL);
  sdcStart(&SDCD1, NULL);

  /*
   * Activates the card insertion monitor.
   */
  tmr_init(&SDCD1);

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  /*
   * Creates the LWIP threads (it changes priority internally).
   */
  chThdCreateStatic(wa_lwip_thread, LWIP_THREAD_STACK_SIZE, NORMALPRIO + 2,
                    lwip_thread, NULL);

  /*
   * Creates the HTTP thread (it changes priority internally).
   */
	/*
  chThdCreateStatic(wa_http_server, sizeof(wa_http_server), NORMALPRIO + 1,
                    http_server, NULL);

	*/

	WORKING_AREA(wa_udp_receive_server, PWM_REC_STACK_SIZE);
	chThdCreateStatic(wa_udp_receive_server, sizeof(wa_udp_receive_server), NORMALPRIO +1,
							udp_receive_server_init, NULL);

  /*
   * Normal main() thread activity, in this demo it does nothing except
   * sleeping in a loop and listen for events.
   */
  chEvtRegister(&inserted_event, &el0, 0);
  chEvtRegister(&removed_event, &el1, 1);
  while (TRUE) {
    if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE))
      shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
    else if (chThdTerminated(shelltp)) {
      chThdRelease(shelltp);    /* Recovers memory of the previous shell.   */
      shelltp = NULL;           /* Triggers spawning of a new shell.        */
    }
    if (palReadPad(GPIOA, GPIOA_BUTTON_WKUP) != 0) {
    }
    chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));
  }
}
예제 #15
0
int main(void)
{
    halInit();
    chSysInit();

    timestamp_stm32_init();

    board_io_pwr_en(true);
    board_sensor_pwr_en(true);

    error_init();

    // standard output
    sdStart(&UART_CONN1, NULL);
    stdout = (BaseSequentialStream*)&UART_CONN1;
    chprintf(stdout, "\n\n\n");

    log_init();
    log_handler_register(&log_handler_stdout, LOG_LVL_DEBUG, log_handler_stdout_cb);
    log_info("=== boot ===");

    led_start();

    // mount SD card
    board_power_cycle_sdcard();
    sdcStart(&SDCD1, NULL);
    sdcard_mount();

    static char logdir[100];
    if (sdcard_find_next_file_name_with_prefix("/", "log_", logdir, sizeof(logdir)) < 0) {
        log_error("could not determine log file directory");
    }
    FRESULT res = f_mkdir(logdir);
    if (!(res == FR_OK || res == FR_EXIST)) {
        log_warning("could not create log directory %s", logdir);
    }
    size_t logdir_strlen = strlen(logdir);
    if (sdcard_is_mounted()) {
        // add .txt to logdir
        strncpy(&logdir[logdir_strlen], "/log.txt", sizeof(logdir) - logdir_strlen);
        logdir[sizeof(logdir)-1] = '\0';
        sdcard_log_handler_init(logdir, LOG_LVL_INFO);
        logdir[logdir_strlen] = '\0'; // reset log dir string
    }

    log_boot_message();

    // initialization
    parameter_namespace_declare(&parameters, NULL, NULL); // root namespace
    parameter_string_declare_with_default(&board_name,
                                          &parameters,
                                          "name",
                                          board_name_p_buf,
                                          sizeof(board_name_p_buf),
                                          "ins-board");

    msgbus_init(&bus);

    services_init();


    // load parameters from SD card
    log_info("loading parameters from sd card");
    sdcard_read_parameter(&parameters, "/config.msgpack");
    chprintf(stdout, "current parameters:");
    parameter_print(&parameters, (parameter_printfn_t)chprintf, stdout);

    // UART driver
    io_setup();

    // USB serial driver
    sduObjectInit(&SDU1);
    sduStart(&SDU1, &serusbcfg);
    usbDisconnectBus(serusbcfg.usbp);
    chThdSleepMilliseconds(100);
    usbStart(serusbcfg.usbp, &usbcfg);
    usbConnectBus(serusbcfg.usbp);

    // start all services
    services_start(logdir);

    // shellInit();
    // char buf[STREAM_DEV_STR_SIZE];
    // parameter_string_get(&shell_port, buf, sizeof(buf));
    // BaseSequentialStream* shell_dev = get_base_seq_stream_device_from_str(buf);
    // static thread_t *shelltp = NULL;
    // static ShellConfig shell_cfg;
    // shell_cfg.sc_channel = shell_dev;
    // shell_cfg.sc_commands = shell_commands;

    chThdSleepMilliseconds(500);

    while (true) {
        // if (shelltp == NULL && shell_dev != NULL) {
        //     static THD_WORKING_AREA(shell_wa, 2048);
        //     shelltp = shellCreateStatic(&shell_cfg, shell_wa, sizeof(shell_wa), THD_PRIO_SHELL);
        // } else if (shelltp != NULL && chThdTerminatedX(shelltp)) {
        //     shelltp = NULL;
        // }
        log_debug("VCC %f", analog_get_vcc());
        log_debug("Temp %f", analog_get_cpu_temp());
        log_debug("V_DC %f", analog_get_vdc());
        log_debug("CONN2_TX %f", analog_get_voltage(ANALOG_CH_CONN2_TX));
        log_debug("CONN2_RX %f", analog_get_voltage(ANALOG_CH_CONN2_RX));
        log_debug("CONN3_TX %f", analog_get_voltage(ANALOG_CH_CONN3_TX));
        log_debug("CONN3_RX %f", analog_get_voltage(ANALOG_CH_CONN3_RX));
        chThdSleepMilliseconds(500);
    }
}
예제 #16
0
/*
 * Application entry point.
 */
int main(void) {
  static thread_t *shelltp = NULL;
//  static const evhandler_t evhndl[] = {
//    InsertHandler,
//    RemoveHandler
//  };
//  event_listener_t el0, el1;

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   * - lwIP subsystem initialization using the default configuration.
   */
  halInit();
  chSysInit();
  lwipInit(NULL);

  /*
   * Initializes a serial-over-USB CDC driver.
   */
  sduObjectInit(&SDU2);
  sduStart(&SDU2, &serusbcfg);

  /*
   * Activates the USB driver and then the USB bus pull-up on D+.
   * Note, a delay is inserted in order to not have to disconnect the cable
   * after a reset.
   */
  usbDisconnectBus(serusbcfg.usbp);
  chThdSleepMilliseconds(1500);
  usbStart(serusbcfg.usbp, &usbcfg);
  usbConnectBus(serusbcfg.usbp);

  /*
   * Shell manager initialization.
   */
  shellInit();

  /*
   * Activates the serial driver 1 and SDC driver 1 using default
   * configuration.
   */
  sdStart(&SD1, NULL);
  sdcStart(&SDCD1, NULL);

  /*
   * Activates the card insertion monitor.
   */
//  tmr_init(&SDCD1);

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  /*
   * Creates the HTTP thread (it changes priority internally).
   */
  chThdCreateStatic(wa_http_server, sizeof(wa_http_server), NORMALPRIO + 1,
                    http_server, NULL);

  /*
   * Normal main() thread activity, in this demo it does nothing except
   * sleeping in a loop and listen for events.
   */
//  chEvtRegister(&inserted_event, &el0, 0);
//  chEvtRegister(&removed_event, &el1, 1);
  while (true) {
    if (!shelltp && (SDU2.config->usbp->state == USB_ACTIVE))
      shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
    else if (chThdTerminatedX(shelltp)) {
      chThdRelease(shelltp);    /* Recovers memory of the previous shell.   */
      shelltp = NULL;           /* Triggers spawning of a new shell.        */
    }
    if (palReadPad(GPIOI, GPIOI_BUTTON_USER) != 0) {
    }
//    chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));
    chThdSleepMilliseconds(500);
  }
}
예제 #17
0
파일: main.c 프로젝트: naniBox/kuroBox
//-----------------------------------------------------------------------------
int
kuroBoxInit(void)
{
	halInit();
	chSysInit();

	PWR->CSR &= ~PWR_CSR_EWUP;

	kbg_setLED1(1);
	kbg_setLED2(1);
	kbg_setLED3(1);

	// Serial
	kuroBoxSerialInit(NULL, NULL);

	// start the SPI bus, just use the LCD's SPI config since
	// it's shared with the eeprom
	spiStart(&SPID1, &lcd_cfg.spicfg);
	memset(lcd_buffer, 0, sizeof(lcd_buffer));
	st7565Start(&ST7565D1, &lcd_cfg, &SPID1, lcd_buffer);
	
	// EEPROM
	spiEepromStart(&spiEepromD1, &eeprom_cfg, &SPID1);
	
	// SDIO 
	sdcStart(&SDCD1, &sdio_cfg);
	
	// just blink to indicate we haven't crashed
#ifdef HAVE_BLINK_THREAD
	blinkerThread = chThdCreateStatic(waBlinker, sizeof(waBlinker), NORMALPRIO, thBlinker, NULL);
#endif // HAVE_BLINK_THREAD

	// read config goes here
	// @TODO: add config reading from eeprom
	
	// ADC to monitor voltage levels.
	// start all the ADC stuff!
	kuroBoxADCInit();
	
	// init the screen, this will spawn a thread to keep it updated
	kuroBoxScreenInit();

	// LTC's, interrupt driven, very quick now
	// Note, this module must be init'd after the screen
	kuroBoxTimeInit();

	// the actual logging thread
	kuroBoxWriterInit();

	// this turns on Layer 1 power, this turns on the mosfets controlling the
	// VCC rail. After this, we can start GPS, VectorNav and altimeter
	kbg_setL1PowerOn();

	// wait for it to stabilise, poweron devices, and let them start before continuing
	chThdSleepMilliseconds(500);

	// gps uart
	kuroBoxGPSInit(&SD6);

	VND1.spip = &SPID2;
	VND1.gpdp = &GPTD14;
	kuroBoxVectorNavInit(&VND1, NULL); // use the defaults

	// start I2C here, since it's a shared bus
	i2cStart(&I2CD2, &i2cfg2);

	// and the altimeter, also spawns a thread.
	kuroBoxAltimeterInit();

	// init the menu structure, and thread, if needed
	kuroBoxMenuInit();

	// set initial button state, AFTER menus!
	kuroBoxButtonsInit();

	// read all configs from bksram and load them up thoughout the system
	kuroBoxConfigInit();

	// Feature "A" - just a test feature that sends updates over serial
	kuroBoxExternalDisplayInit();

	// indicate we're ready
	chprintf(DEBG, "%s\n\r\n\r", BOARD_NAME);
	chThdSleepMilliseconds(50);
	kbg_setLED1(0);
	kbg_setLED2(0);
	kbg_setLED3(0);

	// all external interrupts, all the system should now be ready for it
	extStart(&EXTD1, &extcfg);

	return KB_OK; 
}
예제 #18
0
파일: main.c 프로젝트: ChibiOS/ChibiOS
/*
 * Application entry point.
 */
int main(void) {
  static const evhandler_t evhndl[] = {
    InsertHandler,
    RemoveHandler,
    ShellHandler
  };
  event_listener_t el0, el1, el2;

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   * - lwIP subsystem initialization using the default configuration.
   */
  halInit();
  chSysInit();

  /*
   * Initialize RNG
   */
  rccEnableAHB2(RCC_AHB2ENR_RNGEN, 0);
  RNG->CR |= RNG_CR_IE;
  RNG->CR |= RNG_CR_RNGEN;

  /* lwip */
  lwipInit(NULL);

  /*
   * Target-dependent setup code.
   */
  portab_setup();

  /*
   * Initializes a serial-over-USB CDC driver.
   */
  sduObjectInit(&PORTAB_SDU1);
  sduStart(&PORTAB_SDU1, &serusbcfg);

  /*
   * Activates the USB driver and then the USB bus pull-up on D+.
   * Note, a delay is inserted in order to not have to disconnect the cable
   * after a reset.
   */
  usbDisconnectBus(serusbcfg.usbp);
  chThdSleepMilliseconds(1500);
  usbStart(serusbcfg.usbp, &usbcfg);
  usbConnectBus(serusbcfg.usbp);

  /*
   * Shell manager initialization.
   */
  shellInit();

  /*
   * Activates the  SDC driver 1 using default configuration.
   */
  sdcStart(&SDCD1, NULL);

  /*
   * Activates the card insertion monitor.
   */
  tmr_init(&SDCD1);

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  /*
   * Creates the HTTPS thread (it changes priority internally).
   */
  chThdCreateStatic(wa_https_server, sizeof(wa_https_server), NORMALPRIO + 1,
                    https_server, NULL);

  /*
   * Normal main() thread activity, handling SD card events and shell
   * start/exit.
   */
  chEvtRegister(&inserted_event, &el0, 0);
  chEvtRegister(&removed_event, &el1, 1);
  chEvtRegister(&shell_terminated, &el2, 2);
  while (true) {
    if (!shelltp && (PORTAB_SDU1.config->usbp->state == USB_ACTIVE)) {
      shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
                                    "shell", NORMALPRIO + 1,
                                    shellThread, (void *)&shell_cfg1);
    }
    chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, TIME_MS2I(500)));
  }
}
예제 #19
0
파일: main.c 프로젝트: AndrewCapon/axoloti
int main(void)
{
  // copy vector table
  memcpy((char *)0x20000000, (const char *)&_vectors, 0x200);
  // remap SRAM1 to 0x00000000
  SYSCFG->MEMRMP |= 0x03;

    /* system & hardware initialization */
    halInit();

    // float usb inputs, hope the host notices detach...
    palSetPadMode(GPIOA, 11, PAL_MODE_INPUT);
    palSetPadMode(GPIOA, 12, PAL_MODE_INPUT);
    // setup LEDs
    palSetPadMode(LED1_PORT,LED1_PIN,PAL_MODE_OUTPUT_PUSHPULL);
    palSetPadMode(LED2_PORT, LED2_PIN, PAL_MODE_OUTPUT_PUSHPULL);
    palClearPad(LED1_PORT,LED1_PIN);
    palSetPad(LED2_PORT,LED2_PIN);

    chSysInit();

    palSetPadMode(GPIOA, 11, PAL_MODE_ALTERNATE(10));
    palSetPadMode(GPIOA, 12, PAL_MODE_ALTERNATE(10));

    palSetPadMode(GPIOC, 8, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
    palSetPadMode(GPIOC, 9, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
    palSetPadMode(GPIOC, 10, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
    palSetPadMode(GPIOC, 11, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
    palSetPadMode(GPIOC, 12, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
    palSetPadMode(GPIOD, 2, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST);
    chThdSleepMilliseconds(50);

    /* initialize the SD card */
    sdcStart(&SDCD1, NULL);
    sdcConnect(&SDCD1);

    /* initialize the USB mass storage driver */
    msdInit(&UMSD1);

    /* turn off green LED, turn on red LED */
    palSetPadMode(LED1_PORT, LED1_PIN, PAL_MODE_OUTPUT_PUSHPULL);
    palClearPad(LED1_PORT, LED1_PIN);
    palSetPadMode(LED2_PORT, LED2_PIN, PAL_MODE_OUTPUT_PUSHPULL);
    palSetPad(LED2_PORT, LED2_PIN);

    /* start the USB mass storage service */
    int ret = msdStart(&UMSD1, &msdConfig);
    if (ret != 0) {
        /* no media found : bye bye !*/
        usbDisconnectBus(&USBD1);
        chThdSleepMilliseconds(1000);
        NVIC_SystemReset();
    }

    /* watch the mass storage events */
    EventListener connected;
    EventListener ejected;
    chEvtRegisterMask(&UMSD1.evt_connected, &connected, EVENT_MASK(1));
    chEvtRegisterMask(&UMSD1.evt_ejected, &ejected, EVENT_MASK(2));


    /* start the USB driver */
    usbDisconnectBus(&USBD1);
    chThdSleepMilliseconds(1000);
    usbStart(&USBD1, &usbConfig);
    usbConnectBus(&USBD1);


    while (TRUE)
    {
        eventmask_t event = chEvtWaitOne(EVENT_MASK(1) | EVENT_MASK(2));
        if (event == EVENT_MASK(1))
        {
            /* media connected */
        }
        else if (event == EVENT_MASK(2))
        {
            /* media ejected : bye bye !*/
            usbDisconnectBus(&USBD1);
            chThdSleepMilliseconds(1000);
            NVIC_SystemReset();
        }
    }

    return 0;
}
예제 #20
0
파일: main.c 프로젝트: nistumpe/Workspace
/*
 * Application entry point.
 */
int main(void) {

    /*
     * System initializations.
     * - HAL initialization, this also initializes the configured device drivers
     *   and performs the board-specific initializations.
     * - Kernel initialization, the main() function becomes a thread and the
     *   RTOS is active.
     */
    halInit();
    chSysInit();

    /*
     * Initializes the SDIO drivers.
     */
    sdcStart(&SDCD1, &sdccfg);
    if (!sdcConnect(&SDCD1)) {
        int i;

        /* Single aligned read.*/
        if (sdcRead(&SDCD1, 0, blkbuf, 1))
            chSysHalt();

        /* Single unaligned read.*/
        if (sdcRead(&SDCD1, 0, blkbuf + 1, 1))
            chSysHalt();

        /* Multiple aligned read.*/
        if (sdcRead(&SDCD1, 0, blkbuf, 4))
            chSysHalt();

        /* Multiple unaligned read.*/
        if (sdcRead(&SDCD1, 0, blkbuf + 1, 4))
            chSysHalt();

        /* Repeated multiple aligned reads.*/
        for (i = 0; i < 1000; i++) {
            if (sdcRead(&SDCD1, 0, blkbuf, 4))
                chSysHalt();
        }

        /* Repeated multiple unaligned reads.*/
        for (i = 0; i < 1000; i++) {
            if (sdcRead(&SDCD1, 0, blkbuf + 1, 4))
                chSysHalt();
        }

        /* Repeated multiple aligned writes.*/
        for (i = 0; i < 100; i++) {
            if (sdcRead(&SDCD1, 0x10000, blkbuf, 4))
                chSysHalt();
            if (sdcWrite(&SDCD1, 0x10000, blkbuf, 4))
                chSysHalt();
            if (sdcWrite(&SDCD1, 0x10000, blkbuf, 4))
                chSysHalt();
        }

        /* Repeated multiple unaligned writes.*/
        for (i = 0; i < 100; i++) {
            if (sdcRead(&SDCD1, 0x10000, blkbuf + 1, 4))
                chSysHalt();
            if (sdcWrite(&SDCD1, 0x10000, blkbuf + 1, 4))
                chSysHalt();
            if (sdcWrite(&SDCD1, 0x10000, blkbuf + 1, 4))
                chSysHalt();
        }

        if (sdcDisconnect(&SDCD1))
            chSysHalt();
    }

    /*
     * Normal main() thread activity.
     */
    while (TRUE) {
        chThdSleepMilliseconds(500);
    }
}