mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
!269 增加了PIKA_WIN_PTHREAD_ENABLE的支持,给modbus_rt增加了regs_binding的接口API
Merge pull request !269 from SenySunny/master
This commit is contained in:
commit
f9a7e10210
@ -37,6 +37,7 @@ class _rtu:
|
||||
def _slave_set_addr(self, addr: int) -> int: ...
|
||||
def _slave_set_strict(self, strict: int) -> int: ...
|
||||
def _slave_add_block(self, name: str, type: int, addr: int, nums: int) -> int: ...
|
||||
def _slave_regs_binding(self, regs: any, type: int, addr: int, nums: int) -> int: ...
|
||||
def _slave_set_pre_ans_callback(self, cb: any) -> int: ...
|
||||
def _slave_set_done_callback(self, cb: any) -> int: ...
|
||||
def _slave_set_dev_binding(self, flag: int) -> int: ...
|
||||
@ -64,6 +65,7 @@ class _tcp:
|
||||
def _slave_set_addr(self, addr: int) -> int: ...
|
||||
def _slave_set_strict(self, strict: int) -> int: ...
|
||||
def _slave_add_block(self, name: str, type: int, addr: int, nums: int) -> int: ...
|
||||
def _slave_regs_binding(self, regs: any, type: int, addr: int, nums: int) -> int: ...
|
||||
def _slave_set_pre_ans_callback(self, cb: any) -> int: ...
|
||||
def _slave_set_done_callback(self, cb: any) -> int: ...
|
||||
def _slave_set_dev_binding(self, flag: int) -> int: ...
|
||||
|
@ -330,8 +330,8 @@ int _modbus_rt__rtu__close(PikaObj *self) {
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__slave_set_addr(PikaObj *self, int addr) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus rtu slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -358,8 +358,8 @@ int _modbus_rt__rtu__slave_set_addr(PikaObj *self, int addr) {
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__slave_set_strict(PikaObj *self, int strict) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus rtu slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -386,8 +386,8 @@ int _modbus_rt__rtu__slave_set_strict(PikaObj *self, int strict) {
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__slave_add_block(PikaObj *self, char* name, int type, int addr, int nums) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus rtu slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -416,7 +416,7 @@ int _modbus_rt__rtu__slave_add_block(PikaObj *self, char* name, int type, int ad
|
||||
}
|
||||
obj_setBytes(self, name, NULL, len);
|
||||
uint8_t* block = obj_getBytes(self, name);
|
||||
ret = modbus_rtu_add_block(dev,type, addr, block, nums);
|
||||
ret = modbus_rtu_add_block(dev, type, addr, block, nums);
|
||||
if(MODBUS_RT_EOK != ret){
|
||||
pika_platform_printf("modbus_rtu_add_block error, code: %d.\n", ret);
|
||||
return 0;
|
||||
@ -425,13 +425,60 @@ int _modbus_rt__rtu__slave_add_block(PikaObj *self, char* name, int type, int ad
|
||||
#endif
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__slave_regs_binding(PikaObj *self, Arg* regs, int type, int addr, int nums) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus rtu slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
ArgType t = arg_getType(regs);
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
pika_platform_printf("modbus_rtu_regs_binding: the regs buf type is only for bytes.\n");
|
||||
return 0;
|
||||
}
|
||||
rtu_modbus_device_t dev = (rtu_modbus_device_t)obj_getPtr(self, "dev");
|
||||
if(NULL == dev) {
|
||||
pika_platform_printf("modbus_rtu_regs_binding error, dev is NULL.\n");
|
||||
return 0;
|
||||
}
|
||||
if(MODBUS_SLAVE != dev->mode){
|
||||
pika_platform_printf("modbus_rtu_regs_binding is only for slave.\n");
|
||||
return 0;
|
||||
}
|
||||
if(0 != dev->status) {
|
||||
pika_platform_printf("modbus_rtu_regs_binding error, dev is opened.\n");
|
||||
return 0;
|
||||
}
|
||||
size_t regs_size = arg_getBytesSize(regs);
|
||||
if((CIOLS == type) || (INPUTS == type)) {
|
||||
if(regs_size < nums) {
|
||||
pika_platform_printf("modbus_rtu_regs_binding: For CIOLS and INPUTS, the length of regs buf must be greater than nums.\n");
|
||||
return 0;
|
||||
}
|
||||
} else if((INPUT_REGISTERS == type) || (REGISTERS == type)) {
|
||||
if(regs_size < nums) {
|
||||
pika_platform_printf("modbus_rtu_regs_binding: For INPUT_REGISTERS and REGISTERS, the length of regs buf must be greater than 2 * nums.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
uint8_t* block = arg_getBytes(regs);
|
||||
ret = modbus_rtu_add_block(dev, type, addr, block, nums);
|
||||
if(MODBUS_RT_EOK != ret){
|
||||
pika_platform_printf("modbus_rtu_regs_binding error, code: %d.\n", ret);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (MODBUS_RTU_SLAVE_ENABLE) || (MODBUS_RTU_MASTER_ENABLE)
|
||||
PikaEventListener* g_modbus_rt_rtu_event_listener = NULL;
|
||||
#endif
|
||||
|
||||
int _modbus_rt__rtu__slave_pre_ans_handler(agile_modbus_t *ctx, int slave, int function,int addr, int quantity) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus rtu slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
char hash_str[32] = {0};
|
||||
@ -450,8 +497,8 @@ int _modbus_rt__rtu__slave_pre_ans_handler(agile_modbus_t *ctx, int slave, int f
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__slave_set_pre_ans_callback(PikaObj *self, Arg* cb) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus rtu slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -490,8 +537,8 @@ int _modbus_rt__rtu__slave_set_pre_ans_callback(PikaObj *self, Arg* cb) {
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__slave_done_handler(agile_modbus_t *ctx, int slave, int function,int addr, int quantity) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus rtu slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
char hash_str[32] = {0};
|
||||
@ -510,8 +557,8 @@ int _modbus_rt__rtu__slave_done_handler(agile_modbus_t *ctx, int slave, int func
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__slave_set_done_callback(PikaObj *self, Arg* cb) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus rtu slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -550,8 +597,8 @@ int _modbus_rt__rtu__slave_set_done_callback(PikaObj *self, Arg* cb) {
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__slave_set_dev_binding(PikaObj *self, int flag) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus rtu slave is not activated.\n");
|
||||
return 0;
|
||||
#elif (!SLAVE_DATA_DEVICE_BINDING)
|
||||
pika_platform_printf("SLAVE_DATA_DEVICE_BINDING is not activated.\n");
|
||||
@ -582,8 +629,8 @@ int _modbus_rt__rtu__slave_set_dev_binding(PikaObj *self, int flag) {
|
||||
|
||||
|
||||
int _modbus_rt__rtu__master_set_server(PikaObj *self, char* saddr, int sport) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu master is not activated.\n");
|
||||
return 0;
|
||||
#elif (!MODBUS_SERIAL_OVER_TCP_ENABLE) && (!MODBUS_SERIAL_OVER_UDP_ENABLE)
|
||||
pika_platform_printf("modbus_rtu_set_over_type error, MODBUS_SERIAL_OVER_XXX_ENABLE is not ENABLE.\n");
|
||||
@ -609,8 +656,8 @@ int _modbus_rt__rtu__master_set_server(PikaObj *self, char* saddr, int sport) {
|
||||
}
|
||||
|
||||
char* _modbus_rt__rtu__master_get_saddr(PikaObj *self) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu master is not activated.\n");
|
||||
return NULL;
|
||||
#elif (!MODBUS_SERIAL_OVER_TCP_ENABLE) && (!MODBUS_SERIAL_OVER_UDP_ENABLE)
|
||||
pika_platform_printf("modbus_rtu_set_over_type error, MODBUS_SERIAL_OVER_XXX_ENABLE is not ENABLE.\n");
|
||||
@ -638,8 +685,8 @@ char* _modbus_rt__rtu__master_get_saddr(PikaObj *self) {
|
||||
}
|
||||
|
||||
PikaObj* _modbus_rt__rtu__slave_read_regs(PikaObj *self, int type, int addr, PikaTuple* val){
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus rtu slave is not activated.\n");
|
||||
return NULL;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -707,8 +754,8 @@ PikaObj* _modbus_rt__rtu__slave_read_regs(PikaObj *self, int type, int addr, Pik
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__slave_write_regs(PikaObj *self, int type, int addr, PikaTuple* val) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus rtu slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -794,8 +841,8 @@ int _modbus_rt__rtu__slave_write_regs(PikaObj *self, int type, int addr, PikaTup
|
||||
}
|
||||
|
||||
PikaObj* _modbus_rt__rtu__master_read_list(PikaObj *self, int slave, int fuction, int addr, PikaTuple* val) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu master is not activated.\n");
|
||||
return NULL;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -864,8 +911,8 @@ PikaObj* _modbus_rt__rtu__master_read_list(PikaObj *self, int slave, int fuction
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__master_write_int(PikaObj *self, int slave, int fuction, int addr, PikaTuple* val) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu master is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -904,8 +951,8 @@ int _modbus_rt__rtu__master_write_int(PikaObj *self, int slave, int fuction, int
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__master_write_list(PikaObj *self, int slave, int fuction, int addr, PikaTuple* val) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu master is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -991,8 +1038,8 @@ int _modbus_rt__rtu__master_write_list(PikaObj *self, int slave, int fuction, in
|
||||
}
|
||||
|
||||
int _modbus_rt__rtu__master_download(PikaObj *self, int slave, char* file_dev, char* file_master) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu master is not activated.\n");
|
||||
return 0;
|
||||
#elif (!MODBUS_P2P_ENABLE) || (!MODBUS_P2P_MASTER_ENABLE)
|
||||
pika_platform_printf("MODBUS_P2P_ENABLE and MODBUS_P2P_MASTER_ENABLE is not enabled.\n");
|
||||
@ -1027,8 +1074,8 @@ int _modbus_rt__rtu__master_download(PikaObj *self, int slave, char* file_dev, c
|
||||
|
||||
|
||||
int _modbus_rt__rtu__master_upload(PikaObj *self, int slave, char* file_dev, char* file_master) {
|
||||
#if (!MODBUS_RTU_SLAVE_ENABLE) && (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu is not activated.\n");
|
||||
#if (!MODBUS_RTU_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus rtu master is not activated.\n");
|
||||
return 0;
|
||||
#elif (!MODBUS_P2P_ENABLE) || (!MODBUS_P2P_MASTER_ENABLE)
|
||||
pika_platform_printf("MODBUS_P2P_ENABLE and MODBUS_P2P_MASTER_ENABLE is not enabled.\n");
|
||||
|
@ -247,8 +247,8 @@ int _modbus_rt__tcp__close(PikaObj *self) {
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__slave_set_addr(PikaObj *self, int addr) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus tcp slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -275,8 +275,8 @@ int _modbus_rt__tcp__slave_set_addr(PikaObj *self, int addr) {
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__slave_set_strict(PikaObj *self, int strict) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus tcp slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -303,8 +303,8 @@ int _modbus_rt__tcp__slave_set_strict(PikaObj *self, int strict) {
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__slave_add_block(PikaObj *self, char* name, int type, int addr, int nums) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus tcp slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -342,13 +342,60 @@ int _modbus_rt__tcp__slave_add_block(PikaObj *self, char* name, int type, int ad
|
||||
#endif
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__slave_regs_binding(PikaObj *self, Arg* regs, int type, int addr, int nums) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus tcp slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
ArgType t = arg_getType(regs);
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
pika_platform_printf("modbus_tcp_regs_binding: the regs buf type is only for bytes.\n");
|
||||
return 0;
|
||||
}
|
||||
tcp_modbus_device_t dev = (tcp_modbus_device_t)obj_getPtr(self, "dev");
|
||||
if(NULL == dev) {
|
||||
pika_platform_printf("modbus_tcp_regs_binding error, dev is NULL.\n");
|
||||
return 0;
|
||||
}
|
||||
if(MODBUS_SLAVE != dev->mode){
|
||||
pika_platform_printf("modbus_tcp_regs_binding is only for slave.\n");
|
||||
return 0;
|
||||
}
|
||||
if(0 != dev->status) {
|
||||
pika_platform_printf("modbus_tcp_regs_binding error, dev is opened.\n");
|
||||
return 0;
|
||||
}
|
||||
size_t regs_size = arg_getBytesSize(regs);
|
||||
if((CIOLS == type) || (INPUTS == type)) {
|
||||
if(regs_size < nums) {
|
||||
pika_platform_printf("modbus_tcp_regs_binding: For CIOLS and INPUTS, the length of regs buf must be greater than nums.\n");
|
||||
return 0;
|
||||
}
|
||||
} else if((INPUT_REGISTERS == type) || (REGISTERS == type)) {
|
||||
if(regs_size < nums) {
|
||||
pika_platform_printf("modbus_tcp_regs_binding: For INPUT_REGISTERS and REGISTERS, the length of regs buf must be greater than 2 * nums.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
uint8_t* block = arg_getBytes(regs);
|
||||
ret = modbus_tcp_add_block(dev, type, addr, block, nums);
|
||||
if(MODBUS_RT_EOK != ret){
|
||||
pika_platform_printf("modbus_tcp_regs_binding error, code: %d.\n", ret);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (MODBUS_TCP_SLAVE_ENABLE) || (MODBUS_TCP_MASTER_ENABLE)
|
||||
PikaEventListener* g_modbus_rt_tcp_event_listener = NULL;
|
||||
#endif
|
||||
|
||||
int _modbus_rt__tcp__slave_pre_ans_handler(agile_modbus_t *ctx, int slave, int function,int addr, int quantity) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus tcp slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
char hash_str[32] = {0};
|
||||
@ -367,8 +414,8 @@ int _modbus_rt__tcp__slave_pre_ans_handler(agile_modbus_t *ctx, int slave, int f
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__slave_set_pre_ans_callback(PikaObj *self, Arg* cb) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus tcp slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -407,8 +454,8 @@ int _modbus_rt__tcp__slave_set_pre_ans_callback(PikaObj *self, Arg* cb) {
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__slave_done_handler(agile_modbus_t *ctx, int slave, int function,int addr, int quantity) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus tcp slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
char hash_str[32] = {0};
|
||||
@ -427,8 +474,8 @@ int _modbus_rt__tcp__slave_done_handler(agile_modbus_t *ctx, int slave, int func
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__slave_set_done_callback(PikaObj *self, Arg* cb) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus tcp slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -467,8 +514,8 @@ int _modbus_rt__tcp__slave_set_done_callback(PikaObj *self, Arg* cb) {
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__slave_set_dev_binding(PikaObj *self, int flag) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus tcp slave is not activated.\n");
|
||||
return 0;
|
||||
#elif (!SLAVE_DATA_DEVICE_BINDING)
|
||||
pika_platform_printf("SLAVE_DATA_DEVICE_BINDING is not activated.\n");
|
||||
@ -499,8 +546,8 @@ int _modbus_rt__tcp__slave_set_dev_binding(PikaObj *self, int flag) {
|
||||
|
||||
|
||||
int _modbus_rt__tcp__master_set_server(PikaObj *self, char* saddr, int sport) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp master is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -523,8 +570,8 @@ int _modbus_rt__tcp__master_set_server(PikaObj *self, char* saddr, int sport) {
|
||||
}
|
||||
|
||||
char* _modbus_rt__tcp__master_get_saddr(PikaObj *self) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp master is not activated.\n");
|
||||
return NULL;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -549,8 +596,8 @@ char* _modbus_rt__tcp__master_get_saddr(PikaObj *self) {
|
||||
}
|
||||
|
||||
PikaObj* _modbus_rt__tcp__slave_read_regs(PikaObj *self, int type, int addr, PikaTuple* val){
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus tcp slave is not activated.\n");
|
||||
return NULL;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -618,8 +665,8 @@ PikaObj* _modbus_rt__tcp__slave_read_regs(PikaObj *self, int type, int addr, Pik
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__slave_write_regs(PikaObj *self, int type, int addr, PikaTuple* val) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE)
|
||||
pika_platform_printf("modbus tcp slave is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -705,8 +752,8 @@ int _modbus_rt__tcp__slave_write_regs(PikaObj *self, int type, int addr, PikaTup
|
||||
}
|
||||
|
||||
PikaObj* _modbus_rt__tcp__master_read_list(PikaObj *self, int slave, int fuction, int addr, PikaTuple* val) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp master is not activated.\n");
|
||||
return NULL;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -775,8 +822,8 @@ PikaObj* _modbus_rt__tcp__master_read_list(PikaObj *self, int slave, int fuction
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__master_write_int(PikaObj *self, int slave, int fuction, int addr, PikaTuple* val) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp master is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -815,8 +862,8 @@ int _modbus_rt__tcp__master_write_int(PikaObj *self, int slave, int fuction, int
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__master_write_list(PikaObj *self, int slave, int fuction, int addr, PikaTuple* val) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp master is not activated.\n");
|
||||
return 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
@ -902,8 +949,8 @@ int _modbus_rt__tcp__master_write_list(PikaObj *self, int slave, int fuction, in
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__master_download(PikaObj *self, int slave, char* file_dev, char* file_master) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp master is not activated.\n");
|
||||
return 0;
|
||||
#elif (!MODBUS_P2P_ENABLE) || (!MODBUS_P2P_MASTER_ENABLE)
|
||||
pika_platform_printf("MODBUS_P2P_ENABLE and MODBUS_P2P_MASTER_ENABLE is not enabled.\n");
|
||||
@ -938,8 +985,8 @@ int _modbus_rt__tcp__master_download(PikaObj *self, int slave, char* file_dev, c
|
||||
}
|
||||
|
||||
int _modbus_rt__tcp__master_upload(PikaObj *self, int slave, char* file_dev, char* file_master) {
|
||||
#if (!MODBUS_TCP_SLAVE_ENABLE) && (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp is not activated.\n");
|
||||
#if (!MODBUS_TCP_MASTER_ENABLE)
|
||||
pika_platform_printf("modbus tcp master is not activated.\n");
|
||||
return 0;
|
||||
#elif (!MODBUS_P2P_ENABLE) || (!MODBUS_P2P_MASTER_ENABLE)
|
||||
pika_platform_printf("MODBUS_P2P_ENABLE and MODBUS_P2P_MASTER_ENABLE is not enabled.\n");
|
||||
|
@ -87,15 +87,22 @@ class rtu(_modbus_rt._rtu):
|
||||
# 该函数仅对从机有效
|
||||
def add_block(self, name: str, type: int, addr: int, nums: int):
|
||||
return self._slave_add_block(name, type, addr, nums)
|
||||
# 该函数仅对从机有效
|
||||
def regs_binding(self, regs: bytes, type: int, addr: int, nums: int):
|
||||
return self._slave_regs_binding(regs, type, addr, nums)
|
||||
# 该函数仅对从机有效
|
||||
def set_pre_ans_callback(self, cb):
|
||||
return self._slave_set_pre_ans_callback(cb)
|
||||
# 该函数仅对从机有效
|
||||
def set_done_callback(self, cb):
|
||||
return self._slave_set_done_callback(cb)
|
||||
# 该函数仅对从机有效
|
||||
def set_dev_binding(self, flag: int):
|
||||
return self._slave_set_dev_binding(flag)
|
||||
# 该函数仅对主机有效
|
||||
def set_server(self, saddr: str,sport: int):
|
||||
return self._master_set_server(saddr,sport)
|
||||
# 该函数仅对主机有效
|
||||
def get_saddr(self):
|
||||
return self._master_get_saddr()
|
||||
def excuse(self, dir_slave: int, type_function: int, addr: int, *val):
|
||||
@ -158,15 +165,22 @@ class tcp(_modbus_rt._tcp):
|
||||
# 该函数仅对从机有效
|
||||
def add_block(self, name: str, type: int, addr: int, nums: int):
|
||||
return self._slave_add_block(name, type, addr, nums)
|
||||
# 该函数仅对从机有效
|
||||
def regs_binding(self, regs: bytes, type: int, addr: int, nums: int):
|
||||
return self._slave_regs_binding(regs, type, addr, nums)
|
||||
# 该函数仅对从机有效
|
||||
def set_pre_ans_callback(self, cb):
|
||||
return self._slave_set_pre_ans_callback(cb)
|
||||
# 该函数仅对从机有效
|
||||
def set_done_callback(self, cb):
|
||||
return self._slave_set_done_callback(cb)
|
||||
# 该函数仅对从机有效
|
||||
def set_dev_binding(self, flag: int):
|
||||
return self._slave_set_dev_binding(flag)
|
||||
# 该函数仅对主机有效
|
||||
def set_server(self, saddr: str,sport: int):
|
||||
return self._master_set_server(saddr,sport)
|
||||
# 该函数仅对主机有效
|
||||
def get_saddr(self):
|
||||
return self._master_get_saddr()
|
||||
def excuse(self, dir_slave: int, type_function: int, addr: int, *val):
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* This file is part of the PikaPython project.
|
||||
* http://github.com/pikastech/pikapython
|
||||
*
|
||||
@ -48,6 +48,62 @@
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#if PIKA_WIN_PTHREAD_ENABLE
|
||||
|
||||
struct timeval
|
||||
{
|
||||
long tv_sec; // 秒
|
||||
long tv_usec; // 微秒
|
||||
};
|
||||
|
||||
void usleep(unsigned long usec){
|
||||
HANDLE timer;
|
||||
LARGE_INTEGER interval;
|
||||
interval.QuadPart = (10 * usec);
|
||||
timer = CreateWaitableTimer(NULL, TRUE, NULL);
|
||||
SetWaitableTimer(timer, &interval, 0, NULL, NULL, 0);
|
||||
WaitForSingleObject(timer, INFINITE);
|
||||
CloseHandle(timer);
|
||||
}
|
||||
|
||||
int gettimeofday(struct timeval *tp, void *tzp){
|
||||
time_t clock;
|
||||
struct tm tm;
|
||||
SYSTEMTIME wtm;
|
||||
GetLocalTime(&wtm);
|
||||
tm.tm_year = wtm.wYear - 1900;
|
||||
tm.tm_mon = wtm.wMonth - 1;
|
||||
tm.tm_mday = wtm.wDay;
|
||||
tm.tm_hour = wtm.wHour;
|
||||
tm.tm_min = wtm.wMinute;
|
||||
tm.tm_sec = wtm.wSecond;
|
||||
tm. tm_isdst = -1;
|
||||
clock = mktime(&tm);
|
||||
tp->tv_sec = clock;
|
||||
tp->tv_usec = wtm.wMilliseconds * 1000;
|
||||
return (0);
|
||||
}
|
||||
|
||||
void timeradd(struct timeval *a, struct timeval *b, struct timeval *res){
|
||||
res->tv_sec = a->tv_sec + b->tv_sec;
|
||||
res->tv_usec = a->tv_usec + b->tv_usec;
|
||||
if (res->tv_usec >= 1000000) {
|
||||
res->tv_sec += res->tv_usec / 1000000;
|
||||
res->tv_usec %= 1000000;
|
||||
}
|
||||
}
|
||||
|
||||
void timersub(struct timeval *a, struct timeval *b, struct timeval *res){
|
||||
res->tv_sec = a->tv_sec - b->tv_sec;
|
||||
res->tv_usec = a->tv_usec - b->tv_usec;
|
||||
if (res->tv_usec < 0) {
|
||||
res->tv_sec -= 1;
|
||||
res->tv_usec += 1000000;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void pikaFree(void* mem, uint32_t size);
|
||||
void* pikaMalloc(uint32_t size);
|
||||
int pika_pvsprintf(char** buff, const char* fmt, va_list args);
|
||||
@ -559,7 +615,7 @@ PIKA_WEAK pika_platform_thread_t* pika_platform_thread_init(
|
||||
unsigned int stack_size,
|
||||
unsigned int priority,
|
||||
unsigned int tick) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
int res;
|
||||
pika_platform_thread_t* thread;
|
||||
void* (*thread_entry)(void*);
|
||||
@ -632,8 +688,10 @@ PIKA_WEAK pika_platform_thread_t* pika_platform_thread_init(
|
||||
}
|
||||
|
||||
PIKA_WEAK uint64_t pika_platform_thread_self(void) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux)
|
||||
return (uint64_t)pthread_self();
|
||||
#elif PIKA_WIN_PTHREAD_ENABLE
|
||||
return (uint64_t)(pthread_self().p);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
return (uint64_t)xTaskGetCurrentTaskHandle();
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
@ -652,7 +710,7 @@ PIKA_WEAK void pika_platform_thread_startup(pika_platform_thread_t* thread) {
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_thread_stop(pika_platform_thread_t* thread) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
pthread_mutex_lock(&(thread->mutex));
|
||||
pthread_cond_wait(&(thread->cond), &(thread->mutex));
|
||||
pthread_mutex_unlock(&(thread->mutex));
|
||||
@ -666,7 +724,7 @@ PIKA_WEAK void pika_platform_thread_stop(pika_platform_thread_t* thread) {
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_thread_start(pika_platform_thread_t* thread) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
pthread_mutex_lock(&(thread->mutex));
|
||||
pthread_cond_signal(&(thread->cond));
|
||||
pthread_mutex_unlock(&(thread->mutex));
|
||||
@ -680,7 +738,7 @@ PIKA_WEAK void pika_platform_thread_start(pika_platform_thread_t* thread) {
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_thread_destroy(pika_platform_thread_t* thread) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
if (NULL != thread) {
|
||||
pthread_detach(thread->thread);
|
||||
// pthread_join(thread->thread, NULL);
|
||||
@ -706,8 +764,8 @@ PIKA_WEAK void pika_platform_thread_destroy(pika_platform_thread_t* thread) {
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_thread_exit(pika_platform_thread_t* thread) {
|
||||
#ifdef __linux
|
||||
return pika_platform_thread_destroy(thread);
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
pika_platform_thread_destroy(thread);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
// vTaskDelete(NULL); // test on esp32c3
|
||||
if (NULL == thread) {
|
||||
@ -729,7 +787,7 @@ PIKA_WEAK void pika_platform_thread_exit(pika_platform_thread_t* thread) {
|
||||
}
|
||||
|
||||
PIKA_WEAK int pika_platform_thread_mutex_init(pika_platform_thread_mutex_t* m) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
return pthread_mutex_init(&(m->mutex), NULL);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
m->mutex = xSemaphoreCreateMutex();
|
||||
@ -744,7 +802,7 @@ PIKA_WEAK int pika_platform_thread_mutex_init(pika_platform_thread_mutex_t* m) {
|
||||
}
|
||||
|
||||
PIKA_WEAK int pika_platform_thread_mutex_lock(pika_platform_thread_mutex_t* m) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
return pthread_mutex_lock(&(m->mutex));
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
if (pdTRUE == xSemaphoreTake(m->mutex, portMAX_DELAY)) {
|
||||
@ -761,7 +819,7 @@ PIKA_WEAK int pika_platform_thread_mutex_lock(pika_platform_thread_mutex_t* m) {
|
||||
|
||||
PIKA_WEAK int pika_platform_thread_mutex_trylock(
|
||||
pika_platform_thread_mutex_t* m) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
return pthread_mutex_trylock(&(m->mutex));
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
if (pdTRUE == xSemaphoreTake(m->mutex, 0)) {
|
||||
@ -778,7 +836,7 @@ PIKA_WEAK int pika_platform_thread_mutex_trylock(
|
||||
|
||||
PIKA_WEAK int pika_platform_thread_mutex_unlock(
|
||||
pika_platform_thread_mutex_t* m) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
return pthread_mutex_unlock(&(m->mutex));
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
return xSemaphoreGive(m->mutex);
|
||||
@ -792,7 +850,7 @@ PIKA_WEAK int pika_platform_thread_mutex_unlock(
|
||||
|
||||
PIKA_WEAK int pika_platform_thread_mutex_destroy(
|
||||
pika_platform_thread_mutex_t* m) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
return pthread_mutex_destroy(&(m->mutex));
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
vSemaphoreDelete(m->mutex);
|
||||
@ -864,6 +922,9 @@ int pika_thread_recursive_mutex_destroy(pika_thread_recursive_mutex_t* m) {
|
||||
PIKA_WEAK void pika_platform_thread_timer_init(pika_platform_timer_t* timer) {
|
||||
#ifdef __linux
|
||||
timer->time = (struct timeval){0, 0};
|
||||
#elif PIKA_WIN_PTHREAD_ENABLE
|
||||
timer->platform_data = pikaMalloc(sizeof(struct timeval));
|
||||
*((struct timeval *)(timer->platform_data)) = (struct timeval){0, 0};
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
timer->time = 0;
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
@ -880,6 +941,12 @@ PIKA_WEAK void pika_platform_thread_timer_cutdown(pika_platform_timer_t* timer,
|
||||
gettimeofday(&now, NULL);
|
||||
struct timeval interval = {timeout / 1000, (timeout % 1000) * 1000};
|
||||
timeradd(&now, &interval, &timer->time);
|
||||
#elif PIKA_WIN_PTHREAD_ENABLE
|
||||
struct timeval *timer_temp = (struct timeval *)timer->platform_data;
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
struct timeval interval = {timeout / 1000, (timeout % 1000) * 1000};
|
||||
timeradd(&now, &interval, timer_temp);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
timer->time = platform_uptime_ms();
|
||||
timer->time += timeout;
|
||||
@ -900,6 +967,12 @@ PIKA_WEAK char pika_platform_thread_timer_is_expired(
|
||||
gettimeofday(&now, NULL);
|
||||
timersub(&timer->time, &now, &res);
|
||||
return ((res.tv_sec < 0) || (res.tv_sec == 0 && res.tv_usec <= 0));
|
||||
#elif PIKA_WIN_PTHREAD_ENABLE
|
||||
struct timeval *timer_temp = (struct timeval *)timer->platform_data;
|
||||
struct timeval now, res;
|
||||
gettimeofday(&now, NULL);
|
||||
timersub(timer_temp, &now, &res);
|
||||
return ((res.tv_sec < 0) || (res.tv_sec == 0 && res.tv_usec <= 0));
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
return platform_uptime_ms() > timer->time ? 1 : 0;
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
@ -919,6 +992,12 @@ PIKA_WEAK int pika_platform_thread_timer_remain(pika_platform_timer_t* timer) {
|
||||
gettimeofday(&now, NULL);
|
||||
timersub(&timer->time, &now, &res);
|
||||
return (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000;
|
||||
#elif PIKA_WIN_PTHREAD_ENABLE
|
||||
struct timeval *timer_temp = (struct timeval *)timer->platform_data;
|
||||
struct timeval now, res;
|
||||
gettimeofday(&now, NULL);
|
||||
timersub(timer_temp, &now, &res);
|
||||
return (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000;
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
uint32_t now;
|
||||
now = platform_uptime_ms();
|
||||
@ -941,7 +1020,7 @@ PIKA_WEAK int pika_platform_thread_timer_remain(pika_platform_timer_t* timer) {
|
||||
}
|
||||
|
||||
PIKA_WEAK unsigned long pika_platform_thread_timer_now(void) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
return (unsigned long)time(NULL);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
return (unsigned long)platform_uptime_ms();
|
||||
@ -956,7 +1035,7 @@ PIKA_WEAK unsigned long pika_platform_thread_timer_now(void) {
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_thread_timer_usleep(unsigned long usec) {
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
usleep(usec);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
TickType_t tick = 1;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* This file is part of the PikaPython project.
|
||||
* http://github.com/pikastech/pikapython
|
||||
*
|
||||
@ -262,6 +262,14 @@ typedef struct pika_platform_thread {
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
} pika_platform_thread_t;
|
||||
#elif PIKA_WIN_PTHREAD_ENABLE
|
||||
#define HAVE_STRUCT_TIMESPEC
|
||||
#include <pthread.h>
|
||||
typedef struct pika_platform_thread {
|
||||
pthread_t thread;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
} pika_platform_thread_t;
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
@ -298,7 +306,7 @@ void pika_platform_thread_start(pika_platform_thread_t* thread);
|
||||
void pika_platform_thread_destroy(pika_platform_thread_t* thread);
|
||||
void pika_platform_thread_exit(pika_platform_thread_t* thread);
|
||||
|
||||
#ifdef __linux
|
||||
#if defined(__linux) || (PIKA_WIN_PTHREAD_ENABLE)
|
||||
#include <pthread.h>
|
||||
typedef pthread_mutex_t pika_mutex_platform_data_t;
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
|
@ -503,6 +503,10 @@ extern "C" {
|
||||
#define PIKA_PLATFORM_NO_WEAK 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_WIN_PTHREAD_ENABLE
|
||||
#define PIKA_WIN_PTHREAD_ENABLE 0
|
||||
#endif
|
||||
|
||||
/* configuration validation */
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user