00001 #ifndef __AVR_SETTINGS_H__
00002 #define __AVR_SETTINGS_H__
00003
00004 #include <inttypes.h>
00005 #include <stdlib.h>
00006 #include <stdbool.h>
00007
00008 typedef uint16_t settings_key_t;
00009
00010 #define SETTINGS_KEY_EUI64 'E'*256+'8'
00011 #define SETTINGS_KEY_EUI48 'E'*256+'6'
00012 #define SETTINGS_KEY_CHANNEL 'C'*256+'H'
00013 #define SETTINGS_KEY_TXPOWER 'T'*256+'P'
00014 #define SETTINGS_KEY_PAN_ID 'P'*256+'N'
00015 #define SETTINGS_KEY_PAN_ADDR 'P'*256+'A'
00016 #define SETTINGS_KEY_AES128KEY 'S'*256+'K'
00017 #define SETTINGS_KEY_AES128ENABLED 'S'*256+'E'
00018
00019 typedef enum {
00020 SETTINGS_STATUS_OK=0,
00021 SETTINGS_STATUS_INVALID_ARGUMENT,
00022 SETTINGS_STATUS_NOT_FOUND,
00023 SETTINGS_STATUS_OUT_OF_SPACE,
00024 SETTINGS_STATUS_UNIMPLEMENTED,
00025 SETTINGS_STATUS_FAILURE,
00026 } settings_status_t;
00027
00028
00029 #define SETTINGS_LAST_INDEX (0xFF)
00030
00031 #define SETTINGS_INVALID_KEY (0x00)
00032
00033 #define SETTINGS_MAX_VALUE_SIZE (0x3FFF) // 16383 bytes
00034
00035 extern settings_status_t settings_get(settings_key_t key,uint8_t index,unsigned char* value,size_t* value_size);
00036 extern settings_status_t settings_add(settings_key_t key,const unsigned char* value,size_t value_size);
00037 extern bool settings_check(settings_key_t key,uint8_t index);
00038 extern void settings_wipe(void);
00039
00040 extern settings_status_t settings_set(settings_key_t key,const unsigned char* value,size_t value_size);
00041 extern settings_status_t settings_delete(settings_key_t key,uint8_t index);
00042
00043
00044
00045
00046 static inline uint8_t
00047 settings_get_uint8(settings_key_t key,uint8_t index) {
00048 uint8_t ret = 0;
00049 size_t sizeof_uint8 = sizeof(uint8_t);
00050 settings_get(key,index,(unsigned char*)&ret,&sizeof_uint8);
00051 return ret;
00052 }
00053
00054 static inline settings_status_t
00055 settings_add_uint8(settings_key_t key,uint8_t value) {
00056 return settings_add(key,(const unsigned char*)&value,sizeof(uint8_t));
00057 }
00058
00059 static inline settings_status_t
00060 settings_set_uint8(settings_key_t key,uint8_t value) {
00061 return settings_set(key,(const unsigned char*)&value,sizeof(uint8_t));
00062 }
00063
00064 static inline uint16_t
00065 settings_get_uint16(settings_key_t key,uint8_t index) {
00066 uint16_t ret = 0;
00067 size_t sizeof_uint16 = sizeof(uint16_t);
00068 settings_get(key,index,(unsigned char*)&ret,&sizeof_uint16);
00069 return ret;
00070 }
00071
00072 static inline settings_status_t
00073 settings_add_uint16(settings_key_t key,uint16_t value) {
00074 return settings_add(key,(const unsigned char*)&value,sizeof(uint16_t));
00075 }
00076
00077 static inline settings_status_t
00078 settings_set_uint16(settings_key_t key,uint16_t value) {
00079 return settings_set(key,(const unsigned char*)&value,sizeof(uint16_t));
00080 }
00081
00082 static inline uint32_t
00083 settings_get_uint32(settings_key_t key,uint8_t index) {
00084 uint32_t ret = 0;
00085 size_t sizeof_uint32 = sizeof(uint32_t);
00086 settings_get(key,index,(unsigned char*)&ret,&sizeof_uint32);
00087 return ret;
00088 }
00089
00090 static inline settings_status_t
00091 settings_add_uint32(settings_key_t key,uint32_t value) {
00092 return settings_add(key,(const unsigned char*)&value,sizeof(uint32_t));
00093 }
00094
00095 static inline settings_status_t
00096 settings_set_uint32(settings_key_t key,uint32_t value) {
00097 return settings_set(key,(const unsigned char*)&value,sizeof(uint32_t));
00098 }
00099
00100 static inline uint64_t
00101 settings_get_uint64(settings_key_t key,uint8_t index) {
00102 uint64_t ret = 0;
00103 size_t sizeof_uint64 = sizeof(uint64_t);
00104 settings_get(key,index,(unsigned char*)&ret,&sizeof_uint64);
00105 return ret;
00106 }
00107
00108 static inline settings_status_t
00109 settings_add_uint64(settings_key_t key,uint64_t value) {
00110 return settings_add(key,(const unsigned char*)&value,sizeof(uint64_t));
00111 }
00112
00113 static inline settings_status_t
00114 settings_set_uint64(settings_key_t key,uint64_t value) {
00115 return settings_set(key,(const unsigned char*)&value,sizeof(uint64_t));
00116 }
00117
00118 #endif