git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@729 35acf78f-673a-0410-8e92-d51de3d6d3f4
parent
77df449498
commit
0ed5d7e2e0
|
@ -155,7 +155,7 @@ void hwinit1(void) {
|
||||||
/*
|
/*
|
||||||
* Serial driver initialization, RTS/CTS pins enabled for USART0 only.
|
* Serial driver initialization, RTS/CTS pins enabled for USART0 only.
|
||||||
*/
|
*/
|
||||||
InitSerial(AT91C_AIC_PRIOR_HIGHEST - 2, AT91C_AIC_PRIOR_HIGHEST - 2);
|
sam7x_serial_init(AT91C_AIC_PRIOR_HIGHEST - 2, AT91C_AIC_PRIOR_HIGHEST - 2);
|
||||||
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA3_RTS0 | AT91C_PA4_CTS0;
|
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA3_RTS0 | AT91C_PA4_CTS0;
|
||||||
AT91C_BASE_PIOA->PIO_ASR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
|
AT91C_BASE_PIOA->PIO_ASR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
|
||||||
AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
|
AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
|
||||||
|
|
|
@ -156,7 +156,7 @@ void hwinit1(void) {
|
||||||
/*
|
/*
|
||||||
* Serial driver initialization, RTS/CTS pins enabled for USART0 only.
|
* Serial driver initialization, RTS/CTS pins enabled for USART0 only.
|
||||||
*/
|
*/
|
||||||
InitSerial(AT91C_AIC_PRIOR_HIGHEST - 2, AT91C_AIC_PRIOR_HIGHEST - 2);
|
sam7x_serial_init(AT91C_AIC_PRIOR_HIGHEST - 2, AT91C_AIC_PRIOR_HIGHEST - 2);
|
||||||
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA3_RTS0 | AT91C_PA4_CTS0;
|
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA3_RTS0 | AT91C_PA4_CTS0;
|
||||||
AT91C_BASE_PIOA->PIO_ASR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
|
AT91C_BASE_PIOA->PIO_ASR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
|
||||||
AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
|
AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
|
||||||
|
@ -164,7 +164,7 @@ void hwinit1(void) {
|
||||||
/*
|
/*
|
||||||
* EMAC driver initialization.
|
* EMAC driver initialization.
|
||||||
*/
|
*/
|
||||||
InitEMAC(AT91C_AIC_PRIOR_HIGHEST - 3);
|
sam7x_emac_init(AT91C_AIC_PRIOR_HIGHEST - 3);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ChibiOS/RT initialization.
|
* ChibiOS/RT initialization.
|
||||||
|
|
|
@ -21,3 +21,12 @@
|
||||||
* @ingroup AT91SAM7X
|
* @ingroup AT91SAM7X
|
||||||
*/
|
*/
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup AT91SAM7X_EMAC EMAC Support
|
||||||
|
* @{
|
||||||
|
* @brief EMAC peripheral support.
|
||||||
|
*
|
||||||
|
* @ingroup AT91SAM7X
|
||||||
|
*/
|
||||||
|
/** @} */
|
||||||
|
|
|
@ -17,6 +17,13 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file ports/ARM7-AT91SAM7X/sam7x_emac.c
|
||||||
|
* @brief AT91SAM7X EMAC driver code.
|
||||||
|
* @addtogroup AT91SAM7X_EMAC
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <ch.h>
|
#include <ch.h>
|
||||||
|
@ -26,13 +33,10 @@
|
||||||
#include "mii.h"
|
#include "mii.h"
|
||||||
#include "at91lib/aic.h"
|
#include "at91lib/aic.h"
|
||||||
|
|
||||||
#define EMAC_RECEIVE_BUFFERS 24
|
|
||||||
#define EMAC_RECEIVE_BUFFERS_SIZE 128
|
|
||||||
#define EMAC_TRANSMIT_BUFFERS 2
|
|
||||||
#define EMAC_TRANSMIT_BUFFERS_SIZE 1518
|
|
||||||
|
|
||||||
EventSource EMACFrameTransmitted; /* A frame was transmitted. */
|
EventSource EMACFrameTransmitted; /* A frame was transmitted. */
|
||||||
EventSource EMACFrameReceived; /* A frame was received. */
|
EventSource EMACFrameReceived; /* A frame was received. */
|
||||||
|
|
||||||
|
#ifndef __DOXYGEN__
|
||||||
//static int received; /* Buffered frames counter. */
|
//static int received; /* Buffered frames counter. */
|
||||||
static bool_t link_up; /* Last from EMACGetLinkStatus()*/
|
static bool_t link_up; /* Last from EMACGetLinkStatus()*/
|
||||||
|
|
||||||
|
@ -45,8 +49,8 @@ static BufDescriptorEntry *rxptr;
|
||||||
static BufDescriptorEntry tent[EMAC_TRANSMIT_BUFFERS] __attribute__((aligned(8)));
|
static BufDescriptorEntry tent[EMAC_TRANSMIT_BUFFERS] __attribute__((aligned(8)));
|
||||||
static uint8_t tbuffers[EMAC_TRANSMIT_BUFFERS * EMAC_TRANSMIT_BUFFERS_SIZE] __attribute__((aligned(8)));
|
static uint8_t tbuffers[EMAC_TRANSMIT_BUFFERS * EMAC_TRANSMIT_BUFFERS_SIZE] __attribute__((aligned(8)));
|
||||||
static BufDescriptorEntry *txptr;
|
static BufDescriptorEntry *txptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
#define PHY_ADDRESS 1
|
|
||||||
#define AT91C_PB15_ERXDV AT91C_PB15_ERXDV_ECRSDV
|
#define AT91C_PB15_ERXDV AT91C_PB15_ERXDV_ECRSDV
|
||||||
#define EMAC_PIN_MASK (AT91C_PB0_ETXCK_EREFCK | \
|
#define EMAC_PIN_MASK (AT91C_PB0_ETXCK_EREFCK | \
|
||||||
AT91C_PB1_ETXEN | AT91C_PB2_ETX0 | \
|
AT91C_PB1_ETXEN | AT91C_PB2_ETX0 | \
|
||||||
|
@ -136,7 +140,7 @@ CH_IRQ_HANDLER(EMACIrqHandler) {
|
||||||
/*
|
/*
|
||||||
* EMAC subsystem initialization.
|
* EMAC subsystem initialization.
|
||||||
*/
|
*/
|
||||||
void InitEMAC(int prio) {
|
void sam7x_emac_init(int prio) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -408,3 +412,5 @@ restart:
|
||||||
*sizep = size;
|
*sizep = size;
|
||||||
return found && !overflow;
|
return found && !overflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
|
@ -17,9 +17,23 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file ports/ARM7-AT91SAM7X/sam7x_emac.h
|
||||||
|
* @brief AT91SAM7X EMAC driver macros and structures.
|
||||||
|
* @addtogroup AT91SAM7X_EMAC
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef _SAM7X_EMAC_H_
|
#ifndef _SAM7X_EMAC_H_
|
||||||
#define _SAM7X_EMAC_H_
|
#define _SAM7X_EMAC_H_
|
||||||
|
|
||||||
|
#define PHY_ADDRESS 1
|
||||||
|
|
||||||
|
#define EMAC_RECEIVE_BUFFERS 24
|
||||||
|
#define EMAC_RECEIVE_BUFFERS_SIZE 128
|
||||||
|
#define EMAC_TRANSMIT_BUFFERS 2
|
||||||
|
#define EMAC_TRANSMIT_BUFFERS_SIZE 1518
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t w1;
|
uint32_t w1;
|
||||||
uint32_t w2;
|
uint32_t w2;
|
||||||
|
@ -62,7 +76,7 @@ typedef struct {
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
void InitEMAC(int prio);
|
void sam7x_emac_init(int prio);
|
||||||
void EMACSetAddress(const uint8_t *eaddr);
|
void EMACSetAddress(const uint8_t *eaddr);
|
||||||
bool_t EMACGetLinkStatus(void);
|
bool_t EMACGetLinkStatus(void);
|
||||||
BufDescriptorEntry *EMACGetTransmitBuffer(void);
|
BufDescriptorEntry *EMACGetTransmitBuffer(void);
|
||||||
|
@ -75,3 +89,5 @@ extern "C" {
|
||||||
extern EventSource EMACFrameTransmitted, EMACFrameReceived;
|
extern EventSource EMACFrameTransmitted, EMACFrameReceived;
|
||||||
|
|
||||||
#endif /* _SAM7X_EMAC_H_ */
|
#endif /* _SAM7X_EMAC_H_ */
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
|
@ -125,9 +125,13 @@ static void OutNotify2(void) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* USART setup, must be invoked with interrupts disabled.
|
* @brief UART setup.
|
||||||
* NOTE: Does not reset I/O queues.
|
* @param[in] u pointer to an UART I/O block
|
||||||
|
* @param[in] speed serial port speed in bits per second
|
||||||
|
* @param[in] mode mode flags
|
||||||
|
* @note Must be invoked with interrupts disabled.
|
||||||
|
* @note Does not reset the I/O queues.
|
||||||
*/
|
*/
|
||||||
void SetUSART(AT91PS_USART u, int speed, int mode) {
|
void SetUSART(AT91PS_USART u, int speed, int mode) {
|
||||||
|
|
||||||
|
@ -150,50 +154,69 @@ void SetUSART(AT91PS_USART u, int speed, int mode) {
|
||||||
AT91C_US_RXBRK;
|
AT91C_US_RXBRK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Serial subsystem initialization.
|
* @brief Serial driver initialization.
|
||||||
* NOTE: Handshake pins are not switched to their function because they may have
|
* @param[in] prio0 priority to be assigned to the USART1 IRQ
|
||||||
* another use. Enable them externally if needed.
|
* @param[in] prio1 priority to be assigned to the USART2 IRQ
|
||||||
|
* @note Handshake pads are not enabled inside this function because they
|
||||||
|
* may have another use, enable them externally if needed.
|
||||||
|
* RX and TX pads are handled inside.
|
||||||
*/
|
*/
|
||||||
void InitSerial(int prio0, int prio1) {
|
void sam7x_serial_init(int prio0, int prio1) {
|
||||||
|
|
||||||
/* I/O queues setup.*/
|
#if USE_SAM7X_USART0 || defined(__DOXYGEN__)
|
||||||
|
/* I/O queue setup.*/
|
||||||
chFDDInit(&COM1, ib1, sizeof ib1, NULL, ob1, sizeof ob1, OutNotify1);
|
chFDDInit(&COM1, ib1, sizeof ib1, NULL, ob1, sizeof ob1, OutNotify1);
|
||||||
chFDDInit(&COM2, ib2, sizeof ib2, NULL, ob2, sizeof ob2, OutNotify2);
|
|
||||||
|
|
||||||
/* Switches the I/O pins to the peripheral function A, disables pullups.*/
|
/* Switches the I/O pins to the peripheral function A, disables pullups.*/
|
||||||
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA0_RXD0 | AT91C_PA1_TXD0 |
|
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA0_RXD0 | AT91C_PA1_TXD0;
|
||||||
AT91C_PA5_RXD1 | AT91C_PA6_TXD1;
|
AT91C_BASE_PIOA->PIO_ASR = AT91C_PIO_PA0 | AT91C_PIO_PA1;
|
||||||
AT91C_BASE_PIOA->PIO_ASR = AT91C_PIO_PA0 | AT91C_PIO_PA1 |
|
AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA0 | AT91C_PIO_PA1;
|
||||||
AT91C_PIO_PA5 | AT91C_PIO_PA6;
|
|
||||||
AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA0 | AT91C_PIO_PA1 |
|
|
||||||
AT91C_PIO_PA5 | AT91C_PIO_PA6;
|
|
||||||
|
|
||||||
/* Starts the clock and clears possible sources of immediate interrupts.*/
|
/* Starts the clock and clears possible sources of immediate interrupts.*/
|
||||||
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_US0) | (1 << AT91C_ID_US1);
|
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_US0);
|
||||||
AT91C_BASE_US0->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RSTSTA;
|
AT91C_BASE_US0->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RSTSTA;
|
||||||
AT91C_BASE_US1->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RSTSTA;
|
|
||||||
|
|
||||||
/* Interrupts setup.*/
|
/* Interrupts setup.*/
|
||||||
AIC_ConfigureIT(AT91C_ID_US0,
|
AIC_ConfigureIT(AT91C_ID_US0,
|
||||||
AT91C_AIC_SRCTYPE_HIGH_LEVEL | prio0,
|
AT91C_AIC_SRCTYPE_HIGH_LEVEL | prio0,
|
||||||
USART0IrqHandler);
|
USART0IrqHandler);
|
||||||
AIC_EnableIT(AT91C_ID_US0);
|
AIC_EnableIT(AT91C_ID_US0);
|
||||||
|
|
||||||
|
/* Default parameters.*/
|
||||||
|
SetUSART(AT91C_BASE_US0, SAM7X_USART_BITRATE, AT91C_US_USMODE_NORMAL |
|
||||||
|
AT91C_US_CLKS_CLOCK |
|
||||||
|
AT91C_US_CHRL_8_BITS |
|
||||||
|
AT91C_US_PAR_NONE |
|
||||||
|
AT91C_US_NBSTOP_1_BIT);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if USE_SAM7X_USART1 || defined(__DOXYGEN__)
|
||||||
|
/* I/O queues setup.*/
|
||||||
|
chFDDInit(&COM2, ib2, sizeof ib2, NULL, ob2, sizeof ob2, OutNotify2);
|
||||||
|
|
||||||
|
/* Switches the I/O pins to the peripheral function A, disables pullups.*/
|
||||||
|
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA5_RXD1 | AT91C_PA6_TXD1;
|
||||||
|
AT91C_BASE_PIOA->PIO_ASR = AT91C_PIO_PA5 | AT91C_PIO_PA6;
|
||||||
|
AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA5 | AT91C_PIO_PA6;
|
||||||
|
|
||||||
|
/* Starts the clock and clears possible sources of immediate interrupts.*/
|
||||||
|
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_US1);
|
||||||
|
AT91C_BASE_US1->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RSTSTA;
|
||||||
|
|
||||||
|
/* Interrupts setup.*/
|
||||||
AIC_ConfigureIT(AT91C_ID_US1,
|
AIC_ConfigureIT(AT91C_ID_US1,
|
||||||
AT91C_AIC_SRCTYPE_HIGH_LEVEL | prio1,
|
AT91C_AIC_SRCTYPE_HIGH_LEVEL | prio1,
|
||||||
USART1IrqHandler);
|
USART1IrqHandler);
|
||||||
AIC_EnableIT(AT91C_ID_US1);
|
AIC_EnableIT(AT91C_ID_US1);
|
||||||
|
|
||||||
SetUSART(AT91C_BASE_US0, 38400, AT91C_US_USMODE_NORMAL |
|
/* Default parameters.*/
|
||||||
AT91C_US_CLKS_CLOCK |
|
SetUSART(AT91C_BASE_US1, SAM7X_USART_BITRATE, AT91C_US_USMODE_NORMAL |
|
||||||
AT91C_US_CHRL_8_BITS |
|
|
||||||
AT91C_US_PAR_NONE |
|
|
||||||
AT91C_US_NBSTOP_1_BIT);
|
|
||||||
SetUSART(AT91C_BASE_US1, 38400, AT91C_US_USMODE_NORMAL |
|
|
||||||
AT91C_US_CLKS_CLOCK |
|
AT91C_US_CLKS_CLOCK |
|
||||||
AT91C_US_CHRL_8_BITS |
|
AT91C_US_CHRL_8_BITS |
|
||||||
AT91C_US_PAR_NONE |
|
AT91C_US_PAR_NONE |
|
||||||
AT91C_US_NBSTOP_1_BIT);
|
AT91C_US_NBSTOP_1_BIT);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -44,8 +44,8 @@
|
||||||
* @note It is possible to use @p SetUART() in order to change the working
|
* @note It is possible to use @p SetUART() in order to change the working
|
||||||
* parameters at runtime.
|
* parameters at runtime.
|
||||||
*/
|
*/
|
||||||
#if !defined(SAM7X_UART_BITRATE) || defined(__DOXYGEN__)
|
#if !defined(SAM7X_USART_BITRATE) || defined(__DOXYGEN__)
|
||||||
#define SAM7X_UART_BITRATE 38400
|
#define SAM7X_USART_BITRATE 38400
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +69,7 @@
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
void InitSerial(int prio0, int prio1);
|
void sam7x_serial_init(int prio0, int prio1);
|
||||||
void SetUSART(AT91PS_USART u, int speed, int mode);
|
void SetUSART(AT91PS_USART u, int speed, int mode);
|
||||||
CH_IRQ_HANDLER(UART0IrqHandler);
|
CH_IRQ_HANDLER(UART0IrqHandler);
|
||||||
CH_IRQ_HANDLER(UART1IrqHandler);
|
CH_IRQ_HANDLER(UART1IrqHandler);
|
||||||
|
|
|
@ -216,6 +216,7 @@ static void OutNotify2(void) {
|
||||||
* @param[in] lcr the value for the @p LCR register
|
* @param[in] lcr the value for the @p LCR register
|
||||||
* @param[in] fcr the value for the @p FCR register
|
* @param[in] fcr the value for the @p FCR register
|
||||||
* @note Must be invoked with interrupts disabled.
|
* @note Must be invoked with interrupts disabled.
|
||||||
|
* @note Does not reset the I/O queues.
|
||||||
*/
|
*/
|
||||||
void SetUART(UART *u, int speed, int lcr, int fcr) {
|
void SetUART(UART *u, int speed, int lcr, int fcr) {
|
||||||
|
|
||||||
|
|
|
@ -158,6 +158,7 @@ static void OutNotify3(void) {
|
||||||
* @param[in] cr1 the value for the @p CR1 register
|
* @param[in] cr1 the value for the @p CR1 register
|
||||||
* @param[in] cr2 the value for the @p CR2 register
|
* @param[in] cr2 the value for the @p CR2 register
|
||||||
* @param[in] cr3 the value for the @p CR3 register
|
* @param[in] cr3 the value for the @p CR3 register
|
||||||
|
* @note Must be invoked with interrupts disabled.
|
||||||
* @note Does not reset the I/O queues.
|
* @note Does not reset the I/O queues.
|
||||||
*/
|
*/
|
||||||
void SetUSART(USART_TypeDef *u, uint32_t speed, uint16_t cr1,
|
void SetUSART(USART_TypeDef *u, uint32_t speed, uint16_t cr1,
|
||||||
|
|
|
@ -173,6 +173,7 @@ static void OutNotify2(void) {
|
||||||
* @param[in] div the divider value as calculated by the @p UBR() macro
|
* @param[in] div the divider value as calculated by the @p UBR() macro
|
||||||
* @param[in] mod the value for the @p U1MCTL register
|
* @param[in] mod the value for the @p U1MCTL register
|
||||||
* @param[in] ctl the value for the @p U1CTL register.
|
* @param[in] ctl the value for the @p U1CTL register.
|
||||||
|
* @note Must be invoked with interrupts disabled.
|
||||||
* @note Does not reset the I/O queues.
|
* @note Does not reset the I/O queues.
|
||||||
*/
|
*/
|
||||||
void SetUSART1(uint16_t div, uint8_t mod, uint8_t ctl) {
|
void SetUSART1(uint16_t div, uint8_t mod, uint8_t ctl) {
|
||||||
|
|
Loading…
Reference in New Issue