Browse Source

添加ticket zqueue

transmit_disinfection
zhaohe 11 months ago
parent
commit
7628a01fff
  1. 4
      stm32basic.hpp
  2. 20
      ticket.cpp
  3. 8
      ticket.hpp
  4. 5
      zqueue.cpp
  5. 42
      zqueue.hpp

4
stm32basic.hpp

@ -3,4 +3,6 @@
#include "mutex.hpp"
#include "zadc.hpp"
#include "zspi.hpp"
#include "zgpio.hpp"
#include "zgpio.hpp"
#include "ticket.hpp"
#include "zqueue.hpp"

20
ticket.cpp

@ -0,0 +1,20 @@
#include "ticket.hpp"
#include "cmsis_os.h"
#include "cmsis_version.h"
extern "C" {
uint32_t zos_get_tick(void) { return osKernelSysTick(); }
uint32_t zos_haspassedms2(uint32_t lastticket, uint32_t nowticket) {
if (nowticket >= lastticket) {
return nowticket - lastticket;
}
return UINT32_MAX - lastticket + nowticket;
}
uint32_t zos_haspassedms(uint32_t ticket) {
uint32_t nowticket = zos_get_tick();
if (nowticket >= ticket) {
return nowticket - ticket;
}
return UINT32_MAX - ticket + nowticket;
}
}

8
ticket.hpp

@ -0,0 +1,8 @@
#pragma once
#include <stdint.h>
extern "C" {
uint32_t zos_get_tick(void);
uint32_t zos_haspassedms(uint32_t ticket);
uint32_t zos_haspassedms2(uint32_t lastticket, uint32_t nowticket);
}

5
zqueue.cpp

@ -0,0 +1,5 @@
#include "zqueue.hpp"
#include "basic/zlog.h"
using namespace iflytop;
#define TAG "ZQueue"

42
zqueue.hpp

@ -0,0 +1,42 @@
#pragma once
#include "cmsis_os.h"
#include "basic/zlog.h"
namespace iflytop {
template <typename T>
class ZQueue {
private:
int32_t m_num = 0;
int32_t m_eachsize = 0;
QueueHandle_t xQueue;
public:
void initialize(int32_t num, int32_t eachsize) {
xQueue = xQueueCreate(num, eachsize);
ZASSERT(xQueue);
}
void clear() { xQueueReset(xQueue); }
bool send(T *data, int32_t overtime) { return _send((uint8_t *)data, sizeof(T), overtime); }
bool receive(T *data, int32_t overtime) { return _receive((uint8_t *)data, overtime); }
bool isFull() {
BaseType_t xStatus = xQueueIsQueueFullFromISR(xQueue);
return xStatus == pdTRUE;
}
bool isEmpty() {
BaseType_t xStatus = xQueueIsQueueEmptyFromISR(xQueue);
return xStatus == pdTRUE;
}
private:
bool _send(uint8_t *data, int32_t len, int32_t overtime) {
BaseType_t xStatus = xQueueSend(xQueue, data, overtime);
return xStatus == pdPASS;
}
bool _receive(uint8_t *data, int32_t overtime) {
BaseType_t xStatus = xQueueReceive(xQueue, data, overtime);
return xStatus == pdPASS;
}
};
} // namespace iflytop
Loading…
Cancel
Save