Browse Source

【测试】增加定时休眠唤醒功能,增加sy6970驱动(未开发完成)

BJQX-ZHENGCHAO\Zhengchao 1 year ago
parent
commit
92e3b4d127

+ 11 - 6
code/app/lib/hal_sy6970.c

@@ -1,4 +1,5 @@
 #include "hal_sy6970.h"
+#include "hal_adapter.h"
 
 #define __nop() __asm__("NOP")
 
@@ -16,7 +17,7 @@
 
 
 
-#define sy6970_speed 5
+#define sy6970_speed 4
  
 //需要示波器调1us的时间
 static void delay_us(uint16_t time)
@@ -25,8 +26,7 @@ static void delay_us(uint16_t time)
 
 	for(i=time;i>0;i--)
 	{
-		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
-		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();		
+		__nop();/*__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
 		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
 		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
 		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
@@ -43,6 +43,7 @@ static void delay_us(uint16_t time)
 		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
 		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
 		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();*/
 	}
 }
 
@@ -93,8 +94,9 @@ static void iic_start(void)
 	
 	IIC_SDA4(1);
 	IIC_SCL4(1);
+	Dio_FlipChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2);
 	delay_us(sy6970_speed);
-	
+	Dio_FlipChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2);
 	IIC_SDA4(0);
 	delay_us(sy6970_speed);
 	IIC_SCL4(0);
@@ -187,6 +189,9 @@ static void iic_send_byte(uint8_t byte)
 		delay_us(sy6970_speed);
 		IIC_SCL4(0);
 	}	
+//	IIC_SDA4(1);
+//	IIC_SCL4(1);
+//	iic_ack();//add ack test
 }
  
 
@@ -230,7 +235,7 @@ static void sy6970_write_byte(uint8_t dev_addr,uint8_t RAddr, uint8_t WData)
 }
  
 
-static void sy6970_read_byte(uint8_t dev_addr,uint8_t RAddr, uint8_t *RData)
+void sy6970_read_byte(uint8_t dev_addr,uint8_t RAddr, uint8_t *RData)
 {
   iic_start();								 		 
   iic_send_byte(dev_addr); 
@@ -238,7 +243,7 @@ static void sy6970_read_byte(uint8_t dev_addr,uint8_t RAddr, uint8_t *RData)
   iic_send_byte(RAddr);   		 		 
   iic_wait_ack();	    				 		 
   iic_start();  	 	   				 		 
-  iic_send_byte(dev_addr|0x01);    
+  iic_send_byte(dev_addr|0x01);
   iic_wait_ack();	 						 		 	
   *RData = iic_recive_byte(0);	 		    
   iic_stop();									 		 	

+ 1 - 0
code/app/lib/hal_sy6970.h

@@ -18,4 +18,5 @@
 void sy6970_init(void);
 uint8_t sy6970_charge_status(void);
 void sy6970_task(void *argv);
+void sy6970_read_byte(uint8_t dev_addr,uint8_t RAddr, uint8_t *RData);
 #endif

+ 1 - 1
code/hal/Hal_Wdg.c

@@ -16,7 +16,7 @@ void WdgInit(void)
 	Wdg_43_Instance0_SetMode(WDGIF_FAST_MODE);
 
 	/* Set the Wdg Trigger Condition in order to periodically service the Wdg */
-	Wdg_43_Instance0_SetTriggerCondition(15000);
+	Wdg_43_Instance0_SetTriggerCondition(5000);
 }
 
 void WdgDeInit(void)

+ 27 - 5
code/hal/hal_adapter.c

@@ -358,6 +358,10 @@ Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32
 		 ret = xQueueReceive(UartSendQueue[UartIdx],&UartSendMsg,1);
 		 if(ret==pdTRUE)
 		 {
+			 if(UartIdx==UART_LPUART0)
+			 {
+				 Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN, STD_ON);
+			 }
 			 T_Uart_Status[UartIdx] = Uart_AsyncSend(UartIdx, UartSendMsg.dataPtr, UartSendMsg.DataLen);
 		     if (E_OK != T_Uart_Status[UartIdx])
 		     {
@@ -574,6 +578,10 @@ void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event)
     //    (void)userData;
 		Lpuart_Uart_Ip_StateStructureType * UartState;
 		UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[hwInstance];
