/******************************************************************************/
/* MTB.ini: Initialization Script for Cortex-M0+ MTB(Micro Trace Buffer)      */
/******************************************************************************/
// <<< Use Configuration Wizard in Context Menu >>>                           // 
/******************************************************************************/
/* This file is part of the uVision/ARM development tools.                    */
/* Copyright (c) 2005-2012 Keil Software. All rights reserved.                */
/* This software may only be used under the terms of a valid, current,        */
/* end user licence from KEIL for a compatible version of KEIL software       */
/* development tools. Nothing else gives you the right to use this software.  */
/******************************************************************************/


FUNC void MTB_Setup (void) {
  unsigned long position;
  unsigned long master;
  unsigned long watermark;
  unsigned long _flow;

// <e0.31> Trace: MTB (Micro Trace Buffer)
//   <o0.0..4> Buffer Size
//     <4=>  256B
//     <5=>  512B
//     <6=>   1kB
//     <7=>   2kB
//     <8=>   4kB
//   <o1>   Buffer Position
//     <i> Buffer position in RAM. Must be a multiple of the buffer size.
//   <o2.0> Stop Trace when buffer is full
//   <o2.1> Stop Target when buffer is full
// </e>
  master     = 0x80000005;
  position   = 0x10000E00;
  _flow      = 0x00000000;

  position  &= 0xFFFFFFF8;              // Mask POSITION.POINTER field
  watermark  = position + ((16 << (master & 0x1F)) - 32);
  _flow     |= watermark;

  _WDWORD(0x14000004, 0x00000000);      // MASTER
  _WDWORD(0x14000000, position);        // POSITION
  _WDWORD(0x14000008, _flow);           // FLOW
  _WDWORD(0x14000004, master);          // MASTER
}


MTB_Setup();
