Problem to achieve the functionality of  COP in mc9s12xdp512

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Problem to achieve the functionality of  COP in mc9s12xdp512

2,970件の閲覧回数
Seema
Contributor I
Hello,
 
I am facing a problem o achieve the functionality of COP with  mc9s12xdp512 controller
 
I am trying to test the COP functionality and the code is as follows,
 
void main(void) {
 
  DDRB = 0x0F; /* for port initialization */
 
  COPCTL =  0x07; /* cop initialization*/
  

  /* put your own code here */
  EnableInterrupts;
  asm_main(); /* call the assembly function */
 
  for(;:smileywink:
 {
      /* infinite loop to achieve the watchdog interrupt*/
 
  } /* wait forever */
  /* please make sure that you never leave this function */
}
 
/* watchdog interrupt function added in the vector table*/
void WDG_RESET_ISR(void)  / * ISR for COP, and is at initialised at  VECTOR 2 */
{
    PORTB_PB0 = 0x01;  /* Port B0 should  glow when this ISR is called*/ 
}
 
In the main code i have set (enable)the COP(0x07) with count for 4sec for 4MHz oscillator . but i observe that after 4 seconds COPCTL becomes 0x00 and it goes to inifinite loop and if i observe in debugger that it goes to LDS instruction with address 0xFFFF (unknow ) location, and stays in inifinte loop.
 
In the above code I have done the timeout by using the "for loop"
 
But i actuall want an WDG_RESET_ISR function to be call and the port B0 to glow on COP timeout.
 
Please let me know whether there are any other register to be taken care or i have not implemented it correctly.
 
Thanks,
Seema
ラベル(1)
0 件の賞賛
返信
7 返答(返信)

1,120件の閲覧回数
kef
Specialist I
COP causes not interrupt but a full hardware reset. Pins direction registers are also reset. So to glow PORTB LED in your COP routine you should not only write to PORTB, but also init DDRB again and loop in your COP routine forever or jump to _Startup routine.
0 件の賞賛
返信

1,120件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
A few notes
- The cop handler should not return.
  In  real code, you could call _Startup to follow the same path as on power up, in your test case you could just add an endless loop (which would cause another COP after 4 seconds)
-  a COP reset will reset all registers, so set DDRB in WDG_RESET_ISR too.

Daniel
0 件の賞賛
返信

1,120件の閲覧回数
Seema
Contributor I
Hello Daniel and Hello Kef,
 
Thanks for the quick reply.refering to the above mail.
 
I am presently using codewarior 4.6 for the implementation of the COP.
 
1. Now I have called _Startup in my COP ISR in interrupt vector table.
 
2. But I observe that WCOP,CR2,CR1and CR0 does not get reloaded after call of _Startup in COP ISR,  is it because it is mentioned in the data sheet under chapter Clock and Reset Generator that these bit can be wriiten once in normal mode.
so COPCTL register remain as 0x00 (COP Disable)and so next timeout in 4seconds after the first timeout  is not observed.
 
3.So is  _Startup code a hardware reset or a  software reset ? and so the COPCTL register cannot be re-initialised to 4 seconds after it has been reset once.
 
4. and my  next query is when I remove the debugger  and give a external  reset on the board, and try to run the code it  does not give me an watchdog timeout. - So does this mean that on external reset the COP is written 0xxxx000 and it takes this as write once which disables the COP.
 
Thanks,
Seema
0 件の賞賛
返信

1,120件の閲覧回数
kef
Specialist I
2. But I observe that WCOP,CR2,CR1and CR0 does not get reloaded after call of _Startup in COP ISR,  is it because it is mentioned
 
That's OK. COPCTL is reset on COP reset. You line in main() COPCTL=xx should reload COPCTL.
 
in the data sheet under chapter Clock and Reset Generator that these bit can be wriiten once in normal mode.
 
Can be written once means can be written once between 2 adjacent resets. After reset you can write again, once until next reset.
 
so COPCTL register remain as 0x00 (COP Disable)and so next timeout in 4seconds after the first timeout  is not observed.
It remains reset to 0 until _startup completes and calls your main() routine, where you will set COPCTL again.
 
3.So is  _Startup code a hardware reset or a  software reset ? and so
 
_Startup is not reset, it's startup routine. And COP is hardware reset
4. and my  next query is when I remove the debugger  and give a external  reset on the board, and try to run the code it  does not give me an watchdog timeout. - So does this mean that on external reset the COP is written 0xxxx000 and it takes this as write once which disables the COP.
 
Something not clear here. In code above you write COPCTL once. Did you modify that code and are you now writing to COPCTL more than once? Setting or clearing separate bits like WCOP=1; CR1=0; etc all are write operaions to write once COPCTL. In normal mode first write to write once register is locked and you can't modify it without hardware reset (power-on, COP, CME, ILAF etc).
0 件の賞賛
返信

1,120件の閲覧回数
Seema
Contributor I
Hello Kef,
 
Thanks for your reply.
 
I don't understand why on call of _Startup routine second time i.e after COP reset COPCTL does not get initialise again (reload the counter again).
 
1. At 0xFFFA i have called _Startup routine. (I am using codewarrior 4.6 for implementation)
 
now below is the code
 
2. void main(void) {
  /* put your own code here */
 
  EnableInterrupts;
  asm_main(); /* call the assembly function */
  

  DDRB = 0x0F;
  PUCR |= 0x02;  /* making the PortB high - Only for testing purpose*/

 Modulus_Counter_Timer_Init();    /* One milliseconds interrupt ,and in interrupt I make a LED to toggle*/ 
 COPCTL =0x07;
#if 0
 COPCTL_WCOP = 0;
 COPCTL_RSBCK = 0;
 COPCTL_CR2 = 1;
 COPCTL_CR1 = 1;
 COPCTL_CR0 = 1;
#endif
  while(1)
  {
     /* for testing purpose only*/
     if(PORTB_PB4 == 0)
     {
        PORTB_PB0 = 0x01;   
       
        for(;:smileywink:
        {
      
        }  
     }

 }
 
}
 
i am not able to reload the COPCTL register value in normal mode, can you pleas elet me know how can I change the mode to special mode.
 
I think this is only a solution for me to work in Special mode. Is it so. Please let me know.
 
thanks,
Seema
 

   


Message Edited by Seema on 2008-06-16 03:10 PM
0 件の賞賛
返信

1,120件の閲覧回数
kef
Specialist I
If you found that your write to COPCTL in normal mode is ignored, then COPCTL must be written once after last rest and locked. No more writes are allowed until new reset event.
 
It is impossible to start standalone target in special single chip mode without BDM. So you should forget this idea.
 
To debug in normal single chip mode you can try using hotplug feature. Normally all debugging is done in special single chip mode.
 
After so many posts I don't understand what are you doing. One time you post one code, another time - another. So does COP vector point to _Startup or to your WDC_RESET function?
Do you have large capacitors on /RESET pin? For example DEMO9S12XDT512 board has hardware bug. There's a 0.1uF capacitor on /RESET pin. This effectively disables COP and CME vectors, all vectors are redirected to common vector at 0xFFFE.
 
No more ideas.
0 件の賞賛
返信

1,120件の閲覧回数
Seema
Contributor I
Hello Kef,
 
Thanks a lot for your guidance.
Yes, you are right there is a Capacitor of 0.1uF at the reset pin, and this is the problem.
and we are now studying  the board.
 
and also in the index 5.5.1 of the  datasheet of MC9S12XDP512, we got the details regarding the same.
will let you know the final results.
 
Thanks for all your help.
 
Regards,
Seema
0 件の賞賛
返信