+	if (hwInstance==0&&event == LPUART_UART_IP_EVENT_END_TRANSFER)
+	{
+		Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN, STD_OFF);
+	}
     /* Check the event type */
     if (event == LPUART_UART_IP_EVENT_RX_FULL)
     {
@@ -1005,9 +1013,23 @@ void MCUSleep(void)
 	Icu_Init(&Icu_Config_VS_0);
 #endif
 
+#define TIME_S_GPT_WEAKUP(X) ((unsigned int)(1.9073 * (X)))
+	/* 最大定时时间 = 65535/1.907 34365 S
+	 * 	9.5H
+*/
+    Gpt_StartTimer(GptConf_GptChannelConfiguration_GptChannelConfiguration_LPTMR, TIME_S_GPT_WEAKUP(60));
+    Gpt_EnableWakeup(GptConf_GptChannelConfiguration_GptChannelConfiguration_LPTMR);
+    Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_LPTMR);
+    IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCSTEN(1U);
+    Gpt_SetMode(GPT_MODE_SLEEP);
 	Mcu_SetMode(McuModeSettingConf_VLPS);
 
 
+	Mcu_SetMode(McuModeSettingConf_Run);
+	Gpt_GetTimeElapsed(GptConf_GptChannelConfiguration_GptChannelConfiguration_LPTMR);
+	//Gpt_GetTimeElapsed(GptConf_GptChannelConfiguration_GptChannelConfiguration_LPTMR);
+	Gpt_GetTimeRemaining(GptConf_GptChannelConfiguration_GptChannelConfiguration_LPTMR);
+
 //	typedef void (*AppAddr)(void);
 //	AppAddr resetHandle = (AppAddr)(0x14601);
 //	OsIf_SuspendAllInterrupts();
@@ -1052,7 +1074,7 @@ void SystemDeinit(void)
 
 //	Gpt_DisableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
 
-	Gpt_DeInit();
+//	Gpt_DeInit();
 
 	Spi_DeInit();
 
@@ -1229,16 +1251,16 @@ void SystemModulesInit(void)
 	Gpt_Init(&Gpt_Config_VS_0);
 
 	/* Enable the Gpt notification to periodically service the Wdg */
-//	Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
+	Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_LPIT0_CH0);
 
 	//enable the batt power
 	Dio_WriteChannel(DioConf_DioChannel_PTA1_GPIO_OUT_MCU_BAT_PWR_EN,STD_ON);
 
 	Icu_DeInit();
 
-	WdgInit();
-
-	IsFeedWdg = true;
+//	WdgInit();
+//
+//	IsFeedWdg = true;
 }
 
 void displayResetReasonWithLED(void)

+ 16 - 8
code/main.c

@@ -85,16 +85,24 @@ int main(void)
 	SEGGER_RTT_printf("boot\n");
 #endif
 
