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

multiple instances of ITC objects in CMSIS-RTOS

Hello,

I'd like to write some reusabel code module to handle e.g. UART ports. Therefore I'd like to create a variable number (based on some kind of define...) of threads dealing with UART port 1,2,3 ... since it is possible to declare CMSIS-RTOS threads with a variable number of instances it could look like this:

#define UART_PORT_NUM 3

osThreadDef(uart_thread, osPriorityNormal, UART_PORT_NUM, 0)

my problem: If I need any kind of inter-thread communication (ITC) object, like mutexes or mail queues, for each of this threads I don't know how to declare them, since osMailQDef, osMutexDef and so on, are not designed with a "variable" number of instances...

Any suggestions?

Parents
  • I have the same issue. I need to create a generic buffer function
    that can safely pass data between threads using a Mutex. I want this to be
    reusable code, so I have no idea how many such buffers I will have.
    What I DO NOT want to do is create one set of buffer storage areas, and
    a matching set of osMutexDef definitions that I must coordinate. Yes, that
    would work, but I should not need to do so.

    So I have a typedef something like:

    typedef struct _SAFE_BUFFER { unsigned char *pBuffer; unsigned long iIndex; osMutexDef (SafeMutex);
    } SAFE_BUFFER;

    That won't work. The osMutexDef gives a syntax error.

    So I looked through cmsis_os.h and it appears all I need to do is create a const uint32_t
    variable and create the mutex with a cast to (const osMutexDef_t *) to a pointer to it.

    That actually compiles without error, but it does not work. I even ensured the variable
    was allocated in the same storage area, etc. but no work. I mangled the name with the
    "os_mutex_def_" prefix the way that cmsis_os.h does, still no work.

    I don't need a lecture about why I don't need to do this. I don't need to be told another ways
    of passing buffer data is better. I want a result with straight C reusable code that's simple and
    works like all the other code I have.

    The OS needs a place to store the actual mutex. I should be able to do that in a struct
    and then specify n number of them and initialize them individually. If CMSIS can't do
    that, then it was written incorrectly.

    I'll say it again. I don't care if some other way is better or more preferred. I want to
    do it like I have above. How can I make that work?

Reply
  • I have the same issue. I need to create a generic buffer function
    that can safely pass data between threads using a Mutex. I want this to be
    reusable code, so I have no idea how many such buffers I will have.
    What I DO NOT want to do is create one set of buffer storage areas, and
    a matching set of osMutexDef definitions that I must coordinate. Yes, that
    would work, but I should not need to do so.

    So I have a typedef something like:

    typedef struct _SAFE_BUFFER { unsigned char *pBuffer; unsigned long iIndex; osMutexDef (SafeMutex);
    } SAFE_BUFFER;

    That won't work. The osMutexDef gives a syntax error.

    So I looked through cmsis_os.h and it appears all I need to do is create a const uint32_t
    variable and create the mutex with a cast to (const osMutexDef_t *) to a pointer to it.

    That actually compiles without error, but it does not work. I even ensured the variable
    was allocated in the same storage area, etc. but no work. I mangled the name with the
    "os_mutex_def_" prefix the way that cmsis_os.h does, still no work.

    I don't need a lecture about why I don't need to do this. I don't need to be told another ways
    of passing buffer data is better. I want a result with straight C reusable code that's simple and
    works like all the other code I have.

    The OS needs a place to store the actual mutex. I should be able to do that in a struct
    and then specify n number of them and initialize them individually. If CMSIS can't do
    that, then it was written incorrectly.

    I'll say it again. I don't care if some other way is better or more preferred. I want to
    do it like I have above. How can I make that work?

Children
No data