drivers: adc: move to new logger

Move to new logger subsystem.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2018-09-17 12:00:47 -05:00
commit 9a8567fa4a
9 changed files with 78 additions and 90 deletions

View file

@ -31,26 +31,9 @@ config ADC_ASYNC
help
This option enables the asynchronous API calls.
config SYS_LOG_ADC_LEVEL
int "ADC drivers log level"
depends on SYS_LOG
default 0
range 0 4
help
Sets log level for ADC driver.
Levels are:
- 0 OFF, do not write
- 1 ERROR, only write SYS_LOG_ERR
- 2 WARNING, write SYS_LOG_WRN in addition to previous level
- 3 INFO, write SYS_LOG_INF in addition to previous levels
- 4 DEBUG, write SYS_LOG_DBG in addition to previous levels
module = ADC
module-str = ADC
source "subsys/logging/Kconfig.template.log_config"
config ADC_INIT_PRIORITY
int "Init priority"

View file

@ -19,7 +19,10 @@
#define ADC_CONTEXT_USES_KERNEL_TIMER
#include "adc_context.h"
#include "adc_dw.h"
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_ADC_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(adc_dw);
#define ADC_CLOCK_GATE (1 << 31)
#define ADC_DEEP_POWER_DOWN 0x01
@ -231,27 +234,27 @@ static int adc_dw_channel_setup(struct device *dev,
struct adc_info *info = dev->driver_data;
if (channel_id >= DW_CHANNEL_COUNT) {
SYS_LOG_ERR("Invalid channel id");
LOG_ERR("Invalid channel id");
return -EINVAL;
}
if (channel_cfg->gain != ADC_GAIN_1) {
SYS_LOG_ERR("Invalid channel gain");
LOG_ERR("Invalid channel gain");
return -EINVAL;
}
if (channel_cfg->reference != ADC_REF_INTERNAL) {
SYS_LOG_ERR("Invalid channel reference");
LOG_ERR("Invalid channel reference");
return -EINVAL;
}
if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) {
SYS_LOG_ERR("Invalid channel acquisition time");
LOG_ERR("Invalid channel acquisition time");
return -EINVAL;
}
if (info->state != ADC_STATE_IDLE) {
SYS_LOG_ERR("ADC is busy or in error state");
LOG_ERR("ADC is busy or in error state");
return -EAGAIN;
}

View file

@ -14,9 +14,9 @@
#include <adc.h>
#include <arch/cpu.h>
#define SYS_LOG_DOMAIN "dev/adc_quark_d2000"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ADC_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_ADC_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(adc_intel_quark_d2000);
#define ADC_CONTEXT_USES_KERNEL_TIMER
#include "adc_context.h"
@ -201,27 +201,27 @@ static int adc_quark_d2000_channel_setup(struct device *dev,
u8_t channel_id = channel_cfg->channel_id;
if (channel_id > MAX_CHANNELS) {
SYS_LOG_ERR("Channel %d is not valid", channel_id);
LOG_ERR("Channel %d is not valid", channel_id);
return -EINVAL;
}
if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) {
SYS_LOG_ERR("Invalid channel acquisition time");
LOG_ERR("Invalid channel acquisition time");
return -EINVAL;
}
if (channel_cfg->differential) {
SYS_LOG_ERR("Differential channels are not supported");
LOG_ERR("Differential channels are not supported");
return -EINVAL;
}
if (channel_cfg->gain != ADC_GAIN_1) {
SYS_LOG_ERR("Invalid channel gain");
LOG_ERR("Invalid channel gain");
return -EINVAL;
}
if (channel_cfg->reference != ADC_REF_INTERNAL) {
SYS_LOG_ERR("Invalid channel reference");
LOG_ERR("Invalid channel reference");
return -EINVAL;
}

View file

