git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1251 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2009-10-24 10:09:28 +00:00
parent 09194e6f22
commit fb68f0d517
8 changed files with 82 additions and 27 deletions

View File

@ -68,8 +68,10 @@ CSRC = ${PORTSRC} \
${TESTSRC} \ ${TESTSRC} \
${CHIBIOS}/os/io/pal.c \ ${CHIBIOS}/os/io/pal.c \
${CHIBIOS}/os/io/serial.c \ ${CHIBIOS}/os/io/serial.c \
${CHIBIOS}/os/io/spi.c \
${CHIBIOS}/os/io/platforms/STM32/pal_lld.c \ ${CHIBIOS}/os/io/platforms/STM32/pal_lld.c \
${CHIBIOS}/os/io/platforms/STM32/serial_lld.c \ ${CHIBIOS}/os/io/platforms/STM32/serial_lld.c \
${CHIBIOS}/os/io/platforms/STM32/spi_lld.c \
${CHIBIOS}/os/various/evtimer.c \ ${CHIBIOS}/os/various/evtimer.c \
board.c main.c board.c main.c

View File

@ -24,13 +24,11 @@
* Tricks required to make the TRUE/FALSE declaration inside the library * Tricks required to make the TRUE/FALSE declaration inside the library
* compatible. * compatible.
*/ */
#ifndef __STM32F10x_H
#undef FALSE #undef FALSE
#undef TRUE #undef TRUE
#include <stm32f10x.h> #include <stm32f10x.h>
#define FALSE 0 #define FALSE 0
#define TRUE (!FALSE) #define TRUE (!FALSE)
#endif
/* /*
* Uncomment this if you want a 48MHz system clock, else it will be 72MHz. * Uncomment this if you want a 48MHz system clock, else it will be 72MHz.

View File

@ -27,17 +27,11 @@
#ifndef _PAL_LLD_H_ #ifndef _PAL_LLD_H_
#define _PAL_LLD_H_ #define _PAL_LLD_H_
/*
* Tricks required to make the TRUE/FALSE declaration inside the library
* compatible.
*/
#ifndef __STM32F10x_H
#undef FALSE #undef FALSE
#undef TRUE #undef TRUE
#include <stm32f10x.h> #include <stm32f10x.h>
#define FALSE 0 #define FALSE 0
#define TRUE (!FALSE) #define TRUE (!FALSE)
#endif
/*===========================================================================*/ /*===========================================================================*/
/* I/O Ports Types and constants. */ /* I/O Ports Types and constants. */

View File

@ -27,17 +27,11 @@
#ifndef _SERIAL_LLD_H_ #ifndef _SERIAL_LLD_H_
#define _SERIAL_LLD_H_ #define _SERIAL_LLD_H_
/*
* Tricks required to make the TRUE/FALSE declaration inside the library
* compatible.
*/
#ifndef __STM32F10x_H
#undef FALSE #undef FALSE
#undef TRUE #undef TRUE
#include <stm32f10x.h> #include <stm32f10x.h>
#define FALSE 0 #define FALSE 0
#define TRUE (!FALSE) #define TRUE (!FALSE)
#endif
/*===========================================================================*/ /*===========================================================================*/
/* Driver pre-compile time settings. */ /* Driver pre-compile time settings. */

View File

