Переглянути джерело

add:使用原厂adc校准,c++支持

Dozingfiretruck 3 роки тому
батько
коміт
df945abe33

+ 6 - 10
app/port/luat_adc_air101.c

@@ -42,32 +42,28 @@ int luat_adc_read(int ch, int *val, int *val2)
     switch (ch)
     {
     case 0:
-        voltage = adc_get_inputVolt2(ch, val);
+        voltage = adc_get_inputVolt(ch);
         break;
     case 1:
-        voltage = adc_get_inputVolt2(ch, val);
+        voltage = adc_get_inputVolt(ch);
         break;
-// #ifdef AIR103
     case 2:
-        voltage = adc_get_inputVolt2(ch, val);
+        voltage = adc_get_inputVolt(ch);
         break;
     case 3:
-        voltage = adc_get_inputVolt2(ch, val);
+        voltage = adc_get_inputVolt(ch);
         break;
-// #endif
     case 10:
         voltage = adc_temp();
-        *val = voltage;
-        *val2 = voltage;
         return 0;
     case 11:
         voltage = adc_get_interVolt();
-        *val = voltage;
-        *val2 = voltage;
         return 0;
     default:
         return 1;
     }
+    *val = voltage;
+    *val2 = voltage;
     if (*val < 46134) {
         *val2 = 0;
     }

+ 1 - 3
include/driver/wm_adc.h

@@ -21,7 +21,7 @@
 
 
 /*ADC Result*/
-#define ADC_RESULT_MASK					(0x3FFFC)
+#define ADC_RESULT_MASK					(0x3FFFF)
 #define ADC_RESULT_VAL(n)				((n)&ADC_RESULT_MASK)
 
 /*ADC_ANALOG_CTRL*/
@@ -272,8 +272,6 @@ int adc_get_interTemp(void);
  */
 int adc_get_inputVolt(u8 channel);
 
-int adc_get_inputVolt2(u8 channel, int* origin);
-
 /**
  * @brief           This function is used to read internal voltage.
  *

+ 40 - 7
include/driver/wm_efuse.h

@@ -24,14 +24,36 @@ enum {
 	CMD_TX_IQ_PHASE,
 	CMD_RX_IQ_PHASE,
 	CMD_TX_GAIN,
+	CMD_TX_ADC_CAL,
 	CMD_ALL,
 };
 
-#define VCG_ADDR  (FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST)+4)
-#define VCG_LEN    (4)
+#define FREQERR_ADDR  (FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST))
+#define FREQERR_LEN  (4)
+#define CAL_FLAG_ADDR  (FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST)+4)
+#define CAL_FLAG_LEN    (4)
+
 //#define TX_GAIN_NEW_ADDR (VCG_ADDR+VCG_LEN)
 #define TX_GAIN_LEN   (28*3)
 
+typedef struct FT_ADC_CAL_UNIT
+{
+	unsigned short      ref_val;
+	unsigned short      real_val;
+}FT_ADC_CAL_UINT_ST;
+
+typedef struct FT_ADC_CAL
+{
+	unsigned int       valid_cnt;
+	FT_ADC_CAL_UINT_ST units[8];
+}FT_ADC_CAL_ST;
+
+typedef struct FT_TEMP_CAL
+{
+	int       ref_val;
+	int       real_val;
+}FT_TEMP_CAL_ST;
+
 /**
  * @defgroup Driver_APIs Driver APIs
  * @brief Driver APIs
@@ -252,7 +274,7 @@ int tls_set_rx_iq_phase(u8 *rxPhase);
 /**
 * @brief 	This function is used to set/get freq err
 *
-* @param[in]	freqerr	
+* @param[in]	freqerr	(Unit:Hz),relative to base frequency(chan 1,2,3,4,5......13,14)
 * @param[in]    flag  1-set  0-get
 * @retval	 	TLS_EFUSE_STATUS_OK			set/get success
 * @retval		TLS_EFUSE_STATUS_EIO		set/get failed
@@ -260,15 +282,26 @@ int tls_set_rx_iq_phase(u8 *rxPhase);
 int tls_freq_err_op(u8 *freqerr, u8 flag);
 
 /**
-* @brief 	This function is used to set/get vcg ctrl
+* @brief 	This function is used to set/get cal finish flag
 *
-* @param[in]	vcg	
+* @param[in]	calflag 1- finish calibration, non-1-do not calibration
 * @param[in]    flag  1-set  0-get
 *
-* @retval	 	TLS_EFUSE_STATUS_OK			set/get success
+* @retval	 	TLS_EFUSE_STATUS_OK		set/get success
 * @retval		TLS_EFUSE_STATUS_EIO		set/get failed
 */
-int tls_rf_vcg_ctrl_op(u8 *vcg, u8 flag);
+int tls_rf_cal_finish_op(u8 *calflag, u8 flag);
+
+
+/**
+* @brief 	This function is used to get adc cal param
+*
+* @param[out]	adc_cal		adc cal param
+*
+* @retval	 	TLS_EFUSE_STATUS_OK			get success
+* @retval		TLS_EFUSE_STATUS_EIO		get failed
+*/
+int tls_get_adc_cal_param(FT_ADC_CAL_ST *adc_cal);
 
 /**
  * @}

+ 1 - 0
include/driver/wm_flash_map.h

@@ -28,6 +28,7 @@
 
 
 /**System parameter defined in wm_internal_fls.c*/
+extern unsigned int TLS_FLASH_MESH_PARAM_ADDR;
 extern unsigned int TLS_FLASH_PARAM_DEFAULT;
 extern unsigned int TLS_FLASH_PARAM1_ADDR;
 extern unsigned int TLS_FLASH_PARAM2_ADDR;

+ 17 - 0
include/driver/wm_internal_flash.h

