Beispiel #1
0
/* Initialise HoTT receiver interface */
int32_t PIOS_HSUM_Init(uintptr_t *hsum_id,
                       const struct pios_com_driver *driver,
                       uintptr_t lower_id,
                       enum pios_hsum_proto proto)
{
	PIOS_DEBUG_Assert(hsum_id);
	PIOS_DEBUG_Assert(driver);

	struct pios_hsum_dev *hsum_dev;

	hsum_dev = (struct pios_hsum_dev *)PIOS_HSUM_Alloc();
	if (!hsum_dev)
		return -1;

	/* Bind the configuration to the device instance */
	hsum_dev->proto = proto;

	PIOS_HSUM_ResetState(hsum_dev);

	*hsum_id = (uintptr_t)hsum_dev;

	/* Set comm driver callback */
	(driver->bind_rx_cb)(lower_id, PIOS_HSUM_RxInCallback, *hsum_id);

	if (!PIOS_RTC_RegisterTickCallback(PIOS_HSUM_Supervisor, *hsum_id)) {
		PIOS_DEBUG_Assert(0);
	}

	return 0;
}
Beispiel #2
0
extern int32_t PIOS_RFM22B_Rcvr_Init(uintptr_t * rfm22b_rcvr_id, uint32_t rfm22b_id)
{
	struct pios_rfm22b_rcvr_dev *rfm22b_rcvr_dev;

	/* Allocate the device structure */
	rfm22b_rcvr_dev =
	    (struct pios_rfm22b_rcvr_dev *)PIOS_RFM22B_Rcvr_alloc();
	if (!rfm22b_rcvr_dev) {
		return -1;
	}

	/* Register uavobj callback */
    RFM22BReceiverInitialize();

    *rfm22b_rcvr_id = (uintptr_t) rfm22b_rcvr_dev;
	PIOS_RFM22B_RegisterRcvr(rfm22b_id, *rfm22b_rcvr_id);

	/* Register the failsafe timer callback. */
	if (!PIOS_RTC_RegisterTickCallback
	    (PIOS_RFM22B_Rcvr_Supervisor, *rfm22b_rcvr_id)) {
		PIOS_DEBUG_Assert(0);
	}

	return 0;
}
int32_t PIOS_RFM22B_RCVR_Init(uint32_t rcvr_id)
{
	struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rcvr_id;
	if (!PIOS_RFM22B_validate(rfm22b_dev))
		return -1;

	// Initialize
	for (uint8_t i = 0; i < PIOS_RFM22B_RCVR_MAX_CHANNELS; ++i)
		rfm22b_dev->ppm_channel[i] = PIOS_RCVR_TIMEOUT;
	rfm22b_dev->ppm_supv_timer = 0;

	// Register the failsafe timer callback.
	if (!PIOS_RTC_RegisterTickCallback(PIOS_RFM22B_RCVR_Supervisor, rcvr_id))
		PIOS_DEBUG_Assert(0);

	return 0;
}
Beispiel #4
0
extern int32_t PIOS_GCSRCVR_Init(uint32_t *gcsrcvr_id)
{
	struct pios_gcsrcvr_dev *gcsrcvr_dev;

	/* Allocate the device structure */
	gcsrcvr_dev = (struct pios_gcsrcvr_dev *)PIOS_gcsrcvr_alloc();
	if (!gcsrcvr_dev)
		return -1;

	/* Register uavobj callback */
	GCSReceiverConnectCallback (gcsreceiver_updated);

	/* Register the failsafe timer callback. */
	if (!PIOS_RTC_RegisterTickCallback(PIOS_gcsrcvr_Supervisor, (uint32_t)gcsrcvr_dev)) {
		PIOS_DEBUG_Assert(0);
	}

	return 0;
}
Beispiel #5
0
/* Initialise S.Bus receiver interface */
int32_t PIOS_SBus_Init(uint32_t *sbus_id,
		       const struct pios_sbus_cfg *cfg,
		       const struct pios_com_driver *driver,
		       uint32_t lower_id)
{
	PIOS_DEBUG_Assert(sbus_id);
	PIOS_DEBUG_Assert(cfg);
	PIOS_DEBUG_Assert(driver);

	struct pios_sbus_dev *sbus_dev;

	sbus_dev = (struct pios_sbus_dev *)PIOS_SBus_Alloc();
	if (!sbus_dev) goto out_fail;

	/* Bind the configuration to the device instance */
	sbus_dev->cfg = cfg;

	PIOS_SBus_ResetState(&(sbus_dev->state));

	*sbus_id = (uint32_t)sbus_dev;

	/* Enable inverter clock and enable the inverter */
	(*cfg->gpio_clk_func)(cfg->gpio_clk_periph, ENABLE);
	GPIO_Init(cfg->inv.gpio, &cfg->inv.init);
	GPIO_WriteBit(cfg->inv.gpio, cfg->inv.init.GPIO_Pin, cfg->gpio_inv_enable);

	/* Set comm driver callback */
	(driver->bind_rx_cb)(lower_id, PIOS_SBus_RxInCallback, *sbus_id);

	if (!PIOS_RTC_RegisterTickCallback(PIOS_SBus_Supervisor, *sbus_id)) {
		PIOS_DEBUG_Assert(0);
	}

	return 0;

out_fail:
	return -1;
}
Beispiel #6
0
extern int32_t PIOS_GCSRCVR_Init(uintptr_t *gcsrcvr_id)
{
	struct pios_gcsrcvr_dev *gcsrcvr_dev;

	/* Allocate the device structure */
	gcsrcvr_dev = (struct pios_gcsrcvr_dev *)PIOS_gcsrcvr_alloc();
	if (!gcsrcvr_dev)
		return -1;

	for (uint8_t i = 0; i < GCSRECEIVER_CHANNEL_NUMELEM; i++) {
		/* Flush channels */
		gcsreceiverdata.Channel[i] = PIOS_RCVR_TIMEOUT;
	}

	/* Register uavobj callback */
	GCSReceiverConnectCallback (gcsreceiver_updated);

	/* Register the failsafe timer callback. */
	if (!PIOS_RTC_RegisterTickCallback(PIOS_gcsrcvr_Supervisor, (uintptr_t)gcsrcvr_dev)) {
		PIOS_DEBUG_Assert(0);
	}

	return 0;
}
Beispiel #7
0
extern int32_t PIOS_PPM_Init(uint32_t * ppm_id, const struct pios_ppm_cfg * cfg)
{
	PIOS_DEBUG_Assert(ppm_id);
	PIOS_DEBUG_Assert(cfg);

	struct pios_ppm_dev * ppm_dev;

	ppm_dev = (struct pios_ppm_dev *) PIOS_PPM_alloc();
	if (!ppm_dev) goto out_fail;

	/* Bind the configuration to the device instance */
	ppm_dev->cfg = cfg;

	/* Set up the state variables */
	ppm_dev->PulseIndex = 0;
	ppm_dev->PreviousTime = 0;
	ppm_dev->CurrentTime = 0;
	ppm_dev->DeltaTime = 0;
	ppm_dev->LargeCounter = 0;
	ppm_dev->NumChannels = -1;
	ppm_dev->NumChannelsPrevFrame = -1;
	ppm_dev->NumChannelCounter = 0;
	ppm_dev->Tracking = FALSE;
	ppm_dev->Fresh = FALSE;

	for (uint8_t i = 0; i < PIOS_PPM_IN_MAX_NUM_CHANNELS; i++) {
		/* Flush counter variables */
		ppm_dev->CaptureValue[i] = 0;
		ppm_dev->CaptureValueNewFrame[i] = 0;

	}

	uint32_t tim_id;
	if (PIOS_TIM_InitChannels(&tim_id, cfg->channels, cfg->num_channels, &tim_callbacks, (uint32_t)ppm_dev)) {
		return -1;
	}

	/* Configure the channels to be in capture/compare mode */
	for (uint8_t i = 0; i < cfg->num_channels; i++) {
		const struct pios_tim_channel * chan = &cfg->channels[i];

		/* Configure timer for input capture */
		TIM_ICInitTypeDef TIM_ICInitStructure = cfg->tim_ic_init;
		TIM_ICInitStructure.TIM_Channel = chan->timer_chan;
		TIM_ICInit(chan->timer, &TIM_ICInitStructure);

		/* Enable the Capture Compare Interrupt Request */
		switch (chan->timer_chan) {
		case TIM_Channel_1:
			TIM_ITConfig(chan->timer, TIM_IT_CC1 | TIM_IT_Update, ENABLE);
			break;
		case TIM_Channel_2:
			TIM_ITConfig(chan->timer, TIM_IT_CC2 | TIM_IT_Update, ENABLE);
			break;
		case TIM_Channel_3:
			TIM_ITConfig(chan->timer, TIM_IT_CC3 | TIM_IT_Update, ENABLE);
			break;
		case TIM_Channel_4:
			TIM_ITConfig(chan->timer, TIM_IT_CC4 | TIM_IT_Update, ENABLE);
			break;
		}
	}

	/* Setup local variable which stays in this scope */
	/* Doing this here and using a local variable saves doing it in the ISR */
	TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
	TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
	TIM_ICInitStructure.TIM_ICFilter = 0x0;

	if (!PIOS_RTC_RegisterTickCallback(PIOS_PPM_Supervisor, (uint32_t)ppm_dev)) {
		PIOS_DEBUG_Assert(0);
	}

	*ppm_id = (uint32_t)ppm_dev;

	return(0);

out_fail:
	return(-1);
}
Beispiel #8
0
void PIOS_Board_Init(void)
{
    // Delay system
    PIOS_DELAY_Init();

    PIOS_LED_Init(&pios_led_cfg);

#if defined(PIOS_INCLUDE_SPI)
    /* Set up the SPI interface to the SD card */
    if (PIOS_SPI_Init(&pios_spi_sdcard_id, &pios_spi_sdcard_cfg)) {
        PIOS_Assert(0);
    }

#if defined(PIOS_INCLUDE_SDCARD)
    /* Enable and mount the SDCard */
    PIOS_SDCARD_Init(pios_spi_sdcard_id);
    PIOS_SDCARD_MountFS(0);
#endif
#endif /* PIOS_INCLUDE_SPI */

#ifdef PIOS_INCLUDE_FLASH_LOGFS_SETTINGS
    uintptr_t flash_id;
    PIOS_Flash_Internal_Init(&flash_id, &flash_internal_cfg);
    PIOS_FLASHFS_Logfs_Init(&pios_uavo_settings_fs_id, &flashfs_internal_cfg, &pios_internal_flash_driver, flash_id);
#elif !defined(PIOS_USE_SETTINGS_ON_SDCARD)
#error No setting storage specified. (define PIOS_USE_SETTINGS_ON_SDCARD or INCLUDE_FLASH_SECTOR_SETTINGS)
#endif

    /* Initialize the task monitor */
    if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) {
        PIOS_Assert(0);
    }

    /* Initialize the delayed callback library */
    PIOS_CALLBACKSCHEDULER_Initialize();

    /* Initialize UAVObject libraries */
    EventDispatcherInitialize();
    UAVObjInitialize();

    HwSettingsInitialize();

