Add delay_ticks function

This commit is contained in:
Jeremy Soller 2019-11-08 10:29:04 -07:00
parent 7ce8a8b114
commit 1b0f79c818
No known key found for this signature in database
GPG Key ID: E988B49EE78A7FB1
2 changed files with 10 additions and 3 deletions

View File

@ -3,6 +3,12 @@
#include <arch/delay.h> #include <arch/delay.h>
#include <arch/timer.h> #include <arch/timer.h>
void delay_ticks(uint16_t ticks) {
timer_mode_1(-ticks);
timer_wait();
timer_stop();
}
// One millisecond in ticks is determined as follows: // One millisecond in ticks is determined as follows:
// 9.2 MHz is the clock rate // 9.2 MHz is the clock rate
// The timer divider is 12 // The timer divider is 12
@ -11,8 +17,6 @@
// 65536 - 766.667 = 64769.33 // 65536 - 766.667 = 64769.33
void delay_ms(int ms) { void delay_ms(int ms) {
for (int i = 0; i < ms; i++) { for (int i = 0; i < ms; i++) {
timer_mode_1(64769); delay_ticks(767);
timer_wait();
timer_stop();
} }
} }

View File

@ -1,6 +1,9 @@
#ifndef _ARCH_DELAY_H #ifndef _ARCH_DELAY_H
#define _ARCH_DELAY_H #define _ARCH_DELAY_H
#include <stdint.h>
void delay_ticks(uint16_t ticks);
void delay_ms(int ms); void delay_ms(int ms);
#endif // _ARCH_DELAY_H #endif // _ARCH_DELAY_H