#ifndef __RT_DEF_H__
#define __RT_DEF_H__
/* RT-Thread basic data type definitions */
#ifndef RT_USING_ARCH_DATA_TYPE
typedef signed char rt_int8_t; /**< 8bit integer type */
typedef signed short rt_int16_t; /**< 16bit integer type */
typedef signed int rt_int32_t; /**< 32bit integer type */
typedef unsigned char rt_uint8_t; /**< 8bit unsigned integer type */
typedef unsigned short rt_uint16_t; /**< 16bit unsigned integer type */
typedef unsigned int rt_uint32_t; /**< 32bit unsigned integer type */
#ifdef ARCH_CPU_64BIT
typedef signed long rt_int64_t; /**< 64bit integer type */
typedef unsigned long rt_uint64_t; /**< 64bit unsigned integer type */
#else
typedef signed long long rt_int64_t; /**< 64bit integer type */
typedef unsigned long long rt_uint64_t; /**< 64bit unsigned integer type */
#endif
#endif
typedef int rt_bool_t; /**< boolean type */
typedef long rt_base_t; /**< Nbit CPU related date type */
typedef unsigned long rt_ubase_t; /**< Nbit unsigned CPU related data type */
typedef rt_base_t rt_err_t; /**< Type for error number */
typedef rt_uint32_t rt_time_t; /**< Type for time stamp */
typedef rt_uint32_t rt_tick_t; /**< Type for tick count */
typedef rt_base_t rt_flag_t; /**< Type for flags */
typedef rt_ubase_t rt_size_t; /**< Type for size number */
typedef rt_ubase_t rt_dev_t; /**< Type for device */
typedef rt_base_t rt_off_t; /**< Type for offset */
/* boolean type definitions */
#define RT_TRUE 1 /**< boolean true */
#define RT_FALSE 0 /**< boolean fails */
/**@}*/
/* maximum value of base type */
#define RT_UINT8_MAX 0xff /**< Maxium number of UINT8 */
#define RT_UINT16_MAX 0xffff /**< Maxium number of UINT16 */
#define RT_UINT32_MAX 0xffffffff /**< Maxium number of UINT32 */
#define RT_TICK_MAX RT_UINT32_MAX /**< Maxium number of tick */
#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#define __CLANG_ARM
#endif
/* Compiler Related Definitions */
#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM Compiler */
#include <stdarg.h>
#define SECTION(x) __attribute__((section(x)))
#define RT_UNUSED __attribute__((unused))
#define RT_USED __attribute__((used))
#define ALIGN(n) __attribute__((aligned(n)))
#define RT_WEAK __attribute__((weak))
#define rt_inline static __inline
/* module compiling */
#ifdef RT_USING_MODULE
#define RTT_API __declspec(dllimport)
#else
#define RTT_API __declspec(dllexport)
#endif
#elif defined (__IAR_SYSTEMS_ICC__) /* for IAR Compiler */
#include <stdarg.h>
#define SECTION(x) @ x
#define RT_UNUSED
#define RT_USED __root
#define PRAGMA(x) _Pragma(#x)
#define ALIGN(n) PRAGMA(data_alignment=n)
#define RT_WEAK __weak
#define rt_inline static inline
#define RTT_API
#elif defined (__GNUC__) /* GNU GCC Compiler */
#ifdef RT_USING_NEWLIB
#include <stdarg.h>
#else
/* the version of GNU GCC must be greater than 4.x */
typedef __builtin_va_list __gnuc_va_list;
typedef __gnuc_va_list va_list;
#define va_start(v,l) __builtin_va_start(v,l)
#define va_end(v) __builtin_va_end(v)
#define va_arg(v,l) __builtin_va_arg(v,l)
#endif
#define SECTION(x) __attribute__((section(x)))
#define RT_UNUSED __attribute__((unused))
#define RT_USED __attribute__((used))
#define ALIGN(n) __attribute__((aligned(n)))
#define RT_WEAK __attribute__((weak))
#define rt_inline static __inline
#define RTT_API
#elif defined (__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */
#include <stdarg.h>
#define SECTION(x) __attribute__((section(x)))
#define RT_UNUSED __attribute__((unused))
#define RT_USED __attribute__((used))
#define ALIGN(n) __attribute__((aligned(n)))
#define RT_WEAK __attribute__((weak))
#define rt_inline static inline
#define RTT_API
#elif defined (_MSC_VER)
#include <stdarg.h>
#define SECTION(x)
#define RT_UNUSED
#define RT_USED
#define ALIGN(n) __declspec(align(n))
#define RT_WEAK
#define rt_inline static __inline
#define RTT_API
#elif defined (__TI_COMPILER_VERSION__)
#include <stdarg.h>
/* The way that TI compiler set section is different from other(at least
* GCC and MDK) compilers. See ARM Optimizing C/C++ Compiler 5.9.3 for more
* details. */
#define SECTION(x)
#define RT_UNUSED
#define RT_USED
#define PRAGMA(x) _Pragma(#x)
#define ALIGN(n)
#define RT_WEAK
#define rt_inline static inline
#define RTT_API
#else
#error not supported tool chain
#endif
/**@}*/
/**
* @ingroup BasicDef
*
* @def RT_ALIGN(size, align)
* Return the most contiguous size aligned at specified width. RT_ALIGN(13, 4)
* would return 16.
*/
#define RT_ALIGN(size, align) (((size) + (align) - 1) & ~((align) - 1))
/**
* @ingroup BasicDef
*
* @def RT_ALIGN_DOWN(size, align)
* Return the down number of aligned at specified width. RT_ALIGN_DOWN(13, 4)
* would return 12.
*/
#define RT_ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
/**
* @ingroup BasicDef
*
* @def RT_NULL
* Similar as the \c NULL in C library.
*/
#define RT_NULL (0)
/**
* Double List structure
*/
struct rt_list_node
{
struct rt_list_node *next; /**< point to next node. */
struct rt_list_node *prev; /**< point to prev node. */
};
typedef struct rt_list_node rt_list_t; /**< Type for lists. */
/**
* Single List structure
*/
struct rt_slist_node
{
struct rt_slist_node *next; /**< point to next node. */
};
typedef struct rt_slist_node rt_slist_t; /**< Type for single list. */
#endif
rt_service.h
#ifndef __RT_SERVICE_H__
#define __RT_SERVICE_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup KernelService
*/
/**@{*/
/**
* rt_container_of - return the member address of ptr, if the type of ptr is the
* struct type.
*/
#define rt_container_of(ptr, type, member) \
((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member)))
/**
* @brief initialize a list object
*/
#define RT_LIST_OBJECT_INIT(object) { &(object), &(object) }
/**
* @brief initialize a list
*
* @param l list to be initialized
*/
rt_inline void rt_list_init(rt_list_t *l)
{
l->next = l->prev = l;
}
/**
* @brief insert a node after a list
*
* @param l list to insert it
* @param n new node to be inserted
*/
rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n)
{
l->next->prev = n;
n->next = l->next;
l->next = n;
n->prev = l;
}
/**
* @brief insert a node before a list
*
* @param n new node to be inserted
* @param l list to insert it
*/
rt_inline void rt_list_insert_before(rt_list_t *l, rt_list_t *n)
{
l->prev->next = n;
n->prev = l->prev;
l->prev = n;
n->next = l;
}
/**
* @brief remove node from list.
* @param n the node to remove from the list.
*/
rt_inline void rt_list_remove(rt_list_t *n)
{
n->next->prev = n->prev;
n->prev->next = n->next;
n->next = n->prev = n;
}
/**
* @brief tests whether a list is empty
* @param l the list to test.
*/
rt_inline int rt_list_isempty(const rt_list_t *l)
{
return l->next == l;
}
/**
* @brief tests whether a list is one
* @param l the list to test.
*/
rt_inline int rt_list_isone(const rt_list_t* l)
{
return (l->next != l) && (l->next->next == l);
}
/**
* @brief get the list length
* @param l the list to get.
*/
rt_inline unsigned int rt_list_len(const rt_list_t *l)
{
unsigned int len = 0;
const rt_list_t *p = l;
while (p->next != l)
{
p = p->next;
len ++;
}
return len;
}
/**
* @brief get the struct for this entry
* @param node the entry point
* @param type the type of structure
* @param member the name of list in structure
*/
#define rt_list_entry(node, type, member) \
rt_container_of(node, type, member)
/**
* rt_list_for_each - iterate over a list
* @pos: the rt_list_t * to use as a loop cursor.
* @head: the head for your list.
*/
#define rt_list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
/**
* rt_list_for_each_safe - iterate over a list safe against removal of list entry
* @pos: the rt_list_t * to use as a loop cursor.
* @n: another rt_list_t * to use as temporary storage
* @head: the head for your list.
*/
#define rt_list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
/**
* rt_list_for_each_entry - iterate over list of given type
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define rt_list_for_each_entry(pos, head, member) \
for (pos = rt_list_entry((head)->next, typeof(*pos), member); \
&pos->member != (head); \
pos = rt_list_entry(pos->member.next, typeof(*pos), member))
/**
* rt_list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define rt_list_for_each_entry_safe(pos, n, head, member) \
for (pos = rt_list_entry((head)->next, typeof(*pos), member), \
n = rt_list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = rt_list_entry(n->member.next, typeof(*n), member))
/**
* rt_list_first_entry - get the first element from a list
* @ptr: the list head to take the element from.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*
* Note, that list is expected to be not empty.
*/
#define rt_list_first_entry(ptr, type, member) \
rt_list_entry((ptr)->next, type, member)
/**
* rt_list_last_entry - get the last element from a list
* @ptr: the list head to take the element from.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*
* Note, that list is expected to be not empty.
*/
#define rt_list_last_entry(ptr, type, member) \
rt_list_entry((ptr)->prev, type, member)
#define RT_SLIST_OBJECT_INIT(object) { RT_NULL }
/**
* @brief initialize a single list
*
* @param l the single list to be initialized
*/
rt_inline void rt_slist_init(rt_slist_t *l)
{
l->next = RT_NULL;
}
rt_inline void rt_slist_append(rt_slist_t *l, rt_slist_t *n)
{
struct rt_slist_node *node;
node = l;
while (node->next) node = node->next;
/* append the node to the tail */
node->next = n;
n->next = RT_NULL;
}
rt_inline void rt_slist_insert(rt_slist_t *l, rt_slist_t *n)
{
n->next = l->next;
l->next = n;
}
rt_inline unsigned int rt_slist_len(const rt_slist_t *l)
{
unsigned int len = 0;
const rt_slist_t *list = l->next;
while (list != RT_NULL)
{
list = list->next;
len ++;
}
return len;
}
rt_inline rt_slist_t *rt_slist_remove(rt_slist_t *l, rt_slist_t *n)
{
/* remove slist head */
struct rt_slist_node *node = l;
while (node->next && node->next != n) node = node->next;
/* remove node */
if (node->next != (rt_slist_t *)0) node->next = node->next->next;
return l;
}
rt_inline rt_slist_t *rt_slist_first(rt_slist_t *l)
{
return l->next;
}
rt_inline rt_slist_t *rt_slist_tail(rt_slist_t *l)
{
while (l->next) l = l->next;
return l;
}
rt_inline rt_slist_t *rt_slist_next(rt_slist_t *n)
{
return n->next;
}
rt_inline int rt_slist_isempty(rt_slist_t *l)
{
return l->next == RT_NULL;
}
/**
* @brief get the struct for this single list node
* @param node the entry point
* @param type the type of structure
* @param member the name of list in structure
*/
#define rt_slist_entry(node, type, member) \
rt_container_of(node, type, member)
/**
* rt_slist_for_each - iterate over a single list
* @pos: the rt_slist_t * to use as a loop cursor.
* @head: the head for your single list.
*/
#define rt_slist_for_each(pos, head) \
for (pos = (head)->next; pos != RT_NULL; pos = pos->next)
/**
* rt_slist_for_each_entry - iterate over single list of given type
* @pos: the type * to use as a loop cursor.
* @head: the head for your single list.
* @member: the name of the list_struct within the struct.
*/
#define rt_slist_for_each_entry(pos, head, member) \
for (pos = rt_slist_entry((head)->next, typeof(*pos), member); \
&pos->member != (RT_NULL); \
pos = rt_slist_entry(pos->member.next, typeof(*pos), member))
/**
* rt_slist_first_entry - get the first element from a slist
* @ptr: the slist head to take the element from.
* @type: the type of the struct this is embedded in.
* @member: the name of the slist_struct within the struct.
*
* Note, that slist is expected to be not empty.
*/
#define rt_slist_first_entry(ptr, type, member) \
rt_slist_entry((ptr)->next, type, member)
/**
* rt_slist_tail_entry - get the tail element from a slist
* @ptr: the slist head to take the element from.
* @type: the type of the struct this is embedded in.
* @member: the name of the slist_struct within the struct.
*
* Note, that slist is expected to be not empty.
*/
#define rt_slist_tail_entry(ptr, type, member) \
rt_slist_entry(rt_slist_tail(ptr), type, member)
/**@}*/
#ifdef __cplusplus
}
#endif
#endif
winMain.c
#include "Main.h"
/* Private macro ------------------------------------------------------------*/
/* Private variables --------------------------------------------------------*/
/* Private function prototypes ----------------------------------------------*/
static void Initialize(void);
static void TimerProc(u16 hTimer);
static void WindowProc(WORD Type, WORD Parameter, BYTE *Info,u16 hSrcWin,u16 hTagWin);
/**
* @brief 窗口函数结构体初始化
*/
static WINDOW Window = INIT_WIN(winMain);
/**
* @brief 窗口初始化
* @note 每次窗口被激活为当前窗口时调用,可以初始化每次进入窗口时需初始化的变量
*/
static void Initialize(void)
{
/*< Initialize the variables that needs to be initialized when redraw the window */
}
/**
* @brief 主任务
* @param None
* @retval None
* @note 窗口加载函数,在窗口集合注册当前窗口;
* 如果要每次打开窗口时都进行初始化,则应在此加入初始化
*/
void winMain(void)
{
if (Window.Active)return;
if (RegisterWindow(MAIN_TASK,&Window)){
Initialize();
OpenWindow(MAIN_TASK,&Window);
/*< Initialize the first open window all variables that you need to used */
/*< Set Window Timer, you must set window timer before open another window */
Set_Timer_Window(MAIN_TASK,&Window,100,0,TimerProc);
/*< Do something */
}
}
/**
* @brief 窗口函数
* @param Type: 信息的类型
* @param Parameter: 数值型信息
* @param Info: 字符串型信息
* @param hSrcWin: 源窗口,消息的触发窗口
* @param hTagWin: 目标窗口,消息的目标窗口
* @retval None
* @note 具体处理接收到的信息(如按键输入等),每一个功能窗口都要有一个这样的函数
* 这是一个内部函数,其他模块的窗口函数可以与它同名
*/
static void WindowProc(WORD Type, WORD Parameter, BYTE *Info, u16 hSrcWin, u16 hTagWin)
{
switch( Type ) // 根据信息类型,提取及处理相应的信息
{
case WM_CLOSE:
CloseWindow(MAIN_TASK);
break;
case WM_REDRAW:
Initialize();
OpenWindow(MAIN_TASK,&Window);
break;
case WM_REFRESH:
break;
case WM_ALARM_CODE:
CloseWindow(MAIN_TASK);
(*ActiveWindowProc(MAIN_TASK))(WM_ALARM_CODE,Parameter,Info,hSrcWin,hTagWin);
break;
default:
break;
}
}
/**
* @brief 窗口定时器触发事件
* @param 定时器索引
* @retval None
* @note 窗口定时器与窗口相关联,窗口定时器按照设定周期触发窗口定时器事件
* 一个窗口可以有多个窗口定时器,当窗口关闭时所有的窗口定时器均被注销
* 窗口定时器属性:0全局计时 1:当前窗口计时
*/
static void TimerProc(u16 hTimer)
{
KillWindow_SpecialTimer(MAIN_TASK,TimerProc);
KillWindowTimer(MAIN_TASK, &Window);
}
/*****************************END OF FILE******************************/
win_PowerOn_SelfTest.c
#include "Main.h"
/* Private macro ------------------------------------------------------------*/
/* Private variables --------------------------------------------------------*/
static u8 sSource;
/* Private function prototypes ----------------------------------------------*/
static void Initialize(void);
static void TimerProc(u16 hTimer);
static void WindowProc(WORD Type, WORD Parameter, BYTE *Info,u16 hSrcWin,u16 hTagWin);
/**
* @brief 窗口函数结构体初始化
*/
static WINDOW Window = INIT_WIN(win_PowerOn_SelfTest);
/**
* @brief 窗口初始化
* @note 每次窗口被激活为当前窗口时调用,可以初始化每次进入窗口时需初始化的变量
*/
static void Initialize(void)
{
/*< Initialize the variables that needs to be initialized when redraw the window */
}
/**
* @brief 上电自检
* @param None
* @retval None
* @note 窗口加载函数,在窗口集合注册当前窗口;
* 如果要每次打开窗口时都进行初始化,则应在此加入初始化
*/
void win_PowerOn_SelfTest(u8 hSource)
{
if (Window.Active)return;
if (RegisterWindow(MAIN_TASK,&Window)){
Initialize();
OpenWindow(MAIN_TASK,&Window);
/*< Initialize the first open window all variables that you need to used */
sSource = hSource;
/*< Set Window Timer, you must set window timer before open another window */
Set_Timer_Window(MAIN_TASK,&Window,100,0,TimerProc);
/*< Do something */
CloseWindow(MAIN_TASK);
(*ActiveWindowProc(MAIN_TASK))(WM_ALARM_CODE,NO_ALARM,0,0,0);
}
}
/**
* @brief 窗口函数
* @param Type: 信息的类型
* @param Parameter: 数值型信息
* @param Info: 字符串型信息
* @param hSrcWin: 源窗口,消息的触发窗口
* @param hTagWin: 目标窗口,消息的目标窗口
* @retval None
* @note 具体处理接收到的信息(如按键输入等),每一个功能窗口都要有一个这样的函数
* 这是一个内部函数,其他模块的窗口函数可以与它同名
*/
static void WindowProc(WORD Type, WORD Parameter, BYTE *Info, u16 hSrcWin, u16 hTagWin)
{
switch( Type ) // 根据信息类型,提取及处理相应的信息
{
case WM_CLOSE:
CloseWindow(MAIN_TASK);
break;
case WM_REDRAW:
Initialize();
OpenWindow(MAIN_TASK,&Window);
break;
case WM_REFRESH:
break;
case WM_ALARM_CODE:
CloseWindow(MAIN_TASK);
(*ActiveWindowProc(MAIN_TASK))(WM_ALARM_CODE,Parameter,Info,hSrcWin,hTagWin);
break;
default:
break;
}
}
/**
* @brief 窗口定时器触发事件
* @param 定时器索引
* @retval None
* @note 窗口定时器与窗口相关联,窗口定时器按照设定周期触发窗口定时器事件
* 一个窗口可以有多个窗口定时器,当窗口关闭时所有的窗口定时器均被注销
* 窗口定时器属性:0全局计时 1:当前窗口计时
*/
static void TimerProc(u16 hTimer)
{
KillWindow_SpecialTimer(MAIN_TASK,TimerProc);
KillWindowTimer(MAIN_TASK, &Window);
}
/*****************************END OF FILE******************************/
main.c
#define MAIN
#include "Main.h"
static void Initialize(void);
int main()
{
Initialize();
while (1)
{
TimerServer(); //软件定时器
TimerServerWindow(); //软件窗口定时器
RefreshWindow(); //刷新窗口
}
}
static void Initialize(void)
{
InitManager();
winMain();
win_PowerOn_SelfTest(0);
}