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 | // General command service API |
29 | |
30 | #ifndef GENCMD_H |
31 | #define GENCMD_H |
32 | |
33 | #include "vchost_platform_config.h" |
34 | #include "interface/vchi/vchi.h" |
35 | |
36 | VCHPRE_ void VCHPOST_ vc_vchi_gencmd_init(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections ); |
37 | |
38 | |
39 | /* Initialise general command service. Returns it's interface number. This initialises |
40 | the host side of the interface, it does not send anything to VideoCore. */ |
41 | |
42 | VCHPRE_ int VCHPOST_ vc_gencmd_init(void); |
43 | |
44 | /* Stop the service from being used. */ |
45 | |
46 | VCHPRE_ void VCHPOST_ vc_gencmd_stop(void); |
47 | |
48 | /* Return the service number (-1 if not running). */ |
49 | VCHPRE_ int VCHPOST_ vc_gencmd_inum(void); |
50 | |
51 | /****************************************************************************** |
52 | Send commands to VideoCore. |
53 | These all return 0 for success. They return VC_MSGFIFO_FIFO_FULL if there is |
54 | insufficient space for the whole message in the fifo, and none of the message is |
55 | sent. |
56 | ******************************************************************************/ |
57 | |
58 | /* send command to general command service */ |
59 | VCHPRE_ int VCHPOST_ vc_gencmd_send( const char *format, ... ); |
60 | |
61 | /* get response from general command service */ |
62 | VCHPRE_ int VCHPOST_ vc_gencmd_read_response(char *response, int maxlen); |
63 | |
64 | /* convenience function to send command and receive the response */ |
65 | VCHPRE_ int VCHPOST_ vc_gencmd(char *response, int maxlen, const char *format, ...); |
66 | |
67 | /* read part of a response from the general command service */ |
68 | VCHPRE_ int VCHPOST_ vc_gencmd_read_response_partial(char *response, int nbytes); |
69 | |
70 | /* if reading with vc_gencmd_read_response_partial end response reads with this */ |
71 | VCHPRE_ int VCHPOST_ vc_gencmd_close_response_partial(void); |
72 | |
73 | /* get state of reading of response */ |
74 | VCHPRE_ int VCHPOST_ vc_gencmd_read_partial_state(void); |
75 | |
76 | /****************************************************************************** |
77 | Utilities to help interpret the responses. |
78 | ******************************************************************************/ |
79 | |
80 | /* Read the value of a property=value type pair from a string (typically VideoCore's |
81 | response to a general command). Return non-zero if found. */ |
82 | VCHPRE_ int VCHPOST_ vc_gencmd_string_property(char *text, const char *property, char **value, int *length); |
83 | |
84 | /* Read the numeric value of a property=number field from a response string. Return |
85 | non-zero if found. */ |
86 | VCHPRE_ int VCHPOST_ vc_gencmd_number_property(char *text, const char *property, int *number); |
87 | |
88 | /* Send a command until the desired response is received, the error message is detected, or the timeout */ |
89 | VCHPRE_ int VCHPOST_ vc_gencmd_until( char *cmd, |
90 | const char *property, |
91 | char *value, |
92 | const char *error_string, |
93 | int timeout); |
94 | |
95 | #endif |
96 | |