Skip to content

Commit

Permalink
ready for sync
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxCrazy1101 committed Mar 25, 2023
1 parent bfe5664 commit 1fa4292
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .eide/target 1.arm.options.v6.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"language-cpp": "c++03",
"one-elf-section-per-function": true,
"short-enums#wchar": true,
"warnings": "ac5-like-warnings"
"warnings": "ac5-like-warnings",
"link-time-optimization": true
},
"asm-compiler": {
"$use": "asm-auto"
Expand Down
2 changes: 2 additions & 0 deletions App/Include/my_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#ifdef __cplusplus
extern "C" {
#endif
#include "main.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "event_groups.h"

/**
* @brief 创建任务
Expand Down
112 changes: 95 additions & 17 deletions App/Source/app_task.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "stdio.h"
#include "stdarg.h"

#include "math.h"
#include "arm_math.h"

#include "my_app.h"
#include "bsp_led.h"
#include "bsp_key.h"
#include "adc.h"

/*
**********************************************************************************************************
函数声明
Expand All @@ -15,6 +19,7 @@ static void task_led(void *pvParameters);
static void task_adc0(void *pvParameters);
static void task_start(void *pvParameters);
static void task_user_if(void *pvParameters);
static void task_lcr(void *pvParameters);
static void vTaskMsgPro(void *pvParameters);
static void vTaskStart(void *pvParameters);
static void app_create_object(void);
Expand All @@ -25,13 +30,20 @@ static void thread_safe_printf(char *format, ...);
变量声明
**********************************************************************************************************
*/
/* 任务句柄 */
static TaskHandle_t xHandleTaskLED = NULL;
static TaskHandle_t xHandleTaskADC0 = NULL;
static TaskHandle_t xHandleTaskScan = NULL;
static TaskHandle_t xHandleTaskUserIF = NULL;
// static TaskHandle_t xHandleTaskMsgPro = NULL;
// static TaskHandle_t xHandleTaskStart = NULL;
static SemaphoreHandle_t xMutex = NULL;

/* 互斥量句柄 */
static SemaphoreHandle_t xMutex = NULL;
EventGroupHandle_t xCreatedEventGroup = NULL;

arm_rfft_fast_instance_f32 S;
uint32_t fft_size = 2048;

static void vTaskUsageRate(void)
{
Expand All @@ -47,39 +59,89 @@ void app_create_task(void)
{
/*进入临界区*/
taskENTER_CRITICAL();

/*创建按键扫描任务*/
xTaskCreate((TaskFunction_t)task_start,
(const char *)"task_scan",
(uint16_t)512,
/*创建LED任务*/
xTaskCreate((TaskFunction_t)task_led,
(const char *)"led_toggle",
(uint16_t)128,
(void *)NULL,
(UBaseType_t)16,
(TaskHandle_t *)&xHandleTaskScan);
(UBaseType_t)1,
(TaskHandle_t *)&xHandleTaskLED);
/*创建LED任务*/
xTaskCreate((TaskFunction_t)task_user_if,
(const char *)"task_user_if",
(uint16_t)512,
(void *)NULL,
(UBaseType_t)14,
(UBaseType_t)2,
(TaskHandle_t *)&xHandleTaskUserIF);
/*创建按键扫描任务*/
xTaskCreate((TaskFunction_t)task_start,
(const char *)"task_scan",
(uint16_t)512,
(void *)NULL,
(UBaseType_t)3,
(TaskHandle_t *)&xHandleTaskScan);
/*创建ADC0任务*/
xTaskCreate((TaskFunction_t)task_adc0,
(const char *)"app_adc0",
(uint16_t)512,
(void *)NULL,
(UBaseType_t)15,
(UBaseType_t)4,
(TaskHandle_t *)&xHandleTaskADC0);

/*创建LED任务*/
xTaskCreate((TaskFunction_t)task_led,
(const char *)"led_toggle",
/*创建LCR任务*/
xTaskCreate((TaskFunction_t)task_lcr,
(const char *)"app_lcr",
(uint16_t)512,
(void *)NULL,
(UBaseType_t)16,
(TaskHandle_t *)&xHandleTaskLED);
(UBaseType_t)15,
(TaskHandle_t *)&xHandleTaskADC0);

/*退出临界区,任务级临界区不允许嵌套,中断级允许 */
taskEXIT_CRITICAL();
}

/**
* @brief LCR测量 优先级
*
* @param pvParameters
*/
static void task_lcr(void *pvParameters)
{
/* 实数rfft点数 */
fft_size = 2048;

/* 初始化结构体S中的参数 */
arm_rfft_fast_init_f32(&S, fft_size);
// while (1) {
// if (os_evt_wait_or(StartTaskWaitFlag, 0xFFFF) == OS_R_EVT) {
// xResult = os_evt_get();

// switch (xResult) {
// case DspFFT2048Pro_15:
// /* 读取的是ADC3的位置 */
// g_DSO1->usCurPos = 10240 - DMA2_Stream1->NDTR;

// /* 读取的是ADC1的位置 */
// g_DSO2->usCurPos = 10240 - DMA2_Stream0->NDTR;

// DSO2_WaveTrig(g_DSO2->usCurPos);
// DSO1_WaveTrig(g_DSO1->usCurPos);
// DSO2_WaveProcess();
// DSO1_WaveProcess();
// break;

// case DspMultiMeterPro_0:
// g_uiAdcAvgSample = ADC_GetSampleAvgN();
// break;

// /* 其它位暂未使用 */
// default:
// printf_taskdbg("xResult = %x\r\n", xResult);
// break;
// }
// }
// }
}

/**
* @brief adc0信息读取
*
Expand Down Expand Up @@ -209,6 +271,13 @@ static void task_start(void *pvParameters)
* 返 回 值: 无
*********************************************************************************************************
*/

/**
* @brief 线程安全的printf方式
*
* @param format 同printf的参数。
* @param ... 在C中,当无法列出传递函数的所有实参的类型和数目时,可以用省略号指定参数表
*/
static void thread_safe_printf(char *format, ...)
{
char buf_str[200 + 1];
Expand All @@ -228,10 +297,12 @@ static void thread_safe_printf(char *format, ...)

xSemaphoreGive(xMutex);
}

void os_error_print()
{
printf("ERROR");
printf("OS STARTUP ERROR!\r\n");
}

/**
* @brief 任务通信变量初始化
*
Expand All @@ -245,6 +316,13 @@ static void app_create_object(void)
/* 没有创建成功,用户可以在这里加入创建失败的处理机制 */
os_error_print();
}
/* 创建事件标志组 */
xCreatedEventGroup = xEventGroupCreate();

if (xCreatedEventGroup == NULL) {
/* 没有创建成功,用户可以在这里加入创建失败的处理机制 */
os_error_print();
}
}

void app_main()
Expand Down
2 changes: 1 addition & 1 deletion Firmware/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#define __SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000)
#endif

#define __SYSTEM_CLOCK_240M_PLL_IRC16M (uint32_t)(240000000)
//#define __SYSTEM_CLOCK_240M_PLL_IRC16M (uint32_t)(240000000)
//#define __SYSTEM_CLOCK_240M_PLL_8M_HXTAL (uint32_t)(240000000)
//#define __SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000)

Expand Down
2 changes: 1 addition & 1 deletion GD32F470.sct
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ LR_IROM1 0x08000000 0x00100000 {
;mid_param.o(+RW +ZI)
}
RW_RAM1 0xC0000000 0x10000000 {
.ANY (EXRAM)
.ANY (EXTSDRAM)
}
}

