📄 lnklist.h
字号:
/** * Copyright (c) 2006-2008 iWESUN (ShenZhen) Inf. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the AvrcX MTOS * * Author: Winter Hu <winter.hu@gmail.com> * Create: Nov 26, 2006 */#ifndef __LNKLIST_H__#define __LNKLIST_H__#include "common.h"#ifndef __ASSEMBLER__/* These only work in C program */// Define data structure of a Node with priority propertytypedef struct Node { __volatile__ unsigned char priority; // 0~255, the smaller the value is higher priority void *pData; // Point to the real data struct Node *next; // Point to the next Node} Node;// Define data structure of a LinkedListtypedef struct LinkedList { Node *head;} LinkedList;/** * Retrieves the first Node in the LinkedList * If return NULL, means the list is empty * * @param LinkedList*, The pointer to the LinkedList * @return Node*, the pointer to the first Node */INTERFACE Node* get_first(LinkedList*);/** * Remove the first Node from the LinkedList * If return NULL, means the list is empty * * @param LinkedList*, The pointer to the LinkedList * @return Node*, The pointer to the first Node */INTERFACE Node* remove_first(LinkedList*);/** * Remove the Node from the LinkedList * If return NULL, no Node had been removed * * @param LinkedList*, The pointer to the LinkedList * @param Node*, The pointer to the Node need to be removed * @return Node*, The pointer to the Node that be removed */INTERFACE Node* remove(LinkedList*, Node*);/** * Insert a Node into the order of priority LinkedList * * @param LinkedList*, The pointer to the LinkedList * @param Node*, The pointer to the Node that need to insert * @return none */INTERFACE void insert_ordered(LinkedList*, Node*);/** * Insert a Node into the LinkedList with relative priority * This method could be useful to create a scheduler queue or * a timer queue. * For example: * I want to define three timers to 10ms, 30ms, and 100ms, then the * timer queue should be 10ms, 20ms, 70ms, The timer interrupt service * only minus 1 from the first node and until it equas to 0 to trigger * the first 10ms, after another 20ms, to trigger the second 30ms, etc. * * @param LinkedList*, The pointer to the LinkedList * @param Node*, The pointer to the Node that need to insert * @return none */INTERFACE void insert_relative(LinkedList*, Node*);/** * Append the node to the end of the LinkedList * The priority of Node is ignored * * @param LinkedList*, The pointer to the LinkedList * @param Node*, The pointer to the Node */INTERFACE void append(LinkedList*, Node*);#endif /* !__ASSEMBLER__ *//* Node data structure offsets */#define NODE_PRIORITY 0#define NODE_PDATA_LO 1#define NODE_PDATA_HI 2#define NODE_PNEXT_LO 3#define NODE_PNEXT_HI 4#define NODE_PDATA 1#define NODE_PNEXT 3#endif /* __LNKLIST_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -