serial: extend stream detect for variable length packet checkers The previous implementation of the packet detection in a serial stream assumed that all packets are of equal length which is known in advance. Extend the packet validity check interface such that caller provided callbacks can either decide that the input is valid or invalid (terminal decision), or request more receive data before a decision can be made (deferral, coverring variable length packets, with a minimum size to cover the header before a length becomes available and the total packet length is known). This commit extends the API, and adjusts the call sites to not break the compilation. Actual variable length checkers are yet to be done. Improve readability while we are here: Better reflect the purpose and units of variables in their identifiers. Tweak diagnostics messages, update inline and doxygen comments.
serial: flush() after open() in the serial core. Quite some drivers flush the serial port after opening it. And quite some don't although they should. Factor this out, so serial_open() will always flush the port. The removal in the drivers was done with this small coccinelle script: @@ struct sr_serial_dev_inst *serial; @@ serial_open(serial, ...) ... when != serial - serial_flush(serial); and then the results and the unmatched findings of serial_flush() were audited. Signed-off-by: Wolfram Sang <redacted>
serial: use timeout API in stream detect, obsoletes bitrate param The serial_stream_detect() routine needs to estimate the time which is needed to communicate a given amount of data. Since the serial port got opened and configured before, the serial communication parameters are known, and callers need not redundantly specify the bit rate.
drivers: Add and use STD_CONFIG_LIST(). This ensures consistent handling of the SR_CONF_SCAN_OPTIONS and SR_CONF_DEVICE_OPTIONS (with sdi NULL or non-NULL) config keys and also reduces copy-pasted boilerplate in the drivers a bit. This function does not handle channel-group specific items, that's very driver-specific and thus left to the individual drivers. Also move some generic checks and error messages from the drivers into the sr_config_list() wrapper.
Remove unnecessary std_serial_dev_acquisition_stop() wrappers Now that std_serial_dev_acquisition_stop() has the same signature as the sr_dev_driver dev_acquisition_stop() callback it is possible to remove the wrapper functions and use std_serial_dev_acquisition_stop() directly has the callback function. Signed-off-by: Lars-Peter Clausen <redacted>
std_serial_dev_acquisition_stop(): Remove dev_close_fn parameter All callers of std_serial_dev_acquisition_stop() currently pass the same callback for the dev_close_fn parameter as the dev_close callback of their sr_dev_driver struct. Remove the dev_close_fn parameter and invoke the drivers dev_close() callback directly. This simplifies the API and ensures consistent behaviour between different drivers. Signed-off-by: Lars-Peter Clausen <redacted>
std_serial_dev_acquisition_stop(): Remove serial parameter All callers of std_serial_dev_acquisition_stop() currently pass sdi->conn for the serial parameter. And the other std_serial helper functions already require that the conn field of the sr_driver_inst passed to the functions points to the sr_serial_dev_inst associated with the device. Modify std_serial_dev_acquisition_stop() to follow the same pattern and remove the serial parameter. This simplifies the API and ensures consistent behaviour between different drivers. Signed-off-by: Lars-Peter Clausen <redacted>
Use driver name as the log prefix in standard functions Some of the standard helper functions take a log prefix parameter that is used when printing messages. This log prefix is almost always identical to the name field in the driver's sr_dev_driver struct. The only exception are drivers which register multiple sr_dev_driver structs. Instead of passing the log prefix as a parameter simply use the driver's name. This simplifies the API, gives consistent behaviour between different drivers and also makes it easier to identify where the message originates when a driver registers sr_dev_driver structs. Signed-off-by: Lars-Peter Clausen <redacted>
Fix a few "variable set but not used" compiler warnings. ../src/hardware/appa-55ii/api.c: In function ‘scan’: ../src/hardware/appa-55ii/api.c:47:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^ ../src/hardware/arachnid-labs-re-load-pro/api.c: In function ‘scan’: ../src/hardware/arachnid-labs-re-load-pro/api.c:62:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^ ../src/hardware/atten-pps3xxx/api.c: In function ‘scan’: ../src/hardware/atten-pps3xxx/api.c:81:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^ ../src/hardware/brymen-dmm/api.c: In function ‘scan’: ../src/hardware/brymen-dmm/api.c:89:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^ ../src/hardware/cem-dt-885x/api.c: In function ‘scan’: ../src/hardware/cem-dt-885x/api.c:74:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^ ../src/hardware/conrad-digi-35-cpu/api.c: In function ‘scan’: ../src/hardware/conrad-digi-35-cpu/api.c:45:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^ ../src/hardware/demo/demo.c: In function ‘scan’: ../src/hardware/demo/demo.c:255:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^ ../src/hardware/fluke-dmm/api.c: In function ‘fluke_scan’: ../src/hardware/fluke-dmm/api.c:64:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^ ../src/hardware/gmc-mh-1x-2x/api.c: In function ‘scan_1x_2x_rs232’: ../src/hardware/gmc-mh-1x-2x/api.c:147:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^ ../src/hardware/gmc-mh-1x-2x/api.c: In function ‘scan_2x_bd232’: ../src/hardware/gmc-mh-1x-2x/api.c:234:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^ ../src/hardware/ikalogic-scanaplus/api.c: In function ‘scan’: ../src/hardware/ikalogic-scanaplus/api.c:69:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^ ../src/hardware/tondaj-sl-814/api.c: In function ‘scan’: ../src/hardware/tondaj-sl-814/api.c:44:22: warning: variable ‘drvc’ set but not used [-Wunused-but-set-variable] struct drv_context *drvc; ^
Add helper function for scan completion A common task during device scan is to add the newly discovered devices to the instance list of the driver. Currently this is done by each driver on its own. This patch introduces a new helper function std_scan_complete() which takes care of this. The function should be called at the end of a driver's scan() callback before returning the device list. Doing this with a helper function provides guaranteed consistent behaviour among drivers and hopefully paves the way to moving more standard functionality directly into the sigrok core. Another common task that every driver has to do for each device instance is to initialize the device's driver field. So this is done in the new helper function as well. All drivers that can make use of the new helper are updated. Signed-off-by: Lars-Peter Clausen <redacted>
Don't reset instance list in scan() callback Some drivers set the device instance list to NULL in their scan() callback. This means the driver loses all references to any devices contained in that list and their resources will be leaked. Drivers can't free the devices at this point either since an application might still use a device on the list. So the existing devices on the instance list need to remain unmodified during the scan() callback, even if that means that there will be duplicates on the instance list. Only an explicit invocation of sr_dev_clear() by the application is allowed to free the devices on the instance list and reset the list. Signed-off-by: Lars-Peter Clausen <redacted>
Put driver pointers into special section The sigrok core needs a list of all available drivers. Currently this list is manually maintained by updating a global list whenever a driver is added or removed. Introduce a new special section that contains the list of all drivers. The SR_REGISTER_DEV_DRIVER() and SR_REGISTER_DEV_DRIVER_LIST() macro is used to add drivers to this new list. This is done by placing the pointers to the driver into a special section. Since nothing else is in this section it is known that it is simply a list of driver pointers and the core can iterate over it as if it was an array. The advantage of this approach is that the code necessary to add a driver to the list is completely contained to the driver source and it is no longer necessary to maintain a global list. If a driver is built it will automatically appear in the list, if it is not built in won't. This means that the list is always correct, whereas the previous approach used ifdefs in the global driver list file which could get out-of-sync with the actual condition when the driver was built. Any sr_dev_driver structs that are no longer used outside the driver module are marked as static. Signed-off-by: Lars-Peter Clausen <redacted>