1 #include <stdio.h>
2 #include <string.h>
3 #include <pthread.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include "esp32_mock.h"
7 
8 void*     g_queue;
9 int       g_queue_send_shall_fail = 0;
10 int       g_size = 0;
11 
12 const char * WIFI_EVENT = "wifi_event";
13 const char * ETH_EVENT = "eth_event";
14 
esp_event_handler_register(const char * event_base,int32_t event_id,void * event_handler,void * event_handler_arg)15 esp_err_t esp_event_handler_register(const char * event_base,
16                                         int32_t event_id,
17                                         void* event_handler,
18                                         void* event_handler_arg)
19 {
20     return ESP_OK;
21 }
22 
esp_event_handler_unregister(const char * event_base,int32_t event_id,void * event_handler)23 esp_err_t esp_event_handler_unregister(const char * event_base, int32_t event_id, void* event_handler)
24 {
25     return ESP_OK;
26 }
27 
esp_timer_delete(esp_timer_handle_t timer)28 esp_err_t esp_timer_delete(esp_timer_handle_t timer)
29 {
30     return ESP_OK;
31 }
32 
esp_timer_stop(esp_timer_handle_t timer)33 esp_err_t esp_timer_stop(esp_timer_handle_t timer)
34 {
35     return ESP_OK;
36 }
37 
esp_timer_start_periodic(esp_timer_handle_t timer,uint64_t period)38 esp_err_t esp_timer_start_periodic(esp_timer_handle_t timer, uint64_t period)
39 {
40     return ESP_OK;
41 }
42 
esp_timer_create(const esp_timer_create_args_t * create_args,esp_timer_handle_t * out_handle)43 esp_err_t esp_timer_create(const esp_timer_create_args_t* create_args,
44                            esp_timer_handle_t* out_handle)
45 {
46     return ESP_OK;
47 }
48 
xTaskGetTickCount(void)49 uint32_t xTaskGetTickCount(void)
50 {
51     static uint32_t tick = 0;
52     return tick++;
53 }
54 
55 /// Queue mock
xQueueCreate(uint32_t uxQueueLength,uint32_t uxItemSize)56  QueueHandle_t xQueueCreate( uint32_t uxQueueLength, uint32_t uxItemSize )
57  {
58      g_size = uxItemSize;
59      g_queue = malloc((uxQueueLength)*(uxItemSize));
60      return g_queue;
61  }
62 
63 
vQueueDelete(QueueHandle_t xQueue)64 void vQueueDelete( QueueHandle_t xQueue )
65 {
66     free(xQueue);
67 }
68 
xQueueSend(QueueHandle_t xQueue,const void * pvItemToQueue,TickType_t xTicksToWait)69 uint32_t xQueueSend(QueueHandle_t xQueue, const void * pvItemToQueue, TickType_t xTicksToWait)
70 {
71     if (g_queue_send_shall_fail)
72     {
73         return pdFALSE;
74     }
75     else
76     {
77         memcpy(xQueue, pvItemToQueue, g_size);
78         return pdPASS;
79     }
80 }
81 
82 
xQueueReceive(QueueHandle_t xQueue,void * pvBuffer,TickType_t xTicksToWait)83 uint32_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait)
84 {
85     return pdFALSE;
86 }
87 
GetLastItem(void * pvBuffer)88 void GetLastItem(void *pvBuffer)
89 {
90     memcpy(pvBuffer, g_queue, g_size);
91 }
92 
ForceTaskDelete(void)93 void ForceTaskDelete(void)
94 {
95     g_queue_send_shall_fail = 1;
96 }
97 
xTaskGetCurrentTaskHandle(void)98 TaskHandle_t xTaskGetCurrentTaskHandle(void)
99 {
100     return NULL;
101 }
102 
xTaskNotifyGive(TaskHandle_t task)103 void xTaskNotifyGive(TaskHandle_t task)
104 {
105     return;
106 }
107 
xTaskNotifyWait(uint32_t bits_entry_clear,uint32_t bits_exit_clear,uint32_t * value,TickType_t wait_time)108 BaseType_t xTaskNotifyWait(uint32_t bits_entry_clear, uint32_t bits_exit_clear, uint32_t * value, TickType_t wait_time)
109 {
110     return pdTRUE;
111 }
112