/
delay.c
87 lines (75 loc) · 2.32 KB
/
delay.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
/*
stellarap/delay.c
Copyright (c) 2013 Mark Roy
This file is part of the Stellarap 3D Printer firmware.
http://www.stellarcore.com
http://www.github.com/mroy/stellarap
Stellarap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Stellarap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Stellarap. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
#include "delay.h"
unsigned char delay_stat = DELAY_IDLE;
unsigned long delay_count = 0;
void delay_isr()
{
ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
if (delay_count > 50000)
{
delay_count -= 50000;
ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, 50000*80000);
ROM_TimerEnable(TIMER1_BASE, TIMER_A);
} else if (delay_count > 0)
{
ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, delay_count*80000);
ROM_TimerEnable(TIMER1_BASE, TIMER_A);
delay_count = 0;
} else
{
delay_stat = DELAY_IDLE;
ROM_TimerIntDisable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
ROM_TimerDisable(TIMER1_BASE, TIMER_A);
}
}
void delay(unsigned int milli)
{
delay_count = milli;
if (delay_count > 50000)
{
milli = 50000;
delay_count -= milli;
} else
{
milli = delay_count;
delay_count = 0;
}
// 80000000 ticks/s = 80000 ticks/ms7
ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, milli*80000);
delay_stat = DELAY_RUNNING;
ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
ROM_TimerEnable(TIMER1_BASE, TIMER_A);
}
void delay_init()
{
//configure timer1 for one shot intervals and assign interrupt routine
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
ROM_TimerConfigure(TIMER1_BASE,TIMER_CFG_ONE_SHOT);
ROM_TimerControlStall(TIMER1_BASE, TIMER_A, true);
TimerIntRegister(TIMER1_BASE, TIMER_A, delay_isr);
}