11 changes: 9 additions & 2 deletions Hardware/Include/adc.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#ifndef ADC_H
#define ADC_H
#include "gd32f4xx.h"
/* ADC通道长度 */
#define ADC0_CHANNEL_LENGTH 2
extern uint16_t adc0_data[ADC0_CHANNEL_LENGTH];
extern uint16_t adc1_data[1024];

/* ADC数据缓存大小 */
#define ADC0_BUFFER_LENGTH ADC0_CHANNEL_LENGTH
#define ADC1_BUFFER_LENGTH 10240

extern uint16_t adc0_data[ADC0_BUFFER_LENGTH];
extern uint16_t adc1_data[ADC1_BUFFER_LENGTH];

void adc_config();
#endif // ADC_H
2 changes: 1 addition & 1 deletion Hardware/Include/bsp_sdram_exmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#define BSP_SDRAM_SIZE 0x100000

void bsp_exmc_sdram_init(uint32_t sdram_device);
void bsp_init_extsdram(uint32_t sdram_device);
uint32_t bsp_TestExtSDRAM(void);
void bsp_sdram_test(void);
#endif /* _BSP_SDRAM_FMC_H */
36 changes: 34 additions & 2 deletions Hardware/Source/adc.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
#include "adc.h"
#include "systick.h"
uint16_t adc0_data[ADC0_CHANNEL_LENGTH];
uint16_t adc1_data[1024];
uint16_t adc0_data[ADC0_BUFFER_LENGTH];
uint16_t adc1_data[ADC1_BUFFER_LENGTH];

