/*! ---------------------------------------------------------------------------- * @file port.c * @brief HW specific definitions and functions for portability * * @attention * * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland. * * All rights reserved. * * @author DecaWave */ #include "bsp.h" #include "compiler.h" #include "port.h" /** * @brief Checks whether the specified EXTI line is enabled or not. * @param EXTI_Line: specifies the EXTI line to check. * This parameter can be: * @arg EXTI_Linex: External interrupt line x where x(0..19) * @retval The "enable" state of EXTI_Line (SET or RESET). */ ITStatus EXTI_GetITEnStatus(uint32_t EXTI_Line) { ITStatus bitstatus = RESET; uint32_t enablestatus = 0; /* Check the parameters */ assert_param(IS_GET_EXTI_LINE(EXTI_Line)); enablestatus = EXTI->IMR & EXTI_Line; if (enablestatus != (uint32_t)RESET) { bitstatus = SET; } else { bitstatus = RESET; } return bitstatus; } void reset_DW1000(void) { port_SPIx_RST_clear(); Sleep(2); port_SPIx_RST_set(); Sleep(3); } /* * RST irq * When reset, this PIN is pulled down by DW1000, then rising up */ void setup_DW1000RSTnIRQ(int enable) { GPIO_InitTypeDef GPIO_InitStruct; DWM_RST_CLK_ENABLE(); if(enable) //Enable RST irq { GPIO_InitStruct.Pin = DWM_RST_PIN; //MP IRQ polarity is high by default GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; //IRQ pin should be Pull Down to prevent unnecessary EXT IRQ while DW1000 goes to sleep mode GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Alternate = 0; HAL_GPIO_Init(DWM_RST_PORT, &GPIO_InitStruct); HAL_NVIC_SetPriority(DWM_RST_IRQ, DWM_RST_PRIORITY, 0); HAL_NVIC_EnableIRQ(DWM_RST_IRQ); } else { GPIO_InitStruct.Pin = DWM_RST_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN;//Keep pulldown GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Alternate = 0; HAL_GPIO_Init(DWM_RST_PORT, &GPIO_InitStruct); HAL_NVIC_DisableIRQ(DWM_RST_IRQ); } } void setup_DW1000RSTnPin(uint8_t input) { GPIO_InitTypeDef GPIO_InitStruct; DWM_RST_CLK_ENABLE(); GPIO_InitStruct.Pin = DWM_RST_PIN; if(input) { GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; //GPIO_InitStruct.Pull = GPIO_PULLUP; } else { GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; //GPIO_InitStruct.Pull = GPIO_PULLDOWN; //GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Pull = GPIO_NOPULL; } GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Alternate = 0; HAL_GPIO_Init(DWM_RST_PORT, &GPIO_InitStruct); } uint32_t read_DW1000RstnPin(void) { return HAL_GPIO_ReadPin(DWM_RST_PORT, DWM_RST_PIN); } void write_DW1000RstnPin(uint8_t pin) { if(pin) { HAL_GPIO_WritePin(DWM_RST_PORT, DWM_RST_PIN, GPIO_PIN_SET); } else { HAL_GPIO_WritePin(DWM_RST_PORT, DWM_RST_PIN, GPIO_PIN_RESET); } } int is_IRQ_enabled(void) { return (( NVIC->ISER[((uint32_t)(DWM_IRQ_EXTI) >> 5)] & (uint32_t)(0x01 << (DWM_IRQ_EXTI & (uint8_t)0x1F)) ) ? 1 : 0) ; }