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

master
gdisirio 2008-02-18 15:53:48 +00:00
parent fd63d45d5f
commit 53b6f6d8df
5 changed files with 266 additions and 22 deletions

View File

@ -68,6 +68,7 @@ ASRC = ../../ports/ARM7-LPC214x/GCC/chcore.c \
../../src/chevents.c ../../src/chmsg.c ../../src/chsleep.c ../../src/chqueues.c \
../../src/chserial.c \
../../src/lib/evtimer.c ../../test/test.c \
at91lib\aic.c \
board.c main.c
# List THUMB-mode C sources here

View File

@ -0,0 +1,84 @@
/* ----------------------------------------------------------------------------
* 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;
}

View File

@ -0,0 +1,78 @@
/* ----------------------------------------------------------------------------
* 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

View File

@ -19,7 +19,8 @@
#include <ch.h>
#include "at91lib/AT91SAM7X256.h"
#include "board.h"
#include "at91lib/aic.h"
extern void FiqHandler(void);
@ -29,10 +30,24 @@ static void SpuriousHandler(void) {
AT91C_BASE_AIC->AIC_EOICR = (AT91_REG)AT91C_BASE_AIC;
}
/*
* Timer 0 IRQ handling here.
*/
__attribute__((naked))
static void SYSIrqHandler(void) {
chSysIRQEnterI();
if (AT91C_BASE_PITC->PITC_PISR & AT91C_PITC_PITS) {
chSysTimerHandlerI();
(void) AT91C_BASE_PITC->PITC_PIVR;
}
chSysIRQExitI();
}
void hwinit(void) {
int i;
AT91PS_PMC pmcp = AT91C_BASE_PMC;
AT91PS_AIC aicp = AT91C_BASE_AIC;
/*
* Flash Memory: 1 wait state, about 50 cycles in a microsecond.
@ -47,40 +62,71 @@ void hwinit(void) {
/*
* Enables the main oscillator and waits 56 slow cycles as startup time.
*/
pmcp->PMC_MOR = (AT91C_CKGR_OSCOUNT & (7 << 8)) | AT91C_CKGR_MOSCEN;
while (!(pmcp->PMC_SR & AT91C_PMC_MOSCS))
AT91C_BASE_PMC->PMC_MOR = (AT91C_CKGR_OSCOUNT & (7 << 8)) | AT91C_CKGR_MOSCEN;
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS))
;
/*
* PLL setup: DIV = 14, MUL = 72, PLLCOUNT = 10
* PLLfreq = 96109714 Hz (rounded)
*/
pmcp->PMC_PLLR = (AT91C_CKGR_DIV & 14) |
AT91C_BASE_PMC->PMC_PLLR = (AT91C_CKGR_DIV & 14) |
(AT91C_CKGR_PLLCOUNT & (10 << 8)) |
(AT91C_CKGR_MUL & (72 << 16));
while (!(pmcp->PMC_SR & (AT91C_PMC_LOCK)))
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK))
;
/*
* Master clock = PLLfreq / 2 = 48054858 Hz (rounded)
*/
pmcp->PMC_MCKR = AT91C_PMC_CSS_PLL_CLK | AT91C_PMC_PRES_CLK_2;
while (!(pmcp->PMC_SR & (AT91C_PMC_MCKRDY)))
AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_PLL_CLK | AT91C_PMC_PRES_CLK_2;
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY))
;
/*
* Default AIC setup, the device drivers will modify it as needed.
*/
aicp->AIC_SVR[0] = (AT91_REG)FiqHandler;
for (i = 1; i < 31; i++) {
aicp->AIC_SVR[i] = (AT91_REG)NULL;
aicp->AIC_EOICR = (AT91_REG)i;
}
aicp->AIC_SPU = (AT91_REG)SpuriousHandler;
/*
* I/O setup, enable clocks, initially all pins are inputs with pullups.
*/
pmcp->PMC_PCER = (1 << AT91C_ID_PIOA) | (1 << AT91C_ID_PIOB);
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOA) | (1 << AT91C_ID_PIOB);
AT91C_BASE_PIOA->PIO_PER = 0xFFFFFFFF;
AT91C_BASE_PIOB->PIO_PER = 0xFFFFFFFF;
/*
* Default AIC setup, the device drivers will modify it as needed.
*/
AT91C_BASE_AIC->AIC_ICCR = 0xFFFFFFFF;
AT91C_BASE_AIC->AIC_SVR[0] = (AT91_REG)FiqHandler;
for (i = 1; i < 31; i++) {
AT91C_BASE_AIC->AIC_SVR[i] = (AT91_REG)NULL;
AT91C_BASE_AIC->AIC_EOICR = (AT91_REG)i;
}
AT91C_BASE_AIC->AIC_SPU = (AT91_REG)SpuriousHandler;
/*
* LCD pins setup.
*/
AT91C_BASE_PIOB->PIO_SODR = PIOB_LCD_BL; // Set to high.
AT91C_BASE_PIOB->PIO_OER = PIOB_LCD_BL; // Configure as output.
AT91C_BASE_SYS->PIOA_PPUDR = PIOB_LCD_BL; // Disable internal pullup resistor.
AT91C_BASE_PIOA->PIO_SODR = PIOA_LCD_RESET; // Set to high.
AT91C_BASE_PIOA->PIO_OER = PIOA_LCD_RESET; // Configure as output.
AT91C_BASE_SYS->PIOB_PPUDR = PIOA_LCD_RESET; // Disable internal pullup resistor.
/*
* Joystick and buttons, disable pullups, already inputs.
*/
AT91C_BASE_SYS->PIOA_PPUDR = PIOA_B1 | PIOA_B2 | PIOA_B3 | PIOA_B4 | PIOA_B5;
AT91C_BASE_SYS->PIOB_PPUDR = PIOB_SW1 | PIOB_SW2;
/*
* MMC/SD slot, disable pullups, already inputs.
*/
AT91C_BASE_SYS->PIOB_PPUDR = PIOB_MMC_WP | PIOB_MMC_CP;
/*
* PIT Initialization.
*/
AIC_ConfigureIT(AT91C_ID_SYS, AT91C_AIC_SRCTYPE_POSITIVE_EDGE, SYSIrqHandler);
AT91C_BASE_PITC->PITC_PIMR = (MCK / 16 / CH_FREQUENCY) - 1;
AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN | AT91C_PITC_PITIEN;
}

