2017-11-01 13:30:17 +08:00
|
|
|
/*
|
2021-03-27 17:51:56 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2017-11-01 13:30:17 +08:00
|
|
|
*
|
2018-10-15 01:35:07 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2017-11-01 13:30:17 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2011-09-15 Bernard first version
|
2019-03-25 20:03:49 +08:00
|
|
|
* 2018-11-22 Jesven add rt_hw_cpu_id()
|
2017-11-01 13:30:17 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rthw.h>
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include <board.h>
|
|
|
|
|
2019-03-25 20:03:49 +08:00
|
|
|
#ifdef RT_USING_SMP
|
2019-09-26 18:13:07 +08:00
|
|
|
|
|
|
|
void rt_hw_spin_lock_init(rt_hw_spinlock_t *lock)
|
|
|
|
{
|
|
|
|
lock->slock = 0;
|
|
|
|
}
|
|
|
|
|
2019-03-25 20:03:49 +08:00
|
|
|
void rt_hw_spin_lock(rt_hw_spinlock_t *lock)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned long newval;
|
|
|
|
rt_hw_spinlock_t lockval;
|
|
|
|
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"pld [%0]"
|
|
|
|
::"r"(&lock->slock)
|
|
|
|
);
|
|
|
|
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"1: ldrex %0, [%3]\n"
|
|
|
|
" add %1, %0, %4\n"
|
|
|
|
" strex %2, %1, [%3]\n"
|
|
|
|
" teq %2, #0\n"
|
|
|
|
" bne 1b"
|
|
|
|
: "=&r" (lockval), "=&r" (newval), "=&r" (tmp)
|
|
|
|
: "r" (&lock->slock), "I" (1 << 16)
|
|
|
|
: "cc");
|
|
|
|
|
|
|
|
while (lockval.tickets.next != lockval.tickets.owner) {
|
|
|
|
__asm__ __volatile__("wfe":::"memory");
|
|
|
|
lockval.tickets.owner = *(volatile unsigned short *)(&lock->tickets.owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
__asm__ volatile ("dmb":::"memory");
|
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_spin_unlock(rt_hw_spinlock_t *lock)
|
|
|
|
{
|
|
|
|
__asm__ volatile ("dmb":::"memory");
|
|
|
|
lock->tickets.owner++;
|
|
|
|
__asm__ volatile ("dsb ishst\nsev":::"memory");
|
|
|
|
}
|
|
|
|
#endif /*RT_USING_SMP*/
|
|
|
|
|
2017-11-01 13:30:17 +08:00
|
|
|
/**
|
2019-03-25 20:03:49 +08:00
|
|
|
* @addtogroup ARM CPU
|
2017-11-01 13:30:17 +08:00
|
|
|
*/
|
|
|
|
/*@{*/
|
|
|
|
|
|
|
|
/** shutdown CPU */
|
2020-11-20 08:49:51 +08:00
|
|
|
RT_WEAK void rt_hw_cpu_shutdown()
|
2017-11-01 13:30:17 +08:00
|
|
|
{
|
2022-04-20 10:56:11 +08:00
|
|
|
rt_base_t level;
|
2019-03-25 20:03:49 +08:00
|
|
|
rt_kprintf("shutdown...\n");
|
|
|
|
|
|
|
|
level = rt_hw_interrupt_disable();
|
|
|
|
while (level)
|
|
|
|
{
|
|
|
|
RT_ASSERT(0);
|
|
|
|
}
|
2017-11-01 13:30:17 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 17:09:29 +08:00
|
|
|
#ifdef RT_USING_CPU_FFS
|
|
|
|
/**
|
|
|
|
* This function finds the first bit set (beginning with the least significant bit)
|
|
|
|
* in value and return the index of that bit.
|
|
|
|
*
|
|
|
|
* Bits are numbered starting at 1 (the least significant bit). A return value of
|
|
|
|
* zero from any of these functions means that the argument was zero.
|
|
|
|
*
|
|
|
|
* @return return the index of the first bit set. If value is 0, then this function
|
|
|
|
* shall return 0.
|
|
|
|
*/
|
|
|
|
int __rt_ffs(int value)
|
|
|
|
{
|
|
|
|
return __builtin_ffs(value);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-11-01 13:30:17 +08:00
|
|
|
/*@}*/
|