-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.h
119 lines (93 loc) · 4.04 KB
/
global.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef GLOBAL_H
//header environment variable, is used to detect multiple inclusion
//of the same header, and can be used in the c file to detect the
//included library
#define GLOBAL_H
/****************************************************************************
** ENVROIMENT VARIABILE
****************************************************************************/
#define F_CPU 20000000
//Enable to test reading on the ADC module
//#define TEST_ADC
/****************************************************************************
** GLOBAL INCLUDE
** TIPS: you can put here the library common to all source file
****************************************************************************/
//type definition using the bit width and signedness
#include <stdint.h>
//define the ISR routune, ISR vector, and the sei() cli() function
#include <avr/interrupt.h>
//name all the register and bit
#include <avr/io.h>
//hard delay
#include <util/delay.h>
//General purpose macros
#include "at_utils.h"
//AT Mega specific MACROS
#include "at_mega_port.h"
/****************************************************************************
** DEFINE
****************************************************************************/
///----------------------------------------------------------------------
/// BUFFERS
///----------------------------------------------------------------------
///--------------------------------------------------------------------------
/// COMMANDS
///--------------------------------------------------------------------------
/****************************************************************************
** MACRO
****************************************************************************/
///----------------------------------------------------------------------
///
///----------------------------------------------------------------------
#define H_BRIDGE_OFF() \
SET_BIT( PORTB, PB2 )
#define H_BRIDGE_ON() \
SET_BIT( PORTB, PB2 )
/****************************************************************************
** TYPEDEF
****************************************************************************/
//Global flags raised by ISR functions
typedef struct _Isr_flags Isr_flags;
/****************************************************************************
** STRUCTURE
****************************************************************************/
//Global flags raised by ISR functions
struct _Isr_flags
{
//First byte
U8 led_update : 1; //100Hz System Tick
U8 : 7; //unused bits
};
/****************************************************************************
** PROTOTYPE: INITIALISATION
****************************************************************************/
//port configuration and call the peripherals initialization
extern void global_init( void );
//
extern void timer0_init( void );
//Two PWM channels for H-Bridge A
extern void timer1_init( void );
//Two PWM channels for H-Bridge B
extern void timer2_init( void );
//UART communication
extern void usart0_init( void );
//Init the ADC module
extern void adc_init( void );
/****************************************************************************
** PROTOTYPE: FUNCTION
****************************************************************************/
///----------------------------------------------------------------------
/// SERVO
///----------------------------------------------------------------------
/****************************************************************************
** PROTOTYPE: GLOBAL VARIABILE
****************************************************************************/
///----------------------------------------------------------------------
/// STATUS FLAGS
///----------------------------------------------------------------------
//Volatile flags used by ISRs
extern volatile Isr_flags flags;
#else
#warning "multiple inclusion of the header file global.h"
#endif