1. 代码
//sem.c
#include <rtthread.h>
#include <rtdevice.h>
#include "drv_gpio.h"
#define THREAD_PRIORITY 25
#define THREAD_TIMESLICE 5
#define LED3_PIN GET_PIN(B, 3)
ALIGN(RT_ALIGN_SIZE)
static char thread3_stack[1024];
static struct rt_thread thread3;
static struct rt_semaphore keyPress1_sem;
void KeyScanCallBack(void)
{
rt_sem_release(&keyPress1_sem);
}
static void rt_thread3_entry(void *parameter)
{
static rt_err_t result;
// static int cnt = 0;
while(1)
{
/* 永 久 方 式 等 待 信 号 量, 获 取 到 信 号 量, 则 执 行 number 自 加 的 操 作 */
result = rt_sem_take(&keyPress1_sem, RT_WAITING_FOREVER);
if (result != RT_EOK)
{
rt_kprintf("t3 take a static semaphore, failed.\n");
return;
}
else
{
rt_kprintf("t3 take a static semaphore");
rt_pin_w