本项止转自github官方arduino-esp32 传在这里仅为阅读源码方便
projectuser
2019-07-05 50148ccffe21ff54262064ec9f2245900eaf18aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * FreeRTOS.h
 *
 *  Created on: Feb 24, 2017
 *      Author: kolban
 */
 
#ifndef MAIN_FREERTOS_H_
#define MAIN_FREERTOS_H_
#include <stdint.h>
#include <string>
#include <pthread.h>
 
#include <freertos/FreeRTOS.h>   // Include the base FreeRTOS definitions.
#include <freertos/task.h>       // Include the task definitions.
#include <freertos/semphr.h>     // Include the semaphore definitions.
#include <freertos/ringbuf.h>    // Include the ringbuffer definitions.
 
 
/**
 * @brief Interface to %FreeRTOS functions.
 */
class FreeRTOS {
public:
    static void sleep(uint32_t ms);
    static void startTask(void task(void*), std::string taskName, void* param = nullptr, uint32_t stackSize = 2048);
    static void deleteTask(TaskHandle_t pTask = nullptr);
 
    static uint32_t getTimeSinceStart();
 
    class Semaphore {
    public:
        Semaphore(std::string owner = "<Unknown>");
        ~Semaphore();
        void        give();
        void        give(uint32_t value);
        void        giveFromISR();
        void        setName(std::string name);
        bool        take(std::string owner = "<Unknown>");
        bool        take(uint32_t timeoutMs, std::string owner = "<Unknown>");
        std::string toString();
        uint32_t    wait(std::string owner = "<Unknown>");
 
    private:
        SemaphoreHandle_t m_semaphore;
        pthread_mutex_t   m_pthread_mutex;
        std::string       m_name;
        std::string       m_owner;
        uint32_t          m_value;
        bool              m_usePthreads;
 
    };
};
 
 
/**
 * @brief Ringbuffer.
 */
class Ringbuffer {
public:
    Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT);
    ~Ringbuffer();
 
    void*    receive(size_t* size, TickType_t wait = portMAX_DELAY);
    void     returnItem(void* item);
    bool     send(void* data, size_t length, TickType_t wait = portMAX_DELAY);
private:
    RingbufHandle_t m_handle;
};
 
#endif /* MAIN_FREERTOS_H_ */