| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #include "common.h"
- #include "board_cfg.h"
- #include "query.h"
- static board_t *board = 0;
- static uint8_t is_empty();
- static uint8_t is_full();
- static uint8_t en_queue(w_eeprom_data_t *d);
- static uint8_t de_queue(w_eeprom_data_t *d);
- void query_init(void)
- {
- board = get_board();
- board->q_cache.front = 0;
- board->q_cache.rear = 0;
- board->q_cache.is_empty = is_empty;
- board->q_cache.en_queue = en_queue;
- board->q_cache.de_queue = de_queue;
- board->q_cache.is_full = is_full;
- }
- static uint8_t is_empty()
- {
- return (board->q_cache.front == board->q_cache.rear) ? 1 : 0;
- }
- static uint8_t is_full()
- {
- return (((board->q_cache.rear + 1 ) % QUEUE_MAX) == board->q_cache.front) ? 1 : 0;
- }
- uint8_t de_queue(w_eeprom_data_t *d)
- {
- if(is_empty())
- {
- return 0;
- }
- *d = board->q_cache.data[board->q_cache.front];
- board->q_cache.front = (board->q_cache.front +1) % QUEUE_MAX;
- return 1;
- }
- uint8_t en_queue(w_eeprom_data_t *d)
- {
- if(is_full())
- {
- return 0;
- }
- board->q_cache.data[board->q_cache.rear] = *d;
- board->q_cache.rear = (board->q_cache.rear +1) % QUEUE_MAX;
- return 1;
- }
|