2017-08-04 13:38:18 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 comsuisse AG
|
2018-08-15 15:01:57 -07:00
|
|
|
* Copyright (c) 2018 Justin Watson
|
2017-08-04 13:38:18 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2020-04-21 21:13:16 -05:00
|
|
|
#define DT_DRV_COMPAT atmel_sam_afec
|
|
|
|
|
2017-08-04 13:38:18 +02:00
|
|
|
/** @file
|
|
|
|
* @brief Atmel SAM MCU family ADC (AFEC) driver.
|
2018-08-15 15:01:57 -07:00
|
|
|
*
|
|
|
|
* This is an implementation of the Zephyr ADC driver using the SAM Analog
|
|
|
|
* Front-End Controller (AFEC) peripheral.
|
2017-08-04 13:38:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
2019-06-26 10:33:39 -04:00
|
|
|
#include <sys/__assert.h>
|
2019-06-26 10:33:55 -04:00
|
|
|
#include <sys/util.h>
|
2017-08-04 13:38:18 +02:00
|
|
|
#include <device.h>
|
|
|
|
#include <init.h>
|
|
|
|
#include <soc.h>
|
2019-06-25 15:53:45 -04:00
|
|
|
#include <drivers/adc.h>
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
#define ADC_CONTEXT_USES_KERNEL_TIMER
|
|
|
|
#include "adc_context.h"
|
|
|
|
|
2018-09-17 12:00:47 -05:00
|
|
|
#define LOG_LEVEL CONFIG_ADC_LOG_LEVEL
|
|
|
|
#include <logging/log.h>
|
|
|
|
LOG_MODULE_REGISTER(adc_sam_afec);
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
#define NUM_CHANNELS 12
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
#define CONF_ADC_PRESCALER ((SOC_ATMEL_SAM_MCK_FREQ_HZ / 15000000) - 1)
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
typedef void (*cfg_func_t)(const struct device *dev);
|
2018-08-15 15:01:57 -07:00
|
|
|
|
|
|
|
struct adc_sam_data {
|
|
|
|
struct adc_context ctx;
|
2020-04-30 20:33:38 +02:00
|
|
|
const struct device *dev;
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
/* Pointer to the buffer in the sequence. */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t *buffer;
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
/* Pointer to the beginning of a sample. Consider the number of
|
|
|
|
* channels in the sequence: this buffer changes by that amount
|
|
|
|
* so all the channels would get repeated.
|
|
|
|
*/
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t *repeat_buffer;
|
2018-08-15 15:01:57 -07:00
|
|
|
|
|
|
|
/* Bit mask of the channels to be sampled. */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t channels;
|
2018-08-15 15:01:57 -07:00
|
|
|
|
|
|
|
/* Index of the channel being sampled. */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t channel_id;
|
2017-08-04 13:38:18 +02:00
|
|
|
};
|
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
struct adc_sam_cfg {
|
|
|
|
Afec *regs;
|
|
|
|
cfg_func_t cfg_func;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t periph_id;
|
2018-08-15 15:01:57 -07:00
|
|
|
struct soc_gpio_pin afec_trg_pin;
|
|
|
|
};
|
2017-08-04 13:38:18 +02:00
|
|
|
|
|
|
|
#define DEV_CFG(dev) \
|
2020-05-28 20:44:16 +02:00
|
|
|
((const struct adc_sam_cfg *const)(dev)->config)
|
2018-08-15 15:01:57 -07:00
|
|
|
|
2017-08-04 13:38:18 +02:00
|
|
|
#define DEV_DATA(dev) \
|
2020-05-28 21:23:02 +02:00
|
|
|
((struct adc_sam_data *)(dev)->data)
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int adc_sam_channel_setup(const struct device *dev,
|
2018-08-15 15:01:57 -07:00
|
|
|
const struct adc_channel_cfg *channel_cfg)
|
2017-08-04 13:38:18 +02:00
|
|
|
{
|
2018-08-15 15:01:57 -07:00
|
|
|
const struct adc_sam_cfg * const cfg = DEV_CFG(dev);
|
|
|
|
Afec *const afec = cfg->regs;
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t channel_id = channel_cfg->channel_id;
|
2018-08-15 15:01:57 -07:00
|
|
|
|
|
|
|
/* Clear the gain bits for the channel. */
|
2019-03-26 19:57:45 -06:00
|
|
|
afec->AFEC_CGR &= ~(3 << channel_id * 2U);
|
2018-08-15 15:01:57 -07:00
|
|
|
|
|
|
|
switch (channel_cfg->gain) {
|
|
|
|
case ADC_GAIN_1:
|
|
|
|
/* A value of 0 in this register is a gain of 1. */
|
|
|
|
break;
|
|
|
|
case ADC_GAIN_1_2:
|
2019-03-26 19:57:45 -06:00
|
|
|
afec->AFEC_CGR |= (1 << (channel_id * 2U));
|
2018-08-15 15:01:57 -07:00
|
|
|
break;
|
|
|
|
case ADC_GAIN_1_4:
|
2019-03-26 19:57:45 -06:00
|
|
|
afec->AFEC_CGR |= (2 << (channel_id * 2U));
|
2018-08-15 15:01:57 -07:00
|
|
|
break;
|
|
|
|
default:
|
2018-09-17 12:00:47 -05:00
|
|
|
LOG_ERR("Selected ADC gain is not valid");
|
2018-08-15 15:01:57 -07:00
|
|
|
return -EINVAL;
|
2017-08-04 13:38:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) {
|
2018-09-17 12:00:47 -05:00
|
|
|
LOG_ERR("Selected ADC acquisition time is not valid");
|
2018-08-15 15:01:57 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel_cfg->reference != ADC_REF_EXTERNAL0) {
|
2018-09-17 12:00:47 -05:00
|
|
|
LOG_ERR("Selected reference is not valid");
|
2018-08-15 15:01:57 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel_cfg->differential) {
|
2018-09-17 12:00:47 -05:00
|
|
|
LOG_ERR("Differential input is not supported");
|
2018-08-15 15:01:57 -07:00
|
|
|
return -EINVAL;
|
2017-08-04 13:38:18 +02:00
|
|
|
}
|
2018-08-15 15:01:57 -07:00
|
|
|
|
|
|
|
/* Set single ended channels to unsigned and differential channels
|
|
|
|
* to signed conversions.
|
|
|
|
*/
|
|
|
|
afec->AFEC_EMR &= ~(AFEC_EMR_SIGNMODE(
|
|
|
|
AFEC_EMR_SIGNMODE_SE_UNSG_DF_SIGN_Val));
|
|
|
|
|
|
|
|
return 0;
|
2017-08-04 13:38:18 +02:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void adc_sam_start_conversion(const struct device *dev)
|
2017-08-04 13:38:18 +02:00
|
|
|
{
|
2018-08-15 15:01:57 -07:00
|
|
|
const struct adc_sam_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
struct adc_sam_data *data = DEV_DATA(dev);
|
|
|
|
Afec *const afec = cfg->regs;
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
data->channel_id = find_lsb_set(data->channels) - 1;
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-09-17 12:00:47 -05:00
|
|
|
LOG_DBG("Starting channel %d", data->channel_id);
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
/* Disable all channels. */
|
|
|
|
afec->AFEC_CHDR = 0xfff;
|
|
|
|
afec->AFEC_IDR = 0xfff;
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
/* Enable the ADC channel. This also enables/selects the channel pin as
|
|
|
|
* an input to the AFEC (50.5.1 SAM E70 datasheet).
|
|
|
|
*/
|
|
|
|
afec->AFEC_CHER = (1 << data->channel_id);
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
/* Enable the interrupt for the channel. */
|
|
|
|
afec->AFEC_IER = (1 << data->channel_id);
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
/* Start the conversions. */
|
|
|
|
afec->AFEC_CR = AFEC_CR_START;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is only called once at the beginning of all the conversions,
|
|
|
|
* all channels as a group.
|
|
|
|
*/
|
|
|
|
static void adc_context_start_sampling(struct adc_context *ctx)
|
|
|
|
{
|
|
|
|
struct adc_sam_data *data = CONTAINER_OF(ctx, struct adc_sam_data, ctx);
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2019-03-29 17:24:28 -07:00
|
|
|
data->channels = ctx->sequence.channels;
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
adc_sam_start_conversion(data->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void adc_context_update_buffer_pointer(struct adc_context *ctx,
|
|
|
|
bool repeat_sampling)
|
|
|
|
{
|
|
|
|
struct adc_sam_data *data = CONTAINER_OF(ctx, struct adc_sam_data, ctx);
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
if (repeat_sampling) {
|
|
|
|
data->buffer = data->repeat_buffer;
|
|
|
|
}
|
|
|
|
}
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
static int check_buffer_size(const struct adc_sequence *sequence,
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t active_channels)
|
2018-08-15 15:01:57 -07:00
|
|
|
{
|
|
|
|
size_t needed_buffer_size;
|
2020-05-27 11:26:57 -05:00
|
|
|
needed_buffer_size = active_channels * sizeof(uint16_t);
|
2018-08-15 15:01:57 -07:00
|
|
|
if (sequence->options) {
|
|
|
|
needed_buffer_size *= (1 + sequence->options->extra_samplings);
|
|
|
|
}
|
|
|
|
if (sequence->buffer_size < needed_buffer_size) {
|
2018-09-17 12:00:47 -05:00
|
|
|
LOG_ERR("Provided buffer is too small (%u/%u)",
|
2018-08-15 15:01:57 -07:00
|
|
|
sequence->buffer_size, needed_buffer_size);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2017-08-04 13:38:18 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int start_read(const struct device *dev,
|
|
|
|
const struct adc_sequence *sequence)
|
2017-08-04 13:38:18 +02:00
|
|
|
{
|
2018-08-15 15:01:57 -07:00
|
|
|
struct adc_sam_data *data = DEV_DATA(dev);
|
|
|
|
int error = 0;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t channels = sequence->channels;
|
2018-08-15 15:01:57 -07:00
|
|
|
|
2018-11-29 11:12:22 -08:00
|
|
|
data->channels = 0U;
|
2018-08-15 15:01:57 -07:00
|
|
|
|
|
|
|
/* Signal an error if the channel selection is invalid (no channels or
|
|
|
|
* a non-existing one is selected).
|
|
|
|
*/
|
2019-03-26 19:57:45 -06:00
|
|
|
if (channels == 0U ||
|
|
|
|
(channels & (~0UL << NUM_CHANNELS))) {
|
2018-09-17 12:00:47 -05:00
|
|
|
LOG_ERR("Invalid selection of channels");
|
2018-08-15 15:01:57 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-03-26 19:57:45 -06:00
|
|
|
if (sequence->oversampling != 0U) {
|
2018-09-17 12:00:47 -05:00
|
|
|
LOG_ERR("Oversampling is not supported");
|
2018-08-15 15:01:57 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-03-26 19:57:45 -06:00
|
|
|
if (sequence->resolution != 12U) {
|
2018-08-15 15:01:57 -07:00
|
|
|
/* TODO JKW: Support the Enhanced Resolution Mode 50.6.3 page
|
|
|
|
* 1544.
|
|
|
|
*/
|
2018-09-17 12:00:47 -05:00
|
|
|
LOG_ERR("ADC resolution value %d is not valid",
|
2018-08-15 15:01:57 -07:00
|
|
|
sequence->resolution);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t num_active_channels = 0U;
|
|
|
|
uint8_t channel = 0U;
|
2018-08-15 15:01:57 -07:00
|
|
|
|
|
|
|
while (channels > 0) {
|
|
|
|
if (channels & 1) {
|
|
|
|
++num_active_channels;
|
|
|
|
}
|
|
|
|
channels >>= 1;
|
|
|
|
++channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = check_buffer_size(sequence, num_active_channels);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In the context you have a pointer to the adc_sam_data structure
|
|
|
|
* only.
|
|
|
|
*/
|
|
|
|
data->buffer = sequence->buffer;
|
|
|
|
data->repeat_buffer = sequence->buffer;
|
|
|
|
|
|
|
|
/* At this point we allow the scheduler to do other things while
|
|
|
|
* we wait for the conversions to complete. This is provided by the
|
|
|
|
* adc_context functions. However, the caller of this function is
|
|
|
|
* blocked until the results are in.
|
|
|
|
*/
|
|
|
|
adc_context_start_read(&data->ctx, sequence);
|
|
|
|
|
|
|
|
error = adc_context_wait_for_completion(&data->ctx);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int adc_sam_read(const struct device *dev,
|
2018-08-15 15:01:57 -07:00
|
|
|
const struct adc_sequence *sequence)
|
|
|
|
{
|
|
|
|
struct adc_sam_data *data = DEV_DATA(dev);
|
2018-12-17 08:04:10 +01:00
|
|
|
int error;
|
2018-08-15 15:01:57 -07:00
|
|
|
|
|
|
|
adc_context_lock(&data->ctx, false, NULL);
|
2018-12-17 08:04:10 +01:00
|
|
|
error = start_read(dev, sequence);
|
|
|
|
adc_context_release(&data->ctx, error);
|
|
|
|
|
|
|
|
return error;
|
2018-08-15 15:01:57 -07:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int adc_sam_init(const struct device *dev)
|
2018-08-15 15:01:57 -07:00
|
|
|
{
|
|
|
|
const struct adc_sam_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
struct adc_sam_data *data = DEV_DATA(dev);
|
|
|
|
Afec *const afec = cfg->regs;
|
|
|
|
|
|
|
|
/* Reset the AFEC. */
|
2017-08-04 13:38:18 +02:00
|
|
|
afec->AFEC_CR = AFEC_CR_SWRST;
|
|
|
|
|
|
|
|
afec->AFEC_MR = AFEC_MR_TRGEN_DIS
|
|
|
|
| AFEC_MR_SLEEP_NORMAL
|
|
|
|
| AFEC_MR_FWUP_OFF
|
|
|
|
| AFEC_MR_FREERUN_OFF
|
|
|
|
| AFEC_MR_PRESCAL(CONF_ADC_PRESCALER)
|
|
|
|
| AFEC_MR_STARTUP_SUT96
|
|
|
|
| AFEC_MR_ONE
|
|
|
|
| AFEC_MR_USEQ_NUM_ORDER;
|
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
/* Set all channels CM voltage to Vrefp/2 (512). */
|
|
|
|
for (int i = 0; i < NUM_CHANNELS; i++) {
|
2017-08-04 13:38:18 +02:00
|
|
|
afec->AFEC_CSELR = i;
|
|
|
|
afec->AFEC_COCR = 512;
|
|
|
|
}
|
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
/* Enable PGA and Current Bias. */
|
2017-08-04 13:38:18 +02:00
|
|
|
afec->AFEC_ACR = AFEC_ACR_PGA0EN
|
|
|
|
| AFEC_ACR_PGA1EN
|
|
|
|
| AFEC_ACR_IBCTL(1);
|
2018-08-15 15:01:57 -07:00
|
|
|
|
|
|
|
soc_pmc_peripheral_enable(cfg->periph_id);
|
|
|
|
|
|
|
|
cfg->cfg_func(dev);
|
|
|
|
|
|
|
|
data->dev = dev;
|
|
|
|
|
|
|
|
adc_context_unlock_unconditionally(&data->ctx);
|
|
|
|
|
|
|
|
return 0;
|
2017-08-04 13:38:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
#ifdef CONFIG_ADC_ASYNC
|
2020-04-30 20:33:38 +02:00
|
|
|
static int adc_sam_read_async(const struct device *dev,
|
2018-08-15 15:01:57 -07:00
|
|
|
const struct adc_sequence *sequence,
|
|
|
|
struct k_poll_signal *async)
|
2017-08-04 13:38:18 +02:00
|
|
|
{
|
2018-08-15 15:01:57 -07:00
|
|
|
struct adc_sam_data *data = DEV_DATA(dev);
|
2018-12-17 08:04:10 +01:00
|
|
|
int error;
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
adc_context_lock(&data->ctx, true, async);
|
2018-12-17 08:04:10 +01:00
|
|
|
error = start_read(dev, sequence);
|
|
|
|
adc_context_release(&data->ctx, error);
|
|
|
|
|
|
|
|
return error;
|
2018-08-15 15:01:57 -07:00
|
|
|
}
|
|
|
|
#endif
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
static const struct adc_driver_api adc_sam_api = {
|
|
|
|
.channel_setup = adc_sam_channel_setup,
|
|
|
|
.read = adc_sam_read,
|
|
|
|
#ifdef CONFIG_ADC_ASYNC
|
|
|
|
.read_async = adc_sam_read_async,
|
|
|
|
#endif
|
|
|
|
};
|
2017-08-04 13:38:18 +02:00
|
|
|
|
isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs
This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.
Note that only the ISR passed to IRQ_CONNECT are of interest here.
In order to do so, the script fix_isr.py below is necessary:
from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os
cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
(
const struct device *D = (const struct device *)P;
|
const struct device *D = P;
)
...
}
@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
const struct device *D;
...
(
D = (const struct device *)P;
|
D = P;
)
...
}
@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
...
}
@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);
@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
...
}
@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
...
}
"""
def find_isr(fn):
db = []
data = None
start = 0
try:
with open(fn, 'r+') as f:
data = str(mmap.mmap(f.fileno(), 0).read())
except Exception as e:
return db
while True:
isr = ""
irq = data.find('IRQ_CONNECT', start)
while irq > -1:
p = 1
arg = 1
p_o = data.find('(', irq)
if p_o < 0:
irq = -1
break;
pos = p_o + 1
while p > 0:
if data[pos] == ')':
p -= 1
elif data[pos] == '(':
p += 1
elif data[pos] == ',' and p == 1:
arg += 1
if arg == 3:
isr += data[pos]
pos += 1
isr = isr.strip(',\\n\\t ')
if isr not in db and len(isr) > 0:
db.append(isr)
start = pos
break
if irq < 0:
break
return db
def patch_isr(fn, isr_list):
if len(isr_list) <= 0:
return
for isr in isr_list:
tmplt = cocci_template.replace('<!fn!>', isr)
with open('/tmp/isr_fix.cocci', 'w') as f:
f.write(tmplt)
cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]
subprocess.run(cmd)
def process_files(path):
if path.is_file() and path.suffix in ['.h', '.c']:
p = str(path.parent) + '/' + path.name
isr_list = find_isr(p)
patch_isr(p, isr_list)
elif path.is_dir():
for p in path.iterdir():
process_files(p)
if len(sys.argv) < 2:
print("You need to provide a dir/file path")
sys.exit(1)
process_files(Path(sys.argv[1]))
And is run: ./fix_isr.py <zephyr root directory>
Finally, some files needed manual fixes such.
Fixes #27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-06-17 14:58:56 +02:00
|
|
|
static void adc_sam_isr(const struct device *dev)
|
2018-08-15 15:01:57 -07:00
|
|
|
{
|
|
|
|
struct adc_sam_data *data = DEV_DATA(dev);
|
|
|
|
const struct adc_sam_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
Afec *const afec = cfg->regs;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t result;
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
afec->AFEC_CHDR |= BIT(data->channel_id);
|
|
|
|
afec->AFEC_IDR |= BIT(data->channel_id);
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
afec->AFEC_CSELR = AFEC_CSELR_CSEL(data->channel_id);
|
2020-05-27 11:26:57 -05:00
|
|
|
result = (uint16_t)(afec->AFEC_CDR);
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
*data->buffer++ = result;
|
|
|
|
data->channels &= ~BIT(data->channel_id);
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2018-08-15 15:01:57 -07:00
|
|
|
if (data->channels) {
|
|
|
|
adc_sam_start_conversion(dev);
|
|
|
|
} else {
|
|
|
|
/* Called once all conversions have completed.*/
|
|
|
|
adc_context_on_sampling_done(&data->ctx, dev);
|
|
|
|
}
|
2017-08-04 13:38:18 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 21:13:16 -05:00
|
|
|
#define ADC_SAM_INIT(n) \
|
2020-07-14 17:02:00 +02:00
|
|
|
static void adc##n##_sam_cfg_func(const struct device *dev); \
|
2020-04-21 21:13:16 -05:00
|
|
|
\
|
|
|
|
static const struct adc_sam_cfg adc##n##_sam_cfg = { \
|
|
|
|
.regs = (Afec *)DT_INST_REG_ADDR(n), \
|
|
|
|
.cfg_func = adc##n##_sam_cfg_func, \
|
|
|
|
.periph_id = DT_INST_PROP(n, peripheral_id), \
|
|
|
|
.afec_trg_pin = ATMEL_SAM_DT_PIN(n, 0), \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
static struct adc_sam_data adc##n##_sam_data = { \
|
|
|
|
ADC_CONTEXT_INIT_TIMER(adc##n##_sam_data, ctx), \
|
|
|
|
ADC_CONTEXT_INIT_LOCK(adc##n##_sam_data, ctx), \
|
|
|
|
ADC_CONTEXT_INIT_SYNC(adc##n##_sam_data, ctx), \
|
|
|
|
}; \
|
|
|
|
\
|
2021-04-28 10:02:28 +02:00
|
|
|
DEVICE_DT_INST_DEFINE(n, adc_sam_init, NULL, \
|
2020-12-09 12:49:32 -06:00
|
|
|
&adc##n##_sam_data, \
|
2020-04-21 21:13:16 -05:00
|
|
|
&adc##n##_sam_cfg, POST_KERNEL, \
|
|
|
|
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
|
|
|
&adc_sam_api); \
|
|
|
|
\
|
2020-07-14 17:02:00 +02:00
|
|
|
static void adc##n##_sam_cfg_func(const struct device *dev) \
|
2020-04-21 21:13:16 -05:00
|
|
|
{ \
|
|
|
|
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), \
|
|
|
|
adc_sam_isr, \
|
2020-12-09 12:49:32 -06:00
|
|
|
DEVICE_DT_INST_GET(n), 0); \
|
2020-04-21 21:13:16 -05:00
|
|
|
irq_enable(DT_INST_IRQN(n)); \
|
|
|
|
}
|
2017-08-04 13:38:18 +02:00
|
|
|
|
2020-05-06 11:23:07 -07:00
|
|
|
DT_INST_FOREACH_STATUS_OKAY(ADC_SAM_INIT)
|