Parcourir la source

Add Watchdog, use consistent types, enable interrupts.

Thomas Buck il y a 8 ans
Parent
révision
371205be8a
3 fichiers modifiés avec 17 ajouts et 2 suppressions
  1. 3
    1
      include/cc2500.h
  2. 2
    1
      src/cc2500.c
  3. 12
    0
      src/main.c

+ 3
- 1
include/cc2500.h Voir le fichier

@@ -1,6 +1,8 @@
1 1
 #ifndef _IFACE_CC2500_H_
2 2
 #define _IFACE_CC2500_H_
3 3
 
4
+#include <stdint.h>
5
+
4 6
 enum {
5 7
     CC2500_00_IOCFG2           = 0x00,        // GDO2 output pin configuration
6 8
     CC2500_01_IOCFG1           = 0x01,        // GDO1 output pin configuration
@@ -130,7 +132,7 @@ void cc2500WriteFifo(uint8_t *dpbuffer, uint8_t len);
130 132
 void cc2500ReadRegisterMulti(uint8_t address, uint8_t data[], uint8_t length);
131 133
 void cc2500WriteRegisterMulti(uint8_t address, const uint8_t data[], uint8_t length);
132 134
 
133
-unsigned char cc2500ReadReg(unsigned char address);
135
+uint8_t cc2500ReadReg(uint8_t address);
134 136
 void cc2500WriteReg(uint8_t address, uint8_t data);
135 137
 
136 138
 void cc2500Strobe(uint8_t address);

+ 2
- 1
src/cc2500.c Voir le fichier

@@ -3,6 +3,7 @@
3 3
  */
4 4
 
5 5
 #include <util/delay.h>
6
+
6 7
 #include "spi.h"
7 8
 #include "cc2500.h"
8 9
 
@@ -42,7 +43,7 @@ void cc2500WriteReg(uint8_t address, uint8_t data) {
42 43
     CS_on;
43 44
 }
44 45
 
45
-unsigned char cc2500ReadReg(unsigned char address) {
46
+uint8_t cc2500ReadReg(uint8_t address) {
46 47
     uint8_t result;
47 48
     CS_off;
48 49
     address |= 0x80; // bit 7 =1 for reading

+ 12
- 0
src/main.c Voir le fichier

@@ -2,13 +2,25 @@
2 2
  * main() method
3 3
  */
4 4
 
5
+#include <avr/interrupt.h>
6
+#include <avr/wdt.h>
7
+
5 8
 #include "spi.h"
6 9
 #include "timer.h"
7 10
 #include "rx.h"
8 11
 
12
+void watchdogBoot(void) __attribute__((naked)) __attribute__((section(".init3")));
13
+void watchdogBoot(void) {
14
+    MCUSR = 0;
15
+    wdt_disable();
16
+}
17
+
9 18
 void main(void) {
10 19
     timerInit();
20
+    sei(); // Enable interrupts (required for timer)
11 21
     spiInit();
22
+    wdt_enable(WDTO_120MS); // Trigger Watchdog after 120ms
23
+
12 24
     rxInit();
13 25
 
14 26
     for(;;) { }

Chargement…
Annuler
Enregistrer