#define and header file problem

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi freaks,

I have small program. I have main *.c file and *.h file with #definitions. In AVR Studio 5 this SW working fine. But, now in AVR 6.0 I have this problem.

1) When in code is instruction sei() or cli(), it has no effect. I have to manually set/clear I bit in SREG.
2) I have tried add in *h file commands
#define SEI_MACRO SREG |=(1 << 7);
#define CLI_MACRO SREG &=~(1 << 7);

But build is fail "SEI_MACRO is not defined..." or "CLI_MACRO is not defined.."
I have to place this definition in main *.c file.
When I place theese definition in main *.c file everything is ok.
Where is problem sei() or cli() is not defined in #include ? Why this definition can not be in *.h file. In *.h file is more definitions from history, and this definition compiler know.

- CPU AT Tiny 2313
- Optimization Os
- AVR Studio 6.0

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

(1) what do you mean "has no effect"? here is a program I just built for the tiny2313 in AS6:

#include 
#include 

int main(void) {
   sei();
   cli();
}

This generated:

0000005a 
: #include #include int main(void) { sei(); 5a: 78 94 sei cli(); 5c: f8 94 cli } 5e: 80 e0 ldi r24, 0x00 ; 0 60: 90 e0 ldi r25, 0x00 ; 0 62: 08 95 ret

There is simply no question that sei() and cli() encode the SEI and CLI opcodes.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes it is ok,

i have

0000005a 
: #include #include int main(void) { sei(); 5a: 78 94 sei cli(); 5c: f8 94 cli } 5e: 80 e0 ldi r24, 0x00 ; 0 60: 90 e0 ldi r25, 0x00 ; 0 62: 08 95 ret 00000064 <_exit>: 64: f8 94 cli 00000066 <__stop_program>: 66: ff cf rjmp .-2 ; 0x66 <__stop_program>

But when I tried simulate it -> no effect on SREG - I bit. And my old program not working.

Try it simulate - i think, that sei(); command has to set I bit in SREG, and cli() has to clear it. ?? My fault??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Problem with
#define SEI_MACRO SREG |=(1 << 7);
#define CLI_MACRO SREG &=~(1 << 7);

is solved. My fault. I have have made changes in header files in ../AVR Studio 5/ folder, and project header file is in ../AVR Studio 6/ directory.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Try it simulate

What simulator?

Although it has been improved Atmels simulator(s) have had known bugs/shortcomings and this might such a one.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

But when I tried simulate it -> no effect on SREG - I bit. And my old program not working.

Then does that not tell you that it is a fault in the simulator? Clearly an AVR that does not have I set in SREG cannot have it remain that way after SEI has been exectued.
Quote:

I have have made changes in header files in ../AVR Studio 5/ folder,

Which is the exact reason you should never change ANY system header file because as soon as you upgrade the toolchain any private changes will be lost. I haven't the first idea what motivated you to change system header files but I think it's the case that you can always over-ride default behaviour in your local project files if you see some need to.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff, I think he means a "AVR Studio 5" folder under "My Documents". (This is where AS places projects by default IIRC.) He seems to have two copies of the project, one for each version of AVR/Atmel Studio.

If you are right, and he made changes anywhere in the tool chain directories, then I agree with you. It should not me tampered with, unless you know exactly what you're doing.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes it is true, I have two copies of one project. One is in \Documents and settings\..\AVRStudio 5\.. directory and the second in ...\AVR Studio 6\.. directory. I have made changes in old header file. Beginner fault.
This file order is typical for me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

LX_User wrote:
But when I tried simulate it -> no effect on SREG - I bit.

If you mean that sei() doesn't set the I bit in SREG when you are single-stepping in the simulator, then I'm afraid you are correct. This is actually something that affects all devices, but it is only valid when you are single stepping. If you put a breakpoint before and after sei() and press you will see that it behaves correct.

This bug will be fixed in the next release.

-Jan Egil