mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
arch/arm/src/xmc4: Add SPI support for Infineon XMC45xx microcontroller
This commit is contained in:
committed by
Gregory Nutt
parent
5d2c226675
commit
3b74f80981
@@ -139,3 +139,7 @@ endif
|
|||||||
ifeq ($(CONFIG_I2C),y)
|
ifeq ($(CONFIG_I2C),y)
|
||||||
CHIP_CSRCS += xmc4_i2c.c
|
CHIP_CSRCS += xmc4_i2c.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_XMC4_USCI_SPI),y)
|
||||||
|
CHIP_CSRCS += xmc4_spi.c
|
||||||
|
endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* arch/arm/src/xmc4/xmc4_spi.h
|
* arch/arm/src/xmc4/xmc4_spi.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -42,11 +42,16 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include "chip/xmc4_spi.h"
|
#include "chip/xmc4_usic.h"
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define XMC4_SPI_MODE0 USIC_BRG_SCLKCFG_NOINVDLY
|
||||||
|
#define XMC4_SPI_MODE1 USIC_BRG_SCLKCFG_NOINVNODLY
|
||||||
|
#define XMC4_SPI_MODE2 USIC_BRG_SCLKCFG_INVDLY
|
||||||
|
#define XMC4_SPI_MODE3 USIC_BRG_SCLKCFG_INVNODLY
|
||||||
|
|
||||||
#ifndef __ASSEMBLY__
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
@@ -59,59 +64,61 @@ extern "C"
|
|||||||
#define EXTERN extern
|
#define EXTERN extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Public Data
|
* Public Data
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
struct spi_dev_s;
|
struct spi_dev_s;
|
||||||
|
enum usic_channel_e;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: xmc4_spibus_initialize
|
* Name: xmc4_spibus_initialize
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Initialize the selected SPI bus
|
* Initialize the selected SPI bus
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameter:
|
||||||
* bus number (for hardware that has mutiple SPI interfaces)
|
* channel number (for hardware that has multiple SPI interfaces)
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Valid SPI device structure reference on succcess; a NULL on failure
|
* Valid SPI device structure reference on success; a NULL on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
FAR struct spi_dev_s *xmc4_spibus_initialize(int bus);
|
FAR struct spi_dev_s *xmc4_spibus_initialize(int channel);
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: xmc4_spi[n]select, xmc4_spi[n]status, and xmc4_spi[n]cmddata
|
* Name: xmc4_spi[n]select, xmc4_spi[n]status, and xmc4_spi[n]cmddata
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* These external functions must be provided by board-specific logic. They are
|
* These external functions must be provided by board-specific logic.
|
||||||
* implementations of the select, status, and cmddata methods of the SPI interface
|
* They are implementations of the select, status, and cmddata methods of
|
||||||
* defined by struct spi_ops_s (see include/nuttx/spi/spi.h). All other methods
|
* SPI interface defined by struct spi_ops_s (see include/nuttx/spi/spi.h).
|
||||||
* including xmc4_spibus_initialize()) are provided by common Kinetis logic. To use
|
* All other methods including xmc4_spibus_initialize()) are provided by
|
||||||
* this common SPI logic on your board:
|
* common XMC4 logic. To use this common SPI logic on your board:
|
||||||
*
|
*
|
||||||
* 1. Provide logic in xmc4_board_initialize() to configure SPI chip select
|
* 1. Provide logic in xmc4_board_initialize() to configure SPI chip
|
||||||
* pins.
|
* select pins.
|
||||||
* 2. Provide xmc4_spi[n]select() and xmc4_spi[n]status() functions
|
* 2. Provide xmc4_spi[n]select() and xmc4_spi[n]status() functions
|
||||||
* in your board-specific logic. These functions will perform chip selection
|
* in your board-specific logic. These functions w/ perform chip
|
||||||
* and status operations using GPIOs in the way your board is configured.
|
* selection and status operations using GPIOs in the way your board
|
||||||
* 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide
|
* is configured.
|
||||||
|
* 3. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide
|
||||||
* xmc4_spi[n]cmddata() functions in your board-specific logic. These
|
* xmc4_spi[n]cmddata() functions in your board-specific logic. These
|
||||||
* functions will perform cmd/data selection operations using GPIOs in the way
|
* functions will perform cmd/data selection operations using GPIOs in
|
||||||
* your board is configured.
|
* the way your board is configured.
|
||||||
* 3. Add a call to xmc4_spibus_initialize() in your low level application
|
* 4. Add a call to xmc4_spibus_initialize() in your low level application
|
||||||
* initialization logic
|
* initialization logic
|
||||||
* 4. The handle returned by xmc4_spibus_initialize() may then be used to bind the
|
* 5. The handle returned by xmc4_spibus_initialize() may then be used to
|
||||||
* SPI driver to higher level logic (e.g., calling
|
* bind the SPI driver to higher level logic (e.g., calling
|
||||||
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
|
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
|
||||||
* the SPI MMC/SD driver).
|
* the SPI MMC/SD driver).
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_XMC4_SPI0
|
#ifdef CONFIG_XMC4_SPI0
|
||||||
void xmc4_spi0select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
|
void xmc4_spi0select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
|
||||||
@@ -120,6 +127,7 @@ uint8_t xmc4_spi0status(FAR struct spi_dev_s *dev, uint32_t devid);
|
|||||||
int xmc4_spi0cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
|
int xmc4_spi0cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_XMC4_SPI1
|
#ifdef CONFIG_XMC4_SPI1
|
||||||
void xmc4_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
|
void xmc4_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
|
||||||
uint8_t xmc4_spi1status(FAR struct spi_dev_s *dev, uint32_t devid);
|
uint8_t xmc4_spi1status(FAR struct spi_dev_s *dev, uint32_t devid);
|
||||||
@@ -127,6 +135,7 @@ uint8_t xmc4_spi1status(FAR struct spi_dev_s *dev, uint32_t devid);
|
|||||||
int xmc4_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
|
int xmc4_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_XMC4_SPI2
|
#ifdef CONFIG_XMC4_SPI2
|
||||||
void xmc4_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
|
void xmc4_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
|
||||||
uint8_t xmc4_spi2status(FAR struct spi_dev_s *dev, uint32_t devid);
|
uint8_t xmc4_spi2status(FAR struct spi_dev_s *dev, uint32_t devid);
|
||||||
@@ -135,11 +144,35 @@ int xmc4_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_XMC4_SPI3
|
||||||
|
void xmc4_spi3select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
|
||||||
|
uint8_t xmc4_spi3status(FAR struct spi_dev_s *dev, uint32_t devid);
|
||||||
|
#ifdef CONFIG_SPI_CMDDATA
|
||||||
|
int xmc4_spi3cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_XMC4_SPI4
|
||||||
|
void xmc4_spi4select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
|
||||||
|
uint8_t xmc4_spi4status(FAR struct spi_dev_s *dev, uint32_t devid);
|
||||||
|
#ifdef CONFIG_SPI_CMDDATA
|
||||||
|
int xmc4_spi4cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_XMC4_SPI5
|
||||||
|
void xmc4_spi5select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
|
||||||
|
uint8_t xmc4_spi5status(FAR struct spi_dev_s *dev, uint32_t devid);
|
||||||
|
#ifdef CONFIG_SPI_CMDDATA
|
||||||
|
int xmc4_spi5cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ssp_flush
|
* Name: spi_flush
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Flush and discard any words left in the RX fifo. This can be called
|
* Flush and discard any words left in the RX FIFO. This can be called
|
||||||
* from spi[n]select after a device is deselected (if you worry about such
|
* from spi[n]select after a device is deselected (if you worry about such
|
||||||
* things).
|
* things).
|
||||||
*
|
*
|
||||||
@@ -155,10 +188,6 @@ int xmc4_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
|
|||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_XMC4_SPI0) || defined(CONFIG_XMC4_SPI1) || defined(CONFIG_XMC4_SPI2)
|
|
||||||
struct spi_dev_s;
|
|
||||||
void spi_flush(FAR struct spi_dev_s *dev);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ASSEMBLY__ */
|
#endif /* __ASSEMBLY__ */
|
||||||
#endif /* __ARCH_ARM_SRC_XMC4_XMC4_SPI_H */
|
#endif /* __ARCH_ARM_SRC_XMC4_XMC4_SPI_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user