diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-02-24 09:36:51 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-02-24 09:36:51 +0000 |
commit | 679520b160a61950c5746351ab97632ad48f377b (patch) | |
tree | 3a3ad63b42535211e24e9ab1a25608d82734637c /os/hal/templates | |
parent | 2fe9b90f58e48b68a0598aeb18f70eb434fd25e1 (diff) | |
download | ChibiOS-679520b160a61950c5746351ab97632ad48f377b.tar.gz ChibiOS-679520b160a61950c5746351ab97632ad48f377b.tar.bz2 ChibiOS-679520b160a61950c5746351ab97632ad48f377b.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5309 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/templates')
-rw-r--r-- | os/hal/templates/can_lld.c | 64 | ||||
-rw-r--r-- | os/hal/templates/can_lld.h | 102 | ||||
-rw-r--r-- | os/hal/templates/hal_lld.h | 6 | ||||
-rw-r--r-- | os/hal/templates/mcuconf.h | 29 | ||||
-rw-r--r-- | os/hal/templates/platform.mk | 34 |
5 files changed, 175 insertions, 60 deletions
diff --git a/os/hal/templates/can_lld.c b/os/hal/templates/can_lld.c index 152c14489..1496ea172 100644 --- a/os/hal/templates/can_lld.c +++ b/os/hal/templates/can_lld.c @@ -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) {
-
- return FALSE;
+bool_t can_lld_is_tx_empty(CANDriver *canp, canmbx_t mailbox) {
+
+ 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) {
-
- return FALSE;
+bool_t can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox) {
+
+ 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) {
}
diff --git a/os/hal/templates/can_lld.h b/os/hal/templates/can_lld.h index 91a3ac4b9..c4bf67937 100644 --- a/os/hal/templates/can_lld.h +++ b/os/hal/templates/can_lld.h @@ -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);
diff --git a/os/hal/templates/hal_lld.h b/os/hal/templates/hal_lld.h index c8c0534c3..957d40099 100644 --- a/os/hal/templates/hal_lld.h +++ b/os/hal/templates/hal_lld.h @@ -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. */
diff --git a/os/hal/templates/mcuconf.h b/os/hal/templates/mcuconf.h new file mode 100644 index 000000000..2b437922f --- /dev/null +++ b/os/hal/templates/mcuconf.h @@ -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
diff --git a/os/hal/templates/platform.mk b/os/hal/templates/platform.mk index 6c81166bb..268082a02 100644 --- a/os/hal/templates/platform.mk +++ b/os/hal/templates/platform.mk @@ -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
|