How to clear MCZF flag?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to clear MCZF flag?

跳至解决方案
907 次查看
100asong
Contributor I

MCU:9s12xep100.

I want to clear MCZF flag in ISR,just like here:

#pragma TRAP_PROC
void  
CPU_Modulus_Counter_ISR(void)
{
          ECT_MCFLG_MCZF = 1;//The first way to clear MCZF flag.
          // ECT_MCFLG &= 0x80;  //The second way to clear MCZF flag.

          //ECT_MCCNT = 0x30;//The third way to clear MCZF flag.

          ECT_MCCTL = 0x00;
}
I find that the first and the second can not clear MCZF flag,but only the third way can clear MCZF flag.

According to the datasheet,

"The flag indicates when interrupt conditions have occurred. The flag can be cleared via the normal flag clearing
mechanism (writing a one to the flag) or via the fast flag clearing mechanism (Reference TFFCA bit in
Section 14.3.2.6, “Timer System Control Register 1 (TSCR1)”).",this is to say we can clear it by  ECT_MCFLG_MCZF = 1;

I am  puzzled here,how to understand it?

Thanks.

 

 

标签 (1)
0 项奖励
1 解答
477 次查看
DPB
NXP Employee
NXP Employee

Hello

 

This means

if  TFFC = 0  then MCZF can only be cleared by writing a "1" to it           (e.g. ECT_MCFLG_MCZF = 1:smileywink:

 

if  TFFC =1 then MCZF can only be cleared by the fast flag clearing mechanism            (e.g. ECT_MCCNT = 0x30:smileywink:

 

This corresponds to the behavior that you have observed.

 

DPB

 

在原帖中查看解决方案

0 项奖励
2 回复数
477 次查看
Lundin
Senior Contributor IV

Generally, clearing interrupt source flags from C code is dangerous, it is very easy to get unintended side effects. I strong encourage the practice of always disassembling such code to see what it actually does behind the lines. That will save you from many dangerous, hard-to-find bugs.

 

For this specific case: when setting timer flags with plain, portable bit-wise operators, you will typically get a problem in CW if you write something like:

REG |= 0x01;

This results in a read-modify-write sequence, that destroys all adjacent flags. The work-around is to write REG = 0x01 instead, which results in a bit set instruction.

 

Whether the bit field write in your code results in read-modify-write or bit set, I don't know. Whether accessing a bit in a bit field destroys adjacent bits in the same register, I don't know either. The only way to know how they work is to read the compiler docs in detail.

 

This is the fun thing with bit fields: the C standard guarantees that bit fields are implemented in completely inpredictable ways, and a programmer can never tell what a bit field access actually does between the lines from reading the C code - the behavior isn't specified by the standard.

 

0 项奖励
478 次查看
DPB
NXP Employee
NXP Employee

Hello

 

This means

if  TFFC = 0  then MCZF can only be cleared by writing a "1" to it           (e.g. ECT_MCFLG_MCZF = 1:smileywink:

 

if  TFFC =1 then MCZF can only be cleared by the fast flag clearing mechanism            (e.g. ECT_MCCNT = 0x30:smileywink:

 

This corresponds to the behavior that you have observed.

 

DPB

 

0 项奖励