Changeset - 3243bfc71b35
[Not reviewed]
default
0 9 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-03-22 15:56:41
ethanzonca@CL-ENS241-08.cedarville.edu
Fixed warnings on master, implemented watchdog ISR to flash LEDs and save program timer to EEPROM. Program timer is restored upon reboot after the watchdog triggers, the error LED is activated, and an error message is logged to the SD card.
9 files changed with 75 insertions and 7 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -22,25 +22,25 @@
 
#define F_CPU 11059200
 
#define BOARDTEMP_ADDR 0x90
 
 
 
// --------------------------------------------------------------------------
 
// Module config (master.c)
 
// --------------------------------------------------------------------------
 
 
// Debug Output
 
//#define DEBUG_OUTPUT
 
 
// Blackout (turn off all but power LEDs)
 
#define BLACKOUT_ENABLE
 
//#define BLACKOUT_ENABLE
 
#define BLACKOUT_TIMEOUT 300000 // Blackout after 5 minutes (hopefully after fix)
 
 
// Board heater setpoint
 
#define HEATER_THRESHOLD 80
 
 
// Touchdown buzzer
 
#define BUZZER_RATE 3000
 
#define BUZZER_DURATION 3000
 
#define BUZZER_FAILSAFE_DURATION 600000
 
#define BUZZER_TRIGGER_MINDURATION 1
 
#define BUZZER_TRIGGER_MAXALTITUDE 1
 
 
@@ -49,24 +49,25 @@
 
// --------------------------------------------------------------------------
 
 
// SD Card
 
#define ERROR_SLAVETIMEOUT 0
 
#define ERROR_SD_INIT 1
 
#define ERROR_SD_PARTITION 2
 
#define ERROR_SD_FILE 3
 
#define ERROR_XBEETIMEOUT 4
 
#define ERROR_FATAL 5
 
#define ERROR_ATFAIL 6
 
#define ERROR_EXITAT 7
 
#define ERROR_INFOTEXT 8
 
#define ERROR_WATCHDOG 9
 
// !!! Please specify/update detailed messages for these error codes in logger.c
 
 
// --------------------------------------------------------------------------
 
// Slave Sensors config (slavesensors.c)
 
// --------------------------------------------------------------------------
 
 
// Slave data structure size
 
#define MAX_NUM_SLAVES 5	// Maximum number of nodes in the system
 
#define MAX_NUM_SENSORS 10	// Maximum number of unique types of sensors in the system
 
 
// Node identifier of log destination xbee
 
#define XBEE_LOGDEST_NAME "HAB-LOGGER"
 
@@ -150,23 +151,26 @@
 
 
// Transmit the APRS sentence every X milliseconds
 
#define APRS_TRANSMIT_PERIOD 20000
 

	
 

	
 
// --------------------------------------------------------------------------
 
// Logger config (logger.c)
 
// --------------------------------------------------------------------------
 
 
// Log number EEPROM address (this number is incremented on boot, used for filenames)
 
#define LOGGER_ID_EEPROM_ADDR 0x10
 
 
// Watchdog save/restore of program timer
 
#define WATCHDOG_PROGTIMER_EEPROM_ADDR 0x20
 
 
// Written to the beginning of every log file
 
#define LOGGER_HEADERTEXT "HAB Control Master - 1.0\n"
 
 
// Log to SD card every X milliseconds
 
#define LOGGER_RATE 1000 
 
 
// LED cycle indicator speed
 
#define LEDCYCLE_RATE 100 
 
 
 
#endif /* CONFIG_H_ */
 
\ No newline at end of file
master/master/lib/logger.c
Show inline comments
 
@@ -19,49 +19,51 @@
 
#include <avr/eeprom.h>
 
#include <string.h>
 
#include "sdcard/fat.h"
 
#include "sdcard/fat_config.h"
 
#include "sdcard/partition.h"
 
#include "sdcard/sd_raw.h"
 
#include "sdcard/sd_raw_config.h"
 
#include "serial.h"
 
#include "logger.h"
 
#include "led.h"
 
#include "looptime.h"
 

	
 
#define MAX_ERRNO 8
 
#define MAX_ERRNO 9
 

	
 
// Label lookup table
 
