Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP!: -Create a new CCS project Lab6_2. -Use the Ping-Pong buffering technique to implement the same signal pass-through functionality as in Lab6_1.Triple buffering technique

PLEASE HELP!:

-Create a new CCS project Lab6_2. -Use the Ping-Pong buffering technique to implement the same signal pass-through functionality as in Lab6_1.Triple buffering technique was used in Lab6_1, which is different from the Ping-Pong buffering. Ping-Pong buffering is explained in class and briefly summarized in the lecture notes. -Explain in your report how the Ping-Pong buffering technique works. HERE IS THE CODE LAB6_1: #include  // Variable definitions for the C99 standard. #include  // Boolean definitions for the C99 standard. #include "inc/tm4c123gh6pm.h" // Definitions for the interrupt and register assignments. #include "inc/hw_memmap.h" // Memory map definitions of the Tiva C Series device. #include "inc/hw_types.h" // Definitions of common types and macros. #include "inc/hw_ssi.h" #include "driverlib/sysctl.h" // Definitions and macros for System Control API of DriverLib. #include "driverlib/interrupt.h" // Defines and macros for NVIC Controller API of DriverLib. #include "driverlib/gpio.h" // Definitions and macros for GPIO API of DriverLib. #include "driverlib/timer.h" // Defines and macros for Timer API of DriverLib. #include "driverlib/pin_map.h" //Mapping of peripherals to pins for all parts. #include "driverlib/uart.h" // Definitions and macros for UART API of DriverLib. #include "driverlib/ssi.h" // Prototypes for the SSI/SPI routines. #include "driverlib/adc.h" // Definitions for ADC API of DriverLib. #include "utils/uartstdio.h" // Prototypes for the UART console functions. // Needs to add "utils/uartstdio.c" through a relative link. #define TIMER0_FREQ 2 // Freqency in Hz, heartbeat timer #define RED_LED GPIO_PIN_1 #define BLUE_LED GPIO_PIN_2 #define GREEN_LED GPIO_PIN_3 #define UART0_BAUDRATE 115200 // UART baudrate in bps #define NUM_DISP_TEXT_LINE 4 #define SAMP_FREQ 44100 // Frequency in Hz, common sampling rates for digital audio: 44100, 48000 #define ADC0_SEQ_NUM 0 // ADC Sample Sequence Number #define SPI_BITRATE 15000000 // needs to > SAMP_FREQ*16, and < SysCtrlClock/2, max 20M #define SPI_DATA_MASK 0x0FFF // See datasheet, MCP4921 #define SPI_CTRL_MASK 0x7000 // See datasheet, MCP4921 // Definitions for triple buffering. #define NUM_BUFFER 3 #define BUFFER_LEN 100 // function prototypes void init_LEDs(void); void init_timer(void); void init_UART(void); void init_SPI(void); void init_ADC(void); void init_buffer(void); void process_data(void); void Timer0_ISR(void); void Timer1_ISR(void); extern void UARTStdioIntHandler(void); // global variables uint8_t cur_LED = RED_LED; const char *disp_text[NUM_DISP_TEXT_LINE] = { " ", "UART and LED Demo ", "H: help, R: red, G: green, B: blue. ", "> " }; uint32_t sys_clock; volatile uint32_t triple_buffer[NUM_BUFFER][BUFFER_LEN]; volatile uint32_t input_index=0, output_index=1, data_index=2; volatile bool data_ready=false, buffer_overrun=false; int main(void) { uint32_t i; unsigned char user_cmd; // Configure system clock. //SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // 50 MHz //SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // 40 MHz //sys_clock = SysCtlClockGet(); SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // 80 MHz sys_clock = 80000000; // Hard-coded for 80MHz because of a bug in SysCtlClockGet(). init_LEDs(); init_ADC(); init_UART(); init_timer(); init_SPI(); init_buffer(); // Enable the processor to respond to interrupts. IntMasterEnable(); // Start the timer by enabling operation of the timer module. TimerEnable(TIMER0_BASE, TIMER_A); TimerEnable(TIMER1_BASE, TIMER_A); // Initial display on terminal. for(i=0; i "); break; case 'B': case 'b': cur_LED = BLUE_LED; UARTprintf(" > "); break; case 'G': case 'g': cur_LED = GREEN_LED; UARTprintf(" > "); break; } if(buffer_overrun) { // This error indicates the process_data() routine takes too much time to complete. // Optimize this routine to run faster or set the BUFFER_LEN larger. UARTprintf(" Error: buffer overrun! "); buffer_overrun = false; } // SysCtlDelay(100000); // Un-comment this line to generate buffer_overrun error. if(data_ready) { process_data(); data_ready = false; } } } void init_LEDs(void) { // Enable and configure LED peripheral. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable GPIO Port F. // Three onboard LEDs, R:PF1, B:PF2, G:PF3. GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); } void init_timer(void) { // Enable and configure Timer0 peripheral. SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // Configure as a 32-bit timer in periodic mode. TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); // Initialize timer load register. TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1); // Registers a function to be called when the interrupt occurs. IntRegister(INT_TIMER0A, Timer0_ISR); // The specified interrupt is enabled in the interrupt controller. IntEnable(INT_TIMER0A); // Enable the indicated timer interrupt source. TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // Enable and configure Timer1 peripheral. SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); // Configure as a 32-bit timer in periodic mode. TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); // Initialize timer load register. TimerLoadSet(TIMER1_BASE, TIMER_A, sys_clock/SAMP_FREQ -1); // Registers a function to be called when the interrupt occurs. IntRegister(INT_TIMER1A, Timer1_ISR); // The specified interrupt is enabled in the interrupt controller. IntEnable(INT_TIMER1A); // Enable the indicated timer interrupt source. TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); } void init_UART(void) { // Enable and configure UART0 for debugging printouts. SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // Registers a function to be called when the interrupt occurs. IntRegister(INT_UART0, UARTStdioIntHandler); UARTStdioConfig(0, UART0_BAUDRATE, sys_clock); } void init_SPI(void) { // Enable peripheral for SSI/SPI. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); // Configure the muxing and GPIO settings to bring the SSI functions out to the pins GPIOPinConfigure(GPIO_PA2_SSI0CLK); GPIOPinConfigure(GPIO_PA3_SSI0FSS); GPIOPinConfigure(GPIO_PA5_SSI0TX); GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_5); SSIConfigSetExpClk(SSI0_BASE, sys_clock, SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, SPI_BITRATE, 16); SSIEnable(SSI0_BASE); } void init_ADC(void) { // Enable and configure ADC0. Sample from PD0/AIN7/BY SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0); ADCSequenceConfigure(ADC0_BASE, ADC0_SEQ_NUM, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, ADC0_SEQ_NUM, 0, ADC_CTL_IE|ADC_CTL_CH7|ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, ADC0_SEQ_NUM); } void init_buffer(void) { uint32_t i, j; for(i=0; i= BUFFER_LEN) { sample_index = 0; if(data_ready) buffer_overrun = true; tmp_ui32 = input_index; input_index = output_index; output_index = data_index; data_index = tmp_ui32; data_ready = true; } } // Timer0 interrupt service routine void Timer0_ISR(void) { // Clear the timer interrupt. TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // Blink LED. Read the current state of GPIO pins and write back the opposite state. if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3)) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); } else { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, cur_LED); } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions

Question

c. What were the reasons for their move? Did they come voluntarily?

Answered: 1 week ago

Question

5. How do economic situations affect intergroup relations?

Answered: 1 week ago