commit efd136e96781bd2ef84248e918fce20c7b998e12 Author: MReenen Date: Thu Feb 22 11:22:14 2024 +0100 move everything to git diff --git a/dis10.zip b/dis10.zip new file mode 100644 index 0000000..fce312f Binary files /dev/null and b/dis10.zip differ diff --git a/dis10_lab2.1A b/dis10_lab2.1A new file mode 160000 index 0000000..84afbb3 --- /dev/null +++ b/dis10_lab2.1A @@ -0,0 +1 @@ +Subproject commit 84afbb3b5b5cfdf2fc04355fe0a514696bd7db3e diff --git a/dis10_lab2.1B b/dis10_lab2.1B new file mode 160000 index 0000000..75e408f --- /dev/null +++ b/dis10_lab2.1B @@ -0,0 +1 @@ +Subproject commit 75e408f7cf887aaba3715fa6db4b586455634873 diff --git a/dis10_lab2.2 b/dis10_lab2.2 new file mode 160000 index 0000000..b395a3d --- /dev/null +++ b/dis10_lab2.2 @@ -0,0 +1 @@ +Subproject commit b395a3de77a5c6dac62567a179ba4cdefebccb01 diff --git a/dis10_lab2.2.zip b/dis10_lab2.2.zip new file mode 100644 index 0000000..a320e9a Binary files /dev/null and b/dis10_lab2.2.zip differ diff --git a/dis10_lab2.3 b/dis10_lab2.3 new file mode 160000 index 0000000..5222e5f --- /dev/null +++ b/dis10_lab2.3 @@ -0,0 +1 @@ +Subproject commit 5222e5f1f146d27a94f5b22abeee0be0bc639d3b diff --git a/dis10_lab3.4_float/.ccsproject b/dis10_lab3.4_float/.ccsproject new file mode 100644 index 0000000..8ed2f71 --- /dev/null +++ b/dis10_lab3.4_float/.ccsproject @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_float/.cproject b/dis10_lab3.4_float/.cproject new file mode 100644 index 0000000..92dd42c --- /dev/null +++ b/dis10_lab3.4_float/.cproject @@ -0,0 +1,386 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dis10_lab3.4_float/.gitignore b/dis10_lab3.4_float/.gitignore new file mode 100644 index 0000000..7c1916f --- /dev/null +++ b/dis10_lab3.4_float/.gitignore @@ -0,0 +1,2 @@ +/MCU+Image/ +/Debug/ diff --git a/dis10_lab3.4_float/.launches/dis10_4.2_2.1.launch b/dis10_lab3.4_float/.launches/dis10_4.2_2.1.launch new file mode 100644 index 0000000..cecaeb9 --- /dev/null +++ b/dis10_lab3.4_float/.launches/dis10_4.2_2.1.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_float/.launches/dis10_4.2_2.2.launch b/dis10_lab3.4_float/.launches/dis10_4.2_2.2.launch new file mode 100644 index 0000000..81082fd --- /dev/null +++ b/dis10_lab3.4_float/.launches/dis10_4.2_2.2.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_float/.launches/dis10_4.2_3.3.launch b/dis10_lab3.4_float/.launches/dis10_4.2_3.3.launch new file mode 100644 index 0000000..2864bf6 --- /dev/null +++ b/dis10_lab3.4_float/.launches/dis10_4.2_3.3.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_float/.launches/dis10_lab3.3.launch b/dis10_lab3.4_float/.launches/dis10_lab3.3.launch new file mode 100644 index 0000000..96d66a5 --- /dev/null +++ b/dis10_lab3.4_float/.launches/dis10_lab3.3.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_float/.launches/dis10_lab3.4_float.launch b/dis10_lab3.4_float/.launches/dis10_lab3.4_float.launch new file mode 100644 index 0000000..d2edfd0 --- /dev/null +++ b/dis10_lab3.4_float/.launches/dis10_lab3.4_float.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_float/.launches/dis10_lab3.4_liniaire.launch b/dis10_lab3.4_float/.launches/dis10_lab3.4_liniaire.launch new file mode 100644 index 0000000..cc033cf --- /dev/null +++ b/dis10_lab3.4_float/.launches/dis10_lab3.4_liniaire.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_float/.launches/line_in_2_line_out.launch b/dis10_lab3.4_float/.launches/line_in_2_line_out.launch new file mode 100644 index 0000000..e08bac4 --- /dev/null +++ b/dis10_lab3.4_float/.launches/line_in_2_line_out.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_float/.project b/dis10_lab3.4_float/.project new file mode 100644 index 0000000..4f64306 --- /dev/null +++ b/dis10_lab3.4_float/.project @@ -0,0 +1,34 @@ + + + dis10_lab3.3 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.ti.ccstudio.core.ccsNature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + Board.html + 1 + COM_TI_SIMPLELINK_CC32XX_SDK_INSTALL_DIR/source/ti/boards/CC3220S_LAUNCHXL/Board.html + + + diff --git a/dis10_lab3.4_float/.settings/org.eclipse.cdt.codan.core.prefs b/dis10_lab3.4_float/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..98b6350 --- /dev/null +++ b/dis10_lab3.4_float/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +inEditor=false +onBuild=false diff --git a/dis10_lab3.4_float/.settings/org.eclipse.cdt.debug.core.prefs b/dis10_lab3.4_float/.settings/org.eclipse.cdt.debug.core.prefs new file mode 100644 index 0000000..58d4fb2 --- /dev/null +++ b/dis10_lab3.4_float/.settings/org.eclipse.cdt.debug.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker diff --git a/dis10_lab3.4_float/.settings/org.eclipse.core.resources.prefs b/dis10_lab3.4_float/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..97bbf44 --- /dev/null +++ b/dis10_lab3.4_float/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +encoding//Debug/makefile=UTF-8 +encoding//Debug/objects.mk=UTF-8 +encoding//Debug/sources.mk=UTF-8 +encoding//Debug/subdir_rules.mk=UTF-8 +encoding//Debug/subdir_vars.mk=UTF-8 +encoding//release/sources.mk=UTF-8 +encoding//release/subdir_rules.mk=UTF-8 +encoding//release/subdir_vars.mk=UTF-8 +encoding//release2/sources.mk=UTF-8 +encoding//release2/subdir_rules.mk=UTF-8 +encoding//release2/subdir_vars.mk=UTF-8 diff --git a/dis10_lab3.4_float/audio.syscfg b/dis10_lab3.4_float/audio.syscfg new file mode 100644 index 0000000..1ce1557 --- /dev/null +++ b/dis10_lab3.4_float/audio.syscfg @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2018-2021, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +// @cliArgs --board /ti/boards/CC3220S_LAUNCHXL --rtos nortos + +/* + * gpiointerrupt.syscfg + */ +/* ======== Boosterpacks ========= BroJZ 20220415*/ +const CC3200AUDBOOST = scripting.addHardware("/ti/boards/boosterpacks/CC3200AUDBOOST"); + +/* ======== TIRTOS7 ======== */ +if (system.getRTOS() === "tirtos7") { + const tirtos7_release_syscfg_js = system.getScript("tirtos7_release.syscfg.js"); +} + +/** + * Import the modules used in this configuration. + */ +const I2C = scripting.addModule("/ti/drivers/I2C"); +const I2C1 = I2C.addInstance(); +const I2S = scripting.addModule("/ti/drivers/I2S"); +const I2S1 = I2S.addInstance(); +const RTOS = scripting.addModule("/ti/drivers/RTOS"); + +/** + * Write custom configuration values to the imported modules. + */ +I2C1.$name = "CONFIG_I2C_0"; +I2C1.$hardware = system.deviceData.board.components.LP_I2C; + +I2S1.$name = "CONFIG_I2S_0"; +I2S1.interruptPriority = "2"; +I2S1.$hardware = CC3200AUDBOOST.components.CC3200AUDBOOST_I2S; + +const Power = scripting.addModule("/ti/drivers/Power", {}, false); +Power.parkPins.$name = "ti_drivers_power_PowerCC32XXPins0"; + +RTOS.name = "NoRTOS"; + +/** + * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future + * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to + * re-solve from scratch. + */ +I2C1.i2c.$suggestSolution = "I2C0"; +I2C1.i2c.sdaPin.$suggestSolution = "boosterpack.10"; +I2C1.i2c.sclPin.$suggestSolution = "boosterpack.9"; +I2S1.i2s.$suggestSolution = "McASP0"; +I2S1.i2s.SD0Pin.$suggestSolution = "boosterpack.29"; +I2S1.i2s.SD1Pin.$suggestSolution = "boosterpack.30"; +I2S1.i2s.SCKPin.$suggestSolution = "boosterpack.28"; +I2S1.i2s.WSPin.$suggestSolution = "boosterpack.27"; +I2S1.i2s.dmaRxChannel.$suggestSolution = "UDMA_CH18"; +I2S1.i2s.dmaTxChannel.$suggestSolution = "UDMA_CH19"; diff --git a/dis10_lab3.4_float/berekeningen klokinstellingen codec.xlsx b/dis10_lab3.4_float/berekeningen klokinstellingen codec.xlsx new file mode 100644 index 0000000..304dcbd Binary files /dev/null and b/dis10_lab3.4_float/berekeningen klokinstellingen codec.xlsx differ diff --git a/dis10_lab3.4_float/cc32xxs_nortos.cmd b/dis10_lab3.4_float/cc32xxs_nortos.cmd new file mode 100644 index 0000000..4e6d27a --- /dev/null +++ b/dis10_lab3.4_float/cc32xxs_nortos.cmd @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018-2020, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +--stack_size=0x1000 +--heap_size=0x8000 +--entry_point=resetISR +--diag_suppress=10063 /* suppress warning about non _c_int00 entry point */ + +/* + * The starting address of the application. Normally the interrupt vectors + * must be located at the beginning of the application. + */ +#define SRAM_BASE 0x20004000 +#define SRAM2_BASE 0x20000000 + +MEMORY +{ + SRAM (RWX) : origin = 0x20004000, length = 0x00040000 - 0x4000 + SRAM2 (RWX) : origin = 0x20000000, length = 0x4000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : origin = 0x90000000, length = 0x40000 +} + +/* Section allocation in memory */ + +SECTIONS +{ + .text : > SRAM + .TI.ramfunc : > SRAM + .const : > SRAM + .rodata : > SRAM + .cinit : > SRAM + .pinit : > SRAM + .init_array : > SRAM + + .data : > SRAM + .bss : > SRAM + .sysmem : > SRAM + .stack : > SRAM2(HIGH) + + .resetVecs : > SRAM_BASE + .ramVecs : > SRAM2_BASE, type=NOLOAD + + .log_data : > LOG_DATA, type = COPY +} diff --git a/dis10_lab3.4_float/config.c b/dis10_lab3.4_float/config.c new file mode 100644 index 0000000..af9798e --- /dev/null +++ b/dis10_lab3.4_float/config.c @@ -0,0 +1,289 @@ +/* + * Configure functions to use the TI TLV320AIC3254 codec on the + * CC3200AUDBOOST board with the CC3220S-LAUNCHXL board + * without using DMA. + * + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + * + * Based on Driver for TI TLV320AIC3110 CODEC + * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "config.h" + +// Configure an I2C connection using the TI I2C driver. + +I2C_Handle ConfigureI2C(uint_least8_t index, I2C_BitRate bitRate) +{ + I2C_Handle i2cHandle; + I2C_Params i2cParams; + I2C_init(); + I2C_Params_init(&i2cParams); + i2cParams.bitRate = bitRate; + i2cHandle = I2C_open(index, &i2cParams); + if (i2cHandle == NULL) { + // Error initializing I2C. + while (1); + } + return i2cHandle; +} + +// Configure an I2S connection which is use to send/receive samples to/from the codec. + +void ConfigureI2S(unsigned long peripheral, unsigned long base, unsigned int samplingFrequency) +{ + // Register power dependency. Keeps the I2S clock running in SLP and DSLP modes. + int_fast16_t ret = Power_setDependency(PowerCC32XX_PERIPH_I2S); + if (ret != Power_SOK) { + // Error setting power dependency. + while (1); + } + + // There is no TI I2S driver (without DMA) available so the TI driverlib API is used. + PRCMPeripheralReset(peripheral); + I2SEnable(base, I2S_MODE_TX_RX_SYNC); + + unsigned int bitClock = samplingFrequency * 16 * 2; + PRCMI2SClockFreqSet(bitClock); + I2SConfigSetExpClk(base, bitClock, bitClock, I2S_MODE_MASTER | I2S_SLOT_SIZE_16 | I2S_PORT_CPU); + + I2SSerializerConfig(base, I2S_DATA_LINE_0, I2S_SER_MODE_TX, I2S_INACT_LOW_LEVEL); + I2SSerializerConfig(base, I2S_DATA_LINE_1, I2S_SER_MODE_RX, I2S_INACT_LOW_LEVEL); + + // Configure I2S pins in pin mux + PinTypeI2S(PIN_64, PIN_MODE_7); // xr0Pin = I2S SDout (CC3220S-LAUNCHXL) = DIN_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_50, PIN_MODE_6); // xr1Pin = I2S SDin (CC3220S-LAUNCHXL) = DOUT_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_53, PIN_MODE_2); // clkPin = I2S SCLK (CC3220S-LAUNCHXL) = BCLK_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_63, PIN_MODE_7); // fsxPin = I2S WC (CC3220S-LAUNCHXL) = FSYNC_J3 (CC3200AUDBOOST) + + PRCMPeripheralClkEnable(peripheral, PRCM_RUN_MODE_CLK); +} + +#define CODEC_I2C_SLAVE_ADDR ((0x30 >> 1)) + +static uint8_t CodecRegRead(I2C_Handle i2cHandle, uint8_t regAddr) +{ + I2C_Transaction i2cTransaction; + uint8_t data; + + i2cTransaction.slaveAddress = CODEC_I2C_SLAVE_ADDR; + i2cTransaction.writeBuf = ®Addr; + i2cTransaction.writeCount = 1; + i2cTransaction.readBuf = &data; + i2cTransaction.readCount = 1; + if (!I2C_transfer(i2cHandle, &i2cTransaction)) + { + // I2C transfer failed + while (1); + } + return data; +} + +static void CodecRegWrite(I2C_Handle i2cHandle, uint8_t regAddr, uint8_t regValue) +{ + uint8_t data[2]; + I2C_Transaction i2cTransaction; + + data[0] = regAddr; + data[1] = regValue; + + i2cTransaction.slaveAddress = CODEC_I2C_SLAVE_ADDR; + i2cTransaction.writeBuf = &data[0]; + i2cTransaction.writeCount = 2; + i2cTransaction.readBuf = NULL; + i2cTransaction.readCount = 0; + if (!I2C_transfer(i2cHandle, &i2cTransaction)) + { + // I2C transfer failed + while (1); + } +} + +static void CodecPageSelect(I2C_Handle i2cHandle, unsigned long pageAddress) +{ + CodecRegWrite(i2cHandle, 0, pageAddress); +} + +static void CodecReset(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Soft RESET. + CodecRegWrite(i2cHandle, 1, 0x01); + // Wait for 27000 * 3 = 81000 clock cycles @ 80 MHz ~ 1 ms. + UtilsDelay(27000); +} + +// volume: 0 -> 0 bB (Highest) to 116 -> -72.3 dB (Lowest) +void AudioVolumeControl(I2C_Handle i2cHandle, signed char volume) +{ + // Select page 1 + CodecPageSelect(i2cHandle, 1); + // Enable HPL output analog volume + CodecRegWrite(i2cHandle, 22, volume); + CodecRegWrite(i2cHandle, 23, volume); +} + +void CodecMute(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Mute. + CodecRegWrite(i2cHandle, 64, 0x0C); +} + +void CodecUnmute(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Unmute. + CodecRegWrite(i2cHandle, 64, 0x00); +} + +// Codec configure: + // PGA (Programmable Gain Amplifier) = 0 dB. + // Headphone Output = enabled. + // Line outputs (to class D amplifier) = disabled. + // ADC gain = 0 dB. + // AGC (Automatic Gain Control) = disabled. + // ADC processing block = PRB_R1 (default). + // Microphone = disabled. + // DAC processing block = PRB_P1 (default). + // DRC (Dynamic Gain Compression) = disabled. + +void ConfigureAudioCodec(I2C_Handle i2cHandle, unsigned int samplingFrequency) +{ + // Check parameter. + if (samplingFrequency < 8000 || samplingFrequency > 48000 || samplingFrequency % 4000 != 0) + { + while(1); + // Wrong value for sampling frequency. + } + size_t sampleIndex = (samplingFrequency / 4000) - 2; + // values for DOSR, MDAC, NDAC, NADC and J in steps of 4 kHz starting from 8 kHz to 48 kHz. + // 8 12 16 20 24 28 32 36 40 44 48 + int DOSR[] = {512, 512, 384, 304, 256, 208, 192, 160, 144, 128, 128}; + int MDAC[] = { 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2}; + int NDAC[] = { 1, 1, 2, 16, 8, 8, 8, 8, 8, 8, 8}; + int NADC[] = { 2, 2, 3, 19, 16, 13, 12, 10, 9, 8, 8}; + int J[] = { 4, 4, 6, 38, 32, 26, 24, 20, 18, 16, 16}; + + // Reset code for startup. + CodecReset(i2cHandle); + + // Select page 0. + CodecPageSelect(i2cHandle, 0); + + // Set I2S Mode and Word Length = 16 bits, BCLK and WCLK are inputs to the device. + CodecRegWrite(i2cHandle, 27, 0x00); + // Clock settings chip + CodecRegWrite(i2cHandle, 4, 0x03); // PLL CLock is CODEC_CLKIN + CodecRegWrite(i2cHandle, 5, 0x94); // PLL enabled, P = 1, R = 4 + CodecRegWrite(i2cHandle, 6, J[sampleIndex]); // PLL J + CodecRegWrite(i2cHandle, 7, 0); // PLL D = 0 + CodecRegWrite(i2cHandle, 8, 0); // PLL D = 0 + // PLL_CLK = PLL_CLKIN * R * J.D / P = PLL_CLKIN * 4 * J = (Fs * 32) * 4 * J + + // Clock settings DAC. + CodecRegWrite(i2cHandle, 11, 0x80 + NDAC[sampleIndex]); // NDAC is powered up + CodecRegWrite(i2cHandle, 12, 0x80 + MDAC[sampleIndex]); // MDAC is powered up + CodecRegWrite(i2cHandle, 13, DOSR[sampleIndex] / 256); // DOSR + CodecRegWrite(i2cHandle, 14, DOSR[sampleIndex] % 256); + // DAC_fs = CODEC_CLKIN / (NDAC * MDAC * DOSR) + + // Clock settings ADC. + CodecRegWrite(i2cHandle, 18, 0x80 + NADC[sampleIndex]); // NADC is powered up, NADC = 2 + CodecRegWrite(i2cHandle, 19, 0x80 + 2); // MADC is powered up, MADC = 2 + CodecRegWrite(i2cHandle, 20, 128); // AOSR = 128 + // ADC_fs = CODEC_CLKIN / (NADC * MADC * AOSR) + + // Configure power supplies. + CodecPageSelect(i2cHandle, 1); + CodecRegWrite(i2cHandle, 1, 0x08); // AVdd and DVdd are connected + CodecRegWrite(i2cHandle, 2, 0x01); // LDO enabled AVDD LDO output = 1.72 V + CodecRegWrite(i2cHandle, 71, 0x32); // Aanalog input powerup = 6.4 ms + CodecRegWrite(i2cHandle, 123, 0x01); // Reference powered up in 40 ms + + // Configure ADC channel. + // Route IN1L to Left MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 52, 0x40); + // Route CM to Left MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 54, 0x40); + // Route IN1R to Right MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 55, 0x40); + // Route CM to Right MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 57,0x40); + // Floating IN1L. + CodecRegWrite(i2cHandle, 58, 0xC0); + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + // Power up LADC/RADC. + CodecRegWrite(i2cHandle, 81, 0xC0); + // Unmute LADC/RADC. + CodecRegWrite(i2cHandle, 82, 0x00); + + // Configure DAC channel. + // Select Page 1. + CodecPageSelect(i2cHandle, 1); + + // De-pop: soft stepping disabled, N = 5, Rpop = 6k. See SLAA408A page 11,12,13. + CodecRegWrite(i2cHandle, 20, 0x25); + + // Route LDAC/RDAC to HPL/HPR. + CodecRegWrite(i2cHandle, 12, 0x08); + CodecRegWrite(i2cHandle, 13, 0x08); + + // Power up HPL/HPR drivers. + CodecRegWrite(i2cHandle, 9, 0x30); + + // Unmute HPL/HPR driver, 0dB Gain. + CodecRegWrite(i2cHandle, 16, 0x00); + CodecRegWrite(i2cHandle, 17, 0x00); + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + + // Unmute DAC, 0dB Gain. + CodecRegWrite(i2cHandle, 65, 0x00); + CodecRegWrite(i2cHandle, 66, 0x00); + + // Select Page 1. + CodecPageSelect(i2cHandle, 1); + + while (CodecRegRead(i2cHandle, 63) & 0x11000000 != 0x11000000) + { + UtilsDelay(27000); // delay 27000 * 3 = 81000 clock cycles @ 80 MHz ~ 1 ms. + } + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + + // Power up LDAC/RDAC. + CodecRegWrite(i2cHandle, 63, 0xd4); + + // Unmute LDAC/RDAC. + CodecRegWrite(i2cHandle, 64, 0x00); +} diff --git a/dis10_lab3.4_float/config.h b/dis10_lab3.4_float/config.h new file mode 100644 index 0000000..bfaa628 --- /dev/null +++ b/dis10_lab3.4_float/config.h @@ -0,0 +1,41 @@ +/* + * Configure functions to use the TI TLV320AIC3254 codec on the + * CC3200AUDBOOST board with the CC3220S-LAUNCHXL board + * without using DMA. + * + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + * + * Based on Driver for TI TLV320AIC3110 codec + * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + */ +#ifndef __HR_CONFIG_H__ +#define __HR_CONFIG_H__ + +#include + +// Configure an I2C connection using the TI I2C driver. +extern I2C_Handle ConfigureI2C(uint_least8_t index, I2C_BitRate bitRate); + +// Configure an I2S connection using the TI driverlib API. +extern void ConfigureI2S(unsigned long peripheral, unsigned long base, unsigned int samplingFrequency); + +// Functions to configure the codec using an I2C connection +// volume: 0 -> 0 bB (Highest) to 116 -> -72.3 dB (Lowest) +extern void AudioVolumeControl(I2C_Handle i2cHandle, signed char volume); +extern void CodecMute(I2C_Handle i2cHandle); +extern void CodecUnmute(I2C_Handle i2cHandle); +// Codec configure: + // PGA (Programmable Gain Amplifier) = 0 dB. + // Headphone Output = enabled. + // Line outputs (to class D amplifier) = disabled. + // ADC gain = 0 dB. + // AGC (Automatic Gain Control) = disabled. + // ADC processing block = PRB_R1 (default). + // Microphone = disabled. + // DAC processing block = PRB_P1 (default). + // DRC (Dynamic Gain Compression) = disabled. +extern void ConfigureAudioCodec(I2C_Handle i2cHandle, unsigned int samplingFrequency); + +#endif diff --git a/dis10_lab3.4_float/fdacoefs.h b/dis10_lab3.4_float/fdacoefs.h new file mode 100644 index 0000000..758dd86 --- /dev/null +++ b/dis10_lab3.4_float/fdacoefs.h @@ -0,0 +1,43 @@ +/* + * Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool + * Generated by MATLAB(R) 9.12 and DSP System Toolbox 9.14. + * Generated on: 30-May-2022 14:58:41 + */ + +/* + * Discrete-Time IIR Filter (real) + * ------------------------------- + * Filter Structure : Direct-Form II + * Numerator Length : 4 + * Denominator Length : 4 + * Stable : Yes + * Linear Phase : No + * Arithmetic : fixed + * Numerator : s16,18 -> [-1.250000e-01 1.250000e-01) + * Denominator : s16,14 -> [-2 2) + * Input : s16,16 -> [-5.000000e-01 5.000000e-01) + * Output : s16,15 -> [-1 1) + * State : s16,15 -> [-1 1) + * Numerator Prod : s32,33 -> [-2.500000e-01 2.500000e-01) + * Denominator Prod : s32,29 -> [-4 4) + * Numerator Accum : s40,33 -> [-64 64) + * Denominator Accum : s40,29 -> [-1024 1024) + * Round Mode : convergent + * Overflow Mode : wrap + * Cast Before Sum : true + */ + +/* General type conversion for MATLAB generated C-code */ +#include "tmwtypes.h" +/* + * Expected path to tmwtypes.h + * /home/mreenen/.local/MATLAB/R2022a/extern/include/tmwtypes.h + */ +const int NL = 4; +const int16_T NUM[4] = { + 519, 1558, 1558, 519 +}; +const int DL = 4; +const int16_T DEN[4] = { + 16384, -23905, 14915, -3241 +}; diff --git a/dis10_lab3.4_float/main_nortos.c b/dis10_lab3.4_float/main_nortos.c new file mode 100644 index 0000000..68a8881 --- /dev/null +++ b/dis10_lab3.4_float/main_nortos.c @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#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 float NUM[4] = { +// 0.03169250488, 0.09507369995, 0.09507369995, 0.03169250488 +//}; +//const int DL = 4; +//const float DEN[4] = { +// 1, -1.458984375, 0.9103393555, -0.1978149414 +//}; + +const int NL = 11; +const float NUM[11] = { + 1.105590945372e-05,0.0001105590999941,0.0004975159536116, 0.001326709170826, + 0.002321741078049, 0.002786089200526, 0.002321741078049, 0.001326709170826, + 0.0004975159536116,0.0001105590999941,1.105590945372e-05 +}; +const int DL = 11; +const float DEN[11] = { + 1, -4.986985206604, 11.93643665314, -17.74237251282, + 17.97322845459, -12.88624191284, 6.593202114105, -2.369091749191, + 0.5706326961517, -0.08301767706871, 0.005529714748263 +}; + +float buffer_N[NL]; +float 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); + int16_t dataLeft, dataRight; + int k; + while (1) + { + float 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] = (float)dataRight; + out = 0; + for (k=0; k < NL; k++){ + out += NUM[k] * buffer_N[k]; + } + for(k=NL-1; k >= 1; k--){ + buffer_N[k] = buffer_N[k-1]; + } + for (k=1; k < DL; k++){ + out -= DEN[k] * buffer_D[k]; + } + out /= DEN[0]; + buffer_D[0] = out; + + for(k=DL-1; k >= 1; k--){ + buffer_D[k] = buffer_D[k-1]; + } + + I2SDataPut(I2S_BASE, I2S_DATA_LINE_0, out); + } + return 0; +} diff --git a/dis10_lab3.4_float/release/ccsObjs.opt b/dis10_lab3.4_float/release/ccsObjs.opt new file mode 100644 index 0000000..49626a9 --- /dev/null +++ b/dis10_lab3.4_float/release/ccsObjs.opt @@ -0,0 +1 @@ +"./syscfg/ti_drivers_config.obj" "./config.obj" "./main_nortos.obj" "../cc32xxs_nortos.cmd" -lti_utils_build_linker.cmd.genlibs -l"ti/devices/cc32xx/driverlib/ccs/Release/driverlib.a" -llibc.a \ No newline at end of file diff --git a/dis10_lab3.4_float/release/makefile b/dis10_lab3.4_float/release/makefile new file mode 100644 index 0000000..e69de29 diff --git a/dis10_lab3.4_float/release/sources.mk b/dis10_lab3.4_float/release/sources.mk new file mode 100644 index 0000000..2f01bd6 --- /dev/null +++ b/dis10_lab3.4_float/release/sources.mk @@ -0,0 +1,130 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +C55_SRCS := +A_SRCS := +ASM_UPPER_SRCS := +PINMUX_SRCS := +EXE_SRCS := +LDS_UPPER_SRCS := +CPP_SRCS := +CMD_SRCS := +O_SRCS := +ELF_SRCS := +C??_SRCS := +C64_SRCS := +C67_SRCS := +SA_SRCS := +S64_SRCS := +OPT_SRCS := +CXX_SRCS := +S67_SRCS := +S??_SRCS := +PDE_SRCS := +SV7A_SRCS := +SYSCFG_SRCS := +K_SRCS := +CLA_SRCS := +S55_SRCS := +LD_UPPER_SRCS := +OUT_SRCS := +INO_SRCS := +LIB_SRCS := +ASM_SRCS := +S_UPPER_SRCS := +SYSCONFIG_SRCS := +S43_SRCS := +LD_SRCS := +CMD_UPPER_SRCS := +C_UPPER_SRCS := +C++_SRCS := +C43_SRCS := +OBJ_SRCS := +LDS_SRCS := +S_SRCS := +CC_SRCS := +S62_SRCS := +C62_SRCS := +C_SRCS := +C55_DEPS := +C_UPPER_DEPS := +S67_DEPS := +S62_DEPS := +S_DEPS := +OPT_DEPS := +C??_DEPS := +ASM_UPPER_DEPS := +S??_DEPS := +C64_DEPS := +CXX_DEPS := +S64_DEPS := +INO_DEPS := +GEN_CMDS := +GEN_FILES := +CLA_DEPS := +S55_DEPS := +SV7A_DEPS := +EXE_OUTPUTS := +C62_DEPS := +CUSTOM_TOOL_OUTPUTS_1505879725 := +C67_DEPS := +PDE_DEPS := +GEN_MISC_DIRS := +K_DEPS := +C_DEPS := +CC_DEPS := +BIN_OUTPUTS := +GEN_OPTS := +C++_DEPS := +C43_DEPS := +S43_DEPS := +OBJS := +ASM_DEPS := +GEN_MISC_FILES := +S_UPPER_DEPS := +CPP_DEPS := +SA_DEPS := +C++_DEPS__QUOTED := +OPT_DEPS__QUOTED := +CUSTOM_TOOL_OUTPUTS_1505879725__QUOTED := +S_UPPER_DEPS__QUOTED := +SA_DEPS__QUOTED := +C??_DEPS__QUOTED := +S67_DEPS__QUOTED := +GEN_MISC_DIRS__QUOTED := +C55_DEPS__QUOTED := +CC_DEPS__QUOTED := +ASM_UPPER_DEPS__QUOTED := +SV7A_DEPS__QUOTED := +S??_DEPS__QUOTED := +OBJS__QUOTED := +C67_DEPS__QUOTED := +K_DEPS__QUOTED := +S55_DEPS__QUOTED := +GEN_CMDS__QUOTED := +GEN_MISC_FILES__QUOTED := +INO_DEPS__QUOTED := +C62_DEPS__QUOTED := +C_DEPS__QUOTED := +C_UPPER_DEPS__QUOTED := +C43_DEPS__QUOTED := +CPP_DEPS__QUOTED := +BIN_OUTPUTS__QUOTED := +GEN_FILES__QUOTED := +C64_DEPS__QUOTED := +CXX_DEPS__QUOTED := +CLA_DEPS__QUOTED := +S_DEPS__QUOTED := +ASM_DEPS__QUOTED := +S43_DEPS__QUOTED := +EXE_OUTPUTS__QUOTED := +S64_DEPS__QUOTED := +S62_DEPS__QUOTED := +PDE_DEPS__QUOTED := +GEN_OPTS__QUOTED := + +# Every subdirectory with source files must be described here +SUBDIRS := \ +. \ + diff --git a/dis10_lab3.4_float/release/subdir_rules.mk b/dis10_lab3.4_float/release/subdir_rules.mk new file mode 100644 index 0000000..a82e1c7 --- /dev/null +++ b/dis10_lab3.4_float/release/subdir_rules.mk @@ -0,0 +1,35 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +# Each subdirectory must supply rules for building sources it contributes +build-1986611567: ../audio.syscfg + @echo 'Building file: "$<"' + @echo 'Invoking: SysConfig' + "/home/mreenen/ti/sysconfig_1_10_0/sysconfig_cli.sh" -s "/home/mreenen/ti/simplelink_cc32xx_sdk_5_30_00_08/.metadata/product.json" --script "/home/mreenen/Documents/ccs/dis10_lab3.4_float/audio.syscfg" -o "syscfg" --compiler ccs + @echo 'Finished building: "$<"' + @echo ' ' + +syscfg/ti_drivers_config.c: build-1986611567 ../audio.syscfg +syscfg/ti_drivers_config.h: build-1986611567 +syscfg/ti_utils_build_linker.cmd.genlibs: build-1986611567 +syscfg/syscfg_c.rov.xs: build-1986611567 +syscfg/ti_utils_runtime_model.gv: build-1986611567 +syscfg/ti_utils_runtime_Makefile: build-1986611567 +syscfg/: build-1986611567 + +syscfg/%.obj: ./syscfg/%.c $(GEN_OPTS) | $(GEN_FILES) $(GEN_MISC_FILES) + @echo 'Building file: "$<"' + @echo 'Invoking: Arm Compiler' + "/home/mreenen/.local/ti/ccs1120/ccs/tools/compiler/ti-cgt-arm_20.2.6.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=vfplib -me -O4 --opt_for_speed=5 --include_path="/home/mreenen/Documents/ccs/dis10_lab3.4_float" --include_path="/home/mreenen/Documents/ccs/dis10_lab3.4_float/release" --include_path="/home/mreenen/ti/simplelink_cc32xx_sdk_5_30_00_08/source" --include_path="/home/mreenen/ti/simplelink_cc32xx_sdk_5_30_00_08/kernel/nortos" --include_path="/home/mreenen/ti/simplelink_cc32xx_sdk_5_30_00_08/kernel/nortos/posix" --include_path="/home/mreenen/.local/ti/ccs1120/ccs/tools/compiler/ti-cgt-arm_20.2.6.LTS/include" --define=DeviceFamily_CC3220 --define=NORTOS_SUPPORT -g --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --preproc_with_compile --preproc_dependency="syscfg/$(basename $( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_float/targetConfigs/readme.txt b/dis10_lab3.4_float/targetConfigs/readme.txt new file mode 100644 index 0000000..af97b62 --- /dev/null +++ b/dis10_lab3.4_float/targetConfigs/readme.txt @@ -0,0 +1,9 @@ +The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based +on the device and connection settings specified in your project on the Properties > General page. + +Please note that in automatic target-configuration management, changes to the project's device and/or +connection settings will either modify an existing or generate a new target-configuration file. Thus, +if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively, +you may create your own target-configuration file for this project and manage it manually. You can +always switch back to automatic target-configuration management by checking the "Manage the project's +target-configuration automatically" checkbox on the project's Properties > General page. \ No newline at end of file diff --git a/dis10_lab3.4_liniaire/.ccsproject b/dis10_lab3.4_liniaire/.ccsproject new file mode 100644 index 0000000..8ed2f71 --- /dev/null +++ b/dis10_lab3.4_liniaire/.ccsproject @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_liniaire/.cproject b/dis10_lab3.4_liniaire/.cproject new file mode 100644 index 0000000..92dd42c --- /dev/null +++ b/dis10_lab3.4_liniaire/.cproject @@ -0,0 +1,386 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dis10_lab3.4_liniaire/.gitignore b/dis10_lab3.4_liniaire/.gitignore new file mode 100644 index 0000000..7c1916f --- /dev/null +++ b/dis10_lab3.4_liniaire/.gitignore @@ -0,0 +1,2 @@ +/MCU+Image/ +/Debug/ diff --git a/dis10_lab3.4_liniaire/.launches/dis10_4.2_2.1.launch b/dis10_lab3.4_liniaire/.launches/dis10_4.2_2.1.launch new file mode 100644 index 0000000..cecaeb9 --- /dev/null +++ b/dis10_lab3.4_liniaire/.launches/dis10_4.2_2.1.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_liniaire/.launches/dis10_4.2_2.2.launch b/dis10_lab3.4_liniaire/.launches/dis10_4.2_2.2.launch new file mode 100644 index 0000000..81082fd --- /dev/null +++ b/dis10_lab3.4_liniaire/.launches/dis10_4.2_2.2.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_liniaire/.launches/dis10_4.2_3.3.launch b/dis10_lab3.4_liniaire/.launches/dis10_4.2_3.3.launch new file mode 100644 index 0000000..2864bf6 --- /dev/null +++ b/dis10_lab3.4_liniaire/.launches/dis10_4.2_3.3.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_liniaire/.launches/dis10_lab3.3.launch b/dis10_lab3.4_liniaire/.launches/dis10_lab3.3.launch new file mode 100644 index 0000000..96d66a5 --- /dev/null +++ b/dis10_lab3.4_liniaire/.launches/dis10_lab3.3.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_liniaire/.launches/dis10_lab3.4_liniaire.launch b/dis10_lab3.4_liniaire/.launches/dis10_lab3.4_liniaire.launch new file mode 100644 index 0000000..cc033cf --- /dev/null +++ b/dis10_lab3.4_liniaire/.launches/dis10_lab3.4_liniaire.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_liniaire/.launches/line_in_2_line_out.launch b/dis10_lab3.4_liniaire/.launches/line_in_2_line_out.launch new file mode 100644 index 0000000..e08bac4 --- /dev/null +++ b/dis10_lab3.4_liniaire/.launches/line_in_2_line_out.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_liniaire/.project b/dis10_lab3.4_liniaire/.project new file mode 100644 index 0000000..4f257ac --- /dev/null +++ b/dis10_lab3.4_liniaire/.project @@ -0,0 +1,34 @@ + + + dis10_lab3.4_liniaire + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.ti.ccstudio.core.ccsNature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + Board.html + 1 + COM_TI_SIMPLELINK_CC32XX_SDK_INSTALL_DIR/source/ti/boards/CC3220S_LAUNCHXL/Board.html + + + diff --git a/dis10_lab3.4_liniaire/.settings/org.eclipse.cdt.codan.core.prefs b/dis10_lab3.4_liniaire/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..98b6350 --- /dev/null +++ b/dis10_lab3.4_liniaire/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +inEditor=false +onBuild=false diff --git a/dis10_lab3.4_liniaire/.settings/org.eclipse.cdt.debug.core.prefs b/dis10_lab3.4_liniaire/.settings/org.eclipse.cdt.debug.core.prefs new file mode 100644 index 0000000..58d4fb2 --- /dev/null +++ b/dis10_lab3.4_liniaire/.settings/org.eclipse.cdt.debug.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker diff --git a/dis10_lab3.4_liniaire/.settings/org.eclipse.core.resources.prefs b/dis10_lab3.4_liniaire/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..97bbf44 --- /dev/null +++ b/dis10_lab3.4_liniaire/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +encoding//Debug/makefile=UTF-8 +encoding//Debug/objects.mk=UTF-8 +encoding//Debug/sources.mk=UTF-8 +encoding//Debug/subdir_rules.mk=UTF-8 +encoding//Debug/subdir_vars.mk=UTF-8 +encoding//release/sources.mk=UTF-8 +encoding//release/subdir_rules.mk=UTF-8 +encoding//release/subdir_vars.mk=UTF-8 +encoding//release2/sources.mk=UTF-8 +encoding//release2/subdir_rules.mk=UTF-8 +encoding//release2/subdir_vars.mk=UTF-8 diff --git a/dis10_lab3.4_liniaire/IIR fixed-points.h b/dis10_lab3.4_liniaire/IIR fixed-points.h new file mode 100644 index 0000000..107adf3 --- /dev/null +++ b/dis10_lab3.4_liniaire/IIR fixed-points.h @@ -0,0 +1,85 @@ +/* + * Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool + * Generated by MATLAB(R) 9.12 and DSP System Toolbox 9.14. + * Generated on: 25-May-2023 13:32:39 + */ + +/* + * Discrete-Time IIR Filter (real) + * ------------------------------- + * Filter Structure : Direct-Form I, Second-Order Sections + * Number of Sections : 3 + * Stable : Yes + * Linear Phase : No + * Arithmetic : fixed + * Numerator : s16,14 -> [-2 2) + * Denominator : s16,14 -> [-2 2) + * Scale Values : s16,15 -> [-1 1) + * Input : s16,15 -> [-1 1) + * Output : s16,11 -> [-16 16) + * Numerator State : s16,15 -> [-1 1) + * Denominator State : s16,15 -> [-1 1) + * Numerator Prod : s32,29 -> [-4 4) + * Denominator Prod : s32,29 -> [-4 4) + * Numerator Accum : s40,29 -> [-1024 1024) + * Denominator Accum : s40,29 -> [-1024 1024) + * Round Mode : convergent + * Overflow Mode : wrap + * Cast Before Sum : true + */ + +/* General type conversion for MATLAB generated C-code */ +#include "tmwtypes.h" +/* + * Expected path to tmwtypes.h + * C:\Program Files\MATLAB\R2022a\extern\include\tmwtypes.h + */ +#define MWSPT_NSEC 7 +const int NL[MWSPT_NSEC] = { 1,3,1,3,1,3,1 }; +const int16_T NUM[MWSPT_NSEC][3] = { + { + 15950, 0, 0 + }, + { + 16384, -32409, 16384 + }, + { + 15950, 0, 0 + }, + { + 16384, -32409, 16384 + }, + { + 15568, 0, 0 + }, + { + 16384, -32409, 16384 + }, + { + 16384, 0, 0 + } +}; +const int DL[MWSPT_NSEC] = { 1,3,1,3,1,3,1 }; +const int16_T DEN[MWSPT_NSEC][3] = { + { + 16384, 0, 0 + }, + { + 16384, -31056, 15311 + }, + { + 16384, 0, 0 + }, + { + 16384, -31983, 15790 + }, + { + 16384, 0, 0 + }, + { + 16384, -30795, 14752 + }, + { + 16384, 0, 0 + } +}; diff --git a/dis10_lab3.4_liniaire/IIR_fixed-points2.h b/dis10_lab3.4_liniaire/IIR_fixed-points2.h new file mode 100644 index 0000000..9a8c624 --- /dev/null +++ b/dis10_lab3.4_liniaire/IIR_fixed-points2.h @@ -0,0 +1,42 @@ +/* + * Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool + * Generated by MATLAB(R) 9.12 and DSP System Toolbox 9.14. + * Generated on: 25-May-2023 13:46:35 + */ + +/* + * Discrete-Time IIR Filter (real) + * ------------------------------- + * Filter Structure : Direct-Form I + * Numerator Length : 5 + * Denominator Length : 5 + * Stable : Yes + * Linear Phase : No + * Arithmetic : fixed + * Numerator : s16,12 -> [-8 8) + * Denominator : s16,12 -> [-8 8) + * Input : s16,15 -> [-1 1) + * Output : s16,8 -> [-128 128) + * Numerator Prod : s32,27 -> [-16 16) + * Denominator Prod : s32,20 -> [-2048 2048) + * Numerator Accum : s40,27 -> [-4096 4096) + * Denominator Accum : s40,20 -> [-524288 524288) + * Round Mode : convergent + * Overflow Mode : wrap + * Cast Before Sum : true + */ + +/* General type conversion for MATLAB generated C-code */ +//#include "tmwtypes.h" +/* + * Expected path to tmwtypes.h + * C:\Program Files\MATLAB\R2022a\extern\include\tmwtypes.h + */ +const int NL = 5; +const int16_T NUM[5] = { + 3804, -15048, 22490, -15048, 3804 +}; +const int DL = 5; +const int16_T DEN[5] = { + 4096, -15605, 22470, -14491, 3532 +}; diff --git a/dis10_lab3.4_liniaire/audio.syscfg b/dis10_lab3.4_liniaire/audio.syscfg new file mode 100644 index 0000000..1ce1557 --- /dev/null +++ b/dis10_lab3.4_liniaire/audio.syscfg @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2018-2021, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +// @cliArgs --board /ti/boards/CC3220S_LAUNCHXL --rtos nortos + +/* + * gpiointerrupt.syscfg + */ +/* ======== Boosterpacks ========= BroJZ 20220415*/ +const CC3200AUDBOOST = scripting.addHardware("/ti/boards/boosterpacks/CC3200AUDBOOST"); + +/* ======== TIRTOS7 ======== */ +if (system.getRTOS() === "tirtos7") { + const tirtos7_release_syscfg_js = system.getScript("tirtos7_release.syscfg.js"); +} + +/** + * Import the modules used in this configuration. + */ +const I2C = scripting.addModule("/ti/drivers/I2C"); +const I2C1 = I2C.addInstance(); +const I2S = scripting.addModule("/ti/drivers/I2S"); +const I2S1 = I2S.addInstance(); +const RTOS = scripting.addModule("/ti/drivers/RTOS"); + +/** + * Write custom configuration values to the imported modules. + */ +I2C1.$name = "CONFIG_I2C_0"; +I2C1.$hardware = system.deviceData.board.components.LP_I2C; + +I2S1.$name = "CONFIG_I2S_0"; +I2S1.interruptPriority = "2"; +I2S1.$hardware = CC3200AUDBOOST.components.CC3200AUDBOOST_I2S; + +const Power = scripting.addModule("/ti/drivers/Power", {}, false); +Power.parkPins.$name = "ti_drivers_power_PowerCC32XXPins0"; + +RTOS.name = "NoRTOS"; + +/** + * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future + * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to + * re-solve from scratch. + */ +I2C1.i2c.$suggestSolution = "I2C0"; +I2C1.i2c.sdaPin.$suggestSolution = "boosterpack.10"; +I2C1.i2c.sclPin.$suggestSolution = "boosterpack.9"; +I2S1.i2s.$suggestSolution = "McASP0"; +I2S1.i2s.SD0Pin.$suggestSolution = "boosterpack.29"; +I2S1.i2s.SD1Pin.$suggestSolution = "boosterpack.30"; +I2S1.i2s.SCKPin.$suggestSolution = "boosterpack.28"; +I2S1.i2s.WSPin.$suggestSolution = "boosterpack.27"; +I2S1.i2s.dmaRxChannel.$suggestSolution = "UDMA_CH18"; +I2S1.i2s.dmaTxChannel.$suggestSolution = "UDMA_CH19"; diff --git a/dis10_lab3.4_liniaire/berekeningen klokinstellingen codec.xlsx b/dis10_lab3.4_liniaire/berekeningen klokinstellingen codec.xlsx new file mode 100644 index 0000000..304dcbd Binary files /dev/null and b/dis10_lab3.4_liniaire/berekeningen klokinstellingen codec.xlsx differ diff --git a/dis10_lab3.4_liniaire/cc32xxs_nortos.cmd b/dis10_lab3.4_liniaire/cc32xxs_nortos.cmd new file mode 100644 index 0000000..4e6d27a --- /dev/null +++ b/dis10_lab3.4_liniaire/cc32xxs_nortos.cmd @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018-2020, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +--stack_size=0x1000 +--heap_size=0x8000 +--entry_point=resetISR +--diag_suppress=10063 /* suppress warning about non _c_int00 entry point */ + +/* + * The starting address of the application. Normally the interrupt vectors + * must be located at the beginning of the application. + */ +#define SRAM_BASE 0x20004000 +#define SRAM2_BASE 0x20000000 + +MEMORY +{ + SRAM (RWX) : origin = 0x20004000, length = 0x00040000 - 0x4000 + SRAM2 (RWX) : origin = 0x20000000, length = 0x4000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : origin = 0x90000000, length = 0x40000 +} + +/* Section allocation in memory */ + +SECTIONS +{ + .text : > SRAM + .TI.ramfunc : > SRAM + .const : > SRAM + .rodata : > SRAM + .cinit : > SRAM + .pinit : > SRAM + .init_array : > SRAM + + .data : > SRAM + .bss : > SRAM + .sysmem : > SRAM + .stack : > SRAM2(HIGH) + + .resetVecs : > SRAM_BASE + .ramVecs : > SRAM2_BASE, type=NOLOAD + + .log_data : > LOG_DATA, type = COPY +} diff --git a/dis10_lab3.4_liniaire/config.c b/dis10_lab3.4_liniaire/config.c new file mode 100644 index 0000000..af9798e --- /dev/null +++ b/dis10_lab3.4_liniaire/config.c @@ -0,0 +1,289 @@ +/* + * Configure functions to use the TI TLV320AIC3254 codec on the + * CC3200AUDBOOST board with the CC3220S-LAUNCHXL board + * without using DMA. + * + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + * + * Based on Driver for TI TLV320AIC3110 CODEC + * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "config.h" + +// Configure an I2C connection using the TI I2C driver. + +I2C_Handle ConfigureI2C(uint_least8_t index, I2C_BitRate bitRate) +{ + I2C_Handle i2cHandle; + I2C_Params i2cParams; + I2C_init(); + I2C_Params_init(&i2cParams); + i2cParams.bitRate = bitRate; + i2cHandle = I2C_open(index, &i2cParams); + if (i2cHandle == NULL) { + // Error initializing I2C. + while (1); + } + return i2cHandle; +} + +// Configure an I2S connection which is use to send/receive samples to/from the codec. + +void ConfigureI2S(unsigned long peripheral, unsigned long base, unsigned int samplingFrequency) +{ + // Register power dependency. Keeps the I2S clock running in SLP and DSLP modes. + int_fast16_t ret = Power_setDependency(PowerCC32XX_PERIPH_I2S); + if (ret != Power_SOK) { + // Error setting power dependency. + while (1); + } + + // There is no TI I2S driver (without DMA) available so the TI driverlib API is used. + PRCMPeripheralReset(peripheral); + I2SEnable(base, I2S_MODE_TX_RX_SYNC); + + unsigned int bitClock = samplingFrequency * 16 * 2; + PRCMI2SClockFreqSet(bitClock); + I2SConfigSetExpClk(base, bitClock, bitClock, I2S_MODE_MASTER | I2S_SLOT_SIZE_16 | I2S_PORT_CPU); + + I2SSerializerConfig(base, I2S_DATA_LINE_0, I2S_SER_MODE_TX, I2S_INACT_LOW_LEVEL); + I2SSerializerConfig(base, I2S_DATA_LINE_1, I2S_SER_MODE_RX, I2S_INACT_LOW_LEVEL); + + // Configure I2S pins in pin mux + PinTypeI2S(PIN_64, PIN_MODE_7); // xr0Pin = I2S SDout (CC3220S-LAUNCHXL) = DIN_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_50, PIN_MODE_6); // xr1Pin = I2S SDin (CC3220S-LAUNCHXL) = DOUT_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_53, PIN_MODE_2); // clkPin = I2S SCLK (CC3220S-LAUNCHXL) = BCLK_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_63, PIN_MODE_7); // fsxPin = I2S WC (CC3220S-LAUNCHXL) = FSYNC_J3 (CC3200AUDBOOST) + + PRCMPeripheralClkEnable(peripheral, PRCM_RUN_MODE_CLK); +} + +#define CODEC_I2C_SLAVE_ADDR ((0x30 >> 1)) + +static uint8_t CodecRegRead(I2C_Handle i2cHandle, uint8_t regAddr) +{ + I2C_Transaction i2cTransaction; + uint8_t data; + + i2cTransaction.slaveAddress = CODEC_I2C_SLAVE_ADDR; + i2cTransaction.writeBuf = ®Addr; + i2cTransaction.writeCount = 1; + i2cTransaction.readBuf = &data; + i2cTransaction.readCount = 1; + if (!I2C_transfer(i2cHandle, &i2cTransaction)) + { + // I2C transfer failed + while (1); + } + return data; +} + +static void CodecRegWrite(I2C_Handle i2cHandle, uint8_t regAddr, uint8_t regValue) +{ + uint8_t data[2]; + I2C_Transaction i2cTransaction; + + data[0] = regAddr; + data[1] = regValue; + + i2cTransaction.slaveAddress = CODEC_I2C_SLAVE_ADDR; + i2cTransaction.writeBuf = &data[0]; + i2cTransaction.writeCount = 2; + i2cTransaction.readBuf = NULL; + i2cTransaction.readCount = 0; + if (!I2C_transfer(i2cHandle, &i2cTransaction)) + { + // I2C transfer failed + while (1); + } +} + +static void CodecPageSelect(I2C_Handle i2cHandle, unsigned long pageAddress) +{ + CodecRegWrite(i2cHandle, 0, pageAddress); +} + +static void CodecReset(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Soft RESET. + CodecRegWrite(i2cHandle, 1, 0x01); + // Wait for 27000 * 3 = 81000 clock cycles @ 80 MHz ~ 1 ms. + UtilsDelay(27000); +} + +// volume: 0 -> 0 bB (Highest) to 116 -> -72.3 dB (Lowest) +void AudioVolumeControl(I2C_Handle i2cHandle, signed char volume) +{ + // Select page 1 + CodecPageSelect(i2cHandle, 1); + // Enable HPL output analog volume + CodecRegWrite(i2cHandle, 22, volume); + CodecRegWrite(i2cHandle, 23, volume); +} + +void CodecMute(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Mute. + CodecRegWrite(i2cHandle, 64, 0x0C); +} + +void CodecUnmute(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Unmute. + CodecRegWrite(i2cHandle, 64, 0x00); +} + +// Codec configure: + // PGA (Programmable Gain Amplifier) = 0 dB. + // Headphone Output = enabled. + // Line outputs (to class D amplifier) = disabled. + // ADC gain = 0 dB. + // AGC (Automatic Gain Control) = disabled. + // ADC processing block = PRB_R1 (default). + // Microphone = disabled. + // DAC processing block = PRB_P1 (default). + // DRC (Dynamic Gain Compression) = disabled. + +void ConfigureAudioCodec(I2C_Handle i2cHandle, unsigned int samplingFrequency) +{ + // Check parameter. + if (samplingFrequency < 8000 || samplingFrequency > 48000 || samplingFrequency % 4000 != 0) + { + while(1); + // Wrong value for sampling frequency. + } + size_t sampleIndex = (samplingFrequency / 4000) - 2; + // values for DOSR, MDAC, NDAC, NADC and J in steps of 4 kHz starting from 8 kHz to 48 kHz. + // 8 12 16 20 24 28 32 36 40 44 48 + int DOSR[] = {512, 512, 384, 304, 256, 208, 192, 160, 144, 128, 128}; + int MDAC[] = { 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2}; + int NDAC[] = { 1, 1, 2, 16, 8, 8, 8, 8, 8, 8, 8}; + int NADC[] = { 2, 2, 3, 19, 16, 13, 12, 10, 9, 8, 8}; + int J[] = { 4, 4, 6, 38, 32, 26, 24, 20, 18, 16, 16}; + + // Reset code for startup. + CodecReset(i2cHandle); + + // Select page 0. + CodecPageSelect(i2cHandle, 0); + + // Set I2S Mode and Word Length = 16 bits, BCLK and WCLK are inputs to the device. + CodecRegWrite(i2cHandle, 27, 0x00); + // Clock settings chip + CodecRegWrite(i2cHandle, 4, 0x03); // PLL CLock is CODEC_CLKIN + CodecRegWrite(i2cHandle, 5, 0x94); // PLL enabled, P = 1, R = 4 + CodecRegWrite(i2cHandle, 6, J[sampleIndex]); // PLL J + CodecRegWrite(i2cHandle, 7, 0); // PLL D = 0 + CodecRegWrite(i2cHandle, 8, 0); // PLL D = 0 + // PLL_CLK = PLL_CLKIN * R * J.D / P = PLL_CLKIN * 4 * J = (Fs * 32) * 4 * J + + // Clock settings DAC. + CodecRegWrite(i2cHandle, 11, 0x80 + NDAC[sampleIndex]); // NDAC is powered up + CodecRegWrite(i2cHandle, 12, 0x80 + MDAC[sampleIndex]); // MDAC is powered up + CodecRegWrite(i2cHandle, 13, DOSR[sampleIndex] / 256); // DOSR + CodecRegWrite(i2cHandle, 14, DOSR[sampleIndex] % 256); + // DAC_fs = CODEC_CLKIN / (NDAC * MDAC * DOSR) + + // Clock settings ADC. + CodecRegWrite(i2cHandle, 18, 0x80 + NADC[sampleIndex]); // NADC is powered up, NADC = 2 + CodecRegWrite(i2cHandle, 19, 0x80 + 2); // MADC is powered up, MADC = 2 + CodecRegWrite(i2cHandle, 20, 128); // AOSR = 128 + // ADC_fs = CODEC_CLKIN / (NADC * MADC * AOSR) + + // Configure power supplies. + CodecPageSelect(i2cHandle, 1); + CodecRegWrite(i2cHandle, 1, 0x08); // AVdd and DVdd are connected + CodecRegWrite(i2cHandle, 2, 0x01); // LDO enabled AVDD LDO output = 1.72 V + CodecRegWrite(i2cHandle, 71, 0x32); // Aanalog input powerup = 6.4 ms + CodecRegWrite(i2cHandle, 123, 0x01); // Reference powered up in 40 ms + + // Configure ADC channel. + // Route IN1L to Left MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 52, 0x40); + // Route CM to Left MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 54, 0x40); + // Route IN1R to Right MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 55, 0x40); + // Route CM to Right MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 57,0x40); + // Floating IN1L. + CodecRegWrite(i2cHandle, 58, 0xC0); + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + // Power up LADC/RADC. + CodecRegWrite(i2cHandle, 81, 0xC0); + // Unmute LADC/RADC. + CodecRegWrite(i2cHandle, 82, 0x00); + + // Configure DAC channel. + // Select Page 1. + CodecPageSelect(i2cHandle, 1); + + // De-pop: soft stepping disabled, N = 5, Rpop = 6k. See SLAA408A page 11,12,13. + CodecRegWrite(i2cHandle, 20, 0x25); + + // Route LDAC/RDAC to HPL/HPR. + CodecRegWrite(i2cHandle, 12, 0x08); + CodecRegWrite(i2cHandle, 13, 0x08); + + // Power up HPL/HPR drivers. + CodecRegWrite(i2cHandle, 9, 0x30); + + // Unmute HPL/HPR driver, 0dB Gain. + CodecRegWrite(i2cHandle, 16, 0x00); + CodecRegWrite(i2cHandle, 17, 0x00); + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + + // Unmute DAC, 0dB Gain. + CodecRegWrite(i2cHandle, 65, 0x00); + CodecRegWrite(i2cHandle, 66, 0x00); + + // Select Page 1. + CodecPageSelect(i2cHandle, 1); + + while (CodecRegRead(i2cHandle, 63) & 0x11000000 != 0x11000000) + { + UtilsDelay(27000); // delay 27000 * 3 = 81000 clock cycles @ 80 MHz ~ 1 ms. + } + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + + // Power up LDAC/RDAC. + CodecRegWrite(i2cHandle, 63, 0xd4); + + // Unmute LDAC/RDAC. + CodecRegWrite(i2cHandle, 64, 0x00); +} diff --git a/dis10_lab3.4_liniaire/config.h b/dis10_lab3.4_liniaire/config.h new file mode 100644 index 0000000..bfaa628 --- /dev/null +++ b/dis10_lab3.4_liniaire/config.h @@ -0,0 +1,41 @@ +/* + * Configure functions to use the TI TLV320AIC3254 codec on the + * CC3200AUDBOOST board with the CC3220S-LAUNCHXL board + * without using DMA. + * + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + * + * Based on Driver for TI TLV320AIC3110 codec + * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + */ +#ifndef __HR_CONFIG_H__ +#define __HR_CONFIG_H__ + +#include + +// Configure an I2C connection using the TI I2C driver. +extern I2C_Handle ConfigureI2C(uint_least8_t index, I2C_BitRate bitRate); + +// Configure an I2S connection using the TI driverlib API. +extern void ConfigureI2S(unsigned long peripheral, unsigned long base, unsigned int samplingFrequency); + +// Functions to configure the codec using an I2C connection +// volume: 0 -> 0 bB (Highest) to 116 -> -72.3 dB (Lowest) +extern void AudioVolumeControl(I2C_Handle i2cHandle, signed char volume); +extern void CodecMute(I2C_Handle i2cHandle); +extern void CodecUnmute(I2C_Handle i2cHandle); +// Codec configure: + // PGA (Programmable Gain Amplifier) = 0 dB. + // Headphone Output = enabled. + // Line outputs (to class D amplifier) = disabled. + // ADC gain = 0 dB. + // AGC (Automatic Gain Control) = disabled. + // ADC processing block = PRB_R1 (default). + // Microphone = disabled. + // DAC processing block = PRB_P1 (default). + // DRC (Dynamic Gain Compression) = disabled. +extern void ConfigureAudioCodec(I2C_Handle i2cHandle, unsigned int samplingFrequency); + +#endif diff --git a/dis10_lab3.4_liniaire/fdacoefs.h b/dis10_lab3.4_liniaire/fdacoefs.h new file mode 100644 index 0000000..758dd86 --- /dev/null +++ b/dis10_lab3.4_liniaire/fdacoefs.h @@ -0,0 +1,43 @@ +/* + * Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool + * Generated by MATLAB(R) 9.12 and DSP System Toolbox 9.14. + * Generated on: 30-May-2022 14:58:41 + */ + +/* + * Discrete-Time IIR Filter (real) + * ------------------------------- + * Filter Structure : Direct-Form II + * Numerator Length : 4 + * Denominator Length : 4 + * Stable : Yes + * Linear Phase : No + * Arithmetic : fixed + * Numerator : s16,18 -> [-1.250000e-01 1.250000e-01) + * Denominator : s16,14 -> [-2 2) + * Input : s16,16 -> [-5.000000e-01 5.000000e-01) + * Output : s16,15 -> [-1 1) + * State : s16,15 -> [-1 1) + * Numerator Prod : s32,33 -> [-2.500000e-01 2.500000e-01) + * Denominator Prod : s32,29 -> [-4 4) + * Numerator Accum : s40,33 -> [-64 64) + * Denominator Accum : s40,29 -> [-1024 1024) + * Round Mode : convergent + * Overflow Mode : wrap + * Cast Before Sum : true + */ + +/* General type conversion for MATLAB generated C-code */ +#include "tmwtypes.h" +/* + * Expected path to tmwtypes.h + * /home/mreenen/.local/MATLAB/R2022a/extern/include/tmwtypes.h + */ +const int NL = 4; +const int16_T NUM[4] = { + 519, 1558, 1558, 519 +}; +const int DL = 4; +const int16_T DEN[4] = { + 16384, -23905, 14915, -3241 +}; diff --git a/dis10_lab3.4_liniaire/main_nortos.c b/dis10_lab3.4_liniaire/main_nortos.c new file mode 100644 index 0000000..d4c2d69 --- /dev/null +++ b/dis10_lab3.4_liniaire/main_nortos.c @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#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; +} diff --git a/dis10_lab3.4_liniaire/release/ccsObjs.opt b/dis10_lab3.4_liniaire/release/ccsObjs.opt new file mode 100644 index 0000000..49626a9 --- /dev/null +++ b/dis10_lab3.4_liniaire/release/ccsObjs.opt @@ -0,0 +1 @@ +"./syscfg/ti_drivers_config.obj" "./config.obj" "./main_nortos.obj" "../cc32xxs_nortos.cmd" -lti_utils_build_linker.cmd.genlibs -l"ti/devices/cc32xx/driverlib/ccs/Release/driverlib.a" -llibc.a \ No newline at end of file diff --git a/dis10_lab3.4_liniaire/release/makefile b/dis10_lab3.4_liniaire/release/makefile new file mode 100644 index 0000000..e69de29 diff --git a/dis10_lab3.4_liniaire/release/sources.mk b/dis10_lab3.4_liniaire/release/sources.mk new file mode 100644 index 0000000..2f01bd6 --- /dev/null +++ b/dis10_lab3.4_liniaire/release/sources.mk @@ -0,0 +1,130 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +C55_SRCS := +A_SRCS := +ASM_UPPER_SRCS := +PINMUX_SRCS := +EXE_SRCS := +LDS_UPPER_SRCS := +CPP_SRCS := +CMD_SRCS := +O_SRCS := +ELF_SRCS := +C??_SRCS := +C64_SRCS := +C67_SRCS := +SA_SRCS := +S64_SRCS := +OPT_SRCS := +CXX_SRCS := +S67_SRCS := +S??_SRCS := +PDE_SRCS := +SV7A_SRCS := +SYSCFG_SRCS := +K_SRCS := +CLA_SRCS := +S55_SRCS := +LD_UPPER_SRCS := +OUT_SRCS := +INO_SRCS := +LIB_SRCS := +ASM_SRCS := +S_UPPER_SRCS := +SYSCONFIG_SRCS := +S43_SRCS := +LD_SRCS := +CMD_UPPER_SRCS := +C_UPPER_SRCS := +C++_SRCS := +C43_SRCS := +OBJ_SRCS := +LDS_SRCS := +S_SRCS := +CC_SRCS := +S62_SRCS := +C62_SRCS := +C_SRCS := +C55_DEPS := +C_UPPER_DEPS := +S67_DEPS := +S62_DEPS := +S_DEPS := +OPT_DEPS := +C??_DEPS := +ASM_UPPER_DEPS := +S??_DEPS := +C64_DEPS := +CXX_DEPS := +S64_DEPS := +INO_DEPS := +GEN_CMDS := +GEN_FILES := +CLA_DEPS := +S55_DEPS := +SV7A_DEPS := +EXE_OUTPUTS := +C62_DEPS := +CUSTOM_TOOL_OUTPUTS_1505879725 := +C67_DEPS := +PDE_DEPS := +GEN_MISC_DIRS := +K_DEPS := +C_DEPS := +CC_DEPS := +BIN_OUTPUTS := +GEN_OPTS := +C++_DEPS := +C43_DEPS := +S43_DEPS := +OBJS := +ASM_DEPS := +GEN_MISC_FILES := +S_UPPER_DEPS := +CPP_DEPS := +SA_DEPS := +C++_DEPS__QUOTED := +OPT_DEPS__QUOTED := +CUSTOM_TOOL_OUTPUTS_1505879725__QUOTED := +S_UPPER_DEPS__QUOTED := +SA_DEPS__QUOTED := +C??_DEPS__QUOTED := +S67_DEPS__QUOTED := +GEN_MISC_DIRS__QUOTED := +C55_DEPS__QUOTED := +CC_DEPS__QUOTED := +ASM_UPPER_DEPS__QUOTED := +SV7A_DEPS__QUOTED := +S??_DEPS__QUOTED := +OBJS__QUOTED := +C67_DEPS__QUOTED := +K_DEPS__QUOTED := +S55_DEPS__QUOTED := +GEN_CMDS__QUOTED := +GEN_MISC_FILES__QUOTED := +INO_DEPS__QUOTED := +C62_DEPS__QUOTED := +C_DEPS__QUOTED := +C_UPPER_DEPS__QUOTED := +C43_DEPS__QUOTED := +CPP_DEPS__QUOTED := +BIN_OUTPUTS__QUOTED := +GEN_FILES__QUOTED := +C64_DEPS__QUOTED := +CXX_DEPS__QUOTED := +CLA_DEPS__QUOTED := +S_DEPS__QUOTED := +ASM_DEPS__QUOTED := +S43_DEPS__QUOTED := +EXE_OUTPUTS__QUOTED := +S64_DEPS__QUOTED := +S62_DEPS__QUOTED := +PDE_DEPS__QUOTED := +GEN_OPTS__QUOTED := + +# Every subdirectory with source files must be described here +SUBDIRS := \ +. \ + diff --git a/dis10_lab3.4_liniaire/release/subdir_rules.mk b/dis10_lab3.4_liniaire/release/subdir_rules.mk new file mode 100644 index 0000000..7272296 --- /dev/null +++ b/dis10_lab3.4_liniaire/release/subdir_rules.mk @@ -0,0 +1,35 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +# Each subdirectory must supply rules for building sources it contributes +build-236735937: ../audio.syscfg + @echo 'Building file: "$<"' + @echo 'Invoking: SysConfig' + "/home/mreenen/ti/sysconfig_1_10_0/sysconfig_cli.sh" -s "/home/mreenen/ti/simplelink_cc32xx_sdk_5_30_00_08/.metadata/product.json" --script "/home/mreenen/Documents/ccs/dis10_lab3.4_liniaire/audio.syscfg" -o "syscfg" --compiler ccs + @echo 'Finished building: "$<"' + @echo ' ' + +syscfg/ti_drivers_config.c: build-236735937 ../audio.syscfg +syscfg/ti_drivers_config.h: build-236735937 +syscfg/ti_utils_build_linker.cmd.genlibs: build-236735937 +syscfg/syscfg_c.rov.xs: build-236735937 +syscfg/ti_utils_runtime_model.gv: build-236735937 +syscfg/ti_utils_runtime_Makefile: build-236735937 +syscfg/: build-236735937 + +syscfg/%.obj: ./syscfg/%.c $(GEN_OPTS) | $(GEN_FILES) $(GEN_MISC_FILES) + @echo 'Building file: "$<"' + @echo 'Invoking: Arm Compiler' + "/home/mreenen/.local/ti/ccs1120/ccs/tools/compiler/ti-cgt-arm_20.2.6.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=vfplib -me -O4 --opt_for_speed=5 --include_path="/home/mreenen/Documents/ccs/dis10_lab3.4_liniaire" --include_path="/home/mreenen/Documents/ccs/dis10_lab3.4_liniaire/release" --include_path="/home/mreenen/ti/simplelink_cc32xx_sdk_5_30_00_08/source" --include_path="/home/mreenen/ti/simplelink_cc32xx_sdk_5_30_00_08/kernel/nortos" --include_path="/home/mreenen/ti/simplelink_cc32xx_sdk_5_30_00_08/kernel/nortos/posix" --include_path="/home/mreenen/.local/ti/ccs1120/ccs/tools/compiler/ti-cgt-arm_20.2.6.LTS/include" --define=DeviceFamily_CC3220 --define=NORTOS_SUPPORT -g --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --preproc_with_compile --preproc_dependency="syscfg/$(basename $( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dis10_lab3.4_liniaire/targetConfigs/readme.txt b/dis10_lab3.4_liniaire/targetConfigs/readme.txt new file mode 100644 index 0000000..af97b62 --- /dev/null +++ b/dis10_lab3.4_liniaire/targetConfigs/readme.txt @@ -0,0 +1,9 @@ +The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based +on the device and connection settings specified in your project on the Properties > General page. + +Please note that in automatic target-configuration management, changes to the project's device and/or +connection settings will either modify an existing or generate a new target-configuration file. Thus, +if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively, +you may create your own target-configuration file for this project and manage it manually. You can +always switch back to automatic target-configuration management by checking the "Manage the project's +target-configuration automatically" checkbox on the project's Properties > General page. \ No newline at end of file diff --git a/dis10_sine/.ccsproject b/dis10_sine/.ccsproject new file mode 100644 index 0000000..8ed2f71 --- /dev/null +++ b/dis10_sine/.ccsproject @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dis10_sine/.cproject b/dis10_sine/.cproject new file mode 100644 index 0000000..e076e71 --- /dev/null +++ b/dis10_sine/.cproject @@ -0,0 +1,249 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dis10_sine/.gitignore b/dis10_sine/.gitignore new file mode 100644 index 0000000..7c1916f --- /dev/null +++ b/dis10_sine/.gitignore @@ -0,0 +1,2 @@ +/MCU+Image/ +/Debug/ diff --git a/dis10_sine/.launches/dis10_sine.launch b/dis10_sine/.launches/dis10_sine.launch new file mode 100644 index 0000000..e503f35 --- /dev/null +++ b/dis10_sine/.launches/dis10_sine.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dis10_sine/.launches/line_in_2_line_out.launch b/dis10_sine/.launches/line_in_2_line_out.launch new file mode 100644 index 0000000..e08bac4 --- /dev/null +++ b/dis10_sine/.launches/line_in_2_line_out.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/dis10_sine/.project b/dis10_sine/.project new file mode 100644 index 0000000..6e5e607 --- /dev/null +++ b/dis10_sine/.project @@ -0,0 +1,34 @@ + + + dis10_sine + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.ti.ccstudio.core.ccsNature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + Board.html + 1 + COM_TI_SIMPLELINK_CC32XX_SDK_INSTALL_DIR/source/ti/boards/CC3220S_LAUNCHXL/Board.html + + + diff --git a/dis10_sine/.settings/org.eclipse.cdt.codan.core.prefs b/dis10_sine/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..98b6350 --- /dev/null +++ b/dis10_sine/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +inEditor=false +onBuild=false diff --git a/dis10_sine/.settings/org.eclipse.cdt.debug.core.prefs b/dis10_sine/.settings/org.eclipse.cdt.debug.core.prefs new file mode 100644 index 0000000..58d4fb2 --- /dev/null +++ b/dis10_sine/.settings/org.eclipse.cdt.debug.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker diff --git a/dis10_sine/.settings/org.eclipse.core.resources.prefs b/dis10_sine/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..7c051cc --- /dev/null +++ b/dis10_sine/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//Debug/makefile=UTF-8 +encoding//Debug/objects.mk=UTF-8 +encoding//Debug/sources.mk=UTF-8 +encoding//Debug/subdir_rules.mk=UTF-8 +encoding//Debug/subdir_vars.mk=UTF-8 diff --git a/dis10_sine/audio.syscfg b/dis10_sine/audio.syscfg new file mode 100644 index 0000000..1ce1557 --- /dev/null +++ b/dis10_sine/audio.syscfg @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2018-2021, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +// @cliArgs --board /ti/boards/CC3220S_LAUNCHXL --rtos nortos + +/* + * gpiointerrupt.syscfg + */ +/* ======== Boosterpacks ========= BroJZ 20220415*/ +const CC3200AUDBOOST = scripting.addHardware("/ti/boards/boosterpacks/CC3200AUDBOOST"); + +/* ======== TIRTOS7 ======== */ +if (system.getRTOS() === "tirtos7") { + const tirtos7_release_syscfg_js = system.getScript("tirtos7_release.syscfg.js"); +} + +/** + * Import the modules used in this configuration. + */ +const I2C = scripting.addModule("/ti/drivers/I2C"); +const I2C1 = I2C.addInstance(); +const I2S = scripting.addModule("/ti/drivers/I2S"); +const I2S1 = I2S.addInstance(); +const RTOS = scripting.addModule("/ti/drivers/RTOS"); + +/** + * Write custom configuration values to the imported modules. + */ +I2C1.$name = "CONFIG_I2C_0"; +I2C1.$hardware = system.deviceData.board.components.LP_I2C; + +I2S1.$name = "CONFIG_I2S_0"; +I2S1.interruptPriority = "2"; +I2S1.$hardware = CC3200AUDBOOST.components.CC3200AUDBOOST_I2S; + +const Power = scripting.addModule("/ti/drivers/Power", {}, false); +Power.parkPins.$name = "ti_drivers_power_PowerCC32XXPins0"; + +RTOS.name = "NoRTOS"; + +/** + * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future + * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to + * re-solve from scratch. + */ +I2C1.i2c.$suggestSolution = "I2C0"; +I2C1.i2c.sdaPin.$suggestSolution = "boosterpack.10"; +I2C1.i2c.sclPin.$suggestSolution = "boosterpack.9"; +I2S1.i2s.$suggestSolution = "McASP0"; +I2S1.i2s.SD0Pin.$suggestSolution = "boosterpack.29"; +I2S1.i2s.SD1Pin.$suggestSolution = "boosterpack.30"; +I2S1.i2s.SCKPin.$suggestSolution = "boosterpack.28"; +I2S1.i2s.WSPin.$suggestSolution = "boosterpack.27"; +I2S1.i2s.dmaRxChannel.$suggestSolution = "UDMA_CH18"; +I2S1.i2s.dmaTxChannel.$suggestSolution = "UDMA_CH19"; diff --git a/dis10_sine/berekeningen klokinstellingen codec.xlsx b/dis10_sine/berekeningen klokinstellingen codec.xlsx new file mode 100644 index 0000000..304dcbd Binary files /dev/null and b/dis10_sine/berekeningen klokinstellingen codec.xlsx differ diff --git a/dis10_sine/cc32xxs_nortos.cmd b/dis10_sine/cc32xxs_nortos.cmd new file mode 100644 index 0000000..4e6d27a --- /dev/null +++ b/dis10_sine/cc32xxs_nortos.cmd @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018-2020, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +--stack_size=0x1000 +--heap_size=0x8000 +--entry_point=resetISR +--diag_suppress=10063 /* suppress warning about non _c_int00 entry point */ + +/* + * The starting address of the application. Normally the interrupt vectors + * must be located at the beginning of the application. + */ +#define SRAM_BASE 0x20004000 +#define SRAM2_BASE 0x20000000 + +MEMORY +{ + SRAM (RWX) : origin = 0x20004000, length = 0x00040000 - 0x4000 + SRAM2 (RWX) : origin = 0x20000000, length = 0x4000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : origin = 0x90000000, length = 0x40000 +} + +/* Section allocation in memory */ + +SECTIONS +{ + .text : > SRAM + .TI.ramfunc : > SRAM + .const : > SRAM + .rodata : > SRAM + .cinit : > SRAM + .pinit : > SRAM + .init_array : > SRAM + + .data : > SRAM + .bss : > SRAM + .sysmem : > SRAM + .stack : > SRAM2(HIGH) + + .resetVecs : > SRAM_BASE + .ramVecs : > SRAM2_BASE, type=NOLOAD + + .log_data : > LOG_DATA, type = COPY +} diff --git a/dis10_sine/config.c b/dis10_sine/config.c new file mode 100644 index 0000000..af9798e --- /dev/null +++ b/dis10_sine/config.c @@ -0,0 +1,289 @@ +/* + * Configure functions to use the TI TLV320AIC3254 codec on the + * CC3200AUDBOOST board with the CC3220S-LAUNCHXL board + * without using DMA. + * + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + * + * Based on Driver for TI TLV320AIC3110 CODEC + * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "config.h" + +// Configure an I2C connection using the TI I2C driver. + +I2C_Handle ConfigureI2C(uint_least8_t index, I2C_BitRate bitRate) +{ + I2C_Handle i2cHandle; + I2C_Params i2cParams; + I2C_init(); + I2C_Params_init(&i2cParams); + i2cParams.bitRate = bitRate; + i2cHandle = I2C_open(index, &i2cParams); + if (i2cHandle == NULL) { + // Error initializing I2C. + while (1); + } + return i2cHandle; +} + +// Configure an I2S connection which is use to send/receive samples to/from the codec. + +void ConfigureI2S(unsigned long peripheral, unsigned long base, unsigned int samplingFrequency) +{ + // Register power dependency. Keeps the I2S clock running in SLP and DSLP modes. + int_fast16_t ret = Power_setDependency(PowerCC32XX_PERIPH_I2S); + if (ret != Power_SOK) { + // Error setting power dependency. + while (1); + } + + // There is no TI I2S driver (without DMA) available so the TI driverlib API is used. + PRCMPeripheralReset(peripheral); + I2SEnable(base, I2S_MODE_TX_RX_SYNC); + + unsigned int bitClock = samplingFrequency * 16 * 2; + PRCMI2SClockFreqSet(bitClock); + I2SConfigSetExpClk(base, bitClock, bitClock, I2S_MODE_MASTER | I2S_SLOT_SIZE_16 | I2S_PORT_CPU); + + I2SSerializerConfig(base, I2S_DATA_LINE_0, I2S_SER_MODE_TX, I2S_INACT_LOW_LEVEL); + I2SSerializerConfig(base, I2S_DATA_LINE_1, I2S_SER_MODE_RX, I2S_INACT_LOW_LEVEL); + + // Configure I2S pins in pin mux + PinTypeI2S(PIN_64, PIN_MODE_7); // xr0Pin = I2S SDout (CC3220S-LAUNCHXL) = DIN_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_50, PIN_MODE_6); // xr1Pin = I2S SDin (CC3220S-LAUNCHXL) = DOUT_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_53, PIN_MODE_2); // clkPin = I2S SCLK (CC3220S-LAUNCHXL) = BCLK_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_63, PIN_MODE_7); // fsxPin = I2S WC (CC3220S-LAUNCHXL) = FSYNC_J3 (CC3200AUDBOOST) + + PRCMPeripheralClkEnable(peripheral, PRCM_RUN_MODE_CLK); +} + +#define CODEC_I2C_SLAVE_ADDR ((0x30 >> 1)) + +static uint8_t CodecRegRead(I2C_Handle i2cHandle, uint8_t regAddr) +{ + I2C_Transaction i2cTransaction; + uint8_t data; + + i2cTransaction.slaveAddress = CODEC_I2C_SLAVE_ADDR; + i2cTransaction.writeBuf = ®Addr; + i2cTransaction.writeCount = 1; + i2cTransaction.readBuf = &data; + i2cTransaction.readCount = 1; + if (!I2C_transfer(i2cHandle, &i2cTransaction)) + { + // I2C transfer failed + while (1); + } + return data; +} + +static void CodecRegWrite(I2C_Handle i2cHandle, uint8_t regAddr, uint8_t regValue) +{ + uint8_t data[2]; + I2C_Transaction i2cTransaction; + + data[0] = regAddr; + data[1] = regValue; + + i2cTransaction.slaveAddress = CODEC_I2C_SLAVE_ADDR; + i2cTransaction.writeBuf = &data[0]; + i2cTransaction.writeCount = 2; + i2cTransaction.readBuf = NULL; + i2cTransaction.readCount = 0; + if (!I2C_transfer(i2cHandle, &i2cTransaction)) + { + // I2C transfer failed + while (1); + } +} + +static void CodecPageSelect(I2C_Handle i2cHandle, unsigned long pageAddress) +{ + CodecRegWrite(i2cHandle, 0, pageAddress); +} + +static void CodecReset(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Soft RESET. + CodecRegWrite(i2cHandle, 1, 0x01); + // Wait for 27000 * 3 = 81000 clock cycles @ 80 MHz ~ 1 ms. + UtilsDelay(27000); +} + +// volume: 0 -> 0 bB (Highest) to 116 -> -72.3 dB (Lowest) +void AudioVolumeControl(I2C_Handle i2cHandle, signed char volume) +{ + // Select page 1 + CodecPageSelect(i2cHandle, 1); + // Enable HPL output analog volume + CodecRegWrite(i2cHandle, 22, volume); + CodecRegWrite(i2cHandle, 23, volume); +} + +void CodecMute(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Mute. + CodecRegWrite(i2cHandle, 64, 0x0C); +} + +void CodecUnmute(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Unmute. + CodecRegWrite(i2cHandle, 64, 0x00); +} + +// Codec configure: + // PGA (Programmable Gain Amplifier) = 0 dB. + // Headphone Output = enabled. + // Line outputs (to class D amplifier) = disabled. + // ADC gain = 0 dB. + // AGC (Automatic Gain Control) = disabled. + // ADC processing block = PRB_R1 (default). + // Microphone = disabled. + // DAC processing block = PRB_P1 (default). + // DRC (Dynamic Gain Compression) = disabled. + +void ConfigureAudioCodec(I2C_Handle i2cHandle, unsigned int samplingFrequency) +{ + // Check parameter. + if (samplingFrequency < 8000 || samplingFrequency > 48000 || samplingFrequency % 4000 != 0) + { + while(1); + // Wrong value for sampling frequency. + } + size_t sampleIndex = (samplingFrequency / 4000) - 2; + // values for DOSR, MDAC, NDAC, NADC and J in steps of 4 kHz starting from 8 kHz to 48 kHz. + // 8 12 16 20 24 28 32 36 40 44 48 + int DOSR[] = {512, 512, 384, 304, 256, 208, 192, 160, 144, 128, 128}; + int MDAC[] = { 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2}; + int NDAC[] = { 1, 1, 2, 16, 8, 8, 8, 8, 8, 8, 8}; + int NADC[] = { 2, 2, 3, 19, 16, 13, 12, 10, 9, 8, 8}; + int J[] = { 4, 4, 6, 38, 32, 26, 24, 20, 18, 16, 16}; + + // Reset code for startup. + CodecReset(i2cHandle); + + // Select page 0. + CodecPageSelect(i2cHandle, 0); + + // Set I2S Mode and Word Length = 16 bits, BCLK and WCLK are inputs to the device. + CodecRegWrite(i2cHandle, 27, 0x00); + // Clock settings chip + CodecRegWrite(i2cHandle, 4, 0x03); // PLL CLock is CODEC_CLKIN + CodecRegWrite(i2cHandle, 5, 0x94); // PLL enabled, P = 1, R = 4 + CodecRegWrite(i2cHandle, 6, J[sampleIndex]); // PLL J + CodecRegWrite(i2cHandle, 7, 0); // PLL D = 0 + CodecRegWrite(i2cHandle, 8, 0); // PLL D = 0 + // PLL_CLK = PLL_CLKIN * R * J.D / P = PLL_CLKIN * 4 * J = (Fs * 32) * 4 * J + + // Clock settings DAC. + CodecRegWrite(i2cHandle, 11, 0x80 + NDAC[sampleIndex]); // NDAC is powered up + CodecRegWrite(i2cHandle, 12, 0x80 + MDAC[sampleIndex]); // MDAC is powered up + CodecRegWrite(i2cHandle, 13, DOSR[sampleIndex] / 256); // DOSR + CodecRegWrite(i2cHandle, 14, DOSR[sampleIndex] % 256); + // DAC_fs = CODEC_CLKIN / (NDAC * MDAC * DOSR) + + // Clock settings ADC. + CodecRegWrite(i2cHandle, 18, 0x80 + NADC[sampleIndex]); // NADC is powered up, NADC = 2 + CodecRegWrite(i2cHandle, 19, 0x80 + 2); // MADC is powered up, MADC = 2 + CodecRegWrite(i2cHandle, 20, 128); // AOSR = 128 + // ADC_fs = CODEC_CLKIN / (NADC * MADC * AOSR) + + // Configure power supplies. + CodecPageSelect(i2cHandle, 1); + CodecRegWrite(i2cHandle, 1, 0x08); // AVdd and DVdd are connected + CodecRegWrite(i2cHandle, 2, 0x01); // LDO enabled AVDD LDO output = 1.72 V + CodecRegWrite(i2cHandle, 71, 0x32); // Aanalog input powerup = 6.4 ms + CodecRegWrite(i2cHandle, 123, 0x01); // Reference powered up in 40 ms + + // Configure ADC channel. + // Route IN1L to Left MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 52, 0x40); + // Route CM to Left MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 54, 0x40); + // Route IN1R to Right MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 55, 0x40); + // Route CM to Right MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 57,0x40); + // Floating IN1L. + CodecRegWrite(i2cHandle, 58, 0xC0); + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + // Power up LADC/RADC. + CodecRegWrite(i2cHandle, 81, 0xC0); + // Unmute LADC/RADC. + CodecRegWrite(i2cHandle, 82, 0x00); + + // Configure DAC channel. + // Select Page 1. + CodecPageSelect(i2cHandle, 1); + + // De-pop: soft stepping disabled, N = 5, Rpop = 6k. See SLAA408A page 11,12,13. + CodecRegWrite(i2cHandle, 20, 0x25); + + // Route LDAC/RDAC to HPL/HPR. + CodecRegWrite(i2cHandle, 12, 0x08); + CodecRegWrite(i2cHandle, 13, 0x08); + + // Power up HPL/HPR drivers. + CodecRegWrite(i2cHandle, 9, 0x30); + + // Unmute HPL/HPR driver, 0dB Gain. + CodecRegWrite(i2cHandle, 16, 0x00); + CodecRegWrite(i2cHandle, 17, 0x00); + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + + // Unmute DAC, 0dB Gain. + CodecRegWrite(i2cHandle, 65, 0x00); + CodecRegWrite(i2cHandle, 66, 0x00); + + // Select Page 1. + CodecPageSelect(i2cHandle, 1); + + while (CodecRegRead(i2cHandle, 63) & 0x11000000 != 0x11000000) + { + UtilsDelay(27000); // delay 27000 * 3 = 81000 clock cycles @ 80 MHz ~ 1 ms. + } + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + + // Power up LDAC/RDAC. + CodecRegWrite(i2cHandle, 63, 0xd4); + + // Unmute LDAC/RDAC. + CodecRegWrite(i2cHandle, 64, 0x00); +} diff --git a/dis10_sine/config.h b/dis10_sine/config.h new file mode 100644 index 0000000..bfaa628 --- /dev/null +++ b/dis10_sine/config.h @@ -0,0 +1,41 @@ +/* + * Configure functions to use the TI TLV320AIC3254 codec on the + * CC3200AUDBOOST board with the CC3220S-LAUNCHXL board + * without using DMA. + * + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + * + * Based on Driver for TI TLV320AIC3110 codec + * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + */ +#ifndef __HR_CONFIG_H__ +#define __HR_CONFIG_H__ + +#include + +// Configure an I2C connection using the TI I2C driver. +extern I2C_Handle ConfigureI2C(uint_least8_t index, I2C_BitRate bitRate); + +// Configure an I2S connection using the TI driverlib API. +extern void ConfigureI2S(unsigned long peripheral, unsigned long base, unsigned int samplingFrequency); + +// Functions to configure the codec using an I2C connection +// volume: 0 -> 0 bB (Highest) to 116 -> -72.3 dB (Lowest) +extern void AudioVolumeControl(I2C_Handle i2cHandle, signed char volume); +extern void CodecMute(I2C_Handle i2cHandle); +extern void CodecUnmute(I2C_Handle i2cHandle); +// Codec configure: + // PGA (Programmable Gain Amplifier) = 0 dB. + // Headphone Output = enabled. + // Line outputs (to class D amplifier) = disabled. + // ADC gain = 0 dB. + // AGC (Automatic Gain Control) = disabled. + // ADC processing block = PRB_R1 (default). + // Microphone = disabled. + // DAC processing block = PRB_P1 (default). + // DRC (Dynamic Gain Compression) = disabled. +extern void ConfigureAudioCodec(I2C_Handle i2cHandle, unsigned int samplingFrequency); + +#endif diff --git a/dis10_sine/main_nortos.c b/dis10_sine/main_nortos.c new file mode 100644 index 0000000..356735b --- /dev/null +++ b/dis10_sine/main_nortos.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "ti_drivers_config.h" +#include "config.h" + +// You can select the sample rate here +#define SAMPLINGFREQUENCY 8000 +#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 + +int main(void) +{ + // Init CC3220S LAUNCHXL board. + Board_initGeneral(); + // Prepare to use TI drivers without operating system + NoRTOS_start(); + + printf("1 kHz sine wave ==> Left HP LINE OUT.\n"); + + // 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); + + /* Pre-generated sine wave data, 16-bit signed fixed point samples Q0.15 */ + int16_t sinetable[48] = { + 0x0000, 0x10b4, 0x2120, 0x30fb, 0x3fff, 0x4dea, + 0x5a81, 0x658b, 0x6ed8, 0x763f, 0x7ba1, 0x7ee5, + 0x7ffd, 0x7ee5, 0x7ba1, 0x76ef, 0x6ed8, 0x658b, + 0x5a81, 0x4dea, 0x3fff, 0x30fb, 0x2120, 0x10b4, + 0x0000, 0xef4c, 0xdee0, 0xcf06, 0xc002, 0xb216, + 0xa57f, 0x9a75, 0x9128, 0x89c1, 0x845f, 0x811b, + 0x8002, 0x811b, 0x845f, 0x89c1, 0x9128, 0x9a76, + 0xa57f, 0xb216, 0xc002, 0xcf06, 0xdee0, 0xef4c + }; + + int16_t dataLeft, dataRight; + size_t n = 0, m = 12; + + while (1) { + dataLeft = sinetable[n]; + I2SDataGet(I2S_BASE, I2S_DATA_LINE_1, NULL); + I2SDataPut(I2S_BASE, I2S_DATA_LINE_0, (unsigned long)dataLeft); + dataRight = sinetable[m]; + I2SDataGet(I2S_BASE, I2S_DATA_LINE_1, NULL); + I2SDataPut(I2S_BASE, I2S_DATA_LINE_0, (unsigned long)0); + n++; + m+=2; + if (n == 48) { + n = 0; + } + if (m == 48) { + m = 0; + } + } + + printf("\n***Progam ended***\n"); + + return 0; +} diff --git a/dis10_sine/targetConfigs/CC3220S.ccxml b/dis10_sine/targetConfigs/CC3220S.ccxml new file mode 100644 index 0000000..e643caa --- /dev/null +++ b/dis10_sine/targetConfigs/CC3220S.ccxml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dis10_sine/targetConfigs/readme.txt b/dis10_sine/targetConfigs/readme.txt new file mode 100644 index 0000000..af97b62 --- /dev/null +++ b/dis10_sine/targetConfigs/readme.txt @@ -0,0 +1,9 @@ +The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based +on the device and connection settings specified in your project on the Properties > General page. + +Please note that in automatic target-configuration management, changes to the project's device and/or +connection settings will either modify an existing or generate a new target-configuration file. Thus, +if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively, +you may create your own target-configuration file for this project and manage it manually. You can +always switch back to automatic target-configuration management by checking the "Manage the project's +target-configuration automatically" checkbox on the project's Properties > General page. \ No newline at end of file diff --git a/line_in_2_line_out/.ccsproject b/line_in_2_line_out/.ccsproject new file mode 100644 index 0000000..8ed2f71 --- /dev/null +++ b/line_in_2_line_out/.ccsproject @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/line_in_2_line_out/.cproject b/line_in_2_line_out/.cproject new file mode 100644 index 0000000..3ff00cd --- /dev/null +++ b/line_in_2_line_out/.cproject @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/line_in_2_line_out/.gitignore b/line_in_2_line_out/.gitignore new file mode 100644 index 0000000..7c1916f --- /dev/null +++ b/line_in_2_line_out/.gitignore @@ -0,0 +1,2 @@ +/MCU+Image/ +/Debug/ diff --git a/line_in_2_line_out/.launches/line_in_2_line_out.launch b/line_in_2_line_out/.launches/line_in_2_line_out.launch new file mode 100644 index 0000000..e08bac4 --- /dev/null +++ b/line_in_2_line_out/.launches/line_in_2_line_out.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/line_in_2_line_out/.project b/line_in_2_line_out/.project new file mode 100644 index 0000000..896e3da --- /dev/null +++ b/line_in_2_line_out/.project @@ -0,0 +1,34 @@ + + + line_in_2_line_out + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.ti.ccstudio.core.ccsNature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + Board.html + 1 + COM_TI_SIMPLELINK_CC32XX_SDK_INSTALL_DIR/source/ti/boards/CC3220S_LAUNCHXL/Board.html + + + diff --git a/line_in_2_line_out/.settings/org.eclipse.cdt.codan.core.prefs b/line_in_2_line_out/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..98b6350 --- /dev/null +++ b/line_in_2_line_out/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +inEditor=false +onBuild=false diff --git a/line_in_2_line_out/.settings/org.eclipse.cdt.debug.core.prefs b/line_in_2_line_out/.settings/org.eclipse.cdt.debug.core.prefs new file mode 100644 index 0000000..58d4fb2 --- /dev/null +++ b/line_in_2_line_out/.settings/org.eclipse.cdt.debug.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker diff --git a/line_in_2_line_out/.settings/org.eclipse.core.resources.prefs b/line_in_2_line_out/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..7c051cc --- /dev/null +++ b/line_in_2_line_out/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//Debug/makefile=UTF-8 +encoding//Debug/objects.mk=UTF-8 +encoding//Debug/sources.mk=UTF-8 +encoding//Debug/subdir_rules.mk=UTF-8 +encoding//Debug/subdir_vars.mk=UTF-8 diff --git a/line_in_2_line_out/audio.syscfg b/line_in_2_line_out/audio.syscfg new file mode 100644 index 0000000..1ce1557 --- /dev/null +++ b/line_in_2_line_out/audio.syscfg @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2018-2021, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +// @cliArgs --board /ti/boards/CC3220S_LAUNCHXL --rtos nortos + +/* + * gpiointerrupt.syscfg + */ +/* ======== Boosterpacks ========= BroJZ 20220415*/ +const CC3200AUDBOOST = scripting.addHardware("/ti/boards/boosterpacks/CC3200AUDBOOST"); + +/* ======== TIRTOS7 ======== */ +if (system.getRTOS() === "tirtos7") { + const tirtos7_release_syscfg_js = system.getScript("tirtos7_release.syscfg.js"); +} + +/** + * Import the modules used in this configuration. + */ +const I2C = scripting.addModule("/ti/drivers/I2C"); +const I2C1 = I2C.addInstance(); +const I2S = scripting.addModule("/ti/drivers/I2S"); +const I2S1 = I2S.addInstance(); +const RTOS = scripting.addModule("/ti/drivers/RTOS"); + +/** + * Write custom configuration values to the imported modules. + */ +I2C1.$name = "CONFIG_I2C_0"; +I2C1.$hardware = system.deviceData.board.components.LP_I2C; + +I2S1.$name = "CONFIG_I2S_0"; +I2S1.interruptPriority = "2"; +I2S1.$hardware = CC3200AUDBOOST.components.CC3200AUDBOOST_I2S; + +const Power = scripting.addModule("/ti/drivers/Power", {}, false); +Power.parkPins.$name = "ti_drivers_power_PowerCC32XXPins0"; + +RTOS.name = "NoRTOS"; + +/** + * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future + * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to + * re-solve from scratch. + */ +I2C1.i2c.$suggestSolution = "I2C0"; +I2C1.i2c.sdaPin.$suggestSolution = "boosterpack.10"; +I2C1.i2c.sclPin.$suggestSolution = "boosterpack.9"; +I2S1.i2s.$suggestSolution = "McASP0"; +I2S1.i2s.SD0Pin.$suggestSolution = "boosterpack.29"; +I2S1.i2s.SD1Pin.$suggestSolution = "boosterpack.30"; +I2S1.i2s.SCKPin.$suggestSolution = "boosterpack.28"; +I2S1.i2s.WSPin.$suggestSolution = "boosterpack.27"; +I2S1.i2s.dmaRxChannel.$suggestSolution = "UDMA_CH18"; +I2S1.i2s.dmaTxChannel.$suggestSolution = "UDMA_CH19"; diff --git a/line_in_2_line_out/berekeningen klokinstellingen codec.xlsx b/line_in_2_line_out/berekeningen klokinstellingen codec.xlsx new file mode 100644 index 0000000..304dcbd Binary files /dev/null and b/line_in_2_line_out/berekeningen klokinstellingen codec.xlsx differ diff --git a/line_in_2_line_out/cc32xxs_nortos.cmd b/line_in_2_line_out/cc32xxs_nortos.cmd new file mode 100644 index 0000000..4e6d27a --- /dev/null +++ b/line_in_2_line_out/cc32xxs_nortos.cmd @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018-2020, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +--stack_size=0x1000 +--heap_size=0x8000 +--entry_point=resetISR +--diag_suppress=10063 /* suppress warning about non _c_int00 entry point */ + +/* + * The starting address of the application. Normally the interrupt vectors + * must be located at the beginning of the application. + */ +#define SRAM_BASE 0x20004000 +#define SRAM2_BASE 0x20000000 + +MEMORY +{ + SRAM (RWX) : origin = 0x20004000, length = 0x00040000 - 0x4000 + SRAM2 (RWX) : origin = 0x20000000, length = 0x4000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : origin = 0x90000000, length = 0x40000 +} + +/* Section allocation in memory */ + +SECTIONS +{ + .text : > SRAM + .TI.ramfunc : > SRAM + .const : > SRAM + .rodata : > SRAM + .cinit : > SRAM + .pinit : > SRAM + .init_array : > SRAM + + .data : > SRAM + .bss : > SRAM + .sysmem : > SRAM + .stack : > SRAM2(HIGH) + + .resetVecs : > SRAM_BASE + .ramVecs : > SRAM2_BASE, type=NOLOAD + + .log_data : > LOG_DATA, type = COPY +} diff --git a/line_in_2_line_out/config.c b/line_in_2_line_out/config.c new file mode 100644 index 0000000..af9798e --- /dev/null +++ b/line_in_2_line_out/config.c @@ -0,0 +1,289 @@ +/* + * Configure functions to use the TI TLV320AIC3254 codec on the + * CC3200AUDBOOST board with the CC3220S-LAUNCHXL board + * without using DMA. + * + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + * + * Based on Driver for TI TLV320AIC3110 CODEC + * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "config.h" + +// Configure an I2C connection using the TI I2C driver. + +I2C_Handle ConfigureI2C(uint_least8_t index, I2C_BitRate bitRate) +{ + I2C_Handle i2cHandle; + I2C_Params i2cParams; + I2C_init(); + I2C_Params_init(&i2cParams); + i2cParams.bitRate = bitRate; + i2cHandle = I2C_open(index, &i2cParams); + if (i2cHandle == NULL) { + // Error initializing I2C. + while (1); + } + return i2cHandle; +} + +// Configure an I2S connection which is use to send/receive samples to/from the codec. + +void ConfigureI2S(unsigned long peripheral, unsigned long base, unsigned int samplingFrequency) +{ + // Register power dependency. Keeps the I2S clock running in SLP and DSLP modes. + int_fast16_t ret = Power_setDependency(PowerCC32XX_PERIPH_I2S); + if (ret != Power_SOK) { + // Error setting power dependency. + while (1); + } + + // There is no TI I2S driver (without DMA) available so the TI driverlib API is used. + PRCMPeripheralReset(peripheral); + I2SEnable(base, I2S_MODE_TX_RX_SYNC); + + unsigned int bitClock = samplingFrequency * 16 * 2; + PRCMI2SClockFreqSet(bitClock); + I2SConfigSetExpClk(base, bitClock, bitClock, I2S_MODE_MASTER | I2S_SLOT_SIZE_16 | I2S_PORT_CPU); + + I2SSerializerConfig(base, I2S_DATA_LINE_0, I2S_SER_MODE_TX, I2S_INACT_LOW_LEVEL); + I2SSerializerConfig(base, I2S_DATA_LINE_1, I2S_SER_MODE_RX, I2S_INACT_LOW_LEVEL); + + // Configure I2S pins in pin mux + PinTypeI2S(PIN_64, PIN_MODE_7); // xr0Pin = I2S SDout (CC3220S-LAUNCHXL) = DIN_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_50, PIN_MODE_6); // xr1Pin = I2S SDin (CC3220S-LAUNCHXL) = DOUT_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_53, PIN_MODE_2); // clkPin = I2S SCLK (CC3220S-LAUNCHXL) = BCLK_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_63, PIN_MODE_7); // fsxPin = I2S WC (CC3220S-LAUNCHXL) = FSYNC_J3 (CC3200AUDBOOST) + + PRCMPeripheralClkEnable(peripheral, PRCM_RUN_MODE_CLK); +} + +#define CODEC_I2C_SLAVE_ADDR ((0x30 >> 1)) + +static uint8_t CodecRegRead(I2C_Handle i2cHandle, uint8_t regAddr) +{ + I2C_Transaction i2cTransaction; + uint8_t data; + + i2cTransaction.slaveAddress = CODEC_I2C_SLAVE_ADDR; + i2cTransaction.writeBuf = ®Addr; + i2cTransaction.writeCount = 1; + i2cTransaction.readBuf = &data; + i2cTransaction.readCount = 1; + if (!I2C_transfer(i2cHandle, &i2cTransaction)) + { + // I2C transfer failed + while (1); + } + return data; +} + +static void CodecRegWrite(I2C_Handle i2cHandle, uint8_t regAddr, uint8_t regValue) +{ + uint8_t data[2]; + I2C_Transaction i2cTransaction; + + data[0] = regAddr; + data[1] = regValue; + + i2cTransaction.slaveAddress = CODEC_I2C_SLAVE_ADDR; + i2cTransaction.writeBuf = &data[0]; + i2cTransaction.writeCount = 2; + i2cTransaction.readBuf = NULL; + i2cTransaction.readCount = 0; + if (!I2C_transfer(i2cHandle, &i2cTransaction)) + { + // I2C transfer failed + while (1); + } +} + +static void CodecPageSelect(I2C_Handle i2cHandle, unsigned long pageAddress) +{ + CodecRegWrite(i2cHandle, 0, pageAddress); +} + +static void CodecReset(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Soft RESET. + CodecRegWrite(i2cHandle, 1, 0x01); + // Wait for 27000 * 3 = 81000 clock cycles @ 80 MHz ~ 1 ms. + UtilsDelay(27000); +} + +// volume: 0 -> 0 bB (Highest) to 116 -> -72.3 dB (Lowest) +void AudioVolumeControl(I2C_Handle i2cHandle, signed char volume) +{ + // Select page 1 + CodecPageSelect(i2cHandle, 1); + // Enable HPL output analog volume + CodecRegWrite(i2cHandle, 22, volume); + CodecRegWrite(i2cHandle, 23, volume); +} + +void CodecMute(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Mute. + CodecRegWrite(i2cHandle, 64, 0x0C); +} + +void CodecUnmute(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Unmute. + CodecRegWrite(i2cHandle, 64, 0x00); +} + +// Codec configure: + // PGA (Programmable Gain Amplifier) = 0 dB. + // Headphone Output = enabled. + // Line outputs (to class D amplifier) = disabled. + // ADC gain = 0 dB. + // AGC (Automatic Gain Control) = disabled. + // ADC processing block = PRB_R1 (default). + // Microphone = disabled. + // DAC processing block = PRB_P1 (default). + // DRC (Dynamic Gain Compression) = disabled. + +void ConfigureAudioCodec(I2C_Handle i2cHandle, unsigned int samplingFrequency) +{ + // Check parameter. + if (samplingFrequency < 8000 || samplingFrequency > 48000 || samplingFrequency % 4000 != 0) + { + while(1); + // Wrong value for sampling frequency. + } + size_t sampleIndex = (samplingFrequency / 4000) - 2; + // values for DOSR, MDAC, NDAC, NADC and J in steps of 4 kHz starting from 8 kHz to 48 kHz. + // 8 12 16 20 24 28 32 36 40 44 48 + int DOSR[] = {512, 512, 384, 304, 256, 208, 192, 160, 144, 128, 128}; + int MDAC[] = { 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2}; + int NDAC[] = { 1, 1, 2, 16, 8, 8, 8, 8, 8, 8, 8}; + int NADC[] = { 2, 2, 3, 19, 16, 13, 12, 10, 9, 8, 8}; + int J[] = { 4, 4, 6, 38, 32, 26, 24, 20, 18, 16, 16}; + + // Reset code for startup. + CodecReset(i2cHandle); + + // Select page 0. + CodecPageSelect(i2cHandle, 0); + + // Set I2S Mode and Word Length = 16 bits, BCLK and WCLK are inputs to the device. + CodecRegWrite(i2cHandle, 27, 0x00); + // Clock settings chip + CodecRegWrite(i2cHandle, 4, 0x03); // PLL CLock is CODEC_CLKIN + CodecRegWrite(i2cHandle, 5, 0x94); // PLL enabled, P = 1, R = 4 + CodecRegWrite(i2cHandle, 6, J[sampleIndex]); // PLL J + CodecRegWrite(i2cHandle, 7, 0); // PLL D = 0 + CodecRegWrite(i2cHandle, 8, 0); // PLL D = 0 + // PLL_CLK = PLL_CLKIN * R * J.D / P = PLL_CLKIN * 4 * J = (Fs * 32) * 4 * J + + // Clock settings DAC. + CodecRegWrite(i2cHandle, 11, 0x80 + NDAC[sampleIndex]); // NDAC is powered up + CodecRegWrite(i2cHandle, 12, 0x80 + MDAC[sampleIndex]); // MDAC is powered up + CodecRegWrite(i2cHandle, 13, DOSR[sampleIndex] / 256); // DOSR + CodecRegWrite(i2cHandle, 14, DOSR[sampleIndex] % 256); + // DAC_fs = CODEC_CLKIN / (NDAC * MDAC * DOSR) + + // Clock settings ADC. + CodecRegWrite(i2cHandle, 18, 0x80 + NADC[sampleIndex]); // NADC is powered up, NADC = 2 + CodecRegWrite(i2cHandle, 19, 0x80 + 2); // MADC is powered up, MADC = 2 + CodecRegWrite(i2cHandle, 20, 128); // AOSR = 128 + // ADC_fs = CODEC_CLKIN / (NADC * MADC * AOSR) + + // Configure power supplies. + CodecPageSelect(i2cHandle, 1); + CodecRegWrite(i2cHandle, 1, 0x08); // AVdd and DVdd are connected + CodecRegWrite(i2cHandle, 2, 0x01); // LDO enabled AVDD LDO output = 1.72 V + CodecRegWrite(i2cHandle, 71, 0x32); // Aanalog input powerup = 6.4 ms + CodecRegWrite(i2cHandle, 123, 0x01); // Reference powered up in 40 ms + + // Configure ADC channel. + // Route IN1L to Left MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 52, 0x40); + // Route CM to Left MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 54, 0x40); + // Route IN1R to Right MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 55, 0x40); + // Route CM to Right MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 57,0x40); + // Floating IN1L. + CodecRegWrite(i2cHandle, 58, 0xC0); + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + // Power up LADC/RADC. + CodecRegWrite(i2cHandle, 81, 0xC0); + // Unmute LADC/RADC. + CodecRegWrite(i2cHandle, 82, 0x00); + + // Configure DAC channel. + // Select Page 1. + CodecPageSelect(i2cHandle, 1); + + // De-pop: soft stepping disabled, N = 5, Rpop = 6k. See SLAA408A page 11,12,13. + CodecRegWrite(i2cHandle, 20, 0x25); + + // Route LDAC/RDAC to HPL/HPR. + CodecRegWrite(i2cHandle, 12, 0x08); + CodecRegWrite(i2cHandle, 13, 0x08); + + // Power up HPL/HPR drivers. + CodecRegWrite(i2cHandle, 9, 0x30); + + // Unmute HPL/HPR driver, 0dB Gain. + CodecRegWrite(i2cHandle, 16, 0x00); + CodecRegWrite(i2cHandle, 17, 0x00); + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + + // Unmute DAC, 0dB Gain. + CodecRegWrite(i2cHandle, 65, 0x00); + CodecRegWrite(i2cHandle, 66, 0x00); + + // Select Page 1. + CodecPageSelect(i2cHandle, 1); + + while (CodecRegRead(i2cHandle, 63) & 0x11000000 != 0x11000000) + { + UtilsDelay(27000); // delay 27000 * 3 = 81000 clock cycles @ 80 MHz ~ 1 ms. + } + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + + // Power up LDAC/RDAC. + CodecRegWrite(i2cHandle, 63, 0xd4); + + // Unmute LDAC/RDAC. + CodecRegWrite(i2cHandle, 64, 0x00); +} diff --git a/line_in_2_line_out/config.h b/line_in_2_line_out/config.h new file mode 100644 index 0000000..bfaa628 --- /dev/null +++ b/line_in_2_line_out/config.h @@ -0,0 +1,41 @@ +/* + * Configure functions to use the TI TLV320AIC3254 codec on the + * CC3200AUDBOOST board with the CC3220S-LAUNCHXL board + * without using DMA. + * + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + * + * Based on Driver for TI TLV320AIC3110 codec + * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + */ +#ifndef __HR_CONFIG_H__ +#define __HR_CONFIG_H__ + +#include + +// Configure an I2C connection using the TI I2C driver. +extern I2C_Handle ConfigureI2C(uint_least8_t index, I2C_BitRate bitRate); + +// Configure an I2S connection using the TI driverlib API. +extern void ConfigureI2S(unsigned long peripheral, unsigned long base, unsigned int samplingFrequency); + +// Functions to configure the codec using an I2C connection +// volume: 0 -> 0 bB (Highest) to 116 -> -72.3 dB (Lowest) +extern void AudioVolumeControl(I2C_Handle i2cHandle, signed char volume); +extern void CodecMute(I2C_Handle i2cHandle); +extern void CodecUnmute(I2C_Handle i2cHandle); +// Codec configure: + // PGA (Programmable Gain Amplifier) = 0 dB. + // Headphone Output = enabled. + // Line outputs (to class D amplifier) = disabled. + // ADC gain = 0 dB. + // AGC (Automatic Gain Control) = disabled. + // ADC processing block = PRB_R1 (default). + // Microphone = disabled. + // DAC processing block = PRB_P1 (default). + // DRC (Dynamic Gain Compression) = disabled. +extern void ConfigureAudioCodec(I2C_Handle i2cHandle, unsigned int samplingFrequency); + +#endif diff --git a/line_in_2_line_out/main_nortos.c b/line_in_2_line_out/main_nortos.c new file mode 100644 index 0000000..f81e609 --- /dev/null +++ b/line_in_2_line_out/main_nortos.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "ti_drivers_config.h" +#include "config.h" + +// You can select the sample rate here: +#define SAMPLINGFREQUENCY 16000 +#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 + +int main(void) +{ + // Init CC3220S LAUNCHXL board. + Board_initGeneral(); + // Prepare to use TI drivers without operating system. + NoRTOS_start(); + + printf("line-in_2_line_out: STEREO LINE IN ==> HP LINE OUT.\n"); + printf("Sampling frequency = %d Hz.\n", SAMPLINGFREQUENCY); + + // 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); + + while (1) + { + unsigned long dataLeft, dataRight; + // The 16-bit samples are stored in 32-bit variables because the API also supports 24-bit samples. + I2SDataGet(I2S_BASE, I2S_DATA_LINE_1, &dataLeft); + int16_t left_sample = dataLeft; + // You can process the 16-bit left sample here. + dataLeft = left_sample; + I2SDataPut(I2S_BASE, I2S_DATA_LINE_0, dataLeft); + I2SDataGet(I2S_BASE, I2S_DATA_LINE_1, &dataRight); + int16_t right_sample = dataRight; + // You can process the 16-bit right sample here. + dataRight = right_sample; + I2SDataPut(I2S_BASE, I2S_DATA_LINE_0, dataRight); + } + return 0; +} diff --git a/line_in_2_line_out/targetConfigs/CC3220S.ccxml b/line_in_2_line_out/targetConfigs/CC3220S.ccxml new file mode 100644 index 0000000..ae9589d --- /dev/null +++ b/line_in_2_line_out/targetConfigs/CC3220S.ccxml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/line_in_2_line_out/targetConfigs/readme.txt b/line_in_2_line_out/targetConfigs/readme.txt new file mode 100644 index 0000000..af97b62 --- /dev/null +++ b/line_in_2_line_out/targetConfigs/readme.txt @@ -0,0 +1,9 @@ +The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based +on the device and connection settings specified in your project on the Properties > General page. + +Please note that in automatic target-configuration management, changes to the project's device and/or +connection settings will either modify an existing or generate a new target-configuration file. Thus, +if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively, +you may create your own target-configuration file for this project and manage it manually. You can +always switch back to automatic target-configuration management by checking the "Manage the project's +target-configuration automatically" checkbox on the project's Properties > General page. \ No newline at end of file diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.ccsproject b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.ccsproject new file mode 100644 index 0000000..8ed2f71 --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.ccsproject @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.cproject b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.cproject new file mode 100644 index 0000000..3ff00cd --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.cproject @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.gitignore b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.gitignore new file mode 100644 index 0000000..7c1916f --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.gitignore @@ -0,0 +1,2 @@ +/MCU+Image/ +/Debug/ diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.project b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.project new file mode 100644 index 0000000..896e3da --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.project @@ -0,0 +1,34 @@ + + + line_in_2_line_out + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.ti.ccstudio.core.ccsNature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + Board.html + 1 + COM_TI_SIMPLELINK_CC32XX_SDK_INSTALL_DIR/source/ti/boards/CC3220S_LAUNCHXL/Board.html + + + diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.settings/org.eclipse.cdt.codan.core.prefs b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..98b6350 --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +inEditor=false +onBuild=false diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.settings/org.eclipse.cdt.debug.core.prefs b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.settings/org.eclipse.cdt.debug.core.prefs new file mode 100644 index 0000000..58d4fb2 --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.settings/org.eclipse.cdt.debug.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.settings/org.eclipse.core.resources.prefs b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..7c051cc --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//Debug/makefile=UTF-8 +encoding//Debug/objects.mk=UTF-8 +encoding//Debug/sources.mk=UTF-8 +encoding//Debug/subdir_rules.mk=UTF-8 +encoding//Debug/subdir_vars.mk=UTF-8 diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/audio.syscfg b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/audio.syscfg new file mode 100644 index 0000000..1ce1557 --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/audio.syscfg @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2018-2021, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +// @cliArgs --board /ti/boards/CC3220S_LAUNCHXL --rtos nortos + +/* + * gpiointerrupt.syscfg + */ +/* ======== Boosterpacks ========= BroJZ 20220415*/ +const CC3200AUDBOOST = scripting.addHardware("/ti/boards/boosterpacks/CC3200AUDBOOST"); + +/* ======== TIRTOS7 ======== */ +if (system.getRTOS() === "tirtos7") { + const tirtos7_release_syscfg_js = system.getScript("tirtos7_release.syscfg.js"); +} + +/** + * Import the modules used in this configuration. + */ +const I2C = scripting.addModule("/ti/drivers/I2C"); +const I2C1 = I2C.addInstance(); +const I2S = scripting.addModule("/ti/drivers/I2S"); +const I2S1 = I2S.addInstance(); +const RTOS = scripting.addModule("/ti/drivers/RTOS"); + +/** + * Write custom configuration values to the imported modules. + */ +I2C1.$name = "CONFIG_I2C_0"; +I2C1.$hardware = system.deviceData.board.components.LP_I2C; + +I2S1.$name = "CONFIG_I2S_0"; +I2S1.interruptPriority = "2"; +I2S1.$hardware = CC3200AUDBOOST.components.CC3200AUDBOOST_I2S; + +const Power = scripting.addModule("/ti/drivers/Power", {}, false); +Power.parkPins.$name = "ti_drivers_power_PowerCC32XXPins0"; + +RTOS.name = "NoRTOS"; + +/** + * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future + * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to + * re-solve from scratch. + */ +I2C1.i2c.$suggestSolution = "I2C0"; +I2C1.i2c.sdaPin.$suggestSolution = "boosterpack.10"; +I2C1.i2c.sclPin.$suggestSolution = "boosterpack.9"; +I2S1.i2s.$suggestSolution = "McASP0"; +I2S1.i2s.SD0Pin.$suggestSolution = "boosterpack.29"; +I2S1.i2s.SD1Pin.$suggestSolution = "boosterpack.30"; +I2S1.i2s.SCKPin.$suggestSolution = "boosterpack.28"; +I2S1.i2s.WSPin.$suggestSolution = "boosterpack.27"; +I2S1.i2s.dmaRxChannel.$suggestSolution = "UDMA_CH18"; +I2S1.i2s.dmaTxChannel.$suggestSolution = "UDMA_CH19"; diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/berekeningen klokinstellingen codec.xlsx b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/berekeningen klokinstellingen codec.xlsx new file mode 100644 index 0000000..304dcbd Binary files /dev/null and b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/berekeningen klokinstellingen codec.xlsx differ diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/cc32xxs_nortos.cmd b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/cc32xxs_nortos.cmd new file mode 100644 index 0000000..4e6d27a --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/cc32xxs_nortos.cmd @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018-2020, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +--stack_size=0x1000 +--heap_size=0x8000 +--entry_point=resetISR +--diag_suppress=10063 /* suppress warning about non _c_int00 entry point */ + +/* + * The starting address of the application. Normally the interrupt vectors + * must be located at the beginning of the application. + */ +#define SRAM_BASE 0x20004000 +#define SRAM2_BASE 0x20000000 + +MEMORY +{ + SRAM (RWX) : origin = 0x20004000, length = 0x00040000 - 0x4000 + SRAM2 (RWX) : origin = 0x20000000, length = 0x4000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : origin = 0x90000000, length = 0x40000 +} + +/* Section allocation in memory */ + +SECTIONS +{ + .text : > SRAM + .TI.ramfunc : > SRAM + .const : > SRAM + .rodata : > SRAM + .cinit : > SRAM + .pinit : > SRAM + .init_array : > SRAM + + .data : > SRAM + .bss : > SRAM + .sysmem : > SRAM + .stack : > SRAM2(HIGH) + + .resetVecs : > SRAM_BASE + .ramVecs : > SRAM2_BASE, type=NOLOAD + + .log_data : > LOG_DATA, type = COPY +} diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/config.c b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/config.c new file mode 100644 index 0000000..af9798e --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/config.c @@ -0,0 +1,289 @@ +/* + * Configure functions to use the TI TLV320AIC3254 codec on the + * CC3200AUDBOOST board with the CC3220S-LAUNCHXL board + * without using DMA. + * + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + * + * Based on Driver for TI TLV320AIC3110 CODEC + * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "config.h" + +// Configure an I2C connection using the TI I2C driver. + +I2C_Handle ConfigureI2C(uint_least8_t index, I2C_BitRate bitRate) +{ + I2C_Handle i2cHandle; + I2C_Params i2cParams; + I2C_init(); + I2C_Params_init(&i2cParams); + i2cParams.bitRate = bitRate; + i2cHandle = I2C_open(index, &i2cParams); + if (i2cHandle == NULL) { + // Error initializing I2C. + while (1); + } + return i2cHandle; +} + +// Configure an I2S connection which is use to send/receive samples to/from the codec. + +void ConfigureI2S(unsigned long peripheral, unsigned long base, unsigned int samplingFrequency) +{ + // Register power dependency. Keeps the I2S clock running in SLP and DSLP modes. + int_fast16_t ret = Power_setDependency(PowerCC32XX_PERIPH_I2S); + if (ret != Power_SOK) { + // Error setting power dependency. + while (1); + } + + // There is no TI I2S driver (without DMA) available so the TI driverlib API is used. + PRCMPeripheralReset(peripheral); + I2SEnable(base, I2S_MODE_TX_RX_SYNC); + + unsigned int bitClock = samplingFrequency * 16 * 2; + PRCMI2SClockFreqSet(bitClock); + I2SConfigSetExpClk(base, bitClock, bitClock, I2S_MODE_MASTER | I2S_SLOT_SIZE_16 | I2S_PORT_CPU); + + I2SSerializerConfig(base, I2S_DATA_LINE_0, I2S_SER_MODE_TX, I2S_INACT_LOW_LEVEL); + I2SSerializerConfig(base, I2S_DATA_LINE_1, I2S_SER_MODE_RX, I2S_INACT_LOW_LEVEL); + + // Configure I2S pins in pin mux + PinTypeI2S(PIN_64, PIN_MODE_7); // xr0Pin = I2S SDout (CC3220S-LAUNCHXL) = DIN_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_50, PIN_MODE_6); // xr1Pin = I2S SDin (CC3220S-LAUNCHXL) = DOUT_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_53, PIN_MODE_2); // clkPin = I2S SCLK (CC3220S-LAUNCHXL) = BCLK_J3 (CC3200AUDBOOST) + PinTypeI2S(PIN_63, PIN_MODE_7); // fsxPin = I2S WC (CC3220S-LAUNCHXL) = FSYNC_J3 (CC3200AUDBOOST) + + PRCMPeripheralClkEnable(peripheral, PRCM_RUN_MODE_CLK); +} + +#define CODEC_I2C_SLAVE_ADDR ((0x30 >> 1)) + +static uint8_t CodecRegRead(I2C_Handle i2cHandle, uint8_t regAddr) +{ + I2C_Transaction i2cTransaction; + uint8_t data; + + i2cTransaction.slaveAddress = CODEC_I2C_SLAVE_ADDR; + i2cTransaction.writeBuf = ®Addr; + i2cTransaction.writeCount = 1; + i2cTransaction.readBuf = &data; + i2cTransaction.readCount = 1; + if (!I2C_transfer(i2cHandle, &i2cTransaction)) + { + // I2C transfer failed + while (1); + } + return data; +} + +static void CodecRegWrite(I2C_Handle i2cHandle, uint8_t regAddr, uint8_t regValue) +{ + uint8_t data[2]; + I2C_Transaction i2cTransaction; + + data[0] = regAddr; + data[1] = regValue; + + i2cTransaction.slaveAddress = CODEC_I2C_SLAVE_ADDR; + i2cTransaction.writeBuf = &data[0]; + i2cTransaction.writeCount = 2; + i2cTransaction.readBuf = NULL; + i2cTransaction.readCount = 0; + if (!I2C_transfer(i2cHandle, &i2cTransaction)) + { + // I2C transfer failed + while (1); + } +} + +static void CodecPageSelect(I2C_Handle i2cHandle, unsigned long pageAddress) +{ + CodecRegWrite(i2cHandle, 0, pageAddress); +} + +static void CodecReset(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Soft RESET. + CodecRegWrite(i2cHandle, 1, 0x01); + // Wait for 27000 * 3 = 81000 clock cycles @ 80 MHz ~ 1 ms. + UtilsDelay(27000); +} + +// volume: 0 -> 0 bB (Highest) to 116 -> -72.3 dB (Lowest) +void AudioVolumeControl(I2C_Handle i2cHandle, signed char volume) +{ + // Select page 1 + CodecPageSelect(i2cHandle, 1); + // Enable HPL output analog volume + CodecRegWrite(i2cHandle, 22, volume); + CodecRegWrite(i2cHandle, 23, volume); +} + +void CodecMute(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Mute. + CodecRegWrite(i2cHandle, 64, 0x0C); +} + +void CodecUnmute(I2C_Handle i2cHandle) +{ + // Select page 0. + CodecPageSelect(i2cHandle, 0); + // Unmute. + CodecRegWrite(i2cHandle, 64, 0x00); +} + +// Codec configure: + // PGA (Programmable Gain Amplifier) = 0 dB. + // Headphone Output = enabled. + // Line outputs (to class D amplifier) = disabled. + // ADC gain = 0 dB. + // AGC (Automatic Gain Control) = disabled. + // ADC processing block = PRB_R1 (default). + // Microphone = disabled. + // DAC processing block = PRB_P1 (default). + // DRC (Dynamic Gain Compression) = disabled. + +void ConfigureAudioCodec(I2C_Handle i2cHandle, unsigned int samplingFrequency) +{ + // Check parameter. + if (samplingFrequency < 8000 || samplingFrequency > 48000 || samplingFrequency % 4000 != 0) + { + while(1); + // Wrong value for sampling frequency. + } + size_t sampleIndex = (samplingFrequency / 4000) - 2; + // values for DOSR, MDAC, NDAC, NADC and J in steps of 4 kHz starting from 8 kHz to 48 kHz. + // 8 12 16 20 24 28 32 36 40 44 48 + int DOSR[] = {512, 512, 384, 304, 256, 208, 192, 160, 144, 128, 128}; + int MDAC[] = { 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2}; + int NDAC[] = { 1, 1, 2, 16, 8, 8, 8, 8, 8, 8, 8}; + int NADC[] = { 2, 2, 3, 19, 16, 13, 12, 10, 9, 8, 8}; + int J[] = { 4, 4, 6, 38, 32, 26, 24, 20, 18, 16, 16}; + + // Reset code for startup. + CodecReset(i2cHandle); + + // Select page 0. + CodecPageSelect(i2cHandle, 0); + + // Set I2S Mode and Word Length = 16 bits, BCLK and WCLK are inputs to the device. + CodecRegWrite(i2cHandle, 27, 0x00); + // Clock settings chip + CodecRegWrite(i2cHandle, 4, 0x03); // PLL CLock is CODEC_CLKIN + CodecRegWrite(i2cHandle, 5, 0x94); // PLL enabled, P = 1, R = 4 + CodecRegWrite(i2cHandle, 6, J[sampleIndex]); // PLL J + CodecRegWrite(i2cHandle, 7, 0); // PLL D = 0 + CodecRegWrite(i2cHandle, 8, 0); // PLL D = 0 + // PLL_CLK = PLL_CLKIN * R * J.D / P = PLL_CLKIN * 4 * J = (Fs * 32) * 4 * J + + // Clock settings DAC. + CodecRegWrite(i2cHandle, 11, 0x80 + NDAC[sampleIndex]); // NDAC is powered up + CodecRegWrite(i2cHandle, 12, 0x80 + MDAC[sampleIndex]); // MDAC is powered up + CodecRegWrite(i2cHandle, 13, DOSR[sampleIndex] / 256); // DOSR + CodecRegWrite(i2cHandle, 14, DOSR[sampleIndex] % 256); + // DAC_fs = CODEC_CLKIN / (NDAC * MDAC * DOSR) + + // Clock settings ADC. + CodecRegWrite(i2cHandle, 18, 0x80 + NADC[sampleIndex]); // NADC is powered up, NADC = 2 + CodecRegWrite(i2cHandle, 19, 0x80 + 2); // MADC is powered up, MADC = 2 + CodecRegWrite(i2cHandle, 20, 128); // AOSR = 128 + // ADC_fs = CODEC_CLKIN / (NADC * MADC * AOSR) + + // Configure power supplies. + CodecPageSelect(i2cHandle, 1); + CodecRegWrite(i2cHandle, 1, 0x08); // AVdd and DVdd are connected + CodecRegWrite(i2cHandle, 2, 0x01); // LDO enabled AVDD LDO output = 1.72 V + CodecRegWrite(i2cHandle, 71, 0x32); // Aanalog input powerup = 6.4 ms + CodecRegWrite(i2cHandle, 123, 0x01); // Reference powered up in 40 ms + + // Configure ADC channel. + // Route IN1L to Left MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 52, 0x40); + // Route CM to Left MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 54, 0x40); + // Route IN1R to Right MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 55, 0x40); + // Route CM to Right MICPGA with 10K input impedance. + CodecRegWrite(i2cHandle, 57,0x40); + // Floating IN1L. + CodecRegWrite(i2cHandle, 58, 0xC0); + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + // Power up LADC/RADC. + CodecRegWrite(i2cHandle, 81, 0xC0); + // Unmute LADC/RADC. + CodecRegWrite(i2cHandle, 82, 0x00); + + // Configure DAC channel. + // Select Page 1. + CodecPageSelect(i2cHandle, 1); + + // De-pop: soft stepping disabled, N = 5, Rpop = 6k. See SLAA408A page 11,12,13. + CodecRegWrite(i2cHandle, 20, 0x25); + + // Route LDAC/RDAC to HPL/HPR. + CodecRegWrite(i2cHandle, 12, 0x08); + CodecRegWrite(i2cHandle, 13, 0x08); + + // Power up HPL/HPR drivers. + CodecRegWrite(i2cHandle, 9, 0x30); + + // Unmute HPL/HPR driver, 0dB Gain. + CodecRegWrite(i2cHandle, 16, 0x00); + CodecRegWrite(i2cHandle, 17, 0x00); + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + + // Unmute DAC, 0dB Gain. + CodecRegWrite(i2cHandle, 65, 0x00); + CodecRegWrite(i2cHandle, 66, 0x00); + + // Select Page 1. + CodecPageSelect(i2cHandle, 1); + + while (CodecRegRead(i2cHandle, 63) & 0x11000000 != 0x11000000) + { + UtilsDelay(27000); // delay 27000 * 3 = 81000 clock cycles @ 80 MHz ~ 1 ms. + } + + // Select Page 0. + CodecPageSelect(i2cHandle, 0); + + // Power up LDAC/RDAC. + CodecRegWrite(i2cHandle, 63, 0xd4); + + // Unmute LDAC/RDAC. + CodecRegWrite(i2cHandle, 64, 0x00); +} diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/config.h b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/config.h new file mode 100644 index 0000000..bfaa628 --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/config.h @@ -0,0 +1,41 @@ +/* + * Configure functions to use the TI TLV320AIC3254 codec on the + * CC3200AUDBOOST board with the CC3220S-LAUNCHXL board + * without using DMA. + * + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + * + * Based on Driver for TI TLV320AIC3110 codec + * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + */ +#ifndef __HR_CONFIG_H__ +#define __HR_CONFIG_H__ + +#include + +// Configure an I2C connection using the TI I2C driver. +extern I2C_Handle ConfigureI2C(uint_least8_t index, I2C_BitRate bitRate); + +// Configure an I2S connection using the TI driverlib API. +extern void ConfigureI2S(unsigned long peripheral, unsigned long base, unsigned int samplingFrequency); + +// Functions to configure the codec using an I2C connection +// volume: 0 -> 0 bB (Highest) to 116 -> -72.3 dB (Lowest) +extern void AudioVolumeControl(I2C_Handle i2cHandle, signed char volume); +extern void CodecMute(I2C_Handle i2cHandle); +extern void CodecUnmute(I2C_Handle i2cHandle); +// Codec configure: + // PGA (Programmable Gain Amplifier) = 0 dB. + // Headphone Output = enabled. + // Line outputs (to class D amplifier) = disabled. + // ADC gain = 0 dB. + // AGC (Automatic Gain Control) = disabled. + // ADC processing block = PRB_R1 (default). + // Microphone = disabled. + // DAC processing block = PRB_P1 (default). + // DRC (Dynamic Gain Compression) = disabled. +extern void ConfigureAudioCodec(I2C_Handle i2cHandle, unsigned int samplingFrequency); + +#endif diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/main_nortos.c b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/main_nortos.c new file mode 100644 index 0000000..ecf242c --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/main_nortos.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders + * All rights reserved. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "ti_drivers_config.h" +#include "config.h" + +// You can select the sample rate here: +#define SAMPLINGFREQUENCY 44000 +#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 + +int main(void) +{ + // Init CC3220S LAUNCHXL board. + Board_initGeneral(); + // Prepare to use TI drivers without operating system. + NoRTOS_start(); + + printf("line-in_2_line_out: STEREO LINE IN ==> HP LINE OUT.\n"); + printf("Sampling frequency = %d Hz.\n", SAMPLINGFREQUENCY); + + // 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); + + while (1) + { + unsigned long dataLeft, dataRight; + // The 16-bit samples are stored in 32-bit variables because the API also supports 24-bit samples. + I2SDataGet(I2S_BASE, I2S_DATA_LINE_1, &dataLeft); + int16_t left_sample = dataLeft; + // You can process the 16-bit left sample here. + dataLeft = left_sample; + I2SDataPut(I2S_BASE, I2S_DATA_LINE_0, dataLeft); + I2SDataGet(I2S_BASE, I2S_DATA_LINE_1, &dataRight); + int16_t right_sample = dataRight; + // You can process the 16-bit right sample here. + dataRight = right_sample; + I2SDataPut(I2S_BASE, I2S_DATA_LINE_0, dataRight); + } + return 0; +} diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/targetConfigs/CC3220S.ccxml b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/targetConfigs/CC3220S.ccxml new file mode 100644 index 0000000..ae9589d --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/targetConfigs/CC3220S.ccxml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/targetConfigs/readme.txt b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/targetConfigs/readme.txt new file mode 100644 index 0000000..af97b62 --- /dev/null +++ b/line_in_2_line_out_5_30.zip_expanded/line_in_2_line_out/targetConfigs/readme.txt @@ -0,0 +1,9 @@ +The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based +on the device and connection settings specified in your project on the Properties > General page. + +Please note that in automatic target-configuration management, changes to the project's device and/or +connection settings will either modify an existing or generate a new target-configuration file. Thus, +if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively, +you may create your own target-configuration file for this project and manage it manually. You can +always switch back to automatic target-configuration management by checking the "Manage the project's +target-configuration automatically" checkbox on the project's Properties > General page. \ No newline at end of file diff --git a/pannekoek.zip b/pannekoek.zip new file mode 100644 index 0000000..0502f3d Binary files /dev/null and b/pannekoek.zip differ diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/.ccsproject b/pingpong_5_30.zip_expanded/pingpong_5_30/.ccsproject new file mode 100644 index 0000000..a2394c8 --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/.ccsproject @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/.cproject b/pingpong_5_30.zip_expanded/pingpong_5_30/.cproject new file mode 100644 index 0000000..46b1216 --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/.cproject @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/.gitignore b/pingpong_5_30.zip_expanded/pingpong_5_30/.gitignore new file mode 100644 index 0000000..7c1916f --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/.gitignore @@ -0,0 +1,2 @@ +/MCU+Image/ +/Debug/ diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/.project b/pingpong_5_30.zip_expanded/pingpong_5_30/.project new file mode 100644 index 0000000..da74002 --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/.project @@ -0,0 +1,34 @@ + + + pingpong_5_30 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.ti.ccstudio.core.ccsNature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + Board.html + 1 + COM_TI_SIMPLELINK_CC32XX_SDK_INSTALL_DIR/source/ti/boards/CC3220S_LAUNCHXL/Board.html + + + diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/.settings/org.eclipse.cdt.codan.core.prefs b/pingpong_5_30.zip_expanded/pingpong_5_30/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..98b6350 --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +inEditor=false +onBuild=false diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/.settings/org.eclipse.cdt.debug.core.prefs b/pingpong_5_30.zip_expanded/pingpong_5_30/.settings/org.eclipse.cdt.debug.core.prefs new file mode 100644 index 0000000..58d4fb2 --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/.settings/org.eclipse.cdt.debug.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/.settings/org.eclipse.core.resources.prefs b/pingpong_5_30.zip_expanded/pingpong_5_30/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..7c051cc --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//Debug/makefile=UTF-8 +encoding//Debug/objects.mk=UTF-8 +encoding//Debug/sources.mk=UTF-8 +encoding//Debug/subdir_rules.mk=UTF-8 +encoding//Debug/subdir_vars.mk=UTF-8 diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/cc32xxs_nortos.cmd b/pingpong_5_30.zip_expanded/pingpong_5_30/cc32xxs_nortos.cmd new file mode 100644 index 0000000..4e6d27a --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/cc32xxs_nortos.cmd @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018-2020, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +--stack_size=0x1000 +--heap_size=0x8000 +--entry_point=resetISR +--diag_suppress=10063 /* suppress warning about non _c_int00 entry point */ + +/* + * The starting address of the application. Normally the interrupt vectors + * must be located at the beginning of the application. + */ +#define SRAM_BASE 0x20004000 +#define SRAM2_BASE 0x20000000 + +MEMORY +{ + SRAM (RWX) : origin = 0x20004000, length = 0x00040000 - 0x4000 + SRAM2 (RWX) : origin = 0x20000000, length = 0x4000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : origin = 0x90000000, length = 0x40000 +} + +/* Section allocation in memory */ + +SECTIONS +{ + .text : > SRAM + .TI.ramfunc : > SRAM + .const : > SRAM + .rodata : > SRAM + .cinit : > SRAM + .pinit : > SRAM + .init_array : > SRAM + + .data : > SRAM + .bss : > SRAM + .sysmem : > SRAM + .stack : > SRAM2(HIGH) + + .resetVecs : > SRAM_BASE + .ramVecs : > SRAM2_BASE, type=NOLOAD + + .log_data : > LOG_DATA, type = COPY +} diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/io.c b/pingpong_5_30.zip_expanded/pingpong_5_30/io.c new file mode 100644 index 0000000..e6b3a98 --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/io.c @@ -0,0 +1,206 @@ +// Input/output support functions for pingpong + +#include "io.h" +#include "ti_drivers_config.h" +#include +#include +#include + +// Driver header files +#include +#include +#include +#include + +// tick variable is set to true every sample time. +volatile bool tick = false; +// distance variable contains the measured distance in mm. +volatile int32_t distance; +// Kc variable can be set by typing a float value to the terminal (which is connected to the UART). +//volatile float Kc = 0; + +static Timer_Handle timer1; + +static void gpioButtonFxn0(uint_least8_t index) +{ + int32_t start = Timer_getCount(timer1); // Start time of timer1. + while(GPIO_read(Board_ECHO)); // Wait until ECHO becomes low. Time of pulse equals distance measured. + int32_t stop = Timer_getCount(timer1); // Stop time of timer1. + if (start < stop) + { + distance = (stop - start) / 450; // Calculates distances in mm. + } +} + +void initPort() +{ + GPIO_init(); + GPIO_setConfig(Board_TRIGGER, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH); + GPIO_setConfig(Board_ECHO, GPIO_CFG_IN_PD | GPIO_CFG_IN_INT_RISING); + GPIO_setCallback(Board_ECHO, gpioButtonFxn0); + GPIO_enableInt(Board_ECHO); +} + +static UART_Handle uart; +static char readbuffer[128] = ""; +static volatile bool UART_is_read = false; + +void UART_read_callback(UART_Handle handle, void *buf, size_t count) +{ + float f; + int res = sscanf(buf, "%f", &f); + //if (res == 1) + { + // Kc = f; + } + //sendStringUART("Kc = "); + //sendFloatUART(Kc); + //sendStringUART("Kc = "); + //UART_is_read = true; +} + +bool initUART(void) { + UART_init(); + UART_Params uartParams; + UART_Params_init(&uartParams); + uartParams.writeDataMode = UART_DATA_TEXT; + uartParams.readDataMode = UART_DATA_TEXT; + uartParams.readReturnMode = UART_RETURN_NEWLINE; + uartParams.readEcho = UART_ECHO_ON; + uartParams.readMode = UART_MODE_CALLBACK; + uartParams.baudRate = 115200; + uartParams.readCallback = UART_read_callback; + uart = UART_open(CONFIG_UART_0, &uartParams); + if (uart != NULL) + { + sendStringUART("Kc = "); + UART_read(uart, readbuffer, 128); + } + return uart != NULL; +} + +static void timerTick(Timer_Handle handle, int_fast16_t status) +{ + tick = true; + if (UART_is_read) + { + UART_is_read = false; + UART_read(uart, readbuffer, 128); + } +} + +bool initTimer(uint32_t sampleFrequency) +{ + Timer_init(); + + Timer_Handle timer0; + Timer_Params params; + Timer_Params_init(¶ms); + params.periodUnits = Timer_PERIOD_HZ; + params.period = sampleFrequency; + params.timerMode = Timer_CONTINUOUS_CALLBACK; + params.timerCallback = timerTick; + timer0 = Timer_open(CONFIG_TIMER_0, ¶ms); + if (timer0 == NULL) + { + return false; + } + int32_t status = Timer_start(timer0); + if (status == Timer_STATUS_ERROR) + { + return false; + } + + Timer_Params tparams; + Timer_Params_init(&tparams); //Free running timer for measuring length of the echo pulse. + params.periodUnits = Timer_PERIOD_US; + tparams.period = 0xFFFFFFFF; + tparams.timerMode = Timer_FREE_RUNNING; + timer1 = Timer_open(CONFIG_TIMER_1, &tparams); + if(Timer_start(timer1) == Timer_STATUS_ERROR) + { + return false; + } + return true; +} + +static PWM_Handle pwm0; + +bool initPWM(void) +{ + PWM_Params pwmParams; + + PWM_init(); + + // PWM params init + PWM_Params_init(&pwmParams); + pwmParams.dutyUnits = PWM_DUTY_US; + // PWM duty cycle = 0 + pwmParams.dutyValue = 0; + pwmParams.periodUnits = PWM_PERIOD_US; + // PWM frequency = 1 / 1000 us = 1 / 1 ms = 1 kHz. + pwmParams.periodValue = 1000; + pwmParams.idleLevel = PWM_IDLE_LOW; + + /* Open PWM0 */ + pwm0 = PWM_open(CONFIG_PWM_0, &pwmParams); + + if (!pwm0) + { + return false; + } + PWM_start(pwm0); + return true; +} + +bool setPWM(uint16_t dutyCycle) +{ + if (PWM_setDuty(pwm0, dutyCycle) < 0) + { + return false; + } + return true; +} + +void trigger() +{ + GPIO_write(Board_TRIGGER, 1); + usleep(10); + GPIO_write(Board_TRIGGER, 0); +} + +void sendStringUART(char *s) +{ + UART_writePolling(uart, s, strlen(s)); +} + +void sendIntUART(int i) +{ + char buffer[14]; + int res = sprintf(buffer, "%d\n", i); + if (res > 0) + { + UART_writePolling(uart, buffer, res); + } +} + +void sendIntIntUART(int i1, int i2) +{ + char buffer[28]; + int res = sprintf(buffer, "%d, %d\n", i1, i2); + if (res > 0) + { + UART_writePolling(uart, buffer, res); + } +} + +void sendFloatUART(float f) +{ + char buffer[100]; + int res = sprintf(buffer, "%f\n", f); + if (res > 0) + { + UART_writePolling(uart, buffer, res); + } +} + diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/io.h b/pingpong_5_30.zip_expanded/pingpong_5_30/io.h new file mode 100644 index 0000000..afd7682 --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/io.h @@ -0,0 +1,31 @@ +#ifndef IO_H_ +#define IO_H_ + +// Input/output support functions for pingpong. + +#include +#include + +// tick variable is set to true every sample time. +extern volatile bool tick; +// distance variable contains the measured distance in mm. +extern volatile int32_t distance; +// Kc variable can be set by typing a float value to the terminal (which is connected to the UART). +extern volatile float Kc; + +bool initUART(void); +bool initTimer(uint32_t sampleFrequency); +bool initPWM(void); +void initPort(); + +// setPWM sets dutyCycle in 1000 steps (min = 0, max = 1000) +bool setPWM(uint16_t dutyCycle); +// trigger creates a 10 usec trigger pulse for the ultrasonic sensor. +void trigger(); + +void sendStringUART(char *s); +void sendIntUART(int i); +void sendIntIntUART(int i1, int i2); +void sendFloatUART(float f); + +#endif diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/main_nortos.c b/pingpong_5_30.zip_expanded/pingpong_5_30/main_nortos.c new file mode 100644 index 0000000..96509c3 --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/main_nortos.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017-2020, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ======== main_nortos.c ======== + */ +#include +#include + +#include + +#include + +extern void *mainThread(void *arg0); + +/* + * ======== main ======== + */ +int main(void) +{ + Board_init(); + + /* Start NoRTOS */ + NoRTOS_start(); + + /* Call mainThread function */ + mainThread(NULL); + + while (1) {} +} diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/pingpong.c b/pingpong_5_30.zip_expanded/pingpong_5_30/pingpong.c new file mode 100644 index 0000000..7a1b4fb --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/pingpong.c @@ -0,0 +1,55 @@ +#include "io.h" + +int controller(int dist, int setpoint) +{ + float error = setpoint - dist; + float output = Kc * error; + + if (output > 1000) + { + output = 1000; + } + else if (output < 0) + { + output = 0; + } + return output; +} + +void *mainThread(void *arg0) +{ + if (initUART() == false) + { + // initUart() failed + while(1); + } + // Samplefrequency = 10 Hz + if (initTimer(10) == false) + { + sendStringUART("initTimer() failed"); + while(1); + } + + initPort(); + + if (initPWM() == false) + { + sendStringUART("initPWM() failed"); + while(1); + } + + while(1) + { + trigger(); // Trigger routine creates a 10 usec trigger pulse for the ultrasonic sensor. + int PWM = controller(distance, 800); + setPWM(PWM); + + while (tick == false) + { + // wait for next timer tick + } + tick = false; + } + + return 0; +} diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/pingpong.syscfg b/pingpong_5_30.zip_expanded/pingpong_5_30/pingpong.syscfg new file mode 100644 index 0000000..b33cca7 --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/pingpong.syscfg @@ -0,0 +1,56 @@ +// @cliArgs --board /ti/boards/CC3220S_LAUNCHXL --rtos nortos + +/** + * Import the modules used in this configuration. + */ +const GPIO = scripting.addModule("/ti/drivers/GPIO", {}, false); +const GPIO1 = GPIO.addInstance(); +const GPIO2 = GPIO.addInstance(); +const PWM = scripting.addModule("/ti/drivers/PWM", {}, false); +const PWM1 = PWM.addInstance(); +const RTOS = scripting.addModule("/ti/drivers/RTOS"); +const Timer = scripting.addModule("/ti/drivers/Timer", {}, false); +const Timer1 = Timer.addInstance(); +const Timer2 = Timer.addInstance(); +const UART = scripting.addModule("/ti/drivers/UART", {}, false); +const UART1 = UART.addInstance(); + +/** + * Write custom configuration values to the imported modules. + */ +GPIO1.mode = "Output"; +GPIO1.$name = "Board_TRIGGER"; +GPIO1.gpioPin.$assign = "boosterpack.5"; + +GPIO2.$name = "Board_ECHO"; +GPIO2.gpioPin.$assign = "boosterpack.8"; + +PWM1.$name = "CONFIG_PWM_0"; +PWM1.$hardware = system.deviceData.board.components.LED_GREEN; + +const Power = scripting.addModule("/ti/drivers/Power", {}, true); +Power.parkPins.$name = "ti_drivers_power_PowerCC32XXPins0"; + +RTOS.name = "NoRTOS"; + +Timer1.$name = "CONFIG_TIMER_0"; +Timer1.timerType = "32 Bits"; + +Timer2.$name = "CONFIG_TIMER_1"; +Timer2.timerType = "32 Bits"; + +UART1.$name = "CONFIG_UART_0"; +UART1.$hardware = system.deviceData.board.components.XDS110UART; + +/** + * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future + * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to + * re-solve from scratch. + */ +PWM1.timer.$suggestSolution = "Timer3"; +PWM1.timer.pwmPin.$suggestSolution = "boosterpack.10"; +Timer1.timer.$suggestSolution = "Timer1"; +Timer2.timer.$suggestSolution = "Timer0"; +UART1.uart.$suggestSolution = "UART0"; +UART1.uart.txPin.$suggestSolution = "55"; +UART1.uart.rxPin.$suggestSolution = "57"; diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/targetConfigs/CC3220S.ccxml b/pingpong_5_30.zip_expanded/pingpong_5_30/targetConfigs/CC3220S.ccxml new file mode 100644 index 0000000..ae9589d --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/targetConfigs/CC3220S.ccxml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pingpong_5_30.zip_expanded/pingpong_5_30/targetConfigs/readme.txt b/pingpong_5_30.zip_expanded/pingpong_5_30/targetConfigs/readme.txt new file mode 100644 index 0000000..af97b62 --- /dev/null +++ b/pingpong_5_30.zip_expanded/pingpong_5_30/targetConfigs/readme.txt @@ -0,0 +1,9 @@ +The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based +on the device and connection settings specified in your project on the Properties > General page. + +Please note that in automatic target-configuration management, changes to the project's device and/or +connection settings will either modify an existing or generate a new target-configuration file. Thus, +if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively, +you may create your own target-configuration file for this project and manage it manually. You can +always switch back to automatic target-configuration management by checking the "Manage the project's +target-configuration automatically" checkbox on the project's Properties > General page. \ No newline at end of file diff --git a/pingpong_test/.ccsproject b/pingpong_test/.ccsproject new file mode 100644 index 0000000..a2394c8 --- /dev/null +++ b/pingpong_test/.ccsproject @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/pingpong_test/.cproject b/pingpong_test/.cproject new file mode 100644 index 0000000..8da327c --- /dev/null +++ b/pingpong_test/.cproject @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pingpong_test/.gitignore b/pingpong_test/.gitignore new file mode 100644 index 0000000..7c1916f --- /dev/null +++ b/pingpong_test/.gitignore @@ -0,0 +1,2 @@ +/MCU+Image/ +/Debug/ diff --git a/pingpong_test/.launches/pingpong_5_30.launch b/pingpong_test/.launches/pingpong_5_30.launch new file mode 100644 index 0000000..29003ff --- /dev/null +++ b/pingpong_test/.launches/pingpong_5_30.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/pingpong_test/.launches/pingpong_test.launch b/pingpong_test/.launches/pingpong_test.launch new file mode 100644 index 0000000..0cc899a --- /dev/null +++ b/pingpong_test/.launches/pingpong_test.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/pingpong_test/.project b/pingpong_test/.project new file mode 100644 index 0000000..5793371 --- /dev/null +++ b/pingpong_test/.project @@ -0,0 +1,34 @@ + + + pingpong_test + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.ti.ccstudio.core.ccsNature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + Board.html + 1 + COM_TI_SIMPLELINK_CC32XX_SDK_INSTALL_DIR/source/ti/boards/CC3220S_LAUNCHXL/Board.html + + + diff --git a/pingpong_test/.settings/org.eclipse.cdt.codan.core.prefs b/pingpong_test/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..98b6350 --- /dev/null +++ b/pingpong_test/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +inEditor=false +onBuild=false diff --git a/pingpong_test/.settings/org.eclipse.cdt.debug.core.prefs b/pingpong_test/.settings/org.eclipse.cdt.debug.core.prefs new file mode 100644 index 0000000..58d4fb2 --- /dev/null +++ b/pingpong_test/.settings/org.eclipse.cdt.debug.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker diff --git a/pingpong_test/.settings/org.eclipse.core.resources.prefs b/pingpong_test/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..7c051cc --- /dev/null +++ b/pingpong_test/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//Debug/makefile=UTF-8 +encoding//Debug/objects.mk=UTF-8 +encoding//Debug/sources.mk=UTF-8 +encoding//Debug/subdir_rules.mk=UTF-8 +encoding//Debug/subdir_vars.mk=UTF-8 diff --git a/pingpong_test/cc32xxs_nortos.cmd b/pingpong_test/cc32xxs_nortos.cmd new file mode 100644 index 0000000..4e6d27a --- /dev/null +++ b/pingpong_test/cc32xxs_nortos.cmd @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018-2020, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +--stack_size=0x1000 +--heap_size=0x8000 +--entry_point=resetISR +--diag_suppress=10063 /* suppress warning about non _c_int00 entry point */ + +/* + * The starting address of the application. Normally the interrupt vectors + * must be located at the beginning of the application. + */ +#define SRAM_BASE 0x20004000 +#define SRAM2_BASE 0x20000000 + +MEMORY +{ + SRAM (RWX) : origin = 0x20004000, length = 0x00040000 - 0x4000 + SRAM2 (RWX) : origin = 0x20000000, length = 0x4000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : origin = 0x90000000, length = 0x40000 +} + +/* Section allocation in memory */ + +SECTIONS +{ + .text : > SRAM + .TI.ramfunc : > SRAM + .const : > SRAM + .rodata : > SRAM + .cinit : > SRAM + .pinit : > SRAM + .init_array : > SRAM + + .data : > SRAM + .bss : > SRAM + .sysmem : > SRAM + .stack : > SRAM2(HIGH) + + .resetVecs : > SRAM_BASE + .ramVecs : > SRAM2_BASE, type=NOLOAD + + .log_data : > LOG_DATA, type = COPY +} diff --git a/pingpong_test/io.c b/pingpong_test/io.c new file mode 100644 index 0000000..e6b3a98 --- /dev/null +++ b/pingpong_test/io.c @@ -0,0 +1,206 @@ +// Input/output support functions for pingpong + +#include "io.h" +#include "ti_drivers_config.h" +#include +#include +#include + +// Driver header files +#include +#include +#include +#include + +// tick variable is set to true every sample time. +volatile bool tick = false; +// distance variable contains the measured distance in mm. +volatile int32_t distance; +// Kc variable can be set by typing a float value to the terminal (which is connected to the UART). +//volatile float Kc = 0; + +static Timer_Handle timer1; + +static void gpioButtonFxn0(uint_least8_t index) +{ + int32_t start = Timer_getCount(timer1); // Start time of timer1. + while(GPIO_read(Board_ECHO)); // Wait until ECHO becomes low. Time of pulse equals distance measured. + int32_t stop = Timer_getCount(timer1); // Stop time of timer1. + if (start < stop) + { + distance = (stop - start) / 450; // Calculates distances in mm. + } +} + +void initPort() +{ + GPIO_init(); + GPIO_setConfig(Board_TRIGGER, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH); + GPIO_setConfig(Board_ECHO, GPIO_CFG_IN_PD | GPIO_CFG_IN_INT_RISING); + GPIO_setCallback(Board_ECHO, gpioButtonFxn0); + GPIO_enableInt(Board_ECHO); +} + +static UART_Handle uart; +static char readbuffer[128] = ""; +static volatile bool UART_is_read = false; + +void UART_read_callback(UART_Handle handle, void *buf, size_t count) +{ + float f; + int res = sscanf(buf, "%f", &f); + //if (res == 1) + { + // Kc = f; + } + //sendStringUART("Kc = "); + //sendFloatUART(Kc); + //sendStringUART("Kc = "); + //UART_is_read = true; +} + +bool initUART(void) { + UART_init(); + UART_Params uartParams; + UART_Params_init(&uartParams); + uartParams.writeDataMode = UART_DATA_TEXT; + uartParams.readDataMode = UART_DATA_TEXT; + uartParams.readReturnMode = UART_RETURN_NEWLINE; + uartParams.readEcho = UART_ECHO_ON; + uartParams.readMode = UART_MODE_CALLBACK; + uartParams.baudRate = 115200; + uartParams.readCallback = UART_read_callback; + uart = UART_open(CONFIG_UART_0, &uartParams); + if (uart != NULL) + { + sendStringUART("Kc = "); + UART_read(uart, readbuffer, 128); + } + return uart != NULL; +} + +static void timerTick(Timer_Handle handle, int_fast16_t status) +{ + tick = true; + if (UART_is_read) + { + UART_is_read = false; + UART_read(uart, readbuffer, 128); + } +} + +bool initTimer(uint32_t sampleFrequency) +{ + Timer_init(); + + Timer_Handle timer0; + Timer_Params params; + Timer_Params_init(¶ms); + params.periodUnits = Timer_PERIOD_HZ; + params.period = sampleFrequency; + params.timerMode = Timer_CONTINUOUS_CALLBACK; + params.timerCallback = timerTick; + timer0 = Timer_open(CONFIG_TIMER_0, ¶ms); + if (timer0 == NULL) + { + return false; + } + int32_t status = Timer_start(timer0); + if (status == Timer_STATUS_ERROR) + { + return false; + } + + Timer_Params tparams; + Timer_Params_init(&tparams); //Free running timer for measuring length of the echo pulse. + params.periodUnits = Timer_PERIOD_US; + tparams.period = 0xFFFFFFFF; + tparams.timerMode = Timer_FREE_RUNNING; + timer1 = Timer_open(CONFIG_TIMER_1, &tparams); + if(Timer_start(timer1) == Timer_STATUS_ERROR) + { + return false; + } + return true; +} + +static PWM_Handle pwm0; + +bool initPWM(void) +{ + PWM_Params pwmParams; + + PWM_init(); + + // PWM params init + PWM_Params_init(&pwmParams); + pwmParams.dutyUnits = PWM_DUTY_US; + // PWM duty cycle = 0 + pwmParams.dutyValue = 0; + pwmParams.periodUnits = PWM_PERIOD_US; + // PWM frequency = 1 / 1000 us = 1 / 1 ms = 1 kHz. + pwmParams.periodValue = 1000; + pwmParams.idleLevel = PWM_IDLE_LOW; + + /* Open PWM0 */ + pwm0 = PWM_open(CONFIG_PWM_0, &pwmParams); + + if (!pwm0) + { + return false; + } + PWM_start(pwm0); + return true; +} + +bool setPWM(uint16_t dutyCycle) +{ + if (PWM_setDuty(pwm0, dutyCycle) < 0) + { + return false; + } + return true; +} + +void trigger() +{ + GPIO_write(Board_TRIGGER, 1); + usleep(10); + GPIO_write(Board_TRIGGER, 0); +} + +void sendStringUART(char *s) +{ + UART_writePolling(uart, s, strlen(s)); +} + +void sendIntUART(int i) +{ + char buffer[14]; + int res = sprintf(buffer, "%d\n", i); + if (res > 0) + { + UART_writePolling(uart, buffer, res); + } +} + +void sendIntIntUART(int i1, int i2) +{ + char buffer[28]; + int res = sprintf(buffer, "%d, %d\n", i1, i2); + if (res > 0) + { + UART_writePolling(uart, buffer, res); + } +} + +void sendFloatUART(float f) +{ + char buffer[100]; + int res = sprintf(buffer, "%f\n", f); + if (res > 0) + { + UART_writePolling(uart, buffer, res); + } +} + diff --git a/pingpong_test/io.h b/pingpong_test/io.h new file mode 100644 index 0000000..5cfb29f --- /dev/null +++ b/pingpong_test/io.h @@ -0,0 +1,31 @@ +#ifndef IO_H_ +#define IO_H_ + +// Input/output support functions for pingpong. + +#include +#include + +// tick variable is set to true every sample time. +extern volatile bool tick; +// distance variable contains the measured distance in mm. +extern volatile int32_t distance; +// Kc variable can be set by typing a float value to the terminal (which is connected to the UART). +//extern volatile float Kc; + +bool initUART(void); +bool initTimer(uint32_t sampleFrequency); +bool initPWM(void); +void initPort(); + +// setPWM sets dutyCycle in 1000 steps (min = 0, max = 1000) +bool setPWM(uint16_t dutyCycle); +// trigger creates a 10 usec trigger pulse for the ultrasonic sensor. +void trigger(); + +void sendStringUART(char *s); +void sendIntUART(int i); +void sendIntIntUART(int i1, int i2); +void sendFloatUART(float f); + +#endif diff --git a/pingpong_test/main_nortos.c b/pingpong_test/main_nortos.c new file mode 100644 index 0000000..ee8b416 --- /dev/null +++ b/pingpong_test/main_nortos.c @@ -0,0 +1,28 @@ + +/* + * ======== main_nortos.c ======== + */ +#include +#include + +#include + +#include + +extern void *mainThread(void *arg0); + +/* + * ======== main ======== + */ +int main(void) +{ + Board_init(); + + /* Start NoRTOS */ + NoRTOS_start(); + + /* Call mainThread function */ + mainThread(NULL); + + while (1) {} +} diff --git a/pingpong_test/pingpong.c b/pingpong_test/pingpong.c new file mode 100644 index 0000000..c4425d8 --- /dev/null +++ b/pingpong_test/pingpong.c @@ -0,0 +1,98 @@ +#include "io.h" + +#define Ts 0.1 + +//float Kc = 1.0; +#define Ku 0.9 +#define Tu 2.8 + +#define Kc 1.2//1//Ku/2.2 //=4.1 +#define Ti 3//3//(2.2*Tu) +#define Td 0.5//0.5//(Tu/6.3) + +const float p1 = (Kc*Ts)/Ti; +const float q1 = -Kc - (3*Kc*Td)/(2*Ts); +const float q2 = Kc + (7*Kc*Td)/(2*Ts); +const float q3 = -(5*Kc*Td)/(2*Ts); +const float q4 = (Kc*Td)/(2*Ts); + +float y[4] = {0, 0, 0, 0}; +float n = 0.0; + +int controller(int dist, int r) +{ + int i; + for (i=3; i>0; i--) + { + y[i] = y[i-1]; + } + y[0] = dist; + + n = n + p1 * ( r - y[1] ) + q1 * y[0] + q2 * y[1] + q3 * y[2] + q4 * y[3]; + //n = Kc * ( r - y[0] ); + + if (n > 1000) + { + n = 1000; + } + else if (n < 0) + { + n = 0; + } + return (int)(n+0.5); +} + +void *mainThread(void *arg0) +{ + if (initUART() == false) + { + // initUart() failed + while(1); + } + // Samplefrequency = 10 Hz + if (initTimer(10) == false) + { + sendStringUART("initTimer() failed"); + while(1); + } + + initPort(); + + if (initPWM() == false) + { + sendStringUART("initPWM() failed"); + while(1); + } + + int i = 0, ii = -5, t = 300; + uint32_t sp = 0; + int PWM = 0; + char ploep[100]; + + //Kc = 2; + + setPWM(0); + while(1) + { + trigger(); // Trigger routine creates a 10 usec trigger pulse for the ultrasonic sensor. + PWM = controller(distance, sp); + if(i < 30) + { + setPWM(0); + } + else + { + sp = 400; + setPWM(PWM); + } + + sprintf(&ploep, "%d,%d,%d,%i\n", i, distance, sp, PWM); + sendStringUART(ploep); + + i++; + while(tick == false){} + tick = false; + } + + return 0; +} diff --git a/pingpong_test/pingpong.syscfg b/pingpong_test/pingpong.syscfg new file mode 100644 index 0000000..b33cca7 --- /dev/null +++ b/pingpong_test/pingpong.syscfg @@ -0,0 +1,56 @@ +// @cliArgs --board /ti/boards/CC3220S_LAUNCHXL --rtos nortos + +/** + * Import the modules used in this configuration. + */ +const GPIO = scripting.addModule("/ti/drivers/GPIO", {}, false); +const GPIO1 = GPIO.addInstance(); +const GPIO2 = GPIO.addInstance(); +const PWM = scripting.addModule("/ti/drivers/PWM", {}, false); +const PWM1 = PWM.addInstance(); +const RTOS = scripting.addModule("/ti/drivers/RTOS"); +const Timer = scripting.addModule("/ti/drivers/Timer", {}, false); +const Timer1 = Timer.addInstance(); +const Timer2 = Timer.addInstance(); +const UART = scripting.addModule("/ti/drivers/UART", {}, false); +const UART1 = UART.addInstance(); + +/** + * Write custom configuration values to the imported modules. + */ +GPIO1.mode = "Output"; +GPIO1.$name = "Board_TRIGGER"; +GPIO1.gpioPin.$assign = "boosterpack.5"; + +GPIO2.$name = "Board_ECHO"; +GPIO2.gpioPin.$assign = "boosterpack.8"; + +PWM1.$name = "CONFIG_PWM_0"; +PWM1.$hardware = system.deviceData.board.components.LED_GREEN; + +const Power = scripting.addModule("/ti/drivers/Power", {}, true); +Power.parkPins.$name = "ti_drivers_power_PowerCC32XXPins0"; + +RTOS.name = "NoRTOS"; + +Timer1.$name = "CONFIG_TIMER_0"; +Timer1.timerType = "32 Bits"; + +Timer2.$name = "CONFIG_TIMER_1"; +Timer2.timerType = "32 Bits"; + +UART1.$name = "CONFIG_UART_0"; +UART1.$hardware = system.deviceData.board.components.XDS110UART; + +/** + * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future + * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to + * re-solve from scratch. + */ +PWM1.timer.$suggestSolution = "Timer3"; +PWM1.timer.pwmPin.$suggestSolution = "boosterpack.10"; +Timer1.timer.$suggestSolution = "Timer1"; +Timer2.timer.$suggestSolution = "Timer0"; +UART1.uart.$suggestSolution = "UART0"; +UART1.uart.txPin.$suggestSolution = "55"; +UART1.uart.rxPin.$suggestSolution = "57"; diff --git a/pingpong_test/targetConfigs/CC3220S.ccxml b/pingpong_test/targetConfigs/CC3220S.ccxml new file mode 100644 index 0000000..e643caa --- /dev/null +++ b/pingpong_test/targetConfigs/CC3220S.ccxml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pingpong_test/targetConfigs/readme.txt b/pingpong_test/targetConfigs/readme.txt new file mode 100644 index 0000000..af97b62 --- /dev/null +++ b/pingpong_test/targetConfigs/readme.txt @@ -0,0 +1,9 @@ +The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based +on the device and connection settings specified in your project on the Properties > General page. + +Please note that in automatic target-configuration management, changes to the project's device and/or +connection settings will either modify an existing or generate a new target-configuration file. Thus, +if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively, +you may create your own target-configuration file for this project and manage it manually. You can +always switch back to automatic target-configuration management by checking the "Manage the project's +target-configuration automatically" checkbox on the project's Properties > General page. \ No newline at end of file