This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Pass pointer to struct as UArg to constructClock

Other Parts Discussed in Thread: CC2640, SYSBIOS

My CC2640 system uses the following architecture:

There are multiple clocks running, which trigger different events in the main App loop. Each clock, when triggered, executes a common handler function. This handler function takes the Uarg parameter and &'s it to a global bitmask (events). This events variable is then read during the main App loop to determine which event functions should be executed.

The problem is that I've used all 16 bits of my events bitmask and I need more bits for more events. The plan is to create a struct which holds a 32 bit bitmask, and pass a pointer to the struct to Util_constructClock(). 

Will this work? Does Util_constructClock() expect a 16bit sized type for the UArg param?

  • UArg is a typedef'd unsigned int, which makes it 32 bits wide on TI's ARM MCUs. You can either switch to a 32-bit events bitmask directly, or pass a pointer to a struct containing it.

  • Matthew,

    Let me make sure I understand your description. You have several clock instances where each one is created using the same handler function but with a unique argument. When the clock handler function runs, it simply sets a bit in a global variable as determined by the given argument. You also have a task which is responsible for doing some work as defined by the global event mask. Have I go this correct?

    One suggestions is to use the clock instance argument to specify which bit to set, instead of passing in a literal mask. The handler function would use the argument to shift the bit before setting it into the global. This solves your 16-bit issue.

    But I have concerns about the over all approach. As the task works through the bits in the global event mask, it must have to clear the bit at some point. If the task were preempted by a clock function, then you might miss an event because when the task resumes, it will write a stale value into the global mask. This might also happen if one clock object preempts another clock object.

    I'm also wondering how the task knows when to run. Does it simple poll the event mask continuously or do you have another mechanism.

    My suggestion is to use an Event object (ti.sysbios.knl.Event). This module was designed for just this situation. The task can wait on the event object. The task will only run when the event has been posted. The event object has a mask of event bits. Each clock instance will post only its respective bit. All the concurrency issues will be addressed. The only remaining issue I can think of is if the task is running late and the same clock instance runs a second time. The task will only run once and you will loose one event. But maybe you can guard against this.

    ~Ramsey

  • I agree with Ramsey's concerns about the approach. Just to be clear, however, UArg is definitely 32 bits on TI ARM MCUs.

  • Hi Ramsey,

    Where could I find more info on this Event object you refer to in the last paragraph? 

    Thanks

  • Hello Mario,
    If you haven't already, can you please open a new thread for the issue you are having?

    Thanks
  • I can do that.