Porting PicoTCP WIP

This commit is contained in:
2025-10-29 14:29:06 +01:00
parent 6722f42e68
commit 815c2239fe
464 changed files with 235009 additions and 24 deletions

View File

@ -0,0 +1,35 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*********************************************************************/
#define dbg(...) do {} while(0)
/******************/
/*** MACHINE CONFIGURATION ***/
/* Temporary (POSIX) stuff. */
#include <string.h>
#include <unistd.h>
extern volatile uint32_t __str9_tick;
#define pico_native_malloc(x) calloc(x, 1)
#define pico_native_free(x) free(x)
static inline unsigned long PICO_TIME(void)
{
register uint32_t tick = __str9_tick;
return tick / 1000;
}
static inline unsigned long PICO_TIME_MS(void)
{
return __str9_tick;
}
static inline void PICO_IDLE(void)
{
unsigned long tick_now = __str9_tick;
while(tick_now == __str9_tick) ;
}

View File

@ -0,0 +1,61 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*********************************************************************/
/*** MACHINE CONFIGURATION ***/
/* Temporary (POSIX) stuff. */
#include <string.h>
#include <unistd.h>
/* Temporary debugging stuff. */
#include <stdarg.h>
#include "halUart.h"
#include <stdio.h>
static void print_uart(char *str)
{
int i, len;
len = (int)strlen(str);
for (i = 0; i < len; i++) {
HAL_UartWriteByte(str[i]);
if (HAL_UartTxFull())
HAL_UartFlush();
}
}
static inline void sam_dbg(const char *format, ...)
{
char msg[128] = { 0 };
va_list args;
va_start(args, format);
vsnprintf(msg, 256, format, args);
va_end(args);
print_uart(msg);
}
//#define dbg sam_dbg
#define dbg(...) do { } while(0)
extern volatile uint32_t sam_tick;
#define pico_zalloc(x) calloc(x, 1)
#define pico_free(x) free(x)
static inline unsigned long PICO_TIME(void)
{
register uint32_t tick = sam_tick;
return tick / 1000;
}
static inline unsigned long PICO_TIME_MS(void)
{
return sam_tick;
}
static inline void PICO_IDLE(void)
{
unsigned long tick_now = sam_tick;
while(tick_now == sam_tick) ;
}

View File

@ -0,0 +1,39 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*********************************************************************/
#define dbg(...) do {} while(0)
/* #define dbg printf */
/*************************/
/*** MACHINE CONFIGURATION ***/
/* Temporary (POSIX) stuff. */
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include "pico_mm.h"
extern volatile uint32_t __avr_tick;
#define pico_zalloc(x) calloc(x, 1)
#define pico_free(x) free(x)
static inline unsigned long PICO_TIME(void)
{
register uint32_t tick = __avr_tick;
return tick / 1000;
}
static inline unsigned long PICO_TIME_MS(void)
{
return __avr_tick;
}
static inline void PICO_IDLE(void)
{
unsigned long tick_now = __avr_tick;
while(tick_now == __avr_tick) ;
}

View File

@ -0,0 +1,12 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*********************************************************************/
#ifndef _INCLUDE_PICO_CORTEX_M
#define _INCLUDE_PICO_CORTEX_M
#include "pico_generic_gcc.h"
#endif /* PICO_CORTEX_M */

View File

@ -0,0 +1,44 @@
/*
* This is a picoTCP arch file for the DOS 16 bit target using OpenWatcom v1.9
* Copyright (C) 2015 Mateusz Viste
*
* This code is donated to the picoTCP project, and shares the same licensing,
* that is GNU GPLv2.
*
* See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*/
#include <dos.h> /* provides int86() along with the union REGS type */
#ifndef PICO_SUPPORT_DOS_WATCOM
#define PICO_SUPPORT_DOS_WATCOM
#define dbg(...)
#define pico_zalloc(x) calloc(x, 1)
#define pico_free(x) free(x)
static inline unsigned long PICO_TIME_MS(void)
{
union REGS regs;
unsigned long ticks;
regs.h.ah = 0; /* get system time (IBM BIOS call) - INT 1A,0 */
int86(0x1A, &regs, &regs);
ticks = regs.x.cx; /* number of ticks since midnight (high word) */
ticks <<= 16;
ticks |= regs.x.dx; /* number of ticks since midnight (low word) */
return (ticks * 55); /* a tick is 55ms because the i8253 PIT runs at 18.2 Hz */
}
static inline unsigned long PICO_TIME(void)
{
return (PICO_TIME_MS() / 1000);
}
static inline void PICO_IDLE(void)
{
union REGS regs;
int86(0x28, &regs, &regs); /* DOS 2+ IDLE INTERRUPT */
}
#endif /* PICO_SUPPORT_DOS_WATCOM */

