You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2020/07/19 18:49:28 UTC

[incubator-nuttx] 03/07: AVR: Fix warnings from pointer casts and prototype

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit ff6e2e7b7ddbabacb11ff11024b178eae08950e8
Author: Brennan Ashton <ba...@brennanashton.com>
AuthorDate: Sun Jul 19 16:06:19 2020 +0000

    AVR: Fix warnings from pointer casts and prototype
    
    There was broken logic around serial initialization function
    prototype.  Pointers were also being cast directly to uint32
    without first being cast to uintptr.
    
    Signed-off-by: Brennan Ashton <ba...@brennanashton.com>
---
 arch/avr/src/avr/up_initialstate.c      | 10 +++++-----
 arch/avr/src/avr/up_schedulesigaction.c | 28 +++++++++++++++-------------
 arch/avr/src/common/up_internal.h       | 17 +++++++----------
 3 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/arch/avr/src/avr/up_initialstate.c b/arch/avr/src/avr/up_initialstate.c
index 6780866..5c63f23 100644
--- a/arch/avr/src/avr/up_initialstate.c
+++ b/arch/avr/src/avr/up_initialstate.c
@@ -85,12 +85,12 @@ void up_initial_state(struct tcb_s *tcb)
   /* Save the task entry point */
 
 #if !defined(REG_PC2)
-  xcp->regs[REG_PC0]   = (uint8_t)((uint16_t)tcb->start >> 8);
-  xcp->regs[REG_PC1]   = (uint8_t)((uint16_t)tcb->start & 0xff);
+  xcp->regs[REG_PC0]   = (uint8_t)((uintptr_t)tcb->start >> 8);
+  xcp->regs[REG_PC1]   = (uint8_t)((uintptr_t)tcb->start & 0xff);
 #else
-  xcp->regs[REG_PC0]   = (uint8_t)((uint32_t)tcb->start >> 16);
-  xcp->regs[REG_PC1]   = (uint8_t)((uint32_t)tcb->start >> 8);
-  xcp->regs[REG_PC2]   = (uint8_t)((uint32_t)tcb->start & 0xff);
+  xcp->regs[REG_PC0]   = (uint8_t)((uint32_t)(uintptr_t)tcb->start >> 16);
+  xcp->regs[REG_PC1]   = (uint8_t)((uintptr_t)tcb->start >> 8);
+  xcp->regs[REG_PC2]   = (uint8_t)((uintptr_t)tcb->start & 0xff);
 #endif
 
   /* Enable or disable interrupts, based on user configuration */