#ifdef PIOS_INCLUDE_WDG
    /* Initialize watchdog as early as possible to catch faults during init */
    PIOS_WDG_Init();
#endif /* PIOS_INCLUDE_WDG */

    /* Initialize the alarms library */
    AlarmsInitialize();

    /* IAP System Setup */
    PIOS_IAP_Init();
    uint16_t boot_count = PIOS_IAP_ReadBootCount();
    if (boot_count < 3) {
        PIOS_IAP_WriteBootCount(++boot_count);
        AlarmsClear(SYSTEMALARMS_ALARM_BOOTFAULT);
    } else {
        /* Too many failed boot attempts, force hwsettings to defaults */
        HwSettingsSetDefaults(HwSettingsHandle(), 0);
        AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
    }


#if defined(PIOS_INCLUDE_RTC)
    /* Initialize the real-time clock and its associated tick */
    PIOS_RTC_Init(&pios_rtc_main_cfg);
    if (!PIOS_RTC_RegisterTickCallback(Clock, 0)) {
        PIOS_DEBUG_Assert(0);
    }
#endif

#if defined(PIOS_INCLUDE_USB)
    /* Initialize board specific USB data */
    PIOS_USB_BOARD_DATA_Init();

    /* Flags to determine if various USB interfaces are advertised */
    bool usb_hid_present = false;
    bool usb_cdc_present = false;