@@ -42,6 +42,7 @@ enum TYPE_FLASH_ID{
 	SPIFLASH_MID_XMC		= 0x20,
 	SPIFLASH_MID_XTX        = 0x0B,
 	SPIFLASH_MID_TSINGTENG    = 0xEB, /*UNIGROUP TSINGTENG*/	
+	SPIFLASH_MID_TSINGTENG_1MB    = 0xCD, /*UNIGROUP TSINGTENG*/
 };
 
 typedef union {
@@ -259,6 +260,22 @@ int tls_fls_read(u32 addr, u8 * buf, u32 len);
  */
 int tls_fls_write(u32 addr, u8 * buf, u32 len);
 
+/**
+ * @brief          This function is used to write data into the flash without erase.
+ *
+ * @param[in]      addr     Specifies the starting address to write to
+ * @param[in]      buf      Pointer to a byte array that is to be written
+ * @param[in]      len      Specifies the length of the data to be written
+ *
+ * @retval         TLS_FLS_STATUS_OK	        if write flash success
+ * @retval         TLS_FLS_STATUS_EPERM	        if flash struct point is null
+ * @retval         TLS_FLS_STATUS_ENODRV	    if flash driver is not installed
+ * @retval         TLS_FLS_STATUS_EINVAL	    if argument is invalid
+ *
+ * @note           Erase action should be excuted by API tls_fls_erase in user layer.
+ */
+int tls_fls_write_without_erase(u32 addr, u8 *buf, u32 len);
+
 
 /**
  * @brief          	This function is used to erase the appointed sector

+ 4 - 5
ld/AIR101.ld

@@ -74,16 +74,20 @@ SECTIONS
   *(.rodata*)
   *(.rodata.*)
   *(.rodata.str1.4)
+  . = ALIGN(0x4) ;
+  __ctor_start__ = .;
   KEEP (*crtbegin.o(.ctors))
   KEEP (*crtbegin?.o(.ctors))
   KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
   KEEP (*(SORT(.ctors.*)))
   KEEP (*(.ctors))
+  __ctor_end__ = .;
   KEEP (*crtbegin.o(.dtors))
   KEEP (*crtbegin?.o(.dtors))
   KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
   KEEP (*(SORT(.dtors.*)))
   KEEP (*(.dtors))
+  __dtor_end__ = .;
   . = ALIGN(0x4) ;
   __erodata = .;
  } > REGION_RODATA
@@ -99,11 +103,9 @@ SECTIONS
   __sdata = . ;
   __data_start__ = . ;
   data_start = . ;
-  *(.ram_run)
   *(.got.plt)
   *(.got)
   *(.gnu.linkonce.r*)
-  *(.ram_run)
   *(.data)
   *(.data*)
   *(.data1)
@@ -112,7 +114,6 @@ SECTIONS
   *(.data1)
   *(.gcc_except_table)
   *(.gcc_except_table*)
- 
   __start_init_call = .;
   *(.initcall.init)
   __stop_init_call = .;
@@ -148,8 +149,6 @@ SECTIONS
   __end = . ;
   end = . ;
   __bss_end__ = .;
-  . = ALIGN(0x4) ;
-  *(.heap4)
  } > REGION_BSS
  ._user_heap : {
   . = ALIGN(0x4) ;

+ 4 - 5
ld/AIR103.ld

@@ -74,16 +74,20 @@ SECTIONS
   *(.rodata*)
   *(.rodata.*)
   *(.rodata.str1.4)
+  . = ALIGN(0x4) ;
+  __ctor_start__ = .;
   KEEP (*crtbegin.o(.ctors))
   KEEP (*crtbegin?.o(.ctors))
   KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
   KEEP (*(SORT(.ctors.*)))
   KEEP (*(.ctors))
+  __ctor_end__ = .;
   KEEP (*crtbegin.o(.dtors))
   KEEP (*crtbegin?.o(.dtors))
   KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
   KEEP (*(SORT(.dtors.*)))
   KEEP (*(.dtors))
+  __dtor_end__ = .;
   . = ALIGN(0x4) ;
   __erodata = .;
  } > REGION_RODATA
@@ -99,11 +103,9 @@ SECTIONS
   __sdata = . ;
   __data_start__ = . ;
   data_start = . ;
-  *(.ram_run)
   *(.got.plt)
   *(.got)
   *(.gnu.linkonce.r*)
-  *(.ram_run)
   *(.data)
   *(.data*)
   *(.data1)
@@ -112,7 +114,6 @@ SECTIONS
   *(.data1)
   *(.gcc_except_table)
   *(.gcc_except_table*)
- 
   __start_init_call = .;
   *(.initcall.init)
   __stop_init_call = .;
@@ -148,8 +149,6 @@ SECTIONS
   __end = . ;
   end = . ;
   __bss_end__ = .;
-  . = ALIGN(0x4) ;
-  *(.heap4)
  } > REGION_BSS
  ._user_heap : {
   . = ALIGN(0x4) ;

+ 4 - 5
ld/gcc_csky.ld

@@ -74,16 +74,20 @@ SECTIONS
   *(.rodata*)
   *(.rodata.*)
   *(.rodata.str1.4)
+  . = ALIGN(0x4) ;
+  __ctor_start__ = .;
   KEEP (*crtbegin.o(.ctors))
   KEEP (*crtbegin?.o(.ctors))
   KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
   KEEP (*(SORT(.ctors.*)))
   KEEP (*(.ctors))
+  __ctor_end__ = .;
   KEEP (*crtbegin.o(.dtors))
   KEEP (*crtbegin?.o(.dtors))
   KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
   KEEP (*(SORT(.dtors.*)))
   KEEP (*(.dtors))
+  __dtor_end__ = .;
   . = ALIGN(0x4) ;
   __erodata = .;
  } > REGION_RODATA
@@ -99,11 +103,9 @@ SECTIONS
   __sdata = . ;
   __data_start__ = . ;
   data_start = . ;
-  *(.ram_run)
   *(.got.plt)
   *(.got)
   *(.gnu.linkonce.r*)
-  *(.ram_run)
   *(.data)
   *(.data*)
   *(.data1)
@@ -112,7 +114,6 @@ SECTIONS
   *(.data1)
   *(.gcc_except_table)
   *(.gcc_except_table*)
- 
   __start_init_call = .;
   *(.initcall.init)
   __stop_init_call = .;
@@ -148,8 +149,6 @@ SECTIONS
   __end = . ;
   end = . ;
   __bss_end__ = .;
-  . = ALIGN(0x4) ;
-  *(.heap4)
  } > REGION_BSS
  ._user_heap : {
   . = ALIGN(0x4) ;

+ 4 - 5
ld/gcc_csky_1M.ld

@@ -74,16 +74,20 @@ SECTIONS
   *(.rodata*)
   *(.rodata.*)
   *(.rodata.str1.4)
+  . = ALIGN(0x4) ;
+  __ctor_start__ = .;
   KEEP (*crtbegin.o(.ctors))
   KEEP (*crtbegin?.o(.ctors))
   KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
   KEEP (*(SORT(.ctors.*)))
   KEEP (*(.ctors))
+  __ctor_end__ = .;
   KEEP (*crtbegin.o(.dtors))
   KEEP (*crtbegin?.o(.dtors))
   KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
   KEEP (*(SORT(.dtors.*)))
   KEEP (*(.dtors))
+  __dtor_end__ = .;
   . = ALIGN(0x4) ;
   __erodata = .;
  } > REGION_RODATA
@@ -99,11 +103,9 @@ SECTIONS
   __sdata = . ;
   __data_start__ = . ;
   data_start = . ;
-  *(.ram_run)
   *(.got.plt)
   *(.got)
   *(.gnu.linkonce.r*)
-  *(.ram_run)
   *(.data)
   *(.data*)
   *(.data1)
@@ -112,7 +114,6 @@ SECTIONS
   *(.data1)
   *(.gcc_except_table)
   *(.gcc_except_table*)
- 
   __start_init_call = .;
   *(.initcall.init)
   __stop_init_call = .;
@@ -148,8 +149,6 @@ SECTIONS
   __end = . ;
   end = . ;
   __bss_end__ = .;
-  . = ALIGN(0x4) ;
-  *(.heap4)
  } > REGION_BSS
  ._user_heap : {
   . = ALIGN(0x4) ;

+ 22 - 0
platform/arch/xt804/bsp/system.c

@@ -68,6 +68,25 @@ void mdelay(uint32_t ms)
     }
 }
 
+/**
+  * @brief  initialize c++ constructor
+  * @param  None
+  * @return None
+  */
+extern int __dtor_end__;
+extern int __ctor_end__;
+extern int __ctor_start__;
+typedef void (*func_ptr)(void);
+__attribute__((weak)) void cxx_system_init(void)
+{
+    func_ptr *p;
+    for (p = (func_ptr *)&__ctor_end__ -1; p >= (func_ptr *)&__ctor_start__; p--)
+    {
+        (*p)();
+    }
+}
+
+
 /**
   * @brief  initialize the system
   *         Initialize the psr and vbr.
@@ -95,6 +114,9 @@ void SystemInit(void)
     __enable_excp_irq();
 #endif
 
+	/*c++ variable init*/
+	cxx_system_init();
+
     //csi_coret_config(g_system_clock / CONFIG_SYSTICK_HZ, SYS_TICK_IRQn);    //10ms
 //#ifndef CONFIG_KERNEL_NONE
     csi_vic_enable_irq(SYS_TICK_IRQn);

+ 4 - 1
platform/arch/xt804/bsp/trap_c.c

@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <csi_config.h>
 #include "wm_debug.h"
+#include "wm_ram_config.h"
 #include "wm_watchdog.h"
 
 void trap_c(uint32_t *regs)
@@ -53,6 +54,8 @@ void trap_c(uint32_t *regs)
     printf("epsr: %8x\n", regs[16]);
     printf("epc : %8x\n", regs[17]);
 
-    tls_sys_reset();
+	tls_sys_set_reboot_reason(REBOOT_REASON_EXCEPTION);
+	tls_sys_reset();
+    while (1);
 }
 

