This repository has been archived on 2025-02-28. You can view files and clone it, but cannot push or open issues or pull requests.
controller-hd/Tests/test.c

170 lines
4.1 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// #include "test.h"
// #include "test_bsp.h"
// #include <stdlib.h>
// #include <string.h>
// #include "uthash.h" // 确保包含 uthash 头文件
// struct my_struct
// {
// int id; // 键
// char name[50]; // 假设名字长度不超过 50
// UT_hash_handle hh; // uthash 句柄
// };
// struct my_struct *users = NULL; // 初始化哈希表
// // 定义空的 exit 函数
// void exit(int status)
// {
// // 在嵌入式系统中,通常不需要执行任何操作
// // 你可以在这里添加任何需要的清理代码
// while (1)
// {
// // 无限循环,确保函数不会返回
// }
// }
// void add_user(int user_id, const char *name)
// {
// struct my_struct *s;
// HASH_FIND_INT(users, &user_id, s); /* id already in the hash? */
// if (s == NULL)
// {
// s = (struct my_struct *)malloc(sizeof *s);
// if (s == NULL)
// {
// // 处理内存分配失败
// return;
// }
// s->id = user_id;
// HASH_ADD_INT(users, id, s); /* id is the key field */
// }
// strncpy(s->name, name, sizeof(s->name) - 1);
// s->name[sizeof(s->name) - 1] = '\0'; // 确保字符串以 null 结尾
// }
// struct my_struct *find_user(int user_id)
// {
// struct my_struct *s;
// HASH_FIND_INT(users, &user_id, s); /* s: output pointer */
// return s;
// }
// void delete_user(struct my_struct *user)
// {
// HASH_DEL(users, user); /* user: pointer to deletee */
// free(user);
// }
// static void test_uthash(void)
// {
// add_user(1, "Alice");
// add_user(2, "Bob");
// struct my_struct *user = find_user(1);
// if (user)
// {
// LOG_PRINT("Found user: %s\n", user->name);
// }
// user = find_user(2);
// if (user)
// {
// LOG_PRINT("Found user: %s\n", user->name);
// }
// delete_user(find_user(1));
// delete_user(find_user(2));
// }
// static void test_fpu_float(void)
// {
// ENABLE_TIM(TASK_TIM);
// static uint32_t use_time1 = 0, use_time2 = 0;
// uint16_t count = 30000;
// float32 x1 = 1.0f;
// float32 y1 = 2.1314f;
// float32 x2 = 1.0;
// float32 y2 = 2.1314;
// use_time1 = sys_millis();
// for (uint16_t i = 0; i < count; i++)
// {
// x1 *= y1;
// }
// use_time1 = sys_millis() - use_time1;
// use_time2 = sys_millis();
// for (uint16_t i = 0; i < count; i++)
// {
// x2 *= y2;
// }
// use_time2 = sys_millis() - use_time2;
// __NOP();
// }
// static void test_wl_flash(void)
// {
// uint32_t address = 0;
// wl_flash_t wf = {
// .wl_flag = TRUE,
// .addr = PVD_RESET_STORAGE_START_ADDRESS,
// .len = 2 * LL_FLASH_PAGE_SIZE,
// .page_size = LL_FLASH_PAGE_SIZE,
// .data_size = sizeof(device_reset_t),
// .write_gran = 8,
// .ops.srand = board_srand,
// .ops.read = flash_read,
// .ops.write = flash_write,
// .ops.erase_page = flash_erase_page,
// };
// wl_flash_init(&wf);
// wl_flash_erase(&wf);
// address = wl_flash_get_current_address(&wf);
// device_reset_t power_on;
// power_on.flag = PVD_RESET_FLAG;
// // 一页2048/16 = 128个数据,2页 = 256个数据i=255时数据从头开始
// for (uint16_t i = 0; i < 1000; i++)
// {
// wl_flash_write(&wf, (uint8_t *)&power_on, sizeof(device_reset_t));
// wl_flash_set_next_address(&wf);
// address = wl_flash_get_current_address(&wf);
// if (address == wf.addr)
// {
// __NOP();
// }
// }
// }
// void test(uint8_t flag)
// {
// switch (flag)
// {
// case TEST_DISABLE:
// return;
// case TEST_BSP:
// bsp_test();
// break;
// case TEST_POWER:
// power_test();
// break;
// case TEST_FPU_FLOAT:
// test_fpu_float();
// break;
// case TEST_WL_FLASH:
// test_wl_flash();
// break;
// case TEST_UTHASH:
// test_uthash();
// break;
// default:
// break;
// }
// }