多任务系统中存在一种潜在的风险。当一个任务在使用某个资源的过程中,即还没有完全结束对资源的访问时,便被切出运行态,使得资源处于非一致,不完整的状态
(1)访问外设
如两个任务并发访问LCD
(2)读-改-写操作
ARM7下的赋值操作被编译成多条汇编语言
/* The C code being compiled. */ 155: PORTA |= 0x01; /* The assembly code produced. */ 0x00000264 481C LDR R0,[PC,#0x0070] ; Obtain the address of PORTA 0x00000266 6801 LDR R1,[R0,#0x00] ; Read the value of PORTA into R1 0x00000268 2201 MOV R2,#0x01 ; Move the absolute constant 1 into R2 0x0000026A 4311 ORR R1,R2 ; OR R1 (PORTA) with R2 (constant 1) 0x0000026C 6001 STR R1,[R0,#0x00] ; Store the new value back to PORTA
(3)变量的非原子访问
更新结构体的多个成员变量,或者更新的变量长度超过了架构体系的自然长度,如更新了一个16位机上的32位变量
(4)函数重入
每个任务都单独维护自己的栈空间及其自身在的内存寄存器组中的值
如果一个函数除了访问自己栈空间上分配的数据或是内核寄存器中的数据外,还会访问其它数据,如全局变量等,则这个函数是不可重入的
不可重入的函数如果有多个任务同时访问会造成数据不一致
可重入函数举例
/* A parameter is passed into the function. This will either be
passed on the stack or in a CPU register. Either way is safe as
each task maintains its own stack and its own set of register
values. */
long lAddOneHundered( long lVar1 )
{
/* This function scope variable will also be allocated to the stack
or a register, depending on compiler and optimization level. Each
task or interrupt that calls this function will have its own copy
of lVar2. */
long lVar2;
lVar2 = lVar1 + 100;
/* Most likely the return value will be placed in a CPU register,
although it too could be placed on the stack. */
return lVar2;
}
不可重入函数举例
/* In this case lVar1 is a global variable so every task that calls
the function will be accessing the same single copy of the variable. */
long lVar1;
long lNonsenseFunction( void )
{
/* This variable is static so is not allocated on the stack. Each task
that calls the function will be accessing the same single copy of the
variable. */
static long lState = 0;
long lReturn;
switch( lState )
{
case 0 : lReturn = lVar1 + 10;
lState = 1;
break;
case 1 : lReturn = lVar1 + 20;
lState = 0;
break;
}
}
如果要面向“赛道”类的竞速型的循路应用,那么 Jetbot 范例中的 road_following 项目会更加适合,这个项目使用图像回归(Image Regression)的深度学习技术,是一种统计学上非常有用的数学模型。
外部中断是单片机实时地处理外部事件的一种内部机制。
雷军在个人年度演讲快结束时,顺手扔出了这个王炸——全尺寸仿生人形机器人CyberOne。
5月12日21:07,在包括上海在内的全球各地同时召开的新闻发布会上,天文学家向人们展示了位于我们银河系中心的超大质量黑洞的首张照片!
这次给大家展示的是荒井大师的MOC新作——Jeep Wrangler。说到荒井大师,这是一位灰常灰常值得尊敬的乐高科技MOC大师,其作品向来是外观,功能,可靠性近乎完美的平衡!最最最最关键的是,这位来自东瀛的大师其所有MOC作品的图纸都是免!费!的!
你怀恋小时候玩过的小霸王和街机游戏吗?使用RetroPie软件、树莓派和USB游戏控制器,不到一个小时,你就能重新捡起小时候玩过的游戏了:那些小时候没有打通的关,现在还有兴趣吗?
乐高前驱带悬挂底盘小车。
ESP32 芯片有34个物理GPIO管脚。每个GPIO管脚都可用作一个通用IO,或连接一个内部的外设信号。IO_MUX ¹、RTC IO MUX 和GPIO交换矩阵用于将信号从外设传输至GPIO管脚。