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

This commit is contained in:
gdisirio 2013-02-24 09:36:51 +00:00
parent 2fe9b90f58
commit 679520b160
7 changed files with 353 additions and 150 deletions

View File

@ -39,6 +39,11 @@
/* Driver exported variables. */
/*===========================================================================*/
/** @brief CAN1 driver identifier.*/
#if PLATFORM_CAN_USE_CAN1 || defined(__DOXYGEN__)
CANDriver CAND1;
#endif
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
@ -62,6 +67,10 @@
*/
void can_lld_init(void) {
#if PLATFORM_CAN_USE_CAN1
/* Driver initialization.*/
canObjectInit(&CAND1);
#endif
}
/**
@ -73,6 +82,14 @@ void can_lld_init(void) {
*/
void can_lld_start(CANDriver *canp) {
/* Clock activation.*/
if (canp->state == CAN_STOP) {
#if PLATFORM_CAN_USE_CAN1
if (&CAND1 == canp) {
}
#endif
}
}
/**
@ -90,20 +107,32 @@ void can_lld_stop(CANDriver *canp) {
}
}
/**
* @brief Determines whether a frame can be transmitted.
*
* @param[in] canp pointer to the @p CANDriver object
* @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
*
* @return The queue space availability.
* @retval FALSE no space in the transmit queue.
* @retval TRUE transmit slot available.
*
* @notapi
*/
bool_t can_lld_can_transmit(CANDriver *canp) {
bool_t can_lld_is_tx_empty(CANDriver *canp, canmbx_t mailbox) {
return FALSE;
switch (mailbox) {
case CAN_ANY_MAILBOX:
return FALSE;
case 1:
return FALSE;
case 2:
return FALSE;
case 3:
return FALSE;
default:
return FALSE;
}
}
/**
@ -111,10 +140,13 @@ bool_t can_lld_can_transmit(CANDriver *canp) {
*
* @param[in] canp pointer to the @p CANDriver object
* @param[in] ctfp pointer to the CAN frame to be transmitted
* @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
*
* @notapi
*/
void can_lld_transmit(CANDriver *canp, const CANTxFrame *ctfp) {
void can_lld_transmit(CANDriver *canp,
canmbx_t mailbox,
const CANTxFrame *ctfp) {
}
@ -122,26 +154,40 @@ void can_lld_transmit(CANDriver *canp, const CANTxFrame *ctfp) {
* @brief Determines whether a frame has been received.
*
* @param[in] canp pointer to the @p CANDriver object
* @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
*
* @return The queue space availability.
* @retval FALSE no space in the transmit queue.
* @retval TRUE transmit slot available.
*
* @notapi
*/
bool_t can_lld_can_receive(CANDriver *canp) {
bool_t can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox) {
return FALSE;
switch (mailbox) {
case CAN_ANY_MAILBOX:
return FALSE
case 1:
return FALSE
case 2:
return FALSE
default:
return FALSE;
}
}
/**
* @brief Receives a frame from the input queue.
*
* @param[in] canp pointer to the @p CANDriver object
* @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
* @param[out] crfp pointer to the buffer where the CAN frame is copied
*
* @notapi
*/
void can_lld_receive(CANDriver *canp, CANRxFrame *crfp) {
void can_lld_receive(CANDriver *canp,
canmbx_t mailbox,
CANRxFrame *crfp) {
}

View File

@ -39,12 +39,34 @@
* @brief This switch defines whether the driver implementation supports
* a low power switch mode with automatic an wakeup feature.
*/
#define CAN_SUPPORTS_SLEEP TRUE
#define CAN_SUPPORTS_SLEEP TRUE
/**
* @brief This implementation supports three transmit mailboxes.
*/
#define CAN_TX_MAILBOXES 3
/**
* @brief This implementation supports two receive mailboxes.
*/
#define CAN_RX_MAILBOXES 2
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/**
* @name Configuration options
* @{
*/
/**
* @brief CAN1 driver enable switch.
* @details If set to @p TRUE the support for CAN1 is included.
*/
#if !defined(PLATFORM_CAN_USE_CAN1) || defined(__DOXYGEN__)
#define PLATFORM_CAN_USE_CAN1 FALSE
#endif
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
@ -58,15 +80,14 @@
/*===========================================================================*/
/**
* @brief CAN status flags.
* @brief Type of a transmission mailbox index.
*/
typedef uint32_t canstatus_t;
typedef uint32_t canmbx_t;
/**
* @brief CAN transmission frame.
* @note Accessing the frame data as word16 or word32 is not portable
* because machine data endianness, it can be still useful for a
* quick filling.
* @note Accessing the frame data as word16 or word32 is not portable because
* machine data endianness, it can be still useful for a quick filling.
*/
typedef struct {
struct {
@ -91,9 +112,8 @@ typedef struct {
/**
* @brief CAN received frame.
* @note Accessing the frame data as word16 or word32 is not portable
* because machine data endianness, it can be still useful for a
* quick filling.
* @note Accessing the frame data as word16 or word32 is not portable because
* machine data endianness, it can be still useful for a quick filling.
*/
typedef struct {
struct {
@ -123,6 +143,7 @@ typedef struct {
* @note It could not be present on some architectures.
*/
typedef struct {
uint32_t dummy;
} CANFilter;
/**
@ -132,59 +153,62 @@ typedef struct {
* @note It could be empty on some architectures.
*/
typedef struct {
uint32_t dummy;
} CANConfig;
/**
* @brief Structure representing an CAN driver.
* @note Implementations may extend this structure to contain more,
* architecture dependent, fields.
*/
typedef struct {
/**
* @brief Driver state.
* @brief Driver state.
*/
canstate_t state;
/**
* @brief Current configuration data.
* @brief Current configuration data.
*/
const CANConfig *config;
/**
* @brief Transmission queue semaphore.
* @brief Transmission queue semaphore.
*/
Semaphore txsem;
/**
* @brief Receive queue semaphore.
* @brief Receive queue semaphore.
*/
Semaphore rxsem;
/**
* @brief One or more frames become available.
* @note After broadcasting this event it will not be broadcasted again
* until the received frames queue has been completely emptied. It
* is <b>not</b> broadcasted for each received frame. It is
* responsibility of the application to empty the queue by repeatedly
* invoking @p chReceive() when listening to this event. This behavior
* minimizes the interrupt served by the system because CAN traffic.
* @brief One or more frames become available.
* @note After broadcasting this event it will not be broadcasted again
* until the received frames queue has been completely emptied. It
* is <b>not</b> broadcasted for each received frame. It is
* responsibility of the application to empty the queue by
* repeatedly invoking @p chReceive() when listening to this event.
* This behavior minimizes the interrupt served by the system
* because CAN traffic.
* @note The flags associated to the listeners will indicate which
* receive mailboxes become non-empty.
*/
EventSource rxfull_event;
/**
* @brief One or more transmission slots become available.
* @brief One or more transmission mailbox become available.
* @note The flags associated to the listeners will indicate which
* transmit mailboxes become empty.
*
*/
EventSource txempty_event;
/**
* @brief A CAN bus error happened.
* @brief A CAN bus error happened.
* @note The flags associated to the listeners will indicate the
* error(s) that have occurred.
*/
EventSource error_event;
/**
* @brief Error flags set when an error event is broadcasted.
*/
canstatus_t status;
#if CAN_USE_SLEEP_MODE || defined (__DOXYGEN__)
/**
* @brief Entering sleep state event.
* @brief Entering sleep state event.
*/
EventSource sleep_event;
/**
* @brief Exiting sleep state event.
* @brief Exiting sleep state event.
*/
EventSource wakeup_event;
#endif /* CAN_USE_SLEEP_MODE */
@ -199,16 +223,26 @@ typedef struct {
/* External declarations. */
/*===========================================================================*/
#if PLATFORM_CAN_USE_CAN1 && !defined(__DOXYGEN__)
extern CANDriver CAND1;
#endif
#ifdef __cplusplus
extern "C" {
#endif
void can_lld_init(void);
void can_lld_start(CANDriver *canp);
void can_lld_stop(CANDriver *canp);
bool_t can_lld_can_transmit(CANDriver *canp);
void can_lld_transmit(CANDriver *canp, const CANTxFrame *crfp);
bool_t can_lld_can_receive(CANDriver *canp);
void can_lld_receive(CANDriver *canp, CANRxFrame *ctfp);
bool_t can_lld_is_tx_empty(CANDriver *canp,
canmbx_t mailbox);
void can_lld_transmit(CANDriver *canp,
canmbx_t mailbox,
const CANTxFrame *crfp);
bool_t can_lld_is_rx_nonempty(CANDriver *canp,
canmbx_t mailbox);
void can_lld_receive(CANDriver *canp,
canmbx_t mailbox,
CANRxFrame *ctfp);
#if CAN_USE_SLEEP_MODE
void can_lld_sleep(CANDriver *canp);
void can_lld_wakeup(CANDriver *canp);

View File

@ -50,6 +50,12 @@
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*
* Configuration-related checks.
*/
#if !defined(PLATFORM_MCUCONF)
#error "Using a wrong mcuconf.h file, PLATFORM_MCUCONF not defined"
#endif
/*===========================================================================*/
/* Driver data structures and types. */

View File

@ -0,0 +1,29 @@
/*
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
2011,2012,2013 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Platform drivers configuration.
* The following settings override the default settings present in
* the various device driver implementation headers.
* Note that the settings for each driver only have effect if the whole
* driver is enabled in halconf.h.
*/
#define PLATFORM_MCUCONF

View File

@ -1,20 +1,20 @@
# List of all the template platform files.
PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/templates/hal_lld.c \
${CHIBIOS}/os/hal/platforms/templates/adc_lld.c \
${CHIBIOS}/os/hal/platforms/templates/can_lld.c \
${CHIBIOS}/os/hal/platforms/templates/ext_lld.c \
${CHIBIOS}/os/hal/platforms/templates/gpt_lld.c \
${CHIBIOS}/os/hal/platforms/templates/i2c_lld.c \
${CHIBIOS}/os/hal/platforms/templates/icu_lld.c \
${CHIBIOS}/os/hal/platforms/templates/mac_lld.c \
${CHIBIOS}/os/hal/platforms/templates/pal_lld.c \
${CHIBIOS}/os/hal/platforms/templates/pwm_lld.c \
${CHIBIOS}/os/hal/platforms/templates/rtc_lld.c \
${CHIBIOS}/os/hal/platforms/templates/sdc_lld.c \
${CHIBIOS}/os/hal/platforms/templates/serial_lld.c \
${CHIBIOS}/os/hal/platforms/templates/spi_lld.c \
${CHIBIOS}/os/hal/platforms/templates/uart_lld.c \
${CHIBIOS}/os/hal/platforms/templates/usb_lld.c
PLATFORMSRC = ${CHIBIOS}/os/hal/templates/hal_lld.c \
${CHIBIOS}/os/hal/templates/adc_lld.c \
${CHIBIOS}/os/hal/templates/can_lld.c \
${CHIBIOS}/os/hal/templates/ext_lld.c \
${CHIBIOS}/os/hal/templates/gpt_lld.c \
${CHIBIOS}/os/hal/templates/i2c_lld.c \
${CHIBIOS}/os/hal/templates/icu_lld.c \
${CHIBIOS}/os/hal/templates/mac_lld.c \
${CHIBIOS}/os/hal/templates/pal_lld.c \
${CHIBIOS}/os/hal/templates/pwm_lld.c \
${CHIBIOS}/os/hal/templates/rtc_lld.c \
${CHIBIOS}/os/hal/templates/sdc_lld.c \
${CHIBIOS}/os/hal/templates/serial_lld.c \
${CHIBIOS}/os/hal/templates/spi_lld.c \
${CHIBIOS}/os/hal/templates/uart_lld.c \
${CHIBIOS}/os/hal/templates/usb_lld.c
# Required include directories
PLATFORMINC = ${CHIBIOS}/os/hal/platforms/templates
PLATFORMINC = ${CHIBIOS}/os/hal/templates

View File

@ -1,18 +1,169 @@
# This makefile expects the following variables to be externally
# defined:
# XOPT - Compiler extra options
# XDEFS - Extra definitions
##############################################################################
# Build global options
# NOTE: Can be overridden externally.
#
##############################################################################################
# Compiler options here.
ifeq ($(USE_OPT),)
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
endif
# C specific options here (added to USE_OPT).
ifeq ($(USE_COPT),)
USE_COPT =
endif
# C++ specific options here (added to USE_OPT).
ifeq ($(USE_CPPOPT),)
USE_CPPOPT = -fno-rtti
endif
# Enable this if you want the linker to remove unused code and data
ifeq ($(USE_LINK_GC),)
USE_LINK_GC = yes
endif
# If enabled, this option allows to compile the application in THUMB mode.
ifeq ($(USE_THUMB),)
USE_THUMB = yes
endif
# Enable this if you want to see the full log while compiling.
ifeq ($(USE_VERBOSE_COMPILE),)
USE_VERBOSE_COMPILE = no
endif
#
# Build global options
##############################################################################
##############################################################################
# Architecture or project specific options
#
# Enables the use of FPU on Cortex-M4.
# Enable this if you really want to use the STM FWLib.
ifeq ($(USE_FPU),)
USE_FPU = no
endif
# Enable this if you really want to use the STM FWLib.
ifeq ($(USE_FWLIB),)
USE_FWLIB = no
endif
#
# Architecture or project specific options
##############################################################################
##############################################################################
# Project, sources and paths
#
# Define project name here
PROJECT = ch
# Imported source files and paths
CHIBIOS = ../..
include $(CHIBIOS)/boards/ST_STM32F4_DISCOVERY/board.mk
include $(CHIBIOS)/os/hal/templates/platform.mk
include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F4xx/port.mk
include $(CHIBIOS)/os/kernel/kernel.mk
#include $(CHIBIOS)/test/test.mk
# Define linker script file here
LDSCRIPT= $(PORTLD)/STM32F407xG.ld
#LDSCRIPT= $(PORTLD)/STM32F407xG_CCM.ld
# C sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CSRC = $(PORTSRC) \
$(KERNSRC) \
$(TESTSRC) \
$(HALSRC) \
$(PLATFORMSRC) \
$(BOARDSRC) \
main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CPPSRC =
# C sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
ACSRC =
# C++ sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
ACPPSRC =
# C sources to be compiled in THUMB mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
TCSRC =
# C sources to be compiled in THUMB mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
TCPPSRC =
# List ASM source files here
ASMSRC = $(PORTASM)
INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) \
$(CHIBIOS)/os/various
#
# Project, sources and paths
##############################################################################
##############################################################################
# Compiler settings
#
MCU = cortex-m4
#TRGT = arm-elf-
TRGT = arm-none-eabi-
CC = $(TRGT)gcc
CPPC = $(TRGT)g++
# Enable loading with g++ only if you need C++ runtime support.
# NOTE: You can use C++ even without C++ support if you are careful. C++
# runtime support makes code size explode.
LD = $(TRGT)gcc
#LD = $(TRGT)g++
CP = $(TRGT)objcopy
AS = $(TRGT)gcc -x assembler-with-cpp
OD = $(TRGT)objdump
HEX = $(CP) -O ihex
BIN = $(CP) -O binary
# ARM-specific options here
AOPT =
# THUMB-specific options here
TOPT = -mthumb -DTHUMB
# Define C warning options here
CWARN = -Wall -Wextra -Wstrict-prototypes
# Define C++ warning options here
CPPWARN = -Wall -Wextra
#
# Compiler settings
##############################################################################
##############################################################################
# Start of default section
#
TRGT = mingw32-
CC = $(TRGT)gcc
AS = $(TRGT)gcc -x assembler-with-cpp
# List all default C defines here, like -D_DEBUG=1
DDEFS = -DSIMULATOR
DDEFS =
# List all default ASM defines here, like -D_DEBUG=1
DADEFS =
@ -24,53 +175,24 @@ DINCDIR =
DLIBDIR =
# List all default libraries here
DLIBS = -lws2_32
DLIBS =
#
# End of default section
##############################################################################################
##############################################################################
##############################################################################################
##############################################################################
# Start of user section
#
# Define project name here
PROJECT = ch
# Define linker script file here
LDSCRIPT=
# List all user C define here, like -D_DEBUG=1
UDEFS =
# Define ASM defines here
UADEFS =
# Imported source files
CHIBIOS = ../..
include $(CHIBIOS)/boards/simulator/board.mk
include ${CHIBIOS}/os/hal/hal.mk
include ${CHIBIOS}/os/hal/platforms/templates/platform.mk
include ${CHIBIOS}/os/ports/GCC/SIMIA32/port.mk
include ${CHIBIOS}/os/kernel/kernel.mk
include ${CHIBIOS}/test/test.mk
# List C source files here
SRC = ${PORTSRC} \
${KERNSRC} \
${TESTSRC} \
${HALSRC} \
${PLATFORMSRC} \
$(BOARDSRC) \
main.c
# List ASM source files here
ASRC =
# List all user directories here
UINCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) \
$(CHIBIOS)/os/various
UINCDIR =
# List the user directory to look for the libraries here
ULIBDIR =
@ -78,56 +200,22 @@ ULIBDIR =
# List all user libraries here
ULIBS =
# Define optimisation level here
OPT = $(XOPT)
#
# End of user defines
##############################################################################################
##############################################################################
ifeq ($(USE_FPU),yes)
USE_OPT += -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fsingle-precision-constant
DDEFS += -DCORTEX_USE_FPU=TRUE
else
DDEFS += -DCORTEX_USE_FPU=FALSE
endif
INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
DEFS = $(DDEFS) $(UDEFS) $(XDEFS)
ADEFS = $(DADEFS) $(UADEFS)
OBJS = $(ASRC:.s=.o) $(SRC:.c=.o)
LIBS = $(DLIBS) $(ULIBS)
ifeq ($(USE_FWLIB),yes)
include $(CHIBIOS)/ext/stm32lib/stm32lib.mk
CSRC += $(STM32SRC)
INCDIR += $(STM32INC)
USE_OPT += -DUSE_STDPERIPH_DRIVER
endif
LDFLAGS = -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR)
ASFLAGS = -Wa,-amhls=$(<:.s=.lst) $(ADEFS)
CPFLAGS = $(OPT) -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS)
# Generate dependency information
CPFLAGS += -MD -MP -MF .dep/$(@F).d
#
# makefile rules
#
all: $(OBJS) $(PROJECT).exe
%o : %c
$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@
%o : %s
$(AS) -c $(ASFLAGS) $< -o $@
%exe: $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
clean:
-rm -f $(OBJS)
-rm -f $(PROJECT).exe
-rm -f $(PROJECT).map
-rm -f $(SRC:.c=.c.bak)
-rm -f $(SRC:.c=.lst)
-rm -f $(ASRC:.s=.s.bak)
-rm -f $(ASRC:.s=.lst)
-rm -fR .dep
#
# Include the dependency files, should be the last of the makefile
#
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# *** EOF ***
include $(CHIBIOS)/os/ports/GCC/ARMCMx/rules.mk

View File

@ -29,5 +29,5 @@ int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
exit(0);
return 0;
}