-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
128 lines (104 loc) · 2.31 KB
/
main.cpp
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
#include "common_includes.h"
#include "defined_macros.h"
#include "comm.h"
#include "Utilities/servo.h"
#include "remote_defines.h"
#include "Utilities/pid.h"
#include "Utilities/gpio_pwm_lights.h"
extern "C"
{
void SysTickHandler();
uint32_t millis();
static unsigned long milliSec = 0;
}
static unsigned long ulClockMS=0;
int main(void)
{
MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_12MHZ); //50MHZ
//
// Enable peripherals to operate when CPU is in sleep.
//
MAP_SysCtlPeripheralClockGating(true);
//
// Configure SysTick to occur 1000 times per second, to use as a time
// reference. Enable SysTick to generate interrupts.
//
MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKS_PER_SECOND);
MAP_SysTickIntEnable();
MAP_SysTickEnable();
//
// Get the current processor clock frequency.
//
ulClockMS = MAP_SysCtlClockGet() / (3 * 1000);
// init Serial Comm
initSerialComm(230400);
// init SSI0 in slave mode
initSPIComm();
#ifdef DEBUG
UARTprintf("Setting up PID\n");
#endif
initCarPID();
#ifdef DEBUG
UARTprintf("done\n");
#endif
#ifdef DEBUG
UARTprintf("Setting up PWM ... \n");
#endif
configurePWM();
configureGPIO();
#ifdef DEBUG
UARTprintf("done\n");
#endif
#ifdef DEBUG
UARTprintf("Setting up Servo ... \n");
#endif
servo_init();
servo_setPosition(90);
#ifdef DEBUG
UARTprintf("done\n");
#endif
#ifdef DEBUG
UARTprintf("Starting QEI...");
#endif
encoder_init();
#ifdef DEBUG
UARTprintf("done\n");
#endif
#ifdef USE_I2C
#ifdef DEBUG
UARTprintf("Setting up I2C\n");
#endif
//I2C
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
MAP_GPIOPinTypeI2C(GPIO_PORTB_AHB_BASE,GPIO_PIN_2 | GPIO_PIN_3);
MAP_I2CMasterInitExpClk(I2C0_MASTER_BASE,SysCtlClockGet(),true); //false = 100khz , true = 400khz
I2CMasterTimeoutSet(I2C0_MASTER_BASE, 1000);
#ifdef DEBUG
UARTprintf("done\n");
#endif
#endif
#ifdef USE_I2C
#ifdef USE_INA226
#ifdef DEBUG
UARTprintf("Setting up INA226\n");
#endif
initINA226();
#ifdef DEBUG
UARTprintf("done\n");
#endif
#endif
#endif
while (1)
{
}
}
void SysTickHandler()
{
milliSec++;
communication_update_function();
}
uint32_t millis()
{
return milliSec;
}