nrfx_atomic_u32_store和nrfx_atomic_u32_fetch_store函数赋值操作
nrfx_atomic_u32_t test;
uint32_t ret;
ret = nrfx_atomic_u32_store(&test,4);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_store(&test,3);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_store(&test,2);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_store(&test,8);
NRF_LOG_INFO("ret %d test %d",ret,test);
- 运行结果
- nrfx_atomic_u32_store函数操作返回值和操作的原子变量值都一样
- nrfx_atomic_u32_fetch_store函数操作返回值为原子变量操作前的值,操作后的原子变量值为传参的值
nrfx_atomic_u32_t test = 0;
uint32_t ret;
ret = nrfx_atomic_u32_or(&test,4);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_or(&test,3);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_or(&test,2);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_or(&test,8);
NRF_LOG_INFO("ret %d test %d",ret,test);
- 运行结果
- nrfx_atomic_u32_or函数操作返回值和操作的原子变量值都一样
- nrfx_atomic_u32_fetch_or函数操作返回值为原子变量操作前的值,操作后的原子变量值为操作前原子变量值按位或上传参的值
nrfx_atomic_u32_t test = 0xff;
uint32_t ret;
ret = nrfx_atomic_u32_and(&test,0xfe);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_and(&test,0xfd);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_and(&test,0xfb);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_and(&test,0xf7);
NRF_LOG_INFO("ret %d test %d",ret,test);
- 运行结果
- nrfx_atomic_u32_and函数操作返回值和操作的原子变量值都一样
- nrfx_atomic_u32_fetch_and函数操作返回值为原子变量操作前的值,操作后的原子变量值为操作前原子变量值按位与上传参的值
nrfx_atomic_u32_t test = 0;
uint32_t ret;
ret = nrfx_atomic_u32_xor(&test,1);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_xor(&test,2);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_xor(&test,4);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_xor(&test,8);
NRF_LOG_INFO("ret %d test %d",ret,test);
- 运行结果
- nrfx_atomic_u32_xor函数操作返回值和操作的原子变量值都一样
- nrfx_atomic_u32_fetch_xor函数操作返回值为原子变量操作前的值,操作后的原子变量值为操作前原子变量值按位异或上传参的值
nrfx_atomic_u32_t test = 0;
uint32_t ret;
ret = nrfx_atomic_u32_add(&test,1);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_add(&test,2);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_add(&test,1);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_add(&test,2);
NRF_LOG_INFO("ret %d test %d",ret,test);
- 运行结果
- nrfx_atomic_u32_add函数操作返回值和操作的原子变量值都一样
- nrfx_atomic_u32_fetch_add函数操作返回值为原子变量操作前的值,操作后的原子变量值为操作前原子变量值加上传参的值
nrfx_atomic_u32_t test = 10;
uint32_t ret;
ret = nrfx_atomic_u32_sub(&test,1);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_sub(&test,2);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_sub(&test,1);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_sub(&test,2);
NRF_LOG_INFO("ret %d test %d",ret,test);
- 运行结果
- nrfx_atomic_u32_sub函数操作返回值和操作的原子变量值都一样
- nrfx_atomic_u32_fetch_sub函数操作返回值为原子变量操作前的值,操作后的原子变量值为操作前原子变量值减去传参的值
nrfx_atomic_u32_t test = 0;
uint32_t ret;
ret = nrfx_atomic_flag_set(&test);
NRF_LOG_INFO("ret %d test %d",ret,test);
test = 0;
ret = nrfx_atomic_flag_set_fetch(&test);
NRF_LOG_INFO("ret %d test %d",ret,test);
- 运行结果
- nrfx_atomic_flag_set函数操作返回值和操作的原子变量值都一样为真
- nrfx_atomic_flag_set_fetch函数操作返回值为原子变量操作前的值,操作后的原子变量值为操作前原子变量值为真
nrfx_atomic_u32_t test = 1;
uint32_t ret;
ret = nrfx_atomic_flag_clear(&test);
NRF_LOG_INFO("ret %d test %d",ret,test);
test = 1;
ret = nrfx_atomic_flag_clear_fetch(&test);
NRF_LOG_INFO("ret %d test %d",ret,test);
- 运行结果
- nrfx_atomic_flag_clear函数操作返回值和操作的原子变量值都一样为假
- nrfx_atomic_flag_clear_fetch函数操作返回值为原子变量操作前的值,操作后的原子变量值为操作前原子变量值为假
nrfx_atomic_u32_t test = 10;
uint32_t ret;
ret = nrfx_atomic_u32_sub_hs(&test,1);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_sub_hs(&test,10);
NRF_LOG_INFO("ret %d test %d",ret,test);
test = 10;
ret = nrfx_atomic_u32_fetch_sub_hs(&test,2);
NRF_LOG_INFO("ret %d test %d",ret,test);
ret = nrfx_atomic_u32_fetch_sub_hs(&test,10);
NRF_LOG_INFO("ret %d test %d",ret,test);
- 运行结果
- nrfx_atomic_u32_sub函数操作返回值和操作的原子变量值都一样,如果原子变量值小于传参的值,则原子变量操作的值和返回值为原子变量操作前的值
- nrfx_atomic_u32_fetch_sub函数操作返回值为原子变量操作前的值,操作后的原子变量值为操作前原子变量值减去传参的值,如果原子变量值小于传参的值,则原子变量操作的值和返回值为原子变量操作前的值
nrfx_atomic_u32_t test = 10;
bool ret;
uint32_t exp = 10;
ret = nrfx_atomic_u32_cmp_exch(&test,&exp,6);
NRF_LOG_INFO("ret %d test %d exp %d",ret,test,exp);
test = 8;
ret = nrfx_atomic_u32_cmp_exch(&test,&exp,5);
NRF_LOG_INFO("ret %d test %d exp %d",ret,test,exp);
运行结果
- nrfx_atomic_u32_cmp_exch函数参数1和参数2的值相等,返回值返回true,并且参数1的值更新为参数3的值,如果参数1的值不等于参数2的值,返回值返回false,并且参数2的值更新为参数1的值