Skip to content

Commit 3fcf8cb

Browse files
duynguyenxaKhiemNguyenT
authored andcommitted
drivers: rx: rdp: Replace the define __builtin_rx_xchg for ZSDK
Replace the __builtin_rx_xchg with actual implementation when building with Zephyr SDK because Zephyr SDK hasn't support it yet Signed-off-by: Duy Nguyen <[email protected]>
1 parent e97e756 commit 3fcf8cb

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

drivers/rx/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@ Patch List:
6262
Impacted files:
6363
drivers/rx/rdp/src/r_riic_rx/src/r_riic_rx.c
6464
drivers/rx/rdp/src/r_riic_rx/src/targets/rx130/r_riic_rx130.c
65+
66+
* Replace the __builtin_rx_xchg with actual implementation
67+
because Zephyr SDK hasn't support it yet
68+
Impacted files:
69+
drivers/rx/rdp/src/r_bsp/mcu/all/r_rx_intrinsic_functions.h

drivers/rx/rdp/src/r_bsp/mcu/all/r_rx_intrinsic_functions.h

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,23 @@ Macro definitions
111111
#elif defined(__GNUC__)
112112

113113
/* void __builtin_rx_xchg (int *, int *) */
114+
#if __has_builtin (__builtin_rx_xchg)
114115
#define R_BSP_EXCHANGE(x, y) __builtin_rx_xchg((int *)(x), (int *)(y))
116+
#else
117+
static inline void rx_xchg(int *a, int *b)
118+
{
119+
int temp;
120+
__asm__ __volatile__ (
121+
"mov %2, %0\n\t" // temp = *b
122+
"xchg [%1], %0\n\t" // *a <-> temp
123+
"mov %0, %2\n\t" // *b = temp
124+
: "=&r"(temp) // temp is output only
125+
: "r"(a), "m"(*b)
126+
: "memory"
127+
);
128+
}
129+
#define R_BSP_EXCHANGE(x, y) rx_xchg((int *)(x), (int *)(y))
130+
#endif /* __builtin_rx_xchg */
115131

116132
#elif defined(__ICCRX__)
117133

@@ -713,7 +729,7 @@ Macro definitions
713729

714730
/* Invalid for ICCRX.
715731
Because the initilaze function of TFU is called automatically when the TFU function is called. */
716-
#define R_BSP_INIT_TFU()
732+
#define R_BSP_INIT_TFU()
717733
#endif /* BSP_MCU_TFU_VERSION == 1 */
718734
#endif
719735

@@ -736,7 +752,7 @@ Macro definitions
736752

737753
#endif
738754

739-
/* ---------- Uses the trigonometric function unit to calculate the arc tangent of x and y and the square root of the
755+
/* ---------- Uses the trigonometric function unit to calculate the arc tangent of x and y and the square root of the
740756
sum of squares of these values at the same time. (single precision) ---------- */
741757
#if defined(__CCRX__)
742758

@@ -765,7 +781,7 @@ Macro definitions
765781
/* void __sincosfx(signed long fx, signed long *sin, signed long *cos) */
766782
#define R_BSP_SINCOSFX(x, y, z) __sincosfx((int32_t)(x), (int32_t *)(y), (int32_t *)(z))
767783
#else
768-
#define R_BSP_SINCOSFX(x, y, z)
784+
#define R_BSP_SINCOSFX(x, y, z)
769785
#endif
770786

771787
#elif defined(__GNUC__)
@@ -788,7 +804,7 @@ Macro definitions
788804
/* signed long __sinfx(signed long fx) */
789805
#define R_BSP_SINFX(x) __sinfx((int32_t)(x))
790806
#else
791-
#define R_BSP_SINFX(x)
807+
#define R_BSP_SINFX(x)
792808
#endif
793809

794810
#elif defined(__GNUC__)
@@ -811,7 +827,7 @@ Macro definitions
811827
/* signed long __cosfx(signed long fx) */
812828
#define R_BSP_COSFX(x) __cosfx((int32_t)(x))
813829
#else
814-
#define R_BSP_COSFX(x)
830+
#define R_BSP_COSFX(x)
815831
#endif
816832

817833
#elif defined(__GNUC__)
@@ -826,15 +842,15 @@ Macro definitions
826842

827843
#endif
828844

829-
/* ---------- Uses the trigonometric function unit to calculate the arc tangent of x and y and the square root of the
845+
/* ---------- Uses the trigonometric function unit to calculate the arc tangent of x and y and the square root of the
830846
sum of squares of these values. (fixed-point numbers) ---------- */
831847
#if defined(__CCRX__)
832848

833849
#if __RENESAS_VERSION__ >= 0x03050000
834850
/* __atan2hypotfx(signed long y, signed long x, signed long *atan2, signed long *hypot) */
835851
#define R_BSP_ATAN2HYPOTFX(w, x, y, z) __atan2hypotfx((int32_t)(w), (int32_t)(x), (int32_t *)(y), (int32_t *)(z))
836852
#else
837-
#define R_BSP_ATAN2HYPOTFX(w, x, y, z)
853+
#define R_BSP_ATAN2HYPOTFX(w, x, y, z)
838854
#endif
839855

840856
#elif defined(__GNUC__)
@@ -859,7 +875,7 @@ Macro definitions
859875
/* signed long __atan2fx(signed long y, signed long x) */
860876
#define R_BSP_ATAN2FX(x, y) __atan2fx((int32_t)(x), (int32_t)(y))
861877
#else
862-
#define R_BSP_ATAN2FX(x, y)
878+
#define R_BSP_ATAN2FX(x, y)
863879
#endif
864880

865881
#elif defined(__GNUC__)
@@ -874,15 +890,15 @@ Macro definitions
874890

875891
#endif
876892

877-
/* ---------- Uses the trigonometric function unit to calculate the square root of the
893+
/* ---------- Uses the trigonometric function unit to calculate the square root of the
878894
sum of squares of x and y. (fixed-point numbers) ---------- */
879895
#if defined(__CCRX__)
880896

881897
#if __RENESAS_VERSION__ >= 0x03050000
882898
/* signed long __hypotfx(signed long x, signed long y) */
883899
#define R_BSP_HYPOTFX(x, y) __hypotfx((int32_t)(x), (int32_t)(y))
884900
#else
885-
#define R_BSP_HYPOTFX(x, y)
901+
#define R_BSP_HYPOTFX(x, y)
886902
#endif
887903

888904
#elif defined(__GNUC__)

0 commit comments

Comments
 (0)