/* * @Date: 2025-07-15 11:12:00 * @Author: mypx * @LastEditors: mypx mypx_coder@163.com * @LastEditTime: 2025-09-24 14:24:04 * @FilePath: data_sampling.c * @Description: * Copyright (c) 2025 by mypx, All Rights Reserved. */ #include "data_sampling.h" #include "et_encoder_utils.h" #include "et_log.h" #include "pm_common.h" #include "servo.h" #include #include uint16_t adc_raw_buffer[DATA_PROCESS_UNIT_COUNT] = {0}; float sampling_rate = 0; static void *mq_pool[8]; struct rt_messagequeue adc_mq; /* 半缓冲完成回调 */ // void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef *hadc) // { // if (hadc->Instance == ADC1) // { // __HAL_DMA_CLEAR_FLAG(hadc->DMA_Handle, __HAL_DMA_GET_HT_FLAG_INDEX(hadc->DMA_Handle)); // uint16_t *ptr = &adc_raw_buffer[0]; // pm_system_led_on(); // rt_mq_send(&adc_mq, &ptr, sizeof(ptr)); // } // } /* 整个缓冲区完成回调 */ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc) { if (hadc->Instance == ADC1) { __HAL_DMA_CLEAR_FLAG(hadc->DMA_Handle, __HAL_DMA_GET_TC_FLAG_INDEX(hadc->DMA_Handle)); uint16_t *ptr = &adc_raw_buffer[0]; pm_system_led_toggle (); if (rt_mq_send(&adc_mq, &ptr, sizeof(ptr)) != RT_EOK) { ET_ERR("ADC MQ full!"); } } } void data_sampling_start(void) { pm_sampling_adc_start(adc_raw_buffer, DATA_PROCESS_UNIT_COUNT); pm_sampling_tim_start(); //pm_timestamp_start(); } void data_sampling_stop(void) { //pm_encoder_stop(); // pm_sampling_tim_stop(); // pm_timestamp_stop(); pm_sampling_adc_stop(); } int data_sampling_init(void) { pm_adc_init(); pm_sampling_tim_init(); pm_encoder_init(); //pm_timestamp_tim_init(); pm_encoder_start(); encoder_cpr = pm_encoder_get_cpr(); rt_mq_init(&adc_mq, "adc_mq", mq_pool, sizeof(void *), sizeof(mq_pool), RT_IPC_FLAG_FIFO); // test-> set state manually //pm_set_state(PM_CALIBRATION_STATE); sampling_rate = pm_sampling_tim_get_freq(); ET_WARN("Sampling rate:%.2f", sampling_rate); data_sampling_start(); // test->start at init return 0; } void m_start(int argc, char **argv) { if (argc != 2) { rt_kprintf("Usage: my_cmd \n"); return; } int rpm = atof(argv[1]); // 字符串转整型 //ET_INFO("rpm:%d", rpm); sv630p_speed_mode_start(&sv630p_handle, rpm); } MSH_CMD_EXPORT_ALIAS(m_start, m_start, test); void m_stop(void) { sv630p_speed_mode_stop(&sv630p_handle); } MSH_CMD_EXPORT(m_stop, motor stop); void m_back(void) { sv630p_speed_mode_stop(&sv630p_handle); sv630p_speed_mode_start(&sv630p_handle, -50); } MSH_CMD_EXPORT(m_back, motor backward); void m_fast(void) { sv630p_speed_mode_start(&sv630p_handle, 400); } MSH_CMD_EXPORT(m_fast, motor fast forward);