2008-04-02 05:17:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Michael Sevakis
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2008-04-02 05:17:05 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2008-02-05 04:43:19 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "avic-imx31.h"
|
2008-04-11 08:51:27 +00:00
|
|
|
#include "spi-imx31.h"
|
|
|
|
#include "mc13783.h"
|
2009-03-22 02:13:27 +00:00
|
|
|
#include "ccm-imx31.h"
|
2009-02-08 22:32:41 +00:00
|
|
|
#include "sdma-imx31.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
#include "thread.h"
|
|
|
|
|
2008-02-05 04:43:19 +00:00
|
|
|
static __attribute__((interrupt("IRQ"))) void EPIT1_HANDLER(void)
|
|
|
|
{
|
2008-04-02 05:17:05 +00:00
|
|
|
EPITSR1 = EPITSR_OCIF; /* Clear the pending status */
|
2008-02-05 04:43:19 +00:00
|
|
|
|
2007-09-21 15:51:53 +00:00
|
|
|
/* Run through the list of tick tasks */
|
2008-10-27 16:30:24 +00:00
|
|
|
call_tick_tasks();
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
2008-02-05 04:43:19 +00:00
|
|
|
|
|
|
|
void tick_start(unsigned int interval_in_ms)
|
|
|
|
{
|
2009-03-22 01:50:48 +00:00
|
|
|
ccm_module_clock_gating(CG_EPIT1, CGM_ON_RUN_WAIT); /* EPIT1 module
|
2008-04-11 08:51:27 +00:00
|
|
|
clock ON - before writing
|
|
|
|
regs! */
|
2008-04-02 05:17:05 +00:00
|
|
|
EPITCR1 &= ~(EPITCR_OCIEN | EPITCR_EN); /* Disable the counter */
|
2009-03-22 01:50:48 +00:00
|
|
|
CCM_WIMR0 &= ~CCM_WIMR0_IPI_INT_EPIT1; /* Clear wakeup mask */
|
2008-02-05 04:43:19 +00:00
|
|
|
|
2008-04-02 05:17:05 +00:00
|
|
|
/* mcu_main_clk = 528MHz = 27MHz * 2 * ((9 + 7/9) / 1)
|
|
|
|
* CLKSRC = ipg_clk = 528MHz / 4 / 2 = 66MHz,
|
|
|
|
* EPIT Output Disconnected,
|
|
|
|
* Enabled in wait mode
|
|
|
|
* Prescale 1/2640 for 25KHz
|
|
|
|
* Reload from modulus register,
|
|
|
|
* Compare interrupt enabled,
|
2008-02-05 04:43:19 +00:00
|
|
|
* Count from load value */
|
2008-04-02 05:17:05 +00:00
|
|
|
EPITCR1 = EPITCR_CLKSRC_IPG_CLK | EPITCR_WAITEN | EPITCR_IOVW |
|
2009-03-22 01:50:48 +00:00
|
|
|
(2640-1) << EPITCR_PRESCALER_POS | EPITCR_RLD | EPITCR_OCIEN |
|
2008-04-02 05:17:05 +00:00
|
|
|
EPITCR_ENMOD;
|
|
|
|
|
|
|
|
EPITLR1 = interval_in_ms*25; /* Count down from interval */
|
|
|
|
EPITCMPR1 = 0; /* Event when counter reaches 0 */
|
|
|
|
EPITSR1 = EPITSR_OCIF; /* Clear any pending interrupt */
|
2009-03-22 01:50:48 +00:00
|
|
|
avic_enable_int(INT_EPIT1, INT_TYPE_IRQ, INT_PRIO_DEFAULT,
|
|
|
|
EPIT1_HANDLER);
|
2008-04-02 05:17:05 +00:00
|
|
|
EPITCR1 |= EPITCR_EN; /* Enable the counter */
|
2008-02-05 04:43:19 +00:00
|
|
|
}
|
2008-02-08 02:20:05 +00:00
|
|
|
|
2008-04-11 08:51:27 +00:00
|
|
|
void kernel_device_init(void)
|
|
|
|
{
|
2009-02-08 22:32:41 +00:00
|
|
|
sdma_init();
|
2008-04-11 08:51:27 +00:00
|
|
|
spi_init();
|
|
|
|
mc13783_init();
|
|
|
|
}
|
|
|
|
|
2008-02-08 02:20:05 +00:00
|
|
|
#ifdef BOOTLOADER
|
|
|
|
void tick_stop(void)
|
|
|
|
{
|
2009-03-22 01:50:48 +00:00
|
|
|
avic_disable_int(INT_EPIT1); /* Disable insterrupt */
|
2008-04-02 05:17:05 +00:00
|
|
|
EPITCR1 &= ~(EPITCR_OCIEN | EPITCR_EN); /* Disable counter */
|
2008-04-11 08:51:27 +00:00
|
|
|
EPITSR1 = EPITSR_OCIF; /* Clear pending */
|
2009-03-22 01:50:48 +00:00
|
|
|
ccm_module_clock_gating(CG_EPIT1, CGM_OFF); /* Turn off module clock */
|
2008-02-08 02:20:05 +00:00
|
|
|
}
|
|
|
|
#endif
|