zhyinch
2021-10-12 51f61fd2e68abaecc07f2edd71e19a386e8c94c3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "dw_driver.h"
#include "deca_device_api.h"
 
 
 
void delay_ms(uint32_t nTimer)  
{  
    uint32_t i=1000*nTimer;  
    delay_us(i);  
}  
 
void Reset_DW1000(void)
{
 
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 
    HAL_GPIO_WritePin(DW1000_RSTn_GPIO, DW1000_RSTn, GPIO_PIN_RESET);
    
   GPIO_InitStruct.Pin = DW1000_RSTn;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(DW1000_RSTn_GPIO, &GPIO_InitStruct);
 
    //drive the RSTn pin low
//    GPIO_ResetBits(DW1000_RSTn_GPIO, DW1000_RSTn);
 
    //put the pin back to tri-state ... as input
   GPIO_InitStruct.Pin = DW1000_RSTn;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(DW1000_RSTn_GPIO, &GPIO_InitStruct);
 
    deca_sleep(2);
}
 
//void DW_GPIO_Init(void)
//{
//    GPIO_InitTypeDef GPIO_InitStructure;
//    EXTI_InitTypeDef EXTI_InitStructure;
//    
//    /* Enable GPIO clock */
//    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
 
//    // Enable GPIO used for DW1000 wakeup
//    GPIO_InitStructure.GPIO_Pin = DW1000_WAKEUP;
//    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
//    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//    GPIO_Init(DW1000_WAKEUP_GPIO, &GPIO_InitStructure);
//    
//    // Enable GPIO used for DW1000 IRQ
//    GPIO_InitStructure.GPIO_Pin = DW1000_IRQ;
//    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //IRQ pin should be Pull Down to prevent unnecessary EXT IRQ while DW1000 goes to sleep mode
//    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//    GPIO_Init(DW1000_IRQ_GPIO, &GPIO_InitStructure);
//    
//    // Connect EXTI Line to GPIO Pin
////    GPIO_EXTILineConfig(DECAIRQ_EXTI_PORT, DECAIRQ_EXTI_PIN);
//    
//    // Configure EXTI line
//    EXTI_InitStructure.EXTI_Line = DECAIRQ_EXTI;
//    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
//    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;    //MPW3 IRQ polarity is high by default
//    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
//    EXTI_Init(&EXTI_InitStructure);
 
//}
 
//¶ÁÈ¡ÍⲿÖжÏ״̬
//ITStatus Get_Ext_IRQ_Statues(void)
//{
//    return EXTI_GetITStatus(DECAIRQ_EXTI);
//}
 
 
////ʹÄÜÍⲿÖжÏ
//void Enable_Ext_IRQ(void)
//{
//    NVIC_EnableIRQ(DECAIRQ_EXTI_IRQn);
//}
 
////½ûÖ¹ÍⲿÖжÏ
//void Disable_Ext_IRQ(void)
//{
//    NVIC_DisableIRQ(DECAIRQ_EXTI_IRQn);
//}
 
/*! ------------------------------------------------------------------------------------------------------------------
 * Function: decamutexon()
 *
 * Description: This function should disable interrupts. This is called at the start of a critical section
 * It returns the irq state before disable, this value is used to re-enable in decamutexoff call
 *
 * Note: The body of this function is defined in deca_mutex.c and is platform specific
 *
 * input parameters:
 *
 * output parameters
 *
 * returns the state of the DW1000 interrupt
 */
//decaIrqStatus_t decamutexon(void)
//{
//    decaIrqStatus_t s = Get_Ext_IRQ_Statues();
 
//    if(s)
//    {
//        Disable_Ext_IRQ(); //disable the external interrupt line
//    }
//    return s ;   // return state before disable, value is used to re-enable in decamutexoff call
//}
 
/*! ------------------------------------------------------------------------------------------------------------------
 * Function: decamutexoff()
 *
 * Description: This function should re-enable interrupts, or at least restore their state as returned(&saved) by decamutexon
 * This is called at the end of a critical section
 *
 * Note: The body of this function is defined in deca_mutex.c and is platform specific
 *
 * input parameters:
 * @param s - the state of the DW1000 interrupt as returned by decamutexon
 *
 * output parameters
 *
 * returns the state of the DW1000 interrupt
 */
//void decamutexoff(decaIrqStatus_t s)        // put a function here that re-enables the interrupt at the end of the critical section
//{
//    if(s)   //need to check the port state as we can't use level sensitive interrupt on the STM ARM
//    {
//        Enable_Ext_IRQ();
//    }
//}