From 99563ecc3d5290e1d09b0698ce1ad6196a05fef4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 29 Dec 2009 11:40:09 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1474 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/AT91SAM7/at91sam7_mii.c | 20 ++++++ os/hal/platforms/AT91SAM7/at91sam7_mii.h | 16 +++-- os/hal/platforms/AT91SAM7/hal_lld.c | 10 +-- os/hal/platforms/AT91SAM7/hal_lld.h | 8 +++ os/hal/platforms/AT91SAM7/mac_lld.c | 56 ++++++++++----- os/hal/platforms/AT91SAM7/mac_lld.h | 86 +++++++++++++----------- os/hal/platforms/AT91SAM7/pal_lld.c | 20 ++++++ os/hal/platforms/AT91SAM7/serial_lld.c | 14 +++- os/hal/platforms/AT91SAM7/serial_lld.h | 10 ++- 9 files changed, 168 insertions(+), 72 deletions(-) diff --git a/os/hal/platforms/AT91SAM7/at91sam7_mii.c b/os/hal/platforms/AT91SAM7/at91sam7_mii.c index f390d3e23..8637f5b0c 100644 --- a/os/hal/platforms/AT91SAM7/at91sam7_mii.c +++ b/os/hal/platforms/AT91SAM7/at91sam7_mii.c @@ -30,6 +30,26 @@ #if CH_HAL_USE_MAC || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief Low level MII driver initialization. */ diff --git a/os/hal/platforms/AT91SAM7/at91sam7_mii.h b/os/hal/platforms/AT91SAM7/at91sam7_mii.h index 23dfa70ae..be37a21f1 100644 --- a/os/hal/platforms/AT91SAM7/at91sam7_mii.h +++ b/os/hal/platforms/AT91SAM7/at91sam7_mii.h @@ -29,6 +29,13 @@ #if CH_HAL_USE_MAC || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +#define PHY_MICREL_KS8721 0 +#define PHY_DAVICOM_9161 1 + /*===========================================================================*/ /* Driver pre-compile time settings. */ /*===========================================================================*/ @@ -41,12 +48,9 @@ #endif /*===========================================================================*/ -/* PHY specific constants. */ +/* Derived constants and error checks. */ /*===========================================================================*/ -#define PHY_MICREL_KS8721 0 -#define PHY_DAVICOM_9161 1 - /** * @brief Pins latched by the PHY at reset. */ @@ -83,6 +87,10 @@ typedef uint16_t phyreg_t; */ typedef uint8_t phyaddr_t; +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ diff --git a/os/hal/platforms/AT91SAM7/hal_lld.c b/os/hal/platforms/AT91SAM7/hal_lld.c index 5a3859ed1..3b23b4f74 100644 --- a/os/hal/platforms/AT91SAM7/hal_lld.c +++ b/os/hal/platforms/AT91SAM7/hal_lld.c @@ -28,11 +28,11 @@ #include "hal.h" /*===========================================================================*/ -/* Low Level Driver exported variables. */ +/* Driver exported variables. */ /*===========================================================================*/ /*===========================================================================*/ -/* Low Level Driver local variables. */ +/* Driver local variables. */ /*===========================================================================*/ /** @@ -49,11 +49,11 @@ const AT91SAM7PIOConfig pal_default_config = }; /*===========================================================================*/ -/* Low Level Driver local functions. */ +/* Driver local functions. */ /*===========================================================================*/ /*===========================================================================*/ -/* Low Level Driver interrupt handlers. */ +/* Driver interrupt handlers. */ /*===========================================================================*/ static CH_IRQ_HANDLER(spurious_handler) { @@ -68,7 +68,7 @@ static CH_IRQ_HANDLER(spurious_handler) { } /*===========================================================================*/ -/* Low Level Driver exported functions. */ +/* Driver exported functions. */ /*===========================================================================*/ /** diff --git a/os/hal/platforms/AT91SAM7/hal_lld.h b/os/hal/platforms/AT91SAM7/hal_lld.h index a328dfdf6..958353702 100644 --- a/os/hal/platforms/AT91SAM7/hal_lld.h +++ b/os/hal/platforms/AT91SAM7/hal_lld.h @@ -52,10 +52,18 @@ #define AT91SAM7_USBDIV AT91C_CKGR_USBDIV_1 #endif +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ diff --git a/os/hal/platforms/AT91SAM7/mac_lld.c b/os/hal/platforms/AT91SAM7/mac_lld.c index 9cd4ad4fe..9517c4838 100644 --- a/os/hal/platforms/AT91SAM7/mac_lld.c +++ b/os/hal/platforms/AT91SAM7/mac_lld.c @@ -33,11 +33,6 @@ #if CH_HAL_USE_MAC || defined(__DOXYGEN__) -/** - * @brief Ethernet driver 1. - */ -MACDriver ETH1; - #define EMAC_PIN_MASK (AT91C_PB0_ETXCK_EREFCK | AT91C_PB1_ETXEN | \ AT91C_PB2_ETX0 | AT91C_PB3_ETX1 | \ AT91C_PB4_ECRS | AT91C_PB5_ERX0 | \ @@ -53,6 +48,19 @@ MACDriver ETH1; #define TSR_BITS (AT91C_EMAC_UBR | AT91C_EMAC_COL | AT91C_EMAC_RLES | \ AT91C_EMAC_BEX | AT91C_EMAC_COMP | AT91C_EMAC_UND) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/** + * @brief Ethernet driver 1. + */ +MACDriver ETH1; + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + #ifndef __DOXYGEN__ static bool_t link_up; @@ -70,6 +78,10 @@ static uint8_t tb[EMAC_TRANSMIT_DESCRIPTORS * EMAC_TRANSMIT_BUFFERS_SIZE] __attribute__((aligned(8))); #endif +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + /** * @brief IRQ handler. */ @@ -107,6 +119,23 @@ static void serve_interrupt(void) { AT91C_BASE_AIC->AIC_EOICR = 0; } +/** + * @brief Cleans an incomplete frame. + * @param from the start position of the incomplete frame + */ +static void cleanup(EMACDescriptor *from) { + + while (from != rxptr) { + from->w1 &= ~W1_R_OWNERSHIP; + if (++from >= &rd[EMAC_RECEIVE_DESCRIPTORS]) + from = rd; + } +} + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + /** * @brief EMAC IRQ veneer handler. */ @@ -119,6 +148,10 @@ CH_IRQ_HANDLER(irq_handler) { CH_IRQ_EPILOGUE(); } +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief Low level MAC initialization. */ @@ -295,19 +328,6 @@ void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp) { chSysUnlock(); } -/** - * @brief Cleans an incomplete frame. - * @param from the start position of the incomplete frame - */ -static void cleanup(EMACDescriptor *from) { - - while (from != rxptr) { - from->w1 &= ~W1_R_OWNERSHIP; - if (++from >= &rd[EMAC_RECEIVE_DESCRIPTORS]) - from = rd; - } -} - /** * @brief Returns a receive descriptor. * diff --git a/os/hal/platforms/AT91SAM7/mac_lld.h b/os/hal/platforms/AT91SAM7/mac_lld.h index 23139e989..ea52c4560 100644 --- a/os/hal/platforms/AT91SAM7/mac_lld.h +++ b/os/hal/platforms/AT91SAM7/mac_lld.h @@ -30,47 +30,7 @@ #if CH_HAL_USE_MAC || defined(__DOXYGEN__) /*===========================================================================*/ -/* Driver pre-compile time settings. */ -/*===========================================================================*/ - -/** - * @brief Number of available transmit buffers. - */ -#if !defined(MAC_TRANSMIT_BUFFERS) || defined(__DOXYGEN__) -#define MAC_TRANSMIT_BUFFERS 2 -#endif - -/** - * @brief Number of available receive buffers. - */ -#if !defined(MAC_RECEIVE_BUFFERS) || defined(__DOXYGEN__) -#define MAC_RECEIVE_BUFFERS 2 -#endif - -/** - * @brief Maximum supported frame size. - */ -#if !defined(MAC_BUFFERS_SIZE) || defined(__DOXYGEN__) -#define MAC_BUFFERS_SIZE 1518 -#endif - -/** - * @brief Interrupt priority level for the EMAC device. - */ -#if !defined(EMAC_INTERRUPT_PRIORITY) || defined(__DOXYGEN__) -#define EMAC_INTERRUPT_PRIORITY (AT91C_AIC_PRIOR_HIGHEST - 3) -#endif - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -#if !CH_USE_SEMAPHORES || !CH_USE_EVENTS -#error "the MAC driver requires CH_USE_SEMAPHORES and CH_USE_EVENTS" -#endif - -/*===========================================================================*/ -/* EMAC specific constants. */ +/* Driver constants. */ /*===========================================================================*/ #define EMAC_RECEIVE_BUFFERS_SIZE 128 /* Do not modify */ @@ -116,6 +76,46 @@ #define W2_T_WRAP 0x40000000 #define W2_T_USED 0x80000000 +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/** + * @brief Number of available transmit buffers. + */ +#if !defined(MAC_TRANSMIT_BUFFERS) || defined(__DOXYGEN__) +#define MAC_TRANSMIT_BUFFERS 2 +#endif + +/** + * @brief Number of available receive buffers. + */ +#if !defined(MAC_RECEIVE_BUFFERS) || defined(__DOXYGEN__) +#define MAC_RECEIVE_BUFFERS 2 +#endif + +/** + * @brief Maximum supported frame size. + */ +#if !defined(MAC_BUFFERS_SIZE) || defined(__DOXYGEN__) +#define MAC_BUFFERS_SIZE 1518 +#endif + +/** + * @brief Interrupt priority level for the EMAC device. + */ +#if !defined(EMAC_INTERRUPT_PRIORITY) || defined(__DOXYGEN__) +#define EMAC_INTERRUPT_PRIORITY (AT91C_AIC_PRIOR_HIGHEST - 3) +#endif + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +#if !CH_USE_SEMAPHORES || !CH_USE_EVENTS +#error "the MAC driver requires CH_USE_SEMAPHORES and CH_USE_EVENTS" +#endif + /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ @@ -163,6 +163,10 @@ typedef struct { of the buffers chain. */ } MACReceiveDescriptor; +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ diff --git a/os/hal/platforms/AT91SAM7/pal_lld.c b/os/hal/platforms/AT91SAM7/pal_lld.c index 7cc03b925..60fbb9899 100644 --- a/os/hal/platforms/AT91SAM7/pal_lld.c +++ b/os/hal/platforms/AT91SAM7/pal_lld.c @@ -29,6 +29,26 @@ #if CH_HAL_USE_PAL || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief AT91SAM7 I/O ports configuration. * @details PIO registers initialization. diff --git a/os/hal/platforms/AT91SAM7/serial_lld.c b/os/hal/platforms/AT91SAM7/serial_lld.c index 4b69fc798..be28045fc 100644 --- a/os/hal/platforms/AT91SAM7/serial_lld.c +++ b/os/hal/platforms/AT91SAM7/serial_lld.c @@ -47,6 +47,10 @@ #error "serial lines not defined for this SAM7 version" #endif +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + #if USE_SAM7_USART0 || defined(__DOXYGEN__) /** @brief USART0 serial driver identifier.*/ SerialDriver SD1; @@ -57,6 +61,10 @@ SerialDriver SD1; SerialDriver SD2; #endif +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + /** @brief Driver default configuration.*/ static const SerialDriverConfig default_config = { 38400, @@ -65,7 +73,7 @@ static const SerialDriverConfig default_config = { }; /*===========================================================================*/ -/* Low Level Driver local functions. */ +/* Driver local functions. */ /*===========================================================================*/ /** @@ -175,7 +183,7 @@ static void notify2(void) { #endif /*===========================================================================*/ -/* Low Level Driver interrupt handlers. */ +/* Driver interrupt handlers. */ /*===========================================================================*/ #if USE_SAM7_USART0 || defined(__DOXYGEN__) @@ -201,7 +209,7 @@ CH_IRQ_HANDLER(USART1IrqHandler) { #endif /*===========================================================================*/ -/* Low Level Driver exported functions. */ +/* Driver exported functions. */ /*===========================================================================*/ /** diff --git a/os/hal/platforms/AT91SAM7/serial_lld.h b/os/hal/platforms/AT91SAM7/serial_lld.h index 36984d1b2..b5394aeed 100644 --- a/os/hal/platforms/AT91SAM7/serial_lld.h +++ b/os/hal/platforms/AT91SAM7/serial_lld.h @@ -29,6 +29,10 @@ #if CH_HAL_USE_SERIAL || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver pre-compile time settings. */ /*===========================================================================*/ @@ -76,7 +80,7 @@ #endif /*===========================================================================*/ -/* Unsupported event flags and custom events. */ +/* Derived constants and error checks. */ /*===========================================================================*/ /*===========================================================================*/ @@ -131,6 +135,10 @@ typedef struct { uint32_t mr; } SerialDriverConfig; +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/