port.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*! ----------------------------------------------------------------------------
  2. * @file port.h
  3. * @brief HW specific definitions and functions for portability
  4. *
  5. * @attention
  6. *
  7. * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
  8. *
  9. * All rights reserved.
  10. *
  11. * @author DecaWave
  12. */
  13. #ifndef PORT_H_
  14. #define PORT_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "compiler.h"
  19. #include "deca_types.h"
  20. #include "bsp.h"
  21. #include "utils.h"
  22. //#define USB_SUPPORT
  23. /*****************************************************************************************************************//*
  24. * To enable LDC update (i.e. printing/outputting range result to LCD set this to 1
  25. * NOTE: it takes 3.1 ms to output/write to LCD so this is limiting when performing fast ranging
  26. * (e.g. 6.8 with short slot times - wake up could be 2.25 ms, ranging exchange 1.65 ms and the LCD update 3.1 ms)
  27. */
  28. #define LCD_UPDATE_ON (0)
  29. /*****************************************************************************************************************//*
  30. * To enable Direct Memory Access for SPI set this option to (1)
  31. * This option will increase speed of spi transactions but it will use an extra RAM memory buffer
  32. */
  33. #define DMA_ENABLE (0)
  34. /*****************************************************************************************************************/
  35. #define led_on(x) BSP_LED_On(x)
  36. #define led_off(x) BSP_LED_Off(x)
  37. #define portGetTickCnt() HAL_GetTick()
  38. /**
  39. *
  40. **/
  41. #if (DMA_ENABLE == 1)
  42. #define writetospi writetospi_dma
  43. #define readfromspi readfromspi_dma
  44. void dma_init(void);
  45. #else
  46. extern int32_t writetospi_serial( uint16_t headerLength,
  47. const uint8_t *headerBuffer,
  48. uint32_t bodylength,
  49. const uint8_t *bodyBuffer
  50. );
  51. extern int32_t readfromspi_serial( uint16_t headerLength,
  52. const uint8_t *headerBuffer,
  53. uint32_t readlength,
  54. uint8_t *readBuffer );
  55. #define writetospi writetospi_serial
  56. #define readfromspi readfromspi_serial
  57. #endif
  58. #define port_SPIx_busy_sending() __HAL_SPI_GET_FLAG(&DWM_SpiHandle, SPI_FLAG_TXE)==RESET
  59. #define port_SPIx_no_data() __HAL_SPI_GET_FLAG(&DWM_SpiHandle, SPI_FLAG_RXNE)==RESET
  60. #define port_SPIx_send_data(x) SPI_I2S_SendData(DWM_SpiHandle,(x))
  61. #define port_SPIx_receive_data() SPI_I2S_ReceiveData(DWM_SpiHandle)
  62. #define port_SPIx_disable() __HAL_SPI_DISABLE(&DWM_SpiHandle)
  63. #define port_SPIx_enable() __HAL_SPI_ENABLE(&DWM_SpiHandle)
  64. //#define port_SPIx_set_chip_select() HAL_GPIO_WritePin(DWM_SPIx_CS_GPIO_PORT, BSP_SPIx_CS_PIN, GPIO_PIN_SET)
  65. //#define port_SPIx_clear_chip_select() HAL_GPIO_WritePin(BSP_SPIx_CS_GPIO_PORT, BSP_SPIx_CS_PIN, GPIO_PIN_RESET)
  66. #define port_SPIx_CS_set() HAL_GPIO_WritePin(DWM_SPIx_CS_GPIO_PORT, DWM_SPIx_CS_PIN, GPIO_PIN_SET)
  67. #define port_SPIx_CS_clear() HAL_GPIO_WritePin(DWM_SPIx_CS_GPIO_PORT, DWM_SPIx_CS_PIN, GPIO_PIN_RESET)
  68. #define port_SPIx_RST_set() HAL_GPIO_WritePin(DWM_RST_PORT, DWM_RST_PIN, GPIO_PIN_SET)
  69. #define port_SPIx_RST_clear() HAL_GPIO_WritePin(DWM_RST_PORT, DWM_RST_PIN, GPIO_PIN_RESET)
  70. #define port_SPIx_WAKEUP_set() HAL_GPIO_WritePin(DWM_WAKEUP_PORT, DWM_WAKEUP_PIN, GPIO_PIN_SET)
  71. #define port_SPIx_WAKEUP_clear() HAL_GPIO_WritePin(DWM_WAKEUP_PORT, DWM_WAKEUP_PIN, GPIO_PIN_RESET)
  72. //#define port_GetEXT_IRQStatus() HAL_NVIC_GetPendingIRQ(DWM_IRQ_EXTI)
  73. #define port_GetEXT_IRQStatus() __HAL_GPIO_EXTI_GET_IT(DWM_IRQ_EXTI)
  74. #define port_DisableEXT_IRQ() HAL_NVIC_DisableIRQ(DWM_IRQ_EXTI)
  75. #define port_EnableEXT_IRQ() HAL_NVIC_EnableIRQ(DWM_IRQ_EXTI)
  76. //#define port_CheckEXT_IRQ() HAL_GPIO_ReadPin(DWM_IRQ_PORT, DWM_IRQ_PIN)
  77. #define port_CheckEXT_IRQ() __HAL_GPIO_EXTI_GET_IT(DWM_IRQ_EXTI)
  78. #define Sleep(x) Delay_ms(x)
  79. ITStatus EXTI_GetITEnStatus(uint32_t x);
  80. void __weak process_dwRSTn_irq(void);
  81. void __weak process_deca_irq(void);
  82. void SPI_ChangeRate(uint16_t scalingfactor);
  83. void SPI_ConfigFastRate(uint16_t scalingfactor);
  84. void reset_DW1000(void);
  85. void setup_DW1000RSTnIRQ(int enable);
  86. void setup_DW1000RSTnPin(uint8_t input);
  87. void write_DW1000RstnPin(uint8_t pin);
  88. uint32_t read_DW1000RstnPin(void);
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif /* PORT_H_ */