View File

@ -0,0 +1,58 @@
/*********************************************************************
PicoTCP. Copyright (c) 2014-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*********************************************************************/
#ifndef _INCLUDE_PICO_ESP8266
#define _INCLUDE_PICO_ESP8266
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "pico_constants.h"
/* -------------- DEBUG ------------- */
/* #define dbg(...) */
#define dbg printf
/* -------------- MEMORY ------------- */
extern void *pvPortMalloc( size_t xWantedSize );
extern void vPortFree( void *pv );
#define pico_free vPortFree
static inline void *pico_zalloc(size_t size)
{
void *ptr = (void *)pvPortMalloc(size);
if(ptr)
memset(ptr, 0u, size);
return ptr;
}
/* -------------- TIME ------------- */
extern volatile uint32_t esp_tick;
static inline pico_time PICO_TIME_MS(void)
{
return (pico_time) esp_tick;
}
static inline pico_time PICO_TIME(void)
{
return PICO_TIME_MS() / 1000;
}
static inline void PICO_IDLE(void)
{
uint32_t now = esp_tick;
while (now == esp_tick)
;
}
#endif

View File

@ -0,0 +1,117 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*********************************************************************/
#ifndef _INCLUDE_PICO_GCC
#define _INCLUDE_PICO_GCC
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "pico_constants.h"
/* #define TIME_PRESCALE */
/* 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;
}
/* time prescaler */
#ifdef TIME_PRESCALE
extern int32_t prescale_time;
#endif
static inline pico_time PICO_TIME_MS()
{
#ifdef TIME_PRESCALE
return pico_ms_tick << prescale_time;
#else
return pico_ms_tick;
#endif
}
static inline pico_time PICO_TIME()
{
#ifdef TIME_PRESCALE
return (pico_ms_tick / 1000) << prescale_time;
#else
return (pico_ms_tick / 1000);
#endif
}
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 */

View File

@ -0,0 +1,33 @@
#ifndef PICO_SUPPORT_LINUX
#define PICO_SUPPORT_LINUX
#include "linux/types.h"
#include "linux/mm.h"
#include "linux/slab.h"
#include "linux/jiffies.h"
#define dbg printk
#define pico_zalloc(x) kcalloc(x, 1, GFP_ATOMIC) /* All allocations are GFP_ATOMIC for now */
#define pico_free(x) kfree(x)
static inline unsigned long PICO_TIME(void)
{
return (unsigned long)(jiffies_to_msecs(jiffies) / 1000);
}
static inline unsigned long PICO_TIME_MS(void)
{
return (unsigned long)jiffies_to_msecs(jiffies);
}
static inline void PICO_IDLE(void)
{
unsigned long now = jiffies;
while (now == jiffies) {
;
}
}
#endif

View File

