Thomas Buck 8 лет назад
Родитель
Сommit
b6eeae675e
3 измененных файлов: 57 добавлений и 20 удалений
  1. 14
    0
      include/timer.h
  2. 17
    20
      makefile
  3. 26
    0
      src/timer.c

+ 14
- 0
include/timer.h Просмотреть файл

@@ -0,0 +1,14 @@
1
+/*
2
+ * Time-Keeping helper
3
+ */
4
+
5
+#ifndef _TIMER_H
6
+#define _TIMER_H
7
+
8
+typedef uint64_t time_t;
9
+
10
+void timerInit(void);
11
+time_t timerGet(void);
12
+
13
+#endif
14
+

+ 17
- 20
makefile Просмотреть файл

@@ -1,8 +1,10 @@
1 1
 MCU = attiny85
2 2
 F_CPU = 16000000
3 3
 RM = rm -rf
4
+MKDIR = mkdir -p
4 5
 EXTRAINCDIR = include
5 6
 CSTANDARD = gnu99
7
+BUILDDIR = build
6 8
 
7 9
 GCC = avr-gcc
8 10
 SIZE = avr-size
@@ -10,11 +12,13 @@ OBJCOPY = avr-objcopy
10 12
 OBJDUMP = avr-objdump
11 13
 AVRDUDE = avrdude
12 14
 
13
-SRC = src/spi.c
15
+SRC = src/main.c
16
+SRC += src/timer.c
17
+SRC += src/spi.c
14 18
 SRC += src/cc2500.c
15
-SRC += src/frsky_arduino_rx_complete.c
19
+SRC += src/rx.c
16 20
 
17
-OBJ = $(SRC:.c=.o)
21
+OBJ = $(addprefix $(BUILDDIR)/, $(SRC:.c=.o))
18 22
 
19 23
 CARGS = -mmcu=$(MCU)
20 24
 CARGS += -I$(EXTRAINCDIR)
@@ -25,42 +29,35 @@ CARGS += -fpack-struct
25 29
 CARGS += -fshort-enums
26 30
 CARGS += -Wall -pedantic -Wstrict-prototypes -Wshadow
27 31
 CARGS += -Wpointer-arith -Wcast-qual -Wextra
28
-CARGS += -Wno-write-strings -Wno-unused-parameter
32
+CARGS += -Wno-main -Wno-write-strings -Wno-unused-parameter
29 33
 CARGS += -std=$(CSTANDARD)
30 34
 CARGS += -DF_CPU=$(F_CPU)
31
-#CARGS += -lm -lprintf_flt
32 35
 CARGS += -ffunction-sections
33 36
 
34 37
 LINKER = -Wl,--relax
35
-#LINKER = -Wl,--relax,-u,vfprintf,-lm,-lprintf_flt,-u,vfscanf,-lscanf_flt
36
-#LINKER += -Wl,--defsym=__heap_start=0x802200,--defsym=__heap_end=0x80ffff
37
-#LINKER += -Wl,-gc-sections
38 38
 
39 39
 PROGRAMMER = avrisp2
40 40
 ISPPORT = usb
41 41
 
42 42
 TARGET = rx
43 43
 
44
-all: $(TARGET).hex
44
+all: $(BUILDDIR)/$(TARGET).hex
45 45
 
46
-%.o: %.c
46
+$(BUILDDIR)/%.o: %.c
47
+	@$(MKDIR) $(BUILDDIR)/$(dir $<)
47 48
 	$(GCC) -c $< -o $@ $(CARGS)
48 49
 
49
-$(TARGET).elf: $(OBJ)
50
+$(BUILDDIR)/$(TARGET).elf: $(OBJ)
50 51
 	$(GCC) $(CARGS) $(OBJ) --output $@ $(LINKER) -Wl,-Map -Wl,$(@:.elf=.map)
51
-	$(SIZE) --mcu=$(MCU) -C $@
52
+	$(SIZE) $@
52 53
 
53
-$(TARGET).hex: $(TARGET).elf
54
+$(BUILDDIR)/$(TARGET).hex: $(BUILDDIR)/$(TARGET).elf
54 55
 	$(OBJCOPY) -O ihex $< $@
55 56
 	$(OBJDUMP) -h -S $< > $(@:.hex=.lss)
56 57
 
57
-program: $(TARGET).hex
58
+program: $(BUILDDIR)/$(TARGET).hex
58 59
 	$(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -P $(ISPPORT) -e -U $(TARGET).hex
59 60
 
60 61
 clean:
61
-	$(RM) $(OBJ)
62
-	$(RM) *.o
63
-	$(RM) *.elf
64
-	$(RM) *.hex
65
-	$(RM) *.lss
66
-	$(RM) *.map
62
+	$(RM) $(BUILDDIR)
63
+

+ 26
- 0
src/timer.c Просмотреть файл

@@ -0,0 +1,26 @@
1
+/*
2
+ * Time-Keeping helper
3
+ */
4
+
5
+#include <avr/io.h>
6
+#include <avr/interrupt.h>
7
+
8
+#include "timer.h"
9
+
10
+volatile time_t systemTime = 0;
11
+
12
+void timerInit(void) {
13
+    TCCR1 |= (1 << CTC1); // CTC Mode
14
+    TCCR1 |= (1 << CS12) | (1 << CS11) | (1 << CS10); // Prescaler: 64
15
+    OCR1A = 250; // Count to 250
16
+    TIMSK |= (1 << OCIE1A); // Enable compare match interrupt
17
+}
18
+
19
+ISR(TIMER1_COMPA_vect) {
20
+    systemTime++; // one millisecond has passed
21
+}
22
+
23
+time_t timerGet(void) {
24
+    return systemTime;
25
+}
26
+

Загрузка…
Отмена
Сохранить