Skip to content

Commit

Permalink
arch/arm/src/am335x: Add clock module registers definition. Switch to…
Browse files Browse the repository at this point in the history
… DMTIMER1 for systick.
  • Loading branch information
pkarashchenko authored and gregory-nutt committed Jul 3, 2019
1 parent 03fe07c commit 55026f2
Show file tree
Hide file tree
Showing 3 changed files with 404 additions and 23 deletions.
36 changes: 32 additions & 4 deletions arch/arm/src/am335x/am335x_clockconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,39 @@
#include <nuttx/config.h>

#include "up_arch.h"
#if 0
/* TODO: add clock register module */
#include "hardware/am335x_ccm.h"
#endif
#include "hardware/am335x_cm.h"
#include "am335x_config.h"
#include "am335x_clockconfig.h"

/****************************************************************************
* Private Functions
****************************************************************************/

/****************************************************************************
* Name: am335x_dmtimer1ms_clockconfig
****************************************************************************/

static inline void am335x_dmtimer1ms_clockconfig(void)
{
putreg32(CM_DPLL_DMTIMER1_CLKSEL_CLK_M_OSC,
AM335X_CM_DPLL_CLKSEL_TIMER1MS_CLK);

while ((getreg32(AM335X_CM_DPLL_CLKSEL_TIMER1MS_CLK) &
CM_DPLL_DMTIMER1MS_CLKSEL_MASK)
!= CM_DPLL_DMTIMER1_CLKSEL_CLK_M_OSC)
{
}

modifyreg32(AM335X_CM_WKUP_TIMER1_CLKCTRL, CM_WKUP_CLKCTRL_MODULEMODE_MASK,
CM_WKUP_CLKCTRL_MODULEMODE_ENABLE);

while ((getreg32(AM335X_CM_WKUP_TIMER1_CLKCTRL) &
(CM_WKUP_CLKCTRL_MODULEMODE_MASK | CM_WKUP_CLKCTRL_IDLEST_MASK))
!= (CM_WKUP_CLKCTRL_MODULEMODE_ENABLE | CM_WKUP_CLKCTRL_IDLEST_FUNC))
{
}
}

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -75,6 +101,8 @@ void am335x_clockconfig(void)
* 792MHz.
*/

am335x_dmtimer1ms_clockconfig();

#ifndef CONFIG_AM335X_BOOT_SDRAM
# warning Missing logic
#endif
Expand Down
23 changes: 4 additions & 19 deletions arch/arm/src/am335x/am335x_timerisr.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,15 @@
#include "up_arch.h"
#include "hardware/am335x_timer.h"

#define USE_TIMER1MS

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#ifdef USE_TIMER1MS
/* Timer 1 clock selects the external 32.768 KHz oscillator/clock */

# define TMR_CLOCK (32768)

#else
/* Timer clock selects system clock CLK_M_OSC (24MHz) */

# define TMR_CLOCK (24000000ll)
#endif

/* The desired timer interrupt frequency is provided by the definition
* CLK_TCK (see include/time.h). CLK_TCK defines the desired number of
Expand All @@ -78,21 +73,12 @@
#define TMR_TLDR (0xffffffff - (TMR_CLOCK / CLK_TCK) + 1)
#define TMR_TCRR (0xffffffff - (TMR_CLOCK / CLK_TCK) + 1)

#ifdef USE_TIMER1MS
# define TMR_TPIR \
(((TMR_CLOCK / CLK_TCK + 1) * 1000000l) - \
(TMR_CLOCK * (1000000l / CLK_TCK)))
# define TMR_TNIR \
(((TMR_CLOCK / CLK_TCK) * 1000000l) - \
(TMR_CLOCK * (1000000l / CLK_TCK)))
#else
# define TMR_TPIR \
#define TMR_TPIR \
(((TMR_CLOCK / CLK_TCK + 1) * 1000000ll) - \
(TMR_CLOCK * (1000000ll / CLK_TCK)))
# define TMR_TNIR \
#define TMR_TNIR \
(((TMR_CLOCK / CLK_TCK) * 1000000ll) - \
(TMR_CLOCK * (1000000ll / CLK_TCK)))
#endif

/****************************************************************************
* Private Functions
Expand Down Expand Up @@ -214,6 +200,5 @@ void arm_timer_initialize(void)
/* And enable the timer interrupt */

up_enable_irq(AM335X_IRQ_TIMER2);

#endif
}
Loading

0 comments on commit 55026f2

Please sign in to comment.