#if defined(PIOS_INCLUDE_USB_CDC)
    if (PIOS_USB_DESC_HID_CDC_Init()) {
        PIOS_Assert(0);
    }
    usb_hid_present = true;
    usb_cdc_present = true;
#else
    if (PIOS_USB_DESC_HID_ONLY_Init()) {
        PIOS_Assert(0);
    }
    usb_hid_present = true;
#endif

    uint32_t pios_usb_id;
    PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);

#if defined(PIOS_INCLUDE_USB_CDC)

    uint8_t hwsettings_usb_vcpport;
    /* Configure the USB VCP port */
    HwSettingsUSB_VCPPortGet(&hwsettings_usb_vcpport);

    if (!usb_cdc_present) {
        /* Force VCP port function to disabled if we haven't advertised VCP in our USB descriptor */
        hwsettings_usb_vcpport = HWSETTINGS_USB_VCPPORT_DISABLED;
    }

    switch (hwsettings_usb_vcpport) {
    case HWSETTINGS_USB_VCPPORT_DISABLED:
        break;
    case HWSETTINGS_USB_VCPPORT_USBTELEMETRY:
#if defined(PIOS_INCLUDE_COM)
        {
            uint32_t pios_usb_cdc_id;
            if (PIOS_USB_CDC_Init(&pios_usb_cdc_id, &pios_usb_cdc_cfg, pios_usb_id)) {
                PIOS_Assert(0);
            }
            uint8_t *rx_buffer = (uint8_t *)pios_malloc(PIOS_COM_TELEM_USB_RX_BUF_LEN);
            uint8_t *tx_buffer = (uint8_t *)pios_malloc(PIOS_COM_TELEM_USB_TX_BUF_LEN);
            PIOS_Assert(rx_buffer);
            PIOS_Assert(tx_buffer);
            if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_cdc_com_driver, pios_usb_cdc_id,
                              rx_buffer, PIOS_COM_TELEM_USB_RX_BUF_LEN,
                              tx_buffer, PIOS_COM_TELEM_USB_TX_BUF_LEN)) {
                PIOS_Assert(0);
            }
        }
