/*********************************************************************
*                   (c) SEGGER Microcontroller GmbH                  *
*                        The Embedded Experts                        *
*                           www.segger.com                           *
**********************************************************************

-------------------------- END-OF-HEADER -----------------------------

File    : EnableMonitorModeDebugging.JLinkScript
Purpose : Enable Monitor Mode Debugging
Literature:
  [1]  J-Link User Guide (UM08001_JLink.pdf), chapter "Monitor Mode Debugging"

*/

/*********************************************************************
*
*       Constants (similar to defines)
*
**********************************************************************
*/

/*********************************************************************
*
*       Global functions
*
**********************************************************************
*/

/*********************************************************************
*
*       ConfigTargetSettings()
*
*  Function description
*    Called before InitTarget(). Mainly used to set some global DLL variables to customize the
*    normal connect procedure. For ARM CoreSight devices this may be specifying the base
*    address of some CoreSight components (ETM, …) that cannot be auto-detected by J-Link
*    due to erroneous ROM tables etc. May also be used to specify the device name in case
*    debugger does not pass it to the DLL.
*
*  Return value
*    >= 0:  O.K.
*     < 0:  Error
*
*  Notes
*    (1) May not, under absolutely NO circumstances, call any API functions that perform target
*    (2) Should only set some global DLL variables
*/
int ConfigTargetSettings(void) {
  JLINK_SYS_Report("ConfigTargetSettings(): Enable Monitor Mode Debugging");
  JLINK_ExecCommand("SetMonModeDebug = 1");
  //
  // The offset value below is only valid if you are using softdevice s140_nrf52_7.0.1. 
  // Other versions of the Nordic softdevice might have another vector table offset. For information see Nordic softdevice documentation.
  //
  JLINK_ExecCommand("SetMonModeVTableAddr = 0x26000");  // Needed as the monitor mode interrupts needs to be forwarded, see section "Forwarding of Monitor Interrupts" in the J-Link User Guide (UM08001)
  return 0;
}

/*************************** end of file ****************************/
