#ifndef PROTOCOL_FIELDS_H #define PROTOCOL_FIELDS_H #include #include #define PF_CAPACITY 8u enum pf_status { PF_OK = 0, PF_BAD_ID = 1, PF_BAD_LAYOUT = 2, PF_OVERLAP = 3, PF_NOT_FOUND = 4, PF_RANGE = 5, PF_BAD_WORD = 6, PF_FULL = 7 }; struct pf_field { uint32_t id; uint32_t width; uint32_t offset; uint32_t scale; uint32_t bias; uint32_t value; }; struct pf_bank { struct pf_field fields[PF_CAPACITY]; uint32_t count; uint32_t word; uint32_t epoch; uint32_t writes; uint32_t imports; uint32_t rejects; }; struct pf_info { uint32_t present; uint32_t width; uint32_t offset; uint32_t scale; uint32_t bias; uint32_t value; uint32_t limit; uint32_t token; }; void pf_init(struct pf_bank *bank); uint32_t pf_mask(uint32_t width); uint32_t pf_limit(const struct pf_field *field); uint32_t pf_bits(const struct pf_field *field); int pf_shape(const struct pf_field *field); int pf_find(const struct pf_bank *bank, uint32_t id); int pf_layout(const struct pf_bank *bank); uint32_t pf_occupied(const struct pf_bank *bank); int pf_token(const struct pf_field *field, uint32_t value, uint32_t *token); int pf_untoken(const struct pf_field *field, uint32_t token, uint32_t *value); int pf_encode(const struct pf_bank *bank, uint32_t *word); int pf_decode(const struct pf_bank *bank, uint32_t word, uint32_t *values); int pf_add(struct pf_bank *bank, uint32_t id, uint32_t width, uint32_t offset, uint32_t scale, uint32_t bias); int pf_replace(struct pf_bank *bank, uint32_t id, uint32_t width, uint32_t offset, uint32_t scale, uint32_t bias); int pf_drop(struct pf_bank *bank, uint32_t id); int pf_write(struct pf_bank *bank, uint32_t id, uint32_t value); int pf_import(struct pf_bank *bank, uint32_t word); int pf_zero(struct pf_bank *bank); int pf_clear(struct pf_bank *bank); int pf_read(const struct pf_bank *bank, uint32_t id, uint32_t *value); void pf_info(const struct pf_bank *bank, uint32_t id, struct pf_info *info); uint32_t pf_fingerprint(const struct pf_bank *bank); uint32_t pf_minimum_word(const struct pf_bank *bank); uint32_t pf_maximum_word(const struct pf_bank *bank); uint32_t pf_value_sum(const struct pf_bank *bank); uint32_t pf_value_weight(const struct pf_bank *bank); uint32_t pf_layout_span(const struct pf_bank *bank); uint32_t pf_free_bits(const struct pf_bank *bank); #endif