Passing unsafe pointers through a channel Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
DemoniacMilk
XCore Addict
Posts: 191
Joined: Tue Jul 05, 2016 2:19 pm

Passing unsafe pointers through a channel

Post by DemoniacMilk »

To allow a UI task to display values changed in another task (on same tile) i want to pass a pointer to the structure holding the relevant data as well as a memlock.
For both, I create an unsafe pointer that should be passed to the UI Task.

Code: Select all

    bridgeState_t       bridgeState;
    swlock_t            bridgeStateMemLock;
    unsafe{
        unsigned * unsafe   pBridgeState         = (unsigned  * unsafe)&bridgeState;
        swlock_t * unsafe   pBridgeStateMemLock  = (swlock_t  * unsafe)&bridgeStateMemLock;
    }
    
    // Initialize bridgeState
    
    unsafe{
        bootDone <: (unsigned)pBridgeState; // <--- error: pBridgeState undefined
        bootDone <: (unsigned)bridgeStateMemLock;
    }
however, when i try to output pBridgeState, an error is generated:
../src/sscEthBridge.xc:298:31: error: use of undeclared identifer `pBridgeState'

I dont understand why, as I do the same thing for bridgeStateMemLock, what does not generate an error.


View Solution
User avatar
ers35
Active Member
Posts: 62
Joined: Mon Jun 10, 2013 2:14 pm
Contact:

Post by ers35 »

The scope of pBridgeState is limited to the first unsafe block. You don't get an error for bridgeStateMemLock because it is available in the outer scope. You meant to use pBridgeStateMemLock.

Do the following instead:

Code: Select all

bridgeState_t       bridgeState;
swlock_t            bridgeStateMemLock;
unsafe{
    bootDone <: (bridgeState_t *unsafe)&bridgeState;
    bootDone <: (swlock_t *unsafe)&bridgeStateMemLock;
}
Post Reply