optimize test_can and test_timer

This commit is contained in:
Liu_Weichao
2023-12-06 15:35:42 +08:00
parent 4de08ed386
commit 4c8df066b7
3 changed files with 37 additions and 35 deletions

View File

@@ -60,7 +60,6 @@ void TestCAN(void)
frame_send.stdid = 0x55;
frame_send.rtr=0;
frame_send.data_lenth=8;
frame_send.data = data_buff;
struct CanSendConfigure frame_recv;
uint8_t recv_buff[65U] = {0};
@@ -69,13 +68,20 @@ void TestCAN(void)
// CAN write
while (1)
{
PrivTaskDelay(500);
PrivWrite(can_fd, &frame_send, NONE);
PrivTaskDelay(500);
// PrivTaskDelay(500);
// PrivWrite(can_fd, &frame_send, NONE);
// PrivTaskDelay(500);
PrivRead(can_fd, &frame_recv, NONE);
// if any data has received,Then printf message
if(frame_recv.data_lenth > 0){
printf("ID %08x:%s\n",frame_recv.exdid,frame_recv.data);
printf("ID %08x : \n",frame_recv.exdid);
for(int i = 0; i < frame_recv.data_lenth; i ++) {
printf("0x%x ", frame_recv.data[i]);
}
printf("\n");
frame_send.data = recv_buff;
PrivWrite(can_fd, &frame_send, NONE);
}
}

View File

@@ -23,12 +23,13 @@
void TimerFunction(union sigval sig_val)
{
static int cnt = 0;
printf("%s cnt %d\n", __func__, cnt++);
printf("%s cnt %d ms %d\n", __func__, cnt++, PrivGetTickTime());
}
void TestTimer(void)
{
int ret = 0;
static int count = 0;
int timer_flags;
timer_t timer_id;
struct sigevent evp;
@@ -40,7 +41,9 @@ void TestTimer(void)
evp.sigev_notify_function = TimerFunction;
evp.sigev_notify_attributes = &timer_flags;
ret = timer_create(CLOCK_REALTIME, &evp, &timer_id);
count++;
ret = PrivTimerCreate(count, &evp, &timer_id);
if (ret < 0) {
printf("%s create timer failed ret %d\n", __func__, ret);
return;
@@ -48,14 +51,14 @@ void TestTimer(void)
struct itimerspec value;
//active time interval
value.it_interval.tv_sec = 2;
value.it_interval.tv_nsec = 0;
value.it_interval.tv_sec = 0;
value.it_interval.tv_nsec = 1000000 * 10;
//first timer set time
value.it_value.tv_sec = 2;
value.it_value.tv_nsec = 0;
ret = timer_settime(timer_id, 1, &value, NULL);
ret = PrivTimerModify(timer_id, 1, &value, NULL);
if (ret < 0) {
printf("%s set timer time failed ret %d\n", __func__, ret);
return;