test CCR register/ assembler macros

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

test CCR register/ assembler macros

1,848件の閲覧回数
grzegorzK
Contributor III

Hi

 

I have problem: I would like to find out if function is called from ISR or from main task context. I am not sure if it possible at all, but if I do not use nested interrupts than is enough for me to test if global maskable interrupts are masked or not, it is flag I in CCR register. 

 

I wrote code but I am not sure if is correct, because I do not know how to use assembler with C code, may some one check:

 

 


uint8_t CC;
static uint8_t const BIT_I = 0x10;

 

__asm(pshc);
__asm(movb 1, SP+,CC);
__asm(DES);
__asm(pulc);

 

if (CC & BIT_I)
{
/* I flag is set */
}

 

issue for me are assembler macros, may someone looke at this macros if are they correct or there is easier soultion to read CCR register (maped to global memory?)?

 

Regards

/Greg

ラベル(1)
0 件の賞賛
返信
3 返答(返信)

1,474件の閲覧回数
kef
Specialist I

These two lines should suffice

__asm(pshc);

  __asm(movb 1, SP+,CC);

 

Or without stack manipulations, just

   TFR  CCR, A

   STAA  CC

 

It doesn't make sense to allocate BIT_I constant in flash. Better define it either as

#define BIT_I 0x40

or

enum {BIT_I=0x40};

0 件の賞賛
返信

1,474件の閲覧回数
grzegorzK
Contributor III
Thank you

kef wrote:

 

It doesn't make sense to allocate BIT_I constant in flash. Better define it either as

#define BIT_I 0x40

or

enum {BIT_I=0x40};


why it does not make sense? I do not understand.

0 件の賞賛
返信

1,474件の閲覧回数
kef
Specialist I

Because it's 1) a waste of 1 byte of flash memory to store BIT_I constant, and 2) code is slower. Instead of using immediate addressing (BIT_I constant embedded in CPU instruction and effectively queued in instruction queue), you are forcing CPU to read BIT_I from memory. This is much slower and thus doesn't make sense.

0 件の賞賛
返信