#endif /* PIOS_INCLUDE_COM */
        break;
    case HWSETTINGS_USB_VCPPORT_COMBRIDGE:
#if defined(PIOS_INCLUDE_COM)
        {
            uint32_t pios_usb_cdc_id;
            if (PIOS_USB_CDC_Init(&pios_usb_cdc_id, &pios_usb_cdc_cfg, pios_usb_id)) {
                PIOS_Assert(0);
            }
            uint8_t *rx_buffer = (uint8_t *)pios_malloc(PIOS_COM_BRIDGE_RX_BUF_LEN);
            uint8_t *tx_buffer = (uint8_t *)pios_malloc(PIOS_COM_BRIDGE_TX_BUF_LEN);
            PIOS_Assert(rx_buffer);
            PIOS_Assert(tx_buffer);
            if (PIOS_COM_Init(&pios_com_vcp_id, &pios_usb_cdc_com_driver, pios_usb_cdc_id,
                              rx_buffer, PIOS_COM_BRIDGE_RX_BUF_LEN,
                              tx_buffer, PIOS_COM_BRIDGE_TX_BUF_LEN)) {
                PIOS_Assert(0);
            }
        }
#endif /* PIOS_INCLUDE_COM */
        break;
    }
#endif /* PIOS_INCLUDE_USB_CDC */

