adc: fix segmentation fault when exiting the application
'adc_sampling_cb_data' struct is a local variable of the 'main' function. Sometimes, the ADC callback accesses to it once the main function has exited (when it is out of scope), causing a segmentation fault. To solve this issue, adc_sampling_cb_data' struct is now a global variable. Signed-off-by: Francisco Gil <francisco.gilmartinez@digi.com>
This commit is contained in:
parent
1e02f43c81
commit
5c3834f845
|
|
@ -31,13 +31,14 @@
|
||||||
#define DEFAULT_TIME_INTERVAl 1
|
#define DEFAULT_TIME_INTERVAl 1
|
||||||
#define DEFAULT_NUMBER_OF_SAMPLES 10
|
#define DEFAULT_NUMBER_OF_SAMPLES 10
|
||||||
|
|
||||||
static adc_t *adc;
|
|
||||||
|
|
||||||
struct adc_sampling_cb_data {
|
struct adc_sampling_cb_data {
|
||||||
adc_t *adc;
|
adc_t *adc;
|
||||||
int number_of_samples;
|
int number_of_samples;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static adc_t *adc;
|
||||||
|
struct adc_sampling_cb_data cb_data;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* usage_and_exit() - Show usage information and exit with 'exitval' return
|
* usage_and_exit() - Show usage information and exit with 'exitval' return
|
||||||
* value
|
* value
|
||||||
|
|
@ -157,7 +158,6 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int channel = 0, chip = 0, interval = 0, number_of_samples = 0;
|
int channel = 0, chip = 0, interval = 0, number_of_samples = 0;
|
||||||
char *name = basename(argv[0]);
|
char *name = basename(argv[0]);
|
||||||
struct adc_sampling_cb_data cb_data;
|
|
||||||
|
|
||||||
/* Check input parameters */
|
/* Check input parameters */
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue