This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
zhangyang-libzt/ext/picotcp/include/arch/pico_generic_gcc.h
2017-04-06 19:16:01 -07:00

103 lines
2.2 KiB
C

/*********************************************************************
PicoTCP. Copyright (c) 2012-2015 Altran Intelligent Systems. Some rights reserved.
See LICENSE and COPYING for usage.
*********************************************************************/
#ifndef _INCLUDE_PICO_GCC
#define _INCLUDE_PICO_GCC
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "pico_constants.h"
/* monotonically increasing tick,
* typically incremented every millisecond in a systick interrupt */
extern volatile unsigned int pico_ms_tick;
#define dbg(...)
#ifdef PICO_SUPPORT_PTHREAD
#define PICO_SUPPORT_MUTEX
#endif
#ifdef PICO_SUPPORT_RTOS
#define PICO_SUPPORT_MUTEX
extern void *pico_mutex_init(void);
extern void pico_mutex_lock(void*);
extern void pico_mutex_unlock(void*);
extern void *pvPortMalloc( size_t xSize );
extern void vPortFree( void *pv );
#define pico_free(x) vPortFree(x)
#define free(x) vPortFree(x)
static inline void *pico_zalloc(size_t size)
{
void *ptr = pvPortMalloc(size);
if(ptr)
memset(ptr, 0u, size);
return ptr;
}
static inline pico_time PICO_TIME_MS()
{
return pico_ms_tick;
}
static inline pico_time PICO_TIME()
{
return pico_ms_tick / 1000;
}
static inline void PICO_IDLE(void)
{
pico_time now = PICO_TIME_MS();
while(now == PICO_TIME_MS()) ;
}
#else /* NO RTOS SUPPORT */
#ifdef MEM_MEAS
/* These functions should be implemented elsewhere */
extern void *memmeas_zalloc(size_t size);
extern void memmeas_free(void *);
#define pico_free(x) memmeas_free(x)
#define pico_zalloc(x) memmeas_zalloc(x)
#else
/* Use plain C-lib malloc and free */
#define pico_free(x) free(x)
static inline void *pico_zalloc(size_t size)
{
void *ptr = malloc(size);
if(ptr)
memset(ptr, 0u, size);
return ptr;
}
#endif
static inline pico_time PICO_TIME_MS(void)
{
return (pico_time)pico_ms_tick;
}
static inline pico_time PICO_TIME(void)
{
return (pico_time)(PICO_TIME_MS() / 1000);
}
static inline void PICO_IDLE(void)
{
unsigned int now = pico_ms_tick;
while(now == pico_ms_tick) ;
}
#endif /* IFNDEF RTOS */
#endif /* PICO_GCC */