Cstyle notes, Freertos kernel details, article 3rd

Source: Internet
Author: User

Cstyle notes, Freertos kernel details, article 3rd

The most common and core data structure in RTOS, and the implementation of queues. It can be compiled and tested in VS2008.
 
/** @file   Copyright (c) 2008 - 2014, MX.Studio All rights reserved. Created by Cstyle          **/#ifndef _QUEUE_H_#define _QUEUE_H_#ifdef __cplusplusextern "C" {#endif#include "Syslib.h"#define Cfg_QUE_LEN 20typedef struct{    UINT8 Data[Cfg_QUE_LEN];    UINT8 pHead;    UINT8 pTail;    UINT16 size;}Queue_t;Queue_t * Queue_Creat();UINT8 Queue_IsEmpty(Queue_t * const q);UINT8 Queue_IsFull(Queue_t * const q);UINT8 Queue_Push(Queue_t * const q,UINT8 const * const Dat);UINT8 Queue_Pop(Queue_t * const q,UINT8 * const Dat);UINT16 Queue_GetSize(Queue_t *const q);void Queue_Test();#ifdef __cplusplus}#endif#endif
 
 
 
 
/** @file   Copyright (c) 2008 - 2014, MX.Studio All rights reserved. Created by Cstyle          **/#include "Queue.h"Queue_t * Queue_Creat(){    Queue_t *p;    p=malloc(sizeof(Queue_t));    if(0!=p)    {        p->pHead=0;        p->pTail=0;        p->size=0;                return p;    }    else return 0;}UINT8 Queue_IsEmpty(Queue_t * const q){    if(!q->size) return 1;    else return 0;}UINT8 Queue_IsFull(Queue_t * const q){    if((q->size!=0)&&(q->pHead ==q->pTail)) return 1;//full    else return 0;}UINT8 Queue_Push(Queue_t * const q,UINT8 const * const Dat){        Assert(!Queue_IsFull(q));        q->Data[q->pHead] = *Dat;        q->pHead++;        q->pHead = q->pHead % Cfg_QUE_LEN;        q->size++;        return 0;}UINT8 Queue_Pop(Queue_t * const q,UINT8 * const Dat){    Assert(!Queue_IsEmpty(q));    *Dat = q->Data[q->pTail];    q->pTail++;    q->pTail = q->pTail % Cfg_QUE_LEN;    q->size--;    return 0;}UINT16 Queue_GetSize(Queue_t *const q){return q->size;}void Queue_Test(){ Queue_t *test; UINT8 a=1,b,i; printf("-----------------------------------------------\n"); printf("------------Start Queue Test!------------------\n"); printf("-----------------------------------------------\n"); //creat queue printf("creat queue test:\n\n");     test=Queue_Creat();     printf("p=%x\np->pHead =%x\np->pTail =%x\np->size =%x\n",test,test->pHead,test->pTail,test->size); //push queue printf("push queue test1:\n\n");     Queue_Push(test,&a);     printf("p=%x\np->pHead =%x\np->pTail =%x\np->size =%x\n",test,test->pHead,test->pTail,test->size);     for(i=0;i
  
   Data[i]);     printf("\n \n"); //push queue printf("push queue test2:\n\n"); a++;     Queue_Push(test,&a);     printf("p=%x\np->pHead =%x\np->pTail =%x\np->size =%x\n",test,test->pHead,test->pTail,test->size);     for(i=0;i
   
    Data[i]);     printf("\n \n"); //pop queue printf("push queue test:\n\n");     Queue_Pop(test,&b);     printf("b=%x \n",b);     printf("p=%x\np->pHead =%x\np->pTail =%x\np->size =%x\n",test,test->pHead,test->pTail,test->size);     for(i=0;i
    
     Data[i]); printf("\n\n"); }
    
   
  



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.