49 #define PRINTF(...) printf(__VA_ARGS__)
60 #define BATMON_LOG_PERIOD 60
62 static const uint8_t magic[3] = { 0x0B, 0xEE, 0xF0 };
76 unsigned long f_write;
81 #define RECORD_SIZE 64
82 #define LAST_WRITE (0xFFFF - RECORD_SIZE)
84 #define LOG_TRIGGER_PERIODIC 0xFF
86 struct flash_address {
91 static struct flash_address f;
93 static struct record r;
94 static struct sensors_sensor *s;
96 #define FLASH_START_ADDR 0x1E0000
97 #define FLASH_END_ADDR 0x1FFFFF
99 PROCESS(batmon_process,
"Logger Process");
102 find_gap() CC_NON_BANKED
105 uint32_t address = FLASH_START_ADDR;
106 memset(&f, 0,
sizeof(f));
108 for(address = FLASH_START_ADDR; address <= FLASH_END_ADDR; address +=
110 n740_analog_deactivate();
111 f.s = ((address & 0xFF0000) >> 16);
112 f.p = ((address & 0xFF00) >> 8);
113 f.a = address & 0xFF;
114 m25p16_read_fast((uint8_t *)&f, seq,
sizeof(magic));
115 n740_analog_activate();
116 if(memcmp(seq, magic,
sizeof(magic)) != 0) {
117 PRINTF(
"BatMon: Resume write @ 0x%02x%02x%02x\n", f.s, f.p, f.a);
127 abort() CC_NON_BANKED
129 PRINTF(
"BatMon: Abort\n");
135 batmon_log(uint8_t trigger)
145 next |= (((uint32_t) f.p) << 8);
146 next |= (((uint32_t) f.s) << 16);
148 memcpy(r.magic, magic,
sizeof(magic));
153 r.v = s->value(ADC_SENSOR_TYPE_VDD);
156 r.b = s->value(ADC_SENSOR_TYPE_BATTERY);
160 r.mcu = energest_type_time(ENERGEST_TYPE_CPU);
161 r.lpm = energest_type_time(ENERGEST_TYPE_LPM);
162 r.irq = energest_type_time(ENERGEST_TYPE_IRQ);
163 r.tx = energest_type_time(ENERGEST_TYPE_TRANSMIT);
164 r.rx = energest_type_time(ENERGEST_TYPE_LISTEN);
165 r.f_write = energest_type_time(ENERGEST_TYPE_FLASH_WRITE);
166 r.f_read = energest_type_time(ENERGEST_TYPE_FLASH_READ);
169 n740_analog_deactivate();
174 m25p16_pp((uint8_t *)&f, (uint8_t *)&r,
sizeof(r));
175 n740_analog_activate();
177 PRINTF(
"BatMon: @%lu [%u] ", r.c, r.trigger);
178 PRINTF(
"BatMon: 0x%02x%02x%02x\n", f.s, f.p, f.a);
182 if(next >= FLASH_END_ADDR) {
187 f.s = ((next & 0xFF0000) >> 16);
188 f.p = ((next & 0xFF00) >> 8);
191 if(trigger == LOG_TRIGGER_PERIODIC) {
201 PRINTF(
"BatMon\n",
sizeof(r));
203 s = sensors_find(ADC_SENSOR);
205 PRINTF(
"BatMon: ADC not found\n");
209 n740_analog_deactivate();
211 n740_analog_activate();
214 if(find_gap() == -1) {
215 PRINTF(
"BatMon: Flash storage full\n");
224 batmon_log(LOG_TRIGGER_PERIODIC);
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
int process_is_running(struct process *p)
Check if a process is running.
#define PROCESS_EXIT()
Exit the currently running process.
#define PROCESS_BEGIN()
Define the beginning of a process.
Header file for the control of the M25P16 on sensinode N740s.
void m25p16_pp(uint8_t *addr, uint8_t *buff, uint8_t buff_len)
Program Page (PP) instruction.
Header file for the energy estimation mechanism
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
Header File for the module which controls the Sensinode N740 8-bit serial-in/serial or parall...
#define PROCESS(name, strname)
Declare a process.
CCIF unsigned long clock_seconds(void)
Get the current value of the platform seconds.
void etimer_reset(struct etimer *et)
Reset an event timer with the same interval as was previously set.
void etimer_stop(struct etimer *et)
Stop a pending event timer.
#define PROCESS_YIELD()
Yield the currently running process.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
Defines for the sensors on the various Sensinode models.
#define M25P16_WIP()
Check for Write in Progress.
void process_exit(struct process *p)
Cause a process to exit.
#define CLOCK_SECOND
A second, measured in system clock time.
void m25p16_res()
Release from Deep Power Down (RES) instruction.