diff --git a/arch/arm/arm-v6m/common/include/tos_cpu_def.h b/arch/arm/arm-v6m/common/include/tos_cpu_def.h index 50d0d838..03346cc2 100644 --- a/arch/arm/arm-v6m/common/include/tos_cpu_def.h +++ b/arch/arm/arm-v6m/common/include/tos_cpu_def.h @@ -26,5 +26,8 @@ #define CPU_STK_GROWTH_ASCENDING 1 #define CPU_STK_GROWTH_DESCENDING 2 +#define CPU_BYTE_ORDER_LITTLE_ENDIAN 1 +#define CPU_BYTE_ORDER_BIG_ENDIAN 2 + #endif /* _TOS_CPU_DEF_H_ */ diff --git a/arch/arm/arm-v6m/cortex-m0/armcc/port_config.h b/arch/arm/arm-v6m/cortex-m0/armcc/port_config.h index b0300236..cc3d1e75 100644 --- a/arch/arm/arm-v6m/cortex-m0/armcc/port_config.h +++ b/arch/arm/arm-v6m/cortex-m0/armcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/arm/arm-v6m/cortex-m0/gcc/port_config.h b/arch/arm/arm-v6m/cortex-m0/gcc/port_config.h index b0300236..cc3d1e75 100644 --- a/arch/arm/arm-v6m/cortex-m0/gcc/port_config.h +++ b/arch/arm/arm-v6m/cortex-m0/gcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/arm/arm-v6m/cortex-m0/iccarm/port_config.h b/arch/arm/arm-v6m/cortex-m0/iccarm/port_config.h index b0300236..cc3d1e75 100644 --- a/arch/arm/arm-v6m/cortex-m0/iccarm/port_config.h +++ b/arch/arm/arm-v6m/cortex-m0/iccarm/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/arm/arm-v7a/common/include/tos_cpu_def.h b/arch/arm/arm-v7a/common/include/tos_cpu_def.h index 50d0d838..03346cc2 100644 --- a/arch/arm/arm-v7a/common/include/tos_cpu_def.h +++ b/arch/arm/arm-v7a/common/include/tos_cpu_def.h @@ -26,5 +26,8 @@ #define CPU_STK_GROWTH_ASCENDING 1 #define CPU_STK_GROWTH_DESCENDING 2 +#define CPU_BYTE_ORDER_LITTLE_ENDIAN 1 +#define CPU_BYTE_ORDER_BIG_ENDIAN 2 + #endif /* _TOS_CPU_DEF_H_ */ diff --git a/arch/arm/arm-v7a/cortex-a7/gcc/port_config.h b/arch/arm/arm-v7a/cortex-a7/gcc/port_config.h index fd077913..0c3687ef 100644 --- a/arch/arm/arm-v7a/cortex-a7/gcc/port_config.h +++ b/arch/arm/arm-v7a/cortex-a7/gcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) #define TOS_CFG_CPU_ARM_FPU_EN 1u diff --git a/arch/arm/arm-v7m/common/include/tos_cpu_def.h b/arch/arm/arm-v7m/common/include/tos_cpu_def.h index 50d0d838..03346cc2 100644 --- a/arch/arm/arm-v7m/common/include/tos_cpu_def.h +++ b/arch/arm/arm-v7m/common/include/tos_cpu_def.h @@ -26,5 +26,8 @@ #define CPU_STK_GROWTH_ASCENDING 1 #define CPU_STK_GROWTH_DESCENDING 2 +#define CPU_BYTE_ORDER_LITTLE_ENDIAN 1 +#define CPU_BYTE_ORDER_BIG_ENDIAN 2 + #endif /* _TOS_CPU_DEF_H_ */ diff --git a/arch/arm/arm-v7m/cortex-m0+/armcc/port_config.h b/arch/arm/arm-v7m/cortex-m0+/armcc/port_config.h index b0300236..cc3d1e75 100644 --- a/arch/arm/arm-v7m/cortex-m0+/armcc/port_config.h +++ b/arch/arm/arm-v7m/cortex-m0+/armcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/arm/arm-v7m/cortex-m0+/gcc/port_config.h b/arch/arm/arm-v7m/cortex-m0+/gcc/port_config.h index b0300236..cc3d1e75 100644 --- a/arch/arm/arm-v7m/cortex-m0+/gcc/port_config.h +++ b/arch/arm/arm-v7m/cortex-m0+/gcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/arm/arm-v7m/cortex-m0+/iccarm/port_config.h b/arch/arm/arm-v7m/cortex-m0+/iccarm/port_config.h index b0300236..cc3d1e75 100644 --- a/arch/arm/arm-v7m/cortex-m0+/iccarm/port_config.h +++ b/arch/arm/arm-v7m/cortex-m0+/iccarm/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/arm/arm-v7m/cortex-m3/armcc/port_config.h b/arch/arm/arm-v7m/cortex-m3/armcc/port_config.h index 31d5bd81..caa47cdb 100644 --- a/arch/arm/arm-v7m/cortex-m3/armcc/port_config.h +++ b/arch/arm/arm-v7m/cortex-m3/armcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/arm/arm-v7m/cortex-m3/gcc/port_config.h b/arch/arm/arm-v7m/cortex-m3/gcc/port_config.h index 31d5bd81..caa47cdb 100644 --- a/arch/arm/arm-v7m/cortex-m3/gcc/port_config.h +++ b/arch/arm/arm-v7m/cortex-m3/gcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/arm/arm-v7m/cortex-m4/armcc/port_config.h b/arch/arm/arm-v7m/cortex-m4/armcc/port_config.h index 936d5a6d..84689b44 100644 --- a/arch/arm/arm-v7m/cortex-m4/armcc/port_config.h +++ b/arch/arm/arm-v7m/cortex-m4/armcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #if (defined(ARMCC_V5) && !defined(__TARGET_FPU_SOFTVFP)) || \ (defined(ARMCC_V6) && defined(__ARM_PCS_VFP)) diff --git a/arch/arm/arm-v7m/cortex-m4/gcc/port_config.h b/arch/arm/arm-v7m/cortex-m4/gcc/port_config.h index a363b793..9145f29f 100644 --- a/arch/arm/arm-v7m/cortex-m4/gcc/port_config.h +++ b/arch/arm/arm-v7m/cortex-m4/gcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) #define TOS_CFG_CPU_ARM_FPU_EN 1u diff --git a/arch/arm/arm-v7m/cortex-m4/iccarm/port_config.h b/arch/arm/arm-v7m/cortex-m4/iccarm/port_config.h index 285c1213..9988f682 100644 --- a/arch/arm/arm-v7m/cortex-m4/iccarm/port_config.h +++ b/arch/arm/arm-v7m/cortex-m4/iccarm/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #ifndef __ARMVFP__ #define TOS_CFG_CPU_ARM_FPU_EN 0u diff --git a/arch/arm/arm-v7m/cortex-m7/armcc/port_config.h b/arch/arm/arm-v7m/cortex-m7/armcc/port_config.h index 936d5a6d..84689b44 100644 --- a/arch/arm/arm-v7m/cortex-m7/armcc/port_config.h +++ b/arch/arm/arm-v7m/cortex-m7/armcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #if (defined(ARMCC_V5) && !defined(__TARGET_FPU_SOFTVFP)) || \ (defined(ARMCC_V6) && defined(__ARM_PCS_VFP)) diff --git a/arch/arm/arm-v7m/cortex-m7/gcc/port_config.h b/arch/arm/arm-v7m/cortex-m7/gcc/port_config.h index a363b793..9145f29f 100644 --- a/arch/arm/arm-v7m/cortex-m7/gcc/port_config.h +++ b/arch/arm/arm-v7m/cortex-m7/gcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) #define TOS_CFG_CPU_ARM_FPU_EN 1u diff --git a/arch/arm/arm-v7m/cortex-m7/iccarm/port_config.h b/arch/arm/arm-v7m/cortex-m7/iccarm/port_config.h index 285c1213..9988f682 100644 --- a/arch/arm/arm-v7m/cortex-m7/iccarm/port_config.h +++ b/arch/arm/arm-v7m/cortex-m7/iccarm/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 1u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #ifndef __ARMVFP__ #define TOS_CFG_CPU_ARM_FPU_EN 0u diff --git a/arch/arm/arm-v8m/common/include/tos_cpu_def.h b/arch/arm/arm-v8m/common/include/tos_cpu_def.h index 50d0d838..03346cc2 100644 --- a/arch/arm/arm-v8m/common/include/tos_cpu_def.h +++ b/arch/arm/arm-v8m/common/include/tos_cpu_def.h @@ -26,5 +26,8 @@ #define CPU_STK_GROWTH_ASCENDING 1 #define CPU_STK_GROWTH_DESCENDING 2 +#define CPU_BYTE_ORDER_LITTLE_ENDIAN 1 +#define CPU_BYTE_ORDER_BIG_ENDIAN 2 + #endif /* _TOS_CPU_DEF_H_ */ diff --git a/arch/arm/arm-v8m/cortex-m23/armcc/port_config.h b/arch/arm/arm-v8m/cortex-m23/armcc/port_config.h index b0300236..cc3d1e75 100644 --- a/arch/arm/arm-v8m/cortex-m23/armcc/port_config.h +++ b/arch/arm/arm-v8m/cortex-m23/armcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/arm/arm-v8m/cortex-m23/gcc/port_config.h b/arch/arm/arm-v8m/cortex-m23/gcc/port_config.h index b0300236..cc3d1e75 100644 --- a/arch/arm/arm-v8m/cortex-m23/gcc/port_config.h +++ b/arch/arm/arm-v8m/cortex-m23/gcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/arm/arm-v8m/cortex-m23/iccarm/port_config.h b/arch/arm/arm-v8m/cortex-m23/iccarm/port_config.h index b0300236..cc3d1e75 100644 --- a/arch/arm/arm-v8m/cortex-m23/iccarm/port_config.h +++ b/arch/arm/arm-v8m/cortex-m23/iccarm/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/avr/ATMega32/iccavr/port_config.h b/arch/avr/ATMega32/iccavr/port_config.h index 8259022b..ffa7f9ba 100644 --- a/arch/avr/ATMega32/iccavr/port_config.h +++ b/arch/avr/ATMega32/iccavr/port_config.h @@ -18,13 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_08 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_08 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u - -#define TOS_CFG_CPU_ARM_FPU_EN 0u +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_08 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_08 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_ARM_FPU_EN 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/avr/common/include/tos_cpu_def.h b/arch/avr/common/include/tos_cpu_def.h index 50d0d838..03346cc2 100644 --- a/arch/avr/common/include/tos_cpu_def.h +++ b/arch/avr/common/include/tos_cpu_def.h @@ -26,5 +26,8 @@ #define CPU_STK_GROWTH_ASCENDING 1 #define CPU_STK_GROWTH_DESCENDING 2 +#define CPU_BYTE_ORDER_LITTLE_ENDIAN 1 +#define CPU_BYTE_ORDER_BIG_ENDIAN 2 + #endif /* _TOS_CPU_DEF_H_ */ diff --git a/arch/linux/common/include/tos_cpu_def.h b/arch/linux/common/include/tos_cpu_def.h index 50d0d838..03346cc2 100644 --- a/arch/linux/common/include/tos_cpu_def.h +++ b/arch/linux/common/include/tos_cpu_def.h @@ -26,5 +26,8 @@ #define CPU_STK_GROWTH_ASCENDING 1 #define CPU_STK_GROWTH_DESCENDING 2 +#define CPU_BYTE_ORDER_LITTLE_ENDIAN 1 +#define CPU_BYTE_ORDER_BIG_ENDIAN 2 + #endif /* _TOS_CPU_DEF_H_ */ diff --git a/arch/linux/posix/gcc/port_config.h b/arch/linux/posix/gcc/port_config.h index e87668e6..65b86aa2 100644 --- a/arch/linux/posix/gcc/port_config.h +++ b/arch/linux/posix/gcc/port_config.h @@ -18,12 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_64 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_64 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_64 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_64 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) #define TOS_CFG_CPU_ARM_FPU_EN 1u diff --git a/arch/msp430/MSP430X/icc430/port_config.h b/arch/msp430/MSP430X/icc430/port_config.h index 8779e91d..8ee191ca 100644 --- a/arch/msp430/MSP430X/icc430/port_config.h +++ b/arch/msp430/MSP430X/icc430/port_config.h @@ -21,17 +21,17 @@ /* The stack type changes depending on the data model. */ #if( __DATA_MODEL__ == __DATA_MODEL_SMALL__ ) #define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_16 - #define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_16 + #define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_16 #else #define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 - #define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 + #define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 #endif - -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING // #define TOS_CFG_CPU_HRTIMER_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/arch/msp430/common/include/tos_cpu_def.h b/arch/msp430/common/include/tos_cpu_def.h index f4e48687..0b189c21 100644 --- a/arch/msp430/common/include/tos_cpu_def.h +++ b/arch/msp430/common/include/tos_cpu_def.h @@ -9,5 +9,8 @@ #define CPU_STK_GROWTH_ASCENDING 1 #define CPU_STK_GROWTH_DESCENDING 2 +#define CPU_BYTE_ORDER_LITTLE_ENDIAN 1 +#define CPU_BYTE_ORDER_BIG_ENDIAN 2 + #endif /* _TOS_CPU_DEF_H_ */ diff --git a/arch/risc-v/common/include/tos_cpu_def.h b/arch/risc-v/common/include/tos_cpu_def.h index 6fbb054a..14f046d9 100644 --- a/arch/risc-v/common/include/tos_cpu_def.h +++ b/arch/risc-v/common/include/tos_cpu_def.h @@ -26,5 +26,8 @@ #define CPU_STK_GROWTH_ASCENDING 1 #define CPU_STK_GROWTH_DESCENDING 2 +#define CPU_BYTE_ORDER_LITTLE_ENDIAN 1 +#define CPU_BYTE_ORDER_BIG_ENDIAN 2 + #endif /* _TOS_CPU_DEF_H_ */ diff --git a/arch/risc-v/rv32i/gcc/port_config.h b/arch/risc-v/rv32i/gcc/port_config.h index 9a8a5e2b..d8917780 100644 --- a/arch/risc-v/rv32i/gcc/port_config.h +++ b/arch/risc-v/rv32i/gcc/port_config.h @@ -18,10 +18,12 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_32 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ + diff --git a/arch/stm8/common/include/tos_cpu_def.h b/arch/stm8/common/include/tos_cpu_def.h index 50d0d838..03346cc2 100644 --- a/arch/stm8/common/include/tos_cpu_def.h +++ b/arch/stm8/common/include/tos_cpu_def.h @@ -26,5 +26,8 @@ #define CPU_STK_GROWTH_ASCENDING 1 #define CPU_STK_GROWTH_DESCENDING 2 +#define CPU_BYTE_ORDER_LITTLE_ENDIAN 1 +#define CPU_BYTE_ORDER_BIG_ENDIAN 2 + #endif /* _TOS_CPU_DEF_H_ */ diff --git a/arch/stm8/iccstm8/port_config.h b/arch/stm8/iccstm8/port_config.h index 8259022b..ffa7f9ba 100644 --- a/arch/stm8/iccstm8/port_config.h +++ b/arch/stm8/iccstm8/port_config.h @@ -18,13 +18,13 @@ #ifndef _PORT_CONFIG_H_ #define _PORT_CONFIG_H_ -#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_08 -#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_08 -#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING -#define TOS_CFG_CPU_HRTIMER_EN 0u -#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u - -#define TOS_CFG_CPU_ARM_FPU_EN 0u +#define TOS_CFG_CPU_ADDR_SIZE CPU_WORD_SIZE_08 +#define TOS_CFG_CPU_DATA_SIZE CPU_WORD_SIZE_08 +#define TOS_CFG_CPU_STK_GROWTH CPU_STK_GROWTH_DESCENDING +#define TOS_CFG_CPU_HRTIMER_EN 0u +#define TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT 0u +#define TOS_CFG_CPU_ARM_FPU_EN 0u +#define TOS_CFG_CPU_BYTE_ORDER CPU_BYTE_ORDER_LITTLE_ENDIAN #endif /* _PORT_CONFIG_H_ */ diff --git a/examples/tcp_through_module_based_at_socket/tcp_through_module_based_at_socket.c b/examples/tcp_through_module_based_at_socket/tcp_through_module_based_at_socket.c new file mode 100644 index 00000000..4afd27e9 --- /dev/null +++ b/examples/tcp_through_module_based_at_socket/tcp_through_module_based_at_socket.c @@ -0,0 +1,77 @@ +#include "esp8266.h" +#include "mcu_init.h" +#include "cmsis_os.h" +#include "tos_at_socket.h" + +#define TCP_TEST_TASK_STK_SIZE 4096 +void tcp_test(void); +osThreadDef(tcp_test, osPriorityNormal, 1, TCP_TEST_TASK_STK_SIZE); + +#define RECV_LEN 1024 +uint8_t recv_data[RECV_LEN]; + +void tcp_test(void) +{ + int recv_len = -1; + int fd, rc, cnt = 0; + + struct sockaddr_in addr; + + bzero(&addr, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = inet_addr("39.108.190.129"); + addr.sin_port = htons(8080); + + fd = socket(AF_INET, SOCK_STREAM, 0); + if (fd < 0) { + printf("socket failed\n"); + return; + } + + rc = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); + if (rc < 0) { + printf("connect failed\n"); + close(fd); + return; + } + + while (1) { + send(fd, (const void*)"This is TCP Test!\r\n", strlen("This is TCP Test!\r\n"), 0); + + recv_len = recv(fd, recv_data, sizeof(recv_data), 0); + if (recv_len < 0) { + printf("task receive error\n"); + } else if (recv_len == 0) { + printf("task receive none\n"); + } else { + recv_data[recv_len] = 0; + printf("task: receive len: %d\nmsg from remote: %s\n", recv_len, recv_data); + } + + if (++cnt >= 20) { + break; + } + + tos_sleep_ms(2000); + } + + close(fd); +} + +#define USE_ESP8266 + +void application_entry(void *arg) +{ +#ifdef USE_ESP8266 + esp8266_sal_init(HAL_UART_PORT_0); + esp8266_join_ap("SheldonDai", "srnr6x9xbhmb0"); +#endif + +#ifdef USE_SIM800A + sim800a_power_on(); + sim800a_sal_init(HAL_UART_PORT_2); +#endif + + osThreadCreate(osThread(tcp_test), NULL); +} + diff --git a/examples/tencent_os_mqtt/mqtt_config.h b/examples/tencent_os_mqtt/mqtt_config.h index 83fe2543..5065f52e 100644 --- a/examples/tencent_os_mqtt/mqtt_config.h +++ b/examples/tencent_os_mqtt/mqtt_config.h @@ -6,8 +6,8 @@ #define MQTT_PRODUCT_ID "RUAP1R610V" #define MQTT_DEV_NAME "supowang" #define MQTT_CLIENT_ID "RUAP1R610Vsupowang" -#define MQTT_USR_NAME "RUAP1R610Vsupowang;21010406;12365;4294967295" -#define MQTT_PASSWORD "1371ae55cd1036f088bd7e39d230712bc3c32c40;hmacsha1" +#define MQTT_USR_NAME "RUAP1R610Vsupowang;12010126;LQUY4;1620700055" +#define MQTT_PASSWORD "98398cb32f7cb9d73da51fea84bf400c7f17a3303548624731d76fa8db3b43ff;hmacsha256" #define MQTT_SUBSCRIBE_TOPIC "RUAP1R610V/supowang/data" #define MQTT_PUBLISH_TOPIC "RUAP1R610V/supowang/data" diff --git a/kernel/core/include/tos_config_check.h b/kernel/core/include/tos_config_check.h index 94e8d4e5..1b5cf22a 100644 --- a/kernel/core/include/tos_config_check.h +++ b/kernel/core/include/tos_config_check.h @@ -67,9 +67,9 @@ #endif #ifndef TOS_CFG_CPU_HRTIMER_EN -#error "UNDECLARED config, TOS_CFG_CPU_HRTIMER_EN should be declared in 'port.h'" +#error "UNDECLARED config, TOS_CFG_CPU_HRTIMER_EN should be declared in 'port_config.h'" #elif (TOS_CFG_CPU_HRTIMER_EN > 0u) && !defined(TOS_CFG_CPU_HRTIMER_SIZE) -#error "UNDECLARED config, TOS_CFG_CPU_HRTIMER_SIZE should be declared in 'port.h'" +#error "UNDECLARED config, TOS_CFG_CPU_HRTIMER_SIZE should be declared in 'port_config.h'" #elif (TOS_CFG_CPU_HRTIMER_EN > 0u) && ((TOS_CFG_CPU_HRTIMER_SIZE != CPU_WORD_SIZE_08) && \ (TOS_CFG_CPU_HRTIMER_SIZE != CPU_WORD_SIZE_16) && \ (TOS_CFG_CPU_HRTIMER_SIZE != CPU_WORD_SIZE_32) && \ @@ -78,18 +78,22 @@ #endif #ifndef TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT -#error "UNDECLARED config, TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT, should be declared in 'port.h'" +#error "UNDECLARED config, TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT, should be declared in 'port_config.h'" +#endif + +#ifndef TOS_CFG_CPU_BYTE_ORDER +#error "UNDECLARED config, TOS_CFG_CPU_BYTE_ORDER, should be declared in 'port_config.h'" #endif #ifndef TOS_CFG_CPU_STK_GROWTH -#error "UNDECLARED config, TOS_CFG_CPU_STK_GROWTH, should be declared in 'port.h'" +#error "UNDECLARED config, TOS_CFG_CPU_STK_GROWTH, should be declared in 'port_config.h'" #elif ((TOS_CFG_CPU_STK_GROWTH != CPU_STK_GROWTH_ASCENDING) && \ (TOS_CFG_CPU_STK_GROWTH != CPU_STK_GROWTH_DESCENDING)) #error "INVALID config, TOS_CFG_CPU_STK_GROWTH" #endif #ifndef TOS_CFG_CPU_ADDR_SIZE -#error "UNDECLARED config, TOS_CFG_CPU_ADDR_SIZE, should be declared in 'port.h'" +#error "UNDECLARED config, TOS_CFG_CPU_ADDR_SIZE, should be declared in 'port_config.h'" #elif ((TOS_CFG_CPU_ADDR_SIZE != CPU_WORD_SIZE_08) && \ (TOS_CFG_CPU_ADDR_SIZE != CPU_WORD_SIZE_16) && \ (TOS_CFG_CPU_ADDR_SIZE != CPU_WORD_SIZE_32) && \ @@ -98,7 +102,7 @@ #endif #ifndef TOS_CFG_CPU_DATA_SIZE -#error "UNDECLARED config, TOS_CFG_CPU_DATA_SIZE, should be declared in 'port.h'" +#error "UNDECLARED config, TOS_CFG_CPU_DATA_SIZE, should be declared in 'port_config.h'" #elif ((TOS_CFG_CPU_DATA_SIZE != CPU_WORD_SIZE_08) && \ (TOS_CFG_CPU_DATA_SIZE != CPU_WORD_SIZE_16) && \ (TOS_CFG_CPU_DATA_SIZE != CPU_WORD_SIZE_32) && \ diff --git a/kernel/core/include/tos_config_default.h b/kernel/core/include/tos_config_default.h index 5e5a2185..6fefdbfa 100644 --- a/kernel/core/include/tos_config_default.h +++ b/kernel/core/include/tos_config_default.h @@ -99,14 +99,6 @@ ///////////////////////////////////////// -///////////////////////////////////////// -// disable default -#ifndef TOS_CFG_MMBLK_EN -#define TOS_CFG_MMBLK_EN 0u -#endif -///////////////////////////////////////// - - ///////////////////////////////////////// // disable default #ifndef TOS_CFG_FAULT_BACKTRACE_EN @@ -232,10 +224,6 @@ #define TOS_CFG_TASK_PRIO_MAX 8u #endif -#ifndef TOS_CFG_MMBLK_EN -#define TOS_CFG_MMBLK_EN 0u -#endif - #ifndef TOS_CFG_MMHEAP_EN #define TOS_CFG_MMHEAP_EN 0u #endif diff --git a/kernel/core/include/tos_klib.h b/kernel/core/include/tos_klib.h index 5f6ffdfc..f40277e3 100644 --- a/kernel/core/include/tos_klib.h +++ b/kernel/core/include/tos_klib.h @@ -23,8 +23,8 @@ #include #include -#define TOS_MACRO_BEGIN do { -#define TOS_MACRO_END } while (0) +#define __MACRO_BEGIN do { +#define __MACRO_END } while (0) #define TOS_OFFSET_OF_FIELD(type, field) \ ((uint32_t)&(((type *)0)->field)) @@ -34,59 +34,59 @@ #define TOS_COUNT_OF(array) (sizeof(array) / sizeof(array[0])) -#define TOS_PTR_SANITY_CHECK(ptr) \ -TOS_MACRO_BEGIN \ - if (unlikely(!(ptr))) { \ - return K_ERR_OBJ_PTR_NULL; \ - } \ -TOS_MACRO_END +#define TOS_PTR_SANITY_CHECK(ptr) \ + __MACRO_BEGIN \ + if (unlikely(!(ptr))) { \ + return K_ERR_OBJ_PTR_NULL; \ + } \ + __MACRO_END -#define TOS_PTR_SANITY_CHECK_RC(ptr, return_code) \ -TOS_MACRO_BEGIN \ - if (unlikely(!(ptr))) { \ - return return_code; \ - } \ -TOS_MACRO_END +#define TOS_PTR_SANITY_CHECK_RC(ptr, return_code) \ + __MACRO_BEGIN \ + if (unlikely(!(ptr))) { \ + return return_code; \ + } \ + __MACRO_END -#define TOS_IN_IRQ_CHECK() \ -TOS_MACRO_BEGIN \ - if (unlikely(knl_is_inirq())) { \ - return K_ERR_IN_IRQ; \ - } \ -TOS_MACRO_END +#define TOS_IN_IRQ_CHECK() \ + __MACRO_BEGIN \ + if (unlikely(knl_is_inirq())) { \ + return K_ERR_IN_IRQ; \ + } \ + __MACRO_END #if TOS_CFG_OBJECT_VERIFY_EN > 0u #define TOS_OBJ_INIT(obj, obj_type) knl_object_init(&obj->knl_obj, obj_type) #define TOS_OBJ_DEINIT(obj) knl_object_deinit(&obj->knl_obj) -#define TOS_OBJ_VERIFY(obj, obj_type) \ -TOS_MACRO_BEGIN \ - if (!knl_object_verify(&obj->knl_obj, obj_type)) { \ - return K_ERR_OBJ_INVALID; \ - } \ -TOS_MACRO_END +#define TOS_OBJ_VERIFY(obj, obj_type) \ + __MACRO_BEGIN \ + if (!knl_object_verify(&obj->knl_obj, obj_type)) { \ + return K_ERR_OBJ_INVALID; \ + } \ + __MACRO_END -#define TOS_OBJ_VERIFY_RC(obj, obj_type, return_code) \ -TOS_MACRO_BEGIN \ - if (!knl_object_verify(&obj->knl_obj, obj_type)) { \ - return return_code; \ - } \ -TOS_MACRO_END +#define TOS_OBJ_VERIFY_RC(obj, obj_type, return_code) \ + __MACRO_BEGIN \ + if (!knl_object_verify(&obj->knl_obj, obj_type)) { \ + return return_code; \ + } \ + __MACRO_END -#define TOS_OBJ_TEST(obj, obj_type) \ -TOS_MACRO_BEGIN \ - if (knl_object_verify(&obj->knl_obj, obj_type)) { \ - return K_ERR_OBJ_INVALID; \ - } \ -TOS_MACRO_END +#define TOS_OBJ_TEST(obj, obj_type) \ + __MACRO_BEGIN \ + if (knl_object_verify(&obj->knl_obj, obj_type)) { \ + return K_ERR_OBJ_INVALID; \ + } \ + __MACRO_END -#define TOS_OBJ_TEST_RC(obj, obj_type, return_code) \ -TOS_MACRO_BEGIN \ - if (knl_object_verify(&obj->knl_obj, obj_type)) { \ - return return_code; \ - } \ -TOS_MACRO_END +#define TOS_OBJ_TEST_RC(obj, obj_type, return_code) \ + __MACRO_BEGIN \ + if (knl_object_verify(&obj->knl_obj, obj_type)) { \ + return return_code; \ + } \ + __MACRO_END #else diff --git a/kernel/core/include/tos_mmblk.h b/kernel/core/include/tos_mmblk.h index cc072cd6..4761444b 100644 --- a/kernel/core/include/tos_mmblk.h +++ b/kernel/core/include/tos_mmblk.h @@ -20,8 +20,6 @@ __CDECLS_BEGIN -#if TOS_CFG_MMBLK_EN > 0u - #define K_MMBLK_NEXT_BLK(blk_curr, blk_size) ((void *)((cpu_addr_t)blk_curr + blk_size)) #define K_MMBLK_ALIGN_MASK (sizeof(void *) - 1u) @@ -107,5 +105,3 @@ __API__ k_err_t tos_mmblk_free(k_mmblk_pool_t *mbp, void *blk); __CDECLS_END -#endif /* _TOS_MMBLK_H_ */ - diff --git a/kernel/core/tos_message_queue.c b/kernel/core/tos_message_queue.c index bbf65524..ca91a36f 100644 --- a/kernel/core/tos_message_queue.c +++ b/kernel/core/tos_message_queue.c @@ -15,7 +15,7 @@ * within TencentOS. *---------------------------------------------------------------------------*/ - #include "tos_k.h" +#include "tos_k.h" #if TOS_CFG_MESSAGE_QUEUE_EN > 0u diff --git a/kernel/core/tos_mmblk.c b/kernel/core/tos_mmblk.c index ebda308e..15ba8ec3 100644 --- a/kernel/core/tos_mmblk.c +++ b/kernel/core/tos_mmblk.c @@ -17,13 +17,10 @@ #include "tos_k.h" -#if TOS_CFG_MMBLK_EN > 0u - __API__ k_err_t tos_mmblk_pool_create(k_mmblk_pool_t *mbp, void *pool_start, size_t blk_num, size_t blk_size) { uint32_t i; - void *blk_curr; - void *blk_next; + void *blk_curr, *blk_next; TOS_IN_IRQ_CHECK(); TOS_PTR_SANITY_CHECK(pool_start); @@ -106,6 +103,7 @@ __API__ k_err_t tos_mmblk_free(k_mmblk_pool_t *mbp, void *blk) TOS_CPU_INT_ENABLE(); return K_ERR_MMBLK_POOL_FULL; } + *(void **)blk = mbp->free_list; mbp->free_list = blk; ++mbp->blk_free; @@ -113,5 +111,3 @@ __API__ k_err_t tos_mmblk_free(k_mmblk_pool_t *mbp, void *blk) return K_ERR_NONE; } -#endif - diff --git a/kernel/core/tos_priority_message_queue.c b/kernel/core/tos_priority_message_queue.c index a94e3f37..07925f08 100644 --- a/kernel/core/tos_priority_message_queue.c +++ b/kernel/core/tos_priority_message_queue.c @@ -15,7 +15,7 @@ * within TencentOS. *---------------------------------------------------------------------------*/ - #include "tos_k.h" +#include "tos_k.h" #if TOS_CFG_PRIORITY_MESSAGE_QUEUE_EN > 0u diff --git a/kernel/core/tos_rwlock.c b/kernel/core/tos_rwlock.c index dcc030e7..dcf1a05c 100644 --- a/kernel/core/tos_rwlock.c +++ b/kernel/core/tos_rwlock.c @@ -22,6 +22,7 @@ __API__ k_err_t tos_rwlock_create(k_rwlock_t *rwlock) { k_err_t err; + TOS_PTR_SANITY_CHECK(rwlock); err = tos_sem_create(&rwlock->signal, 0u); diff --git a/net/at/include/tos_at.h b/net/at/include/tos_at.h index 36040eb8..0ac360ef 100644 --- a/net/at/include/tos_at.h +++ b/net/at/include/tos_at.h @@ -93,7 +93,7 @@ typedef struct at_echo_st { size_t __w_idx; int __is_expecting; k_sem_t __expect_notify; - int fuzzy_matching; + int __is_fuzzy_match; } at_echo_t; typedef void (*at_event_callback_t)(void); @@ -269,7 +269,7 @@ __API__ int tos_at_init(hal_uart_port_t uart_port, at_event_t *event_table, size * * @attention None * - * @return + * @return None */ __API__ void tos_at_deinit(void); diff --git a/net/at/include/tos_at_utils.h b/net/at/include/tos_at_utils.h index b4930d7a..e642b8b1 100644 --- a/net/at/include/tos_at_utils.h +++ b/net/at/include/tos_at_utils.h @@ -1,3 +1,20 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + #ifndef _TOS_AT_UTILS_H_ #define _TOS_AT_UTILS_H_ diff --git a/net/at/src/tos_at.c b/net/at/src/tos_at.c index a9cd6cde..f2674cb6 100644 --- a/net/at/src/tos_at.c +++ b/net/at/src/tos_at.c @@ -1,3 +1,20 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + #include "tos_at.h" __STATIC__ at_agent_t at_agent; @@ -161,18 +178,16 @@ __STATIC__ int at_is_echo_expect(void) return 0; } - if(at_echo->fuzzy_matching){ - if(strstr(recv_buffer, expect)!=NULL){ - return 0; - } - return -1; + if (at_echo->__is_fuzzy_match) { + if (strstr(recv_buffer, expect) != NULL) { + return 0; + } + return -1; } - + if (strncmp(expect, recv_buffer, expect_len) == 0) { return 1; } - - return 0; } @@ -346,7 +361,7 @@ __API__ int tos_at_echo_create(at_echo_t *echo, char *buffer, size_t buffer_size echo->status = AT_ECHO_STATUS_NONE; echo->__w_idx = 0; echo->__is_expecting = K_FALSE; - echo->fuzzy_matching = K_FALSE; + echo->__is_fuzzy_match = K_FALSE; return 0; } @@ -367,7 +382,7 @@ __API__ int tos_at_echo_fuzzy_matching_create(at_echo_t *echo, char *buffer, siz echo->status = AT_ECHO_STATUS_NONE; echo->__w_idx = 0; echo->__is_expecting = K_FALSE; - echo->fuzzy_matching = K_TRUE; + echo->__is_fuzzy_match = K_TRUE; return 0; } diff --git a/net/at/src/tos_at_utils.c b/net/at/src/tos_at_utils.c index 8e254034..6aab751e 100644 --- a/net/at/src/tos_at_utils.c +++ b/net/at/src/tos_at_utils.c @@ -1,3 +1,20 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + #include "tos_k.h" #include "tos_at.h" diff --git a/net/sal_module_wrapper/sal_module_wrapper.h b/net/sal_module_wrapper/sal_module_wrapper.h index 7ff5d2cf..74c11393 100644 --- a/net/sal_module_wrapper/sal_module_wrapper.h +++ b/net/sal_module_wrapper/sal_module_wrapper.h @@ -21,7 +21,7 @@ #include #include -typedef enum sal_proto_en { +typedef enum sal_protocol_en { TOS_SAL_PROTO_TCP, TOS_SAL_PROTO_UDP, } sal_proto_t; diff --git a/net/socket_wrapper/include/tos_at_socket.h b/net/socket_wrapper/include/tos_at_socket.h new file mode 100644 index 00000000..c19e089a --- /dev/null +++ b/net/socket_wrapper/include/tos_at_socket.h @@ -0,0 +1,66 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + +#ifndef _TOS_AT_SOCKET_H_ +#define _TOS_AT_SOCKET_H_ + +#include "tos_at_socket_lib.h" +#include "tos_at_socket_types.h" + +#define AF_INET 0 + +#define AF_INET6 1 + +#define AF_UNIX 2 + +/* Provides sequenced, reliable, bidirectional, connection-mode byte streams, and may provide a transmission mechanism for out-of-band data. */ +#define SOCK_STREAM 0 + +/* Provides datagrams, which are connectionless-mode, unreliable messages of fixed maximum length. */ +#define SOCK_DGRAM 1 + +/* Peeks at an incoming message. The data is treated as unread and the next recv() or similar function shall still return this data. */ +#define MSG_PEEK 0x01 + +/* Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific. */ +#define MSG_OOB 0x02 + +/* On SOCK_STREAM sockets this requests that the function block until the full amount of data can be returned. The function may return the smaller amount of data if the socket is a message-based socket, if a signal is caught, if the connection is terminated, if MSG_PEEK was specified, or if an error is pending for the socket. */ +#define MSG_WAITALL 0x04 + +int socket(int domain, int type, int protocol); + +int connect(int socket, const struct sockaddr *address, socklen_t address_len); + +int recv(int socket, void *buffer, size_t length, int flags); + +int recvfrom(int socket, void * buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len); + +int send(int socket, const void *buffer, size_t length, int flags); + +int sendto(int socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len); + +int shutdown(int socket, int how); + +int read(int socket, void *buffer, size_t length); + +int close(int socket); + +int write(int socket, const void *buffer, size_t length); + +#endif /* _TOS_AT_SOCKET_H_ */ + diff --git a/net/socket_wrapper/include/tos_at_socket_lib.h b/net/socket_wrapper/include/tos_at_socket_lib.h new file mode 100644 index 00000000..7081375c --- /dev/null +++ b/net/socket_wrapper/include/tos_at_socket_lib.h @@ -0,0 +1,78 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + +#ifndef _TOS_AT_SOCKET_LIB_H_ +#define _TOS_AT_SOCKET_LIB_H_ + +#include "tos_k.h" +#include "tos_at_socket_types.h" + +#if (TOS_CFG_CPU_BYTE_ORDER == CPU_BYTE_ORDER_BIG_ENDIAN) +#ifndef htons +#define htons(x) (x) +#endif + +#ifndef ntohs +#define ntohs(x) (x) + +#endif + +#ifndef htonl +#define htonl(x) (x) +#endif + +#ifndef ntohl +#define ntohl(x) (x) +#endif + +#elif (TOS_CFG_CPU_BYTE_ORDER == CPU_BYTE_ORDER_LITTLE_ENDIAN) +#ifndef htons +#define htons(x) ((u16_t)((((x) & (u16_t)0x00ffU) << 8) | (((x) & (u16_t)0xff00U) >> 8))) +#endif + +#ifndef ntohs +#define ntohs(x) htons(x) +#endif + +#ifndef htonl +#define htonl(x) ((((x) & (u32_t)0x000000ffUL) << 24) | \ + (((x) & (u32_t)0x0000ff00UL) << 8) | \ + (((x) & (u32_t)0x00ff0000UL) >> 8) | \ + (((x) & (u32_t)0xff000000UL) >> 24)) +#endif + +#ifndef ntohl +#define ntohl(x) htonl(x) +#endif + +#endif + +#define bzero(s, n) memset(s, 0, n) + +#define INADDR_NONE ((u32_t) 0xffffffff) /* 255.255.255.255 */ + +#define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up) +#define isascii(c) in_range(c, 0x20, 0x7f) +#define isdigit(c) in_range(c, '0', '9') +#define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F')) +#define islower(c) in_range(c, 'a', 'z') +#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') + +u32_t inet_addr(const char *cp); + +#endif /* _TOS_AT_SOCKET_LIB_H_ */ + diff --git a/net/socket_wrapper/include/tos_at_socket_prv.h b/net/socket_wrapper/include/tos_at_socket_prv.h new file mode 100644 index 00000000..5bbfd748 --- /dev/null +++ b/net/socket_wrapper/include/tos_at_socket_prv.h @@ -0,0 +1,60 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + +#ifndef _TOS_AT_SOCKET_PRV_H_ +#define _TOS_AT_SOCKET_PRV_H_ + +#include "sal_module_wrapper.h" + +#define SOCKET_CTL_MAX 6 /* should consistent with AT_DATA_CHANNEL_NUM */ + +typedef struct socket_control_st { + int fd; /* the real channel id allocated by at framework. + for some module like NBIot(bc35), you only know the channel id until you really do the + connect to the server */ + int is_taken; /* is this control usable?(if is_taken is FALSE then it's not usable) */ + sal_proto_t protocol; +} socket_ctl_t; + +int socket_id_sanity_check(int id); + +int socket_id_set_sanity_check(int id); + +int socket_id_alloc(void); + +void socket_id_free(int id); + +void socket_set_protocol(int id, sal_proto_t protocol); + +sal_proto_t socket_get_protocol(int id); + +void socket_set_fd(int id, int fd); + +int socket_get_fd(int id); + +#define SOCKET_ID_SANITY_CHECK(id) \ + if (!socket_id_sanity_check(id)) { \ + return -1; \ + } + +#define SOCKET_ID_SET_SANITY_CHECK(id) \ + if (!socket_id_set_sanity_check(id)) { \ + return -1; \ + } + +#endif /* _TOS_AT_SOCKET_PRV_H_ */ + diff --git a/net/socket_wrapper/include/tos_at_socket_types.h b/net/socket_wrapper/include/tos_at_socket_types.h new file mode 100644 index 00000000..3f517dba --- /dev/null +++ b/net/socket_wrapper/include/tos_at_socket_types.h @@ -0,0 +1,58 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + +#ifndef _TOS_AT_SOCKET_TYPES_H_ +#define _TOS_AT_SOCKET_TYPES_H_ + +#include "stdint.h" + +typedef uint8_t u8_t; +typedef uint16_t u16_t; +typedef uint32_t u32_t; + +typedef int8_t s8_t; +typedef int16_t s16_t; +typedef int32_t s32_t; + +#if !defined(in_addr_t) +typedef u32_t in_addr_t; +#endif + +struct in_addr { + in_addr_t s_addr; +}; + +struct sockaddr_in { + u8_t sin_len; + u8_t sin_family; + u16_t sin_port; + struct in_addr sin_addr; + char sin_zero[8]; +}; + +struct sockaddr { + u8_t sa_len; + u8_t sa_family; + char sa_data[14]; +}; + +#ifndef socklen_t +# define socklen_t int +#endif + +#endif /* _TOS_AT_SOCKET_TYPES_H_ */ + diff --git a/net/socket_wrapper/tos_at_socket.c b/net/socket_wrapper/tos_at_socket.c new file mode 100644 index 00000000..818ece87 --- /dev/null +++ b/net/socket_wrapper/tos_at_socket.c @@ -0,0 +1,217 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + +#include "tos_at_socket.h" +#include "tos_at_socket_prv.h" +#include "sal_module_wrapper.h" + +int socket(int domain, int type, int protocol) +{ + int pub_fd; + sal_proto_t proto; + + protocol = protocol; + + if (domain != AF_INET) { + return -1; + } + + if (type == SOCK_STREAM) { + proto = TOS_SAL_PROTO_TCP; + } else if (type == SOCK_DGRAM) { + proto = TOS_SAL_PROTO_UDP; + } else { + return -1; + } + + pub_fd = socket_id_alloc(); + if (pub_fd < 0) { + return -1; + } + + socket_set_protocol(pub_fd, proto); + + return pub_fd; +} + +static int sockaddr2ip(const struct sockaddr_in *addr_in, char ip[], int ip_len) +{ + snprintf(ip, 16, "%u.%u.%u.%u", ((uint8_t *)(&addr_in->sin_addr.s_addr))[0], + ((uint8_t *)(&addr_in->sin_addr.s_addr))[1], + ((uint8_t *)(&addr_in->sin_addr.s_addr))[2], + ((uint8_t *)(&addr_in->sin_addr.s_addr))[3]); + + return 0; +} + +static int sockaddr2port(const struct sockaddr_in *addr_in, char port[], int port_len) +{ + snprintf(port, port_len, "%d", htons(addr_in->sin_port)); + + return 0; +} + +int connect(int socket, const struct sockaddr *address, socklen_t address_len) +{ + int prv_fd; + char ip[16], port[8]; + const struct sockaddr_in *addr_in = (const struct sockaddr_in *)address; + + SOCKET_ID_SANITY_CHECK(socket); + + if (sockaddr2ip(addr_in, ip, sizeof(ip)) != 0) { + return -1; + } + + if (sockaddr2port(addr_in, port, sizeof(port)) != 0) { + return -1; + } + + prv_fd = tos_sal_module_connect(ip, port, socket_get_protocol(socket)); + if (prv_fd < 0) { + return -1; + } + + socket_set_fd(socket, prv_fd); + + return 0; +} + +int recv(int socket, void *buffer, size_t length, int flags) +{ + int total_len = 0, remain_len = length, recv_len; + + SOCKET_ID_SET_SANITY_CHECK(socket); + + if (!(flags & MSG_WAITALL)) { + return tos_sal_module_recv(socket_get_fd(socket), buffer, length); + } + + while (total_len < length) { + recv_len = tos_sal_module_recv(socket_get_fd(socket), + (uint8_t *)buffer + total_len, + remain_len); + + if (recv_len <= 0) { + continue; + } + + remain_len -= recv_len; + total_len += recv_len; + } + + return length; +} + +int recvfrom(int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len) +{ + int total_len = 0, remain_len = length, recv_len; + + (void)address; + (void)address_len; + + SOCKET_ID_SET_SANITY_CHECK(socket); + + if (!(flags & MSG_WAITALL)) { + return tos_sal_module_recvfrom(socket_get_fd(socket), buffer, length); + } + + while (total_len < length) { + recv_len = tos_sal_module_recvfrom(socket_get_fd(socket), + (uint8_t *)buffer + total_len, + remain_len); + + if (recv_len <= 0) { + continue; + } + + remain_len -= recv_len; + total_len += recv_len; + } + + return length; +} + +int send(int socket, const void *buffer, size_t length, int flags) +{ + SOCKET_ID_SET_SANITY_CHECK(socket); + + return tos_sal_module_send(socket_get_fd(socket), buffer, length); +} + +int sendto(int socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len) +{ + (void)dest_addr; + (void)dest_len; + + SOCKET_ID_SET_SANITY_CHECK(socket); + + return tos_sal_module_send(socket_get_fd(socket), message, length); +} + +int shutdown(int socket, int how) +{ + int rc; + + how = how; + + SOCKET_ID_SET_SANITY_CHECK(socket); + + if (socket_id_set_sanity_check(socket)) { + rc = tos_sal_module_close(socket_get_fd(socket)); + if (rc != 0) { + return rc; + } + } + + socket_id_free(socket); + + return 0; +} + +int read(int socket, void *buffer, size_t length) +{ + SOCKET_ID_SET_SANITY_CHECK(socket); + + return tos_sal_module_recv(socket_get_fd(socket), buffer, length); +} + +int close(int socket) +{ + int rc; + + SOCKET_ID_SANITY_CHECK(socket); + + if (socket_id_set_sanity_check(socket)) { + rc = tos_sal_module_close(socket_get_fd(socket)); + if (rc != 0) { + return rc; + } + } + + socket_id_free(socket); + + return 0; +} + +int write(int socket, const void *buffer, size_t length) +{ + SOCKET_ID_SET_SANITY_CHECK(socket); + + return tos_sal_module_send(socket_get_fd(socket), buffer, length); +} + diff --git a/net/socket_wrapper/tos_at_socket_lib.c b/net/socket_wrapper/tos_at_socket_lib.c new file mode 100644 index 00000000..7a69c99e --- /dev/null +++ b/net/socket_wrapper/tos_at_socket_lib.c @@ -0,0 +1,122 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + +#include "tos_at_socket_lib.h" + +s8_t +inet_aton(const char *cp, struct in_addr *addr) +{ + u32_t val; + s32_t base, n; + char c; + u32_t parts[4]; + u32_t* pp = parts; + + c = *cp; + for (;;) { + /* + * Collect number up to ``.''. + * Values are specified as for C: + * 0x=hex, 0=octal, isdigit=decimal. + */ + if (!isdigit(c)) + return (0); + val = 0; base = 10; + if (c == '0') { + c = *++cp; + if (c == 'x' || c == 'X') + base = 16, c = *++cp; + else + base = 8; + } + for (;;) { + if (isdigit(c)) { + val = (val * base) + (s16_t)(c - '0'); + c = *++cp; + } else if (base == 16 && isxdigit(c)) { + val = (val << 4) | + (s16_t)(c + 10 - (islower(c) ? 'a' : 'A')); + c = *++cp; + } else + break; + } + if (c == '.') { + /* + * Internet format: + * a.b.c.d + * a.b.c (with c treated as 16 bits) + * a.b (with b treated as 24 bits) + */ + if (pp >= parts + 3) + return (0); + *pp++ = val; + c = *++cp; + } else + break; + } + /* + * Check for trailing characters. + */ + if (c != '\0' && (!isascii(c) || !isspace(c))) + return (0); + /* + * Concoct the address according to + * the number of parts specified. + */ + n = pp - parts + 1; + switch (n) { + + case 0: + return (0); /* initial nondigit */ + + case 1: /* a -- 32 bits */ + break; + + case 2: /* a.b -- 8.24 bits */ + if (val > 0xffffff) + return (0); + val |= parts[0] << 24; + break; + + case 3: /* a.b.c -- 8.8.16 bits */ + if (val > 0xffff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16); + break; + + case 4: /* a.b.c.d -- 8.8.8.8 bits */ + if (val > 0xff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + break; + } + if (addr) + addr->s_addr = htonl(val); + return (1); +} + +u32_t inet_addr(const char *cp) +{ + struct in_addr val; + + if (inet_aton(cp, &val)) { + return (val.s_addr); + } + + return INADDR_NONE; +} + diff --git a/net/socket_wrapper/tos_at_socket_prv.c b/net/socket_wrapper/tos_at_socket_prv.c new file mode 100644 index 00000000..724bb7bc --- /dev/null +++ b/net/socket_wrapper/tos_at_socket_prv.c @@ -0,0 +1,90 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + +#include "tos_k.h" +#include "tos_at_socket_prv.h" +#include "sal_module_wrapper.h" + +static socket_ctl_t socket_ctl_table[SOCKET_CTL_MAX] = { 0 }; + +int socket_id_sanity_check(int id) +{ + if (id < 0 || + id >= TOS_COUNT_OF(socket_ctl_table) || + !socket_ctl_table[id].is_taken) { + return K_FALSE; + } + + return K_TRUE; +} + +int socket_id_set_sanity_check(int id) +{ + if (!socket_id_sanity_check(id)) { + return K_FALSE; + } + + if (socket_ctl_table[id].fd == -1) { + return K_FALSE; + } + + return K_TRUE; +} + +int socket_id_alloc(void) +{ + int i = 0; + socket_ctl_t *the_ctl; + + for (i = 0; i < TOS_COUNT_OF(socket_ctl_table); ++i) { + the_ctl = &socket_ctl_table[i]; + if (!the_ctl->is_taken) { + the_ctl->is_taken = K_TRUE; + the_ctl->fd = -1; + return i; + } + } + + return -1; +} + +void socket_id_free(int id) +{ + socket_ctl_table[id].is_taken = K_FALSE; + socket_ctl_table[id].fd = -1; +} + +void socket_set_protocol(int id, sal_proto_t protocol) +{ + socket_ctl_table[id].protocol = protocol; +} + +sal_proto_t socket_get_protocol(int id) +{ + return socket_ctl_table[id].protocol; +} + +void socket_set_fd(int id, int fd) +{ + socket_ctl_table[id].fd = fd; +} + +int socket_get_fd(int id) +{ + return socket_ctl_table[id].fd; +} + diff --git a/osal/cmsis_os/cmsis_os.c b/osal/cmsis_os/cmsis_os.c index 3b230ed8..d2d5f0d9 100644 --- a/osal/cmsis_os/cmsis_os.c +++ b/osal/cmsis_os/cmsis_os.c @@ -356,7 +356,6 @@ osStatus osSemaphoreDelete(osSemaphoreId semaphore_id) #endif // TOS_CFG_SEM_EN -#if TOS_CFG_MMBLK_EN > 0u // ==== Memory Pool Management Functions ==== #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available @@ -424,7 +423,6 @@ osStatus osPoolFree(osPoolId pool_id, void *block) } #endif // Memory Pool Management available -#endif // TOS_CFG_MMBLK_EN #if TOS_CFG_MESSAGE_QUEUE_EN > 0u // ==== Message Queue Management Functions ==== diff --git a/osal/cmsis_os/cmsis_os.h b/osal/cmsis_os/cmsis_os.h index 16c3ffb7..bfb14e70 100644 --- a/osal/cmsis_os/cmsis_os.h +++ b/osal/cmsis_os/cmsis_os.h @@ -239,9 +239,7 @@ typedef k_sem_t *osSemaphoreId; /// Pool ID identifies the memory pool (pointer to a memory pool control block). /// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS. -#if TOS_CFG_MMBLK_EN > 0u typedef k_mmblk_pool_t *osPoolId; -#endif /// Message ID identifies the message queue (pointer to a message queue control block). /// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS. @@ -297,14 +295,12 @@ typedef struct os_semaphore_def { /// Definition structure for memory block allocation. /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS. -#if TOS_CFG_MMBLK_EN > 0u typedef struct os_pool_def { uint32_t pool_sz; ///< number of items (elements) in the pool uint32_t item_sz; ///< size of an item void *pool; ///< pointer to memory for pool k_mmblk_pool_t *mmblk_pool; ///< memory blk pool handler } osPoolDef_t; -#endif /// Definition structure for message queue. /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS. @@ -660,7 +656,6 @@ osStatus osSemaphoreDelete(osSemaphoreId semaphore_id); #endif // Semaphore available #endif // TOS_CFG_SEM_EN -#if TOS_CFG_MMBLK_EN > 0u // ==== Memory Pool Management Functions ==== #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available @@ -715,7 +710,6 @@ void *osPoolCAlloc(osPoolId pool_id); osStatus osPoolFree(osPoolId pool_id, void *block); #endif // Memory Pool Management available -#endif // TOS_CFG_MMBLK_EN #if TOS_CFG_MESSAGE_QUEUE_EN > 0u // ==== Message Queue Management Functions ==== diff --git a/platform/hal/st/stm32f1xx/src/tos_hal_uart.c b/platform/hal/st/stm32f1xx/src/tos_hal_uart.c index 17228874..52d766b4 100644 --- a/platform/hal/st/stm32f1xx/src/tos_hal_uart.c +++ b/platform/hal/st/stm32f1xx/src/tos_hal_uart.c @@ -46,6 +46,23 @@ __API__ int tos_hal_uart_write(hal_uart_t *uart, const uint8_t *buf, size_t size __API__ int tos_hal_uart_read(hal_uart_t *uart, const uint8_t *buf, size_t size, uint32_t timeout) { + HAL_StatusTypeDef hal_status; + UART_HandleTypeDef *uart_handle; + + if (!uart || !buf) { + return -1; + } + + if (!uart->private_uart) { + return -1; + } + + uart_handle = (UART_HandleTypeDef *)uart->private_uart; + + hal_status = HAL_UART_Receive(uart_handle, (uint8_t *)buf, size, timeout); + if (hal_status != HAL_OK) { + return -1; + } return 0; } diff --git a/platform/hal/st/stm32f4xx/src/tos_hal_uart.c b/platform/hal/st/stm32f4xx/src/tos_hal_uart.c index 151c8551..9dd8cf2c 100644 --- a/platform/hal/st/stm32f4xx/src/tos_hal_uart.c +++ b/platform/hal/st/stm32f4xx/src/tos_hal_uart.c @@ -41,6 +41,23 @@ __API__ int tos_hal_uart_write(hal_uart_t *uart, const uint8_t *buf, size_t size __API__ int tos_hal_uart_read(hal_uart_t *uart, const uint8_t *buf, size_t size, uint32_t timeout) { + HAL_StatusTypeDef hal_status; + UART_HandleTypeDef *uart_handle; + + if (!uart || !buf) { + return -1; + } + + if (!uart->private_uart) { + return -1; + } + + uart_handle = (UART_HandleTypeDef *)uart->private_uart; + + hal_status = HAL_UART_Receive(uart_handle, (uint8_t *)buf, size, timeout); + if (hal_status != HAL_OK) { + return -1; + } return 0; } diff --git a/platform/hal/st/stm32l0xx/src/tos_hal_uart.c b/platform/hal/st/stm32l0xx/src/tos_hal_uart.c index 91307f21..a3018132 100644 --- a/platform/hal/st/stm32l0xx/src/tos_hal_uart.c +++ b/platform/hal/st/stm32l0xx/src/tos_hal_uart.c @@ -42,6 +42,23 @@ __API__ int tos_hal_uart_write(hal_uart_t *uart, const uint8_t *buf, size_t size __API__ int tos_hal_uart_read(hal_uart_t *uart, const uint8_t *buf, size_t size, uint32_t timeout) { + HAL_StatusTypeDef hal_status; + UART_HandleTypeDef *uart_handle; + + if (!uart || !buf) { + return -1; + } + + if (!uart->private_uart) { + return -1; + } + + uart_handle = (UART_HandleTypeDef *)uart->private_uart; + + hal_status = HAL_UART_Receive(uart_handle, (uint8_t *)buf, size, timeout); + if (hal_status != HAL_OK) { + return -1; + } return 0; } diff --git a/platform/hal/st/stm32l4xx/src/tos_hal_uart.c b/platform/hal/st/stm32l4xx/src/tos_hal_uart.c index e0109ad0..b1d34769 100644 --- a/platform/hal/st/stm32l4xx/src/tos_hal_uart.c +++ b/platform/hal/st/stm32l4xx/src/tos_hal_uart.c @@ -49,6 +49,23 @@ __API__ int tos_hal_uart_write(hal_uart_t *uart, const uint8_t *buf, size_t size __API__ int tos_hal_uart_read(hal_uart_t *uart, const uint8_t *buf, size_t size, uint32_t timeout) { + HAL_StatusTypeDef hal_status; + UART_HandleTypeDef *uart_handle; + + if (!uart || !buf) { + return -1; + } + + if (!uart->private_uart) { + return -1; + } + + uart_handle = (UART_HandleTypeDef *)uart->private_uart; + + hal_status = HAL_UART_Receive(uart_handle, (uint8_t *)buf, size, timeout); + if (hal_status != HAL_OK) { + return -1; + } return 0; }