Ver código fonte

add gpio&irq

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 anos atrás
pai
commit
cd181dccc0
5 arquivos alterados com 243 adições e 3 exclusões
  1. 42 0
      Application/bsp/gpio.c
  2. 31 0
      Application/bsp/gpio.h
  3. 131 0
      Application/bsp/irqs.c
  4. 27 3
      Project/BMS.uvoptx
  5. 12 0
      Project/BMS.uvprojx

+ 42 - 0
Application/bsp/gpio.c

@@ -0,0 +1,42 @@
+#include "gpio.h"
+/* all pins used as gpio(input/output/irq) must be defined here */
+void gpio_init(void){
+	rcu_periph_clock_enable(RCU_GPIOA);
+	rcu_periph_clock_enable(RCU_GPIOB);
+	rcu_periph_clock_enable(RCU_GPIOC);
+	rcu_periph_clock_enable(RCU_GPIOF);
+	//hall 2 detect
+	gpio_mode_input(GPIOC, GPIO_PUPD_NONE, GPIO_PIN_13);
+	//hall 1 detect
+	gpio_mode_input(GPIOC, GPIO_PUPD_NONE, GPIO_PIN_15);
+	
+	//IR uart0 enable
+	gpio_mode_output(GPIOC, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_14);
+	//IR uart2 enable
+	gpio_mode_output(GPIOF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_0);
+	//power good detect
+	gpio_mode_input(GPIOF, GPIO_PUPD_NONE, GPIO_PIN_7);
+	//temp senser enable
+	gpio_mode_output(GPIOF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_1);
+	//charger detect
+	gpio_mode_input(GPIOB, GPIO_PUPD_NONE, GPIO_PIN_10);
+	//aux 12v power enable
+	gpio_mode_output(GPIOB, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_2);
+	//aux 12v lock detect
+	gpio_mode_input(GPIOB, GPIO_PUPD_NONE, GPIO_PIN_11);
+	//LED 0,1,2
+	gpio_mode_output(GPIOB, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_12);
+	gpio_mode_output(GPIOB, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_13);
+	gpio_mode_output(GPIOB, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_14);
+	//LED3,4
+	gpio_mode_output(GPIOA, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_8);
+	gpio_mode_output(GPIOA, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_9);
+	
+	//12v DC-DC enable
+	gpio_mode_output(GPIOA, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_11);
+
+	//ms5238 irq
+	gpio_mode_input(GPIOA, GPIO_PUPD_NONE, GPIO_PIN_12);
+}
+
+

+ 31 - 0
Application/bsp/gpio.h

@@ -0,0 +1,31 @@
+#ifndef _GPIO_H__
+#define _GPIO_H__
+#include "gd32f1x0.h"
+#include "gd32f1x0_libopt.h"
+
+/*switch for temperature sensers */
+#define TEMP_OPEN(x) gpio_bit_write(GPIOF,GPIO_PIN_1,(bit_status)(x))
+/*switch for small current aux */
+#define AUX_VOL_OPEN(x) gpio_bit_write(GPIOB,GPIO_PIN_2,(bit_status)(x))
+/*switch for larger current DCDC  */
+#define DCDC_VOL_OPEN(x) gpio_bit_write(GPIOA,GPIO_PIN_11,(bit_status)(x))
+/*switch for IR uart0 */
+#define UART0_IR_EN(x) gpio_bit_write(GPIOC,GPIO_PIN_14,(bit_status)(x))
+/*switch for IR uart1 */
+#define UART1_IR_EN(x) gpio_bit_write(GPIOF,GPIO_PIN_0,(bit_status)(x))
+/*detect for charger in/out */
+#define IS_CHARGER_IN() !gpio_input_bit_get(GPIOB,GPIO_PIN_10)
+
+
+static __inline__ void gpio_mode_input(uint32_t gpio_periph, uint32_t pull_up_down, uint32_t pin){
+	gpio_mode_set(gpio_periph, GPIO_MODE_INPUT, pull_up_down, pin);
+}
+
+static __inline__ void gpio_mode_output(uint32_t gpio_periph, uint32_t pull_up_down, uint8_t otype, uint32_t speed, uint32_t pin){
+	gpio_mode_set(gpio_periph, GPIO_MODE_OUTPUT, pull_up_down, pin);
+	gpio_output_options_set(gpio_periph, otype, speed, pin);
+}
+
+
+#endif /* _GPIO_H__ */
+