+ 14 - 0
platform/arch/xt804/libc/libc_port.c

@@ -1565,5 +1565,19 @@ __attribute__((weak)) void __assert_fail(const char *file,
 	   func ? ", function: " : "", func ? func : "");
     while(1);
 }
+
+/*For CPP type used, you first call this function in main entry*/
+extern int __dtor_end__;
+extern int __ctor_end__;
+extern int __ctor_start__;
+typedef void (*func_ptr)(void);
+__attribute__((weak)) void cxx_system_init(void)
+{
+    func_ptr *p;
+    for (p = (func_ptr *)&__ctor_end__ -1; p >= (func_ptr *)&__ctor_start__; p--)
+    {
+        (*p)();
+    }
+}
 #endif
 

+ 95 - 49
platform/drivers/adc/wm_adc.c

@@ -21,10 +21,18 @@
 #include "wm_io.h"
 #include "wm_irq.h"
 #include "wm_mem.h"
+#include "wm_efuse.h"
 
 #define  ATTRIBUTE_ISR __attribute__((isr))
 
+typedef struct 
+{
+	int poly_n;
+	double a[3];
+}ST_ADC_POLYFIT_PARAM;
 
+ST_ADC_POLYFIT_PARAM _polyfit_param = {0};
+extern void polyfit(int n,double x[],double y[],int poly_n,double a[]);
 //TODO
 #define HR_SD_ADC_CONFIG_REG 0
 static int adc_offset = 0;
@@ -69,10 +77,45 @@ static void adc_dma_isr_callbk(void)
 		}
 	}
 }
+int adc_polyfit_init(ST_ADC_POLYFIT_PARAM *polyfit_param)
+{
+	FT_ADC_CAL_ST adc_st;
+	double x[16] = {0};
+	double y[16] = {0};
+	int n = 4, poly_n = 1; // or = 2
+
+	int i;
 
 
+	polyfit_param->poly_n = 0;
+	memset(&adc_st, 0, sizeof(adc_st));
+	tls_get_adc_cal_param(&adc_st);
+	//dumpBuffer("adc_st",(char *)&adc_st, sizeof(adc_st));
+	n = adc_st.valid_cnt;
+	if(n >= 4 && n <= 8)
+	{
+		for(i = 0; i < n; i++)
+		{
+			x[i] = (double)adc_st.units[i].real_val;
+			y[i] = (double)adc_st.units[i].ref_val;
+		}
+		polyfit_param->poly_n = poly_n;
+		polyfit(n,x,y,poly_n,polyfit_param->a);
+	}
+
+	return 0;
+}
+
 void tls_adc_init(u8 ifusedma,u8 dmachannel)
 {
+	/*ADC LDO ON here, after 90ns, ADC can work to avoid ADC affect those ADC IOs that are multiplexed GPIO input to capture irq*/
+	u32 value = 0;
+	value = tls_reg_read32(HR_SD_ADC_ANA_CTRL);
+	value |= CONFIG_EN_LDO_ADC_VAL(1);
+	tls_reg_write32(HR_SD_ADC_ANA_CTRL, value);
+
+	memset(&_polyfit_param, 0, sizeof(_polyfit_param));
+	adc_polyfit_init(&_polyfit_param);
 	tls_reg_write32(HR_SD_ADC_CTRL, ANALOG_SWITCH_TIME_VAL(0x50)|ANALOG_INIT_TIME_VAL(0x50)|ADC_IRQ_EN_VAL(0x1));
 	tls_irq_enable(ADC_IRQn);
 
@@ -144,7 +187,7 @@ void tls_adc_start_with_cpu(int Channel)
 	/* Stop adc first */
 	value = tls_reg_read32(HR_SD_ADC_ANA_CTRL);
 	value |= CONFIG_PD_ADC_VAL(1);
-	value &= ~(CONFIG_RSTN_ADC_VAL(1)|CONFIG_EN_LDO_ADC_VAL(1));
+	value &= ~(CONFIG_RSTN_ADC_VAL(1));
 	value &= ~(CONFIG_ADC_CHL_SEL_MASK);
 	value |= CONFIG_ADC_CHL_SEL(Channel);
 
@@ -152,7 +195,7 @@ void tls_adc_start_with_cpu(int Channel)
 	
 	value = tls_reg_read32(HR_SD_ADC_ANA_CTRL);
 	value &= ~(CONFIG_PD_ADC_VAL(1));
-	value |= (CONFIG_RSTN_ADC_VAL(1)|CONFIG_EN_LDO_ADC_VAL(1));
+	value |= (CONFIG_RSTN_ADC_VAL(1));
 	tls_reg_write32(HR_SD_ADC_ANA_CTRL, value);
 }
 
@@ -181,7 +224,7 @@ void tls_adc_start_with_dma(int Channel, int Length)
 	adc_dma_buffer = tls_mem_alloc(len*4);
 	if (adc_dma_buffer == NULL)
 	{
-		wm_printf("adc dma buffer alloc failed\r\n");
+		//wm_printf("adc dma buffer alloc failed\r\n");
 		return;
 	}
 
