File: setjmp-5.c

package info (click to toggle)
avr-libc 1%3A1.6.2.cvs20080610-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 14,848 kB
  • ctags: 55,619
  • sloc: ansic: 92,267; asm: 6,692; sh: 4,131; makefile: 2,481; python: 976; pascal: 426; perl: 116
file content (36 lines) | stat: -rw-r--r-- 657 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Test of setjmp()/longjmp() functions: SREG restoring.
   $Id: setjmp-5.c,v 1.1.2.2 2008/03/24 11:29:55 dmix Exp $	*/

#ifdef	__AVR__

#include <setjmp.h>
#include <stdlib.h>
#include <avr/io.h>

jmp_buf env;

int main ()
{
    SREG = 0;
    if (setjmp (env)) {
	if (SREG & (1 << SREG_I)) exit (__LINE__);
    } else {
	if (SREG & (1 << SREG_I)) exit (__LINE__);
	SREG = 0xff;
	longjmp (env, 1);
    }
    
    SREG = 0xff;
    if (setjmp (env)) {
	if ((SREG & (1 << SREG_I)) == 0) exit (__LINE__);
    } else {
	if ((SREG & (1 << SREG_I)) == 0) exit (__LINE__);
	SREG = 0;
	longjmp (env, 1);
    }
    return 0;
}

#else
int main ()	{ return 0; }
#endif