[Feature]Upload Modem source code

Change-Id: Id4294f30faced84d3e6fd6d5e61e1111bf287a37
diff --git a/mcu/driver/devdrv/gpt/src/drv_litegpt.c b/mcu/driver/devdrv/gpt/src/drv_litegpt.c
new file mode 100644
index 0000000..5bca9f7
--- /dev/null
+++ b/mcu/driver/devdrv/gpt/src/drv_litegpt.c
@@ -0,0 +1,115 @@
+#include "drv_features_gpt.h"
+#include "drv_comm.h"
+
+#include "drv_litegpt.h"
+//#include "intrCtrl.h"
+
+#include "dcl.h"
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "sync_data.h"
+#include "us_timer.h"
+
+/*****************************************************************************
+ *                       Basic Driver Implementation                         *
+ *****************************************************************************/
+
+
+void drv_litegpt_reset(void)
+{
+	kal_uint32 i;
+
+	//PDN_CLR(PDN_GPT_CTL);
+	//Way: Need PDN setting??
+	
+	for(i = 0; i < 2; i++){
+		DRV_WriteReg32(LITE_GPT_BASE+(i<<3), 0); //CTRL
+		DRV_WriteReg32(LITE_GPT_BASE+0x04+(i<<3), 0xFFFFUL);//Len
+		DRV_WriteReg32(LITE_GPT_BASE+0x14+(i<<2), 0x4);//Prescalar
+	}
+       DRV_Reg32(LITE_GPT_BASE+0x10);//STAT1/STATE2 clear
+
+}
+
+/* time = count value */
+void drv_litegpt_set_timer(kal_uint32 num, kal_uint32 time, kal_uint32 mode, kal_uint32 prescaler)
+{
+
+	ASSERT((3 <= num) && (num <= 4) && (time <= (0xFFFFUL + 1)));
+	DRV_WriteReg32_NPW(LITE_GPT_BASE + 0x04 + ((num-3)<<3 ), (time - 1));//[Way] 1T prescaler error range still here?
+}
+
+void drv_litegpt_start_timer(kal_uint32 num)
+{
+	ASSERT((3 <= num) && (num <= 4));
+	DRV_WriteReg32_NPW(LITE_GPT_BASE  + ((num-3)<<3 ), 0x1);//[Way] bit0 and bit1 can write together?
+
+	Data_Sync_Barrier();
+}
+
+void drv_litegpt_stop_timer(kal_uint32 num)
+{
+	ASSERT((3 <= num) && (num <= 4));
+	DRV_WriteReg32_NPW(LITE_GPT_BASE  + ((num-3)<<3 ), 0x2);//[Way] mask bit1
+
+	Data_Sync_Barrier();
+}
+
+kal_uint32 drv_litegpt_time_remaining(kal_uint32 num)
+{
+	kal_uint32 remain_tick;
+	kal_uint32 cmp_val1 = 0;
+	kal_uint32 cmp_val2 = 0;
+	kal_uint32 loop = 0;
+	
+	ASSERT((3 <= num) && (num <= 4));
+	//[Way] designer will provide algorithm for remain tick
+	cmp_val1 = DRV_Reg32(LITE_GPT_BASE + 0x38 + ((num-3)<<2)) & 0xFFFF0000;
+	while(1)
+	{
+		cmp_val2 = DRV_Reg32(LITE_GPT_BASE + 0x38 + ((num-3)<<2)) & 0xFFFF0000;
+		if(cmp_val1 == cmp_val2)
+		{
+			break;
+		}
+		else
+		{
+			loop++;
+			if(loop >= 4)//less than 4 times
+			{
+				ASSERT(0);
+			}
+			cmp_val1 = cmp_val2;
+		}
+	}
+	remain_tick = (cmp_val2 >> 16);
+	
+	if(0xFFFF == remain_tick)//alreay start but in 0xFFFF stage
+	{
+		return DRV_Reg32((LITE_GPT_BASE + 0x4 + ((num - 3)<<3)));
+	}
+	
+	return remain_tick;
+}
+
+void drv_litegpt_set_wakeup_gpt(kal_uint32 time_tick)//the duration is about 1/32K*time_tick us, min/max = 4/0xffff
+{
+	ASSERT((4 <= time_tick) && (time_tick <= 0xFFFEUL));
+	drv_litegpt_set_timer(TOPSM_TEST_LITEGPT_WAKEUP, time_tick - 1,LITEGPT_CTRL_MODE_ONESHOT , LITEGPT_MIN_PRESCALE);
+	drv_litegpt_start_timer(TOPSM_TEST_LITEGPT_WAKEUP);
+}
+
+void drv_litegpt_clr_wakeup_event(void)
+{
+	kal_uint16 INT_Status;
+	//kal_uint16 Wakeup_Status;
+	INT_Status = DRV_Reg32(LITE_GPT_BASE + 0x10);//RU type register
+	//DRV_WriteReg32_NPW(LITE_GPT_BASE + 0x10, INT_Status);//W1C interrupt status
+
+	//Wakeup_Status = DRV_Reg32(LITE_GPT_BASE + 0x34);
+	DRV_WriteReg32_NPW(LITE_GPT_BASE + 0x34, INT_Status); //clear wakeup event/interrupt
+	while(0 != DRV_Reg32(LITE_GPT_BASE + 0x10));
+}
+
+
+