Update platform drivers
src/delay.cpp@9:9e247b9c9abf, 2020-06-15 (annotated)
- Committer:
- EndaKilgarriff
- Date:
- Mon Jun 15 13:03:55 2020 +0000
- Revision:
- 9:9e247b9c9abf
- Parent:
- 8:70fc373a5f46
- Child:
- 10:b5115cd6b916
- Include the following libraries:; - crc; - crc8; - uart; - util; - Add microsecond delay; - Move baud rate definition to mbed_app.json file; - Add bit shift for I2C slave address; - Check error for redefinition; - Make gpio handling more robust;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mahphalke | 8:70fc373a5f46 | 1 | /***************************************************************************//** |
mahphalke | 8:70fc373a5f46 | 2 | * @file delay.cpp |
mahphalke | 8:70fc373a5f46 | 3 | * @brief Implementation of delay functionality |
mahphalke | 8:70fc373a5f46 | 4 | ******************************************************************************** |
mahphalke | 8:70fc373a5f46 | 5 | * Copyright (c) 2019, 2020 Analog Devices, Inc. |
mahphalke | 8:70fc373a5f46 | 6 | * |
mahphalke | 8:70fc373a5f46 | 7 | * All rights reserved. |
mahphalke | 8:70fc373a5f46 | 8 | * |
mahphalke | 8:70fc373a5f46 | 9 | * This software is proprietary to Analog Devices, Inc. and its licensors. |
mahphalke | 8:70fc373a5f46 | 10 | * By using this software you agree to the terms of the associated |
mahphalke | 8:70fc373a5f46 | 11 | * Analog Devices Software License Agreement. |
mahphalke | 8:70fc373a5f46 | 12 | *******************************************************************************/ |
mahphalke | 8:70fc373a5f46 | 13 | |
mahphalke | 8:70fc373a5f46 | 14 | /******************************************************************************/ |
mahphalke | 8:70fc373a5f46 | 15 | /***************************** Include Files **********************************/ |
mahphalke | 8:70fc373a5f46 | 16 | /******************************************************************************/ |
mahphalke | 8:70fc373a5f46 | 17 | |
mahphalke | 8:70fc373a5f46 | 18 | #include <mbed.h> |
mahphalke | 8:70fc373a5f46 | 19 | #include "platform_drivers.h" |
mahphalke | 8:70fc373a5f46 | 20 | |
mahphalke | 8:70fc373a5f46 | 21 | /******************************************************************************/ |
mahphalke | 8:70fc373a5f46 | 22 | /********************** Macros and Constants Definitions **********************/ |
mahphalke | 8:70fc373a5f46 | 23 | /******************************************************************************/ |
mahphalke | 8:70fc373a5f46 | 24 | |
mahphalke | 8:70fc373a5f46 | 25 | /******************************************************************************/ |
mahphalke | 8:70fc373a5f46 | 26 | /************************ Functions Definitions *******************************/ |
mahphalke | 8:70fc373a5f46 | 27 | /******************************************************************************/ |
mahphalke | 8:70fc373a5f46 | 28 | |
mahphalke | 8:70fc373a5f46 | 29 | /** |
mahphalke | 8:70fc373a5f46 | 30 | * @brief Generate microseconds delay. |
mahphalke | 8:70fc373a5f46 | 31 | * @param usecs - Delay in microseconds. |
mahphalke | 8:70fc373a5f46 | 32 | * @return None. |
mahphalke | 8:70fc373a5f46 | 33 | */ |
mahphalke | 8:70fc373a5f46 | 34 | void udelay(uint32_t usecs) |
mahphalke | 8:70fc373a5f46 | 35 | { |
EndaKilgarriff | 9:9e247b9c9abf | 36 | if (usecs < 1000) { |
EndaKilgarriff | 9:9e247b9c9abf | 37 | // Simple delay, minimum time is 1ms. |
EndaKilgarriff | 9:9e247b9c9abf | 38 | HAL_Delay(1); |
EndaKilgarriff | 9:9e247b9c9abf | 39 | } else { |
EndaKilgarriff | 9:9e247b9c9abf | 40 | // This is a simple approach to guarantee a delay |
EndaKilgarriff | 9:9e247b9c9abf | 41 | usecs /= 1000; |
EndaKilgarriff | 9:9e247b9c9abf | 42 | usecs++; // Simple 'ceiling' to round up to guarantee minimum delay |
EndaKilgarriff | 9:9e247b9c9abf | 43 | HAL_Delay(usecs); |
mahphalke | 8:70fc373a5f46 | 44 | } |
mahphalke | 8:70fc373a5f46 | 45 | } |
mahphalke | 8:70fc373a5f46 | 46 | |
mahphalke | 8:70fc373a5f46 | 47 | /** |
mahphalke | 8:70fc373a5f46 | 48 | * @brief Generate miliseconds delay. |
mahphalke | 8:70fc373a5f46 | 49 | * @param msecs - Delay in miliseconds. |
mahphalke | 8:70fc373a5f46 | 50 | * @return None. |
mahphalke | 8:70fc373a5f46 | 51 | */ |
mahphalke | 8:70fc373a5f46 | 52 | void mdelay(uint32_t msecs) |
mahphalke | 8:70fc373a5f46 | 53 | { |
mahphalke | 8:70fc373a5f46 | 54 | if (msecs) { |
mahphalke | 8:70fc373a5f46 | 55 | HAL_Delay(msecs); |
mahphalke | 8:70fc373a5f46 | 56 | } |
mahphalke | 8:70fc373a5f46 | 57 | } |