2015-10-03 01:42:29 +02:00
|
|
|
/****************************************************************************
|
2008-02-16 14:47:29 +01:00
|
|
|
* arch/z80/src/z8/z8_timerisr.c
|
|
|
|
*
|
2021-03-28 18:04:41 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2008-02-16 14:47:29 +01:00
|
|
|
*
|
2021-03-28 18:04:41 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-02-16 14:47:29 +01:00
|
|
|
*
|
2021-03-28 18:04:41 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-02-16 14:47:29 +01:00
|
|
|
*
|
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>
|
|
|
|
|
2019-06-02 23:36:38 +02:00
|
|
|
#include "chip.h"
|
2014-08-08 22:43:02 +02:00
|
|
|
#include "clock/clock.h"
|
2019-06-10 03:08:42 +02:00
|
|
|
#include "z80_internal.h"
|
2008-02-16 14:47:29 +01:00
|
|
|
|
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
|
|
|
|
2019-03-21 02:27:40 +01:00
|
|
|
nxsched_process_timer();
|
2017-02-07 17:35:04 +01:00
|
|
|
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
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-02-07 08:14:06 +01:00
|
|
|
* Function: up_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
|
|
|
|
2020-02-07 08:14:06 +01:00
|
|
|
void up_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.
|
|
|
|
*/
|
|
|
|
|
2021-03-29 21:21:50 +02: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
|
|
|
|
*/
|
|
|
|
|
2021-03-29 21:21:50 +02:00
|
|
|
reload = get_freq() / 400;
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2021-03-29 21:21:50 +02: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);
|
|
|
|
}
|