Browse Source

Add Watchdog, use consistent types, enable interrupts.

Thomas Buck 8 years ago
parent
commit
371205be8a
3 changed files with 17 additions and 2 deletions
  1. 3
    1
      include/cc2500.h
  2. 2
    1
      src/cc2500.c
  3. 12
    0
      src/main.c

+ 3
- 1
include/cc2500.h View File

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

+ 2
- 1
src/cc2500.c View File

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

+ 12
- 0
src/main.c View File

2
  * main() method
2
  * main() method
3
  */
3
  */
4
 
4
 
5
+#include <avr/interrupt.h>
6
+#include <avr/wdt.h>
7
+
5
 #include "spi.h"
8
 #include "spi.h"
6
 #include "timer.h"
9
 #include "timer.h"
7
 #include "rx.h"
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
 void main(void) {
18
 void main(void) {
10
     timerInit();
19
     timerInit();
20
+    sei(); // Enable interrupts (required for timer)
11
     spiInit();
21
     spiInit();
22
+    wdt_enable(WDTO_120MS); // Trigger Watchdog after 120ms
23
+
12
     rxInit();
24
     rxInit();
13
 
25
 
14
     for(;;) { }
26
     for(;;) { }

Loading…
Cancel
Save