I am developing software for MC9SG8S08 microcontroller from HCS08 family. I have to implement logic that will detect microcontroller is in active background mode or not ? I read usermanual and I couldn't find any register that specifies this.
Is there any way to implement this?
Looks like you don't understand what is active background mode. It is when MCU is stopped and listening BKGD pin for BDC commands like GO, TRACE1, etc. When active, your code is not running, it just can't read or write anything!
Since average debugger should use debug module, checking whether DBGEN bit is set has chances to prove activity on BKGD pin. But silent debugger, which just reads memory and registers, is not detectable.
If you are meaning that you wish to have the firmware running in the microcontroller be able to detect that the Background Debug Mode has been made active through the DBG interface, you cannot do this. The debugger controller and its registers are not within the CPU device's memory space (intentionally). IDeally, you want the debug operation to appear invisible to the code being debugged, and also prevent a mishap in the code from putting the CPU into DBG mode while the application is running in the field. This is how it has been implemented. The BDM application notes do provide command syntax for reading and accessing the debugger control registers from the DBG pin interface - if you wish to make a PC-based application to control it.