@ -0,0 +1,185 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
File: pico_mbed.h
Author: Toon Peters
*********************************************************************/
#ifndef PICO_SUPPORT_MBED
#define PICO_SUPPORT_MBED
#include <stdio.h>
#include <pico_queue.h>
/* #include "mbed.h" */
/* #include "serial_api.h" */
/* #define TIME_PRESCALE */
/* #define PICO_MEASURE_STACK */
/* #define MEMORY_MEASURE */
/*
Debug needs initialization:
* void serial_init (serial_t *obj, PinName tx, PinName rx);
* void serial_baud (serial_t *obj, int baudrate);
* void serial_format (serial_t *obj, int data_bits, SerialParity parity, int stop_bits);
*/
#define dbg(...)
/*
#define MEMORY_MEASURE
#define JENKINS_DEBUG
*/
/* Intended for Mr. Jenkins endurance test loggings */
#ifdef JENKINS_DEBUG
#include "PicoTerm.h"
#define jenkins_dbg ptm_dbg
#endif
#ifdef PICO_MEASURE_STACK
extern int freeStack;
#define STACK_TOTAL_WORDS 1000u
#define STACK_PATTERN (0xC0CAC01Au)
void stack_fill_pattern(void *ptr);
void stack_count_free_words(void *ptr);
int stack_get_free_words(void);
#else
#define stack_fill_pattern(...) do {} while(0)
#define stack_count_free_words(...) do {} while(0)
#define stack_get_free_words() (0)
#endif
#ifdef MEMORY_MEASURE /* in case, comment out the two defines above me. */
extern uint32_t max_mem;
extern uint32_t cur_mem;
struct mem_chunk_stats {
#ifdef MEMORY_MEASURE_ADV
uint32_t signature;
void *mem;
#endif
uint32_t size;
};
static inline void *pico_zalloc(int x)
{
struct mem_chunk_stats *stats;
if ((cur_mem + x) > (10 * 1024))
return NULL;
stats = (struct mem_chunk_stats *)calloc(x + sizeof(struct mem_chunk_stats), 1);
#ifdef MEMORY_MEASURE_ADV
stats->signature = 0xdeadbeef;
stats->mem = ((uint8_t *)stats) + sizeof(struct mem_chunk_stats);
#endif
stats->size = x;
/* Intended for Mr. Jenkins endurance test loggings */
#ifdef JENKINS_DEBUG
if (!stats) {
jenkins_dbg(">> OUT OF MEM\n");
while(1) ;
;
}
#endif
cur_mem += x;
if (cur_mem > max_mem) {
max_mem = cur_mem;
/* printf("max mem: %lu\n", max_mem); */
}
#ifdef MEMORY_MEASURE_ADV
return (void*)(stats->mem);
#else
return (void*) (((uint8_t *)stats) + sizeof(struct mem_chunk_stats));
#endif
}
static inline void pico_free(void *x)
{
struct mem_chunk_stats *stats = (struct mem_chunk_stats *) ((uint8_t *)x - sizeof(struct mem_chunk_stats));
#ifdef JENKINS_DEBUG
#ifdef MEMORY_MEASURE_ADV
if ((stats->signature != 0xdeadbeef) || (x != stats->mem)) {
jenkins_dbg(">> FREE ERROR: caller is %p\n", __builtin_return_address(0));
while(1) ;
;
}
#endif
#endif
cur_mem -= stats->size;
memset(stats, 0, sizeof(struct mem_chunk_stats));
free(stats);
}
#else
#define pico_zalloc(x) calloc(x, 1)
#define pico_free(x) free(x)
#endif
#define PICO_SUPPORT_MUTEX
extern void *pico_mutex_init(void);
extern void pico_mutex_lock(void*);
extern void pico_mutex_unlock(void*);
extern void pico_mutex_deinit(void*);
extern uint32_t os_time;
extern pico_time local_time;
extern uint32_t last_os_time;
#ifdef TIME_PRESCALE
extern int32_t prescale_time;
#endif
#define UPDATE_LOCAL_TIME() do {local_time = local_time + ((pico_time)os_time - (pico_time)last_os_time);last_os_time = os_time;} while(0)
static inline pico_time PICO_TIME(void)
{
UPDATE_LOCAL_TIME();
#ifdef TIME_PRESCALE
return (prescale_time < 0) ? (pico_time)(local_time / 1000 << (-prescale_time)) : \
(pico_time)(local_time / 1000 >> prescale_time);
#else
return (pico_time)(local_time / 1000);
#endif
}
static inline pico_time PICO_TIME_MS(void)
{
UPDATE_LOCAL_TIME();
#ifdef TIME_PRESCALE
return (prescale_time < 0) ? (pico_time)(local_time << (-prescale_time)) : \
(pico_time)(local_time >> prescale_time);
#else
return (pico_time)local_time;
#endif
}
static inline void PICO_IDLE(void)
{
/* TODO needs implementation */
}
/*
static inline void PICO_DEBUG(const char * formatter, ... )
{
char buffer[256];
char *ptr;
va_list args;
va_start(args, formatter);
vsnprintf(buffer, 256, formatter, args);
ptr = buffer;
while(*ptr != '\0')
serial_putc(serial_t *obj, (int) (*(ptr++)));
va_end(args);
//TODO implement serial_t
}*/
#endif

View File

