diff network/clock.c @ 107:56d09a0969b5 avr-http

Import uIP and the PPP implementation from https://code.google.com/p/avrusbmodem/
author Matt Johnston <matt@ucc.asn.au>
date Fri, 07 Sep 2012 23:53:53 +0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/network/clock.c	Fri Sep 07 23:53:53 2012 +0800
@@ -0,0 +1,40 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <avr/interrupt.h>
+#include <avr/io.h>
+#include <avr/sfr_defs.h>
+
+#include "clock.h"
+
+//Counted time
+volatile clock_time_t clock_datetime = 0;
+
+//Overflow interrupt
+ISR(TIMER0_COMPA_vect)
+{
+	clock_datetime += 1;
+}
+
+//Initialise the clock
+void clock_init()
+{
+	// 10ms tick interval
+	OCR0A  = ((F_CPU / 1024) / 100);
+	TCCR0A = (1 << WGM01);
+	TCCR0B = ((1 << CS02) | (1 << CS00));
+	TIMSK0 = (1 << OCIE0A);
+}
+
+//Return time
+clock_time_t clock_time()
+{
+	clock_time_t time;
+
+	ATOMIC_BLOCK(ATOMIC_FORCEON)
+	{
+		time = clock_datetime;
+	}
+
+	return time;
+}