@@ -190,7 +233,7 @@ void tls_adc_start_with_dma(int Channel, int Length)
 	/*disable adc:set adc pd, rstn and ldo disable*/
 	value = tls_reg_read32(HR_SD_ADC_ANA_CTRL);
 	value |= CONFIG_PD_ADC_VAL(1);
-	value &= ~(CONFIG_RSTN_ADC_VAL(1)|CONFIG_EN_LDO_ADC_VAL(1));	
+	value &= ~(CONFIG_RSTN_ADC_VAL(1));	
 	tls_reg_write32(HR_SD_ADC_ANA_CTRL, value);	
 	
 	/* Stop dma if necessary */
@@ -200,9 +243,9 @@ void tls_adc_start_with_dma(int Channel, int Length)
 	}
 
     DMA_SRCADDR_REG(gst_adc.dmachannel) = HR_SD_ADC_RESULT_REG;
-	DMA_DESTADDR_REG(gst_adc.dmachannel) = adc_dma_buffer;
+	DMA_DESTADDR_REG(gst_adc.dmachannel) = (u32)adc_dma_buffer;
 	DMA_SRCWRAPADDR_REG(gst_adc.dmachannel) = HR_SD_ADC_RESULT_REG;
-	DMA_DESTWRAPADDR_REG(gst_adc.dmachannel) = adc_dma_buffer;
+	DMA_DESTWRAPADDR_REG(gst_adc.dmachannel) = (u32)adc_dma_buffer;
     DMA_WRAPSIZE_REG(gst_adc.dmachannel) = (len*4) << 16;
 
 	/* Dest_add_inc, halfword,  */
@@ -219,7 +262,7 @@ void tls_adc_start_with_dma(int Channel, int Length)
     value &= ~(CONFIG_ADC_CHL_SEL_MASK);
 	value |= CONFIG_ADC_CHL_SEL(Channel);
 	value &= ~(CONFIG_PD_ADC_VAL(1));
-	value |= (CONFIG_RSTN_ADC_VAL(1)|CONFIG_EN_LDO_ADC_VAL(1));	
+	value |= (CONFIG_RSTN_ADC_VAL(1));	
 	tls_reg_write32(HR_SD_ADC_ANA_CTRL, value);		/*start adc*/
 
 }
@@ -280,7 +323,7 @@ void tls_adc_cmp_start(int Channel, int cmp_data, int cmp_pol)
 	/* Stop adc first */
 	value = tls_reg_read32(HR_SD_ADC_ANA_CTRL);
 	value |= CONFIG_PD_ADC_VAL(1);
-	value &= ~(CONFIG_RSTN_ADC_VAL(1)|CONFIG_EN_LDO_ADC_VAL(1));		
+	value &= ~(CONFIG_RSTN_ADC_VAL(1));		
 	value |= CONFIG_ADC_CHL_SEL(Channel);
 	tls_reg_write32(HR_SD_ADC_ANA_CTRL, value);
 
@@ -288,7 +331,7 @@ void tls_adc_cmp_start(int Channel, int cmp_data, int cmp_pol)
 	
 	value = tls_reg_read32(HR_SD_ADC_ANA_CTRL);
 	value &= ~(CONFIG_PD_ADC_VAL(1));
-	value |= (CONFIG_RSTN_ADC_VAL(1)|CONFIG_EN_LDO_ADC_VAL(1));	
+	value |= (CONFIG_RSTN_ADC_VAL(1));	
 	tls_reg_write32(HR_SD_ADC_ANA_CTRL, value);		/*start adc*/
 
 	/*Enable compare function and compare irq*/
@@ -426,6 +469,41 @@ static void waitForAdcDone(void)
 	tls_irq_enable(ADC_IRQn);
 }
 
+int cal_voltage(double vol)
+{
+	double y1, voltage;
+
+	double vol_30mV;
+	int average = ((int)vol >> 2) & 0xFFFF;
+
+	if(_polyfit_param.poly_n == 2)
+	{
+		y1 = _polyfit_param.a[2]*average*average + _polyfit_param.a[1]*average + _polyfit_param.a[0];
+	}
+	else if(_polyfit_param.poly_n == 1)
+	{
+		y1 = _polyfit_param.a[1]*average + _polyfit_param.a[0];
+		vol_30mV = ((double)300.0L - _polyfit_param.a[0]) / _polyfit_param.a[1];
+		if(average + 170 < vol_30mV)
+		{
+			return 0;
+		}
+		else if(average < vol_30mV)
+		{
+			y1 = 300.0L - 200.0L*(vol_30mV - average) / 170.0L;
+		}
+	}
+	else
+	{
+		voltage = ((double)vol - (double)adc_offset)/4.0;
+		voltage = 1.196 + voltage*(126363/1000.0)/1000000;
+		
+	    y1 = voltage*10000;
+	}
+
+	return (int)(y1/10);
+}
+
 u32 adc_get_offset(void)
 { 
 	adc_offset = 0;
@@ -439,7 +517,7 @@ u32 adc_get_offset(void)
 	adc_offset = tls_read_adc_result(); //获取adc转换结果
 	signedToUnsignedData(&adc_offset);
 	tls_adc_stop(0);
-
+//printf("adc_offset: 0x%x\r\n", adc_offset);
     return adc_offset;
 }
 
