2024-02-22 11:22:14 +01:00

94 lines
2.6 KiB
C

/*
* Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders
* All rights reserved.
*/
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <NoRTOS.h>
#include <ti/devices/cc32xx/inc/hw_memmap.h>
#include <ti/devices/cc32xx/inc/hw_types.h>
#include <ti/devices/cc32xx/driverlib/prcm.h>
#include <ti/devices/cc32xx/driverlib/i2s.h>
#include <ti/drivers/I2C.h>
#include "ti_drivers_config.h"
#include "config.h"
// You can select the sample rate here:
#define SAMPLINGFREQUENCY 36000
#if SAMPLINGFREQUENCY < 8000 || SAMPLINGFREQUENCY > 48000 || SAMPLINGFREQUENCY % 4000 != 0
#error Sampling Frequency must be between 8 kHz and 48 kHz (included) and must be a multiple of 4 kHz.
#endif
//const int AL = 4;
//const int16_t A[4] = {
// 519, 1558, 1558, 519
//};
//const int BL = 4;
//const int16_t B[4] = {
// 16384, -23905, 14915, -3241
//};
//const int NL = 4;
//const int16_t NUM[4] = {
// 519, 1558, 1558, 519
//};
//const int DL = 4;
//const int16_t DEN[4] = {
// 16384, -23904, 14915, -3241
//};
#include "/home/mreenen/.local/MATLAB/R2022a/extern/include/tmwtypes.h"
#include "IIR_fixed-points2.h"
int16_t buffer_N[NL];
int16_t buffer_D[DL];
int main(void)
{
// Init CC3220S LAUNCHXL board.
Board_initGeneral();
// Prepare to use TI drivers without operating system.
NoRTOS_start();
// Configure an I2C connection which is used to configure the audio codec.
I2C_Handle i2cHandle = ConfigureI2C(CONFIG_I2C_0, I2C_400kHz);
// Configure the audio codec.
ConfigureAudioCodec(i2cHandle, SAMPLINGFREQUENCY);
// Configure an I2S connection which is use to send/receive samples to/from the codec.
ConfigureI2S(CONFIG_I2S_0, I2S_BASE, SAMPLINGFREQUENCY);
unsigned long dataLeft, dataRight;
int k;
while (1)
{
int64_t out;
I2SDataGet(I2S_BASE, I2S_DATA_LINE_1, &dataLeft);
I2SDataPut(I2S_BASE, I2S_DATA_LINE_0,(int16_t) 0);
I2SDataGet(I2S_BASE, I2S_DATA_LINE_1, &dataRight);
buffer_N[0] = (int16_t)dataRight;
out = 0;
for (k=0; k < NL; k++){
out += (int64_t)NUM[k] * (int64_t)buffer_N[k];
}
for (k=1; k < DL; k++){
out -= (int64_t)DEN[k] * (int64_t)buffer_D[k];
}
out >>= 12;
//out /= ((int64_t)DEN[0]);
buffer_D[0] = (int16_t)out;
for(k=DL-1; k >= 1; k--){
buffer_N[k] = buffer_N[k-1];
buffer_D[k] = buffer_D[k-1];
}
I2SDataPut(I2S_BASE, I2S_DATA_LINE_0, (int16_t)out);
}
return 0;
}