/**
 * @file cc.h
 * @brief Compiler/Platform specific definitions for LwIP on STM32 + FreeRTOS
 */

#ifndef __CC_H__
#define __CC_H__

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "lwip/errno.h"

/* Use standard integer types from stdint.h */
#define LWIP_NO_STDINT_H  0

/* Define basic types for LwIP */
typedef uint8_t   u8_t;
typedef int8_t    s8_t;
typedef uint16_t  u16_t;
typedef int16_t   s16_t;
typedef uint32_t  u32_t;
typedef int32_t   s32_t;

typedef uint32_t  sys_prot_t;

typedef uintptr_t mem_ptr_t;

/* Byte order - ARM Cortex-M is little endian */
#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
#endif

/* Compiler specific structure packing */
#if defined (__ICCARM__)
/* IAR Compiler */
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#define PACK_STRUCT_USE_INCLUDES

#elif defined (__CC_ARM) || defined (__ARMCC_VERSION)
/* ARM Compiler (Keil MDK) */
#define PACK_STRUCT_BEGIN __packed
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x

#elif defined (__GNUC__)
/* GNU Compiler */
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT __attribute__ ((packed))
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x

#else
/* Default */
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#endif

/* Platform specific diagnostic output */
#ifndef LWIP_PLATFORM_DIAG
#define LWIP_PLATFORM_DIAG(x) do { } while(0)
#endif

/* Platform specific assertion handling */
#ifndef LWIP_PLATFORM_ASSERT
#define LWIP_PLATFORM_ASSERT(x) do { while(1) { } } while(0)
#endif

/* Get current time in milliseconds (provided by sys_arch.c) */
extern u32_t sys_now(void);

/* Random number generator */
#ifndef LWIP_RAND
#define LWIP_RAND() ((u32_t)rand())
#endif

#endif /* __CC_H__ */
