guanjiao ren
2018-05-16 549a8abdc9d1a64bc6cde50f979633eb5e43c555
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*! ----------------------------------------------------------------------------
 * @file    port.h
 * @brief    HW specific definitions and functions for portability
 *
 * @attention
 *
 * Copyright 2013 (c) DecaWave Ltd, Dublin, Ireland.
 *
 * All rights reserved.
 *
 * @author DecaWave
 */
 
 
#ifndef PORT_H_
#define PORT_H_
 
#ifdef __cplusplus
extern "C" {
#endif
 
#include "stm32f10x.h"
 
/* Define our wanted value of CLOCKS_PER_SEC so that we have a millisecond
 * tick timer. */
#undef CLOCKS_PER_SEC
#define CLOCKS_PER_SEC 1000
 
void printf2(const char *format, ...);
 
void USART_puts(uint8_t *s, uint8_t len);
 
extern int writetospi_serial(uint16_t headerLength,
                             const uint8_t *headerBuffer,
                             uint32_t bodylength,
                             const uint8_t *bodyBuffer);
 
extern int readfromspi_serial(uint16_t    headerLength,
                              const uint8_t *headerBuffer,
                              uint32_t readlength,
                              uint8_t *readBuffer );
 
#define writetospi  writetospi_serial
#define readfromspi readfromspi_serial
 
typedef enum
{
    LED_PC6,
    LED_PC7,
    LED_PC8,
    LED_PC9,
    LED_ALL,
    LEDn
} led_t;
 
#define SPIy_PRESCALER                SPI_BaudRatePrescaler_128
 
#define SPIy                        SPI2
#define SPIy_GPIO                    GPIOB
#define SPIy_CS                        GPIO_Pin_12
#define SPIy_CS_GPIO                GPIOB
#define SPIy_SCK                    GPIO_Pin_13
#define SPIy_MISO                    GPIO_Pin_14
#define SPIy_MOSI                    GPIO_Pin_15
 
#define LCD_RW                        GPIO_Pin_10
#define LCD_RS                        GPIO_Pin_11
 
#define SPIx_PRESCALER                SPI_BaudRatePrescaler_8
 
#define SPIx                        SPI1
#define SPIx_GPIO                    GPIOA
#define SPIx_CS                        GPIO_Pin_4
#define SPIx_CS_GPIO                GPIOA
#define SPIx_SCK                    GPIO_Pin_5
#define SPIx_MISO                    GPIO_Pin_6
#define SPIx_MOSI                    GPIO_Pin_7
 
#define DW1000_RSTn                    GPIO_Pin_1
#define DW1000_RSTn_GPIO            GPIOA
 
#define DECARSTIRQ                  GPIO_Pin_0
#define DECARSTIRQ_GPIO             GPIOA
#define DECARSTIRQ_EXTI             EXTI_Line0
#define DECARSTIRQ_EXTI_PORT        GPIO_PortSourceGPIOA
#define DECARSTIRQ_EXTI_PIN         GPIO_PinSource0
#define DECARSTIRQ_EXTI_IRQn        EXTI0_IRQn
 
#define DECAIRQ                     GPIO_Pin_5
#define DECAIRQ_GPIO                GPIOB
#define DECAIRQ_EXTI                EXTI_Line5
#define DECAIRQ_EXTI_PORT           GPIO_PortSourceGPIOB
#define DECAIRQ_EXTI_PIN            GPIO_PinSource5
#define DECAIRQ_EXTI_IRQn           EXTI9_5_IRQn
#define DECAIRQ_EXTI_USEIRQ         ENABLE
#define DECAIRQ_EXTI_NOIRQ          DISABLE
 
#define TA_BOOT1                     GPIO_Pin_2
#define TA_BOOT1_GPIO                GPIOB
 
#define TA_RESP_DLY                 GPIO_Pin_0
#define TA_RESP_DLY_GPIO            GPIOC
 
#define TA_SW1_3                    GPIO_Pin_0
#define TA_SW1_4                    GPIO_Pin_1
#define TA_SW1_5                    GPIO_Pin_2
#define TA_SW1_6                    GPIO_Pin_3
#define TA_SW1_7                    GPIO_Pin_4
#define TA_SW1_8                    GPIO_Pin_5
#define TA_SW1_GPIO                 GPIOC
 
#define LED_PIN         GPIO_Pin_8
#define SW1             GPIO_Pin_12
#define SW2                 GPIO_Pin_15
#define SW3                 GPIO_Pin_3
#define SW4                 GPIO_Pin_4
#define SW5                 GPIO_Pin_5
#define SW6                 GPIO_Pin_6
#define SW7                 GPIO_Pin_7
#define LED_ON             GPIO_WriteBit(GPIOA, LED_PIN,1)
#define LED_OFF             GPIO_WriteBit(GPIOA, LED_PIN,0)
#define S1_SWITCH_ON  (1)
#define S1_SWITCH_OFF (0)
//when switch (S1) is 'on' the pin is low
int is_switch_on(uint16_t GPIOpin);
 
#define port_IS_TAG_pressed()        is_switch_on(TA_SW1_4)
#define port_IS_LONGDLY_pressed()    is_dlybutton_low()
 
#define USARTx                        USART2
 
#define port_USARTx_busy_sending()    0 //(USART_GetFlagStatus((USARTx),(USART_FLAG_TXE))==(RESET))
#define port_USARTx_no_data()        0 //(USART_GetFlagStatus((USARTx),(USART_FLAG_RXNE))==(RESET))
#define port_USARTx_send_data(x)      //USART_SendData((USARTx),(uint8_t)(x))
#define port_USARTx_receive_data()    0 //USART_ReceiveData(USARTx)
 
#define port_SPIx_busy_sending()        (SPI_I2S_GetFlagStatus((SPIx),(SPI_I2S_FLAG_TXE))==(RESET))
#define port_SPIx_no_data()                (SPI_I2S_GetFlagStatus((SPIx),(SPI_I2S_FLAG_RXNE))==(RESET))
#define port_SPIx_send_data(x)            SPI_I2S_SendData((SPIx),(x))
#define port_SPIx_receive_data()        SPI_I2S_ReceiveData(SPIx)
#define port_SPIx_disable()                SPI_Cmd(SPIx,DISABLE)
#define port_SPIx_enable()              SPI_Cmd(SPIx,ENABLE)
#define port_SPIx_set_chip_select()        GPIO_SetBits(SPIx_CS_GPIO,SPIx_CS)
#define port_SPIx_clear_chip_select()    GPIO_ResetBits(SPIx_CS_GPIO,SPIx_CS)
 
#define port_SPIy_busy_sending()        (SPI_I2S_GetFlagStatus((SPIy),(SPI_I2S_FLAG_TXE))==(RESET))
#define port_SPIy_no_data()                (SPI_I2S_GetFlagStatus((SPIy),(SPI_I2S_FLAG_RXNE))==(RESET))
#define port_SPIy_send_data(x)            SPI_I2S_SendData((SPIy),(x))
#define port_SPIy_receive_data()        SPI_I2S_ReceiveData(SPIy)
#define port_SPIy_disable()                SPI_Cmd(SPIy,DISABLE)
#define port_SPIy_enable()              SPI_Cmd(SPIy,ENABLE)
#define port_SPIy_set_chip_select()        GPIO_SetBits(SPIy_CS_GPIO,SPIy_CS)
#define port_SPIy_clear_chip_select()    GPIO_ResetBits(SPIy_CS_GPIO,SPIy_CS)
#define port_LCD_RS_set()                GPIO_SetBits(SPIy_GPIO,LCD_RS)
#define port_LCD_RS_clear()                GPIO_ResetBits(SPIy_GPIO,LCD_RS)
#define port_LCD_RW_set()                GPIO_SetBits(SPIy_GPIO,LCD_RW)
#define port_LCD_RW_clear()                GPIO_ResetBits(SPIy_GPIO,LCD_RW)
 
#define port_GET_stack_pointer()        __get_MSP()
#define port_GET_rtc_time()                RTC_GetCounter()
#define port_SET_rtc_time(x)            RTC_SetCounter(x)
 
ITStatus EXTI_GetITEnStatus(uint32_t x);
 
#define port_GetEXT_IRQStatus()             EXTI_GetITEnStatus(DECAIRQ_EXTI_IRQn)
#define port_DisableEXT_IRQ()               NVIC_DisableIRQ(DECAIRQ_EXTI_IRQn)
#define port_EnableEXT_IRQ()                NVIC_EnableIRQ(DECAIRQ_EXTI_IRQn)
#define port_CheckEXT_IRQ()                 GPIO_ReadInputDataBit(DECAIRQ_GPIO, DECAIRQ)
int NVIC_DisableDECAIRQ(void);
 
//define LCD functions
#define port_LCD_Clear(x)                                             0
#define port_LCD_SetBackColor(x)                                     0
#define port_LCD_SetTextColor(x)                                     0
#define port_LCD_DisplayString(line, column, font_index, buffer)     0
int is_IRQ_enabled(void);
 
int is_button_low(uint16_t GPIOpin);
 
#define is_button_high(x)            0
void led_on(led_t led);
void led_off(led_t led);
#define gpio_set(x)                0
#define gpio_reset(x)                0
#define is_gpio_out_low(x)            0
#define is_gpio_out_high(x)            0
 
/*! ------------------------------------------------------------------------------------------------------------------
 * @fn peripherals_init()
 *
 * @brief Initialise all peripherals.
 *
 * @param none
 *
 * @return none
 */
void peripherals_init (void);
 
void SPI_ChangeRate(uint16_t scalingfactor);
void SPI_ConfigFastRate(uint16_t scalingfactor);
 
/*! ------------------------------------------------------------------------------------------------------------------
 * @fn spi_set_rate_low()
 *
 * @brief Set SPI rate to less than 3 MHz to properly perform DW1000 initialisation.
 *
 * @param none
 *
 * @return none
 */
void spi_set_rate_low (void);
 
/*! ------------------------------------------------------------------------------------------------------------------
 * @fn spi_set_rate_high()
 *
 * @brief Set SPI rate as close to 20 MHz as possible for optimum performances.
 *
 * @param none
 *
 * @return none
 */
void spi_set_rate_high (void);
 
unsigned long portGetTickCnt(void);
 
#define portGetTickCount()             portGetTickCnt()
 
void reset_DW1000(void);
void setup_DW1000RSTnIRQ(int enable);
 
#ifdef __cplusplus
}
#endif
 
#endif /* PORT_H_ */