2015-10-03 01:42:29 +02:00
|
|
|
/****************************************************************************
|
2008-02-16 14:47:29 +01:00
|
|
|
* arch/z80/src/z8/z8_timerisr.c
|
|
|
|
*
|
2017-02-07 17:35:04 +01:00
|
|
|
* Copyright (C) 2008-2009, 2017 Gregory Nutt. All rights reserved.
|
2012-09-13 20:32:24 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2008-02-16 14:47:29 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
|
|
|
*
|
2015-10-03 01:42:29 +02:00
|
|
|
****************************************************************************/
|
2008-02-16 14:47:29 +01:00
|
|
|
|
2015-10-03 01:42:29 +02:00
|
|
|
/****************************************************************************
|
2008-02-16 14:47:29 +01:00
|
|
|
* Included Files
|
2015-10-03 01:42:29 +02:00
|
|
|
****************************************************************************/
|
2008-02-16 14:47:29 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2009-12-16 15:15:34 +01:00
|
|
|
#include <stdint.h>
|
2008-02-16 14:47:29 +01:00
|
|
|
#include <debug.h>
|
2008-02-16 15:48:35 +01:00
|
|
|
#include <ez8.h>
|
2008-02-16 14:47:29 +01:00
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
|
|
|
|
#include "chip/chip.h"
|
2014-08-08 22:43:02 +02:00
|
|
|
#include "clock/clock.h"
|
2008-02-16 14:47:29 +01:00
|
|
|
#include "up_internal.h"
|
|
|
|
|
2015-10-03 01:42:29 +02:00
|
|
|
/****************************************************************************
|
2008-02-16 14:47:29 +01:00
|
|
|
* Public Functions
|
2015-10-03 01:42:29 +02:00
|
|
|
****************************************************************************/
|
2008-02-16 14:47:29 +01:00
|
|
|
|
2008-02-16 15:48:35 +01:00
|
|
|
/* This function is normally prototyped int the ZiLOG header file sio.h */
|
|
|
|
|
2009-12-16 15:15:34 +01:00
|
|
|
extern uint32_t get_freq(void);
|
2008-02-16 15:48:35 +01:00
|
|
|
|
2015-10-03 01:42:29 +02:00
|
|
|
/****************************************************************************
|
2017-02-07 17:35:04 +01:00
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: z8_timerisr
|
2008-02-16 14:47:29 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The timer ISR will perform a variety of services for various portions
|
|
|
|
* of the system.
|
|
|
|
*
|
2015-10-03 01:42:29 +02:00
|
|
|
****************************************************************************/
|
2008-02-16 14:47:29 +01:00
|
|
|
|
2017-02-27 13:27:56 +01:00
|
|
|
static int z8_timerisr(int irq, uint32_t *regs, void *arg)
|
2008-02-16 14:47:29 +01:00
|
|
|
{
|
2017-02-07 17:35:04 +01:00
|
|
|
/* Process timer interrupt */
|
2008-02-16 14:47:29 +01:00
|
|
|
|
2017-02-07 17:35:04 +01:00
|
|
|
sched_process_timer();
|
|
|
|
return 0;
|
2008-02-16 14:47:29 +01:00
|
|
|
}
|
|
|
|
|
2015-10-03 01:42:29 +02:00
|
|
|
/****************************************************************************
|
2017-02-07 17:35:04 +01:00
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: z80_timer_initialize
|
2008-02-16 14:47:29 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called during start-up to initialize the timer
|
|
|
|
* interrupt.
|
|
|
|
*
|
2015-10-03 01:42:29 +02:00
|
|
|
****************************************************************************/
|
2008-02-16 14:47:29 +01:00
|
|
|
|
2017-02-07 17:35:04 +01:00
|
|
|
void z80_timer_initialize(void)
|
2008-02-16 14:47:29 +01:00
|
|
|
{
|
2009-12-16 15:15:34 +01:00
|
|
|
uint32_t reload;
|
2014-04-14 00:22:22 +02:00
|
|
|
|
2008-02-16 14:47:29 +01:00
|
|
|
up_disable_irq(Z8_IRQ_SYSTIMER);
|
|
|
|
|
|
|
|
/* Write to the timer control register to disable the timer, configure
|
|
|
|
* the timer for continuous mode, and set up the pre-scale value for
|
|
|
|
* divide by 4.
|
|
|
|
*/
|
|
|
|
|
2008-02-16 15:48:35 +01:00
|
|
|
putreg8((Z8_TIMERCTL_DIV4|Z8_TIMERCTL_CONT), T0CTL);
|
2008-02-16 14:47:29 +01:00
|
|
|
|
|
|
|
/* Write to the timer high and low byte registers to set a starting
|
|
|
|
* count value (this effects only the first pass in continuous mode)
|
|
|
|
*/
|
|
|
|
|
2008-02-16 15:48:35 +01:00
|
|
|
putreg16(0x0001, T0);
|
2008-02-16 14:47:29 +01:00
|
|
|
|
|
|
|
/* Write to the timer reload register to set the reload value.
|
|
|
|
*
|
|
|
|
* In continuous mode:
|
|
|
|
*
|
|
|
|
* timer_period = reload_value x prescale / system_clock_frequency
|
|
|
|
* or
|
|
|
|
* reload_value = (timer_period * system_clock_frequency) / prescale
|
|
|
|
*
|
|
|
|
* For system_clock_frequency=18.432MHz, timer_period=10mS, and prescale=4,
|
|
|
|
* then reload_value=46,080 - OR:
|
|
|
|
*
|
|
|
|
* reload_value = system_clock_frequency / 400
|
|
|
|
*/
|
|
|
|
|
2008-02-16 15:48:35 +01:00
|
|
|
reload = get_freq() / 400;
|
2009-12-16 15:15:34 +01:00
|
|
|
putreg16((uint16_t)reload, T0R);
|
2008-02-16 14:47:29 +01:00
|
|
|
|
|
|
|
/* Write to the timer control register to enable the timer and to
|
|
|
|
* initiate counting
|
|
|
|
*/
|
|
|
|
|
2008-02-16 15:48:35 +01:00
|
|
|
putreg8((getreg8(T0CTL)|Z8_TIMERCTL_TEN), T0CTL);
|
2008-02-16 14:47:29 +01:00
|
|
|
|
|
|
|
/* Set the timer priority */
|
|
|
|
|
|
|
|
/* Attach and enable the timer interrupt (leaving at priority 0 */
|
|
|
|
|
2017-02-27 13:27:56 +01:00
|
|
|
irq_attach(Z8_IRQ_SYSTIMER, (xcpt_t)z8_timerisr, NULL);
|
2008-02-16 14:47:29 +01:00
|
|
|
up_enable_irq(Z8_IRQ_SYSTIMER);
|
|
|
|
}
|
|
|
|
|