UP Task,Argpase

This commit is contained in:
JiXieShi
2024-05-10 13:47:39 +08:00
parent 84bc401ba4
commit be1d31e732
18 changed files with 591 additions and 63 deletions

10
demo/arg/t_arg.h Normal file
View File

@@ -0,0 +1,10 @@
//
// Created by lydxh on 2024/5/10.
//
#ifndef HW_LIB_T_ARG_H
#define HW_LIB_T_ARG_H
void Test_argpase();
#endif //HW_LIB_T_ARG_H

49
demo/arg/test.c Normal file
View File

@@ -0,0 +1,49 @@
#include "stdio.h"
#include "argpase.h"
enum Opt {
T0 = 0, T1, T2, T3, T4, T5
};
Option Opts[6] = {{"T0", T0},
{"T1", T1},
{"T2", T2},
{"T3", T3},
{"T4", T4},
{"T5", T5}};
void Test_argpase() {
OptList *Head = Options_Creat("Head", -1);
OptList *t;
int i;
for (i = 0; i < 6; i++) {
t = Options_CreatOpt(&Opts[i]);
Options_Add(Head, t);
}
Options_Print(Head);
char *s = "T1 52 T2 64 T5 72";//模拟串口参数传入
char *argv[20];
size_t argc;
argc = Str_To_Args(s, argv);
printf("\nargs\n");
for (i = 0; i < argc; ++i) {
printf("arg[%d]:%s\n", i, argv[i]);//打印参数拆分情况
}
OptId optid;
while ((optid = Options_Load(Head, argv, argc)) != -1) {//开始匹配 Optarg为匹配的参数(字符类型可atoi等转换)
switch (optid) {
case T0:
case T1:
case T2:
case T3:
case T4:
case T5:
printf("Opt_%s[%d]:%s\n", Optstr, optid, Optarg);
break;
default:
break;
}
}
}

View File

@@ -29,7 +29,7 @@ uint8_t SDA_Read() {
}
void Test_iic() {
HW_Dev_IIC dev = {
SW_Dev_IIC dev = {
.CLK_SET = CLK_Pin,
.SDA_SET = SDA_Set,
.SDA = SDA_Read,
@@ -38,14 +38,14 @@ void Test_iic() {
};
uint8_t internalAddress = 0x56;
uint32_t len = 10;
uint32_t len = 64;
uint8_t writeData[len];
uint8_t readData[len];
for (int i = 0; i < len; ++i) {
writeData[i] = rand() % 10;
writeData[i] = rand() % 200;
}
HW_IIC_WL(dev, internalAddress, writeData, len);
SW_IIC_WL(dev, internalAddress, writeData, len);
BufPrint("<IIC> TX", writeData, 8, len, 16);
HW_IIC_RL(dev, internalAddress, readData, len, 1);
SW_IIC_RL(dev, internalAddress, readData, len, 1);
BufPrint("<IIC> RX", readData, 8, len, 16);
}

View File

@@ -33,7 +33,7 @@ uint8_t Miso_Pin() {
}
void Test_spi() {
HW_Dev_Spi ltl = {
SW_Dev_Spi ltl = {
.MOSI_SET=Mosi_Pin,
.SCK_SET=Sck_Pin,
.MISO=Miso_Pin,
@@ -43,20 +43,20 @@ void Test_spi() {
.ENDIAN=LTL,
};
uint8_t r, t = rand() % 10;
r = HW_SPI_RW(ltl, t);
r = SW_SPI_RW(ltl, t);
LOGI("<SPI> Tx:%d,Rx:%d", t, r);
uint8_t rbuf[64], tbuf[64];
for (int i = 0; i < 64; ++i) {
tbuf[i] = rand() % 10;
}
HW_SPI_RWL(ltl, rbuf, tbuf, 64);
SW_SPI_RWL(ltl, rbuf, tbuf, 64);
BufPrint("<SPI> TX", tbuf, 8, 64, 8);
BufPrint("<SPI> RX", rbuf, 8, 64, 8);
uint16_t rbuf16[64], tbuf16[64];
for (int i = 0; i < 64; ++i) {
tbuf16[i] = rand() % 1000;
}
HW_SPI_RWL16(ltl, rbuf16, tbuf16, 64);
SW_SPI_RWL16(ltl, rbuf16, tbuf16, 64);
BufPrint("<SPI> TX[16]", tbuf16, 16, 64, 16);
BufPrint("<SPI> RX[16]", rbuf16, 16, 64, 16);
}

10
demo/task/t_task.h Normal file
View File

@@ -0,0 +1,10 @@
//
// Created by lydxh on 2024/5/10.
//
#ifndef HW_LIB_T_TASK_H
#define HW_LIB_T_TASK_H
void Test_task();
#endif //HW_LIB_T_TASK_H

56
demo/task/test.c Normal file
View File

@@ -0,0 +1,56 @@
#include <sysinfoapi.h>
#include "stdio.h"
#include "task.h"
Task_t *task1;
Task_t *task2;
Task_t *task3;
Task_t *task4;
uint64_t GetTick() {
return (uint64_t) GetTickCount64();
}
void exampleTimer1Callback(Task_t *task, void *userData) {
printf("[%012ld] Task:%p callback-> %s.\r\n", GetTick(), task, (char *) userData);
TaskDel(task);
}
void exampleTimer2Callback(Task_t *task, void *userData) {
printf("[%012ld] Task:%p callback-> %s.\r\n", GetTick(), task, (char *) userData);
}
void exampleTimer3Callback(Task_t *task, void *userData) {
printf("[%012ld] Task:%p callback-> %s.\r\n", GetTick(), task, (char *) userData);
TaskSetTime(task, 4567);
TaskStart(task);
}
typedef struct CustomUserData {
int count;
char *str;
} CustomUserData;
void exampleTimer4Callback(Task_t *task, void *userData) {
CustomUserData *customUserData = (CustomUserData *) userData;
customUserData->count--;
printf("[%012ld] Task:%p callback-> %s.\r\n", GetTick(), task, customUserData->str);
if (customUserData->count > 0) {
TaskStart(task);
}
}
void Test_task() {
TaskInit(GetTick);
TaskCreat(task1, 1000, -1, exampleTimer1Callback, "1000ms CYCLE task");
TaskCreat(task2, 5000, -1, exampleTimer2Callback, "5000ms ONCE task");
TaskCreat(task3, 3456, 2, exampleTimer3Callback, "3456ms delay start, 4567ms CYCLE task");
CustomUserData customUserData = {
.count = 3,
.str = "2000ms 3 task"
};
TaskCreat(task4, 2000, 1, exampleTimer4Callback, &customUserData);
while (1) {
TaskRun();
}
}