From d47ebf0ef8f74c8f60e3beec792ddd531fb7ec72 Mon Sep 17 00:00:00 2001 From: guanjiao ren <guanjiao.ren@ninebot.com> Date: 星期一, 21 五月 2018 16:32:41 +0800 Subject: [PATCH] removed unused code --- /dev/null | 49 ------------------------------------------------- 源码/核心板/MDK-ARM/Project.uvoptx | 8 ++++---- 2 files changed, 4 insertions(+), 53 deletions(-) diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/MDK-ARM/Project.uvoptx" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/MDK-ARM/Project.uvoptx" index eb36a35..ef378e0 100644 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/MDK-ARM/Project.uvoptx" +++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/MDK-ARM/Project.uvoptx" @@ -229,7 +229,7 @@ <Group> <GroupName>App</GroupName> - <tvExp>1</tvExp> + <tvExp>0</tvExp> <tvExpOptDlg>0</tvExpOptDlg> <cbSel>0</cbSel> <RteFlg>0</RteFlg> @@ -281,7 +281,7 @@ <Group> <GroupName>decadriver</GroupName> - <tvExp>1</tvExp> + <tvExp>0</tvExp> <tvExpOptDlg>0</tvExpOptDlg> <cbSel>0</cbSel> <RteFlg>0</RteFlg> @@ -289,7 +289,7 @@ <GroupNumber>3</GroupNumber> <FileNumber>4</FileNumber> <FileType>1</FileType> - <tvExp>1</tvExp> + <tvExp>0</tvExp> <tvExpOptDlg>0</tvExpOptDlg> <bDave2>0</bDave2> <PathWithFileName>..\Src\decadriver\deca_device.c</PathWithFileName> @@ -369,7 +369,7 @@ <Group> <GroupName>OnChipDevices</GroupName> - <tvExp>1</tvExp> + <tvExp>0</tvExp> <tvExpOptDlg>0</tvExpOptDlg> <cbSel>0</cbSel> <RteFlg>0</RteFlg> diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/decadriver/deca_types.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/decadriver/deca_types.h" deleted file mode 100644 index 78d8f5f..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/decadriver/deca_types.h" +++ /dev/null @@ -1,72 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @file deca_types.h - * @brief DecaWave general type definitions - * - * @attention - * - * Copyright 2013 (c) DecaWave Ltd, Dublin, Ireland. - * - * All rights reserved. - * - */ - -#ifndef _DECA_TYPES_H_ -#define _DECA_TYPES_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef uint8 -#ifndef _DECA_UINT8_ -#define _DECA_UINT8_ -typedef unsigned char uint8; -#endif -#endif - -#ifndef uint16 -#ifndef _DECA_UINT16_ -#define _DECA_UINT16_ -typedef unsigned short uint16; -#endif -#endif - -#ifndef uint32 -#ifndef _DECA_UINT32_ -#define _DECA_UINT32_ -typedef unsigned long uint32; -#endif -#endif - -#ifndef int8 -#ifndef _DECA_INT8_ -#define _DECA_INT8_ -typedef signed char int8; -#endif -#endif - -#ifndef int16 -#ifndef _DECA_INT16_ -#define _DECA_INT16_ -typedef signed short int16; -#endif -#endif - -#ifndef int32 -#ifndef _DECA_INT32_ -#define _DECA_INT32_ -typedef signed long int32; -#endif -#endif - -#ifndef NULL -#define NULL ((void *)0UL) -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* DECA_TYPES_H_ */ - - diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/decadriver/deca_version.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/decadriver/deca_version.h" deleted file mode 100644 index dda88ce..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/decadriver/deca_version.h" +++ /dev/null @@ -1,32 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @file deca_version.h - * @brief Defines the version info for the DW1000 device driver including its API - * - * @attention - * - * Copyright 2013 (c) DecaWave Ltd, Dublin, Ireland. - * - * All rights reserved. - * - */ - -#ifndef _DECA_VERSION_H_ -#define _DECA_VERSION_H_ - -// -// The DW1000 device driver is separately version numbered to any version the application using it may have -// -// Two symbols are defined here: one hexadecimal value and one string that includes the hex bytes. -// Both should be updated together in a consistent way when the software is being modified. -// -// The format of the hex version is 0xAABBCC and the string ends with AA.BB.CC, where... -// -// Quantity CC is updated for minor changes/bug fixes that should not need user code changes -// Quantity BB is updated for changes/bug fixes that may need user code changes -// Quantity AA is updated for major changes that will need user code changes -// - -#define DW1000_DRIVER_VERSION 0x030001 -#define DW1000_DEVICE_DRIVER_VER_STRING "DW1000 Device Driver Version 03.00.01" - -#endif diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_mutex.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_mutex.c" deleted file mode 100644 index 1c742cc..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_mutex.c" +++ /dev/null @@ -1,83 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @file deca_mutex.c - * @brief IRQ interface / mutex implementation - * - * @attention - * - * Copyright 2013 (c) DecaWave Ltd, Dublin, Ireland. - * - * All rights reserved. - * - */ - -#include "deca_device_api.h" -#include "port.h" -// --------------------------------------------------------------------------- -// -// NB: The purpose of this file is to provide for microprocessor interrupt enable/disable, this is used for -// controlling mutual exclusion from critical sections in the code where interrupts and background -// processing may interact. The code using this is kept to a minimum and the disabling time is also -// kept to a minimum, so blanket interrupt disable may be the easiest way to provide this. But at a -// minimum those interrupts coming from the decawave device should be disabled/re-enabled by this activity. -// -// In porting this to a particular microprocessor, the implementer may choose to use #defines in the -// deca_irq.h include file to map these calls transparently to the target system. Alternatively the -// appropriate code may be embedded in the functions provided below. -// -// This mutex dependent on HW port. -// If HW port uses EXT_IRQ line to receive ready/busy status from DW1000 then mutex should use this signal -// If HW port not use EXT_IRQ line (i.e. SW polling) then no necessary for decamutex(on/off) -// -// For critical section use this mutex instead -// __save_intstate() -// __restore_intstate() -// --------------------------------------------------------------------------- - - -/*! ------------------------------------------------------------------------------------------------------------------ - * 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 = port_GetEXT_IRQStatus(); - - if(s) - { - port_DisableEXT_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 - { - port_EnableEXT_IRQ(); - } -} diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_sleep.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_sleep.c" deleted file mode 100644 index 1f5dd01..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_sleep.c" +++ /dev/null @@ -1,23 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @file deca_sleep.c - * @brief platform dependent sleep implementation - * - * @attention - * - * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland. - * - * All rights reserved. - * - * @author DecaWave - */ - -#include "deca_sleep.h" -#include "port.h" - -void deca_sleep(unsigned int time_ms) -{ - /* This assumes that the tick has a period of exactly one millisecond. See CLOCKS_PER_SEC define. */ - unsigned long end = portGetTickCount() + time_ms; - while ((signed long)(portGetTickCount() - end) <= 0) - ; -} diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_sleep.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_sleep.h" deleted file mode 100644 index df13efb..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_sleep.h" +++ /dev/null @@ -1,35 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @file deca_sleep.h - * @brief platform dependent sleep implementation - * - * @attention - * - * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland. - * - * All rights reserved. - * - * @author DecaWave - */ - -#ifndef _DECA_SLEEP_H_ -#define _DECA_SLEEP_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/*! ------------------------------------------------------------------------------------------------------------------ - * Function: deca_sleep() - * - * Wait for a given amount of time. - * /!\ This implementation is designed for a single threaded application and is blocking. - * - * param time_ms time to wait in milliseconds - */ -void deca_sleep(unsigned int time_ms); - -#ifdef __cplusplus -} -#endif - -#endif /* _DECA_SLEEP_H_ */ diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_spi.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_spi.c" deleted file mode 100644 index d54ac60..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_spi.c" +++ /dev/null @@ -1,164 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @file deca_spi.c - * @brief SPI access functions - * - * @attention - * - * Copyright 2013 (c) DecaWave Ltd, Dublin, Ireland. - * - * All rights reserved. - * - * @author DecaWave - */ -#include <string.h> - -#include "deca_spi.h" -#include "deca_sleep.h" -#include "deca_device_api.h" -#include "port.h" - - -int writetospi_serial( uint16_t headerLength, - const uint8_t *headerBuffer, - uint32_t bodylength, - const uint8_t *bodyBuffer - ); - -int readfromspi_serial( uint16_t headerLength, - const uint8_t *headerBuffer, - uint32_t readlength, - uint8_t *readBuffer ); -/*! ------------------------------------------------------------------------------------------------------------------ - * Function: openspi() - * - * Low level abstract function to open and initialise access to the SPI device. - * returns 0 for success, or -1 for error - */ -int openspi(/*SPI_TypeDef* SPIx*/) -{ - // done by port.c, default SPI used is SPI1 - - return 0; - -} // end openspi() - -/*! ------------------------------------------------------------------------------------------------------------------ - * Function: closespi() - * - * Low level abstract function to close the the SPI device. - * returns 0 for success, or -1 for error - */ -int closespi(void) -{ - while (port_SPIx_busy_sending()); //wait for tx buffer to empty - - port_SPIx_disable(); - - return 0; - -} // end closespi() - -/*! ------------------------------------------------------------------------------------------------------------------ - * Function: writetospi() - * - * Low level abstract function to write to the SPI - * Takes two separate byte buffers for write header and write data - * returns 0 for success, or -1 for error - */ -#pragma GCC optimize ("O3") -int writetospi_serial -( - uint16_t headerLength, - const uint8_t *headerBuffer, - uint32_t bodylength, - const uint8_t *bodyBuffer -) -{ - - int i = 0; - - decaIrqStatus_t stat ; - - stat = decamutexon() ; - - SPIx_CS_GPIO->BRR = SPIx_CS; - - for(i = 0; i < headerLength; i++) - { - SPIx->DR = headerBuffer[i]; - - while ((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); - - SPIx->DR ; - } - - for(i = 0; i < bodylength; i++) - { - SPIx->DR = bodyBuffer[i]; - - while((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); - - SPIx->DR ; - } - - SPIx_CS_GPIO->BSRR = SPIx_CS; - - decamutexoff(stat) ; - - return 0; -} // end writetospi() - - -/*! ------------------------------------------------------------------------------------------------------------------ - * Function: readfromspi() - * - * Low level abstract function to read from the SPI - * Takes two separate byte buffers for write header and read data - * returns the offset into read buffer where first byte of read data may be found, - * or returns -1 if there was an error - */ -#pragma GCC optimize ("O3") -int readfromspi_serial -( - uint16_t headerLength, - const uint8_t *headerBuffer, - uint32_t readlength, - uint8_t *readBuffer -) -{ - - int i = 0; - - decaIrqStatus_t stat ; - - stat = decamutexon() ; - - /* Wait for SPIx Tx buffer empty */ - //while (port_SPIx_busy_sending()); - - SPIx_CS_GPIO->BRR = SPIx_CS; - - for(i = 0; i < headerLength; i++) - { - SPIx->DR = headerBuffer[i]; - - while((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); - - readBuffer[0] = SPIx->DR ; // Dummy read as we write the header - } - - for(i = 0; i < readlength; i++) - { - SPIx->DR = 0; // Dummy write as we read the message body - - while((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); - - readBuffer[i] = SPIx->DR ;//port_SPIx_receive_data(); //this clears RXNE bit - } - - SPIx_CS_GPIO->BSRR = SPIx_CS; - - decamutexoff(stat) ; - - return 0; -} // end readfromspi() diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_spi.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_spi.h" deleted file mode 100644 index ae66879..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/deca_spi.h" +++ /dev/null @@ -1,45 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @file deca_spi.h - * @brief SPI access functions - * - * @attention - * - * Copyright 2013 (c) DecaWave Ltd, Dublin, Ireland. - * - * All rights reserved. - * - * @author DecaWave - */ - -#ifndef _DECA_SPI_H_ -#define _DECA_SPI_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "deca_types.h" - -#define DECA_MAX_SPI_HEADER_LENGTH (3) // max number of bytes in header (for formating & sizing) - -/*! ------------------------------------------------------------------------------------------------------------------ - * Function: openspi() - * - * Low level abstract function to open and initialise access to the SPI device. - * returns 0 for success, or -1 for error - */ -int openspi(void) ; - -/*! ------------------------------------------------------------------------------------------------------------------ - * Function: closespi() - * - * Low level abstract function to close the the SPI device. - * returns 0 for success, or -1 for error - */ -int closespi(void) ; - -#ifdef __cplusplus -} -#endif - -#endif /* _DECA_SPI_H_ */ diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/lcd.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/lcd.c" deleted file mode 100644 index dd56657..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/lcd.c" +++ /dev/null @@ -1,95 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @file lcd.c - * @brief EVB1000 LCD screen access functions - * - * @attention - * - * Copyright 2015 (c) Decawave Ltd, Dublin, Ireland. - * - * All rights reserved. - * - * @author Decawave - */ -#include <string.h> - -#include "deca_sleep.h" -#include "port.h" -#include "lcd.h" - -#if (EVB1000_LCD_SUPPORT == 1) - -void writetoLCD -( - uint32 bodylength, - uint8 rs_enable, - const uint8 *bodyBuffer -) -{ - - int i = 0; - int sleep = 0; - //int j = 10000; - - // if(rs_enable) - // { - // port_LCD_RS_set(); - // } - // else - // { - // if(bodylength == 1) - // { - // if(bodyBuffer[0] & 0x3) //if this is command = 1 or 2 - exsecution time is > 1ms - // sleep = 1 ; - // } - // port_LCD_RS_clear(); - // } - - // port_SPIy_clear_chip_select(); //CS low - - - // //while(j--); //delay - - // for(i=0; i<bodylength; i++) - // { - // port_SPIy_send_data(bodyBuffer[i]); //send data on the SPI - - // while (port_SPIy_no_data()); //wait for rx buffer to fill - - // port_SPIy_receive_data(); //this clears RXNE bit - // } - - // //j = 10000; - - // port_LCD_RS_clear(); - - // //while(j--); //delay - - // port_SPIy_set_chip_select(); //CS high - - // if(sleep) - // deca_sleep(2); -} // end writetoLCD() - -/*! ------------------------------------------------------------------------------------------------------------------ - * @fn lcd_display_str() - * - * @brief Display a string on the LCD screen. - * /!\ The string must be 16 chars long maximum! - * - * @param string the string to display - * - * @return none - */ -void lcd_display_str(const char *string) -{ - uint8 command; - /* Return cursor home and clear screen. */ - // command = 0x2; - // writetoLCD(1, 0, &command); - // command = 0x1; - // writetoLCD(1, 0, &command); - // /* Write the string to display. */ - // writetoLCD(strlen(string), 1, (const uint8 *)string); -} - -#endif diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/lcd.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/lcd.h" deleted file mode 100644 index 90f0421..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/lcd.h" +++ /dev/null @@ -1,63 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @file deca_spi.h - * @brief EVB1000 LCD screen access functions - * - * @attention - * - * Copyright 2015 (c) Decawave Ltd, Dublin, Ireland. - * - * All rights reserved. - * - * @author Decawave - */ - -#ifndef _LCD_H_ -#define _LCD_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "deca_types.h" - -#define EVB1000_LCD_SUPPORT (1) - -#if (EVB1000_LCD_SUPPORT == 1) -/*! ------------------------------------------------------------------------------------------------------------------ - * Function: writetoLCD() - * - * Low level abstract function to write data to the LCD display via SPI2 peripheral - * Takes byte buffer and rs_enable signals - * or returns -1 if there was an error - */ -void writetoLCD -( - uint32 bodylength, - uint8 rs_enable, - const uint8 *bodyBuffer -); -#else -#define writetoLCD(x) -#endif - -#if (EVB1000_LCD_SUPPORT == 1) -/*! ------------------------------------------------------------------------------------------------------------------ - * @fn lcd_display_str() - * - * @brief Display a string on the LCD screen. - * /!\ The string must be 16 chars long maximum! - * - * @param string the string to display - * - * @return none - */ -void lcd_display_str(const char *string); -#else -#define lcd_display_str(x) -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* _LCD_H_ */ diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/port.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/port.c" deleted file mode 100644 index c9b87fc..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/port.c" +++ /dev/null @@ -1,923 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @file port.c - * @brief HW specific definitions and functions for portability - * - * @attention - * - * Copyright 2013 (c) DecaWave Ltd, Dublin, Ireland. - * - * All rights reserved. - * - * @author DecaWave - */ -#include "deca_sleep.h" -#include "lcd.h" -#include "port.h" - -#define rcc_init(x) RCC_Configuration(x) -#define systick_init(x) SysTick_Configuration(x) -#define rtc_init(x) RTC_Configuration(x) -#define interrupt_init(x) NVIC_Configuration(x) -#define usart_init(x) USART_Configuration(x) -#define spi_init(x) SPI_Configuration(x) -#define gpio_init(x) GPIO_Configuration(x) -#define ethernet_init(x) No_Configuration(x) -#define fs_init(x) No_Configuration(x) -#define usb_init(x) No_Configuration(x) -#define lcd_init(x) LCD_Configuration(x) -#define touch_screen_init(x) No_Configuration(x) - -/* System tick 32 bit variable defined by the platform */ -extern __IO unsigned long time32_incr; - -/* Internal functions prototypes. */ -static void LCD_Configuration(void); -static void spi_peripheral_init(void); - -int No_Configuration(void) -{ - return -1; -} - -unsigned long portGetTickCnt(void) -{ - return time32_incr; -} - -int SysTick_Configuration(void) -{ - if (SysTick_Config(SystemCoreClock / CLOCKS_PER_SEC)) - { - /* Capture error */ - while (1); - } - NVIC_SetPriority (SysTick_IRQn, 5); - - return 0; -} - -void RTC_Configuration(void) -{ - /* Enable PWR and BKP clocks */ - RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); - - /* Allow access to BKP Domain */ - PWR_BackupAccessCmd(ENABLE); - - /* Reset Backup Domain */ - BKP_DeInit(); - - /* Enable LSE */ - RCC_LSEConfig(RCC_LSE_ON); - /* Wait till LSE is ready */ - while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {} - - /* Select LSE as RTC Clock Source */ - RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); - - /* Enable RTC Clock */ - RCC_RTCCLKCmd(ENABLE); - - /* Wait for RTC registers synchronization */ - RTC_WaitForSynchro(); - - /* Wait until last write operation on RTC registers has finished */ - RTC_WaitForLastTask(); - - /* Enable the RTC Second */ - RTC_ITConfig(RTC_IT_SEC, ENABLE); - - /* Wait until last write operation on RTC registers has finished */ - RTC_WaitForLastTask(); - - /* Set RTC prescaler: set RTC period to 1sec */ - RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ - - /* Wait until last write operation on RTC registers has finished */ - RTC_WaitForLastTask(); -} - - -int NVIC_DisableDECAIRQ(void) -{ - EXTI_InitTypeDef EXTI_InitStructure; - - /* 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 = DECAIRQ_EXTI_NOIRQ; - EXTI_Init(&EXTI_InitStructure); - - return 0; -} - - -int NVIC_Configuration(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - EXTI_InitTypeDef EXTI_InitStructure; - NVIC_InitTypeDef NVIC_InitStructure; - - // Enable GPIO used as DECA IRQ for interrupt - GPIO_InitStructure.GPIO_Pin = DECAIRQ; - 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_Init(DECAIRQ_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 = DECAIRQ_EXTI_USEIRQ; - EXTI_Init(&EXTI_InitStructure); - - /* Set NVIC Grouping to 16 groups of interrupt without sub-grouping */ - NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); - - /* Enable and set EXTI Interrupt to the lowest priority */ - NVIC_InitStructure.NVIC_IRQChannel = DECAIRQ_EXTI_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelCmd = DECAIRQ_EXTI_USEIRQ; - - NVIC_Init(&NVIC_InitStructure); - - /* Enable the RTC Interrupt */ - //NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; - //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 10; - //NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; - //NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - - //NVIC_Init(&NVIC_InitStructure); - - return 0; -} - -/** - * @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; -} - -int RCC_Configuration(void) -{ - ErrorStatus HSEStartUpStatus; - RCC_ClocksTypeDef RCC_ClockFreq; - - /* Set HSION bit */ - RCC->CR |= (uint32_t)0x00000001; - - // select HSI as PLL source - RCC->CFGR |= (uint32_t)RCC_CFGR_PLLSRC_HSI_Div2; - - //PLLCLK=8/2*12=48M - RCC->CFGR |= (uint32_t)RCC_CFGR_PLLMULL9; - - /* HCLK = SYSCLK/1 */ - RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1; - - /* Enable PLL */ - RCC->CR |= RCC_CR_PLLON; - - /* Wait till PLL is ready */ - while((RCC->CR & RCC_CR_PLLRDY) == 0) - { - } - /* Select PLL as system clock source */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); - RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL; - - /* Wait till PLL is used as system clock source */ - while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) - { - } - SystemCoreClockUpdate(); - RCC_GetClocksFreq(&RCC_ClockFreq); - - /* Enable SPI1 clock */ - RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); - - /* Enable SPI2 clock */ - RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); - - /* Enable GPIOs clocks */ - RCC_APB2PeriphClockCmd( - RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | - RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | - RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, - ENABLE); - - return 0; -} - -void usartinit(void) -{ - USART_InitTypeDef USART_InitStructure; - GPIO_InitTypeDef GPIO_InitStructure; - - /* USARTx configured as follow: - - BaudRate = 115200 baud - - Word Length = 8 Bits - - One Stop Bit - - No parity - - Hardware flow control disabled (RTS and CTS signals) - - Receive and transmit enabled - */ - USART_InitStructure.USART_BaudRate = 115200 ; - USART_InitStructure.USART_WordLength = USART_WordLength_8b; - USART_InitStructure.USART_StopBits = USART_StopBits_1; - USART_InitStructure.USART_Parity = USART_Parity_No; - USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; - - /* Enable GPIO clock */ - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); - - //For EVB1000 -> USART2_REMAP = 0 - - /* Enable the USART2 Pins Software Remapping */ - - RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); - - - /* Configure USART Tx as alternate function push-pull */ - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* Configure USART Rx as input floating */ - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* USART configuration */ - USART_Init(USART1, &USART_InitStructure); - - /* Enable USART */ - USART_Cmd(USART1, ENABLE); -} - -void SPI_ChangeRate(uint16_t scalingfactor) -{ - uint16_t tmpreg = 0; - - /* Get the SPIx CR1 value */ - tmpreg = SPIx->CR1; - - /*clear the scaling bits*/ - tmpreg &= 0xFFC7; - - /*set the scaling bits*/ - tmpreg |= scalingfactor; - - /* Write to SPIx CR1 */ - SPIx->CR1 = tmpreg; -} - -/*! ------------------------------------------------------------------------------------------------------------------ - * @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) -{ - SPI_ChangeRate(SPI_BaudRatePrescaler_32); -} - -/*! ------------------------------------------------------------------------------------------------------------------ - * @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) -{ - SPI_ChangeRate(SPI_BaudRatePrescaler_16); -} - -void SPI_ConfigFastRate(uint16_t scalingfactor) -{ - SPI_InitTypeDef SPI_InitStructure; - - SPI_I2S_DeInit(SPIx); - - // SPIx Mode setup - SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; - SPI_InitStructure.SPI_Mode = SPI_Mode_Master; - SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; - SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; // - //SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; // - SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; - //SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // - //SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; - SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; - SPI_InitStructure.SPI_BaudRatePrescaler = scalingfactor; //sets BR[2:0] bits - baudrate in SPI_CR1 reg bits 4-6 - SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; - SPI_InitStructure.SPI_CRCPolynomial = 7; - - SPI_Init(SPIx, &SPI_InitStructure); - - // Enable SPIx - SPI_Cmd(SPIx, ENABLE); -} - -int SPI_Configuration(void) -{ - SPI_InitTypeDef SPI_InitStructure; - GPIO_InitTypeDef GPIO_InitStructure; - - SPI_I2S_DeInit(SPIx); - - // SPIx Mode setup - SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; - SPI_InitStructure.SPI_Mode = SPI_Mode_Master; - SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; - SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; // - //SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; // - SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; - //SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // - //SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; - SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; - //SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; //sets BR[2:0] bits - baudrate in SPI_CR1 reg bits 4-6 - SPI_InitStructure.SPI_BaudRatePrescaler = SPIx_PRESCALER; - SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; - SPI_InitStructure.SPI_CRCPolynomial = 7; - - SPI_Init(SPIx, &SPI_InitStructure); - - // SPIx SCK and MOSI pin setup - GPIO_InitStructure.GPIO_Pin = SPIx_SCK | SPIx_MOSI; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - - GPIO_Init(SPIx_GPIO, &GPIO_InitStructure); - - // SPIx MISO pin setup - GPIO_InitStructure.GPIO_Pin = SPIx_MISO; - //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; - - GPIO_Init(SPIx_GPIO, &GPIO_InitStructure); - - // SPIx CS pin setup - GPIO_InitStructure.GPIO_Pin = SPIx_CS; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - - GPIO_Init(SPIx_CS_GPIO, &GPIO_InitStructure); - - // Disable SPIx SS Output - SPI_SSOutputCmd(SPIx, DISABLE); - - // Enable SPIx - SPI_Cmd(SPIx, ENABLE); - - // Set CS high - GPIO_SetBits(SPIx_CS_GPIO, SPIx_CS); - - return 0; -} - - -int SPI2_Configuration(void) -{ - SPI_InitTypeDef SPI_InitStructure; - GPIO_InitTypeDef GPIO_InitStructure; - - SPI_I2S_DeInit(SPIy); - - // SPIy Mode setup - //SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; - SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; - SPI_InitStructure.SPI_Mode = SPI_Mode_Master; - SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; - //SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; // - SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; // - //SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; - SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // - //SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; - SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; - SPI_InitStructure.SPI_BaudRatePrescaler = SPIy_PRESCALER; - SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; - SPI_InitStructure.SPI_CRCPolynomial = 7; - - SPI_Init(SPIy, &SPI_InitStructure); - - // SPIy SCK and MOSI pin setup - GPIO_InitStructure.GPIO_Pin = SPIy_SCK | SPIy_MOSI; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - - GPIO_Init(SPIy_GPIO, &GPIO_InitStructure); - - // SPIy MISO pin setup - GPIO_InitStructure.GPIO_Pin = SPIy_MISO; - //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; - - GPIO_Init(SPIy_GPIO, &GPIO_InitStructure); - - // SPIy CS pin setup - GPIO_InitStructure.GPIO_Pin = SPIy_CS; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - - GPIO_Init(SPIy_CS_GPIO, &GPIO_InitStructure); - - // Disable SPIy SS Output - SPI_SSOutputCmd(SPIy, DISABLE); - - // Enable SPIy - SPI_Cmd(SPIy, ENABLE); - - // Set CS high - GPIO_SetBits(SPIy_CS_GPIO, SPIy_CS); - - // LCD_RS pin setup - GPIO_InitStructure.GPIO_Pin = LCD_RS; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - - GPIO_Init(SPIy_GPIO, &GPIO_InitStructure); - - // LCD_RW pin setup - GPIO_InitStructure.GPIO_Pin = LCD_RW; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - - GPIO_Init(SPIy_GPIO, &GPIO_InitStructure); - - return 0; -} -//#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 SW8 GPIO_Pin_8 -uint8_t Work_Mode; -extern uint8_t TAG_ID, ANCHOR_ID; -int GPIO_Configuration(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - - /* Configure all unused GPIO port pins in Analog Input mode (floating input - * trigger OFF), this will reduce the power consumption and increase the device - * immunity against EMI/EMC */ - - // Enable GPIOs clocks - RCC_APB2PeriphClockCmd( - RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | - RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, - ENABLE); - - // Set all GPIO pins as analog inputs - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; - GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_Init(GPIOB, &GPIO_InitStructure); - GPIO_Init(GPIOC, &GPIO_InitStructure); - - GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); - //Enable GPIO used for User button - GPIO_InitStructure.GPIO_Pin = TA_BOOT1; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_Init(TA_BOOT1_GPIO, &GPIO_InitStructure); - - //Enable GPIO used for Response Delay setting - - GPIO_InitStructure.GPIO_Pin = SW1 | SW2; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - GPIO_InitStructure.GPIO_Pin = SW3 | SW4 | SW5 | SW6 | SW7 | SW8; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; - GPIO_Init(GPIOB, &GPIO_InitStructure); - - GPIO_InitStructure.GPIO_Pin = LED_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - if (GPIO_ReadInputDataBit(GPIOA, SW1) == RESET) - { - Work_Mode = 0;//TX - GPIO_Toggle(GPIOA, LED_PIN); - } - else - { - Work_Mode = 1; //RX - } - TAG_ID = 0; - if(GPIO_ReadInputDataBit(GPIOB, SW6) == RESET) - { - TAG_ID |= 1 << 2; - } - if(GPIO_ReadInputDataBit(GPIOB, SW7) == RESET) - { - TAG_ID |= 1 << 1; - } - if(GPIO_ReadInputDataBit(GPIOB, SW8) == RESET) - { - TAG_ID |= 1; - } - - if(GPIO_ReadInputDataBit(GPIOB, SW3) == RESET) - { - ANCHOR_ID |= 1 << 2; - } - if(GPIO_ReadInputDataBit(GPIOB, SW4) == RESET) - { - ANCHOR_ID |= 1 << 1; - } - if(GPIO_ReadInputDataBit(GPIOB, SW5) == RESET) - { - ANCHOR_ID |= 1; - } - - // Disable GPIOs clocks - //RCC_APB2PeriphClockCmd( - // RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | - // RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | - // RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, - // DISABLE); - - // Enable GPIO used for LEDs - - - return 0; -} - - -void reset_DW1000(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - - // Enable GPIO used for DW1000 reset - GPIO_InitStructure.GPIO_Pin = DW1000_RSTn; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(DW1000_RSTn_GPIO, &GPIO_InitStructure); - - //drive the RSTn pin low - GPIO_ResetBits(DW1000_RSTn_GPIO, DW1000_RSTn); - - //put the pin back to tri-state ... as input - GPIO_InitStructure.GPIO_Pin = DW1000_RSTn; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(DW1000_RSTn_GPIO, &GPIO_InitStructure); - - deca_sleep(2); -} - - -void setup_DW1000RSTnIRQ(int enable) -{ - GPIO_InitTypeDef GPIO_InitStructure; - EXTI_InitTypeDef EXTI_InitStructure; - NVIC_InitTypeDef NVIC_InitStructure; - - if(enable) - { - // Enable GPIO used as DECA IRQ for interrupt - GPIO_InitStructure.GPIO_Pin = DECARSTIRQ; - //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_Mode = GPIO_Mode_IN_FLOATING; - GPIO_Init(DECARSTIRQ_GPIO, &GPIO_InitStructure); - - /* Connect EXTI Line to GPIO Pin */ - GPIO_EXTILineConfig(DECARSTIRQ_EXTI_PORT, DECARSTIRQ_EXTI_PIN); - - /* Configure EXTI line */ - EXTI_InitStructure.EXTI_Line = DECARSTIRQ_EXTI; - EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; - EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //MP IRQ polarity is high by default - EXTI_InitStructure.EXTI_LineCmd = ENABLE; - EXTI_Init(&EXTI_InitStructure); - - /* Set NVIC Grouping to 16 groups of interrupt without sub-grouping */ - NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); - - /* Enable and set EXTI Interrupt to the lowest priority */ - NVIC_InitStructure.NVIC_IRQChannel = DECARSTIRQ_EXTI_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - - NVIC_Init(&NVIC_InitStructure); - } - else - { - //put the pin back to tri-state ... as input - GPIO_InitStructure.GPIO_Pin = DW1000_RSTn; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(DW1000_RSTn_GPIO, &GPIO_InitStructure); - - /* Configure EXTI line */ - EXTI_InitStructure.EXTI_Line = DECARSTIRQ_EXTI; - EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; - EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //MP IRQ polarity is high by default - EXTI_InitStructure.EXTI_LineCmd = DISABLE; - EXTI_Init(&EXTI_InitStructure); - } -} - - -int ETH_GPIOConfigure(void) -{ -#if 0 - GPIO_InitTypeDef GPIO_InitStructure; - - /* ETHERNET pins configuration */ - /* AF Output Push Pull: - - ETH_MII_MDIO / ETH_RMII_MDIO: PA2 - - ETH_MII_MDC / ETH_RMII_MDC: PC1 - - ETH_MII_TXD2: PC2 - - ETH_MII_TX_EN / ETH_RMII_TX_EN: PB11 - - ETH_MII_TXD0 / ETH_RMII_TXD0: PB12 - - ETH_MII_TXD1 / ETH_RMII_TXD1: PB13 - - ETH_MII_PPS_OUT / ETH_RMII_PPS_OUT: PB5 - - ETH_MII_TXD3: PB8 */ - - /* Configure PA2 as alternate function push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* Configure PC1 and PC2 as alternate function push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; - GPIO_Init(GPIOC, &GPIO_InitStructure); - - /* Configure PB5, PB8, PB11, PB12 and PB13 as alternate function push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_11 | - GPIO_Pin_12 | GPIO_Pin_13; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; - GPIO_Init(GPIOB, &GPIO_InitStructure); - - /**************************************************************/ - /* For Remapped Ethernet pins */ - /*************************************************************/ - /* Input (Reset Value): - - ETH_MII_CRS CRS: PA0 - - ETH_MII_RX_CLK / ETH_RMII_REF_CLK: PA1 - - ETH_MII_COL: PA3 - - ETH_MII_RX_DV / ETH_RMII_CRS_DV: PD8 - - ETH_MII_TX_CLK: PC3 - - ETH_MII_RXD0 / ETH_RMII_RXD0: PD9 - - ETH_MII_RXD1 / ETH_RMII_RXD1: PD10 - - ETH_MII_RXD2: PD11 - - ETH_MII_RXD3: PD12 - - ETH_MII_RX_ER: PB10 */ - - /* Configure PA0, PA1 and PA3 as input */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* Configure PB10 as input */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_Init(GPIOB, &GPIO_InitStructure); - - /* Configure PC3 as input */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_Init(GPIOC, &GPIO_InitStructure); - - /* Configure PD8, PD9, PD10, PD11 and PD12 as input */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_Init(GPIOD, &GPIO_InitStructure); /**/ - - - - /* MCO pin configuration------------------------------------------------- */ - /* Configure MCO (PA8) as alternate function push-pull */ - //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; - //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; - //GPIO_Init(GPIOA, &GPIO_InitStructure); -#endif - - return 0; -} - -int is_button_low(uint16_t GPIOpin) -{ - int result = 1; - - if (GPIO_ReadInputDataBit(TA_BOOT1_GPIO, TA_BOOT1)) - result = 0; - - return result; -} - -//when switch (S1) is 'on' the pin is low -int is_switch_on(uint16_t GPIOpin) -{ - int result = 1; - - if (GPIO_ReadInputDataBit(TA_SW1_GPIO, GPIOpin)) - result = 0; - - return result; -} - - -void led_off (led_t led) -{ - switch (led) - { - case LED_PC6: - GPIO_ResetBits(GPIOC, GPIO_Pin_6); - break; - case LED_PC7: - GPIO_ResetBits(GPIOC, GPIO_Pin_7); - break; - case LED_PC8: - GPIO_ResetBits(GPIOC, GPIO_Pin_8); - break; - case LED_PC9: - GPIO_ResetBits(GPIOC, GPIO_Pin_9); - break; - case LED_ALL: - GPIO_ResetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_6 | GPIO_Pin_7); - break; - default: - // do nothing for undefined led number - break; - } -} - -void led_on (led_t led) -{ - switch (led) - { - case LED_PC6: - GPIO_SetBits(GPIOC, GPIO_Pin_6); - break; - case LED_PC7: - GPIO_SetBits(GPIOC, GPIO_Pin_7); - break; - case LED_PC8: - GPIO_SetBits(GPIOC, GPIO_Pin_8); - break; - case LED_PC9: - GPIO_SetBits(GPIOC, GPIO_Pin_9); - break; - case LED_ALL: - GPIO_SetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_6 | GPIO_Pin_7); - break; - default: - // do nothing for undefined led number - break; - } -} - -#ifdef USART_SUPPORT - -/** - * @brief Configures COM port. - * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that - * contains the configuration information for the specified USART peripheral. - * @retval None - */ - - - - -//#include <stdio.h> -//#include <stdarg.h> -//#include <stdlib.h> -//void printf2(const char *format, ...) -//{ -// va_list list; -// va_start(list, format); - -// int len = vsnprintf(0, 0, format, list); -// char *s; - -// s = (char *)malloc(len + 1); -// vsprintf(s, format, list); - -// USART_puts(s); - -// free(s); -// va_end(list); -// return; -//} - - -#endif - - -int is_IRQ_enabled(void) -{ - return (( NVIC->ISER[((uint32_t)(DECAIRQ_EXTI_IRQn) >> 5)] - & (uint32_t)0x01 << (DECAIRQ_EXTI_IRQn & (uint8_t)0x1F) ) ? 1 : 0) ; -} - -/*! ------------------------------------------------------------------------------------------------------------------ - * @fn LCD_configuration() - * - * @brief Initialise LCD screen. - * - * @param none - * - * @return none - */ -static void LCD_Configuration(void) -{ - unsigned char initseq[9] = { 0x39, 0x14, 0x55, 0x6D, 0x78, 0x38, 0x0C, 0x01, 0x06 }; - unsigned char command = 0x0; - - // Write initialisation sequence. - writetoLCD(9, 0, initseq); - deca_sleep(10); - - // Return cursor home and clear screen. - command = 0x2; - writetoLCD(1, 0, &command); - command = 0x1; - writetoLCD(1, 0, &command); -} - -/*! ------------------------------------------------------------------------------------------------------------------ - * @fn spi_peripheral_init() - * - * @brief Initialise all SPI peripherals at once. - * - * @param none - * - * @return none - */ -static void spi_peripheral_init(void) -{ - spi_init(); - - // Initialise SPI2 peripheral for LCD contro - - // Wait for LCD to power on. - deca_sleep(10); -} - -/*! ------------------------------------------------------------------------------------------------------------------ - * @fn peripherals_init() - * - * @brief Initialise all peripherals. - * - * @param none - * - * @return none - */ -void peripherals_init (void) -{ - rcc_init(); - gpio_init(); - systick_init(); - spi_peripheral_init(); - usartinit(); -} diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/port.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/port.h" deleted file mode 100644 index 65d24cc..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/port.h" +++ /dev/null @@ -1,235 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @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_ */ diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/syscalls.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/syscalls.c" deleted file mode 100644 index d5576f4..0000000 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/platform/syscalls.c" +++ /dev/null @@ -1,49 +0,0 @@ -/*! ---------------------------------------------------------------------------- - * @file syscalls.c - * @brief Standard syscalls platform-specific implementation - * - * @attention - * - * Copyright 2015 (c) Decawave Ltd, Dublin, Ireland. - * - * All rights reserved. - * - * @author Decawave - */ -#include <sys/types.h> -#include "port.h" - -/*! ------------------------------------------------------------------------------------------------------------------ - * @fn _sbrk() - * - * @brief Increment heap pointer to allow dynamic memory allocation. - * - * @param incr size of the heap increment to perform, in bytes - * - * @return pointer on the previous heap end or -1 if memory is full and increment cannot be performed. - */ -caddr_t _sbrk(int incr) -{ - extern char _ebss; /* Defined by the linker. */ - static char *heap_end; - char *prev_heap_end; - char *stack; - - if (heap_end == 0) - { - heap_end = &_ebss; - } - - prev_heap_end = heap_end; - - stack = (char *) port_GET_stack_pointer(); - - if (heap_end + incr > stack) - { - return (caddr_t) - 1; - } - - heap_end += incr; - - return (caddr_t) prev_heap_end; -} -- Gitblit v1.9.3