const uint32_t g_TrigFreqTable[][2] =
{
/* 预分频/计数周期 */
{90, 1}, // 2.66Msps 168000000/2800000 = 60 => 60 * 1024
{120, 1}, // 2Msps 168000000/2000000 = 84 => 84 * 1024
{240, 1}, // 1Msps 168000000/1000000 = 168 => 168 * 1024
{480, 1}, // 500Ksps 168000000/500000 = 336 => 336 * 1024
{120, 10}, // 200Ksps 168000000/200000 = 840 => 840 * 1024

{240, 10}, // 100Ksps 168000000/100000 = 1680 => 1680 * 1024
{480, 10}, // 50Ksps 168000000/50000 = 3360 => 3360 * 1024
{120, 100}, // 20Ksps 168000000/20000 = 8400 => 8400 * 1024
{240, 100}, // 10Ksps 168000000/10000 = 16800 => 16800 * 1024
{480, 100}, // 5Ksps 168000000/5000 = 33600 => 33600 * 1024

// /* */
// {42000, 2048}, // 2Ksps 168000000/2000 = 84000 => 84000 * 1024
// {42000, 4096}, // 1Ksps 168000000/1000 = 168000 => 168000 * 1024
// {42000, 8192}, // 500sps 168000000/500 = 336000 => 336000 * 1024
// {42000, 20480}, // 200sps 168000000/200 = 840000 => 840000 * 1024
// {42000, 40960}, // 100sps 168000000/100 = 1680000 => 1680000 * 1024

// /* 不做支持 */
// {42000, 40960}, // 50sps
// {42000, 40960}, // 20sps
// {42000, 40960}, // 10sps
// {42000, 40960}, // 5sps
// {42000, 40960}, // 2sps
// {42000, 40960}, // 1sps
};

