reg_field.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef _REG_FIELD_H
  2. #define _REG_FIELD_H
  3. #include <stdint.h>
  4. #include <stdarg.h>
  5. enum cmd_op {
  6. CMD_OP_GET = (1 << 0),
  7. CMD_OP_SET = (1 << 1),
  8. CMD_OP_EXEC = (1 << 2),
  9. };
  10. enum pstate {
  11. ST_IN_CMD,
  12. ST_IN_ARG,
  13. };
  14. struct strbuf {
  15. uint8_t idx;
  16. char buf[32];
  17. };
  18. struct cmd_state {
  19. struct strbuf cmd;
  20. struct strbuf arg;
  21. enum pstate state;
  22. void (*out)(const char *format, va_list ap);
  23. };
  24. struct cmd {
  25. const char *cmd;
  26. uint32_t ops;
  27. int (*cb)(struct cmd_state *cs, enum cmd_op op, const char *cmd,
  28. int argc, char **argv);
  29. const char *help;
  30. };
  31. /* structure describing a field in a register */
  32. struct reg_field {
  33. uint8_t reg;
  34. uint8_t shift;
  35. uint8_t width;
  36. };
  37. struct reg_field_ops {
  38. const struct reg_field *fields;
  39. const char **field_names;
  40. uint32_t num_fields;
  41. void *data;
  42. int (*write_cb)(void *data, uint32_t reg, uint32_t val);
  43. uint32_t (*read_cb)(void *data, uint32_t reg);
  44. };
  45. uint32_t reg_field_read(struct reg_field_ops *ops, struct reg_field *field);
  46. int reg_field_write(struct reg_field_ops *ops, struct reg_field *field, uint32_t val);
  47. int reg_field_cmd(struct cmd_state *cs, enum cmd_op op,
  48. const char *cmd, int argc, char **argv,
  49. struct reg_field_ops *ops);
  50. #endif