@@ -452,41 +530,12 @@ int adc_get_inputVolt(u8 channel)
 {
 	int average = 0;
 	double voltage = 0.0;
-	
-	adc_get_offset();
 
-	tls_adc_init(0, 0); 
-	tls_adc_reference_sel(ADC_REFERENCE_INTERNAL);
-	tls_adc_set_pga(1,1);
-	tls_adc_set_clk(0x28);	
-	tls_adc_start_with_cpu(channel);
-
-	waitForAdcDone();
-	average = tls_read_adc_result();
-	signedToUnsignedData(&average); 	
-	tls_adc_stop(0);
-
-	if ((channel == 8) || (channel == 9))
-	{
-		voltage = ((double)average - (double)adc_offset)/4.0;
-		voltage = voltage*(126363/1000)/1000000;
-	}
-	else
+	if(_polyfit_param.poly_n == 0 || (channel == 8) || (channel == 9))
 	{
-		voltage = ((double)average - (double)adc_offset)/4.0;
-		voltage = 1.196 + voltage*(126363/1000.0)/1000000;
+		adc_get_offset();
 	}
-
-	average = (int)(voltage*1000);
-    return average;
-}
-
-int adc_get_inputVolt2(u8 channel, int* origin) {
-	int average = 0;
-	double voltage = 0.0;
 	
-	adc_get_offset();
-
 	tls_adc_init(0, 0); 
 	tls_adc_reference_sel(ADC_REFERENCE_INTERNAL);
 	tls_adc_set_pga(1,1);
@@ -495,9 +544,8 @@ int adc_get_inputVolt2(u8 channel, int* origin) {
 
 	waitForAdcDone();
 	average = tls_read_adc_result();
+	signedToUnsignedData(&average); 	
 	tls_adc_stop(0);
-	signedToUnsignedData(&average);
-	*origin = average;	
 
 	if ((channel == 8) || (channel == 9))
 	{
@@ -506,20 +554,18 @@ int adc_get_inputVolt2(u8 channel, int* origin) {
 	}
 	else
 	{
-		voltage = ((double)average - (double)adc_offset)/4.0;
-		voltage = 1.196 + voltage*(126363/1000.0)/1000000;
+		return cal_voltage((double)average);
 	}
 
 	average = (int)(voltage*1000);
     return average;
-
 }
 
 u32 adc_get_interVolt(void)
 {
 	u32 voltValue;
 	u32 value = 0;
-	u32 code = 0;	
+	//u32 code = 0;	
 	int i = 0;
 	adc_get_offset();
 
@@ -533,11 +579,11 @@ u32 adc_get_interVolt(void)
 	{
 		waitForAdcDone();
 		value = tls_read_adc_result();
-		signedToUnsignedData(&value);
+		signedToUnsignedData((int *)&value);
 		voltValue += value;
 	}
 	voltValue = voltValue/10;
-	code = voltValue;
+	//code = voltValue;
 	voltValue = voltValue;
 	adc_offset = adc_offset;
 	tls_adc_stop(0);

+ 171 - 51
platform/drivers/efuse/wm_efuse.c

@@ -24,20 +24,22 @@
 #define USE_OTA_FT_PARAM  0
 #include "wm_flash_map.h"
 
-extern void flashSRRW(unsigned long offset,unsigned char *buf,unsigned long sz, unsigned char *backbuf, unsigned int backlen, unsigned int rd);
-
 
 #define FT_MAGICNUM_ADDR		(FLASH_BASE_ADDR)
 #define MAGICNUM_LEN			(4)
-#define MAC_ADDR_LEN			(8)
+#define MAC_ADDR_LEN			(6)
 #define FT_GAIN_LEN				(84)
 
+#define FT_PARAM_EXT_REVERSED_LEN   32
+
 typedef struct FT_PARAM
 {
 	unsigned int		magic_no;
 	unsigned int 		checksum;
 	unsigned char		wifi_mac_addr[MAC_ADDR_LEN];
+	unsigned short      version_no;
 	unsigned char		bt_mac_addr[MAC_ADDR_LEN];
+	unsigned short      ext_param_len;
 	unsigned int		tx_dcoffset;
 	unsigned int		rx_dcoffset;	
 	unsigned int		tx_iq_gain;
@@ -47,30 +49,49 @@ typedef struct FT_PARAM
 	unsigned char		tx_gain[FT_GAIN_LEN];	
 }FT_PARAM_ST;
 
+typedef struct FT_PARAM_EXT_1
+{
+	unsigned int        rf_freq_err;
+	unsigned int        rf_cal_flag;
+	FT_ADC_CAL_ST       adc_cal_param;
+	FT_TEMP_CAL_ST      temp_cal_param;
+}FT_PARAM_ST_EXT_1;
+
+typedef struct FT_PARAM_VER1
+{
+	FT_PARAM_ST         ft_param;
+	unsigned int 		ext_checksum;
+	FT_PARAM_ST_EXT_1   ft_ext1;
+	unsigned char       _reversed[FT_PARAM_EXT_REVERSED_LEN];
+}FT_PARAM_ST_VER1;
+
 static u8 default_mac[6] = {0x00,0x25,0x08,0x09,0x01,0x0F};
 
-FT_PARAM_ST gftParam;
+FT_PARAM_ST_VER1  gftParamVer1;
+
+FT_PARAM_ST *gftParam = (FT_PARAM_ST *)&gftParamVer1;
 int tls_ft_param_init(void)
 {
 	u32 crcvalue = 0;
 	psCrcContext_t ctx;	
+	FT_PARAM_ST_VER1 *pft_ver1 = NULL;
 	FT_PARAM_ST *pft = NULL;
 	
-	if (gftParam.magic_no == SIGNATURE_WORD)
+	if (gftParam->magic_no == SIGNATURE_WORD)
 	{
 		return TRUE;
 	}
 
-	pft = tls_mem_alloc(sizeof(FT_PARAM_ST));
+	pft = tls_mem_alloc(sizeof(FT_PARAM_ST_VER1));
 	if (pft == NULL)
 	{
 		return FALSE;
 	}
 
-	memset(pft, 0xFF, sizeof(FT_PARAM_ST));
-	memset(&gftParam, 0xFF, sizeof(FT_PARAM_ST));
+	memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
+	memset(gftParam, 0xFF, sizeof(FT_PARAM_ST_VER1));
 
-	tls_fls_read(FT_MAGICNUM_ADDR, (unsigned char *)pft, sizeof(FT_PARAM_ST));
+	tls_fls_read(FT_MAGICNUM_ADDR, (unsigned char *)pft, sizeof(FT_PARAM_ST_VER1));
 	if (pft->magic_no == SIGNATURE_WORD)
 	{
 		tls_crypto_init();
@@ -83,10 +104,25 @@ int tls_ft_param_init(void)
 			return FALSE;
 		}
 
-		if (gftParam.magic_no != SIGNATURE_WORD)
+		do
 		{
-			memcpy(&gftParam, pft, sizeof(FT_PARAM_ST));
-		}
+			if (pft->version_no > 0 && pft->version_no < 0xFFFF && pft->ext_param_len >= sizeof(FT_PARAM_ST_EXT_1) && 
+				pft->ext_param_len <= (sizeof(FT_PARAM_ST_EXT_1) + FT_PARAM_EXT_REVERSED_LEN))
+			{
+				pft_ver1 = (FT_PARAM_ST_VER1 *)pft;
+				tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
+				tls_crypto_crc_update(&ctx, (unsigned char *)&pft_ver1->ft_ext1, pft->ext_param_len);
+				tls_crypto_crc_final(&ctx, &crcvalue);	
+				if(pft_ver1->ext_checksum == crcvalue)
+				{
+					memcpy((unsigned char *)gftParam, (unsigned char *)pft, sizeof(FT_PARAM_ST_VER1));
+					break;
+				}
+			}
+			pft->version_no = 0xFFFF;
+			pft->ext_param_len = 0xFFFF;
+			memcpy((unsigned char *)gftParam, (unsigned char *)pft, sizeof(FT_PARAM_ST));
+		}while(0);
 	}
 	tls_mem_free(pft);
 
@@ -99,22 +135,28 @@ int tls_ft_param_get(unsigned int opnum, void *data, unsigned int rdlen)
 {
 	switch (opnum)
 	{
+		case CMD_TX_ADC_CAL:
+			if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
+			{
+				memcpy(data, (unsigned char *)&gftParamVer1.ft_ext1.adc_cal_param, rdlen);
+			}
+			break;
 		case CMD_WIFI_MAC:	/*MAC*/
-			if ((gftParam.wifi_mac_addr[0]&0x1)
-				||(0 == (gftParam.wifi_mac_addr[0]|gftParam.wifi_mac_addr[1]|gftParam.wifi_mac_addr[2]|gftParam.wifi_mac_addr[3]|gftParam.wifi_mac_addr[4]|gftParam.wifi_mac_addr[5])))		
+			if ((gftParam->wifi_mac_addr[0]&0x1)
+				||(0 == (gftParam->wifi_mac_addr[0]|gftParam->wifi_mac_addr[1]|gftParam->wifi_mac_addr[2]|gftParam->wifi_mac_addr[3]|gftParam->wifi_mac_addr[4]|gftParam->wifi_mac_addr[5])))		
 			{
 				memcpy(data, default_mac, rdlen);
 			}
 			else
 			{
-				memcpy(data, gftParam.wifi_mac_addr, rdlen);
+				memcpy(data, gftParam->wifi_mac_addr, rdlen);
 			}
 		break;
 		case CMD_BT_MAC:	/*MAC*/
             {
                 u8 invalid_bt_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
                 u8 invalid_bt_mac1[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-			    if ((memcmp(gftParam.bt_mac_addr, invalid_bt_mac, 6) == 0)||(memcmp(gftParam.bt_mac_addr, invalid_bt_mac1, 6) == 0))     
+			    if ((memcmp(gftParam->bt_mac_addr, invalid_bt_mac, 6) == 0)||(memcmp(gftParam->bt_mac_addr, invalid_bt_mac1, 6) == 0))     
 			    {
 				    memcpy(data, default_mac, rdlen);
                     *((u8*)data+5) +=1;      /*defalut plus 1*/
@@ -122,7 +164,7 @@ int tls_ft_param_get(unsigned int opnum, void *data, unsigned int rdlen)
 			    }
 			    else
 			    {
-				    memcpy(data, gftParam.bt_mac_addr, rdlen);
+				    memcpy(data, gftParam->bt_mac_addr, rdlen);
 			    }
            }
 		break;
@@ -130,37 +172,37 @@ int tls_ft_param_get(unsigned int opnum, void *data, unsigned int rdlen)
 
 		
 		case CMD_TX_DC: /*tx_dcoffset*/
-			*(unsigned int *)data = gftParam.tx_dcoffset;
+			*(unsigned int *)data = gftParam->tx_dcoffset;
 		break;	
 		
 		case CMD_RX_DC: /*rx_dcoffset*/
-			*(unsigned int *)data = gftParam.rx_dcoffset;
+			*(unsigned int *)data = gftParam->rx_dcoffset;
 		break;	
 		
 		case CMD_TX_IQ_GAIN:
-			*(unsigned int *)data = gftParam.tx_iq_gain;
+			*(unsigned int *)data = gftParam->tx_iq_gain;
 		break;	
 		
 		case CMD_RX_IQ_GAIN:
-			*(unsigned int *)data = gftParam.rx_iq_gain;
+			*(unsigned int *)data = gftParam->rx_iq_gain;
 		break;
 		
 		case CMD_TX_IQ_PHASE:
-			*(unsigned int *)data = gftParam.tx_iq_phase;
+			*(unsigned int *)data = gftParam->tx_iq_phase;
 		break;	
 		
 		case CMD_RX_IQ_PHASE:
-			*(unsigned int *)data = gftParam.rx_iq_phase;
+			*(unsigned int *)data = gftParam->rx_iq_phase;
 		break;
 		
 		case CMD_TX_GAIN: /*gain*/
 			if (rdlen < FT_GAIN_LEN)
 			{
-				memcpy(data, gftParam.tx_gain, rdlen);
+				memcpy(data, gftParam->tx_gain, rdlen);
 			}
 			else
 			{
-				memcpy(data, gftParam.tx_gain, FT_GAIN_LEN);
+				memcpy(data, gftParam->tx_gain, FT_GAIN_LEN);
 			}
 		break;
 		
@@ -180,40 +222,38 @@ int tls_ft_param_set(unsigned int opnum, void *data, unsigned int len)
 	{
 		return -1;
 	}
-	//printf("tls_ft_param_set: opnum=%d, val=%x\n", opnum, *(unsigned int *)data);
-	//tls_fls_read(FT_MAGICNUM_ADDR, (unsigned char *)&gftParam, sizeof(gftParam));
 	switch (opnum)
 	{
 		case CMD_WIFI_MAC:	/*MAC*/
-			memcpy(gftParam.wifi_mac_addr, (unsigned char *)data, len);
+			memcpy(gftParam->wifi_mac_addr, (unsigned char *)data, len);
 		break;
 
 		case CMD_BT_MAC:	/*BT MAC*/
-			memcpy(gftParam.bt_mac_addr, (unsigned char *)data, len);
+			memcpy(gftParam->bt_mac_addr, (unsigned char *)data, len);
 		break;
 
 		case CMD_TX_DC:	/*tx_dcoffset*/
-			gftParam.tx_dcoffset = *(unsigned int *)data;
+			gftParam->tx_dcoffset = *(unsigned int *)data;
 		break;	
 		
 		case CMD_RX_DC:	/*rx_dcoffset*/
-			gftParam.rx_dcoffset = *(unsigned int *)data;
+			gftParam->rx_dcoffset = *(unsigned int *)data;
 		break;	
 		
 		case CMD_TX_IQ_GAIN:
-			gftParam.tx_iq_gain = *(unsigned int *)data;
+			gftParam->tx_iq_gain = *(unsigned int *)data;
 		break;	
 		
 		case CMD_RX_IQ_GAIN:
-			gftParam.rx_iq_gain = *(unsigned int *) data;			
+			gftParam->rx_iq_gain = *(unsigned int *) data;			
 		break;	
 		
 		case CMD_TX_IQ_PHASE:
-			gftParam.tx_iq_phase = *(unsigned int *)data;
+			gftParam->tx_iq_phase = *(unsigned int *)data;
 		break;	
 		
 		case CMD_RX_IQ_PHASE:
-			gftParam.rx_iq_phase = *(unsigned int *) data;			
+			gftParam->rx_iq_phase = *(unsigned int *) data;			
 		break;	
 		
 		case CMD_TX_GAIN: /*gain*/
@@ -225,7 +265,7 @@ int tls_ft_param_set(unsigned int opnum, void *data, unsigned int len)
 			{
 				writelen = len;
 			}
-			memcpy(gftParam.tx_gain, data, writelen);
+			memcpy(gftParam->tx_gain, data, writelen);
 		break;
 		
 		default:
@@ -234,11 +274,19 @@ int tls_ft_param_set(unsigned int opnum, void *data, unsigned int len)
 
 	tls_crypto_init();
 	tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
-	gftParam.magic_no = SIGNATURE_WORD;
-	tls_crypto_crc_update(&ctx, (unsigned char *)&gftParam + 8, sizeof(gftParam) -8);
-	tls_crypto_crc_final(&ctx, &gftParam.checksum);
+	gftParam->magic_no = SIGNATURE_WORD;
+	tls_crypto_crc_update(&ctx, (unsigned char *)gftParam + 8, sizeof(FT_PARAM_ST) -8);
+	tls_crypto_crc_final(&ctx, &gftParam->checksum);
+	writelen = sizeof(FT_PARAM_ST);
+	if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
+	{
+		writelen = sizeof(FT_PARAM_ST_VER1);
+		tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
+		tls_crypto_crc_update(&ctx, (unsigned char *)&gftParamVer1.ft_ext1, gftParam->ext_param_len);
+		tls_crypto_crc_final(&ctx, &gftParamVer1.ext_checksum);
+	}
 	tls_flash_unlock();
-	tls_fls_write(FT_MAGICNUM_ADDR, (unsigned char *)&gftParam, sizeof(gftParam));
+	tls_fls_write(FT_MAGICNUM_ADDR, (unsigned char *)gftParam, writelen);
 	tls_flash_lock();
 	return 0;
 }
@@ -430,30 +478,98 @@ int tls_set_rx_iq_phase(u8 *rxPhase)
 
 int tls_freq_err_op(u8 *freqerr, u8 flag)
 {
-	tls_flash_unlock();
+	int ret = 0;
+	psCrcContext_t ctx;
+	int value = 0;
 	if (flag){
-		tls_fls_write(FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST), freqerr, 4);
+		tls_flash_unlock();
+		if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
+		{
+			memcpy((char *)&gftParamVer1.ft_ext1.rf_freq_err, (char *)freqerr, FREQERR_LEN);
+			tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
+			tls_crypto_crc_update(&ctx, (unsigned char *)&gftParamVer1.ft_ext1, gftParam->ext_param_len);
+			tls_crypto_crc_final(&ctx, &gftParamVer1.ext_checksum);
+			ret = tls_fls_write(FT_MAGICNUM_ADDR, (unsigned char *)gftParam, sizeof(FT_PARAM_ST_VER1));
+		}
+		else
+		{
+			ret = tls_fls_write(FREQERR_ADDR, freqerr, FREQERR_LEN);
+		}
+		tls_flash_lock();
+	}
+	else
+	{
+		if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
+		{
+			memcpy((char *)freqerr, (char *)&gftParamVer1.ft_ext1.rf_freq_err, FREQERR_LEN);
+		}
+		else
+		{
+			ret = tls_fls_read(FREQERR_ADDR, freqerr, FREQERR_LEN);
+		}
+		
+		memcpy(&value, freqerr, FREQERR_LEN);
+		if (value > 200000) /*when freq offset is out of range (-200KHz, 200KHz),do not use it*/
+		{
+			value = 200000;
+			memcpy((char *)freqerr, (char *)&value, FREQERR_LEN);
+		}
+		else if (value < -200000)
+		{
+			value = -200000;
+			memcpy((char *)freqerr, (char *)&value, FREQERR_LEN);
+		}
+	}
+	if (ret == 0)
+	{
+		return TLS_EFUSE_STATUS_OK;
 	}
 	else
 	{
-		tls_fls_read(FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST), freqerr, 4);
+		return TLS_EFUSE_STATUS_EINVALID;
 	}
-	tls_flash_lock();
-	return TLS_EFUSE_STATUS_OK;
 }
 
-int tls_rf_vcg_ctrl_op(u8 *vcg, u8 flag)
+int tls_rf_cal_finish_op(u8 *calflag, u8 flag)
 {
-	tls_flash_unlock();
+	int ret = 0;
+	psCrcContext_t ctx;
 	if (flag){
-		tls_fls_write(VCG_ADDR, vcg, VCG_LEN);
+		tls_flash_unlock();
+		if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
+		{
+			memcpy((char *)&gftParamVer1.ft_ext1.rf_cal_flag, (char *)calflag, CAL_FLAG_LEN);
+			tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
+			tls_crypto_crc_update(&ctx, (unsigned char *)&gftParamVer1.ft_ext1, gftParam->ext_param_len);
+			tls_crypto_crc_final(&ctx, &gftParamVer1.ext_checksum);
+			ret = tls_fls_write(FT_MAGICNUM_ADDR, (unsigned char *)gftParam, sizeof(FT_PARAM_ST_VER1));
+		}
+		else
+		{
+			ret = tls_fls_write(CAL_FLAG_ADDR, calflag, CAL_FLAG_LEN);
+		}
+		tls_flash_lock();
 	}
 	else
 	{
-		tls_fls_read(VCG_ADDR, vcg, VCG_LEN);
+		if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
+		{
+			memcpy((char *)calflag, (char *)&gftParamVer1.ft_ext1.rf_cal_flag, CAL_FLAG_LEN);
+		}
+		else
+		{
+			ret = tls_fls_read(CAL_FLAG_ADDR, calflag, CAL_FLAG_LEN);
+		}
+	}
+
+	if (ret == 0)
+	{
+		return TLS_EFUSE_STATUS_OK;
+	}
+	else
+	{
+		return TLS_EFUSE_STATUS_EINVALID;
 	}
-	tls_flash_lock();	
-	return TLS_EFUSE_STATUS_OK;
 }
 
 /**********************************************************************************************************
@@ -484,6 +600,10 @@ int tls_set_tx_gain(u8 *txgain)
 	
 
 }
+int tls_get_adc_cal_param(FT_ADC_CAL_ST *adc_cal)
+{
+	return tls_ft_param_get(CMD_TX_ADC_CAL, adc_cal, sizeof(FT_ADC_CAL_ST));
+}
 
 
 

+ 12 - 4
platform/drivers/gpio/wm_gpio.c

@@ -377,16 +377,24 @@ void tls_gpio_irq_disable(enum tls_io_name gpio_pin)
         pin    = gpio_pin - WM_IO_PB_00;
         offset = TLS_IO_AB_OFFSET;
 		reg = tls_reg_read32(HR_GPIO_IE + offset);
-		tls_reg_write32(HR_GPIO_IE + offset, reg & (~(0x1 << pin)));	/* disable interrupt */		
-		// tls_irq_disable(GPIOB_IRQn);
+		tls_reg_write32(HR_GPIO_IE + offset, reg & (~(0x1 << pin)));	/* disable interrupt */
+		reg = reg&(~(0x1 << pin));
+		if (reg == 0)
+		{
+			tls_irq_disable(GPIOB_IRQn);
+		}
     }
     else
     {
         pin    = gpio_pin;
         offset = 0;
 		reg = tls_reg_read32(HR_GPIO_IE + offset);
-		tls_reg_write32(HR_GPIO_IE + offset, reg & (~(0x1 << pin)));	/* disable interrupt */		
-		// tls_irq_disable(GPIOA_IRQn);
+		tls_reg_write32(HR_GPIO_IE + offset, reg & (~(0x1 << pin)));	/* disable interrupt */	
+		reg = (reg&(~(0x1 << pin)))&0xFFFF;
+		if (reg == 0)
+		{
+			tls_irq_disable(GPIOA_IRQn);
+		}
     }
 
 }

+ 4 - 4
platform/drivers/gpio/wm_gpio_afsel.c

@@ -219,10 +219,10 @@ void wm_psram_config(uint8_t numsel)
 		case 1://air103
 			tls_io_cfg_set(WM_IO_PA_15, WM_IO_OPTION1);/*CK*/
 			tls_io_cfg_set(WM_IO_PB_27, WM_IO_OPTION1);/*CS*/
-			tls_io_cfg_set(WM_IO_PB_02, WM_IO_OPTION4);/*D0*/
-			tls_io_cfg_set(WM_IO_PB_03, WM_IO_OPTION4);/*D1*/
-			tls_io_cfg_set(WM_IO_PB_04, WM_IO_OPTION4);/*D2*/
-			tls_io_cfg_set(WM_IO_PB_05, WM_IO_OPTION4);/*D3*/
+			tls_io_cfg_set(WM_IO_PB_28, WM_IO_OPTION1);/*D0*/
+			tls_io_cfg_set(WM_IO_PB_29, WM_IO_OPTION1);/*D1*/
+			tls_io_cfg_set(WM_IO_PB_30, WM_IO_OPTION1);/*D2*/
+			tls_io_cfg_set(WM_IO_PB_31, WM_IO_OPTION1);/*D3*/
 			tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_PSRAM);			
 			break;
 