@ -0,0 +1,26 @@
#ifndef PICO_SUPPORT_MOP2
#define PICO_SUPPORT_MOP2
#include "dlmalloc/malloc.h"
#include "time/time.h"
#include "kprintf.h"
// proc/proc.c
extern uint64_t uptime_ms;
#define dbg kprintf
#define pico_zalloc(x) (dlmalloc((x)))
#define pico_free(x) (dlfree((x)))
static inline unsigned long PICO_TIME(void) {
return uptime_ms / 1000;
}
static inline unsigned long PICO_TIME_MS(void) {
return uptime_ms;
}
static inline void PICO_IDLE(void) {
}
#endif // PICO_SUPPORT_MOP2

View File

@ -0,0 +1,38 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*********************************************************************/
#ifndef _INCLUDE_PICO_LPC
#define _INCLUDE_PICO_LPC
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "pico_constants.h"
extern pico_time msp430_time_s(void);
extern pico_time msp430_time_ms(void);
extern void *malloc(size_t);
extern void free(void *);
#define PICO_TIME() msp430_time_s()
#define PICO_TIME_MS() msp430_time_ms()
#define PICO_IDLE() do {} while(0)
#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;
}
#define dbg(...)
#endif

View File

@ -0,0 +1,22 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*********************************************************************/
#ifndef PICO_SUPPORT_ARCHNONE
#define PICO_SUPPORT_ARCHNONE
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#define dbg(...) do {} while(0)
#define pico_zalloc(x) NULL
#define pico_free(x) do {} while(0)
#define PICO_TIME() 666
#define PICO_TIME_MS() 666000
#define PICO_IDLE() do {} while(0)
#endif /* PICO_SUPPORT_ARCHNONE */

View File

@ -0,0 +1,100 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*********************************************************************/
#ifndef PICO_SUPPORT_PIC24
#define PICO_SUPPORT_PIC24
#define dbg printf
/* #define dbg(...) */
/*************************/
/*** MACHINE CONFIGURATION ***/
#include <stdio.h>
#include <stdint.h>
/* #include "phalox_development_board.h" */
#ifndef __PIC24F__
#define __PIC24F__
#endif
/*
#ifndef __PIC24FJ256GA106__
#define __PIC24FJ256GA106__
#endif
*/
#ifndef PICO_MAX_SOCKET_FRAMES
#define PICO_MAX_SOCKET_FRAMES 16
#endif
/* Device header file */
#if defined(__PIC24E__)
# include <p24Exxxx.h>
#elif defined(__PIC24F__)
# include <p24Fxxxx.h>
#elif defined(__PIC24H__)
# include <p24Hxxxx.h>
#endif
#define TIMBASE_INT_E IEC0bits.T2IE
#ifdef PICO_SUPPORT_DEBUG_MEMORY
static inline void *pico_zalloc(int len)
{
/* dbg("%s: Alloc object of len %d, caller: %p\n", __FUNCTION__, len, __builtin_return_address(0)); */
return calloc(len, 1);
}
static inline void pico_free(void *tgt)
{
/* dbg("%s: Discarded object @%p, caller: %p\n", __FUNCTION__, tgt, __builtin_return_address(0)); */
free(tgt);
}
#else
# define pico_zalloc(x) calloc(x, 1)
# define pico_free(x) free(x)
#endif
extern void *pvPortMalloc( size_t xWantedSize );
extern volatile pico_time __pic24_tick;
static inline unsigned long PICO_TIME(void)
{
unsigned long tick;
/* Disable timer interrupts */
TIMBASE_INT_E = 0;
tick = __pic24_tick;
/* Enable timer interrupts */
TIMBASE_INT_E = 1;
return tick / 1000;
}
static inline unsigned long PICO_TIME_MS(void)
{
unsigned long tick;
/* Disable timer interrupts */
TIMBASE_INT_E = 0;
tick = __pic24_tick;
/* Enable timer interrupts */
TIMBASE_INT_E = 1;
return tick;
}
static inline void PICO_IDLE(void)
{
unsigned long tick_now;
/* Disable timer interrupts */
TIMBASE_INT_E = 0;
tick_now = (unsigned long)pico_tick;
/* Enable timer interrupts */
TIMBASE_INT_E = 1;
/* Doesn't matter that this call isn't interrupt safe, */
/* we just check for the value to change */
while(tick_now == __pic24_tick) ;
}
#endif

