User Tools

Site Tools


device_firmware_template

Files

The main source file should be called like the device type and the directory name, prefixed with “shc”, e.g. “shc_yourdevice.c|h”.

Main Function

Use these typical functions to initialize your device in the main function:

Create a delay to avoid problems with E2P access when a programmer resets the device in short intervals (which mine did…):
_delay_ms(1000);

Initialize the util functions (e.g. the LED output):
util_init();

Check if the EEPROM matches the device type (and blink forever if it doesn't):
check_eeprom_compatibility(DEVICETYPE_BASE_STATION);

Set, increase and write packet counter:
packetcounter = eeprom_read_UIntValue32(EEPROM_PACKETCOUNTER_BYTE, EEPROM_PACKETCOUNTER_BIT, EEPROM_PACKETCOUNTER_LENGTH_BITS, EEPROM_PACKETCOUNTER_MINVAL, EEPROM_PACKETCOUNTER_MAXVAL) + PACKET_COUNTER_WRITE_CYCLE;
eeprom_write_UIntValue(EEPROM_PACKETCOUNTER_BYTE, EEPROM_PACKETCOUNTER_BIT, EEPROM_PACKETCOUNTER_LENGTH_BITS, packetcounter);

Read AES key:
aes_key_count = eeprom_read_UIntValue8(EEPROM_AESKEYCOUNT_BYTE, EEPROM_AESKEYCOUNT_BIT, EEPROM_AESKEYCOUNT_LENGTH_BITS, EEPROM_AESKEYCOUNT_MINVAL, EEPROM_AESKEYCOUNT_MAXVAL);

Read device ID:
deviceID = eeprom_read_UIntValue16(EEPROM_DEVICEID_BYTE, EEPROM_DEVICEID_BIT, EEPROM_DEVICEID_LENGTH_BITS, EEPROM_DEVICEID_MINVAL, EEPROM_DEVICEID_MAXVAL);

Init UART and print out software info:
uart_init();
UART_PUTS(…

Blink three times to show everything is ok (or don't if it's not):
led_blink(500, 500, 3);

Init the RFM12:
rfm12_init(); sei();

Start your endless loop:
while (42)
{
/* do something */
}

device_firmware_template.txt · Last modified: 2014/01/16 23:02 by breaker27