Organize into arch, board, and ec modules

This commit is contained in:
Jeremy Soller
2019-09-29 20:13:03 -06:00
parent 9d056547e6
commit ded5181926
47 changed files with 518 additions and 486 deletions

18
src/arch/8051/delay.c Normal file
View File

@@ -0,0 +1,18 @@
#include <8051.h>
#include <arch/delay.h>
#include <arch/timer.h>
// One millisecond in ticks is determined as follows:
// 9.2 MHz is the clock rate
// The timer divider is 12
// The timer rate is 12 / 9.2 MHz = 1.304 us
// The ticks are 1000 ms / (1.304 us) = 766.667
// 65536 - 766.667 = 64769.33
void delay_ms(int ms) {
for (int i = 0; i < ms; i++) {
timer_mode_1(64769);
timer_wait();
timer_stop();
}
}

View File

@@ -0,0 +1,6 @@
#ifndef _ARCH_DELAY_H
#define _ARCH_DELAY_H
void delay_ms(int ms);
#endif // _ARCH_DELAY_H

View File

@@ -0,0 +1,6 @@
#ifndef _ARCH_RESET_H
#define _ARCH_RESET_H
void reset(void);
#endif // _ARCH_RESET_H

View File

@@ -0,0 +1,8 @@
#ifndef _ARCH_TIMER_H
#define _ARCH_TIMER_H
void timer_mode_1(int value);
void timer_wait(void);
void timer_stop(void);
#endif // _ARCH_TIMER_H

5
src/arch/8051/reset.c Normal file
View File

@@ -0,0 +1,5 @@
#include <arch/reset.h>
void reset(void) {
__asm__("ljmp 0");
}

20
src/arch/8051/timer.c Normal file
View File

@@ -0,0 +1,20 @@
#include <8051.h>
#include <arch/timer.h>
void timer_mode_1(int value) {
timer_stop();
TMOD = 0x01;
TH0 = (unsigned char)(value >> 8);
TL0 = (unsigned char)value;
TR0 = 1;
}
void timer_wait(void) {
while (TF0 == 0) {}
}
void timer_stop(void) {
TR0 = 0;
TF0 = 0;
}