aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sys/timer.c25
-rw-r--r--src/util/mutex.c20
-rw-r--r--src/util/mutex.h15
3 files changed, 55 insertions, 5 deletions
diff --git a/src/sys/timer.c b/src/sys/timer.c
index 6996983..16e6fdb 100644
--- a/src/sys/timer.c
+++ b/src/sys/timer.c
@@ -1,17 +1,32 @@
#include "../sys/core.h"
#include "../sys/timer.h"
#include "../util/time.h"
+#include "../util/mutex.h"
#include "../drivers/uart.a.h"
#include "../drivers/uart.h"
+static unsigned long exe_cnt = 0;
+static struct Mutex exe_cnt_m = {.addr = &exe_cnt, .pid = NULL_PID};
+
+//static unsigned long execution_count = 0;
+
void c_timer() {
// Reset the counter
write_cntv_tval(cntfrq);
// Output the value
- uart_string((char*)"Timer Value: ");
- unsigned long v = read_cntv_tval();
- uart_10(v);
- uart_char(0x20);
- uart_hexn(v);
+ //uart_string((char*)"Timer Value: ");
+ //unsigned long v = read_cntv_tval();
+ //uart_10(v);
+ //uart_char(0x20);
+ //uart_hexn(v);
+
+ // Lock the execution counter
+ if (lock_mutex(&exe_cnt_m, SCHED_PID) == 0) {
+ *(exe_cnt_m.addr) += 1;
+ uart_string((char*)"Executed #");
+ uart_10(*(exe_cnt_m.addr));
+ uart_string((char*)" Times\n");
+ release_mutex(&exe_cnt_m, SCHED_PID);
+ }
}
diff --git a/src/util/mutex.c b/src/util/mutex.c
new file mode 100644
index 0000000..86ffcf5
--- /dev/null
+++ b/src/util/mutex.c
@@ -0,0 +1,20 @@
+#include "../util/mutex.h"
+
+unsigned char lock_mutex(struct Mutex* m, unsigned long pid) {
+ if (m->pid == NULL_PID) {
+ m->pid = pid;
+ return 0;
+ }
+ return 1;
+}
+
+// Eventually, there will need to be a hook into the scheduling mechanism
+// that checks the currently running process and check that against the
+// mutex's pid lock
+unsigned char release_mutex(struct Mutex* m, unsigned long pid) {
+ if (m->pid == pid) {
+ m->pid = NULL_PID;
+ return 0;
+ }
+ return 1;
+}
diff --git a/src/util/mutex.h b/src/util/mutex.h
new file mode 100644
index 0000000..8c9a097
--- /dev/null
+++ b/src/util/mutex.h
@@ -0,0 +1,15 @@
+#ifndef SYS_MUTEX_H
+#define SYS_MUTEX_H
+
+#define NULL_PID 0
+#define SCHED_PID 1
+
+struct Mutex {
+ unsigned long* addr;
+ unsigned long pid;
+};
+
+unsigned char lock_mutex(struct Mutex*, unsigned long);
+unsigned char release_mutex(struct Mutex*, unsigned long);
+
+#endif