-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
145 lines (121 loc) · 3.51 KB
/
main.c
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
//Project includes
#include "TaskScheduler/TaskScheduler.h"
#include "TaskScheduler/PriorityQueue.h"
//Standard includes
#include <stdbool.h>
#include <stdint.h>
#include <math.h>
#include <stdio.h>
//Tivaware includes
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "driverlib/adc.h"
#include "driverlib/ssi.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "driverlib/fpu.h"
#include <driverlib/timer.h>
#include <driverlib/interrupt.h>
//System clock running at 120MHz if 129 or 80MHz if 123
#ifdef PART_TM4C129
#define SYS_CLK 120000000
#elif PART_TM4C123
#define SYS_CLK 80000000
#endif
void EnableClock(void);
void EnablePeripherals();
void InitConsole(void);
//Copies val to the buffer as an ascii string. Arg1 is the number of places before decimal, arg2 is after.
void sprintfloat(char *Buffer, float val, int arg1){
int LeftSide = (int)val;
int RightSide = (int)(pow(10,arg1) * (val - LeftSide)); //Remove the portion to the left of the decimal
sprintf(Buffer, "%i.%i", LeftSide, RightSide);
}
void print(){
UARTprintf("Task 1");
}
void print2(){
UARTprintf("Task 2");
}
void print3(){
UARTprintf("Task 3");
}
Task tasks[3];
int main(void)
{
FPULazyStackingEnable();
EnableClock();
EnablePeripherals();
InitializeTaskScheduler(TIMER0_BASE, SYSCTL_PERIPH_TIMER0, SYS_CLK, INT_TIMER0A);
tasks[0].period = 5;
tasks[0].enabled = 1;
tasks[0].pCallback = print;
tasks[0].priority = 2;
tasks[1].period = 30;
tasks[1].enabled = 1;
tasks[1].pCallback = print2;
tasks[1].priority = 1;
tasks[2].period = 1;
tasks[2].enabled = 1;
tasks[2].pCallback = print3;
tasks[2].priority = 0;
AddTask(&tasks[0]);
AddTask(&tasks[1]);
AddTask(&tasks[2]);
while(1){
}
}
void EnableClock(void){
#ifdef PART_TM4C129
SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), SYS_CLK);
#elif PART_TM4C123
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
uint32_t g_ui32SysClock = SysCtlClockGet ();
#endif
}
/*
Enables all peripherals needed for this motor driver test
*/
void EnablePeripherals(void){
InitConsole();
}
//Initializes UART0 to be used as a console.
void InitConsole(void){
//
// Enable GPIO port A which is used for UART0 pins.
// TODO: change this to whichever GPIO port you are using.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Configure the pin muxing for UART0 functions on port A0 and A1.
// This step is not necessary if your part does not support pin muxing.
// TODO: change this to select the port/pin you are using.
//
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
//
// Enable UART0 so that we can configure the clock.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//
// Select the alternate (UART) function for these pins.
// TODO: change this to select the port/pin you are using.
//
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 115200, 16000000);
}