query.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "common.h"
  2. #include "board_cfg.h"
  3. #include "query.h"
  4. static board_t *board = 0;
  5. static uint8_t is_empty();
  6. static uint8_t is_full();
  7. static uint8_t en_queue(w_eeprom_data_t *d);
  8. static uint8_t de_queue(w_eeprom_data_t *d);
  9. void query_init(void)
  10. {
  11. board = get_board();
  12. board->q_cache.front = 0;
  13. board->q_cache.rear = 0;
  14. board->q_cache.is_empty = is_empty;
  15. board->q_cache.en_queue = en_queue;
  16. board->q_cache.de_queue = de_queue;
  17. board->q_cache.is_full = is_full;
  18. }
  19. static uint8_t is_empty()
  20. {
  21. return (board->q_cache.front == board->q_cache.rear) ? 1 : 0;
  22. }
  23. static uint8_t is_full()
  24. {
  25. return (((board->q_cache.rear + 1 ) % QUEUE_MAX) == board->q_cache.front) ? 1 : 0;
  26. }
  27. uint8_t de_queue(w_eeprom_data_t *d)
  28. {
  29. if(is_empty())
  30. {
  31. return 0;
  32. }
  33. *d = board->q_cache.data[board->q_cache.front];
  34. board->q_cache.front = (board->q_cache.front +1) % QUEUE_MAX;
  35. return 1;
  36. }
  37. uint8_t en_queue(w_eeprom_data_t *d)
  38. {
  39. if(is_full())
  40. {
  41. return 0;
  42. }
  43. board->q_cache.data[board->q_cache.rear] = *d;
  44. board->q_cache.rear = (board->q_cache.rear +1) % QUEUE_MAX;
  45. return 1;
  46. }