queue.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. ******************************** STM32F0xx *********************************
  3. * @文件名 : queue.h
  4. * @作者 : sun
  5. * @库版本 : V1.5.0
  6. * @文件版本 : V1.0.0
  7. * @日期 : 2016年06月10日
  8. * @摘要 :Lorausart头文件
  9. ******************************************************************************/
  10. /* 定义防止递归包含 ----------------------------------------------------------*/
  11. #ifndef _QUEUE_H
  12. #define _QUEUE_H
  13. //#define QUEUE_DEBUG_EN 1
  14. #ifdef QUEUE_DEBUG_EN
  15. #include <stdio.h>
  16. #define QUEUE_DEBUG(fmt, x...) \
  17. do \
  18. { \
  19. printf(fmt,##x); \
  20. }while(0)
  21. #define QUEUE_DEBUG1(fmt, x...) \
  22. do \
  23. { \
  24. printf("%s(Line %d): "fmt,__FUNCTION__,__LINE__, ##x); \
  25. }while(0)
  26. #define QUEUE_DEBUG_F(fmt, x...) \
  27. do \
  28. { \
  29. printf("%s %s(Line %d): "fmt,__FILE__,__FUNCTION__,__LINE__, ##x); \
  30. }while(0)
  31. #else
  32. #define QUEUE_DEBUG(fmt, x...)
  33. #define QUEUE_DEBUG1(fmt, x...)
  34. #define QUEUE_DEBUG_F(fmt, x...)
  35. #endif
  36. /* 包含的头文件 --------------------------------------------------------------*/
  37. #include "stm32f10x.h"
  38. #define SQ_DEPTH 32
  39. #define SQ_WIDTH 128
  40. typedef struct
  41. {
  42. //uint8_t data[SQ_DEPTH][SQ_WIDTH]; //队列储存区
  43. uint8_t **data; //队列储存区
  44. uint8_t front; //出队标记
  45. uint8_t rear; //入队标记
  46. uint8_t sum; //数量标记
  47. uint8_t depth; //数量标记
  48. uint8_t width; //数量标记
  49. }sequeue_t;
  50. /********************************
  51. 创建空循环队列
  52. ********************************/
  53. sequeue_t * Create_Empty_Sequeue(uint8_t row,uint8_t col);
  54. /********************************
  55. 检查循环队列是否为空
  56. ********************************/
  57. int8_t Check_Seqeue_Empty(sequeue_t * sq);
  58. /********************************
  59. 检查循环队列是否为满
  60. ********************************/
  61. int8_t Check_Seqeue_Full(sequeue_t * sq);
  62. /********************************
  63. 插入队列,插入1条记录
  64. ********************************/
  65. int8_t En_Queue(sequeue_t *sq ,uint8_t *p,uint8_t sizeof_p,uint8_t l);
  66. /********************************
  67. 出队列,读取1条记录,队列改变
  68. ********************************/
  69. int8_t De_Queue(sequeue_t * sq,uint8_t *p,uint8_t sizeof_p,uint8_t *l);
  70. /********************************
  71. 读取队列,读取1条记录,队列不改变
  72. ********************************/
  73. int8_t Read_Queue(sequeue_t * sq,uint8_t *p,uint8_t *l);
  74. /********************************
  75. 添加1条空记录到队列,记录第0个元素代表长度,初始长度为0
  76. ********************************/
  77. int8_t Add_Blank_Queue(sequeue_t *sq);
  78. /********************************
  79. 当前操作的为记录内容,记录尾元添加1个元素,且长度加1
  80. ********************************/
  81. uint8_t Update_Queue(sequeue_t *sq ,uint8_t mode,uint8_t val);
  82. #endif