1 #include <inttypes.h>
2 #include <stdbool.h>
3 
4 /* Error handling */
5 
6 /*
7  * All the functions return a pointer to the renode_error_t structure in case of an error.
8  * Its memory has to be freed in case it's handled. NULL returned indicates success.
9  */
10 
11 #define NO_ERROR NULL
12 
13 typedef enum {
14     ERR_CONNECTION_FAILED,
15     ERR_FATAL,
16     ERR_NOT_CONNECTED,
17     ERR_PERIPHERAL_INIT_FAILED,
18     ERR_TIMEOUT,
19     ERR_COMMAND_FAILED,
20     ERR_NO_ERROR = -1,
21 } renode_error_code;
22 
23 typedef struct {
24     renode_error_code code;
25     int flags;
26     char *message;
27     void *data;
28 } renode_error_t;
29 
30 /* General */
31 
32 // Pointers to these structs must be obtained in `renode_get_X` functions (`connect` for renode_t)
33 // so that they can be later used in their related functions.
34 // Internals of these structs aren't part of the API.
35 typedef struct renode renode_t;
36 typedef struct renode_machine renode_machine_t;
37 typedef struct renode_adc renode_adc_t;
38 typedef struct renode_gpio renode_gpio_t;
39 
40 renode_error_t *renode_connect(const char *port, renode_t **renode);
41 renode_error_t *renode_disconnect(renode_t **renode);
42 
43 renode_error_t *renode_get_machine(renode_t *renode_instance, const char *name, renode_machine_t **machine);
44 
45 void renode_free_error(renode_error_t *error);
46 
47 /* Time control */
48 
49 typedef enum {
50     TU_MICROSECONDS =       1,
51     TU_MILLISECONDS =    1000,
52     TU_SECONDS      = 1000000,
53 } renode_time_unit_t;
54 
55 renode_error_t *renode_run_for(renode_t *renode, renode_time_unit_t unit, uint64_t value);
56 renode_error_t *renode_get_current_time(renode_t *renode_instance, renode_time_unit_t unit, uint64_t *current_time);
57 
58 /* ADC */
59 
60 renode_error_t *renode_get_adc(renode_machine_t *machine, const char *name, renode_adc_t **adc);
61 renode_error_t *renode_get_adc_channel_count(renode_adc_t *adc, int32_t *count);
62 renode_error_t *renode_get_adc_channel_value(renode_adc_t *adc, int32_t channel, uint32_t *value);
63 renode_error_t *renode_set_adc_channel_value(renode_adc_t *adc, int32_t channel, uint32_t value);
64 
65 /* GPIO */
66 
67 renode_error_t *renode_get_gpio(renode_machine_t *machine, const char *name, renode_gpio_t **gpio);
68 renode_error_t *renode_get_gpio_state(renode_gpio_t *gpio, int32_t id, bool *state);
69 renode_error_t *renode_set_gpio_state(renode_gpio_t *gpio, int32_t id, bool state);
70 
71 typedef struct {
72     uint64_t timestamp_us;
73     bool state;
74 } renode_gpio_event_data_t;
75 
76 renode_error_t *renode_register_gpio_state_change_callback(renode_gpio_t *gpio, int32_t id, void *user_data, void (*callback)(void *, renode_gpio_event_data_t *));
77