Discussion Forum

A simple problem with atomic instructions

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Author
Mehrdad Seyrafi
Posted
6-Oct-2011 09:06 GMT
Toolset
C166
New! A simple problem with atomic instructions

Hi
I am using this code in my program:

_inline void Local_Clear( U8 StackerID ) {
        U8 idata idx;
        idx = StackerID-3;
        _atomic_(0); TxSpiBuff[idx] &= 0x0fff; TxSpiBuff[idx] |= 0x3000;    _endatomic_();
}

But after compiling, this error is shown:
MainTask.c(804): error C185: atomic #8: out of range

I know what is happening, but I want a good solution. A solution to this problem is that I duplicate the function for each StackerID (the parameter) and eliminate it from the parameter list, so the idx will be a constant and the error is resolved. But I am seeking for a better solution.

Thanks all

Author
Per Westermark
Posted
6-Oct-2011 09:41 GMT
Toolset
C166
New! RE: A simple problem with atomic instructions

What if you have a pointer set to &TxSpiBuff[idx] or TxSpiBuff + idx, and then write
*p = (*p & 0xfff) | 0x3000?

Author
Mehrdad Seyrafi
Posted
6-Oct-2011 10:10 GMT
Toolset
C166
New! RE: A simple problem with atomic instructions

Thanks for reply
I tested your suggestion but the following error again:
MainTask.c(804): error C185: atomic #6: out of range

Also with this code:

_atomic_(0); pp[0] &= 0xfff;  _endatomic_();


or

_atomic_(0); *pp &= 0xfff;  _endatomic_();


or

_atomic_(0); *pp = *pp & 0xfff;  _endatomic_();


I had this error:
MainTask.c(804): error C185: atomic #5: out of range

The number of instructions are decreased to 6 from 8. Better but not enough yet. It must be at most 4 instructions.

Author
christian crosa
Posted
6-Oct-2011 14:00 GMT
Toolset
C166
New! RE: A simple problem with atomic instructions

Just an idea, but can the same effect be acheived using #pragma DISABLE directive ?

link:

http://www.keil.com/support/man/docs/c166/c166_disable.htm

I'm not sure the effect is the same but it may work

Author
Mehrdad Seyrafi
Posted
6-Oct-2011 14:25 GMT
Toolset
C166
New! RE: A simple problem with atomic instructions

Dear christian,
Thanks for your reply.

It sound helpful. But because I'm using multitasking, I'm not sure that using this pragma can help me. Because this pragma disables all the interrupts from raising. I don't know if it prevents also task switching. Do you know anything about this issue?
I'm trying to study more about the Pragma.

Regrads

Author
christian crosa
Posted
6-Oct-2011 14:42 GMT
Toolset
C166
New! RE: A simple problem with atomic instructions

Hi Mehrdad,

I understand your concern that you may be disabling task switching, I'm not expert so I cannot tell you for sure.

However technical support seems to be OK with replacing atomic directive with disable directive so I assume they have considered the case of context switching, check the following link:

http://www.keil.com/support/docs/1344.htm

Best regards

Author
christian crosa
Posted
6-Oct-2011 14:45 GMT
Toolset
C166
New! RE: A simple problem with atomic instructions

The link that I posted in previous entry sugest to me that your code is broken down in more than 4 instructions by the compiler and that is why you are getting the error.

Best Regards

Author
Andrew Neil
Posted
6-Oct-2011 14:49 GMT
Toolset
C166
New! RE: I don't know if it prevents also task switching

You should consult the technical support for whatever RTOS you're using about that.

Next Thread | Thread List | Previous Thread Start a Thread | Settings