Second ADC debugging in process
This commit is contained in:
@@ -16,9 +16,16 @@ void spark_timeout_callback(void *arg)
|
||||
void rtIgnitionTask::rtIgnitionTask_manager(void *pvParameters)
|
||||
{
|
||||
rtIgnitionTask *cls = (rtIgnitionTask *)pvParameters;
|
||||
auto last_loop = millis();
|
||||
uint32_t count(0);
|
||||
while (cls->m_running)
|
||||
{
|
||||
cls->run();
|
||||
// if (millis() - last_loop > 2000) {
|
||||
// LOG_DEBUG("TASK [", cls->m_name.c_str(), "] Alive -", count++);
|
||||
// last_loop = millis();
|
||||
// }
|
||||
vTaskDelay(pdMS_TO_TICKS(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,10 +45,12 @@ void rtIgnitionTask::rtIgnitionTask_realtime(void *pvParameters)
|
||||
const rtTaskInterruptParams rt_int = params->rt_int; // copy to avoid external override
|
||||
const rtTaskIOParams rt_rst = params->rt_io; // copy to avoid external override
|
||||
QueueHandle_t rt_queue = params->rt_queue;
|
||||
Devices *dev = params->dev.get();
|
||||
ADS1256 *adc = params->name == "rtIgnTask_A" ? dev->m_adc_a.get() : dev->m_adc_b.get();
|
||||
std::mutex &spi_mutex = params->name == "rtIgnTask_A" ? dev->m_spi_a_mutex : dev->m_spi_b_mutex;
|
||||
ExternalIO *io = dev->m_ext_io.get();
|
||||
Devices *dev = params->dev;
|
||||
ExternalIO *io = dev->m_ext_io;
|
||||
// ADS1256 *adc = params->name == "rtIgnTask_A" ? dev->m_adc_a : dev->m_adc_b;
|
||||
ADS1256 *adc = NULL;
|
||||
// std::mutex &spi_mutex = params->name == "rtIgnTask_A" ? dev->m_spi_a_mutex : dev->m_spi_b_mutex;
|
||||
std::mutex spi_mutex;
|
||||
|
||||
TaskStatus_t rt_task_info;
|
||||
vTaskGetInfo(NULL, &rt_task_info, pdFALSE, eInvalid);
|
||||
@@ -76,10 +85,6 @@ void rtIgnitionTask::rtIgnitionTask_realtime(void *pvParameters)
|
||||
.ign_stat = &ign_box_sts,
|
||||
.rt_handle_ptr = rt_task_info.xHandle};
|
||||
|
||||
LOG_DEBUG("rtTask HDL Params OK, HDL* [", (uint32_t)rt_task_info.xHandle, "]");
|
||||
LOG_DEBUG("rtTask ISR Params OK, ISR* [", (uint32_t)rt_int.isr_ptr, "]");
|
||||
LOG_DEBUG("rtTask QUE Params OK, QUE* [", (uint32_t)rt_queue, "]");
|
||||
|
||||
// Create esp_timer for microsecond precision timeout
|
||||
esp_timer_handle_t timeout_timer;
|
||||
esp_timer_create_args_t timer_args = {
|
||||
@@ -87,7 +92,11 @@ void rtIgnitionTask::rtIgnitionTask_realtime(void *pvParameters)
|
||||
.arg = (void *)rt_task_info.xHandle,
|
||||
.dispatch_method = ESP_TIMER_TASK,
|
||||
.name = "spark_timeout"};
|
||||
esp_timer_create(&timer_args, &timeout_timer);
|
||||
if (esp_timer_create(&timer_args, &timeout_timer) != ESP_OK)
|
||||
{
|
||||
LOG_INFO("rtTask [", params->name.c_str(), "] Fail to allocate timeoutTimer");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
// Attach Pin Interrupts
|
||||
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12p), rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
|
||||
@@ -242,10 +251,10 @@ void rtIgnitionTask::rtIgnitionTask_realtime(void *pvParameters)
|
||||
ign_box_sts.coils12.peak_n_in = adc->convertToVoltage(adc->cycleSingle());
|
||||
ign_box_sts.coils34.peak_p_in = adc->convertToVoltage(adc->cycleSingle());
|
||||
ign_box_sts.coils34.peak_n_in = adc->convertToVoltage(adc->cycleSingle());
|
||||
ign_box_sts.coils12.peak_p_out =adc->convertToVoltage(adc->cycleSingle());
|
||||
ign_box_sts.coils12.peak_n_out =adc->convertToVoltage(adc->cycleSingle());
|
||||
ign_box_sts.coils34.peak_p_out =adc->convertToVoltage(adc->cycleSingle());
|
||||
ign_box_sts.coils34.peak_n_out =adc->convertToVoltage(adc->cycleSingle());
|
||||
ign_box_sts.coils12.peak_p_out = adc->convertToVoltage(adc->cycleSingle());
|
||||
ign_box_sts.coils12.peak_n_out = adc->convertToVoltage(adc->cycleSingle());
|
||||
ign_box_sts.coils34.peak_p_out = adc->convertToVoltage(adc->cycleSingle());
|
||||
ign_box_sts.coils34.peak_n_out = adc->convertToVoltage(adc->cycleSingle());
|
||||
ign_box_sts.adc_read_time = (int32_t)(esp_timer_get_time() - start_adc_read);
|
||||
adc->stopConversion();
|
||||
}
|
||||
@@ -300,6 +309,7 @@ void rtIgnitionTask::rtIgnitionTask_realtime(void *pvParameters)
|
||||
///////////// CLASS MEMBER DEFINITIONS /////////////
|
||||
rtIgnitionTask::rtIgnitionTask(const rtTaskParams params, const uint32_t history_size, const uint32_t queue_size, const uint8_t core, std::mutex &fs_mutex, fs::FS &filesystem) : m_params(params), m_filesystem(filesystem), m_fs_mutex(fs_mutex), m_core(core), m_max_history(history_size)
|
||||
{
|
||||
LOG_WARN("Starting Manager for [", m_params.name.c_str(), "]");
|
||||
// create queue buffers
|
||||
m_queue = xQueueCreate(queue_size, sizeof(ignitionBoxStatus));
|
||||
if (!m_queue)
|
||||
@@ -318,12 +328,12 @@ rtIgnitionTask::rtIgnitionTask(const rtTaskParams params, const uint32_t history
|
||||
m_active_history = std::unique_ptr<PSHistory>(&m_history_0);
|
||||
m_save_history = std::unique_ptr<PSHistory>(&m_history_1);
|
||||
|
||||
LOG_WARN("Starting Manager for [", m_params.name.c_str(), "]");
|
||||
m_name = (std::string("man_") + m_params.name).c_str();
|
||||
// auto task_success = pdPASS;
|
||||
auto task_success = xTaskCreatePinnedToCore(
|
||||
rtIgnitionTask_manager,
|
||||
(std::string("man_") + m_params.name).c_str(),
|
||||
8192,
|
||||
m_name.c_str(),
|
||||
RT_TASK_STACK,
|
||||
(void *)this,
|
||||
m_params.rt_priority >> 2,
|
||||
&m_manager_handle,
|
||||
@@ -362,14 +372,15 @@ void rtIgnitionTask::run()
|
||||
m_last_data = millis();
|
||||
m_manager_status = rtTaskStatus::RUNNING;
|
||||
// if history buffer is full swap buffers and if enabled save history buffer
|
||||
if (m_counter_status >= m_active_history->size())
|
||||
if (m_counter_status >= m_max_history)
|
||||
{
|
||||
LOG_DEBUG("Save for Buffer Full: ", m_counter_status);
|
||||
m_counter_status = 0;
|
||||
m_partial_save = false; // reset partial save flag on new data cycle
|
||||
std::swap(m_active_history, m_save_history);
|
||||
if (m_enable_save)
|
||||
saveHistory(*m_save_history, m_history_path); // directly call the save task function to save without delay
|
||||
// saveHistory(m_save_history, m_history_path); // directly call the save task function to save without delay
|
||||
LOG_INFO("Save History");
|
||||
}
|
||||
|
||||
// update filtered data
|
||||
@@ -391,15 +402,14 @@ void rtIgnitionTask::run()
|
||||
if (m_counter_status > 0 && !m_partial_save)
|
||||
{
|
||||
LOG_DEBUG("Save Partial: ", m_counter_status);
|
||||
m_active_history->resize(m_counter_status);
|
||||
saveHistory(*m_active_history, m_history_path);
|
||||
m_active_history->resize(m_max_history);
|
||||
// m_active_history->resize(m_counter_status);
|
||||
// saveHistory(m_active_history, m_history_path);
|
||||
// m_active_history->resize(m_max_history);
|
||||
m_counter_status = 0;
|
||||
m_partial_save = true;
|
||||
}
|
||||
m_manager_status = rtTaskStatus::IDLE;
|
||||
}
|
||||
delay(5); // yeld to another task
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user