use WEAK for std.time

This commit is contained in:
lyon 2022-12-20 22:44:39 +08:00
parent 8e3691f388
commit fce67d309d
6 changed files with 32 additions and 13 deletions

View File

@ -14,7 +14,7 @@ void PikaStdDevice_Time_sleep_ms(PikaObj* self, int ms) {
#elif defined(_WIN32)
Sleep(ms);
#else
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
__platform_sleep_ms(ms);
#endif
}
void PikaStdDevice_Time_sleep_s(PikaObj* self, int s) {
@ -23,13 +23,12 @@ void PikaStdDevice_Time_sleep_s(PikaObj* self, int s) {
#elif defined(_WIN32)
Sleep(s * 1000);
#else
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
__platform_sleep_s(s);
#endif
}
void PikaStdDevice_Time_platformGetTick(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platformGetTick() need to be override.");
obj_setInt(self, "tick", __platform_get_tick_ms());
}
/*

View File

@ -80,7 +80,7 @@ void PikaStdDevice_UART_platformEnable(PikaObj* self) {
void PikaStdDevice_UART_platformRead(PikaObj* self) {
int len = obj_getInt(self, "length");
obj_setBytes(self, "_readData", NULL, len + 1);
char* buff = obj_getBytes(self, "_readData");
char* buff = (char*)obj_getBytes(self, "_readData");
pika_dev* dev = _get_dev(self);
pika_hal_read(dev, buff, len);
obj_setStr(self, "readData", buff);
@ -113,7 +113,7 @@ void PikaStdDevice_UART_platformReadBytes(PikaObj* self) {
void PikaStdDevice_UART_platformWriteBytes(PikaObj* self) {
uint8_t* data = obj_getBytes(self, "writeData");
int len = obj_getBytesLen(self, "writeData");
int len = obj_getBytesSize(self, "writeData");
pika_dev* dev = _get_dev(self);
pika_hal_write(dev, data, len);
}

View File

@ -14,7 +14,7 @@ void PikaStdDevice_Time_sleep_ms(PikaObj* self, int ms) {
#elif defined(_WIN32)
Sleep(ms);
#else
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
__platform_sleep_ms(ms);
#endif
}
void PikaStdDevice_Time_sleep_s(PikaObj* self, int s) {
@ -23,13 +23,12 @@ void PikaStdDevice_Time_sleep_s(PikaObj* self, int s) {
#elif defined(_WIN32)
Sleep(s * 1000);
#else
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
__platform_sleep_s(s);
#endif
}
void PikaStdDevice_Time_platformGetTick(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platformGetTick() need to be override.");
obj_setInt(self, "tick", __platform_get_tick_ms());
}
/*

View File

@ -80,7 +80,7 @@ void PikaStdDevice_UART_platformEnable(PikaObj* self) {
void PikaStdDevice_UART_platformRead(PikaObj* self) {
int len = obj_getInt(self, "length");
obj_setBytes(self, "_readData", NULL, len + 1);
char* buff = obj_getBytes(self, "_readData");
char* buff = (char*)obj_getBytes(self, "_readData");
pika_dev* dev = _get_dev(self);
pika_hal_read(dev, buff, len);
obj_setStr(self, "readData", buff);
@ -113,7 +113,7 @@ void PikaStdDevice_UART_platformReadBytes(PikaObj* self) {
void PikaStdDevice_UART_platformWriteBytes(PikaObj* self) {
uint8_t* data = obj_getBytes(self, "writeData");
int len = obj_getBytesLen(self, "writeData");
int len = obj_getBytesSize(self, "writeData");
pika_dev* dev = _get_dev(self);
pika_hal_write(dev, data, len);
}

View File

@ -253,3 +253,21 @@ PIKA_WEAK PIKA_BOOL __pks_hook_arg_cache_filter(void* self) {
PIKA_WEAK void __platform_thread_delay(void) {
return;
}
PIKA_WEAK uint64_t __platform_get_tick_ms(void){
__platform_printf("Error: __platform_get_tick_ms need implementation!\r\n");
while (1) {
}
}
PIKA_WEAK void __platform_sleep_ms(uint32_t ms){
__platform_printf("Error: __platform_sleep_ms need implementation!\r\n");
while (1) {
}
}
PIKA_WEAK void __platform_sleep_s(uint32_t s){
__platform_printf("Error: __platform_sleep_s need implementation!\r\n");
while (1) {
}
}

View File

@ -173,7 +173,10 @@ void __platform_panic_handle(void);
void __pks_hook_instruct(void);
PIKA_BOOL __pks_hook_arg_cache_filter(void* self);
PIKA_WEAK void __platform_thread_delay(void);
void __platform_thread_delay(void);
uint64_t __platform_get_tick_ms(void);
void __platform_sleep_ms(uint32_t ms);
void __platform_sleep_s(uint32_t s);
#if PIKA_FLOAT_TYPE_DOUBLE
#define pika_float double