arch/arm/src/xmc4: Add SPI support for Infineon XMC45xx microcontroller
This commit is contained in:
parent
5d2c226675
commit
3b74f80981
@ -139,3 +139,7 @@ endif
|
||||
ifeq ($(CONFIG_I2C),y)
|
||||
CHIP_CSRCS += xmc4_i2c.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_XMC4_USCI_SPI),y)
|
||||
CHIP_CSRCS += xmc4_spi.c
|
||||
endif
|
||||
|
2121
arch/arm/src/xmc4/xmc4_spi.c
Normal file
2121
arch/arm/src/xmc4/xmc4_spi.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* 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>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -42,11 +42,16 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include "chip/xmc4_spi.h"
|
||||
#include "chip/xmc4_usic.h"
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* 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__
|
||||
|
||||
@ -59,59 +64,61 @@ extern "C"
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
struct spi_dev_s;
|
||||
enum usic_channel_e;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: xmc4_spibus_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the selected SPI bus
|
||||
*
|
||||
* Input Parameters:
|
||||
* bus number (for hardware that has mutiple SPI interfaces)
|
||||
* Input Parameter:
|
||||
* channel number (for hardware that has multiple SPI interfaces)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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 xmc4_spibus_initialize()) are provided by common Kinetis logic. To use
|
||||
* this common SPI logic on your board:
|
||||
* These external functions must be provided by board-specific logic.
|
||||
* They are implementations of the select, status, and cmddata methods of
|
||||
* SPI interface defined by struct spi_ops_s (see include/nuttx/spi/spi.h).
|
||||
* All other methods including xmc4_spibus_initialize()) are provided by
|
||||
* common XMC4 logic. To use this common SPI logic on your board:
|
||||
*
|
||||
* 1. Provide logic in xmc4_board_initialize() to configure SPI chip select
|
||||
* pins.
|
||||
* 1. Provide logic in xmc4_board_initialize() to configure SPI chip
|
||||
* select pins.
|
||||
* 2. Provide xmc4_spi[n]select() and xmc4_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
|
||||
* in your board-specific logic. These functions w/ perform chip
|
||||
* selection and status operations using GPIOs in the way your board
|
||||
* 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
|
||||
* functions will perform cmd/data selection operations using GPIOs in the way
|
||||
* your board is configured.
|
||||
* 3. Add a call to xmc4_spibus_initialize() in your low level application
|
||||
* functions will perform cmd/data selection operations using GPIOs in
|
||||
* the way your board is configured.
|
||||
* 4. Add a call to xmc4_spibus_initialize() in your low level application
|
||||
* initialization logic
|
||||
* 4. The handle returned by xmc4_spibus_initialize() may then be used to bind the
|
||||
* SPI driver to higher level logic (e.g., calling
|
||||
* 5. The handle returned by xmc4_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).
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_XMC4_SPI0
|
||||
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);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_XMC4_SPI1
|
||||
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);
|
||||
@ -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);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_XMC4_SPI2
|
||||
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);
|
||||
@ -135,11 +144,35 @@ int xmc4_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
|
||||
#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:
|
||||
* 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
|
||||
* things).
|
||||
*
|
||||
@ -155,10 +188,6 @@ int xmc4_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#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 /* __ARCH_ARM_SRC_XMC4_XMC4_SPI_H */
|
||||
|
Loading…
Reference in New Issue
Block a user