#if defined(PIOS_INCLUDE_USB_HID)
    /* Configure the usb HID port */
    uint8_t hwsettings_usb_hidport;
    HwSettingsUSB_HIDPortGet(&hwsettings_usb_hidport);

    if (!usb_hid_present) {
        /* Force HID port function to disabled if we haven't advertised HID in our USB descriptor */
        hwsettings_usb_hidport = HWSETTINGS_USB_HIDPORT_DISABLED;
    }

    switch (hwsettings_usb_hidport) {
    case HWSETTINGS_USB_HIDPORT_DISABLED:
        break;
    case HWSETTINGS_USB_HIDPORT_USBTELEMETRY:
#if defined(PIOS_INCLUDE_COM)
        {
            uint32_t pios_usb_hid_id;
            if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_cfg, pios_usb_id)) {
                PIOS_Assert(0);
            }
            uint8_t *rx_buffer = (uint8_t *)pios_malloc(PIOS_COM_TELEM_USB_RX_BUF_LEN);
            uint8_t *tx_buffer = (uint8_t *)pios_malloc(PIOS_COM_TELEM_USB_TX_BUF_LEN);
            PIOS_Assert(rx_buffer);
            PIOS_Assert(tx_buffer);
            if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_hid_id,
                              rx_buffer, PIOS_COM_TELEM_USB_RX_BUF_LEN,
                              tx_buffer, PIOS_COM_TELEM_USB_TX_BUF_LEN)) {
                PIOS_Assert(0);
            }
        }
#endif /* PIOS_INCLUDE_COM */
        break;
    }

#endif /* PIOS_INCLUDE_USB_HID */

    if (usb_hid_present || usb_cdc_present) {
        PIOS_USBHOOK_Activate();
    }
#endif /* PIOS_INCLUDE_USB */

#if defined(PIOS_INCLUDE_COM)
#if defined(PIOS_INCLUDE_GPS)

    uint32_t pios_usart_gps_id;
    if (PIOS_USART_Init(&pios_usart_gps_id, &pios_usart_gps_cfg)) {
        PIOS_Assert(0);
    }

    uint8_t *gps_rx_buffer = (uint8_t *)pios_malloc(PIOS_COM_GPS_RX_BUF_LEN);
    PIOS_Assert(gps_rx_buffer);
    if (PIOS_COM_Init(&pios_com_gps_id, &pios_usart_com_driver, pios_usart_gps_id,
                      gps_rx_buffer, PIOS_COM_GPS_RX_BUF_LEN,
                      NULL, 0)) {
        PIOS_Assert(0);
    }

#endif /* PIOS_INCLUDE_GPS */

#if defined(PIOS_INCLUDE_COM_AUX)
    {
        uint32_t pios_usart_aux_id;

        if (PIOS_USART_Init(&pios_usart_aux_id, &pios_usart_aux_cfg)) {
            PIOS_DEBUG_Assert(0);
        }

        uint8_t *aux_rx_buffer = (uint8_t *)pios_malloc(PIOS_COM_AUX_RX_BUF_LEN);
        uint8_t *aux_tx_buffer = (uint8_t *)pios_malloc(PIOS_COM_AUX_TX_BUF_LEN);
        PIOS_Assert(aux_rx_buffer);
        PIOS_Assert(aux_tx_buffer);

        if (PIOS_COM_Init(&pios_com_aux_id, &pios_usart_com_driver, pios_usart_aux_id,
                          aux_rx_buffer, PIOS_COM_AUX_RX_BUF_LEN,
                          aux_tx_buffer, PIOS_COM_AUX_TX_BUF_LEN)) {
            PIOS_DEBUG_Assert(0);
        }
    }
#else
    pios_com_aux_id = 0;
