Opencv 3.1 project on GR-PEACH board
Fork of gr-peach-opencv-project by
platform/mbed_poll.cpp@170:54ff26da7eb6, 2017-07-04 (annotated)
- Committer:
- thedo
- Date:
- Tue Jul 04 06:23:13 2017 +0000
- Revision:
- 170:54ff26da7eb6
- Parent:
- 166:3a9487d57a5c
project opencv 3.1 on GR PEACH board, no use SD card.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thedo | 166:3a9487d57a5c | 1 | /* mbed Microcontroller Library |
thedo | 166:3a9487d57a5c | 2 | * Copyright (c) 2017 ARM Limited |
thedo | 166:3a9487d57a5c | 3 | * |
thedo | 166:3a9487d57a5c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
thedo | 166:3a9487d57a5c | 5 | * you may not use this file except in compliance with the License. |
thedo | 166:3a9487d57a5c | 6 | * You may obtain a copy of the License at |
thedo | 166:3a9487d57a5c | 7 | * |
thedo | 166:3a9487d57a5c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
thedo | 166:3a9487d57a5c | 9 | * |
thedo | 166:3a9487d57a5c | 10 | * Unless required by applicable law or agreed to in writing, software |
thedo | 166:3a9487d57a5c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
thedo | 166:3a9487d57a5c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
thedo | 166:3a9487d57a5c | 13 | * See the License for the specific language governing permissions and |
thedo | 166:3a9487d57a5c | 14 | * limitations under the License. |
thedo | 166:3a9487d57a5c | 15 | */ |
thedo | 166:3a9487d57a5c | 16 | #include "mbed_poll.h" |
thedo | 166:3a9487d57a5c | 17 | #include "FileHandle.h" |
thedo | 166:3a9487d57a5c | 18 | #include "Timer.h" |
thedo | 166:3a9487d57a5c | 19 | #ifdef MBED_CONF_RTOS_PRESENT |
thedo | 166:3a9487d57a5c | 20 | #include "rtos/Thread.h" |
thedo | 166:3a9487d57a5c | 21 | #endif |
thedo | 166:3a9487d57a5c | 22 | |
thedo | 166:3a9487d57a5c | 23 | namespace mbed { |
thedo | 166:3a9487d57a5c | 24 | |
thedo | 166:3a9487d57a5c | 25 | // timeout -1 forever, or milliseconds |
thedo | 166:3a9487d57a5c | 26 | int poll(pollfh fhs[], unsigned nfhs, int timeout) |
thedo | 166:3a9487d57a5c | 27 | { |
thedo | 166:3a9487d57a5c | 28 | /** |
thedo | 166:3a9487d57a5c | 29 | * TODO Proper wake-up mechanism. |
thedo | 166:3a9487d57a5c | 30 | * In order to correctly detect availability of read/write a FileHandle, we needed |
thedo | 166:3a9487d57a5c | 31 | * a select or poll mechanisms. We opted for poll as POSIX defines in |
thedo | 166:3a9487d57a5c | 32 | * http://pubs.opengroup.org/onlinepubs/009695399/functions/poll.html Currently, |
thedo | 166:3a9487d57a5c | 33 | * mbed::poll() just spins and scans filehandles looking for any events we are |
thedo | 166:3a9487d57a5c | 34 | * interested in. In future, his spinning behaviour will be replaced with |
thedo | 166:3a9487d57a5c | 35 | * condition variables. |
thedo | 166:3a9487d57a5c | 36 | */ |
thedo | 166:3a9487d57a5c | 37 | Timer timer; |
thedo | 166:3a9487d57a5c | 38 | if (timeout > 0) { |
thedo | 166:3a9487d57a5c | 39 | timer.start(); |
thedo | 166:3a9487d57a5c | 40 | } |
thedo | 166:3a9487d57a5c | 41 | |
thedo | 166:3a9487d57a5c | 42 | int count = 0; |
thedo | 166:3a9487d57a5c | 43 | for (;;) { |
thedo | 166:3a9487d57a5c | 44 | /* Scan the file handles */ |
thedo | 166:3a9487d57a5c | 45 | for (unsigned n = 0; n < nfhs; n++) { |
thedo | 166:3a9487d57a5c | 46 | FileHandle *fh = fhs[n].fh; |
thedo | 166:3a9487d57a5c | 47 | short mask = fhs[n].events | POLLERR | POLLHUP | POLLNVAL; |
thedo | 166:3a9487d57a5c | 48 | if (fh) { |
thedo | 166:3a9487d57a5c | 49 | fhs[n].revents = fh->poll(mask) & mask; |
thedo | 166:3a9487d57a5c | 50 | } else { |
thedo | 166:3a9487d57a5c | 51 | fhs[n].revents = POLLNVAL; |
thedo | 166:3a9487d57a5c | 52 | } |
thedo | 166:3a9487d57a5c | 53 | if (fhs[n].revents) { |
thedo | 166:3a9487d57a5c | 54 | count++; |
thedo | 166:3a9487d57a5c | 55 | } |
thedo | 166:3a9487d57a5c | 56 | } |
thedo | 166:3a9487d57a5c | 57 | |
thedo | 166:3a9487d57a5c | 58 | if (count) { |
thedo | 166:3a9487d57a5c | 59 | break; |
thedo | 166:3a9487d57a5c | 60 | } |
thedo | 166:3a9487d57a5c | 61 | |
thedo | 166:3a9487d57a5c | 62 | /* Nothing selected - this is where timeout handling would be needed */ |
thedo | 166:3a9487d57a5c | 63 | if (timeout == 0 || (timeout > 0 && timer.read_ms() > timeout)) { |
thedo | 166:3a9487d57a5c | 64 | break; |
thedo | 166:3a9487d57a5c | 65 | } |
thedo | 166:3a9487d57a5c | 66 | #ifdef MBED_CONF_RTOS_PRESENT |
thedo | 166:3a9487d57a5c | 67 | // TODO - proper blocking |
thedo | 166:3a9487d57a5c | 68 | // wait for condition variable, wait queue whatever here |
thedo | 166:3a9487d57a5c | 69 | rtos::Thread::yield(); |
thedo | 166:3a9487d57a5c | 70 | #endif |
thedo | 166:3a9487d57a5c | 71 | } |
thedo | 166:3a9487d57a5c | 72 | return count; |
thedo | 166:3a9487d57a5c | 73 | } |
thedo | 166:3a9487d57a5c | 74 | |
thedo | 166:3a9487d57a5c | 75 | } // namespace mbed |
thedo | 166:3a9487d57a5c | 76 |