+ 2 - 0
platform/drivers/i2s/wm_i2s.c

@@ -20,6 +20,7 @@ static void wm_i2s_set_mode(bool bl)
 }
 
 //master or slave
+#if 0
 static uint32_t wm_i2s_get_mode(void)
 {
 	uint32_t reg;
@@ -29,6 +30,7 @@ static uint32_t wm_i2s_get_mode(void)
 	
 	return (reg & 0x1);
 }
+#endif
 
 //i2s_stardard
 static void wm_i2s_set_format(uint32_t format)

+ 0 - 74
platform/drivers/lcd/wm_lcd.c

@@ -93,79 +93,5 @@ void tls_lcd_init(tls_lcd_options_t *opts)
 	TLS_LCD_POWERDOWM(1);
 }
 
-/**
-  *******************************************************
-  *               TEST CODE IS BELOW
-  *******************************************************
-  */
-
-void lcd_test(void)
-{
-	int i,j;
-	tls_lcd_options_t lcd_opts = {
-	    true,
-	    BIAS_ONEFOURTH,
-	    DUTY_ONEEIGHTH,
-	    VLCD31,
-	    8,
-	    60,
-	};
-	/* COM 0-3 */
-	tls_io_cfg_set(WM_IO_PB_25, WM_IO_OPTION6);
-	tls_io_cfg_set(WM_IO_PB_21, WM_IO_OPTION6);
-	tls_io_cfg_set(WM_IO_PB_22, WM_IO_OPTION6);
-	tls_io_cfg_set(WM_IO_PB_27, WM_IO_OPTION6);
-
-	/* SEG 0-5 */
-	tls_io_cfg_set(WM_IO_PB_23, WM_IO_OPTION6);
-	tls_io_cfg_set(WM_IO_PB_26, WM_IO_OPTION6);
-	tls_io_cfg_set(WM_IO_PB_24, WM_IO_OPTION6);
-	tls_io_cfg_set(WM_IO_PA_07, WM_IO_OPTION6);
-	tls_io_cfg_set(WM_IO_PA_08, WM_IO_OPTION6);
-	tls_io_cfg_set(WM_IO_PA_09, WM_IO_OPTION6);	
-	tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_LCD);
-
-	/*enable output valid*/
-	tls_reg_write32(HR_LCD_COM_EN, 0xF);
-	tls_reg_write32(HR_LCD_SEG_EN, 0x3F);
 
