/** \brief Initialize the Sensor Platform Hardware
 *
 * This function initializes the Atmel \c Xplained platform hardware and
 * must be called once from the client application before any of the Sensors
 * Xplained API routines can be used.
 *
 * After the platform board initialization (i.e. board_init()) configures
 * GPIO pins, interrupts, etc., this routine initializes the AVR and AVR32
 * hardware abstraction layer (HAL) for the Xplained Sensor API.
 *
 * \return  bool    true if the call succeeds, else false is returned.
 */
bool sensor_platform_init(void)
{
	bool initialized = false;

	/* Initialize the system clock and all clocks derived from it. */

	sysclk_init();

	/* Initialize the board (UC3/XMEGA Xplained & Sensor Xplained boards)
	 * I/O pin mappings and any other configurable resources selected in
	 * the build configuration.
	 */

	board_init();

	/* Initialize the sensor bus I/O interface. */

	if (BUSIO_TYPE != BUS_TYPE_UNKNOWN) {
		initialized = sensor_bus_init(&BUSIO_IF, BUSIO_SPEED);
	}

	/* Initialize C Standard I/O (stdio) Redirection. */

#if defined(CONF_STDIO_REDIRECT)
#  if defined(CONF_STDIO_USB)

	/* Start and attach USB CDC device interface for devices with
	 * integrated USB interfaces.
	 */

	stdio_usb_init();
#  elif defined(CONF_STDIO_SERIAL)

	/* Assume the USART is mapped to an appropriate phy in the board
	 * initialization code (e.g. board_init) and initialize terminal
	 * and clib I/O facilities here.
	 */

	usart_serial_options_t const USART_SERIAL_OPTIONS = {
		.baudrate     = CONFIG_USART_BAUDRATE,
		.charlength   = CONFIG_USART_CHAR_LENGTH,
		.paritytype   = CONFIG_USART_PARITY,
		.stopbits     = CONFIG_USART_STOP_BIT
	};

	stdio_serial_init(&CONFIG_USART_IF, &USART_SERIAL_OPTIONS);
#  endif
#endif  /* defined(CONF_STDIO_REDIRECT) */

	/* Sensor devices typically require time to settle after power
	 * is applied.  Wait here for a standard time.  (Individual sensor
	 * drivers may need to wait an additional period during initialization
	 * if the device is particularly slow to settle.)
	 */
	delay_ms(SENSOR_START_DELAY_MSEC);

	return initialized;
}
Пример #2
0
Файл: init.c Проект: XRobinHe/lk
void target_init(void)
{
    stm32_debug_init();

    qspi_flash_init(N25Q128A_FLASH_SIZE);

#if ENABLE_LCD
    memory_lcd_init();
#endif

#if WITH_LIB_MINIP
    uint8_t mac_addr[6];
    gen_random_mac_address(mac_addr);
    eth_init(mac_addr, PHY_KSZ8721);

    /* start minip */
    minip_set_macaddr(mac_addr);

    uint32_t ip_addr = IPV4(192, 168, 0, 98);
    uint32_t ip_mask = IPV4(255, 255, 255, 0);
    uint32_t ip_gateway = IPV4_NONE;

    minip_init(stm32_eth_send_minip_pkt, NULL, ip_addr, ip_mask, ip_gateway);
#endif

#if WITH_LIB_FS_SPIFS
    status_t mount_success = fs_mount(DEAULT_SPIFS_MOUNT_POINT,
                                      DEAULT_SPIFS_NAME, SPIFS_TARGET_DEVICE);
    if (mount_success != NO_ERROR) {
        printf("failed to mount '%s' at path '%s' on '%s'."
               " Make sure that device is formatted\n",
               DEAULT_SPIFS_NAME, DEAULT_SPIFS_MOUNT_POINT,
               SPIFS_TARGET_DEVICE);
    }

#endif

    // start usb
    target_usb_setup();

#if ENABLE_SENSORBUS
    sensor_bus_init();
#endif
}