-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.h
151 lines (115 loc) · 5.13 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#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
/****************************************************************************
** 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"
//AT4809 PORT macros definitions
#include "at4809_port.h"
/****************************************************************************
** DEFINE
****************************************************************************/
///----------------------------------------------------------------------
/// BUFFERS
///----------------------------------------------------------------------
#define RPI_RX_BUF_SIZE 16
#define RPI_TX_BUF_SIZE 8
///----------------------------------------------------------------------
/// PARSER
///----------------------------------------------------------------------
#define RPI_COM_TIMEOUT 50
///----------------------------------------------------------------------
/// MOTORS
///----------------------------------------------------------------------
//Number of DC motors mounted on the platform
#define DC_MOTOR_NUM 4
//Maximum slew rate. PWM increment per tick
#define DC_MOTOR_SLEW_RATE 1
//Maximum PWM setting
#define DC_MOTOR_MAX_PWM 50
/****************************************************************************
** MACRO
****************************************************************************/
///----------------------------------------------------------------------
/// LEDS
///----------------------------------------------------------------------
#define LED0_TOGGLE() \
TOGGLE_BIT( PORTB, PB6 )
/****************************************************************************
** TYPEDEF
****************************************************************************/
//Global flags raised by ISR functions
typedef struct _Isr_flags Isr_flags;
//PWM and direction of a DC motor
typedef struct _Dc_motor_pwm Dc_motor_pwm;
/****************************************************************************
** STRUCTURE
****************************************************************************/
//Global flags raised by ISR functions
struct _Isr_flags
{
//First byte
U8 system_tick : 1; //System Tick
U8 : 7; //unused bits
};
//PWM and direction of a DC motor
struct _Dc_motor_pwm
{
uint8_t pwm; //DC Motor PWM setting. 0x00 = stop | 0xff = maximum
uint8_t f_dir; //DC Motor direction. false=clockwise | true=counterclockwise
};
/****************************************************************************
** PROTOTYPE: INITIALISATION
****************************************************************************/
//port configuration and call the peripherals initialization
extern void init( void );
/****************************************************************************
** PROTOTYPE: FUNCTION
****************************************************************************/
/****************************************************************************
** PROTOTYPE: GLOBAL VARIABILE
****************************************************************************/
///----------------------------------------------------------------------
/// STATUS FLAGS
///----------------------------------------------------------------------
//Volatile flags used by ISRs
extern volatile Isr_flags g_isr_flags;
///----------------------------------------------------------------------
/// BUFFERS
///----------------------------------------------------------------------
// Buffers structure and data vectors
//Safe circular buffer for UART input data
extern volatile At_buf8_safe rpi_rx_buf;
//Safe circular buffer for uart tx data
extern At_buf8 rpi_tx_buf;
//allocate the working vector for the buffer
extern uint8_t v0[ RPI_RX_BUF_SIZE ];
//allocate the working vector for the buffer
extern uint8_t v1[ RPI_TX_BUF_SIZE ];
///--------------------------------------------------------------------------
/// MOTORS
///--------------------------------------------------------------------------
//Desired setting for the DC motor channels
extern Dc_motor_pwm dc_motor_target[DC_MOTOR_NUM];
//Two DC Motor channels current setting
extern Dc_motor_pwm dc_motor[DC_MOTOR_NUM];
#else
#warning "multiple inclusion of the header file global.h"
#endif