#include "common.h"
#include "uart.h"
#include "gpio.h"
//buffer add
struct FifoQueue MyQueue;
uint8_t Queuedata;
//new queue
void InitFifo(Queue *Q,int size)
{
Q->queuesize = size;
Q->q = (uint8_t *)malloc(sizeof(uint8_t) * Q->queuesize); //分配内存
Q->tail = 0;
Q->head = 0;
uint8_t *data=Q->q;
for(int i=0;i<Q->queuesize;i++)
{
*data=0;
data++;
}
}
void InFifo(Queue *Q, uint8_t key)
{
int tail = (Q->tail+1) % Q->queuesize; //取余保证,当quil=queuesize-1时,再转回0
if (tail == Q->head) //此时队列没有空间
{
//full
OutFifo(Q);
Q->q[Q->tail] = key;
Q->tail = tail;
}
else
{
Q->q[Q->tail] = key;
Q->tail = tail;
}
}
void printFifo(Queue *Q)
{
uint8_t *data=Q->q;
for(int i=0;i<Q->queuesize;i++)
{
printf("%d ",*data);
data++;
}
printf("\r\n");
}
uint32_t GetFifoBias(Queue *Q)//获取队列中数据的均值
{
uint8_t *data=Q->q;
uint32_t summary=0;
for(int i=0;i<Q->queuesize;i++)
{
summary+=*data;
data++;
}
summary=summary/Q->queuesize;
return summary;
}
uint8_t OutFifo(Queue *Q)
{
uint8_t tmp=0;
if(Q->tail != Q->head) //判断队列不为空
{
tmp = Q->q[Q->head];
Q->head = (Q->head+1) % Q->queuesize;
}
return tmp;
}
int IsFifoEmpty(Queue *Q)
{
if(Q->head == Q->tail)
{
return 1;
}
else
{
return 0;
}
}
int IsFifoFull(Queue *Q)
{
if((Q->tail+1)% Q->queuesize == Q->head)
{
return 1;
}
else
{
return 0;
}
}
//end new queue
void readIntHandler(uint16_t byteReceived)
{
QueueIn(&MyQueue,(uint8_t)byteReceived);
}
void QueueInit(struct FifoQueue *Queue)
{
Queue->rear=0;
Queue->front = Queue->rear;
Queue->count = 0;
}
uint8_t QueueIn(struct FifoQueue *Queue,ElemType sdat)
{
if((Queue->front == Queue->rear) && (Queue->count == QueueSize))
{
return QueueFull;
}else
{
Queue->dat[Queue->rear] = sdat;
Queue->rear = (Queue->rear + 1) % QueueSize;
Queue->count = Queue->count + 1;
return QueueOperateOk;
}
}
uint8_t QueueOut(struct FifoQueue *Queue,ElemType *sdat)
{
if((Queue->front == Queue->rear) && (Queue->count == 0))
{
return QueueEmpty;
}else
{
*sdat = Queue->dat[Queue->front];
Queue->front = (Queue->front + 1) % QueueSize;
Queue->count = Queue->count - 1;
return QueueOperateOk;
}
}
uint8_t Serial_available()
{
if(MyQueue.count==0&&(MyQueue.front==MyQueue.rear))
return 0;
else
return 1;
}
uint8_t Serial_read()
{
QueueOut(&MyQueue,&Queuedata);
return Queuedata;
}
//buffer finish added
#if (!defined(UART_BASES))
#ifdef UART2
#define UART_BASES {UART0, UART1, UART2}
#elif UART3
#define UART_BASES {UART0, UART1, UART2, UART3}
#elif UART4
#define UART_BASES {UART0, UART1, UART2, UART3, UART4}
#elif UART5
#define UART_BASES {UART0, UART1, UART2, UART3, UART4, UART5}
#else
#define UART_BASES {UART0, UART1}
#endif
#endif
/* gloabl const table defination */
static UART_Type * const UARTBase[] = UART_BASES;
/* callback function slot */
static UART_CallBackTxType UART_CallBackTxTable[ARRAY_SIZE(UARTBase)] = {NULL};
static UART_CallBackRxType UART_CallBackRxTable[ARRAY_SIZE(UARTBase)] = {NULL};
/* special use for printf */
static uint8_t UART_DebugInstance;
/* instance clock gate table */
static const Reg_t ClkTbl[] =
{
{(void*)&(SIM->SCGC4), SIM_SCGC4_UART0_MASK},
{(void*)&(SIM->SCGC4), SIM_SCGC4_UART1_MASK},
{(void*)&(SIM->SCGC4), SIM_SCGC4_UART2_MASK},
#ifdef UART3
{(void*)&(SIM->SCGC4), SIM_SCGC4_UART3_MASK},
#endif
#ifdef UART4
{(void*)&(SIM->SCGC1), SIM_SCGC1_UART4_MASK},
#endif
#ifdef UART5
{(void*)&(SIM->SCGC1), SIM_SCGC1_UART5_MASK},
#endif
};
/* interrupt handler table */
static const IRQn_Type UART_IRQnTable[] =
{
UART0_RX_TX_IRQn,
UART1_RX_TX_IRQn,
UART2_RX_TX_IRQn,
#ifdef UART3
UART3_RX_TX_IRQn,
#endif
#ifdef UART4
UART4_RX_TX_IRQn,
#endif
#ifdef UART5
UART5_RX_TX_IRQn,
#endif
};
static const uint32_t UART_TIFOSizeTable[] = {1, 4, 8, 16, 32, 64, 128};
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __CC_ARM // MDK Support
struct __FILE
{
int handle;
/* Whatever you require here. If the only file you are using is */
/* standard output using printf() for debugging, no file handling */
/* is required. */
};
/* FILE is typedef’ d in stdio.h. */
FILE __stdout;
FILE __stdin;
/**
* \brief put char, called by printf
* \note 若串口初始化完成之后,调用printf函数会重定向到uart的发送函数
* \note 即需要打印的数据可以通过PC的串口调试助手(终端)打印出来
*/
__weak int fputc(int ch,FILE *f)
{
UART_WriteByte(UART_DebugInstance, ch);
return ch;
}
__weak int fgetc(FILE *f)
{
uint16_t ch;
while(UART_ReadByte(UART_DebugInstance, &ch));
return (ch & 0xFF);
}
#ifdef __cplusplus
}
#endif
#elif __ICCARM__ /* IAR support */
#include <yfuns.h>
__weak size_t __write(int handle, const unsigned char * buffer, size_t size)
{
size_t nChars = 0;
if (buffer == 0)
{
/* This means that we should flush internal buffers. Since we*/
/* don't we just return. (Remember, "handle" == -1 means that all*/
/* handles should be flushed.)*/
return 0;
}
/* This function only writes to "standard out" and "standard err",*/
/* for all other file handles it returns failure.*/
if ((handle != _LLIO_STDOUT) && (handle != _LLIO_STDERR))
{
return _LLIO_ERROR;
}
/* Send data.*/
while (size--)
{
UART_WriteByte(UART_DebugInstance, *buffer++);
++nChars;
}
return nChars;
}
__weak size_t __read(int handle, unsigned char * buffer, size_t size)
{
size_t nChars = 0;
uint16_t ch = 0;
if (buffer == 0)
{
/* This means that we should flush internal buffers. Since we*/
/* don't we just return. (Remember, "handle" == -1 means that all*/
/* handles should be flushed.)*/
return 0;
}
/* This function only writes to "standard out" and "standard err",*/
/* for all other file handles it returns failure.*/
if ((handle != _LLIO_STDIN) && (handle != _LLIO_STDERR))
{
return _LLIO_ERROR;
}
/* read data.*/
while (size--)
{
while(UART_ReadByte(UART_DebugInstance, &ch));
*buffer++ = (char)ch & 0xFF;
++nChars;
}
return nChars;
}
#endif
/**
* \brief UART putchar function
* \attention 内部函数,用户无法调用
* \param[in] instance UART模块号
* \param[in] str 指向字符串常量的指针
* \retval None
*/
static void UART_putstr(uint32_t instance, const char *str)
{
while(*str != '\0')
{
UART_WriteByte(instance, *str++);
}
}
/**
* \brief 进制转换
* \attention 内部函数,用户无法调用
* \retval None
*/
static void printn(unsigned int n, unsigned int b)
{
static char *ntab = "0123456789ABCDEF";
unsigned int a, m;
if (n / b)
{
a = n / b;
printn(a, b);
}
m = n % b;
UART_WriteByte(UART_DebugInstance, ntab[m]);
}
/**
* \brief UART printf function
*/
int UART_printf(uint32_t instance, const char *fmt, ...)
{
char c;
unsigned int
没有合适的资源?快使用搜索试试~ 我知道了~
智能车竞赛 摄像头组学习项目
共118个文件
h:55个
c:43个
lib:2个
0 下载量 145 浏览量
2024-02-19
17:03:26
上传
评论
收藏 7.64MB ZIP 举报
温馨提示
智能车竞赛 摄像头组学习项目
资源推荐
资源详情
资源评论
收起资源包目录
智能车竞赛 摄像头组学习项目
(118个子文件)
seusmartcar.Debug.cspy.bat 2KB
uart.c 33KB
ftm.c 31KB
FTM_B.c 28KB
oled.c 24KB
sd.c 24KB
system_MK60D10.c 21KB
gpio.c 20KB
adc.c 19KB
spi.c 16KB
can.c 16KB
nfc.c 15KB
dma.c 14KB
usbd.c 13KB
enet.c 13KB
usbd_desc.c 12KB
main.c 11KB
dac.c 11KB
rtc.c 11KB
i2c.c 10KB
i2s.c 10KB
lptmr.c 8KB
tsi.c 8KB
img_processing.c 7KB
pit.c 7KB
crc.c 7KB
pdb.c 7KB
common.c 6KB
flexbus.c 6KB
flash.c 6KB
wdog.c 5KB
sysinit.c 5KB
DEV_SCCB.c 5KB
cpuidy.c 5KB
init.c 4KB
SCCB.c 4KB
init.c 4KB
systick.c 4KB
usb_cdc.c 2KB
vref.c 2KB
usb_hid.c 2KB
isr.c 1009B
varieble.c 817B
cmp.c 412B
seusmartcar.crun 351B
seusmartcar.dbgdt 5KB
seusmartcar.dep 37KB
seusmartcar.dni 3KB
Backup of seusmartcar.ewd 88KB
seusmartcar.ewd 72KB
seusmartcar.ewp 53KB
Backup of seusmartcar.ewp 51KB
seusmartcar.ewt 8KB
seusmartcar.eww 165B
MK60DZ10.h 884KB
MK60D10.h 514KB
arm_math.h 233KB
core_cm4.h 106KB
core_cm0plus.h 40KB
core_cm4_simd.h 22KB
core_cmInstr.h 20KB
core_cmFunc.h 16KB
ftm.h 8KB
usb.h 7KB
adc.h 7KB
dma.h 7KB
common.h 6KB
uart.h 6KB
gpio.h 5KB
arm_common_tables.h 5KB
enet.h 4KB
tsi.h 4KB
flexbus.h 4KB
spi.h 4KB
can.h 4KB
system_MK60D10.h 3KB
dac.h 3KB
pdb.h 3KB
i2c.h 3KB
arm_const_structs.h 3KB
lptmr.h 2KB
i2s.h 2KB
crc.h 2KB
rtc.h 2KB
FTM_B.h 2KB
sd.h 2KB
pit.h 2KB
oled.h 2KB
wdog.h 1KB
nfc.h 1KB
usb_desc.h 1KB
cpuidy.h 1KB
vref.h 1KB
chlib_k.h 1KB
flash.h 968B
varieble.h 912B
config.h 840B
usb_cdc.h 765B
cmp.h 750B
SysTick.h 747B
共 118 条
- 1
- 2
资源评论
学习资源网
- 粉丝: 938
- 资源: 900
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功