#endif /* PIOS_INCLUDE_COM_AUX */

#if defined(PIOS_INCLUDE_COM_TELEM)
    { /* Eventually add switch for this port function */
        uint32_t pios_usart_telem_rf_id;
        if (PIOS_USART_Init(&pios_usart_telem_rf_id, &pios_usart_telem_main_cfg)) {
            PIOS_Assert(0);
        }

        uint8_t *telem_rx_buffer = (uint8_t *)pios_malloc(PIOS_COM_TELEM_RF_RX_BUF_LEN);
        uint8_t *telem_tx_buffer = (uint8_t *)pios_malloc(PIOS_COM_TELEM_RF_TX_BUF_LEN);
        PIOS_Assert(telem_rx_buffer);
        PIOS_Assert(telem_tx_buffer);
        if (PIOS_COM_Init(&pios_com_telem_rf_id, &pios_usart_com_driver, pios_usart_telem_rf_id,
                          telem_rx_buffer, PIOS_COM_TELEM_RF_RX_BUF_LEN,
                          telem_tx_buffer, PIOS_COM_TELEM_RF_TX_BUF_LEN)) {
            PIOS_Assert(0);
        }
    }
#else
    pios_com_telem_rf_id = 0;
#endif /* PIOS_INCLUDE_COM_TELEM */

#endif /* PIOS_INCLUDE_COM */


    /* Configure FlexiPort */

/*	uint8_t hwsettings_rv_flexiport;
        HwSettingsRV_FlexiPortGet(&hwsettings_rv_flexiport);

        switch (hwsettings_rv_flexiport) {
                case HWSETTINGS_RV_FLEXIPORT_DISABLED:
                        break;
                case HWSETTINGS_RV_FLEXIPORT_I2C:*/
#if defined(PIOS_INCLUDE_I2C)
    {
        if (PIOS_I2C_Init(&pios_i2c_flexiport_adapter_id, &pios_i2c_flexiport_adapter_cfg)) {
            PIOS_Assert(0);
        }
    }
#endif /* PIOS_INCLUDE_I2C */
/*			break;

                case HWSETTINGS_RV_FLEXIPORT_DSM:
                        //TODO: Define the various Channelgroup for Revo dsm inputs and handle here
                        PIOS_Board_configure_dsm(&pios_usart_dsm_flexi_cfg, &pios_dsm_flexi_cfg,
                                                                                         &pios_usart_com_driver, MANUALCONTROLSETTINGS_CHANNELGROUPS_DSMMAINPORT,&hwsettings_DSMxBind);
                        break;
                case HWSETTINGS_RV_FLEXIPORT_COMAUX:
                        PIOS_Board_configure_com(&pios_usart_flexi_cfg, PIOS_COM_AUX_RX_BUF_LEN, PIOS_COM_AUX_TX_BUF_LEN, &pios_usart_com_driver, &pios_com_aux_id);
                        break;
                case HWSETTINGS_RV_FLEXIPORT_COMBRIDGE:
                        PIOS_Board_configure_com(&pios_usart_flexi_cfg, PIOS_COM_BRIDGE_RX_BUF_LEN, PIOS_COM_BRIDGE_TX_BUF_LEN, &pios_usart_com_driver, &pios_com_bridge_id);
                        break;
        }*/
    /* hwsettings_rv_flexiport */


#if defined(PIOS_INCLUDE_WAVE)
    PIOS_WavPlay_Init(&pios_dac_cfg);
#endif

    // ADC system
#if defined(PIOS_INCLUDE_ADC)
    PIOS_ADC_Init(&pios_adc_cfg);
#endif

#if defined(PIOS_INCLUDE_VIDEO)
    PIOS_TIM_InitClock(&tim_8_cfg);
    PIOS_Servo_Init(&pios_servo_cfg);
    // Start the pixel and line clock counter
    // PIOS_TIM_InitClock(&pios_tim4_cfg);
    PIOS_Video_Init(&pios_video_cfg);
#endif
}