[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
    #else
    #define EXTERN
    #endif

    #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 OS_MAILBOX MyMailbox;
    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?
    Bar.
  • 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,
    Martin
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • The reported issue was resolved via our support ticket system.
    This thread will therefore be closed now.
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.