/*********************************************************************
*               (c) SEGGER Microcontroller GmbH & Co. KG             *
*                        The Embedded Experts                        *
*                           www.segger.com                           *
**********************************************************************

-------------------------- END-OF-HEADER -----------------------------

File    : Intel_CycloneV_Connect_Core1.JLinkScript
Purpose : Script to connect to core 1
Literature:
  [1]  J-Link User Guide

Additional information:
  For more information about public functions that can be implemented in order to customize J-Link actions, please refer to [1]
*/

/*********************************************************************
*
*       Public code, functions which are called by the DLL
*
**********************************************************************
*/

/*********************************************************************
*
*       ResetTarget
*/
int ResetTarget(void) {
  //
  // Don't do anything when resetting core 1 as doing a system reset would also reset core 0 and we would lose connection to core 1
  // If a specific reset for core 1 is available by design of the device and needed by the user, it is user's responsibility to edit the script file and add this specific reset here
  //
  return 0;
}

/*********************************************************************
*
*       ConfigTargetSettings()
*
*  Function description
*    Called before InitTarget(). Maninly 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 automatically 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.
*
*  Notes
*    (1) May not, under absolutely NO circumstances, call any API functions that perform target communication.
*    (2) Should only set some global DLL variables
*/
int ConfigTargetSettings(void) {
  Report("J-Link script: Altera Cyclone V core 1 J-Link script");
  //
  // Specify the core
  //
  JLINK_CPU=CORTEX_A9;
  //
  // Tell J-Link about what interfaces to the core are available
  // The Cyclone V provides the following access ports (via JTAG and SWD) as debug interfaces:
  // AP[0] = AHB-AP => Can be used for RTT, see application note for restrictions of RTT on Cortex-A/R devices: https://www.segger.com/downloads/appnotes/AN08005_UsingRTTOnCortexAR.pdf
  // AP[1] = APB-AP => Interface to debug the CPUs
  // AP[2] = JTAG-AP
  //
  JLINK_CORESIGHT_AddAP(0, CORESIGHT_AHB_AP);
  JLINK_CORESIGHT_AddAP(1, CORESIGHT_APB_AP);
  JLINK_CORESIGHT_AddAP(2, CORESIGHT_JTAG_AP);
  JLINK_CORESIGHT_IndexAPBAPToUse = 1;  // Cortex-A/R: AP-Index of APB-AP to use for communication with core
  //
  // The Cyclone V provides the following debug components in the APB-AP address space:
  // Component  Addr
  // ETF        0x80001000
  // CTI        0x80002000
  // TPIU       0x80003000
  // CSTF       0x80004000
  // STM        0x80005000
  // ETR        0x80006000
  // CPU0       0x80110000
  // CPU0_PMU   0x80111000
  // CPU1       0x80112000 => This is the core we want to connect to
  // CPU1_PMU   0x80113000
  // CTI0       0x80118000
  // CTI1       0x80119000
  // PTM0       0x8011C000
  // PTM1       0x8011D000
  //
  JLINK_CORESIGHT_CoreBaseAddr = 0x80112000;    // Tell J-Link to which core to connect
  return 0;
}

/*************************** end of file ****************************/
