This repository has been archived on 2025-02-28. You can view files and clone it, but cannot push or open issues or pull requests.
controller-hd/User/lib/flow/flow.h

130 lines
3.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file flow.h
* @author: xxx
* @date: 2023-07-21 17:00:15
* @brief
* @copyright: Copyright (c) 2023 by xxx, All Rights Reserved.
*/
#ifndef __FLOW_
#define __FLOW_
#include "flow_def.h"
#include "flow_core.h"
#include "flow_sem.h"
#define FL_HARD_TICK (10U) /* 系统硬件中断一次所需要的时间单位ms */
#define FL_CLOCK_SEC (1000U / FL_HARD_TICK) /* 一秒钟需要的tick可以根据需求添加其他时间更短的宏 */
#define FL_CLOCK_100MSEC (100U / FL_HARD_TICK)
#define FL_CLOCK_10MSEC (FL_CLOCK_100MSEC / 10U)
/**
* 初始化一个flow进程
*/
#define FL_INIT(fl) FLOW_INIT((fl))
/**
* flow头必须放在函数内的最前面
*/
#define FL_HEAD(fl) FLOW_HEAD((fl))
/**
* flow尾必须放在函数内的最后面
*/
#define FL_TAIL(fl) FLOW_TAIL((fl))
/**
* 给进程加锁直到judge为真加锁期间一直放开cpu给其他进程使用
*/
#define FL_LOCK_WAIT(fl, judge) FLOW_LOCK_WAIT((fl), (judge))
/**
* 如果judge为真就一直给进程加锁加锁期间一直放开cpu给其他进程使用
*/
#define FL_LOCK_WHILE(fl, judge) FLOW_LOCK_WHILE((fl), (judge))
/**
* 退出该进程
*/
#define FL_EXIT(fl) FLOW_EXIT((fl))
/**
* 无条件锁住进程一次,下次进来再接着往下运行
*/
#define FL_LOCK_ONCE(fl) FLOW_LOCK_ONCE((fl))
/**
* 等待一个flow进程结束
*/
#define FL_WAIT_PROCESS_END(fl, process) FLOW_WAIT_PROCESS_END((fl), (process))
/**
* 等待一个flow子进程结束
*/
#define FL_WAIT_CHILD(fl, cfl, process) FLOW_WAIT_CHILD_PROCESS_END((fl), (cfl), (process))
/**
* 给进程加锁时长为time加锁期间一直放开cpu给其他进程使用time如果用FL_CLOCK_SEC来乘那么time的单位就是s
* 此处time必须是常数
*/
#define FL_LOCK_DELAY(fl, time) FLOW_LOCK_DELAY((fl), (time))
/**
* 给进程加锁时长为time延时期间如果judge为真就直接解锁进程
* 此处time必须是常数
*/
#define FL_LOCK_DELAY_OR_WAIT(fl, judge, time) FLOW_LOCK_DELAY_OR_WAIT((fl), (judge), (time))
/**
* 初始化一个信号量
*/
#define FL_SEM_INIT(sem, count) FLOW_SEM_INIT((sem), (count))
/**
* 给进程加锁,直到有信号释放
*/
#define FL_LOCK_WAIT_SEM(fl, sem) FLOW_LOCK_WAIT_SEM((fl), (sem))
/**
* 给进程加锁直到有信号或者超时此处time可以为常数或者变量其他的接口处time必须是常数
*/
#define FL_LOCK_WAIT_SEM_OR_TIMEOUT(fl, sem, time) FLOW_LOCK_WAIT_SEM_OR_TIMEOUT((fl), (sem), (time))
/**
* 释放一个信号量
*/
#define FL_SEM_RELEASE(sem) FLOW_SEM_RELEASE((sem))
/**
* 检测一个信号量是否被释放
*/
#define FL_SEM_IS_RELEASE(fl ,sem) FLOW_SEM_IS_RELEASE((fl), (sem))
/**
* 初始化一个软件定时器
*/
void fl_timer_set(struct flow_timer *t, unsigned long interval);
/**
* 复位一个软件定时器
*/
void fl_timer_reset(struct flow_timer *t);
/**
* 重启一个软件定时器
*/
void fl_timer_restart(struct flow_timer *t);
/**
* 检测一个软件定时器是否超时0为不超时1为超时
*/
unsigned char fl_timer_timeout(struct flow_timer *t);
/**
* 检测一个软件定时器还剩多少时间超时单位为硬件tick比如硬件tick 500ms中断一次那么
* 返回的剩余时间就是500ms*n
*/
unsigned long fl_hour_much_time(struct flow_timer *t);
#endif /* __FLOW_ */