summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2020-05-02 16:21:38 +0700
committerhathach <[email protected]>2020-05-02 16:29:22 +0700
commit3ad0cd041b7a741b29fd1463c852f907a5ade80a (patch)
tree6554d9d46fffdb43b74defa2f0681953047ed4ee
parentac3c645dc114cfdbff4a232fecf35eb523d9b24f (diff)
clean up
-rw-r--r--src/portable/microchip/samg/dcd_samg.c55
1 files changed, 18 insertions, 37 deletions
diff --git a/src/portable/microchip/samg/dcd_samg.c b/src/portable/microchip/samg/dcd_samg.c
index 36f9b4832..296973247 100644
--- a/src/portable/microchip/samg/dcd_samg.c
+++ b/src/portable/microchip/samg/dcd_samg.c
@@ -106,47 +106,28 @@ static void xact_ep_read(uint8_t epnum, uint8_t* buffer, uint16_t xact_len)
//! Bitmap for all status bits in CSR that are not affected by a value 1.
-#define UDP_REG_NO_EFFECT_1_ALL (UDP_CSR_RX_DATA_BK0 | UDP_CSR_RX_DATA_BK1 | UDP_CSR_STALLSENT | UDP_CSR_RXSETUP | UDP_CSR_TXCOMP)
+#define CSR_NO_EFFECT_1_ALL (UDP_CSR_RX_DATA_BK0 | UDP_CSR_RX_DATA_BK1 | UDP_CSR_STALLSENT | UDP_CSR_RXSETUP | UDP_CSR_TXCOMP)
-/*! Sets specified bit(s) in the UDP_CSR.
-* \param ep
-Endpoint number.
-* \param bits Bitmap to set to 1.
-*/
-#define csr_set(ep, bits) \
- do { \
- volatile uint32_t reg; \
- volatile uint32_t nop_count; \
- reg = UDP->UDP_CSR[ep]; \
- reg |= UDP_REG_NO_EFFECT_1_ALL; \
- reg |= (bits); \
- UDP->UDP_CSR[ep] = reg; \
- for (nop_count = 0; nop_count < 20; nop_count ++) {\
- __NOP(); \
- } \
- } while (0)
+// Per Specs: CSR need synchronization each write
+static inline void csr_set(uint8_t epnum, uint32_t mask)
+{
+ uint32_t const csr = UDP->UDP_CSR[epnum] | CSR_NO_EFFECT_1_ALL | mask;
+ UDP->UDP_CSR[epnum] = csr;
+ volatile uint32_t nop_count;
+ for (nop_count = 0; nop_count < 20; nop_count ++) __NOP();
+}
-/*! Clears specified bit(s) in the UDP_CSR.
-* \param ep
-Endpoint number.
-* \param bits Bitmap to set to 0.
-*/
-#define csr_clear(ep, bits) \
- do { \
- volatile uint32_t reg; \
- volatile uint32_t nop_count; \
- reg = UDP->UDP_CSR[ep]; \
- reg |= UDP_REG_NO_EFFECT_1_ALL; \
- reg &= ~(bits); \
- UDP->UDP_CSR[ep] = reg; \
- for (nop_count = 0; nop_count < 20; nop_count ++) {\
- __NOP(); \
- } \
- } while (0)
+// Per Specs: CSR need synchronization each write
+static inline void csr_clear(uint8_t epnum, uint32_t mask)
+{
+ uint32_t const csr = (UDP->UDP_CSR[epnum] | CSR_NO_EFFECT_1_ALL) & ~mask;
+ UDP->UDP_CSR[epnum] = csr;
+
+ volatile uint32_t nop_count;
+ for (nop_count = 0; nop_count < 20; nop_count ++) __NOP();
+}
-#define udp_clear_csr csr_clear
-#define udp_set_csr csr_set
/*------------------------------------------------------------------*/
/* Device API
*------------------------------------------------------------------*/