forked from kaiwan/L1_sysprg_trg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
64 lines (57 loc) · 2.03 KB
/
common.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* common.h
* Brief Description:
* This is the 'common' code that gets compiled into
* all binary executables.
*/
#ifndef _COMMON_H_
#define _COMMON_H_
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
/*--- 'Regular' headers ---*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <stdlib.h>
/*---*/
#define NON_FATAL 0
int handle_err(int fatal, const char *fmt, ...);
void Dprint(const char *fmt, ...);
#define WARN(warnmsg, args...) do { \
handle_err(NON_FATAL, "!WARNING! %s:%s:%d: " warnmsg, \
__FILE__, __FUNCTION__, __LINE__, ##args); \
} while(0)
#define FATAL(errmsg, args...) do { \
handle_err(EXIT_FAILURE, "FATAL:%s:%s:%d: " errmsg, \
__FILE__, __FUNCTION__, __LINE__, ##args); \
} while(0)
/*------------------------ DELAY_LOOP --------------------------------*/
static inline void beep(int what)
{
char buf[1];
buf[0] = what;
(void)write(STDOUT_FILENO, buf, 1);
}
/*
* DELAY_LOOP macro
* @val : ASCII value to print
* @loop_count : times to loop around
*/
#define HZ 250
#define DELAY_LOOP(val,loop_count) \
{ \
int c=0, m; \
unsigned int for_index,inner_index; \
\
for(for_index=0;for_index<loop_count;for_index++) { \
beep((val)); \
c++; \
for(inner_index=0;inner_index<HZ*1000;inner_index++) \
for(m=0;m<50;m++); \
} \
/*printf("c=%d\n",c);*/ \
}
/*------------------------------------------------------------------------*/
#endif /* #ifndef _COMMON_H_ */