38 #include <util/delay.h> 39 #include <avr/interrupt.h> 40 #include <avr/pgmspace.h> 41 #include <avr/sleep.h> 68 #warning "F_CPU was not defined! It will now be set to 20000000UL." 69 #define F_CPU 20000000UL 124 static uint8_t contact_check_counter = 0u;
125 static uint8_t battery_check_counter = 0u;
126 static uint8_t life_sign_counter = 0u;
128 static uint32_t battery_value = 0u;
129 static uint32_t unencrypted_value = 0u;
130 static uint8_t sensor1_value = 0u;
131 static uint8_t sensor2_value = 0u;
133 static uint8_t warn_memory_u8 = 0u;
135 static uint8_t message_counter_u8 = 0u;
139 int16_t transmission_return_value;
142 uint32_t data_buffer[2];
143 uint32_t encrypted_data_buffer[2];
144 uint8_t checksum_buffer[4];
153 static char tmp_char[40];
211 #if TRANSMISSION_ENABLED == 1 214 #endif // TRANSMISSION_ENABLED 227 contact_check_counter = 0u;
228 battery_check_counter = 0u;
229 life_sign_counter = 0u;
269 TIMSK2 = TIMSK2 | (1 << OCIE2A);
288 PRR |= (1 << PRTWI) | (1 << PRTIM0) | (1 << PRTIM1) | (1 << PRSPI) | (1 << PRUSART0) | (1 << PRADC);
315 battery_check_counter++;
325 PRR &= ~(1 << PRADC);
342 battery_check_counter = 0;
345 #if LCD_DEBUG == 1 && LCD_BAT_DEBUG == 1 351 itoa(battery_value, tmp_char, 10);
367 contact_check_counter++;
373 #if ALARM_SENSOR_INPUT1_ENABLED == 1 383 if (sensor1_value > 0u) {
384 warn_memory_u8 = warn_memory_u8 | 0x01;
389 #endif // ALARM_SENSOR_INPUT1_ENABLED 391 #if ALARM_SENSOR_INPUT2_ENABLED == 1 401 if (sensor2_value > 0u) {
402 warn_memory_u8 = warn_memory_u8 | 0x02;
406 #endif // ALARM_SENSOR_INPUT2_ENABLED 408 contact_check_counter = 0u;
410 #if LCD_DEBUG == 1 && LCD_SEN_DEBUG == 1 433 if (((sensor1_value > 0u) || (sensor2_value > 0u)) && warn_cycle_counter > 0) {
447 unencrypted_value = (uint32_t)
ALARM_SENSOR_ID & (uint32_t) 0x000000ff;
448 unencrypted_value = unencrypted_value | (((uint32_t) message_counter_u8 << 8u) & (uint32_t) 0x0000ff00);
449 unencrypted_value = unencrypted_value | (((uint32_t) battery_value << 16u) & (uint32_t) 0x1fff0000);
450 unencrypted_value = unencrypted_value | (((uint32_t)
ALARM_SENSOR_ENABLED << 29u) & (uint32_t) 0x20000000);
451 unencrypted_value = unencrypted_value | (((uint32_t) sensor1_value << 30u) & (uint32_t) 0x40000000);
452 unencrypted_value = unencrypted_value | (((uint32_t) sensor2_value << 31u) & (uint32_t) 0x80000000);
455 checksum_buffer[0] = (uint8_t) (unencrypted_value & 0xff);
456 checksum_buffer[1] = (uint8_t) ((unencrypted_value >> 8) & 0xff);
457 checksum_buffer[2] = (uint8_t) ((unencrypted_value >> 16) & 0xff);
458 checksum_buffer[3] = (uint8_t) ((unencrypted_value >> 24) & 0xff);
465 data_buffer[0] = checksum;
466 data_buffer[1] = unencrypted_value;
471 PRR &= ~(1 << PRSPI);
474 transmit_buffer[0] = 0xb8aa;
475 transmit_buffer[1] = 0xb8aa;
476 transmit_buffer[2] = 0xb8aa;
477 transmit_buffer[3] = 0xb8aa;
478 transmit_buffer[4] = 0xb82d;
479 transmit_buffer[5] = 0xb8d4;
482 transmit_buffer[8] = 0xb800 | ((encrypted_data_buffer[1] >> 24) & 0xff);
483 transmit_buffer[9] = 0xb800 | ((encrypted_data_buffer[1] >> 16) & 0xff);
484 transmit_buffer[10] = 0xb800 | ((encrypted_data_buffer[1] >> 8) & 0xff);
485 transmit_buffer[11] = 0xb800 | (encrypted_data_buffer[1] & 0xff);
486 transmit_buffer[12] = 0xb800 | ((encrypted_data_buffer[0] >> 24) & 0xff);
487 transmit_buffer[13] = 0xb800 | ((encrypted_data_buffer[0] >> 16) & 0xff);
488 transmit_buffer[14] = 0xb800 | ((encrypted_data_buffer[0] >> 8) & 0xff);
489 transmit_buffer[15] = 0xb800 | (encrypted_data_buffer[0] & 0xff);
490 transmit_buffer[16] = 0xb8aa;
491 transmit_buffer[17] = 0xb8aa;
492 #if TRANSMISSION_ENABLED == 1 494 #endif // TRANSMISSION_ENABLED 496 message_counter_u8++;
500 #if LCD_DEBUG == 1 && LCD_CON_DEBUG == 1 504 itoa(transmission_return_value, tmp_char, 10);
508 warn_cycle_counter--;
513 }
else if ((sensor1_value == 0u) && (sensor2_value == 0u)) {
542 unencrypted_value = (uint32_t)
ALARM_SENSOR_ID & (uint32_t) 0x000000ff;
543 unencrypted_value = unencrypted_value | (((uint32_t) message_counter_u8 << 8u) & (uint32_t) 0x0000ff00);
544 unencrypted_value = unencrypted_value | (((uint32_t) battery_value << 16u) & (uint32_t) 0x1fff0000);
545 unencrypted_value = unencrypted_value | (((uint32_t)
ALARM_SENSOR_ENABLED << 29u) & (uint32_t) 0x20000000);
546 unencrypted_value = unencrypted_value | (((uint32_t) sensor1_value << 30u) & (uint32_t) 0x40000000);
547 unencrypted_value = unencrypted_value | (((uint32_t) sensor2_value << 31u) & (uint32_t) 0x80000000);
550 checksum_buffer[0] = (uint8_t) (unencrypted_value & 0xff);
551 checksum_buffer[1] = (uint8_t) ((unencrypted_value >> 8) & 0xff);
552 checksum_buffer[2] = (uint8_t) ((unencrypted_value >> 16) & 0xff);
553 checksum_buffer[3] = (uint8_t) ((unencrypted_value >> 24) & 0xff);
560 data_buffer[0] = checksum;
561 data_buffer[1] = unencrypted_value;
566 PRR &= ~(1 << PRSPI);
569 transmit_buffer[0] = 0xb8aa;
570 transmit_buffer[1] = 0xb8aa;
571 transmit_buffer[2] = 0xb8aa;
572 transmit_buffer[3] = 0xb8aa;
573 transmit_buffer[4] = 0xb82d;
574 transmit_buffer[5] = 0xb8d4;
577 transmit_buffer[8] = 0xb800 | ((encrypted_data_buffer[1] >> 24) & 0xff);
578 transmit_buffer[9] = 0xb800 | ((encrypted_data_buffer[1] >> 16) & 0xff);
579 transmit_buffer[10] = 0xb800 | ((encrypted_data_buffer[1] >> 8) & 0xff);
580 transmit_buffer[11] = 0xb800 | (encrypted_data_buffer[1] & 0xff);
581 transmit_buffer[12] = 0xb800 | ((encrypted_data_buffer[0] >> 24) & 0xff);
582 transmit_buffer[13] = 0xb800 | ((encrypted_data_buffer[0] >> 16) & 0xff);
583 transmit_buffer[14] = 0xb800 | ((encrypted_data_buffer[0] >> 8) & 0xff);
584 transmit_buffer[15] = 0xb800 | (encrypted_data_buffer[0] & 0xff);
585 transmit_buffer[16] = 0xb8aa;
586 transmit_buffer[17] = 0xb8aa;
587 #if TRANSMISSION_ENABLED == 1 589 #endif // TRANSMISSION_ENABLED 591 message_counter_u8++;
595 life_sign_counter = 0u;
597 #if LCD_DEBUG == 1 && LCD_CON_DEBUG == 1 604 sprintf(tmp_char,
"%04x%04x", (uint16_t) ((data_buffer[1] >> 16) & 0xffff), (uint16_t) (data_buffer[1] & 0xffff));
607 sprintf(tmp_char,
"%04x%04x", (uint16_t) ((encrypted_data_buffer[1] >> 16) & 0xffff), (uint16_t) (encrypted_data_buffer[1] & 0xffff));
624 if ((life_sign_counter == 1) && ((warn_memory_u8 & 0x01u) == 0x01u)) {
632 if ((life_sign_counter == 3) && ((warn_memory_u8 & 0x02u) == 0x02u)) {
640 if ((life_sign_counter == 5) && ((warn_memory_u8 & 0x03u) == 0x03u)) {
665 PRR |= (1 << PRTWI) | (1 << PRTIM0) | (1 << PRTIM1) | (1 << PRSPI) | (1 << PRUSART0) | (1 << PRADC);
#define ALARM_SENSOR_ID
sensor related identification and configuration data (TO BE SET FOR EACH SENSOR SEPARATELY!) each ala...
volatile uint8_t time_scale
counter triggered by timer
#define ALARM_SENSOR_ENABLED
ENABLE flag of current sensor –> to be adapted for each sensor!
void lcd_blpin_init(void)
uint16_t rfm12_init(uint8_t)
Contains all the basic definitions for several projects.
#define ALAM_SENSOR_PROT
alarm sensor protocol identifier
#define WARN_CYCLES
number of warn cycles until the sensor falls back to the normal life sign rate
uint32_t single_adc_read(uint8_t vref_reg, uint16_t vref_val, uint16_t number_cycles, uint16_t min_freq)
void rfm12_pin_init(void)
uint8_t sym_encrypt_buffer(uint32_t *, uint32_t *, uint8_t)
#define CRC_UPDATE
do only an updating and return the current crc value
Contains CRC calculation functions.
#define BATTERY_CHECK_COUNTER
counter (related to TIME_BASE_MS) for battery checking (==> 10 s)
#define POWER_SAFE_MODE
SM0 and SM1 activated, SE set to 1 –> power safe mode.
void adc_pin_deinit(void)
#define LIFE_SIGN_COUNTER
counter (related to TIME_BASE_MS) for life sign to main unit (==> 20 s + (ID * 0.25 s)) ...
#define CRC_FINALIZATION
do only the finalization and return the crc value
#define CRC_INITIALIZATION
do only the initialization and return the init value
void lcd_send_string(const char *data, uint8_t flash_mem)
#define FALSE
value for FALSE
uint32_t calculate_crc32(uint8_t *, uint8_t, uint8_t)
4 Bit Interface to LCD displays with up to 4 rows and a single Controller (e.g. ST7066U or HD44780)...
#define RFM12_POWER_SAFE_ENABLED
enables or disables the power safe mode of the RFM12(B) module
#define CONTACT_CHECK_COUNTER
counter (related to TIME_BASE_MS) for contact checking (==> 1 s)
void lcd_set_cursor(uint8_t column, uint8_t row)
#define RFM12_RXBUFFER_LENGTH
volatile uint8_t prev_time_scale
previous counter value (triggered by timer)
#define RFM12_TXBUFFER_LENGTH
uint32_t calculate_battery_voltage(uint32_t)
Contains the main definitions of the alarm sensor module.
int16_t rfm12_data_io(volatile uint16_t *, volatile uint16_t *, uint8_t, uint8_t, uint8_t)
#define AS_OCR2A
value for compare match (244 = 250 ms for 1 MHz clock)