+ 131 - 0
Application/bsp/irqs.c

@@ -0,0 +1,131 @@
+#include "gd32f1x0.h"
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void){
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1){
+    }
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1){
+    }
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1){
+    }
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1){
+    }
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+void EXTI0_1_IRQHandler(void){
+	if(RESET != exti_interrupt_flag_get(EXTI_0)){
+		exti_interrupt_flag_clear(EXTI_0);
+	}
+	if(RESET != exti_interrupt_flag_get(EXTI_1)){
+		exti_interrupt_flag_clear(EXTI_1);
+	}
+}
+
+void EXTI2_3_IRQHandler(void){
+	if(RESET != exti_interrupt_flag_get(EXTI_2)){
+		exti_interrupt_flag_clear(EXTI_2);
+	}
+	if(RESET != exti_interrupt_flag_get(EXTI_3)){
+		exti_interrupt_flag_clear(EXTI_3);
+	}	
+}
+
+void EXTI4_15_IRQHandler(void){
+	if(RESET != exti_interrupt_flag_get(EXTI_4)){
+		exti_interrupt_flag_clear(EXTI_4);
+	}	
+	if(RESET != exti_interrupt_flag_get(EXTI_5)){
+		exti_interrupt_flag_clear(EXTI_5);
+	}
+	if(RESET != exti_interrupt_flag_get(EXTI_6)){
+		exti_interrupt_flag_clear(EXTI_6);
+	}	
+	if(RESET != exti_interrupt_flag_get(EXTI_7)){
+		exti_interrupt_flag_clear(EXTI_7);
+	}
+	if(RESET != exti_interrupt_flag_get(EXTI_8)){
+		exti_interrupt_flag_clear(EXTI_8);
+	}
+	if(RESET != exti_interrupt_flag_get(EXTI_9)){
+		exti_interrupt_flag_clear(EXTI_9);
+	}		
+	if(RESET != exti_interrupt_flag_get(EXTI_10)){
+		exti_interrupt_flag_clear(EXTI_10);
+	}
+	if(RESET != exti_interrupt_flag_get(EXTI_11)){
+		exti_interrupt_flag_clear(EXTI_11);
+	}
+	//ms5238 irq
+	if(RESET != exti_interrupt_flag_get(EXTI_12)){
+		exti_interrupt_flag_clear(EXTI_12);
+	}
+	if(RESET != exti_interrupt_flag_get(EXTI_13)){
+		exti_interrupt_flag_clear(EXTI_13);
+	}
+	if(RESET != exti_interrupt_flag_get(EXTI_14)){
+		exti_interrupt_flag_clear(EXTI_14);
+	}
+	if(RESET != exti_interrupt_flag_get(EXTI_15)){
+		exti_interrupt_flag_clear(EXTI_15);
+	}
+
+}
+

+ 27 - 3
Project/BMS.uvoptx

@@ -515,6 +515,30 @@
     <tvExpOptDlg>0</tvExpOptDlg>
     <cbSel>0</cbSel>
     <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>28</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Application\bsp\gpio.c</PathWithFileName>
+      <FilenameWithoutPath>gpio.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>29</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Application\bsp\irqs.c</PathWithFileName>
+      <FilenameWithoutPath>irqs.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
   </Group>
 
   <Group>
@@ -527,13 +551,13 @@
 
   <Group>
     <GroupName>StartUP</GroupName>
-    <tvExp>0</tvExp>
+    <tvExp>1</tvExp>
     <tvExpOptDlg>0</tvExpOptDlg>
     <cbSel>0</cbSel>
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>28</FileNumber>
+      <FileNumber>30</FileNumber>
       <FileType>2</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -545,7 +569,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>29</FileNumber>
+      <FileNumber>31</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>

+ 12 - 0
Project/BMS.uvprojx

@@ -527,6 +527,18 @@
         </Group>
         <Group>
           <GroupName>BSP</GroupName>
+          <Files>
+            <File>
+              <FileName>gpio.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Application\bsp\gpio.c</FilePath>
+            </File>
+            <File>
+              <FileName>irqs.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Application\bsp\irqs.c</FilePath>
+            </File>
+          </Files>
         </Group>
         <Group>
           <GroupName>Libs</GroupName>