temp: add T108 temp api

Change-Id: Icef782cc595f090c4dd2a732c4fa34b1acac6cbc
diff --git a/mbtk/include/lynq/lynq_qser_thermal.h b/mbtk/include/lynq/lynq_qser_thermal.h
new file mode 100644
index 0000000..5bcc81b
--- /dev/null
+++ b/mbtk/include/lynq/lynq_qser_thermal.h
@@ -0,0 +1,12 @@
+#ifndef __LYNQ_QSER_THERMAL_H__
+#define __LYNQ_QSER_THERMAL_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int get_thermal_zone(int *numbers, int size);
+#ifdef __cplusplus
+}
+#endif
+#endif
+
diff --git a/mbtk/lynq_lib/Makefile b/mbtk/lynq_lib/Makefile
index ddfa753..5a0ed65 100755
--- a/mbtk/lynq_lib/Makefile
+++ b/mbtk/lynq_lib/Makefile
@@ -40,6 +40,7 @@
 	src/lynq_sim.c \
 	src/lynq_sleep.c \
 	src/lynq_sms.c \
+	src/lynq_thermal.c \
 	src/lynq_time.c \
 	src/lynq_voice_call.c
 
diff --git a/mbtk/lynq_lib/src/lynq_net_light.c b/mbtk/lynq_lib/src/lynq_net_light.c
index 0d59348..ee84b71 100755
--- a/mbtk/lynq_lib/src/lynq_net_light.c
+++ b/mbtk/lynq_lib/src/lynq_net_light.c
@@ -97,6 +97,7 @@
     if(ret != 0)
     {
         LOGE("[qser_led]mbtk_led_gpio_init fail.");
+        qser_led_client_init();
         return QSER_RESULT_FAIL;
     }
 
@@ -126,6 +127,7 @@
     if(ret != 0)
     {
         LOGE("[qser_led]mbtk_led_gpio_init fail.");
+        qser_led_client_init();
         return QSER_RESULT_FAIL;
     }
 
diff --git a/mbtk/lynq_lib/src/lynq_thermal.c b/mbtk/lynq_lib/src/lynq_thermal.c
new file mode 100644
index 0000000..ed88a8b
--- /dev/null
+++ b/mbtk/lynq_lib/src/lynq_thermal.c
@@ -0,0 +1,114 @@
+#if 1
+#include "mbtk_type.h"
+#include "mbtk_log.h"
+#include "lynq_qser_thermal.h"
+#include "mbtk_info_api.h"
+
+/****************************DEFINE***************************************/
+#define QSER_RESULT_FAIL    -1
+#define QSER_RESULT_SUCCESS 0
+/****************************DEFINE***************************************/
+
+/****************************VARIABLE***************************************/
+extern mbtk_info_handle_t* qser_info_handle;
+extern int qser_info_handle_num;
+/****************************VARIABLE***************************************/
+
+
+/******************************FUNC*****************************************/
+static int qser_thermal_client_init(void)
+{
+    if(qser_info_handle == NULL)
+    {
+        qser_info_handle = mbtk_info_handle_get();
+        if(qser_info_handle)
+        {
+            qser_info_handle_num++;
+        } 
+        else
+        {
+            LOGE("[qser_thermal] mbtk_info_handle_get() fail.");
+            return QSER_RESULT_FAIL;
+        }
+    }
+    else
+    {
+        qser_info_handle_num++;
+    }
+
+    LOGE("[qser_thermal] mbtk_info_handle_get() success.");
+    return QSER_RESULT_SUCCESS;
+}
+
+static int qser_thermal_client_deinit(void)
+{
+    if(qser_info_handle)
+    {
+        LOGE("[qser_thermal] qser_info_handle_num = %d", qser_info_handle_num);
+        if(qser_info_handle_num == 1)
+        { // 最后一个引用,可释放。
+            int ret = mbtk_info_handle_free(&qser_info_handle);
+            if(ret)
+            {
+                LOGE("[qser_thermal] mbtk_info_handle_free() fail.");
+                return QSER_RESULT_FAIL;
+            }
+            else
+            {
+                qser_info_handle_num = 0;
+                qser_info_handle = NULL;
+            }
+        } 
+        else
+        {
+            qser_info_handle_num--;
+        }
+    }
+    else
+    {
+        LOGE("[qser_thermal] handle not inited.");
+        return QSER_RESULT_FAIL;
+    }
+
+    return QSER_RESULT_SUCCESS;
+}
+
+/******************************FUNC*****************************************/
+
+/****************************API***************************************/
+int get_thermal_zone(int *numbers, int size)
+{
+    if(numbers == NULL || size < 1)
+    {
+        LOGE("[qser_thermal]: numbers is NULL!");
+        return -1;
+    }
+    
+    int ret = 0;
+    int thermal = -1;
+    int thermal_num = 0;
+
+    ret = qser_thermal_client_init();
+    if(ret != QSER_RESULT_SUCCESS)
+    {
+        LOGE("[qser_thermal]qser_led_client_init fail.");
+        return QSER_RESULT_FAIL;
+    }
+    
+    ret = mbtk_temp_get(qser_info_handle, 1, &thermal);
+    if(ret != QSER_RESULT_SUCCESS)
+    {
+        LOGE("[qser_thermal]mbtk_temp_get fail.");
+        qser_thermal_client_deinit();
+        return QSER_RESULT_FAIL;
+    }
+
+    qser_thermal_client_deinit();
+    thermal_num = 1;
+    numbers[0] = thermal;
+
+    return thermal_num;
+}
+/****************************API***************************************/
+
+#endif
diff --git a/mbtk/test/asr1806/qser_thermal_test.c b/mbtk/test/asr1806/qser_thermal_test.c
new file mode 100644
index 0000000..62af03a
--- /dev/null
+++ b/mbtk/test/asr1806/qser_thermal_test.c
@@ -0,0 +1,27 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+#include"lynq_qser_thermal.h"
+#define MAX_SIZE 3
+
+int main(int argc, char *argv[]){
+    int numbers[MAX_SIZE];
+    int ret = 0;
+    ret = get_thermal_zone(numbers, MAX_SIZE);
+    if (ret <= 0)
+    {
+        printf("get_thermal_zone error\n");
+        return -1;
+    }
+
+    for (int j = 0; j < ret; ++j) {
+        printf("[%s-%d] temp[%d] = %d \n", __func__, __LINE__, j, numbers[j]);
+    }
+
+    return 0;
+}
+