// (C) 2020 Philip Endecott.
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENCE.txt or copy at https://www.boost.org/LICENSE_1_0.txt

#ifndef lipstick_cpu_hh
#define lipstick_cpu_hh

#include "registers.hh"
#include "clocks.hh"


inline void setup_memmap()
{
  // Map the vectors from flash.  This is not the default and is 
  // essential for interrupts to function.
  *MEMMAP = 1;
}


inline void setup_mam()
{
  // Note that the default is the pessimistic 7 cycles, so this gives 
  // a substantial performance boost.
  int cycles;
  if      constexpr (f_cclk < 20'000'000) cycles = 1;
  else if constexpr (f_cclk < 40'000'000) cycles = 2;
  else if constexpr (f_cclk < 60'000'000) cycles = 3;
  else                                    cycles = 4;
  *MAMTIM = cycles;
  *MAMCR = 0b10;  // "fully enabled".
}


inline void idle()
{
  *PCON = 1;
}


#endif

