buf.cpp
资源名称:se06.rar [点击查看]
上传用户:kepeng103
上传日期:2022-07-27
资源大小:2653k
文件大小:1k
源码类别:
DSP编程
开发平台:
C/C++
- #include "..commonhal.h"
- #include "buf.h"
- #include <stdio.h>
- int16 in[2][FRAME_LENGTH];
- int16 out[2][FRAME_LENGTH];
- volatile int i,j;
- volatile int m,n;
- int last_read = 0;
- int last_write = 0;
- void buf_init(void)
- {
- i = 0;
- j = 0;
- m = 0;
- n = 0;
- last_read = 0;
- last_write = 0;
- }
- void data_in(int16 data)
- {
- static int k = 0;
- in[i][j] = data;
- if(++j == FRAME_LENGTH) {
- j = 0;
- i ^= 0x1;
- if(++k == 4) {
- k = 0;
- REG32(MCASP1_PDOUT) ^= 0x10;
- }
- }
- }
- int16 data_out(void)
- {
- static int k = 0;
- int16 data = out[m][n];
- if(++n == FRAME_LENGTH) {
- n = 0;
- m ^= 0x1;
- if(++k == 4) {
- k = 0;
- REG32(MCASP1_PDOUT) ^= 0x8;
- }
- }
- return data;
- }
- int16 *read_data(void)
- {
- int16 *data;
- while(last_read == i)
- data = in[last_read];
- last_read = i;
- return data;
- }
- void write_data(int16 *data)
- {
- while(last_write == m);
- for(int k=0; k<FRAME_LENGTH; k++)
- {out[last_write][k] = data[k];}
- last_write = m;
- }