void adc0_config();
void adc1_config();
void adc_config()
Expand Down
11 changes: 6 additions & 5 deletions Hardware/Source/bsp_sdram_exmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @param sdram_device [EXMC_SDRAM_DEVICE0] 或者 [EXMC_SDRAM_DEVICE1]
*/
void bsp_exmc_sdram_init(uint32_t sdram_device)
void bsp_init_extsdram(uint32_t sdram_device)
{
uint32_t timeout = 0;

Expand Down Expand Up @@ -105,9 +105,9 @@ void bsp_exmc_sdram_init(uint32_t sdram_device)
.sdram_device = EXMC_SDRAM_DEVICE0,
.pipeline_read_delay = EXMC_PIPELINE_DELAY_2_HCLK,
.burst_read_switch = ENABLE,
.sdclock_config = EXMC_SDCLK_PERIODS_3_HCLK, // 使用2分频 240MHz/2=120MHz
.sdclock_config = EXMC_SDCLK_PERIODS_2_HCLK, // 使用2分频 240MHz/2=120MHz
.write_protection = DISABLE,
.cas_latency = EXMC_CAS_LATENCY_3_SDCLK, // CAS 也就是CL参数
.cas_latency = EXMC_CAS_LATENCY_2_SDCLK, // CAS 也就是CL参数
.internal_bank_number = EXMC_SDRAM_4_INTER_BANK,
.data_width = EXMC_SDRAM_DATABUS_WIDTH_16B,
.row_address_width = EXMC_SDRAM_ROW_ADDRESS_13,
Expand Down Expand Up @@ -145,7 +145,7 @@ void bsp_exmc_sdram_init(uint32_t sdram_device)
sdram_command_init_struct.auto_refresh_number = EXMC_SDRAM_AUTO_REFLESH_2_SDCLK;
sdram_command_init_struct.mode_register_content = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_1 |
SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL |
SDRAM_MODEREG_CAS_LATENCY_3 |
SDRAM_MODEREG_CAS_LATENCY_2 |
SDRAM_MODEREG_OPERATING_MODE_STANDARD |
SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
/* wait until the SDRAM controller is ready */
Expand All @@ -159,7 +159,8 @@ void bsp_exmc_sdram_init(uint32_t sdram_device)
/* 64ms, 8192-cycle refresh, 64ms/8192=7.81us */
/* SDCLK_Freq = SYS_Freq/2 */
/* (7.81 us * SDCLK_Freq) - 20 */
exmc_sdram_refresh_count_set(761);

exmc_sdram_refresh_count_set(917);

/* wait until the SDRAM controller is ready */
timeout = SDRAM_TIMEOUT;
Expand Down
2 changes: 1 addition & 1 deletion User/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extern volatile uint32_t ulHighFrequencyTimerCounts; /* 在高精度定时器中
/*************************************************************************************************************/
#define configAPPLICATION_ALLOCATED_HEAP 1 // main中手动分配内存到ccm
#define configSUPPORT_DYNAMIC_ALLOCATION 1 // 支持动态内存申请
#define configTOTAL_HEAP_SIZE ((size_t)(48 * 1024)) // 系统所有总的堆大小
#define configTOTAL_HEAP_SIZE ((size_t)(56 * 1024)) // 系统所有总的堆大小

/*************************************************************************************************************/
/* FreeRTOS与协程有关的配置选项 */
Expand Down
4 changes: 3 additions & 1 deletion User/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ void bsp_Init(void)
{
/* 开启系统配置时钟 */
rcu_periph_clock_enable(RCU_SYSCFG);
nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);

systick_config();
gpio_config();
bsp_key_config();
dma_config();
dac_config();
adc_config();
bsp_init_extsdram(EXMC_SDRAM_DEVICE0);
timer_clk_config();
tim2_enable();
tim3_enable();
Expand Down Expand Up @@ -114,7 +116,7 @@ int main(void)
// bsp_spi_norflash_init();
// basic_timer_config(24000, 10000);
// pwm_config(240, 10000);
// bsp_exmc_sdram_init(EXMC_SDRAM_DEVICE0);
// bsp_init_extsdram(EXMC_SDRAM_DEVICE0);
// printf("Initialization Complate!\n");
// printf("Get Flash ID: %X\n", norflash_read_JEDEC_ID());

Expand Down
2 changes: 1 addition & 1 deletion User/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ OF SUCH DAMAGE.

#include "gd32f4xx_direct_io.h"

#define USE_FREERTOS 1
#define USE_FREERTOS 1

#define RCU_LED1 RCU_GPIOE
#define PORT_LED1 GPIOE
Expand Down

0 comments on commit 1fa4292

Please sign in to comment.