takashi kadono
/
Nucleo_446
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/targets/TARGET_NUVOTON/nu_timer.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 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2015-2016 Nuvoton |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | */ |
kadonotakashi | 0:8fdf9a60065b | 16 | |
kadonotakashi | 0:8fdf9a60065b | 17 | #ifndef NU_TIMER_H |
kadonotakashi | 0:8fdf9a60065b | 18 | #define NU_TIMER_H |
kadonotakashi | 0:8fdf9a60065b | 19 | |
kadonotakashi | 0:8fdf9a60065b | 20 | #include <stdint.h> |
kadonotakashi | 0:8fdf9a60065b | 21 | #include <stdbool.h> |
kadonotakashi | 0:8fdf9a60065b | 22 | #include "cmsis.h" |
kadonotakashi | 0:8fdf9a60065b | 23 | #include "ticker_api.h" |
kadonotakashi | 0:8fdf9a60065b | 24 | #include "us_ticker_api.h" |
kadonotakashi | 0:8fdf9a60065b | 25 | |
kadonotakashi | 0:8fdf9a60065b | 26 | #ifdef __cplusplus |
kadonotakashi | 0:8fdf9a60065b | 27 | extern "C" { |
kadonotakashi | 0:8fdf9a60065b | 28 | #endif |
kadonotakashi | 0:8fdf9a60065b | 29 | |
kadonotakashi | 0:8fdf9a60065b | 30 | /* A simple count-down timer used for Nuvoton ported drivers |
kadonotakashi | 0:8fdf9a60065b | 31 | * |
kadonotakashi | 0:8fdf9a60065b | 32 | * NOTE: nu_countdown_init must be paired with nu_countdown_free. |
kadonotakashi | 0:8fdf9a60065b | 33 | * |
kadonotakashi | 0:8fdf9a60065b | 34 | * Example: |
kadonotakashi | 0:8fdf9a60065b | 35 | * nu_countdown_ctx_s ctx; |
kadonotakashi | 0:8fdf9a60065b | 36 | * |
kadonotakashi | 0:8fdf9a60065b | 37 | * // Set up 2 ms timeout |
kadonotakashi | 0:8fdf9a60065b | 38 | * nu_countdown_init(&ctx, 2000); |
kadonotakashi | 0:8fdf9a60065b | 39 | * |
kadonotakashi | 0:8fdf9a60065b | 40 | * // Timed-wait for a task |
kadonotakashi | 0:8fdf9a60065b | 41 | * while (true) { |
kadonotakashi | 0:8fdf9a60065b | 42 | * // Poll the task |
kadonotakashi | 0:8fdf9a60065b | 43 | * |
kadonotakashi | 0:8fdf9a60065b | 44 | * if (nu_countdown_expired(&ctx)) { |
kadonotakashi | 0:8fdf9a60065b | 45 | * // Timeout |
kadonotakashi | 0:8fdf9a60065b | 46 | * } |
kadonotakashi | 0:8fdf9a60065b | 47 | * } |
kadonotakashi | 0:8fdf9a60065b | 48 | * |
kadonotakashi | 0:8fdf9a60065b | 49 | * // Must pair nu_countdown_init with nu_countdown_free in the end |
kadonotakashi | 0:8fdf9a60065b | 50 | * nu_countdown_free(&ctx); |
kadonotakashi | 0:8fdf9a60065b | 51 | */ |
kadonotakashi | 0:8fdf9a60065b | 52 | |
kadonotakashi | 0:8fdf9a60065b | 53 | struct nu_countdown_ctx_s { |
kadonotakashi | 0:8fdf9a60065b | 54 | const ticker_data_t * _ticker_data; // Hold ticker_data_t |
kadonotakashi | 0:8fdf9a60065b | 55 | us_timestamp_t _interval_end_us; // End of interval in us |
kadonotakashi | 0:8fdf9a60065b | 56 | bool _expired; // Expired or not |
kadonotakashi | 0:8fdf9a60065b | 57 | }; |
kadonotakashi | 0:8fdf9a60065b | 58 | |
kadonotakashi | 0:8fdf9a60065b | 59 | void nu_countdown_init(struct nu_countdown_ctx_s *ctx, us_timestamp_t interval_us); |
kadonotakashi | 0:8fdf9a60065b | 60 | bool nu_countdown_expired(struct nu_countdown_ctx_s *ctx); |
kadonotakashi | 0:8fdf9a60065b | 61 | void nu_countdown_free(struct nu_countdown_ctx_s *ctx); |
kadonotakashi | 0:8fdf9a60065b | 62 | |
kadonotakashi | 0:8fdf9a60065b | 63 | |
kadonotakashi | 0:8fdf9a60065b | 64 | /* Replacement for wait_us when intermediary us ticker layer is disabled |
kadonotakashi | 0:8fdf9a60065b | 65 | * |
kadonotakashi | 0:8fdf9a60065b | 66 | * Use of wait_us directly from the low power ticker causes the system to deadlock during |
kadonotakashi | 0:8fdf9a60065b | 67 | * the sleep test because the sleep test disables the intermediary us ticker layer during |
kadonotakashi | 0:8fdf9a60065b | 68 | * the test. |
kadonotakashi | 0:8fdf9a60065b | 69 | * |
kadonotakashi | 0:8fdf9a60065b | 70 | * To prevent this lockup, nu_busy_wait_us is created to replace wait_us, which uses the us ticker |
kadonotakashi | 0:8fdf9a60065b | 71 | * directly rather than go though the intermediary us ticker layer. |
kadonotakashi | 0:8fdf9a60065b | 72 | * |
kadonotakashi | 0:8fdf9a60065b | 73 | * During wait period through nu_busy_wait_us, CPU would be busy spinning. |
kadonotakashi | 0:8fdf9a60065b | 74 | */ |
kadonotakashi | 0:8fdf9a60065b | 75 | void nu_busy_wait_us(uint32_t us); |
kadonotakashi | 0:8fdf9a60065b | 76 | |
kadonotakashi | 0:8fdf9a60065b | 77 | /* Delay 4 cycles per round by hand-counting instruction cycles */ |
kadonotakashi | 0:8fdf9a60065b | 78 | void nu_delay_cycle_x4(uint32_t rounds); |
kadonotakashi | 0:8fdf9a60065b | 79 | |
kadonotakashi | 0:8fdf9a60065b | 80 | #ifdef __cplusplus |
kadonotakashi | 0:8fdf9a60065b | 81 | } |
kadonotakashi | 0:8fdf9a60065b | 82 | #endif |
kadonotakashi | 0:8fdf9a60065b | 83 | |
kadonotakashi | 0:8fdf9a60065b | 84 | #endif |