![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/targets/TARGET_Atmel/TARGET_SAM_CortexM4/services/delay/sam/cycle_counter.h@3:f3764f852aa8, 2018-10-11 (annotated)
- Committer:
- kadonotakashi
- Date:
- Thu Oct 11 02:27:46 2018 +0000
- Revision:
- 3:f3764f852aa8
- Parent:
- 0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /** |
kadonotakashi | 0:8fdf9a60065b | 2 | * \file |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * \brief ARM functions for busy-wait delay loops |
kadonotakashi | 0:8fdf9a60065b | 5 | * |
kadonotakashi | 0:8fdf9a60065b | 6 | * Copyright (c) 2014-2015 Atmel Corporation. All rights reserved. |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * \asf_license_start |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * \page License |
kadonotakashi | 0:8fdf9a60065b | 11 | * |
kadonotakashi | 0:8fdf9a60065b | 12 | * Redistribution and use in source and binary forms, with or without |
kadonotakashi | 0:8fdf9a60065b | 13 | * modification, are permitted provided that the following conditions are met: |
kadonotakashi | 0:8fdf9a60065b | 14 | * |
kadonotakashi | 0:8fdf9a60065b | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
kadonotakashi | 0:8fdf9a60065b | 16 | * this list of conditions and the following disclaimer. |
kadonotakashi | 0:8fdf9a60065b | 17 | * |
kadonotakashi | 0:8fdf9a60065b | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
kadonotakashi | 0:8fdf9a60065b | 19 | * this list of conditions and the following disclaimer in the documentation |
kadonotakashi | 0:8fdf9a60065b | 20 | * and/or other materials provided with the distribution. |
kadonotakashi | 0:8fdf9a60065b | 21 | * |
kadonotakashi | 0:8fdf9a60065b | 22 | * 3. The name of Atmel may not be used to endorse or promote products derived |
kadonotakashi | 0:8fdf9a60065b | 23 | * from this software without specific prior written permission. |
kadonotakashi | 0:8fdf9a60065b | 24 | * |
kadonotakashi | 0:8fdf9a60065b | 25 | * 4. This software may only be redistributed and used in connection with an |
kadonotakashi | 0:8fdf9a60065b | 26 | * Atmel microcontroller product. |
kadonotakashi | 0:8fdf9a60065b | 27 | * |
kadonotakashi | 0:8fdf9a60065b | 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED |
kadonotakashi | 0:8fdf9a60065b | 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
kadonotakashi | 0:8fdf9a60065b | 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
kadonotakashi | 0:8fdf9a60065b | 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR |
kadonotakashi | 0:8fdf9a60065b | 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
kadonotakashi | 0:8fdf9a60065b | 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
kadonotakashi | 0:8fdf9a60065b | 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
kadonotakashi | 0:8fdf9a60065b | 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
kadonotakashi | 0:8fdf9a60065b | 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
kadonotakashi | 0:8fdf9a60065b | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
kadonotakashi | 0:8fdf9a60065b | 38 | * POSSIBILITY OF SUCH DAMAGE. |
kadonotakashi | 0:8fdf9a60065b | 39 | * |
kadonotakashi | 0:8fdf9a60065b | 40 | * \asf_license_stop |
kadonotakashi | 0:8fdf9a60065b | 41 | * |
kadonotakashi | 0:8fdf9a60065b | 42 | */ |
kadonotakashi | 0:8fdf9a60065b | 43 | /* |
kadonotakashi | 0:8fdf9a60065b | 44 | * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> |
kadonotakashi | 0:8fdf9a60065b | 45 | */ |
kadonotakashi | 0:8fdf9a60065b | 46 | #ifndef _cycle_counter_h_ |
kadonotakashi | 0:8fdf9a60065b | 47 | #define _cycle_counter_h_ |
kadonotakashi | 0:8fdf9a60065b | 48 | |
kadonotakashi | 0:8fdf9a60065b | 49 | #ifdef __cplusplus |
kadonotakashi | 0:8fdf9a60065b | 50 | extern "C" { |
kadonotakashi | 0:8fdf9a60065b | 51 | #endif |
kadonotakashi | 0:8fdf9a60065b | 52 | |
kadonotakashi | 0:8fdf9a60065b | 53 | |
kadonotakashi | 0:8fdf9a60065b | 54 | #include <compiler.h> |
kadonotakashi | 0:8fdf9a60065b | 55 | |
kadonotakashi | 0:8fdf9a60065b | 56 | /** |
kadonotakashi | 0:8fdf9a60065b | 57 | * @name Convenience functions for busy-wait delay loops |
kadonotakashi | 0:8fdf9a60065b | 58 | * |
kadonotakashi | 0:8fdf9a60065b | 59 | * @def delay_cycles |
kadonotakashi | 0:8fdf9a60065b | 60 | * @brief Delay program execution for a specified number of CPU cycles. |
kadonotakashi | 0:8fdf9a60065b | 61 | * @param n number of CPU cycles to wait |
kadonotakashi | 0:8fdf9a60065b | 62 | * |
kadonotakashi | 0:8fdf9a60065b | 63 | * @def cpu_delay_ms |
kadonotakashi | 0:8fdf9a60065b | 64 | * @brief Delay program execution for a specified number of milliseconds. |
kadonotakashi | 0:8fdf9a60065b | 65 | * @param delay number of milliseconds to wait |
kadonotakashi | 0:8fdf9a60065b | 66 | * @param f_cpu CPU frequency in Hertz |
kadonotakashi | 0:8fdf9a60065b | 67 | * |
kadonotakashi | 0:8fdf9a60065b | 68 | * @def cpu_delay_us |
kadonotakashi | 0:8fdf9a60065b | 69 | * @brief Delay program execution for a specified number of microseconds. |
kadonotakashi | 0:8fdf9a60065b | 70 | * @param delay number of microseconds to wait |
kadonotakashi | 0:8fdf9a60065b | 71 | * @param f_cpu CPU frequency in Hertz |
kadonotakashi | 0:8fdf9a60065b | 72 | * |
kadonotakashi | 0:8fdf9a60065b | 73 | * @def cpu_ms_2_cy |
kadonotakashi | 0:8fdf9a60065b | 74 | * @brief Convert milli-seconds into CPU cycles. |
kadonotakashi | 0:8fdf9a60065b | 75 | * @param ms number of milliseconds |
kadonotakashi | 0:8fdf9a60065b | 76 | * @param f_cpu CPU frequency in Hertz |
kadonotakashi | 0:8fdf9a60065b | 77 | * @return the converted number of CPU cycles |
kadonotakashi | 0:8fdf9a60065b | 78 | * |
kadonotakashi | 0:8fdf9a60065b | 79 | * @def cpu_us_2_cy |
kadonotakashi | 0:8fdf9a60065b | 80 | * @brief Convert micro-seconds into CPU cycles. |
kadonotakashi | 0:8fdf9a60065b | 81 | * @param ms number of microseconds |
kadonotakashi | 0:8fdf9a60065b | 82 | * @param f_cpu CPU frequency in Hertz |
kadonotakashi | 0:8fdf9a60065b | 83 | * @return the converted number of CPU cycles |
kadonotakashi | 0:8fdf9a60065b | 84 | * |
kadonotakashi | 0:8fdf9a60065b | 85 | * @{ |
kadonotakashi | 0:8fdf9a60065b | 86 | */ |
kadonotakashi | 0:8fdf9a60065b | 87 | |
kadonotakashi | 0:8fdf9a60065b | 88 | /** |
kadonotakashi | 0:8fdf9a60065b | 89 | * \brief Delay loop to delay n number of cycles |
kadonotakashi | 0:8fdf9a60065b | 90 | * |
kadonotakashi | 0:8fdf9a60065b | 91 | * \note The function runs in internal RAM so that flash wait states |
kadonotakashi | 0:8fdf9a60065b | 92 | * will not affect the delay time. |
kadonotakashi | 0:8fdf9a60065b | 93 | * |
kadonotakashi | 0:8fdf9a60065b | 94 | * \param n Number of cycles |
kadonotakashi | 0:8fdf9a60065b | 95 | */ |
kadonotakashi | 0:8fdf9a60065b | 96 | void portable_delay_cycles(unsigned long n); |
kadonotakashi | 0:8fdf9a60065b | 97 | |
kadonotakashi | 0:8fdf9a60065b | 98 | /* Cortex-M7 is faster than Cortex-M3/M4/M0+ */ |
kadonotakashi | 0:8fdf9a60065b | 99 | #ifdef __CM7_REV |
kadonotakashi | 0:8fdf9a60065b | 100 | |
kadonotakashi | 0:8fdf9a60065b | 101 | # define cpu_ms_2_cy(ms, f_cpu) \ |
kadonotakashi | 0:8fdf9a60065b | 102 | (((uint64_t)(ms) * (f_cpu) + (uint64_t)(5.932e3 - 1ul)) / (uint64_t)5.932e3) |
kadonotakashi | 0:8fdf9a60065b | 103 | # define cpu_us_2_cy(us, f_cpu) \ |
kadonotakashi | 0:8fdf9a60065b | 104 | (((uint64_t)(us) * (f_cpu) + (uint64_t)(5.932e6 - 1ul)) / (uint64_t)5.932e6) |
kadonotakashi | 0:8fdf9a60065b | 105 | |
kadonotakashi | 0:8fdf9a60065b | 106 | #else |
kadonotakashi | 0:8fdf9a60065b | 107 | |
kadonotakashi | 0:8fdf9a60065b | 108 | # define cpu_ms_2_cy(ms, f_cpu) \ |
kadonotakashi | 0:8fdf9a60065b | 109 | (((uint64_t)(ms) * (f_cpu) + (uint64_t)(14e3 - 1ul)) / (uint64_t)14e3) |
kadonotakashi | 0:8fdf9a60065b | 110 | # define cpu_us_2_cy(us, f_cpu) \ |
kadonotakashi | 0:8fdf9a60065b | 111 | (((uint64_t)(us) * (f_cpu) + (uint64_t)(14e6 - 1ul)) / (uint64_t)14e6) |
kadonotakashi | 0:8fdf9a60065b | 112 | |
kadonotakashi | 0:8fdf9a60065b | 113 | #endif |
kadonotakashi | 0:8fdf9a60065b | 114 | |
kadonotakashi | 0:8fdf9a60065b | 115 | #define delay_cycles portable_delay_cycles |
kadonotakashi | 0:8fdf9a60065b | 116 | |
kadonotakashi | 0:8fdf9a60065b | 117 | #define cpu_delay_ms(delay, f_cpu) delay_cycles(cpu_ms_2_cy(delay, f_cpu)) |
kadonotakashi | 0:8fdf9a60065b | 118 | #define cpu_delay_us(delay, f_cpu) delay_cycles(cpu_us_2_cy(delay, f_cpu)) |
kadonotakashi | 0:8fdf9a60065b | 119 | //! @} |
kadonotakashi | 0:8fdf9a60065b | 120 | |
kadonotakashi | 0:8fdf9a60065b | 121 | |
kadonotakashi | 0:8fdf9a60065b | 122 | #ifdef __cplusplus |
kadonotakashi | 0:8fdf9a60065b | 123 | } |
kadonotakashi | 0:8fdf9a60065b | 124 | #endif |
kadonotakashi | 0:8fdf9a60065b | 125 | |
kadonotakashi | 0:8fdf9a60065b | 126 | #endif /* _cycle_counter_h_ */ |