boards organization

This commit is contained in:
Daniel Agar
2018-11-26 14:40:14 -08:00
committed by David Sidrane
parent c1f851a600
commit f692ad04d0
507 changed files with 9976 additions and 10990 deletions
+118
View File
@@ -0,0 +1,118 @@
px4_add_board(
PLATFORM nuttx
VENDOR nxp
MODEL hlite-v3
ARCH cortex-m4
ROMFS
ROMFSROOT px4fmu_common
TESTING
UAVCAN_INTERFACES 2
SERIAL_PORTS
GPS1:/dev/ttyS3
TEL1:/dev/ttyS4
DRIVERS
barometer # all available barometer drivers
barometer/mpl3115a2
batt_smbus
blinkm
camera_trigger
differential_pressure # all available differential pressure drivers
distance_sensor # all available distance sensor drivers
gps
kinetis
kinetis/adc
kinetis/tone_alarm
#heater
#imu # all available imu drivers
imu/fxas21002c
imu/fxos8701cq
imu/l3gd20
imu/mpu6000
imu/mpu9250
irlock
magnetometer # all available magnetometer drivers
mkblctrl
oreoled
pca9685
#pwm_input # NOT Portable YET drivers
pwm_out_sim
px4flow
px4fmu
rc_input
rgbled
rgbled_pwm
tap_esc
telemetry # all available telemetry drivers
#test_ppm # NOT Portable YET
vmount
MODULES
attitude_estimator_q
camera_feedback
commander
dataman
ekf2
events
fw_att_control
fw_pos_control_l1
gnd_att_control
gnd_pos_control
gpio_led
land_detector
landing_target_estimator
load_mon
local_position_estimator
logger
mavlink
mc_att_control
mc_pos_control
navigator
position_estimator_inav
sensors
uavcan
vtol_att_control
wind_estimator
SYSTEMCMDS
bl_update
config
dumpfile
esc_calib
#hardfault_log # Needs bbsrm
led_control
mixer
motor_ramp
motor_test
mtd
nshterm
param
perf
pwm
reboot
reflect
sd_bench
shutdown
tests # tests and test runner
top
topic_listener
tune_control
usb_connected
ver
EXAMPLES
bottle_drop # OBC challenge
fixedwing_control # Tutorial code from https://px4.io/dev/example_fixedwing_control
hwtest # Hardware test
#matlab_csv_serial
#publisher
px4_mavlink_debug # Tutorial code from https://px4.io/dev/debug_values
px4_simple_app # Tutorial code from https://px4.io/dev/px4_simple_app
rover_steering_control # Rover example app
segway
#subscriber
uuv_example_app
)
+13
View File
@@ -0,0 +1,13 @@
{
"board_id": 28,
"magic": "PX4FWv1",
"description": "Firmware for the NXPHLITEv3 board",
"image": "",
"build_time": 0,
"summary": "NXPHLITEv3",
"version": "0.1",
"image_size": 0,
"image_maxsize": 2096112,
"git_identity": "",
"board_revision": 0
}
+50
View File
@@ -0,0 +1,50 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
if ARCH_BOARD_NXPHLITE_V3
config NXPHLITE_SDHC_AUTOMOUNT
bool "SDHC automounter"
default n
depends on FS_AUTOMOUNTER && KINETIS_SDHC
if NXPHLITE_SDHC_AUTOMOUNT
config NXPHLITE_SDHC_AUTOMOUNT_FSTYPE
string "SDHC file system type"
default "vfat"
config NXPHLITE_SDHC_AUTOMOUNT_BLKDEV
string "SDHC block device"
default "/dev/mmcsd0"
config NXPHLITE_SDHC_AUTOMOUNT_MOUNTPOINT
string "SDHC mount point"
default "/mnt/sdcard"
config NXPHLITE_SDHC_AUTOMOUNT_DDELAY
int "SDHC debounce delay (milliseconds)"
default 1000
config NXPHLITE_SDHC_AUTOMOUNT_UDELAY
int "SDHC unmount retry delay (milliseconds)"
default 2000
endif # NXPHLITE_SDHC_AUTOMOUNT
config BOARD_HAS_PROBES
bool "Board provides GPIO or other Hardware for signaling to timing analyze."
default y
---help---
This board provides GPIO FMU-CH1-6 as PROBE_1-6 to provide timing signals from selected drivers.
config BOARD_USE_PROBES
bool "Enable the use the board provided GPIO FMU-CH1-6 as PROBE_1-6 to provide timing signals from selected drivers"
default n
depends on BOARD_HAS_PROBES
---help---
Select to use GPIO FMU-CH1-6 to provide timing signals from selected drivers.
endif
@@ -0,0 +1,559 @@
/************************************************************************************
* configs/nxphlit-v3/include/board.h
*
* Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org>
* Jordan MacIntyre
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************************/
#ifndef __CONFIG_NXPHLITE_V3_INCLUDE_BOARD_H
#define __CONFIG_NXPHLITE_V3_INCLUDE_BOARD_H
/************************************************************************************
* Included Files
************************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
# include <stdint.h>
#endif
#include <arch/chip/chip.h>
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/*
* The NXPHlite-v3 is populated with a MK66FN2M0VLQ18 has 2 MiB of FLASH and
* 256 KiB of SRAM.
*/
/* Clocking *************************************************************************/
/* The NXPHlite-v3 uses a 16MHz external powered Oscillator. The Kinetis MCU startup
* from an internal digitally-controlled oscillator (DCO). Nuttx will enable the main
* external oscillator EXTAL0. The external oscillator can range from
* 32.768 KHz up to 50 MHz. The default external source for the MCG oscillator inputs
* EXTAL.
*
* Y1 a High-frequency, Oscillator
*/
#define BOARD_EXTAL_LP 1
#define BOARD_EXTAL_FREQ 16000000 /* 16MHz Oscillator Y1 */
#define BOARD_XTAL32_FREQ 32768 /* 32KHz RTC Oscillator */
#define BOARD_OSC_CR OSC_CR_ERCLKEN /* Enable the OSCERCLK */
#define BOARD_OSC_DIV OSC_DIV_ERPS_DIV1 /* No OSCERCLK Divide */
/* FLL Configuration.
* BOARD_EXTAL_FREQ / BOARD_FRDIV has to be in the range 31.25 kHz to 39.0625
* 16 Mhz / MCG_C1_FRDIV_DIV512 = 31.25 kHz * 640 the default for MCG_C4
* FLL is 20Mhz
*/
#define BOARD_FRDIV MCG_C1_FRDIV_DIV512
/* PLL Configuration. Either the external clock or crystal frequency is used to
* select the PRDIV value. Only reference clock frequencies are supported that will
* produce a KINETIS_MCG_PLL_REF_MIN=8MHz >= PLLIN <=KINETIS_MCG_PLL_REF_MAX=16Mhz
* reference clock to the PLL.
*
* PLL Input frequency: PLLIN = REFCLK / PRDIV = 16 MHz / 2 = 8Mhz MHz
* PLL Output frequency: PLLOUT = PLLIN * VDIV = 8 MHz * 42 = 336 MHz
* MCG Frequency: PLLOUT = 168 Mhz = 336 MHz / KINETIS_MCG_PLL_INTERNAL_DIVBY=2
*
* PRDIV register value is the divider minus KINETIS_MCG_C5_PRDIV_BASE.
* VDIV register value is offset by KINETIS_MCG_C6_VDIV_BASE.
*/
#define BOARD_PRDIV 2 /* PLL External Reference Divider */
#define BOARD_VDIV 42 /* PLL VCO Divider (frequency multiplier) */
/* Define additional MCG_C2 Setting */
#define BOARD_MCG_C2_FCFTRIM 0 /* Do not enable FCFTRIM */
#define BOARD_MCG_C2_LOCRE0 MCG_C2_LOCRE0 /* Enable reset on loss of clock */
#define BOARD_PLLIN_FREQ (BOARD_EXTAL_FREQ / BOARD_PRDIV)
#define BOARD_PLLOUT_FREQ (BOARD_PLLIN_FREQ * BOARD_VDIV)
#define BOARD_MCG_FREQ (BOARD_PLLOUT_FREQ/KINETIS_MCG_PLL_INTERNAL_DIVBY)
/* SIM CLKDIV1 dividers */
#define BOARD_OUTDIV1 1 /* Core = MCG, 168 MHz */
#define BOARD_OUTDIV2 3 /* Bus = MCG / 3, 56 MHz */
#define BOARD_OUTDIV3 3 /* FlexBus = MCG / 3, 56 MHz */
#define BOARD_OUTDIV4 6 /* Flash clock = MCG / 6, 28 MHz */
#define BOARD_CORECLK_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV1)
#define BOARD_BUS_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV2)
#define BOARD_FLEXBUS_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV3)
#define BOARD_FLASHCLK_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV4)
/* Use BOARD_MCG_FREQ as the output SIM_SOPT2 MUX selected by
* SIM_SOPT2[PLLFLLSEL]
*/
#define BOARD_SOPT2_PLLFLLSEL SIM_SOPT2_PLLFLLSEL_MCGPLLCLK
#define BOARD_SOPT2_FREQ BOARD_MCG_FREQ
/* Divider output clock = Divider input clock × [ (USBFRAC+1) / (USBDIV+1) ]
* SIM_CLKDIV2_FREQ = BOARD_SOPT2_FREQ × [ (USBFRAC+1) / (USBDIV+1) ]
* 48Mhz = 168Mhz X [(1 + 1) / (6 + 1)]
* 48Mhz = 168Mhz / (6 + 1) * (1 + 1)
*/
#define BOARD_SIM_CLKDIV2_USBFRAC 2
#define BOARD_SIM_CLKDIV2_USBDIV 7
#define BOARD_SIM_CLKDIV2_FREQ (BOARD_SOPT2_FREQ / \
BOARD_SIM_CLKDIV2_USBDIV * \
BOARD_SIM_CLKDIV2_USBFRAC)
#define BOARD_USB_CLKSRC SIM_SOPT2_USBSRC
#define BOARD_USB_FREQ BOARD_SIM_CLKDIV2_FREQ
/* Divider output clock = Divider input clock * ((PLLFLLFRAC+1)/(PLLFLLDIV+1))
* SIM_CLKDIV3_FREQ = BOARD_SOPT2_FREQ × [ (PLLFLLFRAC+1) / (PLLFLLDIV+1)]
* 84 Mhz = 168 Mhz X [(0 + 1) / (1 + 1)]
* 84 Mhz = 168 Mhz / (1 + 1) * (0 + 1)
*/
#define BOARD_SIM_CLKDIV3_PLLFLLFRAC 1
#define BOARD_SIM_CLKDIV3_PLLFLLDIV 2
#define BOARD_SIM_CLKDIV3_FREQ (BOARD_SOPT2_FREQ / \
BOARD_SIM_CLKDIV3_PLLFLLDIV * \
BOARD_SIM_CLKDIV3_PLLFLLFRAC)
#define BOARD_LPUART0_CLKSRC SIM_SOPT2_LPUARTSRC_MCGCLK
#define BOARD_LPUART0_FREQ BOARD_SIM_CLKDIV3_FREQ
#define BOARD_TPM_CLKSRC SIM_SOPT2_TPMSRC_OCSERCLK
#define BOARD_TPM_FREQ BOARD_EXTAL_FREQ
/* SDHC clocking ********************************************************************/
/* SDCLK configurations corresponding to various modes of operation. Formula is:
*
* SDCLK frequency = (base clock) / (prescaler * divisor)
*
* The SDHC module is always configure configured so that the core clock is the base
* clock. Possible values for prescaler and divisor are:
*
* SDCLKFS: {2, 4, 8, 16, 32, 63, 128, 256}
* DVS: {1..16}
*/
/* SDHC pull-up resistors **********************************************************/
/* There are external pull-ups on the NXPhlite
* So enable we do not them.
*/
#undef BOARD_SDHC_ENABLE_PULLUPS
/* Identification mode: Optimal 400KHz, Actual 168Mhz / (32 * 14) = 375 KHz */
#define BOARD_SDHC_IDMODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV32
#define BOARD_SDHC_IDMODE_DIVISOR SDHC_SYSCTL_DVS_DIV(14)
/* MMC normal mode: Optimal 20MHz, Actual 168Mhz / (2 * 5) = 16.8 MHz */
#define BOARD_SDHC_MMCMODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2
#define BOARD_SDHC_MMCMODE_DIVISOR SDHC_SYSCTL_DVS_DIV(5)
/* SD normal mode (1-bit): Optimal 20MHz, Actual 168Mhz / (2 * 5) = 16.8 MHz */
#define BOARD_SDHC_SD1MODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2
#define BOARD_SDHC_SD1MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(5)
/* SD normal mode (4-bit): Optimal 25MHz, Actual Actual 168Mhz / (2 * 4) = 21 MHz (with DMA)
* SD normal mode (4-bit): Optimal 20MHz, Actual 168Mhz / (2 * 5) = 16.8 MHz (no DMA)
*/
#ifdef CONFIG_KINETIS_SDHC_DMA
# define BOARD_SDHC_SD4MODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2
# define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(4)
#else
# define BOARD_SDHC_SD4MODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2
# define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(5)
#endif
/* LED definitions ******************************************************************/
/* The NXPHlite-v3 has a separate Red, Green and Blue LEDs driven by the K66 as
* follows:
*
* LED K66
* ------ -------------------------------------------------------
* RED FB_CS0_b/ UART2_CTS_b / ADC0_SE5b / SPI0_SCK / FTM3_CH1/ PTD1
* GREEN FTM2_FLT0/ CMP0_IN3/ FB_AD6 / I2S0_RX_BCLK/ FTM3_CH5/ ADC1_SE5b/ PTC9
* BLUE CMP0_IN2/ FB_AD7 / I2S0_MCLK/ FTM3_CH4/ ADC1_SE4b/ PTC8
*
* If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs in any
* way. The following definitions are used to access individual LEDs.
*/
/* LED index values for use with board_userled() */
#define BOARD_LED_R 0
#define BOARD_LED_G 1
#define BOARD_LED_B 2
#define BOARD_NLEDS 3
/* LED bits for use with board_userled_all() */
#define BOARD_LED_R_BIT (1 << BOARD_LED_R)
#define BOARD_LED_G_BIT (1 << BOARD_LED_G)
#define BOARD_LED_B_BIT (1 << BOARD_LED_B)
/* If CONFIG_ARCH_LEDs is defined, then NuttX will control the LED on board
* the NXPHlite-v3. The following definitions describe how NuttX controls
* the LEDs:
*
* SYMBOL Meaning LED state
* RED GREEN BLUE
* ------------------- ---------------------------- ----------------- */
#define LED_STARTED 1 /* NuttX has been started OFF OFF OFF */
#define LED_HEAPALLOCATE 2 /* Heap has been allocated OFF OFF ON */
#define LED_IRQSENABLED 0 /* Interrupts enabled OFF OFF ON */
#define LED_STACKCREATED 3 /* Idle stack created OFF ON OFF */
#define LED_INIRQ 0 /* In an interrupt (no change) */
#define LED_SIGNAL 0 /* In a signal handler (no change) */
#define LED_ASSERTION 0 /* An assertion failed (no change) */
#define LED_PANIC 4 /* The system has crashed FLASH OFF OFF */
#undef LED_IDLE /* K66 is in sleep mode (Not used) */
/* Alternative pin resolution *******************************************************/
/* If there are alternative configurations for various pins in the
* kinetis_k66pinmux.h header file, those alternative pins will be labeled with a
* suffix like _1, _2, etc. The logic in this file must select the correct pin
* configuration for the board by defining a pin configuration (with no suffix) that
* maps to the correct alternative.
*/
/* CAN
* Signal Conn Port Pin Name
* ------- -------- ----- ----- --------
* CAN0TX P8-2(H) PTB18 97 CAN0_TX
* CAN0RX P8-3(L) PTB19 98 CAN0_RX
* CAN1TX P19-2(H) PTC16 123 CAN1_TX
* CAN1RX P19-3(L) PTC17 124 CAN1_RX
*
*/
#define PIN_CAN0_RX PIN_CAN0_RX_2
#define PIN_CAN0_TX PIN_CAN0_TX_2
#define PIN_CAN1_RX PIN_CAN1_RX_2
#define PIN_CAN1_TX PIN_CAN1_TX_2
/* 12C
*
*/
/* I2C0
*
* This device can be pinned out to be either or
* Bit Pin Device Signal Usage Conn
* ----- --- ------- --------------------------- ------
* PTB2 83 I2C0_SCL U_ECH Ultrasonic P13-3
* PTB3 84 I2C0_SDA U_TRI Ultrasonic P13-2
* ----- --- ------- --------------------------- ------
*
* Bit Pin Device Signal Usage Conn
* ----- --- ------- --------------------------- ------
* PTE24 45 I2C0_SCL IIC_SCL NFC Connector, IIC P2-2
* PTE25 46 I2C0_SDA IIC_SDA NFC Connector, IIC P2-3
* ----- --- ------- --------------------------- ------
*/
#define PIN_I2C0_SCL PIN_I2C0_SCL_4 /* PTE24 IIC_SCL */
#define PIN_I2C0_SDA PIN_I2C0_SDA_4 /* PTE25 IIC_SDA */
/* I2C1
*
* Bit Pin Device Signal Usage Conn
* ----- --- ------- -------------- ------------- ------
* PTC10 115 I2C1_SCL P_SCL, GPS_SCL Pressure, GPS P3-4
* PTC11 116 I2C1_SDA P_SDA, GPS_SDA Pressure, GPS P3-5
* ----- --- ------- -------------- ------------- ------
*/
#define PIN_I2C1_SCL PIN_I2C1_SCL_1 /* PTC10 GPS / Pressure Sensor*/
#define PIN_I2C1_SDA PIN_I2C1_SDA_1 /* PTC11 GPS / Pressure Sensor */
/* PWM
*
*/
/* PWM Channels */
#define GPIO_FTM0_CH0OUT PIN_FTM0_CH0_2 /* PTC1 FMU_CH1 P4-19 */
#define GPIO_FTM0_CH3OUT PIN_FTM0_CH3_1 /* PTA6 FMU_CH2 P4-16 */
#define GPIO_FTM0_CH4OUT PIN_FTM0_CH4_3 /* PTD4 FMU_CH3 P4-13 */
#define GPIO_FTM0_CH5OUT PIN_FTM0_CH5_3 /* PTD5 FMU_CH4 P4-10 */
#define GPIO_FTM3_CH6OUT PIN_FTM3_CH6_2 /* PTE11 FMU_CH5 P4-7 */
#define GPIO_FTM3_CH7OUT PIN_FTM3_CH7_2 /* PTE12 FMU_CH5 P4-4 */
#define GPIO_FTM3_CH0OUT PIN_FTM3_CH0_1 /* PTD0 U_TRI P10-2 */
#define GPIO_FTM2_CH0OUT PIN_FTM2_CH0_1 /* PTA10 U_ECH P20-3 */
#define GPIO_FTM0_CH0IN PIN_FTM0_CH0_2 /* PTC1 FMU_CH1 P4-19 */
#define GPIO_FTM0_CH3IN PIN_FTM0_CH3_1 /* PTA6 FMU_CH2 P4-16 */
#define GPIO_FTM0_CH4IN PIN_FTM0_CH4_3 /* PTD4 FMU_CH3 P4-13 */
#define GPIO_FTM0_CH5IN PIN_FTM0_CH5_3 /* PTD5 FMU_CH4 P4-10 */
#define GPIO_FTM3_CH6IN PIN_FTM3_CH6_2 /* PTE11 FMU_CH5 P4-7 */
#define GPIO_FTM3_CH7IN PIN_FTM3_CH7_2 /* PTE12 FMU_CH5 P4-4 */
#define GPIO_FTM3_CH0IN PIN_FTM3_CH0_1 /* PTD0 U_TRI P10-2 */
#define GPIO_FTM2_CH0IN PIN_FTM2_CH0_1 /* PTA10 U_ECH P20-3 */
/* SPI
*
*/
/* SPI0 FRAM */
#define PIN_SPI0_PCS0 PIN_SPI0_PCS2_1 /* PTC2 SPI_CS FRAM_CS */
#define PIN_SPI0_SCK PIN_SPI0_SCK_2 /* PTC5 SPI_CLK FRAM_SCK */
#define PIN_SPI0_OUT PIN_SPI0_SOUT_2 /* PTC6 SPI_OUT FRAM_MOSI */
#define PIN_SPI0_SIN PIN_SPI0_SIN_2 /* PTC7 SPI_IN FRAM_MISO */
/* SPI1
* FXOS8700CQ Accelerometer
* FXAS21002CQ Gyroscope
*/
#define PIN_SPI1_PCS0 PIN_SPI1_PCS0_1 /* PTB10 A_CS */
#define PIN_SPI1_PCS1 PIN_SPI1_PCS1_1 /* PTB9 GM_CS */
#define PIN_SPI1_SCK PIN_SPI1_SCK_1 /* PTB11 A_SCLK */
#define PIN_SPI1_OUT PIN_SPI1_SOUT_1 /* PTB16 A_MOSI */
#define PIN_SPI1_SIN PIN_SPI1_SIN_1 /* PTB17 A_MISO */
/* SPI2
* Bit Pin Device Signal Conn
* ----- --- ------- --------- ------
* PTB20 99 SPI2_PCS0 SPI2_CS P18-5
* PTB21 100 SPI2_SCK SPI2_CLK P18-2
* PTB22 101 SPI2_SOUT SPI2_OUT P18-3
* PTB23 102 SPI2_SIN SPI2_IN P18-4
*
*/
#define PIN_SPI2_PCS0 PIN_SPI2_PCS0_1 /* PTB20 SPI2_CS */
#define PIN_SPI2_SCK PIN_SPI2_SCK_1 /* PTB21 SPI2_CLK */
#define PIN_SPI2_OUT PIN_SPI2_SOUT_1 /* PTB22 SPI2_OUT */
#define PIN_SPI2_SIN PIN_SPI2_SIN_1 /* PTB23 SPI2_IN */
/* UART
*
* NuttX Will use LPUART0 as the Console
*
* LPUAR0
* P16 Pin Name K66 Name
* -------- ------------ ------ ---------
* 2 UART_TX PTD9 LPUART0_TX
* 3 UART_RX PTD8 LPUART0_RX
* -------- ----- ------ ---------
*/
#define PIN_LPUART0_RX PIN_LPUART0_RX_3
#define PIN_LPUART0_TX PIN_LPUART0_TX_3
/* UART0
*
* P7 Pin Name K66 Name
* -------- ------------ ------- ---------
* 2 IR_Transmitter PTA2 UART0_TX
* 4 IR_Receiver PTA1 UART0_RX
* -------- ------------ ------- ---------
*/
#define PIN_UART0_RX PIN_UART0_RX_1
#define PIN_UART0_TX PIN_UART0_TX_1
/* UART1
*
* Pin Name K66 Name
* ------------- -------------- ----- ---------
* P14-3,P15-2 FrSky_IN_RC_IN PTC3 UART1_RX
* P14-2 FrSky_OUT PTC4 UART1_TX
* ------------- ------------ ----- ---------
*/
#define PIN_UART1_RX PIN_UART1_RX_1
#define PIN_UART1_TX PIN_UART1_TX_1
/* UART2
* No Alternative pins for UART2
*
* P7 Pin Name K66 Name
* -------- ------------ ------- ---------
* 2 GPS_TX PTD3 UART2_TX
* 3 GPS_RX PTD2 UART2_RX
* -------- ------------ ------- ---------
*/
/* UART4
*
* P10 Pin Name K66 Name
* -------- ------------ ------- ---------
* 2 UART4_TX PTC15 UART4_TX
* 3 UART4_RX PTC14 UART4_RX
* 4 UART4_CTS PTC13 UART4_CTS
* 5 UART4_RTS PTE27 UART4_RTS
* -------- ------------ ------- ---------
*/
#define PIN_UART4_RX PIN_UART4_RX_1
#define PIN_UART4_TX PIN_UART4_TX_1
#define PIN_UART4_RTS PIN_UART4_RTS_2
#define PIN_UART4_CTS PIN_UART4_CTS_1
/*
* Ethernet TJA1100 OPEN Alliance BroadR-Reach PHY for Automotive Ethernet
* -----------------------------------------------------------------------
*
* -------------- ----------------- -----------------------------------------
* TJA1100 Board Signal(s) K66F Pin
* Pin Signal Function pinmux Name
* --- ---------- ----------------- ------------------------------------------
* 1 MDC RMII0_MDC PTB1/RMII0_MDC PIN_RMII0_MDC
* 2 INT RMII0_INT_B, PTA27 PTA27
* 3 nRST ENET_RST PTA28 PTA28
* 4 VDDA(1V8) Cap to GND --- ---
* 5 XO 25Mhz OSC --- ---
* 6 XI 25Mhz OSC --- ---
* 7 VDDA(3V3) E_3V3 --- ---
* 8 LED (LED_ENABLE = 1) WAKE (LED_ENABLE = 0) ---
* 8 VBAT E_3V3 --- ---
* 10 nINH ENET_INH PTA8 PTA8
* 11 VDDA(TX) E_3V3 --- ---
* 12 TRX_P ENET_P --- ---
* 13 TRX_M ENET_P --- ---
* 14 VDDD(3V3) E_3V3 --- ---
* 15 GND --- --- ---
* 16 VDDD(1V8) Cap to GND --- ---
* 17 RXER RMII0_RXER PTA5/RMII0_RXER PIN_RMII0_RXER
* 18 CRS_DIV RMII_CRSDV PTA14/RMII0_CRS_DV PIN_RMII0_CRS_DV
* 19 TXEN RMII0_TXEN PTA15/RMII0_TXEN PIN_RMII0_TXEN
* 20 GND --- --- ---
* 21 CONFIG1 ENET_CON1 THIS PIN IS A NO CONNECT
* 22 CONFIG0 ENET_CONFIG0 PTA24 PTA24
* 23 RXD1 RMII0_RXD_1 PTA12/RMII0_RXD1 PIN_RMII0_RXD1
* 24 RXD0 RMII0_RXD_0 PTA13/RMII0_RXD0 PIN_RMII0_RXD0
* 25 REF_CLK E_REF_CLK PTE26/ENET_1588_CLKIN PIN_ENET_1588_CLKIN
* 26 GND2 --- --- ---
* 27 VDD(IO) E_3V3 --- ---
* 28 TXC --- --- ---
* 29 TXEN RMII_TXEN PTA15/RMII0_TXEN PIN_RMII0_TXEN
* 30 TXD3
* 31 TXD2
* 32 TXD1 RMII0_TXD_1 PTA17/RMII0_TXD1 PIN_RMII0_TXD1
* 33 TXD0 RMII0_TXD_0 PTA16/RMII0_TXD0 PIN_RMII0_TXD0
* 34 TXER
* 35 EN ENET_EN PTA29 PTA29
* 36 MDIO RMII0_MDIO PTB0/RMII0_MDIO PIN_RMII0_MDIO
* --- ---------- ----------------- ------------------------------------
*
*/
#define PIN_RMII0_MDIO PIN_RMII0_MDIO_1
#define PIN_RMII0_MDC PIN_RMII0_MDC_1
/* Board provides GPIO or other Hardware for signaling to timing analyzer */
#if defined(CONFIG_BOARD_USE_PROBES)
# define PROBE_N(n) (1<<((n)-1))
# define PROBE_1 (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTC | PIN1)
# define PROBE_2 (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTA | PIN6)
# define PROBE_3 (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTD | PIN4)
# define PROBE_4 (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTD | PIN5)
# define PROBE_5 (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTE | PIN11)
# define PROBE_6 (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTE | PIN12)
# define PROBE_INIT(mask) \
do { \
if ((mask)& PROBE_N(1)) { kinetis_pinconfig(PROBE_1); } \
if ((mask)& PROBE_N(2)) { kinetis_pinconfig(PROBE_2); } \
if ((mask)& PROBE_N(3)) { kinetis_pinconfig(PROBE_3); } \
if ((mask)& PROBE_N(4)) { kinetis_pinconfig(PROBE_4); } \
if ((mask)& PROBE_N(5)) { kinetis_pinconfig(PROBE_5); } \
if ((mask)& PROBE_N(6)) { kinetis_pinconfig(PROBE_6); } \
} while(0)
# define PROBE(n,s) do {kinetis_gpiowrite(PROBE_##n,(s));}while(0)
# define PROBE_MARK(n) PROBE(n,false);PROBE(n,true)
#else
# define PROBE_INIT(mask)
# define PROBE(n,s)
# define PROBE_MARK(n)
#endif
/************************************************************************************
* Public Data
************************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/************************************************************************************
* Public Function Prototypes
************************************************************************************/
/************************************************************************************
* Name: kinetis_boardinitialize
*
* Description:
* All kinetis architectures must provide the following entry point. This entry point
* is called early in the intitialization -- after all memory has been configured
* and mapped but before any devices have been initialized.
*
************************************************************************************/
void kinetis_boardinitialize(void);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __CONFIG_NXPHLITE_V23_INCLUDE_BOARD_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,179 @@
/****************************************************************************
* configs/nxphlite-v3/scripts/flash.ld
*
* Copyright (C) 2016, 2017 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org>
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/* The MK66FN2M0VLQ18 has 2 MiB of FLASH beginning at address 0x0000:0000 and
* 256 KiB of SRAM beginning at address 0x1fff:0000- (SRAM_L) (64Kib) and
* 0x2000:0000 196 Kib (SRAM_U).
*
* NOTE: that the first part of the K66 FLASH region is reserved for
* interrupt vectflash and, following that, is a region from 0x0000:0400
* to 0x0000:040f that is reserved for the FLASH control fields (FCF).
*
* NOTE: The on-chip RAM is split evenly among SRAM_L and SRAM_U. The RAM is
* also implemented such that the SRAM_L and SRAM_U ranges form a
* contiguous block in the memory map.
*/
MEMORY
{
vectflash (rx) : ORIGIN = 0x00006000, LENGTH = 1K
cfmprotect (rx) : ORIGIN = 0x00006400, LENGTH = 16
progflash (rx) : ORIGIN = 0x00006410, LENGTH = 2M - ((6*4K) + 1K + 16)
datasram (rwx) : ORIGIN = 0x1fff0000, LENGTH = 256K
}
OUTPUT_ARCH(arm)
ENTRY(__start)
EXTERN(__flashconfigbytes)
SECTIONS
{
.vectors : {
_svectors = ABSOLUTE(.);
KEEP(*(.vectors))
_evectors = ABSOLUTE(.);
} > vectflash
.cfmprotect : {
KEEP(*(.cfmconfig))
} > cfmprotect
.text : {
_stext = ABSOLUTE(.);
*(.text .text.*)
*(.fixup)
*(.gnu.warning)
*(.rodata .rodata.*)
*(.gnu.linkonce.t.*)
*(.got)
*(.gcc_except_table)
*(.gnu.linkonce.r.*)
_etext = ABSOLUTE(.);
/*
* This is a hack to make the newlib libm __errno() call
* use the NuttX get_errno_ptr() function.
*/
__errno = get_errno_ptr;
. = ALIGN(8);
FILL(0xff)
. += 8;
} > progflash =0xff
/*
* Init functions (static constructors and the like)
*/
.init_section : {
_sinit = ABSOLUTE(.);
KEEP(*(.init_array .init_array.*))
_einit = ABSOLUTE(.);
. = ALIGN(8);
FILL(0xff)
. += 8;
} > progflash
/*
* Construction data for parameters.
*/
__param ALIGN(4): {
__param_start = ABSOLUTE(.);
KEEP(*(__param*))
__param_end = ABSOLUTE(.);
. = ALIGN(8);
FILL(0xff)
. += 8;
} > progflash
.ARM.extab : {
*(.ARM.extab*)
. = ALIGN(8);
FILL(0xff)
. += 8;
} > progflash
__exidx_start = ABSOLUTE(.);
.ARM.exidx : {
*(.ARM.exidx*)
} > progflash
__exidx_end = ABSOLUTE(.);
_eronly = ABSOLUTE(.);
.data : {
_sdata = ABSOLUTE(.);
*(.data .data.*)
*(.gnu.linkonce.d.*)
CONSTRUCTORS
_edata = ABSOLUTE(.);
. = ALIGN(8);
FILL(0xff)
. += 8;
} > datasram AT > progflash
.ramfunc ALIGN(4): {
_sramfuncs = ABSOLUTE(.);
*(.ramfunc .ramfunc.*)
_eramfuncs = ABSOLUTE(.);
. = ALIGN(8);
FILL(0xff)
. += 8;
} > datasram AT > progflash =0xff
_framfuncs = LOADADDR(.ramfunc);
.bss : {
_sbss = ABSOLUTE(.);
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(4);
_ebss = ABSOLUTE(.);
} > datasram
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}
+53
View File
@@ -0,0 +1,53 @@
############################################################################
#
# Copyright (c) 2016 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
px4_add_library(drivers_board
autoleds.c
automount.c
can.c
init.c
led.c
sdhc.c
spi.c
timer_config.c
usb.c
)
target_link_libraries(drivers_board
PRIVATE
nuttx_apps # up_cxxinitialize
nuttx_arch # sdio
nuttx_drivers # sdio
drivers__led # drv_led_start
parameters # param_init
)
+164
View File
@@ -0,0 +1,164 @@
/****************************************************************************
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org>
* David Sidrane <david_s5@nscdg.com>
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/*
* This module shaol be used during board bring up of Nuttx.
*
* The NXPHlite-v3 has a separate Red, Green and Blue LEDs driven by the K66
* as follows:
*
* LED K66
* ------ -------------------------------------------------------
* RED FB_CS0_b/ UART2_CTS_b / ADC0_SE5b / SPI0_SCK / FTM3_CH1/ PTD1
* GREEN FTM2_FLT0/ CMP0_IN3/ FB_AD6 / I2S0_RX_BCLK/ FTM3_CH5/ ADC1_SE5b/ PTC9
* BLUE CMP0_IN2/ FB_AD7 / I2S0_MCLK/ FTM3_CH4/ ADC1_SE4b/ PTC8
*
* If CONFIG_ARCH_LEDs is defined, then NuttX will control the LED on board
* the NXPhlite-v3. The following definitions describe how NuttX controls
* the LEDs:
*
* SYMBOL Meaning LED state
* RED GREEN BLUE
* ------------------- ----------------------- -----------------
* LED_STARTED NuttX has been started OFF OFF OFF
* LED_HEAPALLOCATE Heap has been allocated OFF OFF ON
* LED_IRQSENABLED Interrupts enabled OFF OFF ON
* LED_STACKCREATED Idle stack created OFF ON OFF
* LED_INIRQ In an interrupt (no change)
* LED_SIGNAL In a signal handler (no change)
* LED_ASSERTION An assertion failed (no change)
* LED_PANIC The system has crashed FLASH OFF OFF
* LED_IDLE K66 is in sleep mode (Optional, not used)
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <px4_config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "chip.h"
#include "kinetis.h"
#include "board_config.h"
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Summary of all possible settings */
#define LED_NOCHANGE 0 /* LED_IRQSENABLED, LED_INIRQ, LED_SIGNAL, LED_ASSERTION */
#define LED_OFF_OFF_OFF 1 /* LED_STARTED */
#define LED_OFF_OFF_ON 2 /* LED_HEAPALLOCATE */
#define LED_OFF_ON_OFF 3 /* LED_STACKCREATED */
#define LED_ON_OFF_OFF 4 /* LED_PANIC */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_autoled_initialize
*
* Description:
* Initialize the on-board LED
*
****************************************************************************/
void board_autoled_initialize(void)
{
kinetis_pinconfig(GPIO_LED_R);
kinetis_pinconfig(GPIO_LED_G);
kinetis_pinconfig(GPIO_LED_B);
}
/****************************************************************************
* Name: board_autoled_on
****************************************************************************/
void board_autoled_on(int led)
{
if (led != LED_NOCHANGE) {
bool redoff = true;
bool greenoff = true;
bool blueoff = true;
switch (led) {
default:
case LED_OFF_OFF_OFF:
break;
case LED_OFF_OFF_ON:
blueoff = false;
break;
case LED_OFF_ON_OFF:
greenoff = false;
break;
case LED_ON_OFF_OFF:
redoff = false;
break;
}
kinetis_gpiowrite(GPIO_LED_R, redoff);
kinetis_gpiowrite(GPIO_LED_G, greenoff);
kinetis_gpiowrite(GPIO_LED_B, blueoff);
}
}
/****************************************************************************
* Name: board_autoled_off
****************************************************************************/
void board_autoled_off(int led)
{
if (led == LED_ON_OFF_OFF) {
kinetis_gpiowrite(GPIO_LED_R, true);
kinetis_gpiowrite(GPIO_LED_G, true);
kinetis_gpiowrite(GPIO_LED_B, true);
}
}
#endif /* CONFIG_ARCH_LEDS */
+306
View File
@@ -0,0 +1,306 @@
/************************************************************************************
*
* Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org>
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************************/
/************************************************************************************
* Included Files
************************************************************************************/
#include <px4_config.h>
#if defined(CONFIG_FS_AUTOMOUNTER_DEBUG) && !defined(CONFIG_DEBUG_FS)
# define CONFIG_DEBUG_FS 1
#endif
#include <debug.h>
#include <stddef.h>
#include <nuttx/irq.h>
#include <nuttx/clock.h>
#include <nuttx/fs/automount.h>
#include "board_config.h"
#ifdef HAVE_AUTOMOUNTER
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/************************************************************************************
* Private Types
************************************************************************************/
/* This structure represents the changeable state of the automounter */
struct nxphlite_automount_state_s {
volatile automount_handler_t handler; /* Upper half handler */
FAR void *arg; /* Handler argument */
bool enable; /* Fake interrupt enable */
bool pending; /* Set if there an event while disabled */
};
/* This structure represents the static configuration of an automounter */
struct nxphlite_automount_config_s {
/* This must be first thing in structure so that we can simply cast from struct
* automount_lower_s to struct nxphlite_automount_config_s
*/
struct automount_lower_s lower; /* Publicly visible part */
FAR struct nxphlite_automount_state_s *state; /* Changeable state */
};
/************************************************************************************
* Private Function Prototypes
************************************************************************************/
static int nxphlite_attach(FAR const struct automount_lower_s *lower,
automount_handler_t isr, FAR void *arg);
static void nxphlite_enable(FAR const struct automount_lower_s *lower, bool enable);
static bool nxphlite_inserted(FAR const struct automount_lower_s *lower);
/************************************************************************************
* Private Data
************************************************************************************/
static struct nxphlite_automount_state_s g_sdhc_state;
static const struct nxphlite_automount_config_s g_sdhc_config = {
.lower =
{
.fstype = CONFIG_NXPHLITE_SDHC_AUTOMOUNT_FSTYPE,
.blockdev = CONFIG_NXPHLITE_SDHC_AUTOMOUNT_BLKDEV,
.mountpoint = CONFIG_NXPHLITE_SDHC_AUTOMOUNT_MOUNTPOINT,
.ddelay = MSEC2TICK(CONFIG_NXPHLITE_SDHC_AUTOMOUNT_DDELAY),
.udelay = MSEC2TICK(CONFIG_NXPHLITE_SDHC_AUTOMOUNT_UDELAY),
.attach = nxphlite_attach,
.enable = nxphlite_enable,
.inserted = nxphlite_inserted
},
.state = &g_sdhc_state
};
/************************************************************************************
* Private Functions
************************************************************************************/
/************************************************************************************
* Name: nxphlite_attach
*
* Description:
* Attach a new SDHC event handler
*
* Input Parameters:
* lower - An instance of the auto-mounter lower half state structure
* isr - The new event handler to be attach
* arg - Client data to be provided when the event handler is invoked.
*
* Returned Value:
* Always returns OK
*
************************************************************************************/
static int nxphlite_attach(FAR const struct automount_lower_s *lower,
automount_handler_t isr, FAR void *arg)
{
FAR const struct nxphlite_automount_config_s *config;
FAR struct nxphlite_automount_state_s *state;
/* Recover references to our structure */
config = (FAR struct nxphlite_automount_config_s *)lower;
DEBUGASSERT(config != NULL && config->state != NULL);
state = config->state;
/* Save the new handler info (clearing the handler first to eliminate race
* conditions).
*/
state->handler = NULL;
state->pending = false;
state->arg = arg;
state->handler = isr;
return OK;
}
/************************************************************************************
* Name: nxphlite_enable
*
* Description:
* Enable card insertion/removal event detection
*
* Input Parameters:
* lower - An instance of the auto-mounter lower half state structure
* enable - True: enable event detection; False: disable
*
* Returned Value:
* None
*
************************************************************************************/
static void nxphlite_enable(FAR const struct automount_lower_s *lower, bool enable)
{
FAR const struct nxphlite_automount_config_s *config;
FAR struct nxphlite_automount_state_s *state;
irqstate_t flags;
/* Recover references to our structure */
config = (FAR struct nxphlite_automount_config_s *)lower;
DEBUGASSERT(config != NULL && config->state != NULL);
state = config->state;
/* Save the fake enable setting */
flags = enter_critical_section();
state->enable = enable;
/* Did an interrupt occur while interrupts were disabled? */
if (enable && state->pending) {
/* Yes.. perform the fake interrupt if the interrutp is attached */
if (state->handler) {
bool inserted = nxphlite_cardinserted();
(void)state->handler(&config->lower, state->arg, inserted);
}
state->pending = false;
}
leave_critical_section(flags);
}
/************************************************************************************
* Name: nxphlite_inserted
*
* Description:
* Check if a card is inserted into the slot.
*
* Input Parameters:
* lower - An instance of the auto-mounter lower half state structure
*
* Returned Value:
* True if the card is inserted; False otherwise
*
************************************************************************************/
static bool nxphlite_inserted(FAR const struct automount_lower_s *lower)
{
return nxphlite_cardinserted();
}
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: nxphlite_automount_initialize
*
* Description:
* Configure auto-mounters for each enable and so configured SDHC
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
************************************************************************************/
void nxphlite_automount_initialize(void)
{
FAR void *handle;
finfo("Initializing automounter(s)\n");
/* Initialize the SDHC0 auto-mounter */
handle = automount_initialize(&g_sdhc_config.lower);
if (!handle) {
ferr("ERROR: Failed to initialize auto-mounter for SDHC0\n");
}
}
/************************************************************************************
* Name: nxphlite_automount_event
*
* Description:
* The SDHC card detection logic has detected an insertion or removal event. It
* has already scheduled the MMC/SD block driver operations. Now we need to
* schedule the auto-mount event which will occur with a substantial delay to make
* sure that everything has settle down.
*
* Input Parameters:
* slotno - Identifies the SDHC0 slot: SDHC0_SLOTNO or SDHC1_SLOTNO. There is a
* terminology problem here: Each SDHC supports two slots, slot A and slot B.
* Only slot A is used. So this is not a really a slot, but an HSCMI peripheral
* number.
* inserted - True if the card is inserted in the slot. False otherwise.
*
* Returned Value:
* None
*
* Assumptions:
* Interrupts are disabled.
*
************************************************************************************/
void nxphlite_automount_event(bool inserted)
{
FAR const struct nxphlite_automount_config_s *config = &g_sdhc_config;
FAR struct nxphlite_automount_state_s *state = &g_sdhc_state;
/* Is the auto-mounter interrupt attached? */
if (state->handler) {
/* Yes.. Have we been asked to hold off interrupts? */
if (!state->enable) {
/* Yes.. just remember the there is a pending interrupt. We will
* deliver the interrupt when interrupts are "re-enabled."
*/
state->pending = true;
} else {
/* No.. forward the event to the handler */
(void)state->handler(&config->lower, state->arg, inserted);
}
}
}
#endif /* HAVE_AUTOMOUNTER */
+694
View File
@@ -0,0 +1,694 @@
/****************************************************************************
*
* Copyright (c) 2013-2017 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file board_config.h
*
* nxphlite-v3 internal definitions
*/
#pragma once
/****************************************************************************************************
* Included Files
****************************************************************************************************/
#include <px4_config.h>
#include <nuttx/compiler.h>
#include <stdint.h>
__BEGIN_DECLS
/* these headers are not C++ safe */
#include <kinetis.h>
#include <chip/kinetis_pinmux.h>
#include <arch/board/board.h>
/* NXPHLITE GPIOs ***********************************************************************************/
/* LEDs */
/* An RGB LED is connected through GPIO as shown below:
* TBD (no makring on schematic)
* LED K66
* ------ -------------------------------------------------------
* RED FB_CS0_b/ UART2_CTS_b / ADC0_SE5b / SPI0_SCK / FTM3_CH1/ PTD1
* GREEN FTM2_FLT0/ CMP0_IN3/ FB_AD6 / I2S0_RX_BCLK/ FTM3_CH5/ ADC1_SE5b/ PTC9
* BLUE CMP0_IN2/ FB_AD7 / I2S0_MCLK/ FTM3_CH4/ ADC1_SE4b/ PTC8
*/
#define GPIO_LED_R (GPIO_HIGHDRIVE | GPIO_OUTPUT_ONE | PIN_PORTD | PIN1)
#define GPIO_LED_G (GPIO_HIGHDRIVE | GPIO_OUTPUT_ONE | PIN_PORTC | PIN9)
#define GPIO_LED_B (GPIO_HIGHDRIVE | GPIO_OUTPUT_ONE | PIN_PORTC | PIN8)
#define GPIO_LED_1 (GPIO_HIGHDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTD | PIN13)
#define GPIO_LED_2 (GPIO_HIGHDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTD | PIN14)
#define BOARD_HAS_CONTROL_STATUS_LEDS 1 // Use D9 and D10
#define BOARD_OVERLOAD_LED LED_AMBER
#define BOARD_ARMED_STATE_LED LED_GREEN
#define GPIO_NFC_IO (GPIO_HIGHDRIVE | GPIO_OUTPUT_ONE | PIN_PORTA | PIN26)
#define GPIO_SENSOR_P_EN (GPIO_HIGHDRIVE | GPIO_OUTPUT_ONE | PIN_PORTB | PIN8)
/* UART tty Mapping
* Device tty alt Connector Name
* ------- ---------- -------------- --------- -------------------------
* LPUART0 /dev/tty0 /dev/console P16 DCD-Mini
* UART0 /dev/tty1 --- P7 IR transmitter & receiver
* UART1 /dev/tty2 --- P14,P15 SERIAL4/FrSky, RC_IN
* UART2 /dev/tty3 --- P3 GPS connector
* UART4 /dev/tty4 --- P10 UART (Bluetooth)
*/
/* High-resolution timer */
#define HRT_TIMER 1 /* TPM1 timer for the HRT */
#define HRT_TIMER_CHANNEL 0 /* Use capture/compare channel 0 */
/* PPM IN
*/
#define HRT_PPM_CHANNEL 1 /* Use TPM1 capture/compare channel 1 */
#define GPIO_PPM_IN PIN_TPM1_CH1_1 /* PTC3 USART1 RX and PTA9 and PIN_TPM1_CH1 AKA FrSky_IN_RC_IN */
/*
*
* NXPhlite-v3 has separate RC_IN
*
* GPIO PPM_IN on PTA9 PIN_TPM1_CH1 and PCT3 USART1 RX
* SPEKTRUM_RX (it's TX or RX in Bind) on PCT3 USART1 RX
* Inversion is possible the UART
* The FMU can drive GPIO PPM_IN as an output
*/
/* Spektrum controls ******************************************************/
/* Power is a p-Channel FET */
#define GPIO_SPEKTRUM_P_EN (GPIO_HIGHDRIVE | GPIO_OUTPUT_ONE | PIN_PORTA | PIN7)
/* For binding the Spektrum 3-pin interfaces is used with it TX (output)
* as an input Therefore we drive are UARTx_RX (normaly an input) as an
* output
*/
#define GPIO_PPM_IN_AS_OUT (GPIO_HIGHDRIVE | GPIO_OUTPUT_ONE | PIN_PORTC | PIN3)
#define SPEKTRUM_RX_AS_GPIO_OUTPUT() px4_arch_configgpio(GPIO_PPM_IN_AS_OUT)
#define SPEKTRUM_RX_AS_UART() px4_arch_configgpio(PIN_UART1_RX)
#define SPEKTRUM_OUT(_one_true) px4_arch_gpiowrite(GPIO_PPM_IN_AS_OUT, (_one_true))
/* RC input */
#define RC_UXART_BASE KINETIS_UART1_BASE
#define RC_SERIAL_PORT "/dev/ttyS2" /* UART1 */
#define GPIO_RSSI_IN PIN_ADC1_SE13
/* Ethernet Control
*
* Uninitialized to Reset Disabled and Inhibited
* All pins driven low to not back feed when power is off
*/
#define nGPIO_ETHERNET_P_EN (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTB | PIN3)
#define GPIO_ENET_RST (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTA | PIN28)
#define GPIO_ENET_EN (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTA | PIN29)
#define GPIO_ENET_INH (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTA | PIN8)
#define GPIO_ENET_CONFIG0 (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTA | PIN24)
#define GPIO_ENET_CONFIG1 (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTB | PIN2)
/* CAN Control
* Control pin S allows two operating modes to be selected:
* high-speed mode (Low) or silent mode (high)
*/
#define GPIO_CAN0_STB (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTC | PIN19)
#define GPIO_CAN1_STB (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTC | PIN18)
/* Safety Switch
* TBD
*/
#define GPIO_LED_SAFETY (GPIO_HIGHDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTC | PIN0)
#define GPIO_BTN_SAFETY (GPIO_PULLUP | PIN_PORTE | PIN28)
/* NXPHlite-v3 GPIOs ****************************************************************/
/* SDHC
*
* A micro Secure Digital (SD) card slot is available on the board connected to
* the SD Host Controller (SDHC) signals of the MCU. This slot will accept micro
* format SD memory cards. The SD card detect pin (PTE6) is an open switch that
* shorts with VDD when card is inserted.
*
* ------------ ------------- --------
* SD Card Slot Board Signal K66 Pin
* ------------ ------------- --------
* DAT0 SDHC0_D0 PTE1
* DAT1 SDHC0_D1 PTE0
* DAT2 SDHC0_D2 PTE5
* CD/DAT3 SDHC0_D3 PTE4
* CMD SDHC0_CMD PTE3
* CLK SDHC0_DCLK PTE2
* SWITCH D_CARD_DETECT PTD10
* CAED_P_EN PTD6
* ------------ ------------- --------
*
* There is no Write Protect pin available to the K66
*/
#define SD_CAED_P_EN (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTD | PIN6)
#define GPIO_SD_CARDDETECT (GPIO_PULLUP | PIN_INT_BOTH | PIN_PORTD | PIN10)
/* SPI
*
* SD Card is on SPI 0
* FXOS8700CQ Accelerometer & Magnetometer is on SPI 1
* FXAS21002CQ Gyro is on SPI 2
*/
/* SPI Bus assignments */
#define PX4_SPI_BUS_MEMORY PX4_BUS_NUMBER_TO_PX4(0)
#define PX4_SPI_BUS_SENSORS PX4_BUS_NUMBER_TO_PX4(1)
#define PX4_SPI_BUS_EXTERNAL PX4_BUS_NUMBER_TO_PX4(2)
#define PX4_SPI_BUS_RAMTRON PX4_SPI_BUS_MEMORY
#define PX4_SPI_BUS_EXT PX4_SPI_BUS_EXTERNAL
/* SPI chip selects */
#define GPIO_SPI_CS_MEMORY (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTC | PIN2)
#define GPIO_SPI_CS_FXAS21002CQ_GYRO (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTB | PIN9)
#define GPIO_SPI_CS_FXOS8700CQ_ACCEL_MAG (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTB | PIN10)
#define GPIO_SPI2_CS (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTB | PIN20)
#define GPIO_SPI2_EXT (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTD | PIN15)
/* SPI device reset signals
* In Active state
*/
/* Init in reset */
#define GPIO_GM_nRST (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTD | PIN12)
#define GPIO_A_RST (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTA | PIN25)
/* Sensor interrupts */
#define GPIO_EXTI_GYRO_INT1 (GPIO_PULLUP | PIN_INT_BOTH | PIN_PORTE | PIN7)
#define GPIO_EXTI_GYRO_INT2 (GPIO_PULLUP | PIN_INT_BOTH | PIN_PORTE | PIN6)
#define GPIO_EXTI_ACCEL_MAG_INT1 (GPIO_PULLUP | PIN_INT_BOTH | PIN_PORTE | PIN9)
#define GPIO_EXTI_ACCEL_MAG_INT2 (GPIO_PULLUP | PIN_INT_BOTH | PIN_PORTE | PIN10)
#define GPIO_EXTI_BARO_INT1 (GPIO_PULLUP | PIN_INT_BOTH | PIN_PORTD | PIN11)
#define GPIO_EXTI_BARO_INT2 (GPIO_PULLUP | PIN_INT_BOTH | PIN_PORTD | PIN7)
/* Use these in place of the uint32_t enumeration to select a specific SPI device on SPI1 */
#define PX4_SPIDEV_MEMORY PX4_MK_SPI_SEL(PX4_SPI_BUS_MEMORY,0)
#define PX4_MEMORY_BUS_CS_GPIO {GPIO_SPI_CS_MEMORY}
#define PX4_MEMORY_BUS_FIRST_CS PX4_SPIDEV_MEMORY
#define PX4_MEMORY_BUS_LAST_CS PX4_SPIDEV_MEMORY
#define PX4_SPIDEV_ACCEL_MAG PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS,0)
#define PX4_SPIDEV_GYRO PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS,1)
#define PX4_SENSOR_BUS_CS_GPIO {GPIO_SPI_CS_FXOS8700CQ_ACCEL_MAG, GPIO_SPI_CS_FXAS21002CQ_GYRO}
#define PX4_SENSOR_BUS_FIRST_CS PX4_SPIDEV_ACCEL_MAG
#define PX4_SENSOR_BUS_LAST_CS PX4_SPIDEV_GYRO
#define PX4_SPIDEV_EXTERNAL1 PX4_MK_SPI_SEL(PX4_SPI_BUS_EXTERNAL,0)
#define PX4_SPIDEV_EXTERNAL2 PX4_MK_SPI_SEL(PX4_SPI_BUS_EXTERNAL,1)
#define PX4_EXTERNAL_BUS_CS_GPIO {GPIO_SPI2_CS, GPIO_SPI2_EXT}
#define PX4_EXTERNAL_BUS_FIRST_CS PX4_SPIDEV_EXTERNAL1
#define PX4_EXTERNAL_BUS_LAST_CS PX4_SPIDEV_EXTERNAL2
#define PX4_SPIDEV_ICM_20602 PX4_SPIDEV_EXTERNAL1
#define PX4_SPIDEV_ICM_20608 PX4_SPIDEV_EXTERNAL1
#define PX4_SPIDEV_ICM_20689 PX4_SPIDEV_EXTERNAL1
#define PX4_SPIDEV_EXT_MPU PX4_SPIDEV_EXTERNAL1
#define PX4_SPIDEV_MPU PX4_SPIDEV_EXTERNAL1
/* I2C busses */
#define PX4_I2C_BUS_EXPANSION PX4_BUS_NUMBER_TO_PX4(0)
#define PX4_I2C_BUS_EXPANSION1 PX4_BUS_NUMBER_TO_PX4(1) // V3 RC15 has mpl3115a2 on onboard but this goes to a connector
// So it is treated as external.
#define PX4_I2C_BUS_LED PX4_I2C_BUS_EXPANSION1
/*
* ADC channels
*
* These are the channel numbers of the ADCs of the microcontroller that can be used by the Px4
* Firmware in the adc driver. ADC1 has 32 channels, with some a/b selection overlap
* in the AD4-AD7 range on the same ADC.
*
* Only ADC1 is used
* Bits 31:0 are ADC1 channels 31:0
*/
#define ADC1_CH(c) (((c) & 0x1f)) /* Define ADC number Channel number */
#define ADC1_GPIO(n) PIN_ADC1_SE##n
/* ADC defines to be used in sensors.cpp to read from a particular channel */
#define ADC_USB_VBUS_VALID ADC1_CH(0) /* USB_VBUS_VALID 29 - ADC1_DP0 */
#define ADC_BATTERY_VOLTAGE_CHANNEL ADC1_CH(10) /* BAT_VSENS 85 PTB4 ADC1_SE10 */
#define ADC_BATTERY_CURRENT_CHANNEL ADC1_CH(11) /* BAT_ISENS 86 PTB5 ADC1_SE11 */
#define ADC_5V_RAIL_SENSE ADC1_CH(12) /* 5V_VSENS 87 PTB6 ADC1_SE12 */
#define ADC_RSSI_IN ADC1_CH(13) /* RSSI_IN 88 PTB7 ADC1_SE13 */
#define ADC_AD1 ADC1_CH(16) /* AD1 35 - ADC1_SE16 */
#define ADC_AD2 ADC1_CH(18) /* AD2 37 - ADC1_SE18 */
#define ADC_AD3 ADC1_CH(23) /* AD3 39 - ADC1_SE23 */
/* Mask use to initialize the ADC driver */
#define ADC_CHANNELS ((1 << ADC_USB_VBUS_VALID) | \
(1 << ADC_BATTERY_VOLTAGE_CHANNEL) | \
(1 << ADC_BATTERY_CURRENT_CHANNEL) | \
(1 << ADC_5V_RAIL_SENSE) | \
(1 << ADC_RSSI_IN) | \
(1 << ADC_AD1) | \
(1 << ADC_AD2) | \
(1 << ADC_AD3))
/* GPIO that require Configuration */
#define PX4_ADC_GPIO \
/* PTB4 ADC1_SE10 */ ADC1_GPIO(10), \
/* PTB5 ADC1_SE11 */ ADC1_GPIO(11), \
/* PTB6 ADC1_SE12 */ ADC1_GPIO(12), \
/* PTB7 ADC1_SE13 */ ADC1_GPIO(13)
#define BOARD_BATTERY1_V_DIV (10.177939394f)
#define BOARD_BATTERY1_A_PER_V (15.391030303f)
/* User GPIOs
*
* GPIO-
* Define as GPIO input / GPIO outputs and timers IO
*/
#define PX4_MK_GPIO(pin_ftmx, io) ((((uint32_t)(pin_ftmx)) & ~(_PIN_MODE_MASK | _PIN_OPTIONS_MASK)) |(io))
#define PX4_MK_GPIO_INPUT(pin_ftmx) PX4_MK_GPIO(pin_ftmx, GPIO_PULLUP)
#define PX4_MK_GPIO_OUTPUT(pin_ftmx) PX4_MK_GPIO(pin_ftmx, GPIO_HIGHDRIVE)
#define GPIO_GPIO0_INPUT PX4_MK_GPIO_INPUT(GPIO_FTM0_CH0OUT) /* FMU_CH1 */
#define GPIO_GPIO1_INPUT PX4_MK_GPIO_INPUT(GPIO_FTM0_CH3OUT) /* FMU_CH2 */
#define GPIO_GPIO2_INPUT PX4_MK_GPIO_INPUT(GPIO_FTM0_CH4OUT) /* FMU_CH3 */
#define GPIO_GPIO3_INPUT PX4_MK_GPIO_INPUT(GPIO_FTM0_CH5OUT) /* FMU_CH4 */
#define GPIO_GPIO4_INPUT PX4_MK_GPIO_INPUT(GPIO_FTM3_CH6OUT) /* FMU_CH5 */
#define GPIO_GPIO5_INPUT PX4_MK_GPIO_INPUT(GPIO_FTM3_CH7OUT) /* FMU_CH6 */
#define GPIO_GPIO6_INPUT PX4_MK_GPIO_INPUT(GPIO_FTM3_CH0OUT) /* U_TRI */
#define GPIO_GPIO7_INPUT PX4_MK_GPIO_INPUT(GPIO_FTM2_CH0OUT) /* U_ECHO */
#define GPIO_GPIO0_OUTPUT PX4_MK_GPIO_OUTPUT(GPIO_FTM0_CH0OUT) /* FMU_CH1 */
#define GPIO_GPIO1_OUTPUT PX4_MK_GPIO_OUTPUT(GPIO_FTM0_CH3OUT) /* FMU_CH2 */
#define GPIO_GPIO2_OUTPUT PX4_MK_GPIO_OUTPUT(GPIO_FTM0_CH4OUT) /* FMU_CH3 */
#define GPIO_GPIO3_OUTPUT PX4_MK_GPIO_OUTPUT(GPIO_FTM0_CH5OUT) /* FMU_CH4 */
#define GPIO_GPIO4_OUTPUT PX4_MK_GPIO_OUTPUT(GPIO_FTM3_CH6OUT) /* FMU_CH5 */
#define GPIO_GPIO5_OUTPUT PX4_MK_GPIO_OUTPUT(GPIO_FTM3_CH7OUT) /* FMU_CH6 */
#define GPIO_GPIO6_OUTPUT PX4_MK_GPIO_OUTPUT(GPIO_FTM3_CH0OUT) /* U_TRI */
#define GPIO_GPIO7_OUTPUT PX4_MK_GPIO_OUTPUT(GPIO_FTM2_CH0OUT) /* U_ECHO */
/* P13 Ultrasonic Sensors
* Timer Capture driver the the Trigger and sample the response on Echo
*/
#define GPIO_TRI GPIO_GPIO6_OUTPUT
#define GPIO_ECH GPIO_GPIO7_INPUT
/* Timer I/O PWM and capture
*
* 14 PWM outputs are configured.
* 14 Timer inputs are configured.
*
* Pins:
* Defined in board.h
*/
// todo:Design this!
#define DIRECT_PWM_OUTPUT_CHANNELS 8
#define DIRECT_INPUT_TIMER_CHANNELS 8
/* Power supply control and monitoring GPIOs */
// None
#define GPIO_PERIPH_3V3_EN 0
/* Tone alarm output PTA11 - TMP 2_CH1 is On +P12-4, -P12-5
* It is driving a NPN
*/
#define TONE_ALARM_TIMER 2 /* timer */
#define TONE_ALARM_CHANNEL 1 /* channel */
#define GPIO_TONE_ALARM_IDLE (GPIO_LOWDRIVE | GPIO_OUTPUT_ZER0 | PIN_PORTA | PIN11)
#define GPIO_TONE_ALARM (PIN_TPM2_CH1_1)
/* USB
*
* VBUS detection is on 29 ADC_DPM0 and PTE8
*/
#define GPIO_USB_VBUS_VALID /* PTE8 */ (GPIO_PULLUP | PIN_PORTE | PIN8)
/* PWM input driver. Use FMU PWM14 pin
* todo:desing this
*/
#define PWMIN_TIMER 0
#define PWMIN_TIMER_CHANNEL 2
#define GPIO_PWM_IN GPIO_FTM0_CH2IN
#define BOARD_NAME "NXPHLITE_V3"
/* Define True logic Power Control in arch agnostic form */
#define VDD_ETH_EN(on_true) px4_arch_gpiowrite(nGPIO_ETHERNET_P_EN, !(on_true))
// Do not have #define VDD_5V_PERIPH_EN(on_true) px4_arch_gpiowrite(GPIO_nVDD_5V_PERIPH_EN, !(on_true))
// Do not have #define VDD_5V_HIPOWER_EN(on_true) px4_arch_gpiowrite(GPIO_nVDD_5V_HIPOWER_EN, !(on_true))
#define VDD_3V3_SENSORS_EN(on_true) px4_arch_gpiowrite(GPIO_SENSOR_P_EN, !(on_true))
#define VDD_3V3_SPEKTRUM_POWER_EN(on_true) px4_arch_gpiowrite(GPIO_SPEKTRUM_P_EN, !(on_true))
#define READ_VDD_3V3_SPEKTRUM_POWER_EN() px4_arch_gpioread(GPIO_SPEKTRUM_P_EN)
// Do not have #define VDD_5V_RC_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_5V_RC_EN, (on_true))
// Do not have #define VDD_5V_WIFI_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_5V_WIFI_EN, (on_true))
#define VDD_3V3_SD_CARD_EN(on_true) px4_arch_gpiowrite(SD_CAED_P_EN, !(on_true))
/* Map to control term used in RC lib */
#define SPEKTRUM_POWER(on_true) VDD_3V3_SPEKTRUM_POWER_EN((on_true))
/*
* By Providing BOARD_ADC_USB_CONNECTED (using the px4_arch abstraction)
* this board support the ADC system_power interface, and therefore
* provides the true logic GPIO BOARD_ADC_xxxx macros.
*/
#define BOARD_ADC_USB_CONNECTED (px4_arch_gpioread(GPIO_USB_VBUS_VALID))
#define BOARD_ADC_BRICK_VALID (1)
#define BOARD_ADC_SERVO_VALID (1)
#define BOARD_ADC_PERIPH_5V_OC (0)
#define BOARD_ADC_HIPOWER_5V_OC (0)
#define BOARD_HAS_PWM DIRECT_PWM_OUTPUT_CHANNELS
#define BOARD_FMU_GPIO_TAB { \
{GPIO_GPIO0_INPUT, GPIO_GPIO0_OUTPUT, 0}, \
{GPIO_GPIO1_INPUT, GPIO_GPIO1_OUTPUT, 0}, \
{GPIO_GPIO2_INPUT, GPIO_GPIO2_OUTPUT, 0}, \
{GPIO_GPIO3_INPUT, GPIO_GPIO3_OUTPUT, 0}, \
{GPIO_GPIO4_INPUT, GPIO_GPIO4_OUTPUT, 0}, \
{GPIO_GPIO5_INPUT, GPIO_GPIO5_OUTPUT, 0}, \
{0, GPIO_TRI, 0}, \
{GPIO_ECH, 0, 0}, \
}
#define BOARD_HAS_LED_PWM 1
#define LED_TIM3_CH1OUT /* PTD1 RGB_R */ PIN_FTM3_CH1_1
#define LED_TIM3_CH5OUT /* PTC9 RGB_G */ PIN_FTM3_CH5_1
#define LED_TIM3_CH4OUT /* PTC8 RGB_B */ PIN_FTM3_CH4_1
/*
* GPIO numbers.
*
* There are no alternate functions on this board.
*/
#define GPIO_SERVO_1 (1<<0) /**< servo 1 output */
#define GPIO_SERVO_2 (1<<1) /**< servo 2 output */
#define GPIO_SERVO_3 (1<<2) /**< servo 3 output */
#define GPIO_SERVO_4 (1<<3) /**< servo 4 output */
#define GPIO_SERVO_5 (1<<4) /**< servo 5 output */
#define GPIO_SERVO_6 (1<<5) /**< servo 6 output */
#define GPIO_SERVO_7 (1<<6) /**< servo 7 output U_TRI */
#define GPIO_SERVO_8 (1<<6) /**< servo 8 output U_ECH */
/* This board provides a DMA pool and APIs */
#define BOARD_DMA_ALLOC_POOL_SIZE 5120
/* This board provides the board_on_reset interface */
#define BOARD_HAS_ON_RESET 1
#define PX4_GPIO_PWM_INIT_LIST { \
GPIO_GPIO5_INPUT, \
GPIO_GPIO4_INPUT, \
GPIO_GPIO3_INPUT, \
GPIO_GPIO2_INPUT, \
GPIO_GPIO1_INPUT, \
GPIO_GPIO0_INPUT, \
GPIO_TRI, \
}
#define PX4_GPIO_INIT_LIST { \
GPIO_LED_R, \
GPIO_LED_G, \
GPIO_LED_B, \
GPIO_SENSOR_P_EN, \
SD_CAED_P_EN, \
nGPIO_ETHERNET_P_EN, \
GPIO_SPEKTRUM_P_EN, \
PX4_ADC_GPIO, \
GPIO_GM_nRST, \
GPIO_A_RST, \
GPIO_USB_VBUS_VALID, \
GPIO_ECH, \
GPIO_ENET_RST, \
GPIO_ENET_EN, \
GPIO_ENET_INH, \
GPIO_ENET_CONFIG0, \
GPIO_ENET_CONFIG1, \
PIN_CAN0_RX, \
PIN_CAN0_TX, \
PIN_CAN1_RX, \
PIN_CAN1_TX, \
GPIO_CAN0_STB, \
GPIO_CAN1_STB, \
GPIO_BTN_SAFETY, \
GPIO_TONE_ALARM_IDLE, \
GPIO_NFC_IO, \
GPIO_LED_1, \
GPIO_LED_2 \
}
/* Automounter */
#define HAVE_MMCSD 1
#define HAVE_AUTOMOUNTER 1
#if !defined(CONFIG_FS_AUTOMOUNTER) || !defined(HAVE_MMCSD)
# undef HAVE_AUTOMOUNTER
# undef CONFIG_NXPHLITE_SDHC_AUTOMOUNT
#endif
#ifndef CONFIG_NXPHLITE_SDHC_AUTOMOUNT
# undef HAVE_AUTOMOUNTER
#endif
/* Automounter defaults */
#ifdef HAVE_AUTOMOUNTER
# ifndef CONFIG_NXPHLITE_SDHC_AUTOMOUNT_FSTYPE
# define CONFIG_NXPHLITE_SDHC_AUTOMOUNT_FSTYPE "vfat"
# endif
# ifndef CONFIG_NXPHLITE_SDHC_AUTOMOUNT_BLKDEV
# define CONFIG_NXPHLITE_SDHC_AUTOMOUNT_BLKDEV "/dev/mmcds0"
# endif
# ifndef CONFIG_NXPHLITE_SDHC_AUTOMOUNT_MOUNTPOINT
# define CONFIG_NXPHLITE_SDHC_AUTOMOUNT_MOUNTPOINT "/mnt/sdcard"
# endif
# ifndef CONFIG_NXPHLITE_SDHC_AUTOMOUNT_DDELAY
# define CONFIG_NXPHLITE_SDHC_AUTOMOUNT_DDELAY 1000
# endif
# ifndef CONFIG_NXPHLITE_SDHC_AUTOMOUNT_UDELAY
# define CONFIG_NXPHLITE_SDHC_AUTOMOUNT_UDELAY 2000
# endif
#endif /* HAVE_AUTOMOUNTER */
#define BOARD_HAS_NOISY_FXOS8700_MAG 1 // Disable internal MAG
/************************************************************************************
* Public data
************************************************************************************/
#ifndef __ASSEMBLY__
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: nxphlite_spidev_initialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the NXPHlite-v3 board.
*
************************************************************************************/
void nxphlite_spidev_initialize(void);
/************************************************************************************
* Name: nxphlite_spi_bus_initialize
*
* Description:
* Called to configure SPI Buses.
*
************************************************************************************/
int nxphlite_spi_bus_initialize(void);
/****************************************************************************************************
* Name: board_spi_reset board_peripheral_reset
*
* Description:
* Called to reset SPI and the perferal bus
*
****************************************************************************************************/
void board_spi_reset(int ms);
void board_peripheral_reset(int ms);
/************************************************************************************
* Name: nxphlite_bringup
*
* Description:
* Bring up board features
*
************************************************************************************/
#if defined(CONFIG_LIB_BOARDCTL) || defined(CONFIG_BOARD_INITIALIZE)
int nxphlite_bringup(void);
#endif
/****************************************************************************
* Name: nxphlite_sdhc_initialize
*
* Description:
* Inititialize the SDHC SD card slot
*
****************************************************************************/
int nxphlite_sdhc_initialize(void);
/************************************************************************************
* Name: nxphlite_cardinserted
*
* Description:
* Check if a card is inserted into the SDHC slot
*
************************************************************************************/
#ifdef HAVE_AUTOMOUNTER
bool nxphlite_cardinserted(void);
#else
# define nxphlite_cardinserted() (false)
#endif
/************************************************************************************
* Name: nxphlite_writeprotected
*
* Description:
* Check if the card in the MMC/SD slot is write protected
*
************************************************************************************/
#ifdef HAVE_AUTOMOUNTER
bool nxphlite_writeprotected(void);
#else
# define nxphlite_writeprotected() (false)
#endif
/************************************************************************************
* Name: nxphlite_automount_initialize
*
* Description:
* Configure auto-mounter for the configured SDHC slot
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
************************************************************************************/
#ifdef HAVE_AUTOMOUNTER
void nxphlite_automount_initialize(void);
#endif
/************************************************************************************
* Name: nxphlite_automount_event
*
* Description:
* The SDHC card detection logic has detected an insertion or removal event. It
* has already scheduled the MMC/SD block driver operations. Now we need to
* schedule the auto-mount event which will occur with a substantial delay to make
* sure that everything has settle down.
*
* Input Parameters:
* inserted - True if the card is inserted in the slot. False otherwise.
*
* Returned Value:
* None
*
* Assumptions:
* Interrupts are disabled.
*
************************************************************************************/
#ifdef HAVE_AUTOMOUNTER
void nxphlite_automount_event(bool inserted);
#endif
/************************************************************************************
* Name: nxphlite_timer_initialize
*
* Description:
* Called to configure the FTM to provide 1 Mhz
*
************************************************************************************/
void nxphlite_timer_initialize(void);
#include <drivers/boards/common/board_common.h>
#endif /* __ASSEMBLY__ */
__END_DECLS
+129
View File
@@ -0,0 +1,129 @@
/****************************************************************************
*
* Copyright (C) 2016 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file nxphlite_can.c
*
* Board-specific CAN functions.
*/
/************************************************************************************
* Included Files
************************************************************************************/
#include <px4_config.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/can/can.h>
#include <arch/board/board.h>
#include <chip.h>
#include <kinetis.h>
#include "up_arch.h"
#include "board_config.h"
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/* Configuration ********************************************************************/
#if defined(KINETIS_FLEXCAN0) && defined(KINETIS_FLEXCAN1)
# warning "Both CAN0 and CAN1 are enabled. Assuming only CAN0."
# undef KINETIS_FLEXCAN0
#endif
#ifdef KINETIS_FLEXCAN0
# define CAN_PORT 1
#else
# define CAN_PORT 2
#endif
/************************************************************************************
* Private Functions
************************************************************************************/
/************************************************************************************
* Public Functions
************************************************************************************/
int can_devinit(void);
/************************************************************************************
* Name: can_devinit
*
* Description:
* All architectures must provide the following interface to work with
* examples/can.
*
************************************************************************************/
int can_devinit(void)
{
static bool initialized = false;
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
if (!initialized) {
/* Call kinetis_caninitialize() to get an instance of the CAN interface */
can = kinetis_caninitialize(CAN_PORT);
if (can == NULL) {
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0) {
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
}
return OK;
}
#endif
+362
View File
@@ -0,0 +1,362 @@
/****************************************************************************
*
* Copyright (c) 2016 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file nxphlite_init.c
*
* NXPHLITEV1v2-specific early startup code. This file implements the
* board_app_initialize() function that is called early by nsh during startup.
*
* Code here is run before the rcS script is invoked; it should start required
* subsystems and perform board-specific initialization.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <px4_config.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <debug.h>
#include <errno.h>
#include "platform/cxxinitialize.h"
#include <nuttx/board.h>
#include <nuttx/spi/spi.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/sdio.h>
#include <nuttx/mmcsd.h>
#include <nuttx/analog/adc.h>
#include <kinetis.h>
#include <kinetis_uart.h>
#include <chip/kinetis_uart.h>
#include "board_config.h"
#include "up_arch.h"
#include <arch/board/board.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_board_led.h>
#include <systemlib/px4_macros.h>
#include <systemlib/cpuload.h>
#include <perf/perf_counter.h>
#include <systemlib/err.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
# ifdef CONFIG_DEBUG
# define message(...) syslog(__VA_ARGS__)
# else
# define message(...) printf(__VA_ARGS__)
# endif
#else
# ifdef CONFIG_DEBUG
# define message syslog
# else
# define message printf
# endif
#endif
/*
* Ideally we'd be able to get these from up_internal.h,
* but since we want to be able to disable the NuttX use
* of leds for system indication at will and there is no
* separate switch, we need to build independent of the
* CONFIG_ARCH_LEDS configuration switch.
*/
__BEGIN_DECLS
extern void led_init(void);
extern void led_on(int led);
extern void led_off(int led);
__END_DECLS
/****************************************************************************
* Protected Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/************************************************************************************
* Name: board_on_reset
*
* Description:
* Optionally provided function called on entry to board_system_reset
* It should perform any house keeping prior to the rest.
*
* status - 1 if resetting to boot loader
* 0 if just resetting
*
************************************************************************************/
void board_on_reset(int status)
{
/* configure the GPIO pins to outputs and keep them low */
const uint32_t gpio[] = PX4_GPIO_PWM_INIT_LIST;
board_gpio_init(gpio, arraySize(gpio));
if (status >= 0) {
up_mdelay(6);
}
}
/************************************************************************************
* Name: board_read_VBUS_state
*
* Description:
* All boards must provide a way to read the state of VBUS, this my be simple
* digital input on a GPIO. Or something more complicated like a Analong input
* or reading a bit from a USB controller register.
*
* Returns - 0 if connected.
*
************************************************************************************/
int board_read_VBUS_state(void)
{
return BOARD_ADC_USB_CONNECTED ? 0 : 1;
}
/************************************************************************************
* Name: board_rc_input
*
* Description:
* All boards my optionally provide this API to invert the Serial RC input.
* This is needed on SoCs that support the notion RXINV or TXINV as opposed to
* and external XOR controlled by a GPIO
*
************************************************************************************/
__EXPORT void board_rc_input(bool invert_on, uint32_t uxart_base)
{
irqstate_t irqstate = px4_enter_critical_section();
uint8_t s2 = getreg8(KINETIS_UART_S2_OFFSET + uxart_base);
uint8_t c3 = getreg8(KINETIS_UART_C3_OFFSET + uxart_base);
/* {R|T}XINV bit fields can written any time */
if (invert_on) {
s2 |= (UART_S2_RXINV);
c3 |= (UART_C3_TXINV);
} else {
s2 &= ~(UART_S2_RXINV);
c3 &= ~(UART_C3_TXINV);
}
putreg8(s2, KINETIS_UART_S2_OFFSET + uxart_base);
putreg8(c3, KINETIS_UART_C3_OFFSET + uxart_base);
leave_critical_section(irqstate);
}
/************************************************************************************
* Name: board_peripheral_reset
*
* Description:
*
************************************************************************************/
__EXPORT void board_peripheral_reset(int ms)
{
/* set the peripheral rails off */
/* wait for the peripheral rail to reach GND */
usleep(ms * 1000);
warnx("reset done, %d ms", ms);
/* re-enable power */
/* switch the peripheral rail back on */
}
/************************************************************************************
* Name: stm32_boardinitialize
*
* Description:
* All Kinetis architectures must provide the following entry point. This entry point
* is called early in the intitialization -- after all memory has been configured
* and mapped but before any devices have been initialized.
*
************************************************************************************/
__EXPORT void
kinetis_boardinitialize(void)
{
board_on_reset(-1); /* Reset PWM first thing */
/* configure LEDs */
board_autoled_initialize();
const uint32_t gpio[] = PX4_GPIO_INIT_LIST;
board_gpio_init(gpio, arraySize(gpio));
nxphlite_timer_initialize();
/* Power on Spektrum */
VDD_3V3_SPEKTRUM_POWER_EN(true);
}
/****************************************************************************
* Name: board_app_initialize
*
* Description:
* Perform application specific initialization. This function is never
* called directly from application code, but only indirectly via the
* (non-standard) boardctl() interface using the command BOARDIOC_INIT.
*
* Input Parameters:
* arg - The boardctl() argument is passed to the board_app_initialize()
* implementation without modification. The argument has no
* meaning to NuttX; the meaning of the argument is a contract
* between the board-specific initalization logic and the the
* matching application logic. The value cold be such things as a
* mode enumeration value, a set of DIP switch switch settings, a
* pointer to configuration data read from a file or serial FLASH,
* or whatever you would like to do with it. Every implementation
* should accept zero/NULL as a default configuration.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure to indicate the nature of the failure.
*
****************************************************************************/
__EXPORT int board_app_initialize(uintptr_t arg)
{
VDD_3V3_SD_CARD_EN(true);
VDD_3V3_SENSORS_EN(true);
/* configure SPI interfaces */
nxphlite_spidev_initialize();
VDD_ETH_EN(true);
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
/* run C++ ctors before we go any further */
up_cxxinitialize();
# if defined(CONFIG_EXAMPLES_NSH_CXXINITIALIZE)
# error CONFIG_EXAMPLES_NSH_CXXINITIALIZE Must not be defined! Use CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE.
# endif
#else
# error platform is dependent on c++ both CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE must be defined.
#endif
param_init();
/* configure the high-resolution time/callout interface */
hrt_init();
/* configure the DMA allocator */
if (board_dma_alloc_init() < 0) {
message("DMA alloc FAILED");
}
/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
cpuload_initialize_once();
#endif
/* set up the serial DMA polling */
#ifdef SERIAL_HAVE_DMA
static struct hrt_call serial_dma_call;
struct timespec ts;
/*
* Poll at 1ms intervals for received bytes that have not triggered
* a DMA event.
*/
ts.tv_sec = 0;
ts.tv_nsec = 1000000;
hrt_call_every(&serial_dma_call,
ts_to_abstime(&ts),
ts_to_abstime(&ts),
(hrt_callout)kinetis_serial_dma_poll,
NULL);
#endif
/* initial LED state */
drv_led_start();
led_off(LED_RED);
led_off(LED_GREEN);
led_off(LED_BLUE);
int ret = nxphlite_sdhc_initialize();
if (ret != OK) {
board_autoled_on(LED_RED);
return ret;
}
#ifdef HAVE_AUTOMOUNTER
/* Initialize the auto-mounter */
nxphlite_automount_initialize();
#endif
/* Configure SPI-based devices */
#ifdef CONFIG_SPI
ret = nxphlite_spi_bus_initialize();
if (ret != OK) {
board_autoled_on(LED_RED);
return ret;
}
#endif
return OK;
}
+115
View File
@@ -0,0 +1,115 @@
/****************************************************************************
*
* Copyright (c) 2016 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file nxphlite_led.c
*
* NXPHLITEV1 LED backend.
*/
#include <px4_config.h>
#include <stdbool.h>
#include "kinetis.h"
#include "chip.h"
#include "board_config.h"
#include <arch/board/board.h>
/*
* Ideally we'd be able to get these from up_internal.h,
* but since we want to be able to disable the NuttX use
* of leds for system indication at will and there is no
* separate switch, we need to build independent of the
* CONFIG_ARCH_LEDS configuration switch.
*/
__BEGIN_DECLS
extern void led_init(void);
extern void led_on(int led);
extern void led_off(int led);
extern void led_toggle(int led);
__END_DECLS
static uint32_t g_ledmap[] = {
0, // Indexed by LED_BLUE
GPIO_LED_1, // Indexed by LED_RED, LED_AMBER
GPIO_LED_SAFETY, // Indexed by LED_SAFETY
GPIO_LED_2, // Indexed by LED_GREEN
};
__EXPORT void led_init(void)
{
/* Configure LED GPIOs for output */
for (size_t l = 0; l < (sizeof(g_ledmap) / sizeof(g_ledmap[0])); l++) {
if (g_ledmap[l] != 0) {
kinetis_pinconfig(g_ledmap[l]);
}
}
}
static void phy_set_led(int led, bool state)
{
/* Drive High to switch on */
if (g_ledmap[led] != 0) {
kinetis_gpiowrite(g_ledmap[led], state);
}
}
static bool phy_get_led(int led)
{
if (g_ledmap[led] != 0) {
return kinetis_gpioread(g_ledmap[led]);
}
return false;
}
__EXPORT void led_on(int led)
{
phy_set_led(led, true);
}
__EXPORT void led_off(int led)
{
phy_set_led(led, false);
}
__EXPORT void led_toggle(int led)
{
phy_set_led(led, !phy_get_led(led));
}
+250
View File
@@ -0,0 +1,250 @@
/****************************************************************************
*
* Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org>
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/* A micro Secure Digital (SD) card slot is available on the board connected to
* the SD Host Controller (SDHC) signals of the MCU. This slot will accept micro
* format SD memory cards. The SD card detect pin (PTE6) is an open switch that
* shorts with VDD when card is inserted.
*
* ------------ ------------- --------
* SD Card Slot Board Signal K66 Pin
* ------------ ------------- --------
* DAT0 SDHC0_D0 PTE1
* DAT1 SDHC0_D1 PTE0
* DAT2 SDHC0_D2 PTE5
* CD/DAT3 SDHC0_D3 PTE4
* CMD SDHC0_CMD PTE3
* CLK SDHC0_DCLK PTE2
* SWITCH D_CARD_DETECT PTE6
* ------------ ------------- --------
*
* There is no Write Protect pin available to the K66.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <px4_config.h>
#include <stdbool.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/sdio.h>
#include <nuttx/mmcsd.h>
#include "kinetis.h"
#include "board_config.h"
#ifdef CONFIG_KINETIS_SDHC
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/* This structure holds static information unique to one SDHC peripheral */
struct nxphlite_sdhc_state_s {
struct sdio_dev_s *sdhc; /* R/W device handle */
bool inserted; /* TRUE: card is inserted */
};
/****************************************************************************
* Private Data
****************************************************************************/
/* HSCMI device state */
static struct nxphlite_sdhc_state_s g_sdhc;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxphlite_mediachange
****************************************************************************/
static void nxphlite_mediachange(struct nxphlite_sdhc_state_s *sdhc)
{
bool inserted;
/* Get the current value of the card detect pin. This pin is pulled up on
* board. So low means that a card is present.
*/
inserted = !kinetis_gpioread(GPIO_SD_CARDDETECT);
mcinfo("inserted: %s\n", inserted ? "Yes" : "No");
/* Has the pin changed state? */
if (inserted != sdhc->inserted) {
mcinfo("Media change: %d->%d\n", sdhc->inserted, inserted);
/* Yes.. perform the appropriate action (this might need some debounce). */
sdhc->inserted = inserted;
sdhc_mediachange(sdhc->sdhc, inserted);
#ifdef CONFIG_NXPHLITE_SDHC_AUTOMOUNT
/* Let the automounter know about the insertion event */
nxphlite_automount_event(nxphlite_cardinserted());
#endif
}
}
/****************************************************************************
* Name: nxphlite_cdinterrupt
****************************************************************************/
static int nxphlite_cdinterrupt(int irq, FAR void *context, FAR void *args)
{
/* All of the work is done by nxphlite_mediachange() */
nxphlite_mediachange((struct nxphlite_sdhc_state_s *) args);
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxphlite_sdhc_initialize
*
* Description:
* Inititialize the SDHC SD card slot
*
****************************************************************************/
int nxphlite_sdhc_initialize(void)
{
int ret;
struct nxphlite_sdhc_state_s *sdhc = &g_sdhc;
/* Configure GPIO pins */
VDD_3V3_SD_CARD_EN(true);
kinetis_pinconfig(GPIO_SD_CARDDETECT);
/* Attached the card detect interrupt (but don't enable it yet) */
kinetis_pinirqattach(GPIO_SD_CARDDETECT, nxphlite_cdinterrupt, sdhc);
/* Configure the write protect GPIO -- None */
/* Mount the SDHC-based MMC/SD block driver */
/* First, get an instance of the SDHC interface */
mcinfo("Initializing SDHC slot %d\n", CONFIG_NSH_MMCSDSLOTNO);
sdhc->sdhc = sdhc_initialize(CONFIG_NSH_MMCSDSLOTNO);
if (!sdhc->sdhc) {
mcerr("ERROR: Failed to initialize SDHC slot %d\n", CONFIG_NSH_MMCSDSLOTNO);
return -ENODEV;
}
/* Now bind the SDHC interface to the MMC/SD driver */
mcinfo("Bind SDHC to the MMC/SD driver, minor=%d\n", CONFIG_NSH_MMCSDMINOR);
ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdhc->sdhc);
if (ret != OK) {
syslog(LOG_ERR, "ERROR: Failed to bind SDHC to the MMC/SD driver: %d\n", ret);
return ret;
}
syslog(LOG_INFO, "Successfully bound SDHC to the MMC/SD driver\n");
/* Handle the initial card state */
nxphlite_mediachange(sdhc);
/* Enable CD interrupts to handle subsequent media changes */
kinetis_pinirqenable(GPIO_SD_CARDDETECT);
return OK;
}
/****************************************************************************
* Name: nxphlite_cardinserted
*
* Description:
* Check if a card is inserted into the SDHC slot
*
****************************************************************************/
#ifdef HAVE_AUTOMOUNTER
bool nxphlite_cardinserted(void)
{
bool inserted;
/* Get the current value of the card detect pin. This pin is pulled up on
* board. So low means that a card is present.
*/
inserted = !kinetis_gpioread(GPIO_SD_CARDDETECT);
mcinfo("inserted: %s\n", inserted ? "Yes" : "No");
return inserted;
}
#endif
/****************************************************************************
* Name: nxphlite_writeprotected
*
* Description:
* Check if a card is inserted into the SDHC slot
*
****************************************************************************/
#ifdef HAVE_AUTOMOUNTER
bool nxphlite_writeprotected(void)
{
/* There are no write protect pins */
return false;
}
#endif
#endif /* HAVE_MMCSD */
+392
View File
@@ -0,0 +1,392 @@
/************************************************************************************
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org>
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************************/
/************************************************************************************
* Included Files
************************************************************************************/
#include <px4_config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
//#include <unistd.h>
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
#include "up_arch.h"
#include "chip.h"
#include <kinetis.h>
#include "board_config.h"
#include <systemlib/err.h>
#include <systemlib/px4_macros.h>
#if defined(CONFIG_KINETIS_SPI0) || defined(CONFIG_KINETIS_SPI1) || \
defined(CONFIG_KINETIS_SPI2)
#ifdef CONFIG_CPP_HAVE_VARARGS
# ifdef CONFIG_DEBUG
# define message(...) syslog(__VA_ARGS__)
# else
# define message(...) printf(__VA_ARGS__)
# endif
#else
# ifdef CONFIG_DEBUG
# define message syslog
# else
# define message printf
# endif
#endif
/* Define CS GPIO array */
static const uint32_t spi0selects_gpio[] = PX4_MEMORY_BUS_CS_GPIO;
static const uint32_t spi1selects_gpio[] = PX4_SENSOR_BUS_CS_GPIO;
static const uint32_t spi2selects_gpio[] = PX4_EXTERNAL_BUS_CS_GPIO;
/************************************************************************************
* Public Functions
************************************************************************************/
__EXPORT void board_spi_reset(int ms)
{
/* Goal not to back feed the chips on the bus via IO lines */
/* First float the A_MISO line tied to SA0 to ensure SPI Auto selection*/
kinetis_pinconfig(PX4_MK_GPIO(PIN_SPI1_SIN, GPIO_OPENDRAIN));
kinetis_gpiowrite(PIN_SPI1_SIN, 1);
/* Next Change CS to inputs with pull downs */
for (unsigned int cs = 0; cs < arraySize(spi1selects_gpio); cs++) {
if (spi1selects_gpio[cs] != 0) {
kinetis_pinconfig(PX4_MK_GPIO(spi1selects_gpio[cs], GPIO_PULLDOWN));
}
}
/* Turn all the int inputs to inputs with pull down */
kinetis_pinconfig(PX4_MK_GPIO(GPIO_EXTI_GYRO_INT1, GPIO_PULLDOWN));
kinetis_pinconfig(PX4_MK_GPIO(GPIO_EXTI_GYRO_INT2, GPIO_PULLDOWN));
kinetis_pinconfig(PX4_MK_GPIO(GPIO_EXTI_ACCEL_MAG_INT1, GPIO_PULLDOWN));
kinetis_pinconfig(PX4_MK_GPIO(GPIO_EXTI_ACCEL_MAG_INT2, GPIO_PULLDOWN));
kinetis_pinconfig(PX4_MK_GPIO(GPIO_EXTI_BARO_INT1, GPIO_PULLDOWN));
kinetis_pinconfig(PX4_MK_GPIO(GPIO_EXTI_BARO_INT2, GPIO_PULLDOWN));
/* Drive the Reset Pins LOW
* For the Gyro FXAS21002C this is RESET
* for the Accel FXOS8700CQ this is not RESET */
kinetis_gpiowrite(GPIO_GM_nRST, false);
kinetis_gpiowrite(GPIO_A_RST, false);
/* Power Down The Sensors */
VDD_3V3_SENSORS_EN(false);
up_mdelay(ms);
/* Power Up The Sensors */
VDD_3V3_SENSORS_EN(true);
up_mdelay(2);
/* Restore all the CS to ouputs inactive */
for (unsigned int cs = 0; cs < arraySize(spi1selects_gpio); cs++) {
if (spi1selects_gpio[cs] != 0) {
kinetis_pinconfig(spi1selects_gpio[cs]);
}
}
/* Restore all the int inputs to inputs */
kinetis_pinconfig(GPIO_EXTI_GYRO_INT1);
kinetis_pinconfig(GPIO_EXTI_GYRO_INT2);
kinetis_pinconfig(GPIO_EXTI_ACCEL_MAG_INT1);
kinetis_pinconfig(GPIO_EXTI_ACCEL_MAG_INT2);
kinetis_pinconfig(GPIO_EXTI_BARO_INT1);
kinetis_pinconfig(GPIO_EXTI_BARO_INT2);
/* Set Rests Active */
/* Accel Assert Reset to reset the FXOS8700CQ */
/* The Gyro was reset above */
kinetis_gpiowrite(GPIO_A_RST, true);
up_mdelay(ms);
/* Accel & Gyro release Reset */
kinetis_gpiowrite(GPIO_A_RST, false);
kinetis_gpiowrite(GPIO_GM_nRST, true);
/* Allow the Accel time to see PIN_SPI1_SIN as a float */
up_mdelay(2);
kinetis_pinconfig(PIN_SPI1_SIN);
}
/************************************************************************************
* Name: nxphlite_spidev_initialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the NXPHlite-v3 board.
*
************************************************************************************/
void nxphlite_spidev_initialize(void)
{
board_spi_reset(10);
for (unsigned int cs = 0; cs < arraySize(spi0selects_gpio); cs++) {
if (spi0selects_gpio[cs] != 0) {
kinetis_pinconfig(spi0selects_gpio[cs]);
}
}
for (unsigned int cs = 0; cs < arraySize(spi1selects_gpio); cs++) {
if (spi1selects_gpio[cs] != 0) {
kinetis_pinconfig(spi1selects_gpio[cs]);
}
}
for (unsigned int cs = 0; cs < arraySize(spi2selects_gpio); cs++) {
if (spi2selects_gpio[cs] != 0) {
kinetis_pinconfig(spi2selects_gpio[cs]);
}
}
}
/************************************************************************************
* Name: kinetis_spi_bus_initialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the NXPHLITEV1 board.
*
************************************************************************************/
static struct spi_dev_s *spi_sensors;
static struct spi_dev_s *spi_memory;
static struct spi_dev_s *spi_ext;
__EXPORT int nxphlite_spi_bus_initialize(void)
{
/* Configure SPI-based devices */
spi_sensors = px4_spibus_initialize(PX4_SPI_BUS_SENSORS);
if (!spi_sensors) {
message("[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_SENSORS);
return -ENODEV;
}
/* Default PX4_SPI_BUS_SENSORS to 1MHz and de-assert the known chip selects.
*/
SPI_SETFREQUENCY(spi_sensors, 1 * 1000 * 1000);
SPI_SETBITS(spi_sensors, 8);
SPI_SETMODE(spi_sensors, SPIDEV_MODE0);
for (int cs = PX4_SENSOR_BUS_FIRST_CS; cs <= PX4_SENSOR_BUS_LAST_CS; cs++) {
SPI_SELECT(spi_sensors, cs, false);
}
/* Get the SPI port for the Memory */
spi_memory = px4_spibus_initialize(PX4_SPI_BUS_MEMORY);
if (!spi_memory) {
message("[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_MEMORY);
return -ENODEV;
}
/* Default PX4_SPI_BUS_MEMORY to 12MHz and de-assert the known chip selects.
*/
SPI_SETFREQUENCY(spi_memory, 12 * 1000 * 1000);
SPI_SETBITS(spi_memory, 8);
SPI_SETMODE(spi_memory, SPIDEV_MODE3);
for (int cs = PX4_MEMORY_BUS_FIRST_CS; cs <= PX4_MEMORY_BUS_LAST_CS; cs++) {
SPI_SELECT(spi_memory, cs, false);
}
/* Configure EXTERNAL SPI-based devices */
spi_ext = px4_spibus_initialize(PX4_SPI_BUS_EXTERNAL);
if (!spi_ext) {
message("[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_EXTERNAL);
return -ENODEV;
}
/* Default PX4_SPI_BUS_SENSORS to 1MHz and de-assert the known chip selects.
*/
SPI_SETFREQUENCY(spi_ext, 8 * 1000 * 1000);
SPI_SETBITS(spi_ext, 8);
SPI_SETMODE(spi_ext, SPIDEV_MODE3);
for (int cs = PX4_EXTERNAL_BUS_FIRST_CS; cs <= PX4_EXTERNAL_BUS_LAST_CS; cs++) {
SPI_SELECT(spi_ext, cs, false);
}
return OK;
}
/************************************************************************************
* Name: kinetis_spi[n]select, kinetis_spi[n]status, and kinetis_spi[n]cmddata
*
* Description:
* These external functions must be provided by board-specific logic. They are
* implementations of the select, status, and cmddata methods of the SPI interface
* defined by struct spi_ops_s (see include/nuttx/spi/spi.h). All other methods
* including kinetis_spibus_initialize()) are provided by common Kinetis logic.
* To use this common SPI logic on your board:
*
* 1. Provide logic in kinetis_boardinitialize() to configure SPI chip select
* pins.
* 2. Provide kinetis_spi[n]select() and kinetis_spi[n]status() functions
* in your board-specific logic. These functions will perform chip selection
* and status operations using GPIOs in the way your board is configured.
* 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide
* kinetis_spi[n]cmddata() functions in your board-specific logic. These
* functions will perform cmd/data selection operations using GPIOs in the way
* your board is configured.
* 3. Add a call to kinetis_spibus_initialize() in your low level application
* initialization logic
* 4. The handle returned by kinetis_spibus_initialize() may then be used to bind the
* SPI driver to higher level logic (e.g., calling
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
* the SPI MMC/SD driver).
*
************************************************************************************/
void kinetis_spi0select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
/* SPI select is active low, so write !selected to select the device */
uint32_t sel = devid;
if (devid == SPIDEV_FLASH(0)) {
sel = PX4_SPIDEV_MEMORY;
}
ASSERT(PX4_SPI_BUS_ID(sel) == PX4_SPI_BUS_MEMORY);
/* Making sure the other peripherals are not selected */
for (unsigned int cs = 0; arraySize(spi0selects_gpio) > 1 && cs < arraySize(spi0selects_gpio); cs++) {
if (spi0selects_gpio[cs] != 0) {
kinetis_gpiowrite(spi0selects_gpio[cs], 1);
}
}
uint32_t gpio = spi0selects_gpio[PX4_SPI_DEV_ID(sel)];
if (gpio) {
kinetis_gpiowrite(gpio, !selected);
}
}
uint8_t kinetis_spi0status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
void kinetis_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
/* SPI select is active low, so write !selected to select the device */
int sel = (int) devid;
ASSERT(PX4_SPI_BUS_ID(sel) == PX4_SPI_BUS_SENSORS);
/* Making sure the other peripherals are not selected */
for (unsigned int cs = 0; arraySize(spi1selects_gpio) > 1 && cs < arraySize(spi1selects_gpio); cs++) {
if (spi1selects_gpio[cs] != 0) {
kinetis_gpiowrite(spi1selects_gpio[cs], 1);
}
}
uint32_t gpio = spi1selects_gpio[PX4_SPI_DEV_ID(sel)];
if (gpio) {
kinetis_gpiowrite(gpio, !selected);
}
}
uint8_t kinetis_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
void kinetis_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
/* SPI select is active low, so write !selected to select the device */
int sel = (int) devid;
ASSERT(PX4_SPI_BUS_ID(sel) == PX4_SPI_BUS_EXTERNAL);
/* Making sure the other peripherals are not selected */
for (unsigned int cs = 0; arraySize(spi2selects_gpio) > 1 && cs < arraySize(spi2selects_gpio); cs++) {
if (spi2selects_gpio[cs] != 0) {
kinetis_gpiowrite(spi2selects_gpio[cs], 1);
}
}
uint32_t gpio = spi2selects_gpio[PX4_SPI_DEV_ID(sel)];
if (gpio) {
kinetis_gpiowrite(gpio, !selected);
}
}
uint8_t kinetis_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif /* CONFIG_KINETIS_SPI0 || CONFIG_KINETIS_SPI1 || CONFIG_KINETIS_SPI2 */
+250
View File
@@ -0,0 +1,250 @@
/****************************************************************************
*
* Copyright (C) 2016 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/*
* @file nxphlite_timer_config.c
*
* Configuration data for the kinetis pwm_servo, input capture and pwm input driver.
*
* Note that these arrays must always be fully-sized.
*/
// TODO:Stubbed out for now
#include <stdint.h>
#include <kinetis.h>
#include "chip/kinetis_sim.h"
#include "chip/kinetis_ftm.h"
#include <drivers/drv_pwm_output.h>
#include <drivers/kinetis/drv_io_timer.h>
#include "board_config.h"
__EXPORT const io_timers_t io_timers[MAX_IO_TIMERS] = {
{
.base = KINETIS_FTM0_BASE,
.clock_register = KINETIS_SIM_SCGC6,
.clock_bit = SIM_SCGC6_FTM0,
.first_channel_index = 0,
.last_channel_index = 3,
.handler = io_timer_handler0,
.vectorno = KINETIS_IRQ_FTM0,
},
{
.base = KINETIS_FTM3_BASE,
.clock_register = KINETIS_SIM_SCGC3,
.clock_bit = SIM_SCGC3_FTM3,
.first_channel_index = 4,
.last_channel_index = 5,
.handler = io_timer_handler1,
.vectorno = KINETIS_IRQ_FTM3,
},
{
.base = KINETIS_FTM2_BASE,
.clock_register = KINETIS_SIM_SCGC3,
.clock_bit = SIM_SCGC3_FTM2,
.first_channel_index = 6,
.last_channel_index = 7,
.handler = io_timer_handler2,
.vectorno = KINETIS_IRQ_FTM2,
}
};
__EXPORT const timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = {
{
.gpio_out = GPIO_FTM0_CH0OUT, // FMU_CH1
.gpio_in = GPIO_FTM0_CH0IN,
.timer_index = 0,
.timer_channel = 1, // physical channel number +1
},
{
.gpio_out = GPIO_FTM0_CH3OUT, // FMU_CH2
.gpio_in = GPIO_FTM0_CH3IN,
.timer_index = 0,
.timer_channel = 4,
},
{
.gpio_out = GPIO_FTM0_CH4OUT, // FMU_CH3
.gpio_in = GPIO_FTM0_CH4IN,
.timer_index = 0,
.timer_channel = 5,
},
{
.gpio_out = GPIO_FTM0_CH5OUT, // FMU_CH4
.gpio_in = GPIO_FTM0_CH5IN,
.timer_index = 0,
.timer_channel = 6,
},
{
.gpio_out = GPIO_FTM3_CH6OUT, // FMU_CH5
.gpio_in = GPIO_FTM3_CH6IN,
.timer_index = 1,
.timer_channel = 7,
},
{
.gpio_out = GPIO_FTM3_CH7OUT, // FMU_CH6
.gpio_in = GPIO_FTM3_CH7IN,
.timer_index = 1,
.timer_channel = 8,
},
{
.gpio_out = GPIO_FTM3_CH0OUT, // U_TRI
.gpio_in = GPIO_FTM3_CH0IN,
.timer_index = 1,
.timer_channel = 1,
},
{
.gpio_out = GPIO_FTM2_CH0OUT,
.gpio_in = GPIO_FTM2_CH0IN, // U_ECH
.timer_index = 2,
.timer_channel = 1,
},
};
__EXPORT const struct io_timers_t led_pwm_timers[MAX_LED_TIMERS] = {
{
.base = KINETIS_FTM3_BASE,
.clock_register = KINETIS_SIM_SCGC3,
.clock_bit = SIM_SCGC3_FTM3,
.first_channel_index = 0,
.last_channel_index = 2,
.vectorno = 0,
},
};
__EXPORT const struct timer_io_channels_t led_pwm_channels[MAX_TIMER_LED_CHANNELS] = {
{
.gpio_out = LED_TIM3_CH5OUT, // RGB_G
.gpio_in = 0,
.timer_index = 0,
.timer_channel = 6,
},
{
.gpio_out = LED_TIM3_CH1OUT, // RGB_R
.gpio_in = 0,
.timer_index = 0,
.timer_channel = 2,
},
{
.gpio_out = LED_TIM3_CH4OUT, // RGB_B
.gpio_in = 0,
.timer_index = 0,
.timer_channel = 5,
},
};
#define _REG(_addr) (*(volatile uint32_t *)(_addr))
/* Timer register accessors */
#define REG(t, _reg) _REG(KINETIS_FTM##t##_BASE + (_reg))
#define rSC(t) REG(t,KINETIS_FTM_SC_OFFSET)
#define rCNT(t) REG(t,KINETIS_FTM_CNT_OFFSET)
#define rMOD(t) REG(t,KINETIS_FTM_MOD_OFFSET)
#define rC0SC(t) REG(t,KINETIS_FTM_C0SC_OFFSET)
#define rC0V(t) REG(t,KINETIS_FTM_C0V_OFFSET)
#define rC1SC(t) REG(t,KINETIS_FTM_C1SC_OFFSET)
#define rC1V(t) REG(t,KINETIS_FTM_C1V_OFFSET)
#define rC2SC(t) REG(t,KINETIS_FTM_C2SC_OFFSET)
#define rC2V(t) REG(t,KINETIS_FTM_C2V_OFFSET)
#define rC3SC(t) REG(t,KINETIS_FTM_C3SC_OFFSET)
#define rC3V(t) REG(t,KINETIS_FTM_C3V_OFFSET)
#define rC4SC(t) REG(t,KINETIS_FTM_C4SC_OFFSET)
#define rC4V(t) REG(t,KINETIS_FTM_C4V_OFFSET)
#define rC5SC(t) REG(t,KINETIS_FTM_C5SC_OFFSET)
#define rC5V(t) REG(t,KINETIS_FTM_C5V_OFFSET)
#define rC6SC(t) REG(t,KINETIS_FTM_C6SC_OFFSET)
#define rC6V(t) REG(t,KINETIS_FTM_C6V_OFFSET)
#define rC7SC(t) REG(t,KINETIS_FTM_C7SC_OFFSET)
#define rC7V(t) REG(t,KINETIS_FTM_C7V_OFFSET)
#define rCNTIN(t) REG(t,KINETIS_FTM_CNTIN_OFFSET)
#define rSTATUS(t) REG(t,KINETIS_FTM_STATUS_OFFSET)
#define rMODE(t) REG(t,KINETIS_FTM_MODE_OFFSET)
#define rSYNC(t) REG(t,KINETIS_FTM_SYNC_OFFSET)
#define rOUTINIT(t) REG(t,KINETIS_FTM_OUTINIT_OFFSET)
#define rOUTMASK(t) REG(t,KINETIS_FTM_OUTMASK_OFFSET)
#define rCOMBINE(t) REG(t,KINETIS_FTM_COMBINE_OFFSET)
#define rDEADTIME(t) REG(t,KINETIS_FTM_DEADTIME_OFFSET)
#define rEXTTRIG(t) REG(t,KINETIS_FTM_EXTTRIG_OFFSET)
#define rPOL(t) REG(t,KINETIS_FTM_POL_OFFSET)
#define rFMS(t) REG(t,KINETIS_FTM_FMS_OFFSET)
#define rFILTER(t) REG(t,KINETIS_FTM_FILTER_OFFSET)
#define rFLTCTRL(t) REG(t,KINETIS_FTM_FLTCTRL_OFFSET)
#define rQDCTRL(t) REG(t,KINETIS_FTM_QDCTRL_OFFSET)
#define rCONF(t) REG(t,KINETIS_FTM_CONF_OFFSET)
#define rFLTPOL(t) REG(t,KINETIS_FTM_FLTPOL_OFFSET)
#define rSYNCONF(t) REG(t,KINETIS_FTM_SYNCONF_OFFSET)
#define rINVCTRL(t) REG(t,KINETIS_FTM_INVCTRL_OFFSET)
#define rSWOCTRL(t) REG(t,KINETIS_FTM_SWOCTRL_OFFSET)
#define rPWMLOAD(t) REG(t,KINETIS_FTM_PWMLOAD_OFFSET)
#if !defined(BOARD_PWM_SRC_CLOCK_FREQ)
#define BOARD_PWM_SRC_CLOCK_FREQ 16000000
#endif
__EXPORT void nxphlite_timer_initialize(void)
{
/* Y1 is 16 Mhz used to driver the FTM_CLKIN0 (PCT12) */
/* Enable PCT12 as FTM_CLKIN0 */
kinetis_pinconfig(PIN_FTM_CLKIN0_3);
/* Select FTM_CLKIN0 as source for FTM0, FTM2, and FTM3 */
uint32_t regval = _REG(KINETIS_SIM_SOPT4);
regval &= ~(SIM_SOPT4_FTM0CLKSEL | SIM_SOPT4_FTM2CLKSEL | SIM_SOPT4_FTM3CLKSEL);
_REG(KINETIS_SIM_SOPT4) = regval;
/* Enabled System Clock Gating Control for FTM 0 and 2*/
regval = _REG(KINETIS_SIM_SCGC6);
regval |= SIM_SCGC6_FTM0 | SIM_SCGC6_FTM2;
_REG(KINETIS_SIM_SCGC6) = regval;
/* Enabled System Clock Gating Control for FTM 2 and 3 */
regval = _REG(KINETIS_SIM_SCGC3);
regval |= SIM_SCGC3_FTM2 | SIM_SCGC3_FTM3;
_REG(KINETIS_SIM_SCGC3) = regval;
}
+113
View File
@@ -0,0 +1,113 @@
/****************************************************************************
*
* Copyright (C) 2016 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file nxphlite_usb.c
*
* Board-specific USB functions.
*/
/************************************************************************************
* Included Files
************************************************************************************/
#include <px4_config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/usb/usbdev.h>
#include <nuttx/usb/usbdev_trace.h>
#include <up_arch.h>
#include <kinetis.h>
#include <kinetis_usbotg.h>
#include "board_config.h"
/************************************************************************************
* Definitions
************************************************************************************/
/************************************************************************************
* Private Functions
************************************************************************************/
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: kinetis_usbpullup
*
* Description:
* If USB is supported and the board supports a pullup via GPIO (for USB software
* connect and disconnect), then the board software must provide kinetis_usbpullup.
* See include/nuttx/usb/usbdev.h for additional description of this method.
* Alternatively, if no pull-up GPIO the following EXTERN can be redefined to be
* NULL.
*
************************************************************************************/
__EXPORT
int kinetis_usbpullup(FAR struct usbdev_s *dev, bool enable)
{
usbtrace(TRACE_DEVPULLUP, (uint16_t)enable);
if (enable) {
putreg8(USB_CONTROL_DPPULLUPNONOTG, KINETIS_USB0_CONTROL);
} else {
putreg8(0, KINETIS_USB0_CONTROL);
}
return OK;
}
/************************************************************************************
* Name: kinetis_usbsuspend
*
* Description:
* Board logic must provide the kinetis_usbsuspend logic if the USBDEV driver is
* used. This function is called whenever the USB enters or leaves suspend mode.
* This is an opportunity for the board logic to shutdown clocks, power, etc.
* while the USB is suspended.
*
************************************************************************************/
__EXPORT
void kinetis_usbsuspend(FAR struct usbdev_s *dev, bool resume)
{
uinfo("resume: %d\n", resume);
}