Mutex simplicity studio – does not work from another file

Mutex simplicity studio – does not work from another file

Home Forums Real-Time Kernels Mutex simplicity studio – does not work from another file

This topic contains 3 replies, has 3 voices, and was last updated by  Valentin Kulikov 5 days, 11 hours ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #25605

    Valentin Kulikov
    Participant

    Hello
    let me briefly outline the situation, in main.c file I have created mutex:
    #include “bsp/siliconlabs/generic/include/bsp_os.h”
    static OS_MUTEX I2C_Mutex;
    int main(void)
    {
    OSInit(&err); /* Initialize the Kernel. */
    /* Check error code. */
    APP_RTOS_ASSERT_DBG((RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE), 1);

    OSMutexCreate((OS_MUTEX *)&I2C_Mutex,
    (CPU_CHAR *)”I2C Mutex”,
    (RTOS_ERR *)&err);…
    follows tasks definition

    OSStart(&err); /* Start the kernel. */
    /* Check error code. */
    APP_RTOS_ASSERT_DBG((RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE), 1);

    return (1);
    }
    if calling OSMutexPend – OSMutexPost mutext within main.c file it works, but
    if calling from other file like app.c it stops completely program execution for some reason, I have tried define
    static OS_MUTEX I2C_Mutex;
    within app.h header file and remove it from main.c file, this does not help
    If I have define mutex again prior to call OSMutexPend – OSMutexPost it works, this looks strange to me.

    Do somebody of you have an idea what can be wrong?

    Here is reference what I have followed (there are several mistakes in code, once you copy and paste):
    https://doc.micrium.com/display/osiiidoc/Multiple+Tasks+Application+with+Kernel+Objects
    based soc thermometer rtos example for BGM13P22
    Thanks a lot,
    Valentin

    #25606

    Michael Rausch
    Participant

    The problem comes from having ‘I2C_Mutex’ defined as static, so it is visible only within ‘main.c’.
    Doing the same in ‘app.c’ defines a different variable (same name and different scope).

    #25613

    Farukh Chaudhry
    Participant

    Hello,

    As Michael has indicated, you need to make the variable OS_MUTEX I2C_Mutex a global variable. In the example code you referenced, that code is assumed to be in the same file.

    #25635

    Valentin Kulikov
    Participant

    thank you very much guys for your great help, now muttex works well, I have overseen static variable, my fault. This question is resolved, currently working on interrupts and have difficulties, released new question, believe will help too

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

View the complete site map

x
Loading...