View File

@ -20,7 +20,42 @@
#ifndef _BOARD_H_
#define _BOARD_H_
#ifndef AT91SAM7X256_H
#include "at91lib/AT91SAM7X256.h"
#endif
#define BOARD_OLIMEX_SAM7_EX256
#define MCK 18432000
/*
* I/O definitions.
*/
#define PIOA_LCD_RESET (1 << 2)
#define PIOA_B1 (1 << 7)
#define PIOA_B2 (1 << 8)
#define PIOA_B3 (1 << 9)
#define PIOA_B4 (1 << 14)
#define PIOA_B5 (1 << 15)
#define PIOA_USB_PUP (1 << 25)
#define PIOA_USB_PR (1 << 26)
#define PIOA_PA27 (1 << 27)
#define PIOA_PA28 (1 << 28)
#define PIOA_PA29 (1 << 29)
#define PIOA_PA30 (1 << 30)
#define PIOB_PHY_PD (1 << 18)
#define PIOB_AUDIO_OUT (1 << 19)
#define PIOB_LCD_BL (1 << 20)
#define PIOB_PB21 (1 << 21)
#define PIOB_MMC_WP (1 << 22)
#define PIOB_MMC_CP (1 << 23)
#define PIOB_SW1 (1 << 24)
#define PIOB_SW2 (1 << 25)
#define PIOB_PHY_IRQ (1 << 26)
#define PIOB_PB27_AD0 (1 << 27)
#define PIOB_PB27_AD1 (1 << 28)
#define PIOB_PB27_AD2 (1 << 29)
#define PIOB_PB27_AD3 (1 << 30)
#endif /* _BOARD_H_ */