diff --git a/arch/avr/src/avr/up_schedulesigaction.c b/arch/avr/src/avr/up_schedulesigaction.c
index 955606d..f0d4f45 100644
--- a/arch/avr/src/avr/up_schedulesigaction.c
+++ b/arch/avr/src/avr/up_schedulesigaction.c
@@ -91,6 +91,7 @@
 void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
 {
   irqstate_t flags;
+  uintptr_t reg_ptr = (uintptr_t)up_sigdeliver;
 
   sinfo("tcb=0x%p sigdeliver=0x%p\n", tcb, sigdeliver);
 
@@ -136,9 +137,9 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
 
           else
             {
-              /* Save registers that must be protected while the signal handler
-               * runs. These will be restored by the signal trampoline after
-               * the signal(s) have been delivered.
+              /* Save registers that must be protected while the signal
+               * handler runs. These will be restored by the signal
+               * trampoline after the signal(s) have been delivered.
                */
 
               tcb->xcp.sigdeliver   = sigdeliver;
@@ -152,13 +153,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
               /* Then set up to vector to the trampoline with interrupts
                * disabled
                */
+
 #if !defined(REG_PC2)
-              g_current_regs[REG_PC0]   = (uint16_t)up_sigdeliver >> 8;
-              g_current_regs[REG_PC1]   = (uint16_t)up_sigdeliver & 0xff;
+              g_current_regs[REG_PC0] = (uint16_t)reg_ptr >> 8;
+              g_current_regs[REG_PC1] = (uint16_t)reg_ptr & 0xff;
 #else
-              g_current_regs[REG_PC0]   = (uint32_t)up_sigdeliver >> 16;
-              g_current_regs[REG_PC1]   = (uint32_t)up_sigdeliver >> 8;
-              g_current_regs[REG_PC2]   = (uint32_t)up_sigdeliver & 0xff;
+              g_current_regs[REG_PC0] = (uint32_t)reg_ptr >> 16;
+              g_current_regs[REG_PC1] = (uint32_t)reg_ptr >> 8;
+              g_current_regs[REG_PC2] = (uint32_t)reg_ptr & 0xff;
 #endif
               g_current_regs[REG_SREG] &= ~(1 << SREG_I);
 
@@ -196,12 +198,12 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
            */
 
 #if !defined(REG_PC2)
-          tcb->xcp.regs[REG_PC0]    = (uint16_t)up_sigdeliver >> 8;
-          tcb->xcp.regs[REG_PC1]    = (uint16_t)up_sigdeliver & 0xff;
+          tcb->xcp.regs[REG_PC0]    = (uint16_t)reg_ptr >> 8;
+          tcb->xcp.regs[REG_PC1]    = (uint16_t)reg_ptr & 0xff;
 #else
-          tcb->xcp.regs[REG_PC0]    = (uint32_t)up_sigdeliver >> 16;
-          tcb->xcp.regs[REG_PC1]    = (uint32_t)up_sigdeliver >> 8;
-          tcb->xcp.regs[REG_PC2]    = (uint32_t)up_sigdeliver & 0xff;
+          tcb->xcp.regs[REG_PC0]    = (uint32_t)reg_ptr >> 16;
+          tcb->xcp.regs[REG_PC1]    = (uint32_t)reg_ptr >> 8;
+          tcb->xcp.regs[REG_PC2]    = (uint32_t)reg_ptr & 0xff;
 
 #endif
           tcb->xcp.regs[REG_SREG]  &= ~(1 << SREG_I);
diff --git a/arch/avr/src/common/up_internal.h b/arch/avr/src/common/up_internal.h
index ae89d54..c853815 100644
--- a/arch/avr/src/common/up_internal.h
+++ b/arch/avr/src/common/up_internal.h
@@ -89,14 +89,14 @@ typedef void (*up_vector_t)(void);
 extern void g_intstackbase;
 #endif
 
-/* These 'addresses' of these values are setup by the linker script.  They are
- * not actual uint32_t storage locations! They are only used meaningfully in the
- * following way:
+/* These 'addresses' of these values are setup by the linker script.  They
+ * are not actual uint32_t storage locations! They are only used meaningfully
+ * in the following way:
  *
  *  - The linker script defines, for example, the symbol_sdata.
  *  - The declareion extern uint32_t _sdata; makes C happy.  C will believe
- *    that the value _sdata is the address of a uint32_t variable _data (it is
- *    not!).
+ *    that the value _sdata is the address of a uint32_t variable _data
+ *    (it is not!).
  *  - We can recoved the linker value then by simply taking the address of
  *    of _data.  like:  uint32_t *pdata = &_sdata;
  */
@@ -116,7 +116,7 @@ extern uint32_t _ebss;            /* End+1 of .bss */
  ****************************************************************************/
 
 /****************************************************************************
- * Public Functions
+ * Public Function Prototypes
  ****************************************************************************/
 
 #ifndef __ASSEMBLY__
@@ -150,11 +150,8 @@ void up_lowinit(void);
 
 /* Defined in chip/xxx_serial.c */
 
-#ifdef USE_EARLYSERIALINIT
+#ifdef CONFIG_DEV_CONSOLE
 void up_earlyserialinit(void);
-#endif
-
-#ifdef USE_SERIALDRIVER
 void up_serialinit(void);
 #endif