freertos系统,列表的操作,修改源码,实现降序插入

#include "bsp.h"

capList sysHybird[24];


List_t Up_List;                     //升序列表
List_t Down_List;                   //降序列表


void key_task(void * parameter)
{
	vListInitialise(&Up_List);                  //初始化
    vListInitialiseDescending(&Down_List);      //初始化

    for(uint8_t i = 0; i < 24; i ++)
    {
		//电容器容量参数初始化
        vListInitialiseItem( &sysHybird[i].xLoadCommonListItem );
		//电容器的值,赋值
        sysHybird[i].xLoadCommonListItem.xItemValue = i;
		//每个电容器,找到根节点
        listSET_LIST_ITEM_OWNER( &( sysHybird[i].xLoadCommonListItem ), &sysHybird[i] );
		//插入链表
        vListInsertEnd(&Up_List, &sysHybird[i].xLoadCommonListItem );  
        // vListInsertDescending(&Down_List, &sysHybird[i].xLifeCommonListItem); 
    }


    for( ;; )
    {

        vTaskDelay(10);        //10s
    }
	
	
}

#include "bsp.h"

#include "gd32f30x.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "queue.h"
#include "task.h"
#include "timers.h"
#include "event_groups.h"

#include <string.h>
#include "stdio.h"
#include "stdbool.h"
#include "stdlib.h"
#include <math.h>

typedef struct
{

    Relay_t Fun;
    cap_par cap_v;                      //  电容投切状态

    ListItem_t xLoadCommonListItem;     //  共补容量      手动模式时 采用此节点
    ListItem_t xLoadAListItem;
    ListItem_t xLoadBListItem;
    ListItem_t xLoadCListItem;

    ListItem_t xLifeCommonListItem;     //  使用时长
    ListItem_t xLifeAListItem;
    ListItem_t xLifeBListItem;
    ListItem_t xLifeCListItem;

    ListItem_t xStateListItem;

}capList;

#include "list.h"

//降序排列的列表,初始化列表项的时候,需要调用 vListInitialiseDescending()

void vListInitialiseDescending( List_t * const pxList )
{
    /* The list structure contains a list item which is used to mark the
     * end of the list.  To initialise the list the list end is inserted
     * as the only list entry. */
    pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM.  This is checked and valid. */

    /* The list end value is the highest possible value in the list to
     * ensure it remains at the end of the list. */
    pxList->xListEnd.xItemValue = 0U;

    /* The list end next and previous pointers point to itself so we know
     * when the list is empty. */
    pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd );     /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM.  This is checked and valid. */
    pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM.  This is checked and valid. */

    pxList->uxNumberOfItems = ( UBaseType_t ) 0U;

    /* Write known values into the list if
     * configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
    listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
    listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
}
/*-----------------------------------------------------------*/


//降序插入列表时,需要调降序插入API
void vListInsertDescending( List_t * const pxList,
                  ListItem_t * const pxNewListItem )                                   
{
    ListItem_t * pxIterator;
    const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;

    listTEST_LIST_INTEGRITY( pxList );
    listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );

    if( xValueOfInsertion == 0U )
    {
        pxIterator = pxList->xListEnd.pxNext;
    }
    else
    {

        for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue >= xValueOfInsertion; pxIterator = pxIterator->pxPrevious ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM.  This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */
        {

        }
    }

	pxNewListItem->pxNext = pxIterator->pxNext;
    pxNewListItem->pxNext->pxPrevious = pxNewListItem;
    pxNewListItem->pxPrevious = pxIterator;
    pxIterator->pxNext = pxNewListItem;

    /* Remember which list the item is in.  This allows fast removal of the
     * item later. */
    pxNewListItem->pxContainer = pxList;

    ( pxList->uxNumberOfItems )++;
}
/*-----------------------------------------------------------*/


注意:vListInitialiseDescending();和vListInsertDescending();函数均需要在"list.h"中声明

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值