-    tls_lcd_init(&lcd_opts);
-	
-	while(1)
-	{
-#if 1
-		for(i=0; i<4; i++)
-		{
-			for(j=0; j<9; j++)
-			{
-				tls_lcd_seg_set(i, j, 1);
-				tls_os_time_delay(500);
-				printf("%d %d %d\n", i, j, 1);
-			}
-		}
-		
-		for(i=0; i<4; i++)
-		{
-			for(j=0; j<9; j++)
-			{
-				tls_lcd_seg_set(i, j, 0);
-				tls_os_time_delay(500);
-				printf("%d %d %d\n", i, j, 0);
-			}
-		}
-#else
-		
-		for(i=0; i<40; i++)
-		{
-			lcdDisplaySegment(i, 1);
-			tls_os_time_delay(HZ/2);
-		}
-		for(i=0; i<40; i++)
-		{
-			lcdDisplaySegment(i, 0);
-			tls_os_time_delay(HZ/2);
-		}
-#endif		
-	}
-}
 

+ 39 - 0
platform/drivers/watchdog/wm_watchdog.c

@@ -12,6 +12,7 @@
 #include "wm_irq.h"
 #include "wm_cpu.h"
 #include "wm_watchdog.h"
+#include "wm_ram_config.h"
 
 #define WDG_LOAD_VALUE_MAX  (0xFFFFFFFF / 40)
 #define WDG_LOAD_VALUE_DEF  (20 * 1000 * 1000)