@ -27,11 +27,41 @@
#include <ch.h> #include <ch.h>
#include <spi.h> #include <spi.h>
#include "nvic.h"
#include "board.h"
#if USE_STM32_SPI1 || defined(__DOXYGEN__)
/** @brief SPI1 driver identifier.*/
SPIDriver SPID1;
#endif
#if USE_STM32_SPI2 || defined(__DOXYGEN__)
/** @brief SPI2 driver identifier.*/
SPIDriver SPID2;
#endif
/** /**
* @brief Low level SPI driver initialization. * @brief Low level SPI driver initialization.
*/ */
void spi_lld_init(void) { void spi_lld_init(void) {
#if USE_STM32_SPI1
spiObjectInit(&SPID1);
SPID1.spd_spi = SPI1;
SPID1.spd_dmarx = DMA1_Channel2;
SPID1.spd_dmatx = DMA1_Channel3;
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
GPIOA->CRH = (GPIOA->CRH & 0x000FFFFF) | 0xB4B00000;
#endif
#if USE_STM32_SPI2
spiObjectInit(&SPID2);
SPID2.spd_spi = SPI2;
SPID2.spd_dmarx = DMA1_Channel4;
SPID2.spd_dmatx = DMA1_Channel5;
RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;
GPIOB->CRL = (GPIOB->CRL & 0x000FFFFF) | 0xB4B00000;
#endif
} }
/** /**

View File

@ -27,19 +27,32 @@
#ifndef _SPI_LLD_H_ #ifndef _SPI_LLD_H_
#define _SPI_LLD_H_ #define _SPI_LLD_H_
#undef FALSE
#undef TRUE
#include <stm32f10x.h>
#define FALSE 0
#define TRUE (!FALSE)
/*===========================================================================*/ /*===========================================================================*/
/* Driver pre-compile time settings. */ /* Driver pre-compile time settings. */
/*===========================================================================*/ /*===========================================================================*/
/** /**
* @brief Enables the mutual exclusion APIs on the SPI bus. * @brief SPI1 driver enable switch.
* @details If set to @p TRUE the support for SPI is included.
* @note The default is @p TRUE.
*/ */
#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) #if !defined(USE_STM32_SPI1) || defined(__DOXYGEN__)
#define SPI_USE_MUTUAL_EXCLUSION TRUE #define USE_STM32_SPI1 TRUE
#endif #endif
#if SPI_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES /**
#error "SPI_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES" * @brief SPI1 driver enable switch.
* @details If set to @p TRUE the support for SPI is included.
* @note The default is @p TRUE.
*/
#if !defined(USE_STM32_SPI2) || defined(__DOXYGEN__)
#define USE_STM32_SPI2 TRUE
#endif #endif
/*===========================================================================*/ /*===========================================================================*/
@ -50,9 +63,9 @@
* @brief Driver state machine possible states. * @brief Driver state machine possible states.
*/ */
typedef enum { typedef enum {
SPI_UNINIT = 0,//!< SPI_UNINIT SPI_UNINIT = 0,
SPI_IDLE = 1, //!< SPI_IDLE SPI_IDLE = 1,
SPI_ACTIVE = 2 //!< SPI_ACTIVE SPI_ACTIVE = 2
} spistate_t; } spistate_t;
/** /**
@ -85,16 +98,28 @@ typedef struct {
#endif #endif
#endif /* SPI_USE_MUTUAL_EXCLUSION */ #endif /* SPI_USE_MUTUAL_EXCLUSION */
/** /**
* Current configuration data. * @brief Current configuration data.
*/ */
const SPIConfig *spd_config; const SPIConfig *spd_config;
/* End of the mandatory fields.*/ /* End of the mandatory fields.*/
SPI_TypeDef *spd_spi;
DMA_Channel_TypeDef *spd_dmarx;
DMA_Channel_TypeDef *spd_dmatx;
} SPIDriver; } SPIDriver;
/*===========================================================================*/ /*===========================================================================*/
/* External declarations. */ /* External declarations. */
/*===========================================================================*/ /*===========================================================================*/
/** @cond never*/
#if USE_STM32_SPI1
extern SPIDriver SPID1;
#endif
#if USE_STM32_SPI2
extern SPIDriver SPID2;
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -106,6 +131,7 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
/** @endcond*/
#endif /* _SPI_LLD_H_ */ #endif /* _SPI_LLD_H_ */

View File

@ -27,6 +27,17 @@
#ifndef _SPI_H_ #ifndef _SPI_H_
#define _SPI_H_ #define _SPI_H_
/**
* @brief Enables the mutual exclusion APIs on the SPI bus.
*/
#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
#define SPI_USE_MUTUAL_EXCLUSION TRUE
#endif
#if SPI_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
#error "SPI_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
#endif
#include "spi_lld.h" #include "spi_lld.h"
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -50,9 +50,9 @@
* @brief Driver state machine possible states. * @brief Driver state machine possible states.
*/ */
typedef enum { typedef enum {
SPI_UNINIT = 0,//!< SPI_UNINIT SPI_UNINIT = 0,
SPI_IDLE = 1, //!< SPI_IDLE SPI_IDLE = 1,
SPI_ACTIVE = 2 //!< SPI_ACTIVE SPI_ACTIVE = 2
} spistate_t; } spistate_t;
/** /**
@ -85,7 +85,7 @@ typedef struct {
#endif #endif
#endif /* SPI_USE_MUTUAL_EXCLUSION */ #endif /* SPI_USE_MUTUAL_EXCLUSION */
/** /**
* Current configuration data. * @brief Current configuration data.
*/ */
const SPIConfig *spd_config; const SPIConfig *spd_config;
/* End of the mandatory fields.*/ /* End of the mandatory fields.*/