+#include "hal_sy6970.h"
+	uint8 data = 0;
+
+	for(int i =0 ;i<10000;i++)
+	{
+		sy6970_read_byte(SY6970_ADDR<<1,0x0E,&data);
+		Dio_FlipChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1);
+	}
 
 
-	UartInit();
-	xTaskCreate(MainTask, (const char *const)"MainTask", 512, (void *)0, main_TASK_PRIORITY + 6, &MainTask_Handle);
-	//xTaskCreate(Uart0Task, (const char *const)"Uart0_Bms_Task", 512, (void *)0, main_TASK_PRIORITY + 2, Uart0Task_Handle);
-	xTaskCreate(CanTask, (const char *const)"CanTask", 512, (void *)0, main_TASK_PRIORITY + 2, &CanTask_Handle);
-	xTaskCreate(GpsTask, (const char *const)"GpsTask", 2048, (void *)0, main_TASK_PRIORITY + 1, &GpsTask_Handle);
-	xTaskCreate(Uart_4G_Task, (const char *const)"Uart_4G_Task", 2048, (void *)0, main_TASK_PRIORITY + 0, &Uart_4G_Task_Handle);
-	xTaskCreate(BBox_BCU_Task, (const char *const)"BBox_BCU_Task", 2048, (void *)0, main_TASK_PRIORITY + 3, &BBox_BCU_Task_Handle);
-	vTaskStartScheduler();
+//	UartInit();
+//	xTaskCreate(MainTask, (const char *const)"MainTask", 512, (void *)0, main_TASK_PRIORITY + 6, &MainTask_Handle);
+//	//xTaskCreate(Uart0Task, (const char *const)"Uart0_Bms_Task", 512, (void *)0, main_TASK_PRIORITY + 2, Uart0Task_Handle);
+//	xTaskCreate(CanTask, (const char *const)"CanTask", 512, (void *)0, main_TASK_PRIORITY + 2, &CanTask_Handle);
+//	xTaskCreate(GpsTask, (const char *const)"GpsTask", 2048, (void *)0, main_TASK_PRIORITY + 1, &GpsTask_Handle);
+//	xTaskCreate(Uart_4G_Task, (const char *const)"Uart_4G_Task", 2048, (void *)0, main_TASK_PRIORITY + 0, &Uart_4G_Task_Handle);
+//	xTaskCreate(BBox_BCU_Task, (const char *const)"BBox_BCU_Task", 2048, (void *)0, main_TASK_PRIORITY + 3, &BBox_BCU_Task_Handle);
+//	vTaskStartScheduler();
 
 	for (;;)
 	{

+ 1 - 1
generate/src/Clock_Ip_VS_0_PBcfg.c

@@ -498,7 +498,7 @@ const Clock_Ip_ClockConfigType Mcu_aClockConfigPB_VS_0[1U] = {
             #if CLOCK_DIVIDERS_NO > 1U
             {
                 SIRCDIV2_CLK,
-                2U,
+                64U,
                 {
                     0U,
                 }

+ 4 - 4
generate/src/Gpt_VS_0_PBcfg.c

@@ -193,10 +193,10 @@ static const uint8 u8GptChannelIdToIndexMap_VS_0[GPT_NUM_CONFIG] =
 static const Gpt_ChannelConfigType Gpt_InitChannelPB_VS_0[GPT_CONF_CHANNELS_PB_VS_0] =
 {
     {   /*GptChannelConfiguration_LPIT0_CH0 configuration data*/
-        (boolean)FALSE, /* Wakeup capability */
+        (boolean)TRUE, /* Wakeup capability */
         &Wdg_Cbk_GptNotification0, /* Channel notification */
 #if ((GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_REPORT_WAKEUP_SOURCE == STD_ON))
-        (EcuM_WakeupSourceType)0U, /* Wakeup information */
+        (EcuM_WakeupSourceType)((uint32)((uint32)1 << 0)), /* Wakeup information */
 #endif
         (Gpt_ValueType)(4294967295U), /* Maximum ticks value*/
         (GPT_CH_MODE_CONTINUOUS), /* Timer mode:continous/one-shot */
@@ -215,10 +215,10 @@ static const Gpt_ChannelConfigType Gpt_InitChannelPB_VS_0[GPT_CONF_CHANNELS_PB_V
     }
 ,
     {   /*GptChannelConfiguration_LPTMR configuration data*/
-        (boolean)FALSE, /* Wakeup capability */
+        (boolean)TRUE, /* Wakeup capability */
         &LPTMR_WakeUp_Notification, /* Channel notification */
 #if ((GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_REPORT_WAKEUP_SOURCE == STD_ON))
-        (EcuM_WakeupSourceType)0U, /* Wakeup information */
+        (EcuM_WakeupSourceType)((uint32)((uint32)1 << 0)), /* Wakeup information */
 #endif
         (Gpt_ValueType)(65535U), /* Maximum ticks value*/
         (GPT_CH_MODE_CONTINUOUS), /* Timer mode:continous/one-shot */

+ 1 - 1
generate/src/LPit_Gpt_Ip_VS_0_PBcfg.c

@@ -108,7 +108,7 @@ const Lpit_Gpt_Ip_InstanceConfigType LPIT_0_InitConfig_PB_VS_0 =
         /** @brief DOZE Mode Enable Bit */
         (boolean)TRUE,
         /** @brief LPIT Debug Mode */
-        (boolean)FALSE
+        (boolean)TRUE
 };
 
 const Lpit_Gpt_Ip_ChannelConfigType LPIT_0_ChannelConfig_PB_VS_0[1U] = 

+ 1 - 1
generate/src/Lptmr_Gpt_Ip_VS_0_PBcfg.c

@@ -112,7 +112,7 @@ Lptmr_Gpt_Ip_ConfigType LPTMR_0_InitConfig_PB_VS_0 =
     0U, /* LPTMR alternate Clock divider */ 
     #endif
     /** @brief Prescaler value */
-    1U, /* LPTMR Prescaler */ 
+    15U, /* LPTMR Prescaler */ 
     /** @brief LPtimer clock source  */
     LPTMR_GPT_IP_CLOCK_SIRCDIV2,
     /** @brief LPtimer callback name */