mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
test soft_tim.py passed
This commit is contained in:
parent
cecaee8e63
commit
683ec49215
@ -1,4 +1,5 @@
|
||||
from PikaStdDevice import Timer
|
||||
import time
|
||||
|
||||
tim = Timer()
|
||||
cb_times = 0
|
||||
@ -9,10 +10,11 @@ def cb_test(signal):
|
||||
|
||||
tim.setCallback(cb_test, Timer.SIGNAL_ANY)
|
||||
tim.setId(-1) # -1 means soft timer
|
||||
tim.setPeriod(500) # 500ms
|
||||
tim.setPeriod(100) # 100ms
|
||||
tim.enable()
|
||||
|
||||
while True:
|
||||
if cb_times >= 10:
|
||||
time.sleep(0.1)
|
||||
if cb_times >= 3:
|
||||
tim.close()
|
||||
break
|
||||
|
@ -6,6 +6,7 @@
|
||||
typedef struct platform_data_SOFT_TIM {
|
||||
pika_platform_timer_t thread_timer;
|
||||
pika_platform_thread_t* thread;
|
||||
pika_bool need_exit;
|
||||
} platform_data_SOFT_TIM;
|
||||
|
||||
void _SOFT_TIM_thread(void* arg) {
|
||||
@ -18,6 +19,11 @@ void _SOFT_TIM_thread(void* arg) {
|
||||
pika_platform_thread_timer_cutdown(thread_timer, timeout_ms);
|
||||
while (!pika_platform_thread_timer_is_expired(thread_timer)) {
|
||||
pika_platform_thread_yield();
|
||||
if (platform_tim->need_exit) {
|
||||
platform_tim->need_exit = pika_false;
|
||||
pika_debug("SOFT_TIM: exit signal got, exit thread");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (cfg->event_callback_ena && cfg->event_callback != NULL) {
|
||||
cfg->event_callback(dev, PIKA_HAL_TIM_EVENT_SIGNAL_TIMEOUT);
|
||||
@ -39,6 +45,7 @@ int pika_hal_platform_SOFT_TIM_open(pika_dev* dev, char* name) {
|
||||
}
|
||||
|
||||
int pika_hal_platform_SOFT_TIM_close(pika_dev* dev) {
|
||||
pika_hal_platform_SOFT_TIM_ioctl_disable(dev);
|
||||
platform_data_SOFT_TIM* platform_tim = dev->platform_data;
|
||||
pikaFree(platform_tim, sizeof(platform_data_SOFT_TIM));
|
||||
return 0;
|
||||
@ -66,6 +73,10 @@ int pika_hal_platform_SOFT_TIM_ioctl_enable(pika_dev* dev) {
|
||||
int pika_hal_platform_SOFT_TIM_ioctl_disable(pika_dev* dev) {
|
||||
platform_data_SOFT_TIM* platform_tim = dev->platform_data;
|
||||
if (NULL != platform_tim->thread) {
|
||||
platform_tim->need_exit = pika_true;
|
||||
while (platform_tim->need_exit) {
|
||||
pika_platform_thread_yield();
|
||||
}
|
||||
pika_platform_thread_destroy(platform_tim->thread);
|
||||
platform_tim->thread = NULL;
|
||||
pika_debug("pika_hal_platform_SOFT_TIM_ioctl_disable: thread deleted");
|
||||
|
@ -6,6 +6,7 @@
|
||||
typedef struct platform_data_SOFT_TIM {
|
||||
pika_platform_timer_t thread_timer;
|
||||
pika_platform_thread_t* thread;
|
||||
pika_bool need_exit;
|
||||
} platform_data_SOFT_TIM;
|
||||
|
||||
void _SOFT_TIM_thread(void* arg) {
|
||||
@ -18,6 +19,11 @@ void _SOFT_TIM_thread(void* arg) {
|
||||
pika_platform_thread_timer_cutdown(thread_timer, timeout_ms);
|
||||
while (!pika_platform_thread_timer_is_expired(thread_timer)) {
|
||||
pika_platform_thread_yield();
|
||||
if (platform_tim->need_exit) {
|
||||
platform_tim->need_exit = pika_false;
|
||||
pika_debug("SOFT_TIM: exit signal got, exit thread");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (cfg->event_callback_ena && cfg->event_callback != NULL) {
|
||||
cfg->event_callback(dev, PIKA_HAL_TIM_EVENT_SIGNAL_TIMEOUT);
|
||||
@ -39,6 +45,7 @@ int pika_hal_platform_SOFT_TIM_open(pika_dev* dev, char* name) {
|
||||
}
|
||||
|
||||
int pika_hal_platform_SOFT_TIM_close(pika_dev* dev) {
|
||||
pika_hal_platform_SOFT_TIM_ioctl_disable(dev);
|
||||
platform_data_SOFT_TIM* platform_tim = dev->platform_data;
|
||||
pikaFree(platform_tim, sizeof(platform_data_SOFT_TIM));
|
||||
return 0;
|
||||
@ -66,6 +73,10 @@ int pika_hal_platform_SOFT_TIM_ioctl_enable(pika_dev* dev) {
|
||||
int pika_hal_platform_SOFT_TIM_ioctl_disable(pika_dev* dev) {
|
||||
platform_data_SOFT_TIM* platform_tim = dev->platform_data;
|
||||
if (NULL != platform_tim->thread) {
|
||||
platform_tim->need_exit = pika_true;
|
||||
while (platform_tim->need_exit) {
|
||||
pika_platform_thread_yield();
|
||||
}
|
||||
pika_platform_thread_destroy(platform_tim->thread);
|
||||
platform_tim->thread = NULL;
|
||||
pika_debug("pika_hal_platform_SOFT_TIM_ioctl_disable: thread deleted");
|
||||
|
@ -629,7 +629,6 @@ TEST_RUN_SINGLE_FILE(modbus,
|
||||
|
||||
TEST_RUN_SINGLE_FILE_PASS(proxy, proxy3, "test/python/proxy/proxy3.py")
|
||||
|
||||
TEST_RUN_SINGLE_FILE(stddevice, soft_tim, "test/python/PikaStdDevice/soft_tim.py")
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,5 @@
|
||||
from PikaStdDevice import Timer
|
||||
import time
|
||||
|
||||
tim = Timer()
|
||||
cb_times = 0
|
||||
@ -9,10 +10,11 @@ def cb_test(signal):
|
||||
|
||||
tim.setCallback(cb_test, Timer.SIGNAL_ANY)
|
||||
tim.setId(-1) # -1 means soft timer
|
||||
tim.setPeriod(500) # 500ms
|
||||
tim.setPeriod(100) # 100ms
|
||||
tim.enable()
|
||||
|
||||
while True:
|
||||
if cb_times >= 10:
|
||||
time.sleep(0.1)
|
||||
if cb_times >= 3:
|
||||
tim.close()
|
||||
break
|
||||
|
Loading…
x
Reference in New Issue
Block a user