English 中文(简体)
ARM cortex: mutex
原标题:ARM cortex: mutex using bit banding

鉴于在ARM Cortex M3上,我可以:

  • atomically read a single bit
  • atomically set a single bit
  • atomically clear a single bit

• 我如何把这些行动结合起来,以便开展一系列行动:

try lock
take lock
release lock

看来,<代码>try_lock or take_lock将要求开展两种并非原样的业务。

我是否需要更多控制权才能做到这一点? 可消除的全球中断会发生,但似乎应当采取更多的外科方法。

最佳回答

您的rwl_TryLock() ,如果锁在所叫时已经关了,则一定会退回失败(汇编者至少应当就没有回报价值的密码途径发出警告)。 如下:

int rwl_TryLock(volatile uint32_t *lock, int who){

    Var_SetBit_BB((uint32_t)lock, who);
    if(*lock == (1<<who)){ // check that we have exclusive access
        // got the lock!
        return 1;
    } 

    // do not have the lock
    Var_ResetBit_BB((uint32_t)lock, who); // clear the lock flag
    return 0;
}

请注意,上述工作不会重复要求同一24小时(例如,如果<代码>具体规定的任务= 1)。 前面的法典已经锁定,试图再次提出,但同样符合你的原文。

另外,中断也可能是残疾/在Corx M3上迅速残疾(这是对NVIC登记册的简单更新)。 您能否确保您的系统能够以另外几轮中断时间为生,使处理锁定数据结构的代码简单化(通常意味着更容易纠正)?

问题回答

某些人搜查后发现胎儿:

" ARM Cortex-M3 bit-banding ARM s microcontroller core offers yet another way to implement semaphores. Write access to variables in the bit-band alias region causes an atomic read–modify–write access to a memory location in the bit-band region at system bus level. How does that translate into semaphores? A variable in the bit-band region could serve as container for semaphores. Every client "owns" a bit in that container. Whenever a client needs to claim the semaphore, it sets its own bit by writing a 1 to the corresponding location in the bit-band alias region. It would then read the container (bit-band region) and check that no other bits are set, meaning the client has sucessfully claimed the semaphore. In case that other bits are set, the client would have to clear its own bit again, and retry (perhaps after waiting). " (source)

我的粗略(未经测试)解释如下:

/*
 * Frees a lock.
 *
 * @note lock must point to a fully aligned 32 bit integer.
 * (atomically set to 0)
 *
 * @returns 1 if successfull
 */
int rwl_FreeLock(volatile uint32_t *lock){
    *lock = 0;
    return 1; // always successful
}

/*
 * Attempts to acquire a lock
 * @param who is the client taking the lock
 * @lock pointer to the mutex (uint32_t value in memory)
 * @note lock must point to a fully aligned 32 bit integer.
 * (atomically set to 1 only if set to 0)
 */
int rwl_TryLock(volatile uint32_t *lock, int who){
    // initial check of lock
    if(*lock == 0){
        Var_SetBit_BB((uint32_t)lock, who);
        if(*lock == (1<<who)){ // check that we still have exclusive access
            // got the lock!
            return 1;
        } else {
                    // do not have the lock
            Var_ResetBit_BB((uint32_t)lock, who); // clear the lock flag
            return 0;
        }
    }
}

Var_Set_BB / Var_Reset_BB: set / clear a bit using bit Banding. (组)

然而,它并不发挥作用!

Bit子为这种情况赢得了一定的工作。 这只是一种在装置登记册档案和你的记忆中确定借方的真正 ne。 利用Load 专有和储存 排他性指示来执行你的ema光/变体。 在这里,你可以使用一个实例文件,利用这些指示实施一种ema动,并详细说明这一作用。

rel=“nofollow” http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0439b/CHDDIGAC.html

尽管如此,你可以通过借用借机来减少你的记忆。

我从未在异常低价竞标上使用过借方;我的倾向是对所有此类业务使用排他性/包裹。 采用排外法,将旧价值计算在内,计算新价值,并使用有条件的储存加以重写。 直到有条件的仓库成功(如果是第一次,它很可能是第二次)。





相关问题
Steps to read data from ARM microcontroller port

I am having trouble reading serial data from ARM LPC2378 microcontroller. Will I have to use UART or any GPIO port can be used?? is ayone having c code for it??

high speed tracing

I have an embedded board with a 32 Micro-controller, and an custom built OS, Unfortunately, as of now, connection to the PC is only through serial port, Internal memory is limited to 512KB. There are ...

Affordable, programmable device with gprs and simple sensors?

I ve got quite a fun challenge / work assignment. I m to monitor a couple of 5V light bulbs (warning lights) on a machine standing far out in no man s land. I m looking for an affordable device with ...

Alarm history stack or queue?

I m trying to develop an alarm history structure to be stored in non-volatile flash memory. Flash memory has a limited number of write cycles so I need a way to add records to the structure without ...

LD linker: Target address aligning but not address in ROM

I have a program that s resident in flash and will run from flash. Early in the program data segments are copied from flash to ram. I m using a linker script like (simplified): .text : { *(....

clear code for counting from 0 to 255 using 8-bit datatype

I was wondering if there is a clean way of counting from 0 to 255 using an 8 bit datatype, something like: for(uint8_t i(0);i<=255;++i) { .... } This obviously will not work but it makes it ...

热门标签