[SOLVED] mailbox call from diffrent file

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] mailbox call from diffrent file

    I try to operate the mailbox example in embOS but to send the message not from the main.c but from other file.
    I write the create in the main.c

    #define MAIN
    OS_MAILBOX_Create(&MyMailbox, MAX_MSG_SIZE, MAX_MSG_NUM, &MyMailboxBuffer);
    where all the deafine and announce sit in main.h where I use extern for all except main that call them like this:

    #ifndef MAIN // only main use those variables and function as original
    #define EXTERN extern
    #define EXTERN

    #include "RTOS.h"
    /* MailBox defines */
    #define MAX_MSG_SIZE (9) // Max. number of bytes per message
    #define MAX_MSG_NUM (2) // Max. number of messages per Mailbox

    EXTERN char MyMailboxBuffer[MAX_MSG_SIZE * MAX_MSG_NUM];

    on file call SPI.c
    I write this
    #include "main.h"

    OS_MAILBOX_Put(&MyMailbox, "\nHello\0");

    When the program get to this line it jump to error function
    void OS_Error(OS_STATUS ErrCode)

    But if I run OS_MAILBOX_Put... from the main.c it save the message to the buffer.
    What do I miss?
  • Hi Bar,

    When OS_MAILBOX_Put() results in a call to OS_Error(), that indicates that the mailbox structure passed as parameter was not previously initialized by a call to OS_MAILBOX_Create().
    The error code in that case should be OS_ERR_INV_MAILBOX. Can you confirm this is the error code you're facing as well?

    If so, it seems "MyMailbox" was declared twice, which in turn would indicate that the extern declaration was implemented erroneously.

    You may check if MyMailbox was declared twice by searching the project's map file for that name, or else by comparing the addresses that are passed to OS_Mailbox_Put() in main.c and the other file within a debug session.

    Does this solve observed issue?

    Best regards,