View File

@ -0,0 +1,54 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*********************************************************************/
#ifndef _INCLUDE_PICO_PIC32
#define _INCLUDE_PICO_PIC32
#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;
#ifdef PIC32_NO_PRINTF
#define dbg(...) do {} while(0)
#else
#define dbg printf
#endif
/* 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;
}
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 /* PICO_PIC32 */

View File

@ -0,0 +1,137 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
*********************************************************************/
#ifndef PICO_SUPPORT_POSIX
#define PICO_SUPPORT_POSIX
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
/*
#define MEMORY_MEASURE
#define TIME_PRESCALE
#define PICO_SUPPORT_THREADING
*/
#define dbg printf
#define stack_fill_pattern(...) do {} while(0)
#define stack_count_free_words(...) do {} while(0)
#define stack_get_free_words() (0)
/* measure allocated memory */
#ifdef MEMORY_MEASURE
extern uint32_t max_mem;
extern uint32_t cur_mem;
static inline void *pico_zalloc(int x)
{
uint32_t *ptr;
if ((cur_mem + x) > (10 * 1024))
return NULL;
ptr = (uint32_t *)calloc(x + 4, 1);
*ptr = (uint32_t)x;
cur_mem += x;
if (cur_mem > max_mem) {
max_mem = cur_mem;
}
return (void*)(ptr + 1);
}
static inline void pico_free(void *x)
{
uint32_t *ptr = (uint32_t*)(((uint8_t *)x) - 4);
cur_mem -= *ptr;
free(ptr);
}
#else
#define pico_zalloc(x) calloc(x, 1)
#define pico_free(x) free(x)
#endif
/* time prescaler */
#ifdef TIME_PRESCALE
extern int32_t prescale_time;
#endif
#if defined(PICO_SUPPORT_RTOS) || defined (PICO_SUPPORT_PTHREAD)
/* pico_ms_tick must be defined */
extern volatile uint32_t pico_ms_tick;
static inline uint32_t PICO_TIME(void)
{
#ifdef TIME_PRESCALE
return (pico_ms_tick / 1000) << prescale_time;
#else
return (pico_ms_tick / 1000);
#endif
}
static inline uint32_t PICO_TIME_MS(void)
{
#ifdef TIME_PRESCALE
return pico_ms_tick << prescale_time;
#else
return pico_ms_tick;
#endif
}
#else
static inline uint32_t PICO_TIME(void)
{
struct timeval t;
gettimeofday(&t, NULL);
#ifdef TIME_PRESCALE
return (prescale_time < 0) ? (uint32_t)(t.tv_sec / 1000 << (-prescale_time)) : \
(uint32_t)(t.tv_sec / 1000 >> prescale_time);
#else
return (uint32_t)t.tv_sec;
#endif
}
static inline uint32_t PICO_TIME_MS(void)
{
struct timeval t;
gettimeofday(&t, NULL);
#ifdef TIME_PRESCALER
uint32_t tmp = ((t.tv_sec * 1000) + (t.tv_usec / 1000));
return (prescale_time < 0) ? (uint32_t)(tmp / 1000 << (-prescale_time)) : \
(uint32_t)(tmp / 1000 >> prescale_time);
#else
return (uint32_t)((t.tv_sec * 1000) + (t.tv_usec / 1000));
#endif
}
#endif
#ifdef PICO_SUPPORT_THREADING
#define PICO_SUPPORT_MUTEX
/* mutex implementations */
extern void *pico_mutex_init(void);
extern void pico_mutex_lock(void *mux);
extern void pico_mutex_unlock(void *mux);
/* semaphore implementations (only used in wrapper code) */
extern void *pico_sem_init(void);
extern void pico_sem_destroy(void *sem);
extern void pico_sem_post(void *sem);
/* returns -1 on timeout (in ms), else returns 0 */
/* if timeout < 0, the semaphore waits forever */
extern int pico_sem_wait(void *sem, int timeout);
/* thread implementations */
extern void *pico_thread_create(void *(*routine)(void *), void *arg);
#endif /* PICO_SUPPORT_THREADING */
static inline void PICO_IDLE(void)
{
usleep(5000);
}
#endif /* PICO_SUPPORT_POSIX */