@ -8,8 +8,9 @@
#include <adc.h>
#include <fsl_adc16.h>
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ADC_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_ADC_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(adc_mcux_adc16);
#define ADC_CONTEXT_USES_KERNEL_TIMER
#include "adc_context.h"
@ -34,27 +35,27 @@ static int mcux_adc16_channel_setup(struct device *dev,
u8_t channel_id = channel_cfg->channel_id;
if (channel_id > (ADC_SC1_ADCH_MASK >> ADC_SC1_ADCH_SHIFT)) {
SYS_LOG_ERR("Channel %d is not valid", channel_id);
LOG_ERR("Channel %d is not valid", channel_id);
return -EINVAL;
}
if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) {
SYS_LOG_ERR("Invalid channel acquisition time");
LOG_ERR("Invalid channel acquisition time");
return -EINVAL;
}
if (channel_cfg->differential) {
SYS_LOG_ERR("Differential channels are not supported");
LOG_ERR("Differential channels are not supported");
return -EINVAL;
}
if (channel_cfg->gain != ADC_GAIN_1) {
SYS_LOG_ERR("Invalid channel gain");
LOG_ERR("Invalid channel gain");
return -EINVAL;
}
if (channel_cfg->reference != ADC_REF_INTERNAL) {
SYS_LOG_ERR("Invalid channel reference");
LOG_ERR("Invalid channel reference");
return -EINVAL;
}
@ -69,7 +70,7 @@ static int start_read(struct device *dev, const struct adc_sequence *sequence)
int error;
if (sequence->resolution != 12) {
SYS_LOG_ERR("Invalid resolution");
LOG_ERR("Invalid resolution");
return -EINVAL;
}
@ -90,7 +91,7 @@ static int start_read(struct device *dev, const struct adc_sequence *sequence)
mode = kADC16_HardwareAverageCount32;
break;
default:
SYS_LOG_ERR("Invalid oversampling");
LOG_ERR("Invalid oversampling");
return -EINVAL;
}
ADC16_SetHardwareAverage(config->base, mode);
@ -136,7 +137,7 @@ static void mcux_adc16_start_channel(struct device *dev)
data->channel_id = find_lsb_set(data->channels) - 1;
SYS_LOG_DBG("Starting channel %d", data->channel_id);
LOG_DBG("Starting channel %d", data->channel_id);
#if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
channel_config.enableDifferentialConversion = false;
@ -177,7 +178,7 @@ static void mcux_adc16_isr(void *arg)
u16_t result;
result = ADC16_GetChannelConversionValue(base, channel_group);
SYS_LOG_DBG("Finished channel %d. Result is 0x%04x",
LOG_DBG("Finished channel %d. Result is 0x%04x",
data->channel_id, result);
*data->buffer++ = result;

View file

@ -8,9 +8,9 @@
#include "adc_context.h"
#include <nrfx_adc.h>
#define SYS_LOG_DOMAIN "adc_nrfx_adc"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ADC_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_ADC_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(adc_mcux_adc16);
struct driver_data {
struct adc_context ctx;
@ -40,12 +40,12 @@ static int adc_nrfx_channel_setup(struct device *dev,
}
if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) {
SYS_LOG_ERR("Selected ADC acquisition time is not valid");
LOG_ERR("Selected ADC acquisition time is not valid");
return -EINVAL;
}
if (channel_cfg->differential) {
SYS_LOG_ERR("Differential channels are not supported");
LOG_ERR("Differential channels are not supported");
return -EINVAL;
}
@ -60,7 +60,7 @@ static int adc_nrfx_channel_setup(struct device *dev,
config->scaling = NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE;
break;
default:
SYS_LOG_ERR("Selected ADC gain is not valid");
LOG_ERR("Selected ADC gain is not valid");
return -EINVAL;
}
@ -86,7 +86,7 @@ static int adc_nrfx_channel_setup(struct device *dev,
config->extref = NRF_ADC_CONFIG_EXTREFSEL_AREF1;
break;
default:
SYS_LOG_ERR("Selected ADC reference is not valid");
LOG_ERR("Selected ADC reference is not valid");
return -EINVAL;
}
@ -126,7 +126,7 @@ static int check_buffer_size(const struct adc_sequence *sequence,
}
if (sequence->buffer_size < needed_buffer_size) {
SYS_LOG_ERR("Provided buffer is too small (%u/%u)",
LOG_ERR("Provided buffer is too small (%u/%u)",
sequence->buffer_size, needed_buffer_size);
return -ENOMEM;
}
@ -148,12 +148,12 @@ static int start_read(struct device *dev, const struct adc_sequence *sequence)
if (!selected_channels ||
(selected_channels &
~BIT_MASK(CONFIG_ADC_NRFX_ADC_CHANNEL_COUNT))) {
SYS_LOG_ERR("Invalid selection of channels");
LOG_ERR("Invalid selection of channels");
return -EINVAL;
}
if (sequence->oversampling != 0) {
SYS_LOG_ERR("Oversampling is not supported");
LOG_ERR("Oversampling is not supported");
return -EINVAL;
}
@ -168,7 +168,7 @@ static int start_read(struct device *dev, const struct adc_sequence *sequence)
nrf_resolution = NRF_ADC_CONFIG_RES_10BIT;
break;
default:
SYS_LOG_ERR("ADC resolution value %d is not valid",
LOG_ERR("ADC resolution value %d is not valid",
sequence->resolution);
return -EINVAL;
}
@ -248,7 +248,7 @@ static int init_adc(struct device *dev)
nrfx_err_t result = nrfx_adc_init(&config, event_handler);
if (result != NRFX_SUCCESS) {
SYS_LOG_ERR("Failed to initialize device: %s",
LOG_ERR("Failed to initialize device: %s",
dev->config->name);
return -EBUSY;
}

View file

@ -8,9 +8,9 @@
#include "adc_context.h"
#include <hal/nrf_saadc.h>
#define SYS_LOG_DOMAIN "adc_nrfx_saadc"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ADC_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_ADC_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(adc_nrfx_saadc);
struct driver_data {
struct adc_context ctx;
@ -66,7 +66,7 @@ static int adc_nrfx_channel_setup(struct device *dev,
config.gain = NRF_SAADC_GAIN4;
break;
default:
SYS_LOG_ERR("Selected ADC gain is not valid");
LOG_ERR("Selected ADC gain is not valid");
return -EINVAL;
}
@ -78,7 +78,7 @@ static int adc_nrfx_channel_setup(struct device *dev,
config.reference = NRF_SAADC_REFERENCE_VDD4;
break;
default:
SYS_LOG_ERR("Selected ADC reference is not valid");
LOG_ERR("Selected ADC reference is not valid");
return -EINVAL;
}
@ -103,7 +103,7 @@ static int adc_nrfx_channel_setup(struct device *dev,
config.acq_time = NRF_SAADC_ACQTIME_40US;
break;
default:
SYS_LOG_ERR("Selected ADC acquisition time is not valid");
LOG_ERR("Selected ADC acquisition time is not valid");
return -EINVAL;
}
@ -168,7 +168,7 @@ static int set_resolution(const struct adc_sequence *sequence)
nrf_resolution = NRF_SAADC_RESOLUTION_14BIT;
break;
default:
SYS_LOG_ERR("ADC resolution value %d is not valid",
LOG_ERR("ADC resolution value %d is not valid",
sequence->resolution);
return -EINVAL;
}
@ -183,7 +183,7 @@ static int set_oversampling(const struct adc_sequence *sequence,
nrf_saadc_oversample_t nrf_oversampling;
if ((active_channels > 1) && (sequence->oversampling > 0)) {
SYS_LOG_ERR(
LOG_ERR(
"Oversampling is supported for single channel only");
return -EINVAL;
}
@ -217,7 +217,7 @@ static int set_oversampling(const struct adc_sequence *sequence,
nrf_oversampling = NRF_SAADC_OVERSAMPLE_256X;
break;
default:
SYS_LOG_ERR("Oversampling value %d is not valid",
LOG_ERR("Oversampling value %d is not valid",
sequence->oversampling);
return -EINVAL;
}
@ -237,7 +237,7 @@ static int check_buffer_size(const struct adc_sequence *sequence,
}
if (sequence->buffer_size < needed_buffer_size) {
SYS_LOG_ERR("Provided buffer is too small (%u/%u)",
LOG_ERR("Provided buffer is too small (%u/%u)",
sequence->buffer_size, needed_buffer_size);
return -ENOMEM;
}
@ -257,7 +257,7 @@ static int start_read(struct device *dev, const struct adc_sequence *sequence)
*/
if (!selected_channels ||
(selected_channels & ~BIT_MASK(NRF_SAADC_CHANNEL_COUNT))) {
SYS_LOG_ERR("Invalid selection of channels");
LOG_ERR("Invalid selection of channels");
return -EINVAL;
}
@ -273,7 +273,7 @@ static int start_read(struct device *dev, const struct adc_sequence *sequence)
* configured yet.
*/
if (m_data.positive_inputs[channel_id] == 0) {
SYS_LOG_ERR("Channel %u not configured",
LOG_ERR("Channel %u not configured",
channel_id);
return -EINVAL;
}

View file

@ -23,9 +23,9 @@
#define ADC_CONTEXT_USES_KERNEL_TIMER
#include "adc_context.h"
#define SYS_LOG_DOMAIN "dev/adc_sam_afec"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ADC_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_ADC_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(adc_sam_afec);
#define NUM_CHANNELS 12
@ -88,22 +88,22 @@ static int adc_sam_channel_setup(struct device *dev,
afec->AFEC_CGR |= (2 << (channel_id * 2));
break;
default:
SYS_LOG_ERR("Selected ADC gain is not valid");
LOG_ERR("Selected ADC gain is not valid");
return -EINVAL;
}
if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) {
SYS_LOG_ERR("Selected ADC acquisition time is not valid");
LOG_ERR("Selected ADC acquisition time is not valid");
return -EINVAL;
}
if (channel_cfg->reference != ADC_REF_EXTERNAL0) {
SYS_LOG_ERR("Selected reference is not valid");
LOG_ERR("Selected reference is not valid");
return -EINVAL;
}
if (channel_cfg->differential) {
SYS_LOG_ERR("Differential input is not supported");
LOG_ERR("Differential input is not supported");
return -EINVAL;
}
@ -124,7 +124,7 @@ static void adc_sam_start_conversion(struct device *dev)
data->channel_id = find_lsb_set(data->channels) - 1;
SYS_LOG_DBG("Starting channel %d", data->channel_id);
LOG_DBG("Starting channel %d", data->channel_id);
/* Disable all channels. */
afec->AFEC_CHDR = 0xfff;
@ -174,7 +174,7 @@ static int check_buffer_size(const struct adc_sequence *sequence,
needed_buffer_size *= (1 + sequence->options->extra_samplings);
}
if (sequence->buffer_size < needed_buffer_size) {
SYS_LOG_ERR("Provided buffer is too small (%u/%u)",
LOG_ERR("Provided buffer is too small (%u/%u)",
sequence->buffer_size, needed_buffer_size);
return -ENOMEM;
}
@ -194,12 +194,12 @@ static int start_read(struct device *dev, const struct adc_sequence *sequence)
*/
if (channels == 0 ||
(channels & (~0UL << NUM_CHANNELS))) {
SYS_LOG_ERR("Invalid selection of channels");
LOG_ERR("Invalid selection of channels");
return -EINVAL;
}
if (sequence->oversampling != 0) {
SYS_LOG_ERR("Oversampling is not supported");
LOG_ERR("Oversampling is not supported");
return -EINVAL;
}
@ -207,7 +207,7 @@ static int start_read(struct device *dev, const struct adc_sequence *sequence)
/* TODO JKW: Support the Enhanced Resolution Mode 50.6.3 page
* 1544.
*/
SYS_LOG_ERR("ADC resolution value %d is not valid",
LOG_ERR("ADC resolution value %d is not valid",
sequence->resolution);
return -EINVAL;
}

View file

@ -10,12 +10,13 @@
#include <kernel.h>
#include <misc/util.h>
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ADC_LEVEL
#include <logging/sys_log.h>
#include <string.h>
#include <init.h>
#include "adc_ti_adc108s102.h"
#define LOG_LEVEL CONFIG_ADC_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(adc_ti_adc108s102);
static inline int _ti_adc108s102_sampling(struct device *dev)
{
@ -37,7 +38,7 @@ static inline int _ti_adc108s102_sampling(struct device *dev)
.count = 1
};
SYS_LOG_DBG("Sampling!");
LOG_DBG("Sampling!");
return spi_transceive(adc->spi, &adc->spi_cfg, &tx, &rx);
}
@ -50,7 +51,7 @@ static inline void _ti_adc108s102_handle_result(struct device *dev)
struct adc_seq_entry *entry;
u32_t s_i, i;
SYS_LOG_DBG("_ti_adc108s102_handle_result()");
LOG_DBG("_ti_adc108s102_handle_result()");
for (i = 0, s_i = 1; i < seq_table->num_entries; i++, s_i++) {
entry = &seq_table->entries[i];
@ -87,7 +88,7 @@ static inline s32_t _ti_adc108s102_prepare(struct device *dev)
continue;
}
SYS_LOG_DBG("Requesting channel %d", entry->channel_id);
LOG_DBG("Requesting channel %d", entry->channel_id);
adc->cmd_buffer[adc->cmd_buf_len] =
ADC108S102_CHANNEL_CMD(entry->channel_id);
@ -105,7 +106,7 @@ static inline s32_t _ti_adc108s102_prepare(struct device *dev)
adc->cmd_buffer[adc->cmd_buf_len] = 0;
adc->cmd_buf_len++;
SYS_LOG_DBG("ADC108S102 is prepared...");
LOG_DBG("ADC108S102 is prepared...");
return sampling_delay;
}
@ -221,7 +222,7 @@ static int ti_adc108s102_init(struct device *dev)
adc->spi_cfg.slave = CONFIG_ADC_TI_ADC108S102_SPI_SLAVE;
SYS_LOG_DBG("ADC108s102 initialized");
LOG_DBG("ADC108s102 initialized");
dev->driver_api = &ti_adc108s102_api;

View file

@ -4,5 +4,5 @@ CONFIG_ADC=y
CONFIG_ADC_ASYNC=y
CONFIG_ADC_0=y
CONFIG_SYS_LOG=y
CONFIG_SYS_LOG_ADC_LEVEL=1
CONFIG_LOG=y
CONFIG_ADC_LOG_LEVEL_INF=y