This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to Cast a void* ponter to a char without a warning?

I am using the RTX mailbox and a lot of it's usage uses casting of the mailbox message to other types - a really quick and clever way to use it(thanks Keil :). When I cast a void * vPointer to a unigned int - like (uint32_t)vPointer - the compiler is happy - but when I cast to a signed char - like (int8_t)vPointer the compiler complains and says:

Source_App\TerminalDrv.c(56): warning: #767-D: conversion from pointer to smaller integer

Now it all works fine ... but what do I do to stop it complaining?

uint32_t TerminalControllerGetChar(int8_t *pcRxedChar )
{
void * pvmbxTerminalRx;
uint32_t ulNoRxMessage,ulI;

        ulNoRxMessage = SIZEOF_OS_MBX_RXTERMINAL - os_mbx_check(mbxHandleTerminalRx);

        if(ulNoRxMessage == 0)
                return 0 ;
        else
        {
        for(ulI = 0;ulI < ulNoRxMessage ; ulI++)
                {
                if(os_mbx_wait(mbxHandleTerminalRx,(void **)&pvmbxTerminalRx,0x0000) == OS_R_OK)
                        {
                     *pcRxedChar  = (int8_t)pvmbxTerminalRx; 
                        pcRxedChar++;
                        }
                else
                        {
                        break;
                        }
                }
        }
return ulNoRxMessage;
}

Parents
  • Hi Per
    My mailbox sender looks like this - getting interupt data from the USART on a STM32xx part (the relevant section):

    void vTerminalInteruptHandler (void)
    {
    uint16_t usTermRxChar;
    
            if( TerminalUSARTx->SR & USART_RXNE_MASK)
                    {
                    usTermRxChar  = (uint16_t)(USART3->DR & (uint16_t)0x01FF);
                    isr_mbx_send(mbxHandleTerminalRx,(void*)usTermRxChar);
                    }
    }
    

    I added the (unsigned) as you suggested - so now that wait on mailbox part looks like this:

                    if(os_mbx_wait(mbxHandleTerminalRx,(void **)&pvmbxTerminalRx,0x0000) == OS_R_OK)
                            {
                            *pcRxedChar  = (int8_t)(unsigned)pvmbxTerminalRx;
                            pcRxedChar++;
                            }
    

    And now the compiler is happy ... and it works. That is what is so great about the scheme that uses the mailbox pointer to pass data - all the the nasty FIFO business etc is taken care of and you don't have to worry about allocating memory - really works a treat. I use the mailbox a lot and try and fit the data into 32 bits and out of 17x mailboxes that are used -only 4x use the mailbox pointer as intended - as a pointer to a array of message structs. Many thanks.

Reply
  • Hi Per
    My mailbox sender looks like this - getting interupt data from the USART on a STM32xx part (the relevant section):

    void vTerminalInteruptHandler (void)
    {
    uint16_t usTermRxChar;
    
            if( TerminalUSARTx->SR & USART_RXNE_MASK)
                    {
                    usTermRxChar  = (uint16_t)(USART3->DR & (uint16_t)0x01FF);
                    isr_mbx_send(mbxHandleTerminalRx,(void*)usTermRxChar);
                    }
    }
    

    I added the (unsigned) as you suggested - so now that wait on mailbox part looks like this:

                    if(os_mbx_wait(mbxHandleTerminalRx,(void **)&pvmbxTerminalRx,0x0000) == OS_R_OK)
                            {
                            *pcRxedChar  = (int8_t)(unsigned)pvmbxTerminalRx;
                            pcRxedChar++;
                            }
    

    And now the compiler is happy ... and it works. That is what is so great about the scheme that uses the mailbox pointer to pass data - all the the nasty FIFO business etc is taken care of and you don't have to worry about allocating memory - really works a treat. I use the mailbox a lot and try and fit the data into 32 bits and out of 17x mailboxes that are used -only 4x use the mailbox pointer as intended - as a pointer to a array of message structs. Many thanks.

Children
No data