OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2237|回复: 0

不知道为什么,STM32运行自己写的队列就死机,大佬帮我看看

[复制链接]

2

主题

7

帖子

0

精华

新手上路

积分
44
金钱
44
注册时间
2019-4-18
在线时间
10 小时
发表于 2019-4-18 08:51:04 来自手机 | 显示全部楼层 |阅读模式
只要连续入队就导致32死机,我队列只创建40字节的数据领,不可能内存不够,会不会是队列的操作有错,可是我在VC中试过正常啊。

#include <stdio.h>
#include <stdlib.h>

#define   uint8_t   unsigned char

typedef struct queue
{
  uint8_t *data;  //数据域
  uint8_t head;   //队首
  uint8_t tail;   //队尾
  uint8_t len;    //队列长度
}*pQueue,Queue;
/*********队列是否为空************/
uint8_t Empty(pQueue p)
{
   if(p->head==p->tail)
   {
     return 1;
   }
     return 0;
}
/*********队列是否为满************/
uint8_t Impletion(pQueue  p)
{
   if( (p->tail+1)%p->len == p->head)
   {
     return 1;
   }
     return 0;
}
/*********创建队列************/
pQueue QueueCreate(uint8_t len)
{
  pQueue  newQueue = (pQueue)malloc(sizeof(Queue));
          newQueue->data=(uint8_t*)malloc(len);
          newQueue->len=len;
          newQueue->head=0;
                  newQueue->tail=0;
     return newQueue;
}

/*********入队***************/
uint8_t Enqueue(pQueue p,uint8_t data)
{
   if(Impletion(p)) //判断队列是否为满
   {
     return 0; //入队失败
   }
   p->data[p->tail]=data;
   p->tail=(p->tail+1)%p->len;
   return   1; //入队成功
}
/*********出队***************/
uint8_t Dequeue(pQueue p,uint8_t *data)
{
  if(Empty(p))
  {
    return 0;//失败,队列空
  }
  *data=p->data[p->head];
  p->head=(p->head+1)%p->len;
    return 1;
}

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-22 01:38

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表