test CCR register/ assembler macros

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

test CCR register/ assembler macros

1,849 次查看
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,475 次查看
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,475 次查看
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,475 次查看
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 项奖励
回复