Realtime spectrogram for DISCO-F746NG. On-board MEMS microphone is used for input sound signal. リアルタイムスペクトログラム.入力:MEMSマイク
Dependencies: F746_GUI F746_SAI_IO UIT_FFT_Real
mbed_src_STM32F7/common/ticker_api.c@6:b3885567877c, 2017-04-10 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Apr 10 13:43:07 2017 +0000
- Revision:
- 6:b3885567877c
- Parent:
- 4:c1beacfc42c7
7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 4:c1beacfc42c7 | 1 | /* mbed Microcontroller Library |
MikamiUitOpen | 4:c1beacfc42c7 | 2 | * Copyright (c) 2015 ARM Limited |
MikamiUitOpen | 4:c1beacfc42c7 | 3 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
MikamiUitOpen | 4:c1beacfc42c7 | 5 | * you may not use this file except in compliance with the License. |
MikamiUitOpen | 4:c1beacfc42c7 | 6 | * You may obtain a copy of the License at |
MikamiUitOpen | 4:c1beacfc42c7 | 7 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
MikamiUitOpen | 4:c1beacfc42c7 | 9 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 10 | * Unless required by applicable law or agreed to in writing, software |
MikamiUitOpen | 4:c1beacfc42c7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
MikamiUitOpen | 4:c1beacfc42c7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MikamiUitOpen | 4:c1beacfc42c7 | 13 | * See the License for the specific language governing permissions and |
MikamiUitOpen | 4:c1beacfc42c7 | 14 | * limitations under the License. |
MikamiUitOpen | 4:c1beacfc42c7 | 15 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 16 | #include <stddef.h> |
MikamiUitOpen | 4:c1beacfc42c7 | 17 | #include "ticker_api.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 18 | #include "cmsis.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 19 | |
MikamiUitOpen | 4:c1beacfc42c7 | 20 | void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler) { |
MikamiUitOpen | 4:c1beacfc42c7 | 21 | data->interface->init(); |
MikamiUitOpen | 4:c1beacfc42c7 | 22 | |
MikamiUitOpen | 4:c1beacfc42c7 | 23 | data->queue->event_handler = handler; |
MikamiUitOpen | 4:c1beacfc42c7 | 24 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 25 | |
MikamiUitOpen | 4:c1beacfc42c7 | 26 | void ticker_irq_handler(const ticker_data_t *const data) { |
MikamiUitOpen | 4:c1beacfc42c7 | 27 | data->interface->clear_interrupt(); |
MikamiUitOpen | 4:c1beacfc42c7 | 28 | |
MikamiUitOpen | 4:c1beacfc42c7 | 29 | /* Go through all the pending TimerEvents */ |
MikamiUitOpen | 4:c1beacfc42c7 | 30 | while (1) { |
MikamiUitOpen | 4:c1beacfc42c7 | 31 | if (data->queue->head == NULL) { |
MikamiUitOpen | 4:c1beacfc42c7 | 32 | // There are no more TimerEvents left, so disable matches. |
MikamiUitOpen | 4:c1beacfc42c7 | 33 | data->interface->disable_interrupt(); |
MikamiUitOpen | 4:c1beacfc42c7 | 34 | return; |
MikamiUitOpen | 4:c1beacfc42c7 | 35 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 36 | |
MikamiUitOpen | 4:c1beacfc42c7 | 37 | if ((int)(data->queue->head->timestamp - data->interface->read()) <= 0) { |
MikamiUitOpen | 4:c1beacfc42c7 | 38 | // This event was in the past: |
MikamiUitOpen | 4:c1beacfc42c7 | 39 | // point to the following one and execute its handler |
MikamiUitOpen | 4:c1beacfc42c7 | 40 | ticker_event_t *p = data->queue->head; |
MikamiUitOpen | 4:c1beacfc42c7 | 41 | data->queue->head = data->queue->head->next; |
MikamiUitOpen | 4:c1beacfc42c7 | 42 | if (data->queue->event_handler != NULL) { |
MikamiUitOpen | 4:c1beacfc42c7 | 43 | (*data->queue->event_handler)(p->id); // NOTE: the handler can set new events |
MikamiUitOpen | 4:c1beacfc42c7 | 44 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 45 | /* Note: We continue back to examining the head because calling the |
MikamiUitOpen | 4:c1beacfc42c7 | 46 | * event handler may have altered the chain of pending events. */ |
MikamiUitOpen | 4:c1beacfc42c7 | 47 | } else { |
MikamiUitOpen | 4:c1beacfc42c7 | 48 | // This event and the following ones in the list are in the future: |
MikamiUitOpen | 4:c1beacfc42c7 | 49 | // set it as next interrupt and return |
MikamiUitOpen | 4:c1beacfc42c7 | 50 | data->interface->set_interrupt(data->queue->head->timestamp); |
MikamiUitOpen | 4:c1beacfc42c7 | 51 | return; |
MikamiUitOpen | 4:c1beacfc42c7 | 52 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 53 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 54 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 55 | |
MikamiUitOpen | 4:c1beacfc42c7 | 56 | void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id) { |
MikamiUitOpen | 4:c1beacfc42c7 | 57 | /* disable interrupts for the duration of the function */ |
MikamiUitOpen | 4:c1beacfc42c7 | 58 | __disable_irq(); |
MikamiUitOpen | 4:c1beacfc42c7 | 59 | |
MikamiUitOpen | 4:c1beacfc42c7 | 60 | // initialise our data |
MikamiUitOpen | 4:c1beacfc42c7 | 61 | obj->timestamp = timestamp; |
MikamiUitOpen | 4:c1beacfc42c7 | 62 | obj->id = id; |
MikamiUitOpen | 4:c1beacfc42c7 | 63 | |
MikamiUitOpen | 4:c1beacfc42c7 | 64 | /* Go through the list until we either reach the end, or find |
MikamiUitOpen | 4:c1beacfc42c7 | 65 | an element this should come before (which is possibly the |
MikamiUitOpen | 4:c1beacfc42c7 | 66 | head). */ |
MikamiUitOpen | 4:c1beacfc42c7 | 67 | ticker_event_t *prev = NULL, *p = data->queue->head; |
MikamiUitOpen | 4:c1beacfc42c7 | 68 | while (p != NULL) { |
MikamiUitOpen | 4:c1beacfc42c7 | 69 | /* check if we come before p */ |
MikamiUitOpen | 4:c1beacfc42c7 | 70 | if ((int)(timestamp - p->timestamp) < 0) { |
MikamiUitOpen | 4:c1beacfc42c7 | 71 | break; |
MikamiUitOpen | 4:c1beacfc42c7 | 72 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 73 | /* go to the next element */ |
MikamiUitOpen | 4:c1beacfc42c7 | 74 | prev = p; |
MikamiUitOpen | 4:c1beacfc42c7 | 75 | p = p->next; |
MikamiUitOpen | 4:c1beacfc42c7 | 76 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 77 | /* if prev is NULL we're at the head */ |
MikamiUitOpen | 4:c1beacfc42c7 | 78 | if (prev == NULL) { |
MikamiUitOpen | 4:c1beacfc42c7 | 79 | data->queue->head = obj; |
MikamiUitOpen | 4:c1beacfc42c7 | 80 | data->interface->set_interrupt(timestamp); |
MikamiUitOpen | 4:c1beacfc42c7 | 81 | } else { |
MikamiUitOpen | 4:c1beacfc42c7 | 82 | prev->next = obj; |
MikamiUitOpen | 4:c1beacfc42c7 | 83 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 84 | /* if we're at the end p will be NULL, which is correct */ |
MikamiUitOpen | 4:c1beacfc42c7 | 85 | obj->next = p; |
MikamiUitOpen | 4:c1beacfc42c7 | 86 | |
MikamiUitOpen | 4:c1beacfc42c7 | 87 | __enable_irq(); |
MikamiUitOpen | 4:c1beacfc42c7 | 88 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 89 | |
MikamiUitOpen | 4:c1beacfc42c7 | 90 | void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj) { |
MikamiUitOpen | 4:c1beacfc42c7 | 91 | __disable_irq(); |
MikamiUitOpen | 4:c1beacfc42c7 | 92 | |
MikamiUitOpen | 4:c1beacfc42c7 | 93 | // remove this object from the list |
MikamiUitOpen | 4:c1beacfc42c7 | 94 | if (data->queue->head == obj) { |
MikamiUitOpen | 4:c1beacfc42c7 | 95 | // first in the list, so just drop me |
MikamiUitOpen | 4:c1beacfc42c7 | 96 | data->queue->head = obj->next; |
MikamiUitOpen | 4:c1beacfc42c7 | 97 | if (data->queue->head == NULL) { |
MikamiUitOpen | 4:c1beacfc42c7 | 98 | data->interface->disable_interrupt(); |
MikamiUitOpen | 4:c1beacfc42c7 | 99 | } else { |
MikamiUitOpen | 4:c1beacfc42c7 | 100 | data->interface->set_interrupt(data->queue->head->timestamp); |
MikamiUitOpen | 4:c1beacfc42c7 | 101 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 102 | } else { |
MikamiUitOpen | 4:c1beacfc42c7 | 103 | // find the object before me, then drop me |
MikamiUitOpen | 4:c1beacfc42c7 | 104 | ticker_event_t* p = data->queue->head; |
MikamiUitOpen | 4:c1beacfc42c7 | 105 | while (p != NULL) { |
MikamiUitOpen | 4:c1beacfc42c7 | 106 | if (p->next == obj) { |
MikamiUitOpen | 4:c1beacfc42c7 | 107 | p->next = obj->next; |
MikamiUitOpen | 4:c1beacfc42c7 | 108 | break; |
MikamiUitOpen | 4:c1beacfc42c7 | 109 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 110 | p = p->next; |
MikamiUitOpen | 4:c1beacfc42c7 | 111 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 112 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 113 | |
MikamiUitOpen | 4:c1beacfc42c7 | 114 | __enable_irq(); |
MikamiUitOpen | 4:c1beacfc42c7 | 115 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 116 | |
MikamiUitOpen | 4:c1beacfc42c7 | 117 | timestamp_t ticker_read(const ticker_data_t *const data) |
MikamiUitOpen | 4:c1beacfc42c7 | 118 | { |
MikamiUitOpen | 4:c1beacfc42c7 | 119 | return data->interface->read(); |
MikamiUitOpen | 4:c1beacfc42c7 | 120 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 121 | |
MikamiUitOpen | 4:c1beacfc42c7 | 122 | int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *timestamp) |
MikamiUitOpen | 4:c1beacfc42c7 | 123 | { |
MikamiUitOpen | 4:c1beacfc42c7 | 124 | int ret = 0; |
MikamiUitOpen | 4:c1beacfc42c7 | 125 | |
MikamiUitOpen | 4:c1beacfc42c7 | 126 | /* if head is NULL, there are no pending events */ |
MikamiUitOpen | 4:c1beacfc42c7 | 127 | __disable_irq(); |
MikamiUitOpen | 4:c1beacfc42c7 | 128 | if (data->queue->head != NULL) { |
MikamiUitOpen | 4:c1beacfc42c7 | 129 | *timestamp = data->queue->head->timestamp; |
MikamiUitOpen | 4:c1beacfc42c7 | 130 | ret = 1; |
MikamiUitOpen | 4:c1beacfc42c7 | 131 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 132 | __enable_irq(); |
MikamiUitOpen | 4:c1beacfc42c7 | 133 | |
MikamiUitOpen | 4:c1beacfc42c7 | 134 | return ret; |
MikamiUitOpen | 4:c1beacfc42c7 | 135 | } |