1/*********************************************************************
2   PicoTCP. Copyright (c) 2014-2017 Altran Intelligent Systems. Some rights reserved.
3   See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
4
5 *********************************************************************/
6#ifndef _INCLUDE_PICO_ESP8266
7#define _INCLUDE_PICO_ESP8266
8
9#include <stdio.h>
10
11#include <stdint.h>
12#include <stdlib.h>
13#include <string.h>
14#include "pico_constants.h"
15
16/* -------------- DEBUG ------------- */
17
18/* #define dbg(...) */
19#define dbg             printf
20
21/* -------------- MEMORY ------------- */
22extern void *pvPortMalloc( size_t xWantedSize );
23extern void vPortFree( void *pv );
24
25#define pico_free   vPortFree
26
27static inline void *pico_zalloc(size_t size)
28{
29    void *ptr = (void *)pvPortMalloc(size);
30
31    if(ptr)
32        memset(ptr, 0u, size);
33
34    return ptr;
35}
36
37/* -------------- TIME ------------- */
38
39extern volatile uint32_t esp_tick;
40
41static inline pico_time PICO_TIME_MS(void)
42{
43    return (pico_time) esp_tick;
44}
45
46static inline pico_time PICO_TIME(void)
47{
48    return PICO_TIME_MS() / 1000;
49}
50
51static inline void PICO_IDLE(void)
52{
53    uint32_t now = esp_tick;
54    while (now == esp_tick)
55        ;
56}
57
58#endif
59