diff --git a/base_c/include/embb/base/c/internal/atomic/and_assign.h b/base_c/include/embb/base/c/internal/atomic/and_assign.h index e145052..3654cd8 100644 --- a/base_c/include/embb/base/c/internal/atomic/and_assign.h +++ b/base_c/include/embb/base/c/internal/atomic/and_assign.h @@ -137,14 +137,13 @@ EMBB_DEFINE_AND_ASSIGN(4, "") uint32_t width = sizeof(value) == sizeof(uint32_t) ? 31 : sizeof(value) * 8; \ register uint64_t e_ins = ((uint64_t)width << 32) | pos; \ __asm__ __volatile__ ("dsync\n\t" \ - "mov.a %[pointer_to_value], %[add]\n\t" \ "loop_%=:\tld.w %H0, [%2]0\n\t" \ "insert %L0, %H0, %[value], %A1\n\t" \ "and %L0, %H0\n\t" \ "cmpswap.w [%2]0, %A0\n\t" \ "jne %H0, %L0, loop_%=" \ : "+d"(e_reg), [e_ins]"+d"(e_ins) \ - : [pointer_to_value]"a"(pointer_to_value), [value] "r" (value), [add] "d" (add) \ + : [add]"a"(add), [value] "r" (value) \ : "memory"); \ } #else diff --git a/base_c/include/embb/base/c/internal/atomic/fetch_and_add.h b/base_c/include/embb/base/c/internal/atomic/fetch_and_add.h index b18cfc1..9752ada 100644 --- a/base_c/include/embb/base/c/internal/atomic/fetch_and_add.h +++ b/base_c/include/embb/base/c/internal/atomic/fetch_and_add.h @@ -130,7 +130,6 @@ EMBB_DEFINE_FETCH_AND_ADD(4, "") uint32_t width = sizeof(new_value) == sizeof(uint32_t) ? 31 : sizeof(new_value) * 8; \ register uint64_t e_mask = ((uint64_t)width << 32) | pos; \ __asm__ __volatile__ ("dsync\n\t" \ - "mov.a %[pointer_to_value], %[add]\n\t" \ "loop_%=:\tld.w %H0, [%3]0\n\t" \ "insert %L0, %L0, %[new_value], %A1\n\t" \ "add" EMBB_ATOMIC_TC_SIZE_SUFFIX " %L0, %L0, %H0\n\t" \ @@ -138,7 +137,7 @@ EMBB_DEFINE_FETCH_AND_ADD(4, "") "jne %H0, %L0, loop_%=\n\t" \ "extr %[result], %H0, %A1" \ : "+d"(e_reg), [e_mask]"+d"(e_mask), [result] "=&d" (result) \ - : [pointer_to_value]"a"(pointer_to_value), [new_value] "r" (new_value), [add] "d" (add) \ + : [add]"a"(add), [new_value] "r" (new_value) \ : "memory"); \ return result; \ } diff --git a/base_c/include/embb/base/c/internal/atomic/or_assign.h b/base_c/include/embb/base/c/internal/atomic/or_assign.h index 81ac7e8..b29af08 100644 --- a/base_c/include/embb/base/c/internal/atomic/or_assign.h +++ b/base_c/include/embb/base/c/internal/atomic/or_assign.h @@ -122,14 +122,13 @@ EMBB_DEFINE_OR_ASSIGN(4, "") uint32_t width = sizeof(value) == sizeof(uint32_t) ? 31 : sizeof(value) * 8; \ register uint64_t e_ins = ((uint64_t)width << 32) | pos; \ __asm__ __volatile__ ("dsync\n\t" \ - "mov.a %[pointer_to_value], %[add]\n\t" \ "loop_%=:\tld.w %H0, [%2]0\n\t" \ "insert %L0, %L0, %[value], %A1\n\t" \ "or %L0, %H0\n\t" \ "cmpswap.w [%2]0, %A0\n\t" \ "jne %H0, %L0, loop_%=" \ : "+d"(e_reg), [e_ins]"+d"(e_ins) \ - : [pointer_to_value]"a"(pointer_to_value), [value] "r" (value), [add] "d" (add) \ + : [add]"a"(add), [value] "r" (value) \ : "memory"); \ } diff --git a/base_c/include/embb/base/c/internal/atomic/xor_assign.h b/base_c/include/embb/base/c/internal/atomic/xor_assign.h index 557a3f7..610bb9d 100644 --- a/base_c/include/embb/base/c/internal/atomic/xor_assign.h +++ b/base_c/include/embb/base/c/internal/atomic/xor_assign.h @@ -125,14 +125,13 @@ EMBB_DEFINE_XOR_ASSIGN(4, "") uint32_t width = sizeof(value) == sizeof(uint32_t) ? 31 : sizeof(value) * 8; \ register uint64_t e_ins = ((uint64_t)width << 32) | pos; \ __asm__ __volatile__ ("dsync\n\t" \ - "mov.a %[pointer_to_value], %[add]\n\t" \ "loop_%=:\tld.w %H0, [%2]0\n\t" \ "insert %L0, %L0, %[value], %A1\n\t" \ "xor %L0, %H0\n\t" \ "cmpswap.w [%2]0, %A0\n\t" \ "jne %H0, %L0, loop_%=" \ : "+d"(e_reg), [e_ins]"+d"(e_ins) \ - : [pointer_to_value]"a"(pointer_to_value), [value] "r" (value), [add] "d" (add) \ + : [add]"a"(add), [value] "r" (value) \ : "memory"); \ } diff --git a/base_c/src/time.c b/base_c/src/time.c index f49e3d3..2e92138 100644 --- a/base_c/src/time.c +++ b/base_c/src/time.c @@ -114,18 +114,16 @@ int embb_time_in(embb_time_t* time, const embb_duration_t* duration) { return EMBB_ERROR; } - uint64_t ticks_count = xTaskGetTickCount(); - time->seconds = ticks_count / configTICK_RATE_HZ; - time->nanoseconds = ((ticks_count % configTICK_RATE_HZ) * 1000000000ul)/configTICK_RATE_HZ; + uint32_t ticks_count = xTaskGetTickCount(); + time->seconds = ticks_count; - ticks_count = (uint64_t)(duration->seconds *configTICK_RATE_HZ + (duration->nanoseconds * configTICK_RATE_HZ / 1000000000ul)); + uint64_t duration_ticks = (uint64_t)(duration->seconds *configTICK_RATE_HZ + (duration->nanoseconds * configTICK_RATE_HZ / 1000000000ul)); - if (ticks_count > UINT32_MAX || time->seconds + duration->seconds > EMBB_TIME_MAX_SECONDS) { + if ( (uint64_t) (time->seconds + duration_ticks) > UINT32_MAX) { return EMBB_OVERFLOW; } - time->seconds += duration->seconds; - time->nanoseconds += duration->nanoseconds; + time->seconds += duration_ticks; return EMBB_SUCCESS; }