00. 目录
文章目录
01. FR801xH概述
FR801xH 系列芯片是面向SOC(片上系统),易于快速开发的低功耗蓝牙芯片。基于 Freqchip 的蓝牙智能固件和协议栈的支持,完全兼容蓝牙 V5.3(LE 模式)协议。同时用户可以基于芯片内置的 ARM CorteM3 嵌入式 32 位高性能单片机开发各种应用程序。
蓝牙智能固件包括 L2CAP 服务层协议、安全管理器 (SM)、属性协议(ATT)、通用属性配置文件 (GATT)和通用访问配置文件(GAP)。此外,还 支持应用程序配置文件,例如接近度、健康温度计、 心率、血压、血糖、人机界面设备(HID)和 SDK (包括驱动程序、OS-API 等)。SDK 还集成了用于网络应用程序的 SIG Mesh 协议。
采用 Freqchip 的创新技术,将 PMU(锂电池充电 器+LDO)、带 XIP 模式的 QSPI FLASH ROM、 I2C、UART、GPIO、ADC、PWM 集成在一块芯片中,为客户提供:
- 竞争力的功耗
- 稳定的蓝牙连接
- 极低的 BOM 成本
02. FR801xH功能框图
03. Task API概述
位于 components\modules\os\include\os_task.h。
/**
* Copyright (c) 2019, Freqchip
*
* All rights reserved.
*
*
*/
#ifndef OS_TASK_H_
#define OS_TASK_H_
#include <stdint.h>
#include "os_msg_q.h"
#define TASK_ID_FAIL (0xff)
#define TASK_ID_NONE (0xff)
enum os_event_hdl_result
{
EVT_CONSUMED = 0, ///< consumed, msg and ext are freed by the kernel
EVT_NO_FREE, ///< consumed, nothing is freed by the kernel
EVT_SAVED, ///< not consumed, will be pushed in the saved queue
};
typedef int (*os_task_func_t)(os_event_t *param);
void os_task_delete(uint8_t task_id);
/*********************************************************************
* @fn osal_task_create
*
* @brief Create an os task. ???????????. ?????????????????????event process????
* @param task_func - Event process function for the task.
*
*
* @return 0xff - Task create failure; others - Assigned task ID, 0~50
*/
uint16_t os_task_create(os_task_func_t task_func);
/*********************************************************************
* @fn os_user_loop_event_set
*
* @brief set a loop event that run inside the while(1),and attention that the prioity is lowest.
* If you want to goto sleep,you should clear the event.
*
* @param callback - the callback function of the loop event.
*
* @return None.
*/
void os_user_loop_event_set(void (*callback)(void));
/*********************************************************************
* @fn os_user_loop_event_clear
*
* @brief clear the event when you want not to run the loop.
*
* @param None.
*
* @return None.
*/
void os_user_loop_event_clear(void);
/**********************************************************************
************loop event eg***************
void user_loop_callback(void)
{
static uint16_t count = 0;
count++;
if(count > 30000)
{
count = 0;
uart_putc_noint(UART1,'t');
os_user_loop_event_clear(); // clear event
}
//uart_putc_noint(UART1,'t');
}
os_user_loop_event_set(&user_loop_callback); // create a loop event
*/
void os_task_process_saved_msg(uint8_t task_id);
#endif // APP_HT_H_
04. Task相关函数
4.1 os_task_create
uint16_t os_task_create(os_task_func_t task_func)
功能:
创建一个任务。最多支持 20 个任务。任务不分优先级。消息按抛送的顺序进行处理。
参数:
task_func 任务的执行函数。
返回值:
创建任务的 id 号,
0xff,任务创建失败。
其他值,任务创建成功,返回值是任务的 id 号。
示例:
uint16_t user_task_id;
static int user_task_func(os_event_t *param)
{
switch(param->event_id)
{
case 0
break;
case 1
break;
}
return EVT_CONSUMED;
}
void user_task_init(void)
{
user_task_id = os_task_create(user_task_func);
}
4.2 os_task_delete
void os_task_delete(uint8_t task_id);
功能:
删除一个已经创建的任务。
参数:
task_id 创建任务时返回的任务 id 号。
返回值:
无
4.3 os_msg_post
/**
* OS event definition.
*/
typedef struct _os_event_
{
uint16_t event_id;
uint16_t src_task_id;
void *param;
uint16_t param_len;
} os_event_t;
void os_msg_post(uint16_t dst_task_id, os_event_t *evt);
功能:
向某个已经创建的目标任务抛一个消息事件。
参数:
dst_task_id 目标任务的任务 id 号
evt 指向要抛送的消息事件的指针。
返回值:
无
4.4 os_user_loop_event_set
void os_user_loop_event_set(void (*callback)(void));
功能:
用户设置一个跑在 while(1)循环中的函数,便于用户做一些循环检测或者操作处理。该循环处理事件优先级最低,另外用户在
需要睡眠时应先清除这个事件。
参数:
callback 设置的循环调用的 callback 函数。
返回值:
无
示例:
void user_loop_callback(void)
{
static uint16_t count = 0;
count++;
if(count > 30000)
{
count = 0;
uart_putc_noint(UART1,'t');
os_user_loop_event_clear(); // clear event
}
//uart_putc_noint(UART1,'t');
}
os_user_loop_event_set(&user_loop_callback); // create a loop event
4.5 os_user_loop_event_clear
void os_user_loop_event_clear(void);
功能:
清除循环处理事件。
参数:
无
返回值:
无
05. Task示例
程序示例
/*
* INCLUDE FILES
****************************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include "demo_peripheral.h"
#include "co_printf.h"
#include "sys_utils.h"
#include "driver_system.h"
#include "os_task.h"
#include "os_timer.h"
uint16_t task_id1 = 0;
uint16_t task_id2 = 0;
os_timer_t timer1;
os_timer_t timer2;
//定时器1
void os_timer_func1(void *parg)
{
os_event_t ev;
os_msg_post(task_id1, &ev);
}
//定时器2
void os_timer_func2(void *parg)
{
os_event_t ev;
os_msg_post(task_id2, &ev);
}
static int user_task_func1(os_event_t *param)
{
co_printf("user_task_func1 do work\r\n");
}
static int user_task_func2(os_event_t *param)
{
co_printf("user_task_func2 do work\r\n");
}
void peripheral_demo(void)
{
//创建任务1
task_id1 = os_task_create(user_task_func1);
//创建任务2
task_id2 = os_task_create(user_task_func2);
//创建定时器1
os_timer_init(&timer1, os_timer_func1, NULL);
os_timer_start(&timer1, 1000, 0);
//创建定时器2
os_timer_init(&timer2, os_timer_func2, NULL);
os_timer_start(&timer2, 2000, 1);
}
执行结果
******Connected******
******Start Auto Burn******
****************************************************
******CRC Success******
******Burn Success******
user_task_func1 do work
user_task_func2 do work
user_task_func2 do work
user_task_func2 do work
user_task_func2 do work
user_task_func2 do work
user_task_func2 do work
user_task_func2 do work
user_task_func2 do work
user_task_func2 do work
user_task_func2 do work
user_task_func2 do work
user_task_func2 do work
user_task_func2 do work