// Make sure there are never more labels than there are MAX_NUM_SENSORS!
 
const char err_0[] PROGMEM = "slave timeout";
 
const char err_1[] PROGMEM = "initializing SD card failed";
 
const char err_2[] PROGMEM = "opening SD partition failed";
 
const char err_3[] PROGMEM = "opening SD file failed";
 
const char err_4[] PROGMEM = "XBee timeout";
 
const char err_5[] PROGMEM = "FATAL UNHANDLED ERROR";
 
const char err_6[] PROGMEM = "enter AT mode failed";
 
const char err_7[] PROGMEM = "exit AT mode failed";
 
const char err_8[] PROGMEM = "infotext";
 
const char err_9[] PROGMEM = "watchdog";
 

	
 
const char *const errorMessageLookup[] PROGMEM =
 
{
 
	err_0,
 
	err_1,
 
	err_2,
 
	err_3,
 
	err_4,
 
	err_5,
 
	err_6,
 
	err_7,
 
	err_8,
 
	err_9
 
};
 
 
 
 
struct partition_struct* partition;
 
struct fat_fs_struct* fs;
 
struct fat_dir_struct* dd;
 
struct fat_file_struct* fd_datalog;
 
struct fat_file_struct* fd_errorlog;
 
 
void logger_setup()
 
{
master/master/lib/looptime.c
Show inline comments
 
@@ -30,12 +30,17 @@ void time_setup()
 
	TIMSK0 |= (1 << TOIE0); // enable overflow interrupt
 
}
 

	
 
ISR(TIMER0_OVF_vect) 
 
{
 
	millis = millis + 1;
 
}
 

	
 
uint32_t time_millis() 
 
{
 
	return millis; // meh accuracy, but that's OK
 
}
 

	
 
void time_watchdogrestore(uint32_t saved_millis)
 
{
 
	millis = saved_millis;
 
}	
master/master/lib/looptime.h
Show inline comments
 
@@ -8,14 +8,15 @@
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#ifndef LOOPTIME_H_
 
#define LOOPTIME_H_
 
 
#include <inttypes.h>
 

	
 
void time_setup();
 
uint32_t time_millis();
 
void time_watchdogrestore(uint32_t saved_millis);
 
 
#endif /* LOOPTIME_H_ */
 
\ No newline at end of file
master/master/lib/sdcard/sd_raw.c
Show inline comments
 
@@ -4,25 +4,24 @@
 
 *
 
 * This file is free software; you can redistribute it and/or modify
 
 * it under the terms of either the GNU General Public License version 2
 
 * or the GNU Lesser General Public License version 2.1, both as
 
 * published by the Free Software Foundation.
 
 */
 

	
 
#include <string.h>
 
#include <avr/io.h>
 
#include "sd_raw.h"
 
#include "sd_raw_config.h"
 
#include "../led.h"
 
#include <avr/delay.h>
 

	
 
/**
 
 * \addtogroup sd_raw MMC/SD/SDHC card raw access
 
 *
 
 * This module implements read and write access to MMC, SD
 
 * and SDHC cards. It serves as a low-level driver for the
 
 * higher level modules such as partition and file system
 
 * access.
 
 *
 
 * @{
 
 */
 
