X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fao_log.c;h=21d0bc34419fa96f883a9d7eefac0946e5addad1;hb=408a3e04362d626778640dd0ce7d356d3863de53;hp=132512e6ea682f53032dc9a6d56966ae4b35183b;hpb=e4ba9bf4291bf17c777c8c3ef7c71e4a30b9947a;p=fw%2Faltos diff --git a/src/ao_log.c b/src/ao_log.c index 132512e6..21d0bc34 100644 --- a/src/ao_log.c +++ b/src/ao_log.c @@ -168,7 +168,7 @@ ao_log_erase_pos(uint8_t i) return i * sizeof (struct ao_log_erase) + AO_STORAGE_ERASE_LOG; } -static void +void ao_log_write_erase(uint8_t pos) { erase.unused = 0x00; @@ -234,9 +234,10 @@ ao_log_flight(uint8_t slot) } static void -ao_log_scan(void) +ao_log_scan(void) __reentrant { uint8_t log_slot; + uint8_t log_slots; uint8_t log_avail = 0; uint16_t log_flight; @@ -244,7 +245,7 @@ ao_log_scan(void) ao_flight_number = 0; - /* Scan the log space looking for an empty one, and find the biggest flight number */ + /* Scan the log space looking for the biggest flight number */ log_slot = 0; { log_flight = ao_log_flight(log_slot); @@ -256,8 +257,9 @@ ao_log_scan(void) ao_flight_number = log_flight; } } else - log_avail |= 1 << log_slot; + log_avail = 1; } + log_slots = log_slot + 1; /* Now look through the log of flight numbers from erase operations and * see if the last one is bigger than what we found above @@ -279,25 +281,12 @@ ao_log_scan(void) * that we write logs to each spot about the same number of times. */ - /* If there are no log slots available, then - * do not log the next flight - */ - if (!log_avail) { - ao_log_current_pos = 0; - ao_log_end_pos = 0; - } else { - log_slot = ao_flight_number % log_slot; - while (!((log_avail & (1 << log_slot)))) { - if ((1 << log_slot) > log_avail) - log_slot = 0; - else - log_slot++; - } -// ao_log_current_pos = log_slot * ao_config.flight_log_max; -// ao_log_end_pos = ao_log_current_pos + ao_config.flight_log_max; + /* Find a log slot for the next flight, if available */ + if (log_avail) { ao_log_current_pos = 0; ao_log_end_pos = ao_storage_config; - } + } else + ao_log_current_pos = ao_log_end_pos = 0; ao_wakeup(&ao_flight_number); } @@ -331,6 +320,7 @@ ao_log_list(void) __reentrant if (flight) printf ("Flight %d\n", flight); } + printf ("done\n"); } void @@ -364,13 +354,16 @@ ao_log_delete(void) __reentrant ao_storage_erase(ao_log_current_pos); ao_log_current_pos += ao_storage_block; } - puts("Erased\n"); + puts("Erased"); return; } } + ao_log_erase_mark(); printf("No such flight: %d\n", ao_cmd_lex_i); } + + __code struct ao_cmds ao_log_cmds[] = { { 'l', ao_log_list, "l List stored flight logs" }, { 'd', ao_log_delete, "d Delete stored flight" },