git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1330 35acf78f-673a-0410-8e92-d51de3d6d3f4
parent
7f36cb0f42
commit
63a16cf951
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,84 +0,0 @@
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* ATMEL Microcontroller Software Support - ROUSSET -
|
|
||||||
* ----------------------------------------------------------------------------
|
|
||||||
* Copyright (c) 2006, Atmel Corporation
|
|
||||||
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* - Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the disclaiimer below.
|
|
||||||
*
|
|
||||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the disclaimer below in the documentation and/or
|
|
||||||
* other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* Atmel's name may not be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
||||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
||||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
* ----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Headers
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#include "aic.h"
|
|
||||||
#include <board.h>
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Exported functions
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// Configures the interrupt associated with the given source, using the
|
|
||||||
/// specified mode and interrupt handler.
|
|
||||||
/// \param source Interrupt source to configure.
|
|
||||||
/// \param mode Triggering mode of the interrupt.
|
|
||||||
/// \param handler Interrupt handler function.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void AIC_ConfigureIT(unsigned int source,
|
|
||||||
unsigned int mode,
|
|
||||||
void (*handler)( void ))
|
|
||||||
{
|
|
||||||
// Disable the interrupt first
|
|
||||||
AT91C_BASE_AIC->AIC_IDCR = 1 << source;
|
|
||||||
|
|
||||||
// Configure mode and handler
|
|
||||||
AT91C_BASE_AIC->AIC_SMR[source] = mode;
|
|
||||||
AT91C_BASE_AIC->AIC_SVR[source] = (unsigned int) handler;
|
|
||||||
|
|
||||||
// Clear interrupt
|
|
||||||
AT91C_BASE_AIC->AIC_ICCR = 1 << source;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// Enables interrupts coming from the given (unique) source.
|
|
||||||
/// \param source Interrupt source to enable.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void AIC_EnableIT(unsigned int source)
|
|
||||||
{
|
|
||||||
AT91C_BASE_AIC->AIC_IECR = 1 << source;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// Disables interrupts coming from the given (unique) source.
|
|
||||||
/// \param source Interrupt source to enable.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void AIC_DisableIT(unsigned int source)
|
|
||||||
{
|
|
||||||
AT91C_BASE_AIC->AIC_IDCR = 1 << source;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,78 +0,0 @@
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* ATMEL Microcontroller Software Support - ROUSSET -
|
|
||||||
* ----------------------------------------------------------------------------
|
|
||||||
* Copyright (c) 2006, Atmel Corporation
|
|
||||||
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* - Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the disclaiimer below.
|
|
||||||
*
|
|
||||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the disclaimer below in the documentation and/or
|
|
||||||
* other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* Atmel's name may not be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
||||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
||||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
* ----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// \dir
|
|
||||||
/// !Purpose
|
|
||||||
///
|
|
||||||
/// Methods and definitions for configuring interrupts using the Advanced
|
|
||||||
/// Interrupt Controller (AIC).
|
|
||||||
///
|
|
||||||
/// !Usage
|
|
||||||
/// -# Configure an interrupt source using AIC_ConfigureIT
|
|
||||||
/// -# Enable or disable interrupt generation of a particular source with
|
|
||||||
/// AIC_EnableIT and AIC_DisableIT.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef AIC_H
|
|
||||||
#define AIC_H
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Headers
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#include <board.h>
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Definitions
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL
|
|
||||||
/// Redefinition of missing constant.
|
|
||||||
#define AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Global functions
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern void AIC_ConfigureIT(unsigned int source,
|
|
||||||
unsigned int mode,
|
|
||||||
void (*handler)( void ));
|
|
||||||
|
|
||||||
extern void AIC_EnableIT(unsigned int source);
|
|
||||||
|
|
||||||
extern void AIC_DisableIT(unsigned int source);
|
|
||||||
|
|
||||||
#endif //#ifndef AIC_H
|
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS/RT - Copyright (C) 2006-2007 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _AT91SAM7_H_
|
|
||||||
#define _AT91SAM7_H_
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Supported platforms.
|
|
||||||
*/
|
|
||||||
#define SAM7S64 0
|
|
||||||
#define SAM7S128 1
|
|
||||||
#define SAM7S256 2
|
|
||||||
#define SAM7S512 3
|
|
||||||
#define SAM7X128 4
|
|
||||||
#define SAM7X256 5
|
|
||||||
#define SAM7X512 6
|
|
||||||
|
|
||||||
#ifndef SAM7_PLATFORM
|
|
||||||
#error "SAM7 platform not defined"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SAM7_PLATFORM == SAM7S64
|
|
||||||
#include "at91lib/AT91SAM7S64.h"
|
|
||||||
#elif SAM7_PLATFORM == SAM7S128
|
|
||||||
#include "at91lib/AT91SAM7S128.h"
|
|
||||||
#elif SAM7_PLATFORM == SAM7S256
|
|
||||||
#include "at91lib/AT91SAM7S256.h"
|
|
||||||
#elif SAM7_PLATFORM == SAM7S512
|
|
||||||
#include "at91lib/AT91SAM7S512.h"
|
|
||||||
#elif SAM7_PLATFORM == SAM7X128
|
|
||||||
#include "at91lib/AT91SAM7X128.h"
|
|
||||||
#elif SAM7_PLATFORM == SAM7X256
|
|
||||||
#include "at91lib/AT91SAM7X256.h"
|
|
||||||
#elif SAM7_PLATFORM == SAM7X512
|
|
||||||
#include "at91lib/AT91SAM7X512.h"
|
|
||||||
#else
|
|
||||||
#error "SAM7 platform not supported"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* _AT91SAM7_H_ */
|
|
|
@ -1,484 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS/RT - Copyright (C) 2006-2007 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file AT91SAM7/mac_lld.c
|
|
||||||
* @brief AT91SAM7 low level MAC driver code
|
|
||||||
* @addtogroup AT91SAM7_MAC
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <ch.h>
|
|
||||||
#include <mac.h>
|
|
||||||
#include <mii.h>
|
|
||||||
|
|
||||||
#include "at91lib/aic.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 | \
|
|
||||||
AT91C_PB6_ERX1 | AT91C_PB7_ERXER | \
|
|
||||||
AT91C_PB8_EMDC | AT91C_PB9_EMDIO | \
|
|
||||||
AT91C_PB10_ETX2 | AT91C_PB11_ETX3 | \
|
|
||||||
AT91C_PB12_ETXER | AT91C_PB13_ERX2 | \
|
|
||||||
AT91C_PB14_ERX3 | AT91C_PB15_ERXDV_ECRSDV | \
|
|
||||||
AT91C_PB16_ECOL | AT91C_PB17_ERXCK)
|
|
||||||
|
|
||||||
#define RSR_BITS (AT91C_EMAC_BNA | AT91C_EMAC_REC | AT91C_EMAC_OVR)
|
|
||||||
|
|
||||||
#define TSR_BITS (AT91C_EMAC_UBR | AT91C_EMAC_COL | AT91C_EMAC_RLES | \
|
|
||||||
AT91C_EMAC_BEX | AT91C_EMAC_COMP | AT91C_EMAC_UND)
|
|
||||||
|
|
||||||
#ifndef __DOXYGEN__
|
|
||||||
static bool_t link_up;
|
|
||||||
|
|
||||||
static uint8_t default_mac[] = {0xAA, 0x55, 0x13, 0x37, 0x01, 0x10};
|
|
||||||
|
|
||||||
static EMACDescriptor *rxptr;
|
|
||||||
static EMACDescriptor *txptr;
|
|
||||||
static EMACDescriptor rd[EMAC_RECEIVE_DESCRIPTORS]
|
|
||||||
__attribute__((aligned(8)));
|
|
||||||
static EMACDescriptor td[EMAC_TRANSMIT_DESCRIPTORS]
|
|
||||||
__attribute__((aligned(8)));
|
|
||||||
static uint8_t rb[EMAC_RECEIVE_DESCRIPTORS * EMAC_RECEIVE_BUFFERS_SIZE]
|
|
||||||
__attribute__((aligned(8)));
|
|
||||||
static uint8_t tb[EMAC_TRANSMIT_DESCRIPTORS * EMAC_TRANSMIT_BUFFERS_SIZE]
|
|
||||||
__attribute__((aligned(8)));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief IRQ handler.
|
|
||||||
*/
|
|
||||||
/** @cond never*/
|
|
||||||
__attribute__((noinline))
|
|
||||||
/** @endcond*/
|
|
||||||
static void serve_interrupt(void) {
|
|
||||||
uint32_t isr, rsr, tsr;
|
|
||||||
|
|
||||||
/* Fix for the EMAC errata */
|
|
||||||
isr = AT91C_BASE_EMAC->EMAC_ISR;
|
|
||||||
rsr = AT91C_BASE_EMAC->EMAC_RSR;
|
|
||||||
tsr = AT91C_BASE_EMAC->EMAC_TSR;
|
|
||||||
|
|
||||||
if ((isr & AT91C_EMAC_RCOMP) || (rsr & RSR_BITS)) {
|
|
||||||
if (rsr & AT91C_EMAC_REC) {
|
|
||||||
chSysLockFromIsr();
|
|
||||||
chSemResetI(Ð1.md_rdsem, 0);
|
|
||||||
#if CH_USE_EVENTS
|
|
||||||
chEvtBroadcastI(Ð1.md_rdevent);
|
|
||||||
#endif
|
|
||||||
chSysUnlockFromIsr();
|
|
||||||
}
|
|
||||||
AT91C_BASE_EMAC->EMAC_RSR = RSR_BITS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((isr & AT91C_EMAC_TCOMP) || (tsr & TSR_BITS)) {
|
|
||||||
if (tsr & AT91C_EMAC_COMP) {
|
|
||||||
chSysLockFromIsr();
|
|
||||||
chSemResetI(Ð1.md_tdsem, 0);
|
|
||||||
chSysUnlockFromIsr();
|
|
||||||
}
|
|
||||||
AT91C_BASE_EMAC->EMAC_TSR = TSR_BITS;
|
|
||||||
}
|
|
||||||
AT91C_BASE_AIC->AIC_EOICR = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief EMAC IRQ veneer handler.
|
|
||||||
*/
|
|
||||||
CH_IRQ_HANDLER(irq_handler) {
|
|
||||||
|
|
||||||
CH_IRQ_PROLOGUE();
|
|
||||||
|
|
||||||
serve_interrupt();
|
|
||||||
|
|
||||||
CH_IRQ_EPILOGUE();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Low level MAC initialization.
|
|
||||||
*/
|
|
||||||
void mac_lld_init(void) {
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
miiInit();
|
|
||||||
macObjectInit(Ð1);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Buffers initialization.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < EMAC_RECEIVE_DESCRIPTORS; i++) {
|
|
||||||
rd[i].w1 = (uint32_t)&rb[i * EMAC_RECEIVE_BUFFERS_SIZE];
|
|
||||||
rd[i].w2 = 0;
|
|
||||||
}
|
|
||||||
rd[EMAC_RECEIVE_DESCRIPTORS - 1].w1 |= W1_R_WRAP;
|
|
||||||
rxptr = rd;
|
|
||||||
for (i = 0; i < EMAC_TRANSMIT_DESCRIPTORS; i++) {
|
|
||||||
td[i].w1 = (uint32_t)&tb[i * EMAC_TRANSMIT_BUFFERS_SIZE];
|
|
||||||
td[i].w2 = EMAC_TRANSMIT_BUFFERS_SIZE | W2_T_LAST_BUFFER | W2_T_USED;
|
|
||||||
}
|
|
||||||
td[EMAC_TRANSMIT_DESCRIPTORS - 1].w2 |= W2_T_WRAP;
|
|
||||||
txptr = td;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Associated PHY initialization.
|
|
||||||
*/
|
|
||||||
miiReset(Ð1);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* EMAC pins setup and clock enable. Note, PB18 is not included because it is
|
|
||||||
* used as #PD control and not as EF100.
|
|
||||||
*/
|
|
||||||
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;
|
|
||||||
AT91C_BASE_PIOB->PIO_ASR = EMAC_PIN_MASK;
|
|
||||||
AT91C_BASE_PIOB->PIO_PDR = EMAC_PIN_MASK;
|
|
||||||
AT91C_BASE_PIOB->PIO_PPUDR = EMAC_PIN_MASK;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* EMAC Initial setup.
|
|
||||||
*/
|
|
||||||
AT91C_BASE_EMAC->EMAC_NCR = 0; /* Stopped but MCE active.*/
|
|
||||||
AT91C_BASE_EMAC->EMAC_NCFGR = 2 << 10; /* MDC-CLK = MCK / 32 */
|
|
||||||
AT91C_BASE_EMAC->EMAC_USRIO = AT91C_EMAC_CLKEN;/* Enable EMAC in MII mode.*/
|
|
||||||
AT91C_BASE_EMAC->EMAC_RBQP = (AT91_REG)rd; /* RX descriptors list.*/
|
|
||||||
AT91C_BASE_EMAC->EMAC_TBQP = (AT91_REG)td; /* TX descriptors list.*/
|
|
||||||
AT91C_BASE_EMAC->EMAC_RSR = AT91C_EMAC_OVR |
|
|
||||||
AT91C_EMAC_REC |
|
|
||||||
AT91C_EMAC_BNA; /* Clears RSR.*/
|
|
||||||
AT91C_BASE_EMAC->EMAC_NCFGR |= AT91C_EMAC_DRFCS;/* Initial NCFGR settings.*/
|
|
||||||
AT91C_BASE_EMAC->EMAC_NCR |= AT91C_EMAC_TE |
|
|
||||||
AT91C_EMAC_RE |
|
|
||||||
AT91C_EMAC_CLRSTAT;/* Initial NCR settings.*/
|
|
||||||
mac_lld_set_address(Ð1, default_mac);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* PHY device identification.
|
|
||||||
*/
|
|
||||||
AT91C_BASE_EMAC->EMAC_NCR |= AT91C_EMAC_MPE;
|
|
||||||
if ((miiGet(Ð1, MII_PHYSID1) != (PHY_ID >> 16)) ||
|
|
||||||
((miiGet(Ð1, MII_PHYSID2) & 0xFFF0) != (PHY_ID & 0xFFF0)))
|
|
||||||
chSysHalt();
|
|
||||||
AT91C_BASE_EMAC->EMAC_NCR &= ~AT91C_EMAC_MPE;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Interrupt configuration.
|
|
||||||
*/
|
|
||||||
AT91C_BASE_EMAC->EMAC_IER = AT91C_EMAC_RCOMP | AT91C_EMAC_TCOMP;
|
|
||||||
AIC_ConfigureIT(AT91C_ID_EMAC,
|
|
||||||
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | EMAC_INTERRUPT_PRIORITY,
|
|
||||||
irq_handler);
|
|
||||||
AIC_EnableIT(AT91C_ID_EMAC);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Low level MAC address setup.
|
|
||||||
*
|
|
||||||
* @param[in] macp pointer to the @p MACDriver object
|
|
||||||
* @param[in] p pointer to a six bytes buffer containing the MAC address. If
|
|
||||||
* this parameter is set to @p NULL then a system default MAC is
|
|
||||||
* used. The MAC address must be aligned with the most significant
|
|
||||||
* byte first.
|
|
||||||
*/
|
|
||||||
void mac_lld_set_address(MACDriver *macp, const uint8_t *p) {
|
|
||||||
|
|
||||||
(void)macp;
|
|
||||||
AT91C_BASE_EMAC->EMAC_SA1L = (AT91_REG)((p[3] << 24) | (p[2] << 16) |
|
|
||||||
(p[1] << 8) | p[0]);
|
|
||||||
AT91C_BASE_EMAC->EMAC_SA1H = (AT91_REG)((p[5] << 8) | p[4]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns a transmission descriptor.
|
|
||||||
* @details One of the available transmission descriptors is locked and
|
|
||||||
* returned.
|
|
||||||
*
|
|
||||||
* @param[in] macp pointer to the @p MACDriver object
|
|
||||||
* @param[out] tdp pointer to a @p MACTransmitDescriptor structure
|
|
||||||
* @return The operation status.
|
|
||||||
* @retval RDY_OK the descriptor was obtained.
|
|
||||||
* @retval RDY_TIMEOUT descriptor not available.
|
|
||||||
*/
|
|
||||||
msg_t max_lld_get_transmit_descriptor(MACDriver *macp,
|
|
||||||
MACTransmitDescriptor *tdp) {
|
|
||||||
EMACDescriptor *edp;
|
|
||||||
|
|
||||||
(void)macp;
|
|
||||||
|
|
||||||
if (!link_up)
|
|
||||||
return RDY_TIMEOUT;
|
|
||||||
|
|
||||||
chSysLock();
|
|
||||||
edp = txptr;
|
|
||||||
if (!(edp->w2 & W2_T_USED) || (edp->w2 & W2_T_LOCKED)) {
|
|
||||||
chSysUnlock();
|
|
||||||
return RDY_TIMEOUT;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Set the buffer size and configuration, the buffer is also marked
|
|
||||||
* as locked.
|
|
||||||
*/
|
|
||||||
if (++txptr >= &td[EMAC_TRANSMIT_DESCRIPTORS]) {
|
|
||||||
edp->w2 = W2_T_LOCKED | W2_T_USED | W2_T_LAST_BUFFER | W2_T_WRAP;
|
|
||||||
txptr = td;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
edp->w2 = W2_T_LOCKED | W2_T_USED | W2_T_LAST_BUFFER;
|
|
||||||
chSysUnlock();
|
|
||||||
tdp->td_offset = 0;
|
|
||||||
tdp->td_size = EMAC_TRANSMIT_BUFFERS_SIZE;
|
|
||||||
tdp->td_physdesc = edp;
|
|
||||||
return RDY_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Writes to a transmit descriptor's stream.
|
|
||||||
*
|
|
||||||
* @param[in] tdp pointer to a @p MACTransmitDescriptor structure
|
|
||||||
* @param[in] buf pointer to the buffer cointaining the data to be written
|
|
||||||
* @param[in] size number of bytes to be written
|
|
||||||
* @return The number of bytes written into the descriptor's stream, this
|
|
||||||
* value can be less than the amount specified in the parameter
|
|
||||||
* @p size if the maximum frame size is reached.
|
|
||||||
*/
|
|
||||||
size_t mac_lld_write_transmit_descriptor(MACTransmitDescriptor *tdp,
|
|
||||||
uint8_t *buf,
|
|
||||||
size_t size) {
|
|
||||||
|
|
||||||
if (size > tdp->td_size - tdp->td_offset)
|
|
||||||
size = tdp->td_size - tdp->td_offset;
|
|
||||||
if (size > 0) {
|
|
||||||
memcpy((uint8_t *)(tdp->td_physdesc->w1 & W1_T_ADDRESS_MASK) +
|
|
||||||
tdp->td_offset,
|
|
||||||
buf, size);
|
|
||||||
tdp->td_offset += size;
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Releases a transmit descriptor and starts the transmission of the
|
|
||||||
* enqueued data as a single frame.
|
|
||||||
*
|
|
||||||
* @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
|
|
||||||
*/
|
|
||||||
void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp) {
|
|
||||||
|
|
||||||
chSysLock();
|
|
||||||
tdp->td_physdesc->w2 = (tdp->td_physdesc->w2 &
|
|
||||||
~(W2_T_LOCKED | W2_T_USED | W2_T_LENGTH_MASK)) |
|
|
||||||
tdp->td_offset;
|
|
||||||
AT91C_BASE_EMAC->EMAC_NCR |= AT91C_EMAC_TSTART;
|
|
||||||
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.
|
|
||||||
*
|
|
||||||
* @param[in] macp pointer to the @p MACDriver object
|
|
||||||
* @param[out] rdp pointer to a @p MACReceiveDescriptor structure
|
|
||||||
* @return The operation status.
|
|
||||||
* @retval RDY_OK the descriptor was obtained.
|
|
||||||
* @retval RDY_TIMEOUT descriptor not available.
|
|
||||||
*/
|
|
||||||
msg_t max_lld_get_receive_descriptor(MACDriver *macp,
|
|
||||||
MACReceiveDescriptor *rdp) {
|
|
||||||
unsigned n;
|
|
||||||
EMACDescriptor *edp;
|
|
||||||
|
|
||||||
(void)macp;
|
|
||||||
n = EMAC_RECEIVE_DESCRIPTORS;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Skips unused buffers, if any.
|
|
||||||
*/
|
|
||||||
skip:
|
|
||||||
while ((n > 0) && !(rxptr->w1 & W1_R_OWNERSHIP)) {
|
|
||||||
if (++rxptr >= &rd[EMAC_RECEIVE_DESCRIPTORS])
|
|
||||||
rxptr = rd;
|
|
||||||
n--;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Skips fragments, if any, cleaning them up.
|
|
||||||
*/
|
|
||||||
while ((n > 0) && (rxptr->w1 & W1_R_OWNERSHIP) &&
|
|
||||||
!(rxptr->w2 & W2_R_FRAME_START)) {
|
|
||||||
rxptr->w1 &= ~W1_R_OWNERSHIP;
|
|
||||||
if (++rxptr >= &rd[EMAC_RECEIVE_DESCRIPTORS])
|
|
||||||
rxptr = rd;
|
|
||||||
n--;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now compute the total frame size skipping eventual incomplete frames
|
|
||||||
* or holes...
|
|
||||||
*/
|
|
||||||
restart:
|
|
||||||
edp = rxptr;
|
|
||||||
while (n > 0) {
|
|
||||||
if (!(rxptr->w1 & W1_R_OWNERSHIP)) {
|
|
||||||
/* Empty buffer for some reason... cleaning up the incomplete frame.*/
|
|
||||||
cleanup(edp);
|
|
||||||
goto skip;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* End Of Frame found.
|
|
||||||
*/
|
|
||||||
if (rxptr->w2 & W2_R_FRAME_END) {
|
|
||||||
rdp->rd_offset = 0;
|
|
||||||
rdp->rd_size = rxptr->w2 & W2_T_LENGTH_MASK;
|
|
||||||
rdp->rd_physdesc = edp;
|
|
||||||
return RDY_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((edp != rxptr) && (rxptr->w2 & W2_R_FRAME_START)) {
|
|
||||||
/* Found another start... cleaning up the incomplete frame.*/
|
|
||||||
cleanup(edp);
|
|
||||||
goto restart; /* Another start buffer for some reason... */
|
|
||||||
}
|
|
||||||
|
|
||||||
if (++rxptr >= &rd[EMAC_RECEIVE_DESCRIPTORS])
|
|
||||||
rxptr = rd;
|
|
||||||
n--;
|
|
||||||
}
|
|
||||||
return RDY_TIMEOUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Reads from a receive descriptor's stream.
|
|
||||||
*
|
|
||||||
* @param[in] rdp pointer to a @p MACReceiveDescriptor structure
|
|
||||||
* @param[in] buf pointer to the buffer that will receive the read data
|
|
||||||
* @param[in] size number of bytes to be read
|
|
||||||
* @return The number of bytes read from the descriptor's stream, this
|
|
||||||
* value can be less than the amount specified in the parameter
|
|
||||||
* @p size if there are no more bytes to read.
|
|
||||||
*/
|
|
||||||
size_t mac_lld_read_receive_descriptor(MACReceiveDescriptor *rdp,
|
|
||||||
uint8_t *buf,
|
|
||||||
size_t size) {
|
|
||||||
if (size > rdp->rd_size - rdp->rd_offset)
|
|
||||||
size = rdp->rd_size - rdp->rd_offset;
|
|
||||||
if (size > 0) {
|
|
||||||
uint8_t *src = (uint8_t *)(rdp->rd_physdesc->w1 & W1_R_ADDRESS_MASK) +
|
|
||||||
rdp->rd_offset;
|
|
||||||
uint8_t *limit = &rb[EMAC_RECEIVE_DESCRIPTORS * EMAC_RECEIVE_BUFFERS_SIZE];
|
|
||||||
if (src >= limit)
|
|
||||||
src -= EMAC_RECEIVE_DESCRIPTORS * EMAC_RECEIVE_BUFFERS_SIZE;
|
|
||||||
if (src + size > limit ) {
|
|
||||||
memcpy(buf, src, (size_t)(limit - src));
|
|
||||||
memcpy(buf + (size_t)(limit - src), rb, size - (size_t)(limit - src));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
memcpy(buf, src, size);
|
|
||||||
rdp->rd_offset += size;
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Releases a receive descriptor.
|
|
||||||
* @details The descriptor and its buffer are made available for more incoming
|
|
||||||
* frames.
|
|
||||||
*
|
|
||||||
* @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
|
|
||||||
*/
|
|
||||||
void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp) {
|
|
||||||
bool_t done;
|
|
||||||
EMACDescriptor *edp = rdp->rd_physdesc;
|
|
||||||
|
|
||||||
unsigned n = EMAC_RECEIVE_DESCRIPTORS;
|
|
||||||
do {
|
|
||||||
done = ((edp->w2 & W2_R_FRAME_END) != 0);
|
|
||||||
chDbgAssert(edp->w1 & W1_R_OWNERSHIP,
|
|
||||||
"mac_lld_release_receive_descriptor(), #1",
|
|
||||||
"found not owned descriptor");
|
|
||||||
edp->w1 &= ~(W1_R_OWNERSHIP | W2_R_FRAME_START | W2_R_FRAME_END);
|
|
||||||
if (++edp >= &rd[EMAC_RECEIVE_DESCRIPTORS])
|
|
||||||
edp = rd;
|
|
||||||
n--;
|
|
||||||
}
|
|
||||||
while ((n > 0) && !done);
|
|
||||||
/*
|
|
||||||
* Make rxptr point to the descriptor where the next frame will most
|
|
||||||
* likely appear.
|
|
||||||
*/
|
|
||||||
rxptr = edp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Updates and returns the link status.
|
|
||||||
*
|
|
||||||
* @param[in] macp pointer to the @p MACDriver object
|
|
||||||
* @return The link status.
|
|
||||||
* @retval TRUE if the link is active.
|
|
||||||
* @retval FALSE if the link is down.
|
|
||||||
*/
|
|
||||||
bool_t mac_lld_poll_link_status(MACDriver *macp) {
|
|
||||||
uint32_t ncfgr, bmsr, bmcr, lpa;
|
|
||||||
|
|
||||||
AT91C_BASE_EMAC->EMAC_NCR |= AT91C_EMAC_MPE;
|
|
||||||
(void)miiGet(macp, MII_BMSR);
|
|
||||||
bmsr = miiGet(macp, MII_BMSR);
|
|
||||||
if (!(bmsr & BMSR_LSTATUS)) {
|
|
||||||
AT91C_BASE_EMAC->EMAC_NCR &= ~AT91C_EMAC_MPE;
|
|
||||||
return link_up = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ncfgr = AT91C_BASE_EMAC->EMAC_NCFGR & ~(AT91C_EMAC_SPD | AT91C_EMAC_FD);
|
|
||||||
bmcr = miiGet(macp, MII_BMCR);
|
|
||||||
if (bmcr & BMCR_ANENABLE) {
|
|
||||||
lpa = miiGet(macp, MII_LPA);
|
|
||||||
if (lpa & (LPA_100HALF | LPA_100FULL | LPA_100BASE4))
|
|
||||||
ncfgr |= AT91C_EMAC_SPD;
|
|
||||||
if (lpa & (LPA_10FULL | LPA_100FULL))
|
|
||||||
ncfgr |= AT91C_EMAC_FD;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (bmcr & BMCR_SPEED100)
|
|
||||||
ncfgr |= AT91C_EMAC_SPD;
|
|
||||||
if (bmcr & BMCR_FULLDPLX)
|
|
||||||
ncfgr |= AT91C_EMAC_FD;
|
|
||||||
}
|
|
||||||
AT91C_BASE_EMAC->EMAC_NCFGR = ncfgr;
|
|
||||||
AT91C_BASE_EMAC->EMAC_NCR &= ~AT91C_EMAC_MPE;
|
|
||||||
return link_up = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @} */
|
|
|
@ -1,192 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS/RT - Copyright (C) 2006-2007 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file AT91SAM7/mac_lld.h
|
|
||||||
* @brief AT91SAM7 low level MAC driver header
|
|
||||||
* @addtogroup AT91SAM7_MAC
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _MAC_LLD_H_
|
|
||||||
#define _MAC_LLD_H_
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* 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
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* EMAC specific settings. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* EMAC specific constants. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
#define EMAC_RECEIVE_BUFFERS_SIZE 128 /* Do not modify */
|
|
||||||
#define EMAC_TRANSMIT_BUFFERS_SIZE MAC_BUFFERS_SIZE
|
|
||||||
#define EMAC_RECEIVE_DESCRIPTORS \
|
|
||||||
(((((MAC_BUFFERS_SIZE - 1) | (EMAC_RECEIVE_BUFFERS_SIZE - 1)) + 1) \
|
|
||||||
/ EMAC_RECEIVE_BUFFERS_SIZE) * MAC_RECEIVE_BUFFERS)
|
|
||||||
#define EMAC_TRANSMIT_DESCRIPTORS MAC_TRANSMIT_BUFFERS
|
|
||||||
|
|
||||||
#define W1_R_OWNERSHIP 0x00000001
|
|
||||||
#define W1_R_WRAP 0x00000002
|
|
||||||
#define W1_R_ADDRESS_MASK 0xFFFFFFFC
|
|
||||||
|
|
||||||
#define W2_R_LENGTH_MASK 0x00000FFF
|
|
||||||
#define W2_R_FRAME_START 0x00004000
|
|
||||||
#define W2_R_FRAME_END 0x00008000
|
|
||||||
#define W2_R_CFI 0x00010000
|
|
||||||
#define W2_R_VLAN_PRIO_MASK 0x000E0000
|
|
||||||
#define W2_R_PRIO_TAG_DETECTED 0x00100000
|
|
||||||
#define W2_R_VLAN_TAG_DETECTED 0x00200000
|
|
||||||
#define W2_R_TYPE_ID_MATCH 0x00400000
|
|
||||||
#define W2_R_ADDR4_MATCH 0x00800000
|
|
||||||
#define W2_R_ADDR3_MATCH 0x01000000
|
|
||||||
#define W2_R_ADDR2_MATCH 0x02000000
|
|
||||||
#define W2_R_ADDR1_MATCH 0x04000000
|
|
||||||
#define W2_R_RFU1 0x08000000
|
|
||||||
#define W2_R_ADDR_EXT_MATCH 0x10000000
|
|
||||||
#define W2_R_UNICAST_MATCH 0x20000000
|
|
||||||
#define W2_R_MULTICAST_MATCH 0x40000000
|
|
||||||
#define W2_R_BROADCAST_DETECTED 0x80000000
|
|
||||||
|
|
||||||
#define W1_T_ADDRESS_MASK 0xFFFFFFFF
|
|
||||||
|
|
||||||
#define W2_T_LENGTH_MASK 0x000007FF
|
|
||||||
#define W2_T_LOCKED 0x00000800 /* Not an EMAC flag, used by the driver */
|
|
||||||
#define W2_T_RFU1 0x00003000
|
|
||||||
#define W2_T_LAST_BUFFER 0x00008000
|
|
||||||
#define W2_T_NO_CRC 0x00010000
|
|
||||||
#define W2_T_RFU2 0x07FE0000
|
|
||||||
#define W2_T_BUFFERS_EXHAUSTED 0x08000000
|
|
||||||
#define W2_T_TRANSMIT_UNDERRUN 0x10000000
|
|
||||||
#define W2_T_RETRY_LIMIT_EXC 0x20000000
|
|
||||||
#define W2_T_WRAP 0x40000000
|
|
||||||
#define W2_T_USED 0x80000000
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Driver data structures and types. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Structure representing a buffer physical descriptor.
|
|
||||||
* @note It represents both descriptor types.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
uint32_t w1;
|
|
||||||
uint32_t w2;
|
|
||||||
} EMACDescriptor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Structure representing a MAC driver.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
Semaphore md_tdsem; /**< Transmit semaphore. */
|
|
||||||
Semaphore md_rdsem; /**< Receive semaphore. */
|
|
||||||
#if CH_USE_EVENTS
|
|
||||||
EventSource md_rdevent; /**< Receive event source. */
|
|
||||||
#endif
|
|
||||||
/* End of the mandatory fields.*/
|
|
||||||
} MACDriver;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Structure representing a transmit descriptor.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
size_t td_offset; /**< Current write offset. */
|
|
||||||
size_t td_size; /**< Available space size. */
|
|
||||||
/* End of the mandatory fields.*/
|
|
||||||
EMACDescriptor *td_physdesc; /**< Pointer to the physical
|
|
||||||
descriptor. */
|
|
||||||
} MACTransmitDescriptor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Structure representing a receive descriptor.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
size_t rd_offset; /**< Current read offset. */
|
|
||||||
size_t rd_size; /**< Available data size. */
|
|
||||||
/* End of the mandatory fields.*/
|
|
||||||
EMACDescriptor *rd_physdesc; /**< Pointer to the first descriptor
|
|
||||||
of the buffers chain. */
|
|
||||||
} MACReceiveDescriptor;
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* External declarations. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/** @cond never*/
|
|
||||||
extern MACDriver ETH1;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
void mac_lld_init(void);
|
|
||||||
void mac_lld_set_address(MACDriver *macp, const uint8_t *p);
|
|
||||||
msg_t max_lld_get_transmit_descriptor(MACDriver *macp,
|
|
||||||
MACTransmitDescriptor *tdp);
|
|
||||||
size_t mac_lld_write_transmit_descriptor(MACTransmitDescriptor *tdp,
|
|
||||||
uint8_t *buf,
|
|
||||||
size_t size);
|
|
||||||
void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp);
|
|
||||||
msg_t max_lld_get_receive_descriptor(MACDriver *macp,
|
|
||||||
MACReceiveDescriptor *rdp);
|
|
||||||
size_t mac_lld_read_receive_descriptor(MACReceiveDescriptor *rdp,
|
|
||||||
uint8_t *buf,
|
|
||||||
size_t size);
|
|
||||||
void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp);
|
|
||||||
bool_t mac_lld_poll_link_status(MACDriver *macp);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/** @endcond*/
|
|
||||||
|
|
||||||
#endif /* _MAC_LLD_H_ */
|
|
||||||
|
|
||||||
/** @} */
|
|
|
@ -1,114 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS/RT - Copyright (C) 2006-2007 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file AT91SAM7/mii_lld.c
|
|
||||||
* @brief AT91SAM7 low level MII driver code
|
|
||||||
* @addtogroup AT91SAM7_MII
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ch.h>
|
|
||||||
#include <mii.h>
|
|
||||||
#include <mac.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Low level MII driver initialization.
|
|
||||||
*/
|
|
||||||
void mii_lld_init(void) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Resets a PHY device.
|
|
||||||
*
|
|
||||||
* @param[in] macp pointer to the @p MACDriver object
|
|
||||||
*/
|
|
||||||
void mii_lld_reset(MACDriver *macp) {
|
|
||||||
|
|
||||||
(void)macp;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Disables the pullups on all the pins that are latched on reset by the PHY.
|
|
||||||
*/
|
|
||||||
AT91C_BASE_PIOB->PIO_PPUDR = PHY_LATCHED_PINS;
|
|
||||||
|
|
||||||
#ifdef PIOB_PHY_PD_MASK
|
|
||||||
/*
|
|
||||||
* PHY power control.
|
|
||||||
*/
|
|
||||||
AT91C_BASE_PIOB->PIO_OER = PIOB_PHY_PD_MASK; // Becomes an output.
|
|
||||||
AT91C_BASE_PIOB->PIO_PPUDR = PIOB_PHY_PD_MASK; // Default pullup disabled.
|
|
||||||
#if (PHY_HARDWARE == PHY_DAVICOM_9161)
|
|
||||||
AT91C_BASE_PIOB->PIO_CODR = PIOB_PHY_PD_MASK; // Output to low level.
|
|
||||||
#else
|
|
||||||
AT91C_BASE_PIOB->PIO_SODR = PIOB_PHY_PD_MASK; // Output to high level.
|
|
||||||
#endif
|
|
||||||
#endif // PIOB_PHY_PD_MASK
|
|
||||||
|
|
||||||
/*
|
|
||||||
* PHY reset by pulsing the NRST pin.
|
|
||||||
*/
|
|
||||||
AT91C_BASE_RSTC->RSTC_RMR = 0xA5000100;
|
|
||||||
AT91C_BASE_RSTC->RSTC_RCR = 0xA5000000 | AT91C_RSTC_EXTRST;
|
|
||||||
while (!(AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_NRSTL))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Reads a PHY register through the MII interface.
|
|
||||||
*
|
|
||||||
* @param[in] macp pointer to the @p MACDriver object
|
|
||||||
* @param addr the register address
|
|
||||||
* @return The register value.
|
|
||||||
*/
|
|
||||||
phyreg_t mii_lld_get(MACDriver *macp, phyaddr_t addr) {
|
|
||||||
|
|
||||||
(void)macp;
|
|
||||||
AT91C_BASE_EMAC->EMAC_MAN = (0b01 << 30) | /* SOF */
|
|
||||||
(0b10 << 28) | /* RW */
|
|
||||||
(PHY_ADDRESS << 23) | /* PHYA */
|
|
||||||
(addr << 18) | /* REGA */
|
|
||||||
(0b10 << 16); /* CODE */
|
|
||||||
while (!( AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE))
|
|
||||||
;
|
|
||||||
return (phyreg_t)(AT91C_BASE_EMAC->EMAC_MAN & 0xFFFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Writes a PHY register through the MII interface.
|
|
||||||
*
|
|
||||||
* @param[in] macp pointer to the @p MACDriver object
|
|
||||||
* @param addr the register address
|
|
||||||
* @param value the new register value
|
|
||||||
*/
|
|
||||||
void mii_lld_put(MACDriver *macp, phyaddr_t addr, phyreg_t value) {
|
|
||||||
|
|
||||||
(void)macp;
|
|
||||||
AT91C_BASE_EMAC->EMAC_MAN = (0b01 << 30) | /* SOF */
|
|
||||||
(0b01 << 28) | /* RW */
|
|
||||||
(PHY_ADDRESS << 23) | /* PHYA */
|
|
||||||
(addr << 18) | /* REGA */
|
|
||||||
(0b10 << 16) | /* CODE */
|
|
||||||
value;
|
|
||||||
while (!( AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @} */
|
|
|
@ -1,103 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS/RT - Copyright (C) 2006-2007 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file AT91SAM7/mii_lld.h
|
|
||||||
* @brief AT91SAM7 low level MII driver header
|
|
||||||
* @addtogroup AT91SAM7_MII
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _MII_LLD_H_
|
|
||||||
#define _MII_LLD_H_
|
|
||||||
|
|
||||||
#include "board.h"
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Driver pre-compile time settings. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief PHY manufacturer and model.
|
|
||||||
*/
|
|
||||||
#if !defined(PHY_HARDWARE) || defined(__DOXYGEN__)
|
|
||||||
#define PHY_HARDWARE PHY_MICREL_KS8721
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* PHY specific constants. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
#define PHY_MICREL_KS8721 0
|
|
||||||
#define PHY_DAVICOM_9161 1
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Pins latched by the PHY at reset.
|
|
||||||
*/
|
|
||||||
#if PHY_HARDWARE == PHY_MICREL_KS8721
|
|
||||||
#define PHY_ADDRESS 1
|
|
||||||
#define PHY_ID MII_KS8721_ID
|
|
||||||
#define PHY_LATCHED_PINS (AT91C_PB4_ECRS | AT91C_PB5_ERX0 | \
|
|
||||||
AT91C_PB6_ERX1 | AT91C_PB7_ERXER | \
|
|
||||||
AT91C_PB13_ERX2 | AT91C_PB14_ERX3 | \
|
|
||||||
AT91C_PB15_ERXDV_ECRSDV | AT91C_PB16_ECOL | \
|
|
||||||
AT91C_PIO_PB26)
|
|
||||||
|
|
||||||
#elif PHY_HARDWARE == PHY_DAVICOM_9161
|
|
||||||
#define PHY_ADDRESS 0
|
|
||||||
#define PHY_ID MII_DM9161_ID
|
|
||||||
#define PHY_LATCHED_PINS (AT91C_PB0_ETXCK_EREFCK | AT91C_PB4_ECRS | \
|
|
||||||
AT91C_PB5_ERX0 | AT91C_PB6_ERX1 | \
|
|
||||||
AT91C_PB7_ERXER | AT91C_PB13_ERX2 | \
|
|
||||||
AT91C_PB14_ERX3 | AT91C_PB15_ERXDV_ECRSDV | \
|
|
||||||
AT91C_PB16_ECOL | AT91C_PB17_ERXCK)
|
|
||||||
#endif /* PHY_HARDWARE */
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Driver data structures and types. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Type of a PHY register value.
|
|
||||||
*/
|
|
||||||
typedef uint16_t phyreg_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Type of a PHY register address.
|
|
||||||
*/
|
|
||||||
typedef uint8_t phyaddr_t;
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* External declarations. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
void mii_lld_init(void);
|
|
||||||
void mii_lld_reset(MACDriver *macp);
|
|
||||||
phyreg_t mii_lld_get(MACDriver *macp, phyaddr_t addr);
|
|
||||||
void mii_lld_put(MACDriver *macp, phyaddr_t addr, phyreg_t value);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* _MII_LLD_H_ */
|
|
||||||
|
|
||||||
/** @} */
|
|
|
@ -1,125 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS/RT - Copyright (C) 2006-2007 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file AT91SAM7/pal_lld.c
|
|
||||||
* @brief AT91SAM7 PIO low level driver code
|
|
||||||
* @addtogroup AT91SAM7_PAL
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ch.h>
|
|
||||||
#include <pal.h>
|
|
||||||
|
|
||||||
#include "board.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief AT91SAM7 I/O ports configuration.
|
|
||||||
* @details PIO registers initialization.
|
|
||||||
*
|
|
||||||
* @param[in] config the AT91SAM7 ports configuration
|
|
||||||
*/
|
|
||||||
void _pal_lld_init(const AT91SAM7PIOConfig *config) {
|
|
||||||
|
|
||||||
unsigned int ports = (1 << AT91C_ID_PIOA);
|
|
||||||
#if defined(SAM7X128) || defined(SAM7X256) || defined(SAM7X512)
|
|
||||||
ports |= (1 << AT91C_ID_PIOB);
|
|
||||||
#endif
|
|
||||||
AT91C_BASE_PMC->PMC_PCER = ports;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* PIOA setup.
|
|
||||||
*/
|
|
||||||
AT91C_BASE_PIOA->PIO_PPUER = config->P0Data.pusr; /* Pull-up as spec.*/
|
|
||||||
AT91C_BASE_PIOA->PIO_PPUDR = ~config->P0Data.pusr;
|
|
||||||
AT91C_BASE_PIOA->PIO_PER = 0xFFFFFFFF; /* PIO enabled.*/
|
|
||||||
AT91C_BASE_PIOA->PIO_ODSR = config->P0Data.odsr; /* Data as specified.*/
|
|
||||||
AT91C_BASE_PIOA->PIO_OER = config->P0Data.osr; /* Dir. as specified.*/
|
|
||||||
AT91C_BASE_PIOA->PIO_ODR = ~config->P0Data.osr;
|
|
||||||
AT91C_BASE_PIOA->PIO_IFDR = 0xFFFFFFFF; /* Filter disabled.*/
|
|
||||||
AT91C_BASE_PIOA->PIO_IDR = 0xFFFFFFFF; /* Int. disabled.*/
|
|
||||||
AT91C_BASE_PIOA->PIO_MDDR = 0xFFFFFFFF; /* Push Pull drive.*/
|
|
||||||
AT91C_BASE_PIOA->PIO_ASR = 0xFFFFFFFF; /* Peripheral A.*/
|
|
||||||
AT91C_BASE_PIOA->PIO_OWER = 0xFFFFFFFF; /* Write enabled.*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* PIOB setup.
|
|
||||||
*/
|
|
||||||
#if defined(SAM7X128) || defined(SAM7X256) || defined(SAM7X512)
|
|
||||||
AT91C_BASE_PIOB->PIO_PPUER = config->P1Data.pusr; /* Pull-up as spec.*/
|
|
||||||
AT91C_BASE_PIOB->PIO_PPUDR = ~config->P1Data.pusr;
|
|
||||||
AT91C_BASE_PIOB->PIO_PER = 0xFFFFFFFF; /* PIO enabled.*/
|
|
||||||
AT91C_BASE_PIOB->PIO_ODSR = config->P1Data.odsr; /* Data as specified.*/
|
|
||||||
AT91C_BASE_PIOB->PIO_OER = config->P1Data.osr; /* Dir. as specified.*/
|
|
||||||
AT91C_BASE_PIOB->PIO_ODR = ~config->P1Data.osr;
|
|
||||||
AT91C_BASE_PIOB->PIO_IFDR = 0xFFFFFFFF; /* Filter disabled.*/
|
|
||||||
AT91C_BASE_PIOB->PIO_IDR = 0xFFFFFFFF; /* Int. disabled.*/
|
|
||||||
AT91C_BASE_PIOB->PIO_MDDR = 0xFFFFFFFF; /* Push Pull drive.*/
|
|
||||||
AT91C_BASE_PIOB->PIO_ASR = 0xFFFFFFFF; /* Peripheral A.*/
|
|
||||||
AT91C_BASE_PIOB->PIO_OWER = 0xFFFFFFFF; /* Write enabled.*/
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Pads mode setup.
|
|
||||||
* @details This function programs a pads group belonging to the same port
|
|
||||||
* with the specified mode.
|
|
||||||
*
|
|
||||||
* @param[in] port the port identifier
|
|
||||||
* @param[in] mask the group mask
|
|
||||||
* @param[in] mode the mode
|
|
||||||
*
|
|
||||||
* @note This function is not meant to be invoked directly by the application
|
|
||||||
* code.
|
|
||||||
* @note @p PAL_MODE_RESET is implemented as input with pull-up.
|
|
||||||
* @note @p PAL_MODE_UNCONNECTED is implemented as push pull output with high
|
|
||||||
* state.
|
|
||||||
* @note @p PAL_MODE_OUTPUT_OPENDRAIN also enables the pull-up resistor.
|
|
||||||
*/
|
|
||||||
void _pal_lld_setgroupmode(ioportid_t port,
|
|
||||||
ioportmask_t mask,
|
|
||||||
uint_fast8_t mode) {
|
|
||||||
|
|
||||||
switch (mode & PAL_MODE_MASK) {
|
|
||||||
case PAL_MODE_RESET:
|
|
||||||
case PAL_MODE_INPUT_PULLUP:
|
|
||||||
port->PIO_PPUER = mask;
|
|
||||||
port->PIO_ODR = mask;
|
|
||||||
break;
|
|
||||||
case PAL_MODE_INPUT:
|
|
||||||
case PAL_MODE_INPUT_ANALOG:
|
|
||||||
port->PIO_PPUDR = mask;
|
|
||||||
port->PIO_ODR = mask;
|
|
||||||
break;
|
|
||||||
case PAL_MODE_UNCONNECTED:
|
|
||||||
port->PIO_SODR = mask;
|
|
||||||
/* Falls in */
|
|
||||||
case PAL_MODE_OUTPUT_PUSHPULL:
|
|
||||||
port->PIO_PPUDR = mask;
|
|
||||||
port->PIO_OER = mask;
|
|
||||||
port->PIO_MDDR = mask;
|
|
||||||
break;
|
|
||||||
case PAL_MODE_OUTPUT_OPENDRAIN:
|
|
||||||
port->PIO_PPUER = mask;
|
|
||||||
port->PIO_OER = mask;
|
|
||||||
port->PIO_MDER = mask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @} */
|
|
|
@ -1,251 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS/RT - Copyright (C) 2006-2007 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file AT91SAM7/pal_lld.h
|
|
||||||
* @brief AT91SAM7 PIO low level driver header
|
|
||||||
* @addtogroup AT91SAM7_PAL
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _PAL_LLD_H_
|
|
||||||
#define _PAL_LLD_H_
|
|
||||||
|
|
||||||
#include "board.h"
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Unsupported modes and specific modes */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
#undef PAL_MODE_INPUT_PULLDOWN
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* I/O Ports Types and constants. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief PIO port setup info.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
/** Initial value for ODSR register (data).*/
|
|
||||||
uint32_t odsr;
|
|
||||||
/** Initial value for OSR register (direction).*/
|
|
||||||
uint32_t osr;
|
|
||||||
/** Initial value for PUSR register (Pull-ups).*/
|
|
||||||
uint32_t pusr;
|
|
||||||
} at91sam7_pio_setup_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief AT91SAM7 PIO static initializer.
|
|
||||||
* @details An instance of this structure must be passed to @p palInit() at
|
|
||||||
* system startup time in order to initialized the digital I/O
|
|
||||||
* subsystem. This represents only the initial setup, specific pads
|
|
||||||
* or whole ports can be reprogrammed at later time.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
/** @brief Port 0 setup data.*/
|
|
||||||
at91sam7_pio_setup_t P0Data;
|
|
||||||
#if defined(SAM7X128) || defined(SAM7X256) || defined(SAM7X512) || \
|
|
||||||
defined(__DOXYGEN__)
|
|
||||||
/** @brief Port 1 setup data.*/
|
|
||||||
at91sam7_pio_setup_t P1Data;
|
|
||||||
#endif
|
|
||||||
} AT91SAM7PIOConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Width, in bits, of an I/O port.
|
|
||||||
*/
|
|
||||||
#define PAL_IOPORTS_WIDTH 32
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Digital I/O port sized unsigned type.
|
|
||||||
*/
|
|
||||||
typedef uint32_t ioportmask_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Port Identifier.
|
|
||||||
* @details This type can be a scalar or some kind of pointer, do not make
|
|
||||||
* any assumption about it, use the provided macros when populating
|
|
||||||
* variables of this type.
|
|
||||||
*/
|
|
||||||
typedef AT91PS_PIO ioportid_t;
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* I/O Ports Identifiers. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief PIO port A identifier.
|
|
||||||
*/
|
|
||||||
#define IOPORT1 AT91C_BASE_PIOA
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief PIO port B identifier.
|
|
||||||
*/
|
|
||||||
#if defined(SAM7X128) || defined(SAM7X256) || defined(SAM7X512) || \
|
|
||||||
defined(__DOXYGEN__)
|
|
||||||
#define IOPORT2 AT91C_BASE_PIOB
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Implementation, some of the following macros could be implemented as */
|
|
||||||
/* functions, if so please put them in a file named pal_lld.c. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Low level PAL subsystem initialization.
|
|
||||||
*/
|
|
||||||
#define pal_lld_init(config) _pal_lld_init(config)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Reads the physical I/O port states.
|
|
||||||
* @details This function is implemented by reading the PIO_PDSR register, the
|
|
||||||
* implementation has no side effects.
|
|
||||||
*
|
|
||||||
* @param[in] port the port identifier
|
|
||||||
* @return The port bits.
|
|
||||||
*
|
|
||||||
* @note This function is not meant to be invoked directly by the application
|
|
||||||
* code.
|
|
||||||
*/
|
|
||||||
#define pal_lld_readport(port) ((port)->PIO_PDSR)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Reads the output latch.
|
|
||||||
* @details This function is implemented by reading the PIO_ODSR register, the
|
|
||||||
* implementation has no side effects.
|
|
||||||
*
|
|
||||||
* @param[in] port the port identifier
|
|
||||||
* @return The latched logical states.
|
|
||||||
*
|
|
||||||
* @note This function is not meant to be invoked directly by the application
|
|
||||||
* code.
|
|
||||||
*/
|
|
||||||
#define pal_lld_readlatch(port) ((port)->PIO_ODSR)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Writes a bits mask on a I/O port.
|
|
||||||
* @details This function is implemented by writing the PIO_ODSR register, the
|
|
||||||
* implementation has no side effects.
|
|
||||||
*
|
|
||||||
* @param[in] port the port identifier
|
|
||||||
* @param[in] bits the bits to be written on the specified port
|
|
||||||
*
|
|
||||||
* @note This function is not meant to be invoked directly by the application
|
|
||||||
* code.
|
|
||||||
*/
|
|
||||||
#define pal_lld_writeport(port, bits) { \
|
|
||||||
(port)->PIO_ODSR = (bits); \
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets a bits mask on a I/O port.
|
|
||||||
* @details This function is implemented by writing the PIO_SODR register, the
|
|
||||||
* implementation has no side effects.
|
|
||||||
*
|
|
||||||
* @param[in] port the port identifier
|
|
||||||
* @param[in] bits the bits to be ORed on the specified port
|
|
||||||
*
|
|
||||||
* @note This function is not meant to be invoked directly by the application
|
|
||||||
* code.
|
|
||||||
*/
|
|
||||||
#define pal_lld_setport(port, bits) { \
|
|
||||||
(port)->PIO_SODR = (bits); \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Clears a bits mask on a I/O port.
|
|
||||||
* @details This function is implemented by writing the PIO_CODR register, the
|
|
||||||
* implementation has no side effects.
|
|
||||||
*
|
|
||||||
* @param[in] port the port identifier
|
|
||||||
* @param[in] bits the bits to be cleared on the specified port
|
|
||||||
*
|
|
||||||
* @note This function is not meant to be invoked directly by the application
|
|
||||||
* code.
|
|
||||||
*/
|
|
||||||
#define pal_lld_clearport(port, bits) { \
|
|
||||||
(port)->PIO_CODR = (bits); \
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Writes a group of bits.
|
|
||||||
* @details This function is implemented by writing the PIO_OWER, PIO_ODSR and
|
|
||||||
* PIO_OWDR registers, the implementation is not atomic because the
|
|
||||||
* multiple accesses.
|
|
||||||
*
|
|
||||||
* @param[in] port the port identifier
|
|
||||||
* @param[in] mask the group mask
|
|
||||||
* @param[in] offset the group bit offset within the port
|
|
||||||
* @param[in] bits the bits to be written. Values exceeding the group width
|
|
||||||
* are masked.
|
|
||||||
*
|
|
||||||
* @note This function is not meant to be invoked directly by the application
|
|
||||||
* code.
|
|
||||||
*/
|
|
||||||
#define pal_lld_writegroup(port, mask, offset, bits) { \
|
|
||||||
(port)->PIO_OWER = (mask) << (offset); \
|
|
||||||
(port)->PIO_ODSR = (bits) << (offset); \
|
|
||||||
(port)->PIO_OWDR = (mask) << (offset); \
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Pads group mode setup.
|
|
||||||
* @details This function programs a pads group belonging to the same port
|
|
||||||
* with the specified mode.
|
|
||||||
*
|
|
||||||
* @param[in] port the port identifier
|
|
||||||
* @param[in] mask the group mask
|
|
||||||
* @param[in] mode the mode
|
|
||||||
*
|
|
||||||
* @note This function is not meant to be invoked directly by the application
|
|
||||||
* code.
|
|
||||||
* @note @p PAL_MODE_UNCONNECTED is implemented as push pull output with high
|
|
||||||
* state.
|
|
||||||
*/
|
|
||||||
#define pal_lld_setgroupmode(port, mask, mode) \
|
|
||||||
_pal_lld_setgroupmode(port, mask, mode)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Writes a logical state on an output pad.
|
|
||||||
*
|
|
||||||
* @param[in] port the port identifier
|
|
||||||
* @param[in] pad the pad number within the port
|
|
||||||
* @param[out] bit the logical value, the value must be @p 0 or @p 1
|
|
||||||
*
|
|
||||||
* @note This function is not meant to be invoked directly by the application
|
|
||||||
* code.
|
|
||||||
*/
|
|
||||||
#define pal_lld_writepad(port, pad, bit) pal_lld_writegroup(port, 1, pad, bit)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
void _pal_lld_init(const AT91SAM7PIOConfig *config);
|
|
||||||
void _pal_lld_setgroupmode(ioportid_t port,
|
|
||||||
ioportmask_t mask,
|
|
||||||
uint_fast8_t mode);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* _PAL_LLD_H_ */
|
|
||||||
|
|
||||||
/** @} */
|
|
|
@ -1,85 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS/RT - Copyright (C) 2006-2007 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup AT91SAM7 AT91SAM7 Support
|
|
||||||
* @brief AT91SAM7 specific support.
|
|
||||||
* @details The AT91SAM7 support includes:
|
|
||||||
* - Buffered, interrupt driven, serial driver.
|
|
||||||
* - EMAC driver with MII support.
|
|
||||||
* - A demo supporting the kernel test suite.
|
|
||||||
* - A Web server demo using the uIP TCP/IP stack.
|
|
||||||
* .
|
|
||||||
* @ingroup ARM7
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup AT91SAM7_PAL AT91SAM7 I/O Ports Support
|
|
||||||
* @brief I/O Ports peripherals support.
|
|
||||||
* @details This module supports the AT91SAM7 PIO controller. The controller
|
|
||||||
* supports the following features (see @ref PAL):
|
|
||||||
* - 32 bits wide ports.
|
|
||||||
* - Atomic set/reset functions.
|
|
||||||
* - Output latched regardless of the pad setting.
|
|
||||||
* - Direct read of input pads regardless of the pad setting.
|
|
||||||
* .
|
|
||||||
* <h2>Supported Setup Modes</h2>
|
|
||||||
* - @p PAL_MODE_RESET.
|
|
||||||
* - @p PAL_MODE_UNCONNECTED.
|
|
||||||
* - @p PAL_MODE_INPUT.
|
|
||||||
* - @p PAL_MODE_INPUT_ANALOG (same as @p PAL_MODE_INPUT).
|
|
||||||
* - @p PAL_MODE_INPUT_PULLUP.
|
|
||||||
* - @p PAL_MODE_OUTPUT_PUSHPULL.
|
|
||||||
* - @p PAL_MODE_OUTPUT_OPENDRAIN.
|
|
||||||
* .
|
|
||||||
* Any attempt to setup an invalid mode is ignored.
|
|
||||||
*
|
|
||||||
* <h2>Suboptimal Behavior</h2>
|
|
||||||
* Some PIO features are less than optimal:
|
|
||||||
* - Pad/port toggling operations are not atomic.
|
|
||||||
* - Pad/group mode setup is not atomic.
|
|
||||||
* .
|
|
||||||
* @ingroup AT91SAM7
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup AT91SAM7_SERIAL AT91SAM7 USART Support
|
|
||||||
* @brief USART peripherals support.
|
|
||||||
* @details The serial driver supports the AT91SAM7 USART peripherals.
|
|
||||||
*
|
|
||||||
* @ingroup AT91SAM7
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup AT91SAM7_MAC AT91SAM7 EMAC Support
|
|
||||||
* @brief EMAC peripheral support.
|
|
||||||
* @details the @ref MAC supports the AT91SAM7 EMAC peripheral.
|
|
||||||
*
|
|
||||||
* @ingroup AT91SAM7
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup AT91SAM7_MII AT91SAM7 MII Support
|
|
||||||
* @brief EMAC peripheral support.
|
|
||||||
* @details the @ref MII supports the AT91SAM7 EMAC peripheral communicating
|
|
||||||
* with an external PHY transceiver. The driver currently supports
|
|
||||||
* only the Micrel KS8721 PHY module.
|
|
||||||
*
|
|
||||||
* @ingroup AT91SAM7
|
|
||||||
*/
|
|
|
@ -1,298 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS/RT - Copyright (C) 2006-2007 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file AT91SAM7/serial_lld.c
|
|
||||||
* @brief AT91SAM7 low level serial driver code
|
|
||||||
* @addtogroup AT91SAM7_SERIAL
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ch.h>
|
|
||||||
#include <serial.h>
|
|
||||||
|
|
||||||
#include "at91lib/aic.h"
|
|
||||||
#include "at91sam7.h"
|
|
||||||
|
|
||||||
#if SAM7_PLATFORM == SAM7S256
|
|
||||||
|
|
||||||
#define SAM7_USART0_RX AT91C_PA5_RXD0
|
|
||||||
#define SAM7_USART0_TX AT91C_PA6_TXD0
|
|
||||||
#define SAM7_USART1_RX AT91C_PA21_RXD1
|
|
||||||
#define SAM7_USART1_TX AT91C_PA22_TXD1
|
|
||||||
|
|
||||||
#elif SAM7_PLATFORM == SAM7X256
|
|
||||||
|
|
||||||
#define SAM7_USART0_RX AT91C_PA0_RXD0
|
|
||||||
#define SAM7_USART0_TX AT91C_PA1_TXD0
|
|
||||||
#define SAM7_USART1_RX AT91C_PA5_RXD1
|
|
||||||
#define SAM7_USART1_TX AT91C_PA6_TXD1
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error "serial lines not defined for this SAM7 version"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if USE_SAM7_USART0 || defined(__DOXYGEN__)
|
|
||||||
/** @brief USART0 serial driver identifier.*/
|
|
||||||
SerialDriver SD1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if USE_SAM7_USART1 || defined(__DOXYGEN__)
|
|
||||||
/** @brief USART1 serial driver identifier.*/
|
|
||||||
SerialDriver SD2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** @brief Driver default configuration.*/
|
|
||||||
static const SerialDriverConfig default_config = {
|
|
||||||
38400,
|
|
||||||
AT91C_US_USMODE_NORMAL | AT91C_US_CLKS_CLOCK |
|
|
||||||
AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT
|
|
||||||
};
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Low Level Driver local functions. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART initialization.
|
|
||||||
* @param[in] u pointer to an USART I/O block
|
|
||||||
* @param[in] config the architecture-dependent serial driver configuration
|
|
||||||
*/
|
|
||||||
static void usart_init(AT91PS_USART u, const SerialDriverConfig *config) {
|
|
||||||
|
|
||||||
/* Disables IRQ sources and stop operations.*/
|
|
||||||
u->US_IDR = 0xFFFFFFFF;
|
|
||||||
u->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RSTSTA;
|
|
||||||
|
|
||||||
/* New parameters setup.*/
|
|
||||||
if (config->mr & AT91C_US_OVER)
|
|
||||||
u->US_BRGR = MCK / (config->speed * 8);
|
|
||||||
else
|
|
||||||
u->US_BRGR = MCK / (config->speed * 16);
|
|
||||||
u->US_MR = config->mr;
|
|
||||||
u->US_RTOR = 0;
|
|
||||||
u->US_TTGR = 0;
|
|
||||||
|
|
||||||
/* Enables operations and IRQ sources.*/
|
|
||||||
u->US_CR = AT91C_US_RXEN | AT91C_US_TXEN | AT91C_US_DTREN | AT91C_US_RTSEN;
|
|
||||||
u->US_IER = AT91C_US_RXRDY | AT91C_US_OVRE | AT91C_US_FRAME | AT91C_US_PARE |
|
|
||||||
AT91C_US_RXBRK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART de-initialization.
|
|
||||||
* @param[in] u pointer to an USART I/O block
|
|
||||||
*/
|
|
||||||
static void usart_deinit(AT91PS_USART u) {
|
|
||||||
|
|
||||||
/* Disables IRQ sources and stop operations.*/
|
|
||||||
u->US_IDR = 0xFFFFFFFF;
|
|
||||||
u->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RSTSTA;
|
|
||||||
u->US_MR = 0;
|
|
||||||
u->US_RTOR = 0;
|
|
||||||
u->US_TTGR = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Error handling routine.
|
|
||||||
* @param[in] err USART CSR register value
|
|
||||||
* @param[in] sdp communication channel associated to the USART
|
|
||||||
*/
|
|
||||||
static void set_error(AT91_REG csr, SerialDriver *sdp) {
|
|
||||||
sdflags_t sts = 0;
|
|
||||||
|
|
||||||
if (csr & AT91C_US_OVRE)
|
|
||||||
sts |= SD_OVERRUN_ERROR;
|
|
||||||
if (csr & AT91C_US_PARE)
|
|
||||||
sts |= SD_PARITY_ERROR;
|
|
||||||
if (csr & AT91C_US_FRAME)
|
|
||||||
sts |= SD_FRAMING_ERROR;
|
|
||||||
if (csr & AT91C_US_RXBRK)
|
|
||||||
sts |= SD_BREAK_DETECTED;
|
|
||||||
chSysLockFromIsr();
|
|
||||||
sdAddFlagsI(sdp, sts);
|
|
||||||
chSysUnlockFromIsr();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(__GNU__)
|
|
||||||
__attribute__((noinline))
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* @brief Common IRQ handler.
|
|
||||||
* @param[in] u pointer to an USART I/O block
|
|
||||||
* @param[in] com communication channel associated to the USART
|
|
||||||
*/
|
|
||||||
static void serve_interrupt(AT91PS_USART u, SerialDriver *sdp) {
|
|
||||||
|
|
||||||
if (u->US_CSR & AT91C_US_RXRDY) {
|
|
||||||
chSysLockFromIsr();
|
|
||||||
sdIncomingDataI(sdp, u->US_RHR);
|
|
||||||
chSysUnlockFromIsr();
|
|
||||||
}
|
|
||||||
if (u->US_CSR & AT91C_US_TXRDY) {
|
|
||||||
chSysLockFromIsr();
|
|
||||||
msg_t b = sdRequestDataI(sdp);
|
|
||||||
chSysUnlockFromIsr();
|
|
||||||
if (b < Q_OK)
|
|
||||||
u->US_IDR = AT91C_US_TXRDY;
|
|
||||||
else
|
|
||||||
u->US_THR = b;
|
|
||||||
}
|
|
||||||
if (u->US_CSR & (AT91C_US_OVRE | AT91C_US_FRAME | AT91C_US_PARE | AT91C_US_RXBRK)) {
|
|
||||||
set_error(u->US_CSR, sdp);
|
|
||||||
u->US_CR = AT91C_US_RSTSTA;
|
|
||||||
}
|
|
||||||
AT91C_BASE_AIC->AIC_EOICR = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if USE_SAM7_USART0 || defined(__DOXYGEN__)
|
|
||||||
static void notify1(void) {
|
|
||||||
|
|
||||||
AT91C_BASE_US0->US_IER = AT91C_US_TXRDY;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if USE_SAM7_USART1 || defined(__DOXYGEN__)
|
|
||||||
static void notify2(void) {
|
|
||||||
|
|
||||||
AT91C_BASE_US1->US_IER = AT91C_US_TXRDY;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Low Level Driver interrupt handlers. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
#if USE_SAM7_USART0 || defined(__DOXYGEN__)
|
|
||||||
CH_IRQ_HANDLER(USART0IrqHandler) {
|
|
||||||
|
|
||||||
CH_IRQ_PROLOGUE();
|
|
||||||
|
|
||||||
serve_interrupt(AT91C_BASE_US0, &SD1);
|
|
||||||
|
|
||||||
CH_IRQ_EPILOGUE();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if USE_SAM7_USART1 || defined(__DOXYGEN__)
|
|
||||||
CH_IRQ_HANDLER(USART1IrqHandler) {
|
|
||||||
|
|
||||||
CH_IRQ_PROLOGUE();
|
|
||||||
|
|
||||||
serve_interrupt(AT91C_BASE_US1, &SD2);
|
|
||||||
|
|
||||||
CH_IRQ_EPILOGUE();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Low Level Driver exported functions. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Low level serial driver initialization.
|
|
||||||
*/
|
|
||||||
void sd_lld_init(void) {
|
|
||||||
|
|
||||||
#if USE_SAM7_USART0
|
|
||||||
sdObjectInit(&SD1, NULL, notify1);
|
|
||||||
AT91C_BASE_PIOA->PIO_PDR = SAM7_USART0_RX | SAM7_USART0_TX;
|
|
||||||
AT91C_BASE_PIOA->PIO_ASR = SAM7_USART0_RX | SAM7_USART0_TX;
|
|
||||||
AT91C_BASE_PIOA->PIO_PPUDR = SAM7_USART0_RX | SAM7_USART0_TX;
|
|
||||||
AIC_ConfigureIT(AT91C_ID_US0,
|
|
||||||
AT91C_AIC_SRCTYPE_HIGH_LEVEL | SAM7_USART0_PRIORITY,
|
|
||||||
USART0IrqHandler);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if USE_SAM7_USART1
|
|
||||||
sdObjectInit(&SD2, NULL, notify2);
|
|
||||||
AT91C_BASE_PIOA->PIO_PDR = SAM7_USART1_RX | SAM7_USART1_TX;
|
|
||||||
AT91C_BASE_PIOA->PIO_ASR = SAM7_USART1_RX | SAM7_USART1_TX;
|
|
||||||
AT91C_BASE_PIOA->PIO_PPUDR = SAM7_USART1_RX | SAM7_USART1_TX;
|
|
||||||
AIC_ConfigureIT(AT91C_ID_US1,
|
|
||||||
AT91C_AIC_SRCTYPE_HIGH_LEVEL | SAM7_USART1_PRIORITY,
|
|
||||||
USART1IrqHandler);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Low level serial driver configuration and (re)start.
|
|
||||||
*
|
|
||||||
* @param[in] sdp pointer to a @p SerialDriver object
|
|
||||||
* @param[in] config the architecture-dependent serial driver configuration.
|
|
||||||
* If this parameter is set to @p NULL then a default
|
|
||||||
* configuration is used.
|
|
||||||
*/
|
|
||||||
void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config) {
|
|
||||||
|
|
||||||
if (config == NULL)
|
|
||||||
config = &default_config;
|
|
||||||
|
|
||||||
#if USE_SAM7_USART0
|
|
||||||
if (&SD1 == sdp) {
|
|
||||||
/* Starts the clock and clears possible sources of immediate interrupts.*/
|
|
||||||
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_US0);
|
|
||||||
/* USART initialization.*/
|
|
||||||
usart_init(AT91C_BASE_US0, config);
|
|
||||||
/* Enables associated interrupt vector.*/
|
|
||||||
AIC_EnableIT(AT91C_ID_US0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if USE_SAM7_USART1
|
|
||||||
if (&SD2 == sdp) {
|
|
||||||
/* Starts the clock and clears possible sources of immediate interrupts.*/
|
|
||||||
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_US1);
|
|
||||||
/* USART initialization.*/
|
|
||||||
usart_init(AT91C_BASE_US1, config);
|
|
||||||
/* Enables associated interrupt vector.*/
|
|
||||||
AIC_EnableIT(AT91C_ID_US1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Low level serial driver stop.
|
|
||||||
* @details De-initializes the USART, stops the associated clock, resets the
|
|
||||||
* interrupt vector.
|
|
||||||
*
|
|
||||||
* @param[in] sdp pointer to a @p SerialDriver object
|
|
||||||
*/
|
|
||||||
void sd_lld_stop(SerialDriver *sdp) {
|
|
||||||
|
|
||||||
#if USE_SAM7_USART0
|
|
||||||
if (&SD1 == sdp) {
|
|
||||||
usart_deinit(AT91C_BASE_US0);
|
|
||||||
AT91C_BASE_PMC->PMC_PCDR = (1 << AT91C_ID_US0);
|
|
||||||
AIC_DisableIT(AT91C_ID_US0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if USE_SAM7_USART1
|
|
||||||
if (&SD2 == sdp) {
|
|
||||||
usart_deinit(AT91C_BASE_US1);
|
|
||||||
AT91C_BASE_PMC->PMC_PCDR = (1 << AT91C_ID_US1);
|
|
||||||
AIC_DisableIT(AT91C_ID_US1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @} */
|
|
|
@ -1,157 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS/RT - Copyright (C) 2006-2007 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file AT91SAM7/serial_lld.h
|
|
||||||
* @brief AT91SAM7 low level serial driver header
|
|
||||||
* @addtogroup AT91SAM7_SERIAL
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _SERIAL_LLD_H_
|
|
||||||
#define _SERIAL_LLD_H_
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Driver pre-compile time settings. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Serial buffers size.
|
|
||||||
* @details Configuration parameter, you can change the depth of the queue
|
|
||||||
* buffers depending on the requirements of your application.
|
|
||||||
* @note The default is 128 bytes for both the transmission and receive buffers.
|
|
||||||
*/
|
|
||||||
#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
|
|
||||||
#define SERIAL_BUFFERS_SIZE 128
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief UART0 driver enable switch.
|
|
||||||
* @details If set to @p TRUE the support for USART1 is included.
|
|
||||||
* @note The default is @p TRUE.
|
|
||||||
*/
|
|
||||||
#if !defined(USE_SAM7_USART0) || defined(__DOXYGEN__)
|
|
||||||
#define USE_SAM7_USART0 TRUE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief UART1 driver enable switch.
|
|
||||||
* @details If set to @p TRUE the support for USART2 is included.
|
|
||||||
* @note The default is @p TRUE.
|
|
||||||
*/
|
|
||||||
#if !defined(USE_SAM7_USART1) || defined(__DOXYGEN__)
|
|
||||||
#define USE_SAM7_USART1 TRUE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief UART1 interrupt priority level setting.
|
|
||||||
*/
|
|
||||||
#if !defined(SAM7_USART0_PRIORITY) || defined(__DOXYGEN__)
|
|
||||||
#define SAM7_USART0_PRIORITY (AT91C_AIC_PRIOR_HIGHEST - 2)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief UART2 interrupt priority level setting.
|
|
||||||
*/
|
|
||||||
#if !defined(SAM7_USART1_PRIORITY) || defined(__DOXYGEN__)
|
|
||||||
#define SAM7_USART1_PRIORITY (AT91C_AIC_PRIOR_HIGHEST - 2)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Unsupported event flags and custom events. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Driver data structures and types. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serial Driver condition flags type.
|
|
||||||
*/
|
|
||||||
typedef uint32_t sdflags_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief @p SerialDriver specific data.
|
|
||||||
*/
|
|
||||||
struct _serial_driver_data {
|
|
||||||
/**
|
|
||||||
* Input queue, incoming data can be read from this input queue by
|
|
||||||
* using the queues APIs.
|
|
||||||
*/
|
|
||||||
InputQueue iqueue;
|
|
||||||
/**
|
|
||||||
* Output queue, outgoing data can be written to this output queue by
|
|
||||||
* using the queues APIs.
|
|
||||||
*/
|
|
||||||
OutputQueue oqueue;
|
|
||||||
/**
|
|
||||||
* Status Change @p EventSource. This event is generated when one or more
|
|
||||||
* condition flags change.
|
|
||||||
*/
|
|
||||||
EventSource sevent;
|
|
||||||
/**
|
|
||||||
* I/O driver status flags.
|
|
||||||
*/
|
|
||||||
sdflags_t flags;
|
|
||||||
/**
|
|
||||||
* Input circular buffer.
|
|
||||||
*/
|
|
||||||
uint8_t ib[SERIAL_BUFFERS_SIZE];
|
|
||||||
/**
|
|
||||||
* Output circular buffer.
|
|
||||||
*/
|
|
||||||
uint8_t ob[SERIAL_BUFFERS_SIZE];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief AT91SAM7 Serial Driver configuration structure.
|
|
||||||
* @details An instance of this structure must be passed to @p sdStart()
|
|
||||||
* in order to configure and start a serial driver operations.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
uint32_t speed;
|
|
||||||
uint32_t mr;
|
|
||||||
} SerialDriverConfig;
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* External declarations. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/** @cond never*/
|
|
||||||
#if USE_SAM7_USART0
|
|
||||||
extern SerialDriver SD1;
|
|
||||||
#endif
|
|
||||||
#if USE_SAM7_USART1
|
|
||||||
extern SerialDriver SD2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
void sd_lld_init(void);
|
|
||||||
void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config);
|
|
||||||
void sd_lld_stop(SerialDriver *sdp);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/** @endcond*/
|
|
||||||
|
|
||||||
#endif /* _SERIAL_LLD_H_ */
|
|
||||||
|
|
||||||
/** @} */
|
|
Loading…
Reference in New Issue