@@ -28,6 +29,7 @@ ATTRIBUTE_ISR void WDG_IRQHandler(void)
     	csi_kernel_intrpt_exit();
         return;
     }
+	tls_sys_set_reboot_reason(REBOOT_REASON_WDG_TIMEOUT);
 	csi_kernel_intrpt_exit();	
 }
 
@@ -187,3 +189,40 @@ void tls_sys_reset(void)
 	while(1);
 }
 
+/**
+ * @brief          This function is used to set reboot reason
+ *
+ * @param          reason (enum SYS_REBOOT_REASON)
+ *
+ * @return         None
+ *
+ * @note           used with tls_sys_reset
+ */
+void tls_sys_set_reboot_reason(u32 reason)
+{
+	tls_reg_write32(SYS_REBOOT_REASON_ADDRESS, reason);
+}
+
+/**
+ * @brief          This function is used to get reboot reason
+ *
+ * @param          None
+ *
+ * @return         reason (enum SYS_REBOOT_REASON)
+ *
+ * @note           None
+ */
+int tls_sys_get_reboot_reason(void)
+{
+	u32 rebootval = 0;
+	rebootval = tls_reg_read32(SYS_REBOOT_REASON_ADDRESS);
+	if (rebootval >= REBOOT_REASON_MAX)
+	{
+		return REBOOT_REASON_POWER_ON;
+	}
+	else
+	{
+		return rebootval;
+	}
+}
+

+ 0 - 3
platform/inc/tls_wireless.h

@@ -325,9 +325,6 @@ struct tls_wl_event_ops {
 	int (*net_fail)(struct tls_wif *wif);
     int (*net_up)(struct tls_wif *wif);
     int (*update_stat)(struct tls_wif *wif, void *cur_bss);/* struct ieee80211_bss *cur_bss */
-#if TLS_PS_MODE_NEW_FTR		
-	int (*sleep_func)(struct tls_wif *wif);
-#endif
 };
 
 /* sk_buff allocated by wlan driver  */