/**
master/master/lib/slavesensors.c
Show inline comments
 
@@ -559,24 +559,29 @@ void slavesensors_process(uint8_t parseR
 
	// If fail, try retransmit. Or we could skip and hit it next time.
 
	// TODO: Maximum number of retransmissions
 
	else if(parseResult == PARSERESULT_FAIL) 
 
	{
 
		if(requesting) 
 
		{
 
			if(numRetries < MAX_SLAVEREQUEST_RETRIES) 
 
			{
 
				slavesensors_request();	// re-request
 
			}
 
			else {
 
				numRetries = 0;
 
				
 
				char msg[128];
 
				snprintf(msg, 128, "Slave %u (%s) failed max retries",currentSlave,slaveNames[currentSlave]);
 
				error_log_msg(ERROR_SLAVETIMEOUT, false, msg); // log error, don't blink LED
 
				
 
				gotoNextSlaveOrSensor(true);
 
			}
 
		}			
 
	}
 
	
 
	
 
	else if(parseResult == PARSERESULT_STILLPARSING)
 
	{
 
		return; // do nothing
 
	}
 
	else 
 
	{
master/master/lib/watchdog.c
Show inline comments
 
/*
 
 * Master Firmware: Watchdog Timer
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#include "../config.h"
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include <avr/wdt.h>
 
#include <util/delay.h>
 
#include <avr/eeprom.h>
 
 
#include "looptime.h"
 
#include "led.h"
 
#include "logger.h"
 
 
//initialize watchdog
 
void watchdog_setup(void)
 
{
 
	cli();
 
	wdt_reset();
 
	// Set change enable bit, enable the WDT
 
	WDTCSR = (1<<WDCE)|(1<<WDE);
 
	WDTCSR = (1<<WDCE)|(1<<WDE)| (1<<WDIE);
 
	// Start watchdog, 4 second timeout
 
	WDTCSR = (1<<WDE)|(1<<WDP3)|(1<<WDP0);
 
	WDTCSR = (1<<WDE)|(1<<WDP3)|(1<<WDP0)|(1<<WDIE);
 
	sei();
 
}
 
 
void watchdog_checkreset(void)
 
{
 
	// Check if WDT reset occurred
 
	if( (MCUSR & (1<<WDRF)) > 0)
 
	{
 
		MCUSR &= ~(1<<WDRF);
 
		
 
		// Restore timer from EEPROM
 
		uint32_t oldtimer = 0;
 
		oldtimer = eeprom_read_dword((uint32_t*)WATCHDOG_PROGTIMER_EEPROM_ADDR);
 
		time_watchdogrestore(oldtimer);
 
		
 
		error_log_msg(ERROR_WATCHDOG,false,"Booting up after watchdog reset");
 
	}
 
}
 
 
ISR(WDT_vect) 
 
{
 
	// Store timer in EEPROM
 
	eeprom_write_dword((uint32_t*)WATCHDOG_PROGTIMER_EEPROM_ADDR, time_millis());
 
	
 
	// Trippy error LEDs while waiting 4 seconds for system reset
 
	while(1)
 
	{
 
		led_on(LED_ACT0);
 
		led_on(LED_ACT1);
 
		led_on(LED_ACT2);
 
		led_on(LED_ACT3);
 
		led_on(LED_ERROR);
 
		led_on(LED_STATUS);
 
		led_on(LED_ACTIVITY);
 
		led_on(LED_SIDEBOARD);
 
		_delay_ms(50);
 
		led_off(LED_ACT0);
 
		led_off(LED_ACT1);
 
		led_off(LED_ACT2);
 
		led_off(LED_ACT3);
 
		led_off(LED_ERROR);
 
		led_off(LED_STATUS);
 
		led_off(LED_ACTIVITY);
 
		led_off(LED_SIDEBOARD);
 
		_delay_ms(50);
 
	}	
 
}
 
\ No newline at end of file
master/master/lib/watchdog.h
Show inline comments
 
@@ -6,14 +6,15 @@
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#ifndef WATCHDOG_H
 
#define WATCHDOG_H
 
 
void watchdog_setup(void);
 
void watchdog_checkreset(void);
 
 
#endif
 
\ No newline at end of file
master/master/master.c
Show inline comments
 
@@ -45,26 +45,26 @@ int main(void)
 
	// Power debounce
 
	_delay_ms(1000);
 
	
 
	led_setup();
 
	gps_setup();
 
	serial0_setup();
 
	serial1_setup();
 
	i2c_init();
 
	sensordata_setup(); // must happen before slavesensors/logger/AFSK
 
	slavesensors_setup();
 
	sensors_setup();
 
	logger_setup();
 
	watchdog_checkreset();
 
	afsk_setup();
 
	
 
	serial0_sendString("\r\nHello.\r\n\r\n");
 
	
 
	// Blocking ZigBee node discovery
 
	slavesensors_network_scan();
 
	
 
	// Software timers	
 
	uint32_t lastAprsBroadcast = 0;
 
	uint32_t lastLog = 0;
 
	uint32_t lastLedCycle = 0;
 
	uint32_t lastDataReq = 0;
 
	uint32_t lastBuzz = 0;
 
	
0 comments (0 inline, 0 general)