00001
00045 #ifndef JOURNAL_H_INCLUDED
00046 #define JOURNAL_H_INCLUDED
00047
00048 #include <dataflash/dataflash.h>
00049
00050 enum journal_status {
00051 JOURNAL_IDLE,
00052 JOURNAL_BUSY,
00053 JOURNAL_END_NOT_LOCALIZED,
00054 JOURNAL_ENTRY_OPEN,
00055 JOURNAL_ERROR,
00056 };
00057
00062 struct journal_entry {
00063 uint16_t magic0;
00064 uint16_t length;
00065 uint32_t card_id;
00066 uint32_t block;
00067 uint16_t committed_card0_magic;
00068 uint16_t committed_card1_magic;
00069 };
00070
00071 struct journal;
00072 typedef void (*journal_callback_t)(
00073 struct journal *,
00074 struct journal_entry *,
00075 void *);
00076
00078 struct journal {
00080 struct dataflash_device *storage;
00082 unsigned int start;
00084 unsigned int length;
00089 unsigned int last_location;
00091 unsigned int current_location;
00093 unsigned long flags;
00095 unsigned int status;
00097 journal_callback_t callback;
00099 void *context;
00100
00102 struct buffer entry_buffer;
00104 struct dataflash_request request;
00105 struct dataflash_request erase_request;
00107 struct journal_entry *current_entry;
00109 uint16_t magic_number;
00111 unsigned int search_mode;
00112
00113 struct workqueue_item workqueue_item;
00114 };
00115
00116 #define JOURNAL_EMPTY (1 << 0)
00117 #define JOURNAL_CARD0_COMMITTED (1 << 1)
00118 #define JOURNAL_CARD1_COMMITTED (1 << 2)
00119
00120 void journal_init(
00121 struct journal *media,
00122 struct dataflash_device *storage,
00123 unsigned int start_addr,
00124 unsigned int length);
00125
00126 void journal_open_entry(
00127 struct journal *media,
00128 struct journal_entry *entry,
00129 journal_callback_t entry_stored,
00130 void *context);
00131
00132 void journal_commit_card(
00133 struct journal *media,
00134 struct journal_entry *entry,
00135 unsigned int card_nr,
00136 journal_callback_t card_committed,
00137 void *context);
00138
00139 void journal_close_entry(struct journal *media);
00140
00141 void journal_get_last_entry(
00142 struct journal *media,
00143 struct journal_entry *entry,
00144 journal_callback_t entry_retrieved,
00145 void *context);
00146
00147 void journal_clean_last_entry(
00148 struct journal *media,
00149 journal_callback_t entry_cleaned,
00150 void *context);
00151
00152 void journal_prepare_entry(
00153 struct journal_entry *entry,
00154 uint32_t card_id,
00155 uint32_t block,
00156 uint16_t length);
00157
00158 bool journal_entry_card_is_intact(
00159 struct journal_entry *entry,
00160 unsigned int card_nr);
00161
00162 bool journal_entry_is_consistent(struct journal_entry *entry);
00163
00176 static inline bool journal_is_empty(struct journal *journal)
00177 {
00178 assert(journal);
00179 return !!(journal->flags & JOURNAL_EMPTY);
00180 }
00181
00182 #endif
00183