Skip to content
Permalink
b2b2aaaf68
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
143 lines (130 sloc) 5.13 KB
/*********************************************************************
* (c) SEGGER Microcontroller GmbH & Co. KG *
* The Embedded Experts *
* www.segger.com *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
File : Main.c
Purpose : Main application to demonstrate monitor mode debugging with J-Link,
while keeping certain interrupts firing when main application is halted.
*/
#define MAIN_C
/*********************************************************************
*
* Defines, fixed
*
**********************************************************************
*/
#define SYSTICK ((SYSTICK_REGS*)0xE000E010)
#define SCS ((SCS_REGS*)0xE000ED00)
/*********************************************************************
*
* Types, local
*
**********************************************************************
*/
typedef struct {
volatile unsigned int CSR;
volatile unsigned int RVR;
volatile unsigned int CVR;
volatile unsigned int CALIB;
} SYSTICK_REGS;
typedef struct {
volatile unsigned int CPUID; // CPUID Base Register
volatile unsigned int ICSR; // Interrupt Control and State Register
volatile unsigned int VTOR; // Vector Table Offset Register
volatile unsigned int AIRCR; // Application Interrupt and Reset Control Register
volatile unsigned int SCR; // System Control Register
volatile unsigned int CCR; // Configuration and Control Register
volatile unsigned int SHPR1; // System Handler Priority Register 1
volatile unsigned int SHPR2; // System Handler Priority Register 2
volatile unsigned int SHPR3; // System Handler Priority Register 3
volatile unsigned int SHCSR; // System Handler Control and State Register
volatile unsigned int CFSR; // Configurable Fault Status Register
volatile unsigned int HFSR; // HardFault Status Register
volatile unsigned int DFSR; // Debug Fault Status Register
volatile unsigned int MMFAR; // MemManage Fault Address Register
volatile unsigned int BFAR; // BusFault Address Register
volatile unsigned int AFSR; // Auxiliary Fault Status Register
volatile unsigned int aDummy0[4]; // 0x40-0x4C Reserved
volatile unsigned int aDummy1[4]; // 0x50-0x5C Reserved
volatile unsigned int aDummy2[4]; // 0x60-0x6C Reserved
volatile unsigned int aDummy3[4]; // 0x70-0x7C Reserved
volatile unsigned int aDummy4[2]; // 0x80-0x87 - - - Reserved.
volatile unsigned int CPACR; // Coprocessor Access Control Register
} SCS_REGS;
/*********************************************************************
*
* Global data
*
**********************************************************************
*/
volatile int MAIN_AppCnt; // Incremented by user application
volatile int MAIN_TckCnt; // Incremented by user application
/*********************************************************************
*
* Global functions
*
**********************************************************************
*/
/*********************************************************************
*
* SysTick_Handler()
*
* Function description
* Interrupt service routine called by SysTick interrupt.
*
* Notes
* (1) As it is configured in main() with a higher priority than the debug monitor, this routine cannot be debugged in monitor mode
*/
void SysTick_Handler(void);
void SysTick_Handler(void) {
MAIN_TckCnt++;
}
/*********************************************************************
*
* main
*/
void main(void) {
unsigned int v;
//
// Increment MAIN_AppCnt while user application is running
// Increment MAIN_MonCnt while application is halted and monitor is running
// Always increment MAIN_TckCnt (no matter if in monitor or not)
//
//
// Configure SysTick and debug monitor interrupt priorities
// Low value means high priority
// A maximum of 8 priority bits and a minimum of 3 bits is implemented per interrupt.
// How many bits are implemented depends on the actual CPU being used
// If less than 8 bits are supported, the lower bits of the priority byte are RAZ.
// In order to make sure that priority of monitor and SysTick always differ, please make sure that the difference is visible in the highest 3 bits
//
v = SCS->SHPR3;
v |= (0xFF << 0); // Set priority of debug monitor to lowest priority so all interrupts keep firing while application is halted
v &= ~(0xFFuL << 24); // Highest prio for SysTick
// v |= (0x80uL << 24); // Set higher priority for SysTick than for debug monitor
SCS->SHPR3 = v;
//
// Configure SysTick interrupt
//
SYSTICK->RVR = 0xFFFF; // set reload
SYSTICK->CVR = 0x00; // set counter
SYSTICK->CSR = 0x07; // enable systick
//
// Main application
//
do {
MAIN_AppCnt++;
MAIN_AppCnt++;
MAIN_AppCnt++;
MAIN_AppCnt++;
MAIN_AppCnt++;
MAIN_AppCnt++;
MAIN_AppCnt++;
MAIN_AppCnt++;
MAIN_AppCnt++;
MAIN_AppCnt++;
MAIN_AppCnt++;
} while(1);
}