| 1 | /* |
| 2 | Copyright (c) 2012, Broadcom Europe Ltd |
| 3 | All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above copyright |
| 10 | notice, this list of conditions and the following disclaimer in the |
| 11 | documentation and/or other materials provided with the distribution. |
| 12 | * Neither the name of the copyright holder nor the |
| 13 | names of its contributors may be used to endorse or promote products |
| 14 | derived from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifndef VC_VCHI_GENCMD_H |
| 29 | #define VC_VCHI_GENCMD_H |
| 30 | #include "vchost_platform_config.h" |
| 31 | #include "interface/vchi/vchi.h" |
| 32 | #include "interface/vcos/vcos.h" //for VCHPRE_ abd VCHPOST_ macro's for func declaration |
| 33 | |
| 34 | /* Initialise general command service. Returns it's interface number. This initialises |
| 35 | the host side of the interface, it does not send anything to VideoCore. */ |
| 36 | |
| 37 | VCHPRE_ int VCHPOST_ vc_gencmd_init(void); |
| 38 | |
| 39 | VCHPRE_ void VCHPOST_ vc_vchi_gencmd_init(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections ); |
| 40 | |
| 41 | |
| 42 | /* Stop the service from being used. */ |
| 43 | |
| 44 | VCHPRE_ void VCHPOST_ vc_gencmd_stop(void); |
| 45 | |
| 46 | /* Functions to support videocore suspend/resume for cases where vc_gencmd_send expects a response to |
| 47 | * ensure videocore is not shut down (done internally in vc_gencmd / vc_gencmd_until) */ |
| 48 | |
| 49 | VCHPRE_ int VCHPOST_ use_gencmd_service(void); |
| 50 | VCHPRE_ int VCHPOST_ release_gencmd_service(void); |
| 51 | |
| 52 | /****************************************************************************** |
| 53 | Send commands to VideoCore. |
| 54 | These all return 0 for success. They return VC_MSGFIFO_FIFO_FULL if there is |
| 55 | insufficient space for the whole message in the fifo, and none of the message is |
| 56 | sent. |
| 57 | ******************************************************************************/ |
| 58 | |
| 59 | /* send command to general command serivce */ |
| 60 | VCHPRE_ int VCHPOST_ vc_gencmd_send( const char *format, ... ); |
| 61 | |
| 62 | /* get resonse from general command serivce */ |
| 63 | VCHPRE_ int VCHPOST_ vc_gencmd_read_response(char *response, int maxlen); |
| 64 | |
| 65 | /* convenience function to send command and receive the response */ |
| 66 | VCHPRE_ int VCHPOST_ vc_gencmd(char *response, int maxlen, const char *format, ...); |
| 67 | |
| 68 | /****************************************************************************** |
| 69 | Utilities to help interpret the responses. |
| 70 | ******************************************************************************/ |
| 71 | |
| 72 | /* Read the value of a property=value type pair from a string (typically VideoCore's |
| 73 | response to a general command). Return non-zero if found. */ |
| 74 | VCHPRE_ int VCHPOST_ vc_gencmd_string_property(char *text, const char *property, char **value, int *length); |
| 75 | |
| 76 | /* Read the numeric value of a property=number field from a response string. Return |
| 77 | non-zero if found. */ |
| 78 | VCHPRE_ int VCHPOST_ vc_gencmd_number_property(char *text, const char *property, int *number); |
| 79 | |
| 80 | /* Send a command until the desired response is received, the error message is detected, or the timeout */ |
| 81 | VCHPRE_ int VCHPOST_ vc_gencmd_until( char *cmd, |
| 82 | const char *property, |
| 83 | char *value, |
| 84 | const char *error_string, |
| 85 | int timeout); |
| 86 | |
| 87 | |
| 88 | #endif |
| 89 | |