123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #pragma once
- #include <avr/interrupt.h>
- #include "expander.h"
- #define LOCALDIFF +1 /* Time difference from UTC [hours] */
- #define IVT_SYNC 180 /* f_sync() interval (0:no periodic sync) [sec] */
- #define VI_LVL 4.2 /* Blackout threshold [volt] */
- #define VI_LVH 4.8 /* Recharge threshold [volt] */
- #define VI_MULT (3.3 / 6.6 / 2.495 * 1024)
- /* pin definitions */
- #define BUZZER_PORT PORTA
- #define BUZZER _BV(PA7)
- #define BUZZER_DDR DDRA
- #define GPS_DIS_PORT PORTC
- #define GPS_DIS _BV(PC6)
- #define GPS_DIS_DDR DDRC
- #define LEDR_PORT PORTA
- #define LEDR _BV(PA6)
- #define LEDR_DDR DDRA
- #define SD_CS_PORT PORTB
- #define SD_CS _BV(PB4)
- #define SD_CS_DDR DDRB
- #define SD_PWROFF_PORT PORTB
- #define SD_PWROFF _BV(PB3)
- #define SD_PWROFF_DDR DDRB
- #define SD_PWROFF_PIN PINB
- #define SD_CD _BV(PB1)
- #define SD_CD_PIN PINB
- #define SD_WP _BV(PB2)
- #define SD_WP_PIN PINB
- #define LEDG_PORT 1 /* expander */
- #define LEDG _BV(4)
- /* on/off macros */
- #define BEEP_ON() {BUZZER_PORT |= BUZZER;}
- #define BEEP_OFF() {BUZZER_PORT &= ~BUZZER;}
- #define LEDR_ON() {LEDR_PORT |= LEDR;}
- #define LEDR_OFF() {LEDR_PORT &= ~LEDR;}
- #define LEDG_ON() expander_set_bit(LEDG_PORT, LEDG, 1)
- #define LEDG_OFF() expander_set_bit(LEDG_PORT, LEDG, 0)
- #define GPS_ON() {GPS_DIS_PORT &= ~GPS_DIS;}
- #define GPS_OFF() {GPS_DIS_PORT |= GPS_DIS;}
- #define FLAGS GPIOR0 /* Status flags and bit definitions */
- #define F_POW 0x80 /* Power */
- #define F_GPSOK 0x08 /* GPS data valid */
- #define F_SYNC 0x04 /* Sync request */
- #define F_FILEOPEN 0x02 /* File is open, logging in progress */
- #define F_LVD 0x01 /* Low battery detect */
- /* System.global_error vals */
- #define ERROR_NO 0
- #define ERROR_I2C 1
- #define ERROR_I2C_TIMEOUT 2
- /* System.status vals */
- #define STATUS_NO_POWER 0
- #define STATUS_NO_DISK 1
- #define STATUS_NO_GPS 2
- #define STATUS_OK 3
- #define STATUS_DISK_ERROR 4
- #define STATUS_FILE_WRITE_ERROR 5
- #define STATUS_FILE_SYNC_ERROR 6
- #define STATUS_FILE_CLOSE_ERROR 7
- #define STATUS_FILE_OPEN_ERROR 8
- #define ms(x) (x/10)
- struct timers {
- unsigned int owire;
- unsigned int beep;
- unsigned int recv_timeout;
- };
- struct system_s {
- struct timers timers;
- unsigned int global_error;
- unsigned char status;
- };
- extern volatile struct system_s System;
- static inline void atomic_set_uint(volatile unsigned int *volatile data, unsigned int value) __attribute__((always_inline));
- static inline void atomic_set_uint(volatile unsigned int *volatile data, unsigned int value){
- cli();
- *data = value;
- sei();
- }
- static inline unsigned int atomic_get_uint(volatile unsigned int *volatile data) __attribute__((always_inline));
- static inline unsigned int atomic_get_uint(volatile unsigned int *volatile data){
- unsigned int ret;
- cli();
- ret = *data;
- sei();
- return ret;
- }
- #define set_timer(timer,val) set_timer_counts(timer, ms(val))
- #define set_timer_counts(timer,val) atomic_set_uint(&System.timers.timer, val)
- #define timer_expired(timer) !atomic_get_uint(&System.timers.timer)
|