Link to the old thread:
Hello,
here is my concept.
The function convertStreamDataxxxxx is an exact precalculation for a number of 161 pixels per strip and for four strips.
But I have problems at the moment when I start the timers and when I stop the timers.
Here are the start and stop times:
Any ideas to fix this ?
/* * ==================================================================== * * MIT License * * Copyright (c) [2022] * [Jan Grossniklaus, Jan Kunert, Sascha Hildebrands, Kevin Hinrichs] * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * urnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall * be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * ==================================================================== */ /* + -------------------------------------------------------------------- + + Created : 18/04/2022 + Owner : Kevin Hinrichs + + Description: Musik spectrum analyzer make cool effects + on a LED stripe Matrix to music. + + -------------------------------------------------------------------- */ #define EXTERN #include <stdint.h> #include <stdbool.h> #include <stdio.h> #include <arm_math.h> #include "project.h" // global header file #include "tm4c123gxl_init.h" #include "ws2812b.h" #include "inc/hw_memmap.h" #include "driverlib/gpio.h" //********************************************************************* // // Info // Version: RC 2.01 // SRAM: // 2.048 Bytes SRAM --> system stack // 1.024 Bytes SRAM --> uDMA control table // 12.481 Bytes SRAM --> led driver // ----------------- // 15.523 Bytes SRAM // //********************************************************************* //********************************************************************* // // Hardware SETUP // // LED DATA SIGNAL 1: PB6 // LED DATA SIGNAL 2: PB4 // LED DATA SIGNAL 3: PB0 // LED DATA SIGNAL 4: PB2 // // Need to be bridged: PB7 <---> PA7 // Need to be bridged: PB5 <---> PC7 // Need to be bridged: PB1 <---> PD3 // Need to be bridged: PB3 <---> PF2 // //********************************************************************* //********************************************************************* // // MAIN // //********************************************************************* void main() { //***************************************************************** // // Locale Variable // //***************************************************************** static streamDataDataTyp streamData; // 12.481 Bytes SRAM //***************************************************************** // // Hardware Main Setup // //***************************************************************** init_hardware(); //***************************************************************** // // Debug Mode // //***************************************************************** #ifndef DEBUG_OFF init_GPIO_DEBUG(); // reset all debug pins DEBUG_PA2 = 0; DEBUG_PA3 = 0; DEBUG_PA4 = 0; DEBUG_PA5 = 0; DEBUG_PA6 = 0; DEBUG_PC4 = 0; DEBUG_PC5 = 0; DEBUG_PC6 = 0; DEBUG_PE0 = 0; DEBUG_PE1 = 0; DEBUG_PE2 = 0; DEBUG_PE3 = 0; DEBUG_PE4 = 0; DEBUG_PE5 = 0; DEBUG_PF0 = 0; DEBUG_PF1 = 0; DEBUG_PF3 = 0; DEBUG_PF4 = 0; // // ***LA2016 - LED-Signal*** // // DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv // DEBUG_PA5 = GPIO_PIN_5; // CH03 Pri // DEBUG_PA6 = GPIO_PIN_6; // CH04 Alt // DEBUG_PC4 = GPIO_PIN_4; // CH05 Color // DEBUG_PC5 = GPIO_PIN_5; // CH06 DMAP // DEBUG_PC6 = GPIO_PIN_6; // CH07 DMAA // PB6 -> CH08 // LED1 // PB4 -> CH09 // LED2 // PB0 -> CH10 // LED3 // PB2 -> CH11 // LED4 // PB7 -> CH12 // DMA1 // PB5 -> CH13 // DMA2 // PB1 -> CH14 // DMA3 // PB3 -> CH15 // DMA4 // // ***LA5016 - DSP*** // // DEBUG_PE0 = GPIO_PIN_0; // CH02 Pri // DEBUG_PE1 = GPIO_PIN_1; // CH03 Alt // DEBUG_PE2 = GPIO_PIN_2; // CH04 Mic // DEBUG_PE3 = GPIO_PIN_3; // CH05 DMA P // DEBUG_PE4 = GPIO_PIN_4; // CH06 DMA A // DEBUG_PE5 = GPIO_PIN_5; // CH07 AGC // DEBUG_PF0 = GPIO_PIN_0; // CH08 FFT // DEBUG_PF1 = GPIO_PIN_1; // CH09 FBand // DEBUG_PF3 = GPIO_PIN_3; // CH10 // DEBUG_PF4 = GPIO_PIN_4; // CH11 // CH12 // CH13 // CH14 // CH15 // // ***LA2016 / LA5016*** // // DEBUG_PA2 = GPIO_PIN_2; // CH00 Start LED // DEBUG_PA3 = GPIO_PIN_3; // CH01 Start Rec #endif streamData.sendLedData = 1; // switch all leds with full white for (int i = 0; i < 464; i++) { streamData.pixelData[i][0] = 255; streamData.pixelData[i][1] = 255; streamData.pixelData[i][2] = 255; } while (1) { if (streamData.sendLedData) { if (sendLED(&streamData)) { streamData.sendLedData--; } } } }
/* * ==================================================================== * * MIT License * * Copyright (c) [2022] * [Jan Grossniklaus, Jan Kunert, Sascha Hildebrands, Kevin Hinrichs] * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * urnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall * be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * ==================================================================== */ /* + -------------------------------------------------------------------- + + Created : 13/03/2022 + Owner : Kevin Hinrichs + + Description: Hardware setup for Texas Instruments EK-TM4C123GXL + TM4C123G LaunchPad Evaluation Kit. + + -------------------------------------------------------------------- */ #include <stdint.h> #include <stdbool.h> #include <stdio.h> #include <arm_math.h> #include "project.h" // global header file #include "tm4c123gxl_init.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "driverlib/sysctl.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/rom.h" #include "driverlib/rom_map.h" #include "driverlib/interrupt.h" #include "driverlib/timer.h" #include "driverlib/udma.h" //********************************************************************* // // The error routine that is called if the driver library error. // //********************************************************************* #ifdef DEBUG void __error__(char *pcFilename, uint32_t ui32Line) { } #endif //********************************************************************* // // Interrupts Handler // //********************************************************************* void uDMAErrorIntHandler(void) { #ifndef DEBUG_OFF MAP_uDMAErrorStatusClear(); uDMAErrorHandlerCounter++; #endif } //********************************************************************* // // Functions // //********************************************************************* void init_SYS_CLOCK() { // 80Mhz Clock MAP_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); MAP_SysCtlDelay(10); } void init_FPU() { MAP_FPUEnable(); MAP_FPULazyStackingEnable(); MAP_SysCtlDelay(10); } void init_GPIO_CLOCK_A() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA)); } void init_GPIO_CLOCK_B() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB)); } void init_GPIO_CLOCK_C() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOC)); } void init_GPIO_CLOCK_D() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD)); } void init_GPIO_CLOCK_E() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE)); } void init_GPIO_CLOCK_F() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF)); } void init_uDMA_TRIGGER_0() { // GPIO TIGGER 0: PA7 MAP_GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIODMATriggerEnable(GPIO_PORTA_BASE, GPIO_PIN_7); MAP_GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_FALLING_EDGE); MAP_GPIOIntEnable(GPIO_PORTA_BASE, GPIO_INT_DMA); // ------------------ // // Priority Levels // Priority 4 = 0xE0 ->lower // Priority 3 = 0x60 // Priority 2 = 0x20 // Priority 1 = 0x00 ->higher // ------------------ // MAP_IntPrioritySet(INT_GPIOA, 0x00); // Priority 1 !!! MAP_IntEnable(INT_GPIOA); } void init_uDMA_TRIGGER_1() { // GPIO TIGGER C: PC7 MAP_GPIODirModeSet(GPIO_PORTC_BASE, GPIO_PIN_7, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIODMATriggerEnable(GPIO_PORTC_BASE, GPIO_PIN_7); MAP_GPIOIntTypeSet(GPIO_PORTC_BASE, GPIO_PIN_7, GPIO_FALLING_EDGE); MAP_GPIOIntEnable(GPIO_PORTC_BASE, GPIO_INT_DMA); // ------------------ // // Priority Levels // Priority 4 = 0xE0 ->lower // Priority 3 = 0x60 // Priority 2 = 0x20 // Priority 1 = 0x00 ->higher // ------------------ // MAP_IntPrioritySet(INT_GPIOC, 0x00); // Priority 1 !!! MAP_IntEnable(INT_GPIOC); } void init_uDMA_TRIGGER_2() { // GPIO TIGGER D: PD3 MAP_GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIODMATriggerEnable(GPIO_PORTD_BASE, GPIO_PIN_3); MAP_GPIOIntTypeSet(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_FALLING_EDGE); MAP_GPIOIntEnable(GPIO_PORTD_BASE, GPIO_INT_DMA); // ------------------ // // Priority Levels // Priority 4 = 0xE0 ->lower // Priority 3 = 0x60 // Priority 2 = 0x20 // Priority 1 = 0x00 ->higher // ------------------ // MAP_IntPrioritySet(INT_GPIOD, 0x00); // Priority 1 !!! MAP_IntEnable(INT_GPIOD); } void init_uDMA_TRIGGER_3() { // GPIO TIGGER E: PF2 MAP_GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIODMATriggerEnable(GPIO_PORTF_BASE, GPIO_PIN_2); MAP_GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE); MAP_GPIOIntEnable(GPIO_PORTF_BASE, GPIO_INT_DMA); // ------------------ // // Priority Levels // Priority 4 = 0xE0 ->lower // Priority 3 = 0x60 // Priority 2 = 0x20 // Priority 1 = 0x00 ->higher // ------------------ // MAP_IntPrioritySet(INT_GPIOF, 0x00); // Priority 1 !!! MAP_IntEnable(INT_GPIOF); } void init_TIMER_0() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0)); // Timer 0A is the data signal 1: PB6 // Timer 0B is the udma trigger signal to GPIO: PB7 MAP_GPIOPinConfigure(GPIO_PB6_T0CCP0); MAP_GPIOPinConfigure(GPIO_PB7_T0CCP1); MAP_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6); MAP_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_7); MAP_TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PWM); MAP_TimerLoadSet(TIMER0_BASE, TIMER_BOTH, (SysCtlClockGet()/SIGNAL_FREQUENZ) - 1); // start led signal with the reset signal MAP_TimerMatchSet(TIMER0_BASE, TIMER_A, SIGNAL_RESET); // DMA Request MAP_TimerMatchSet(TIMER0_BASE, TIMER_B, SIGNAL_DMA); } void init_TIMER_1() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER1)); // Timer 1A is the data signal 2: PB4 // Timer 1B is the udma trigger signal to GPIO: PB5 MAP_GPIOPinConfigure(GPIO_PB4_T1CCP0); MAP_GPIOPinConfigure(GPIO_PB5_T1CCP1); MAP_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_4); MAP_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_5); MAP_TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PWM); MAP_TimerLoadSet(TIMER1_BASE, TIMER_BOTH, (SysCtlClockGet()/SIGNAL_FREQUENZ) - 1); // start led signal with the reset signal MAP_TimerMatchSet(TIMER1_BASE, TIMER_A, SIGNAL_RESET); // DMA Request MAP_TimerMatchSet(TIMER1_BASE, TIMER_B, SIGNAL_DMA); } void init_TIMER_2() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER2)); // Timer 2A is the data signal 3: PB0 // Timer 2B is the udma trigger signal to GPIO: PB1 MAP_GPIOPinConfigure(GPIO_PB0_T2CCP0); MAP_GPIOPinConfigure(GPIO_PB1_T2CCP1); MAP_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0); MAP_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_1); MAP_TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PWM); MAP_TimerLoadSet(TIMER2_BASE, TIMER_BOTH, (SysCtlClockGet()/SIGNAL_FREQUENZ) - 1); // start led signal with the reset signal MAP_TimerMatchSet(TIMER2_BASE, TIMER_A, SIGNAL_RESET); // DMA Request MAP_TimerMatchSet(TIMER2_BASE, TIMER_B, SIGNAL_DMA); } void init_TIMER_3() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER3)); // Timer 3A is the data signal 4: PB2 // Timer 3B is the udma trigger signal to GPIO: PB3 // special setup because GPIO is locked and preconfigured MAP_GPIOUnlockPin(GPIO_PORTB_BASE, GPIO_PIN_2); MAP_GPIOUnlockPin(GPIO_PORTB_BASE, GPIO_PIN_3); MAP_GPIOPinConfigure(GPIO_PB2_T3CCP0); MAP_GPIOPinConfigure(GPIO_PB3_T3CCP1); MAP_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2); MAP_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_3); MAP_TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PWM); MAP_TimerLoadSet(TIMER3_BASE, TIMER_BOTH, (SysCtlClockGet()/SIGNAL_FREQUENZ) - 1); // start led signal with the reset signal MAP_TimerMatchSet(TIMER3_BASE, TIMER_A, SIGNAL_RESET); // DMA Request MAP_TimerMatchSet(TIMER3_BASE, TIMER_B, SIGNAL_DMA); } void init_WTIMER_5() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER5); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_WTIMER5)); // WTimer 5A is PD6 and the trigger for adc // WTimer 5B is PD7 and the timer for led reset time MAP_TimerConfigure(WTIMER5_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_A_ONE_SHOT); // WTimer 5B // set ADC sampling frequency MAP_TimerLoadSet(WTIMER5_BASE, TIMER_B, (SysCtlClockGet()/SIGNAL_RESET_FREQUENZ) - 1); // WTimer 5B // enable timer done interrupt TimerIntEnable(WTIMER5_BASE, TIMER_TIMB_TIMEOUT); IntEnable(INT_WTIMER5B); } void init_uDMA() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_UDMA)); // general uDMA setup MAP_uDMAEnable(); MAP_SysCtlDelay(10); // declare controltable MAP_uDMAControlBaseSet(uDMAControlTable); MAP_SysCtlDelay(10); #ifndef DEBUG_OFF MAP_IntEnable(INT_UDMAERR); #endif } void init_uDMA_LED0() { // signal 0 // uDMA Channel 4 MAP_uDMAChannelAssign(UDMA_CH4_GPIOA); MAP_uDMAChannelAttributeDisable(4, UDMA_ATTR_ALTSELECT | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK | UDMA_ATTR_USEBURST); MAP_uDMAChannelControlSet(4 | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_16 | UDMA_DST_INC_NONE | UDMA_ARB_1); MAP_uDMAChannelControlSet(4 | UDMA_ALT_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_16 | UDMA_DST_INC_NONE | UDMA_ARB_1); //MAP_uDMAChannelAttributeEnable(4, UDMA_ATTR_HIGH_PRIORITY); } void init_uDMA_LED1() { // signal 1 // uDMA Channel 6 MAP_uDMAChannelAssign(UDMA_CH6_GPIOC); MAP_uDMAChannelAttributeDisable(6, UDMA_ATTR_ALTSELECT | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK | UDMA_ATTR_USEBURST); MAP_uDMAChannelControlSet(6 | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_16 | UDMA_DST_INC_NONE | UDMA_ARB_1); MAP_uDMAChannelControlSet(6 | UDMA_ALT_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_16 | UDMA_DST_INC_NONE | UDMA_ARB_1); //MAP_uDMAChannelAttributeEnable(6, UDMA_ATTR_HIGH_PRIORITY); } void init_uDMA_LED2() { // signal 2 // uDMA Channel 7 MAP_uDMAChannelAssign(UDMA_CH7_GPIOD); MAP_uDMAChannelAttributeDisable(7, UDMA_ATTR_ALTSELECT | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK | UDMA_ATTR_USEBURST); MAP_uDMAChannelControlSet(7 | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_16 | UDMA_DST_INC_NONE | UDMA_ARB_1); MAP_uDMAChannelControlSet(7 | UDMA_ALT_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_16 | UDMA_DST_INC_NONE | UDMA_ARB_1); //MAP_uDMAChannelAttributeEnable(7, UDMA_ATTR_HIGH_PRIORITY); } void init_uDMA_LED3() { // signal 3 // uDMA Channel 15 MAP_uDMAChannelAssign(UDMA_CH15_GPIOF); MAP_uDMAChannelAttributeDisable(15, UDMA_ATTR_ALTSELECT | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK | UDMA_ATTR_USEBURST); MAP_uDMAChannelControlSet(15 | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_16 | UDMA_DST_INC_NONE | UDMA_ARB_1); MAP_uDMAChannelControlSet(15 | UDMA_ALT_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_16 | UDMA_DST_INC_NONE | UDMA_ARB_1); //MAP_uDMAChannelAttributeEnable(15, UDMA_ATTR_HIGH_PRIORITY); } void init_GPIO_DEBUG() { // Port A //MAP_GPIOUnlockPin(GPIO_PORTA_BASE, GPIO_PIN_2); MAP_GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6, GPIO_DIR_MODE_OUT); MAP_GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); //----------------------------------------------------------------- // Port C MAP_GPIODirModeSet(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6, GPIO_DIR_MODE_OUT); MAP_GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); //----------------------------------------------------------------- // Port D // in used for adc trigger for poti /* MAP_GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_7, GPIO_DIR_MODE_OUT); MAP_GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_7, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); */ //----------------------------------------------------------------- // Port E MAP_GPIODirModeSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5, GPIO_DIR_MODE_OUT); MAP_GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); //----------------------------------------------------------------- // Port F MAP_GPIOUnlockPin(GPIO_PORTF_BASE, GPIO_PIN_0); MAP_GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_4, GPIO_DIR_MODE_OUT); MAP_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_4, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); //----------------------------------------------------------------- } void init_hardware() { init_SYS_CLOCK(); init_FPU(); init_GPIO_CLOCK_A(); init_GPIO_CLOCK_B(); init_GPIO_CLOCK_C(); init_GPIO_CLOCK_D(); init_GPIO_CLOCK_E(); init_GPIO_CLOCK_F(); init_uDMA_TRIGGER_0(); init_uDMA_TRIGGER_1(); init_uDMA_TRIGGER_2(); init_uDMA_TRIGGER_3(); init_TIMER_0(); init_TIMER_1(); init_TIMER_2(); init_TIMER_3(); init_WTIMER_5(); init_uDMA(); init_uDMA_LED0(); init_uDMA_LED1(); init_uDMA_LED2(); init_uDMA_LED3(); }
/* * ==================================================================== * * MIT License * * Copyright (c) [2022] * [Jan Grossniklaus, Jan Kunert, Sascha Hildebrands, Kevin Hinrichs] * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * urnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall * be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * ==================================================================== */ /* + -------------------------------------------------------------------- + + Created : 10/04/2022 + Owner : Kevin Hinrichs + + Description: Driver to create the data signal for a + ws2812b LED stripe. + Four parallel data signals are generated. + + -------------------------------------------------------------------- */ #include <stdint.h> #include <stdbool.h> #include <stdio.h> #include <arm_math.h> #include "project.h" // global header file #include "ws2812b.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "inc/hw_timer.h" #include "driverlib/rom.h" #include "driverlib/rom_map.h" #include "driverlib/udma.h" #include "driverlib/gpio.h" #include "driverlib/timer.h" //********************************************************************* // // Interrupts Handler // //********************************************************************* void uDMAGPIOAIntHandler(void) { if ((uDMAChannelModeGet(4 | UDMA_PRI_SELECT) == UDMA_MODE_STOP)) { ledStreamTranferState_PRI[0] = EMPTY; #ifndef DEBUG_OFF DEBUG_PC5 = GPIO_PIN_5; // CH06 DMAP #endif } if ((uDMAChannelModeGet(4 | UDMA_ALT_SELECT) == UDMA_MODE_STOP)) { ledStreamTranferState_ALT[0] = EMPTY; #ifndef DEBUG_OFF DEBUG_PC6 = GPIO_PIN_6; // CH07 DMAA #endif } #ifndef DEBUG_OFF DEBUG_PC5 = 0; // CH06 DMAP DEBUG_PC6 = 0; // CH07 DMAA #endif } void uDMAGPIOCIntHandler(void) { if ((uDMAChannelModeGet(6 | UDMA_PRI_SELECT) == UDMA_MODE_STOP)) { ledStreamTranferState_PRI[1] = EMPTY; #ifndef DEBUG_OFF DEBUG_PC5 = GPIO_PIN_5; // CH06 DMAP #endif } if ((uDMAChannelModeGet(6 | UDMA_ALT_SELECT) == UDMA_MODE_STOP)) { ledStreamTranferState_ALT[1] = EMPTY; #ifndef DEBUG_OFF DEBUG_PC6 = GPIO_PIN_6; // CH07 DMAA #endif } #ifndef DEBUG_OFF DEBUG_PC5 = 0; // CH06 DMAP DEBUG_PC6 = 0; // CH07 DMAA #endif } void uDMAGPIODIntHandler(void) { if ((uDMAChannelModeGet(7 | UDMA_PRI_SELECT) == UDMA_MODE_STOP)) { ledStreamTranferState_PRI[2] = EMPTY; #ifndef DEBUG_OFF DEBUG_PC5 = GPIO_PIN_5; // CH06 DMAP #endif } if ((uDMAChannelModeGet(7 | UDMA_ALT_SELECT) == UDMA_MODE_STOP)) { ledStreamTranferState_ALT[2] = EMPTY; #ifndef DEBUG_OFF DEBUG_PC6 = GPIO_PIN_6; // CH07 DMAA #endif } #ifndef DEBUG_OFF DEBUG_PC5 = 0; // CH06 DMAP DEBUG_PC6 = 0; // CH07 DMAA #endif } void uDMAGPIOFIntHandler(void) { if ((uDMAChannelModeGet(15 | UDMA_PRI_SELECT) == UDMA_MODE_STOP)) { ledStreamTranferState_PRI[3] = EMPTY; #ifndef DEBUG_OFF DEBUG_PC5 = GPIO_PIN_5; // CH06 DMAP #endif } if ((uDMAChannelModeGet(15 | UDMA_ALT_SELECT) == UDMA_MODE_STOP)) { ledStreamTranferState_ALT[3] = EMPTY; #ifndef DEBUG_OFF DEBUG_PC6 = GPIO_PIN_6; // CH07 DMAA #endif } #ifndef DEBUG_OFF DEBUG_PC5 = 0; // CH06 DMAP DEBUG_PC6 = 0; // CH07 DMAA #endif } void WTIMER5BIntHandler(void) { TimerIntClear(WTIMER5_BASE, TIMER_TIMB_TIMEOUT); // reset time for led is done ledResetTimeIsRunnig = 0; } //********************************************************************* // // Functions // //********************************************************************* void startTimer() { // start timers with a delay to prevent signal conflicts // use direct memory access instead of the tivaware // TIMER 0 TimerEnable(TIMER0_BASE, TIMER_BOTH); for (int i = 0; i < 3; i++) { while ((*((volatile uint32_t *)0x40030054)) <= 15) { // ...waiting the period is start } while ((*((volatile uint32_t *)0x40030054)) > 15) { // ...waiting the period is done } } MAP_SysCtlDelay(1); // TIMER 1 TimerEnable(TIMER1_BASE, TIMER_BOTH); for (int i = 0; i < 3; i++) { while ((*((volatile uint32_t *)0x40031054)) <= 15) { // ...waiting the period is start } while ((*((volatile uint32_t *)0x40031054)) > 15) { // ...waiting the period is done } } MAP_SysCtlDelay(1); // TIMER 2 TimerEnable(TIMER2_BASE, TIMER_BOTH); for (int i = 0; i < 3; i++) { while ((*((volatile uint32_t *)0x40032054)) <= 15) { // ...waiting the period is start } while ((*((volatile uint32_t *)0x40032054)) > 15) { // ...waiting the period is done } } MAP_SysCtlDelay(1); // TIMER 3 TimerEnable(TIMER3_BASE, TIMER_BOTH); } void stopTimer() { // stop all timers when the signal is off // use direct memory access instead of the tivaware // Timer 0A while ((*((volatile uint32_t *)0x40030050)) > SIGNAL_RESET) { // ...waiting the signal is off } (*((volatile uint32_t *)0x4003000C)) &= ~0x00000001; // Timer 1A while ((*((volatile uint32_t *)0x40031050)) > SIGNAL_RESET) { // ...waiting the signal is off } (*((volatile uint32_t *)0x4003100C)) &= ~0x00000001; // Timer 2A while ((*((volatile uint32_t *)0x40032050)) > SIGNAL_RESET) { // ...waiting the signal is 0 } (*((volatile uint32_t *)0x4003200C)) &= ~0x00000001; // Timer 3A while ((*((volatile uint32_t *)0x40033050)) > SIGNAL_RESET) { // ...waiting the signal is 0 } (*((volatile uint32_t *)0x4003300C)) &= ~0x00000001; // Timer 0B while ((*((volatile uint32_t *)0x40030054)) > SIGNAL_DMA) { // ...waiting the signal is off } (*((volatile uint32_t *)0x4003000C)) &= ~0x00000100; // Timer 1B while ((*((volatile uint32_t *)0x40031054)) > SIGNAL_DMA) { // ...waiting the signal is off } (*((volatile uint32_t *)0x4003100C)) &= ~0x00000100; // Timer 2B while ((*((volatile uint32_t *)0x40032054)) > SIGNAL_DMA) { // ...waiting the signal is 0 } (*((volatile uint32_t *)0x4003200C)) &= ~0x00000100; // Timer 3B while ((*((volatile uint32_t *)0x40033054)) > SIGNAL_DMA) { // ...waiting the signal is 0 } (*((volatile uint32_t *)0x4003300C)) &= ~0x00000100; /* // Timer 0 while ((*((volatile uint32_t *)0x40030050)) > SIGNAL_DMA) { // ...waiting the signal is off } TimerDisable(TIMER0_BASE, TIMER_BOTH); // Timer 1 while ((*((volatile uint32_t *)0x40031050)) > SIGNAL_DMA) { // ...waiting the signal is off } TimerDisable(TIMER1_BASE, TIMER_BOTH); // Timer 2A while ((*((volatile uint32_t *)0x40032050)) > SIGNAL_DMA) { // ...waiting the signal is 0 } TimerDisable(TIMER2_BASE, TIMER_BOTH); // Timer 3 while ((*((volatile uint32_t *)0x40033050)) > SIGNAL_DMA) { // ...waiting the signal is 0 } TimerDisable(TIMER3_BASE, TIMER_BOTH); */ // reset all counters (*((volatile uint32_t *)0x40030050)) = 0x00000000; (*((volatile uint32_t *)0x40030054)) = 0x00000000; (*((volatile uint32_t *)0x40031050)) = 0x00000000; (*((volatile uint32_t *)0x40031054)) = 0x00000000; (*((volatile uint32_t *)0x40032050)) = 0x00000000; (*((volatile uint32_t *)0x40032054)) = 0x00000000; (*((volatile uint32_t *)0x40033050)) = 0x00000000; (*((volatile uint32_t *)0x40033054)) = 0x00000000; } void updatePixelData(streamDataDataTyp* streamData, uint16_t offsetNum, uint8_t red, uint8_t green, uint8_t blue) { streamData->pixelData[offsetNum][0] = green; streamData->pixelData[offsetNum][1] = red; streamData->pixelData[offsetNum][2] = blue; } void convertStreamData0PRI1Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks <---- // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 0; i < 29; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_PRI[0][dma_index] = 30; } else { streamData->streamData_PRI[0][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData1PRI1Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks <---- // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 116; i < 145; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_PRI[1][dma_index] = 30; } else { streamData->streamData_PRI[1][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData2PRI1Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks <---- // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 232; i < 261; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_PRI[2][dma_index] = 30; } else { streamData->streamData_PRI[2][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData3PRI1Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks <---- // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 348; i < 377; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_PRI[3][dma_index] = 30; } else { streamData->streamData_PRI[3][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData0ALT2Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks <---- // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 29; i < 58; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_ALT[0][dma_index] = 30; } else { streamData->streamData_ALT[0][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData1ALT2Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks <---- // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 145; i < 174; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_ALT[1][dma_index] = 30; } else { streamData->streamData_ALT[1][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData2ALT2Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks <---- // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 261; i < 290; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_ALT[2][dma_index] = 30; } else { streamData->streamData_ALT[2][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData3ALT2Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks <---- // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 377; i < 406; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_ALT[3][dma_index] = 30; } else { streamData->streamData_ALT[3][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData0PRI3Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks <---- // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 58; i < 87; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_PRI[0][dma_index] = 30; } else { streamData->streamData_PRI[0][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData1PRI3Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks <---- // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 174; i < 203; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_PRI[1][dma_index] = 30; } else { streamData->streamData_PRI[1][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData2PRI3Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks <---- // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 290; i < 319; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_PRI[2][dma_index] = 30; } else { streamData->streamData_PRI[2][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData3PRI3Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks <---- // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 406; i < 435; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_PRI[3][dma_index] = 30; } else { streamData->streamData_PRI[3][dma_index] = 70; } dma_index++; } } #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData0ALT4Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks <---- // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 87; i < 116; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_ALT[0][dma_index] = 30; } else { streamData->streamData_ALT[0][dma_index] = 70; } dma_index++; } } // put reset code and the end streamData->streamData_ALT[0][dma_index] = 98; #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData1ALT4Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks <---- // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 203; i < 232; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_ALT[1][dma_index] = 30; } else { streamData->streamData_ALT[1][dma_index] = 70; } dma_index++; } } // put reset code and the end streamData->streamData_ALT[1][dma_index] = 98; #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData2ALT4Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks <---- // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks // ^ // | // for the for loop + 1 ---+ // for (int i = 319; i < 348; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_ALT[2][dma_index] = 30; } else { streamData->streamData_ALT[2][dma_index] = 70; } dma_index++; } } // put reset code and the end streamData->streamData_ALT[2][dma_index] = 98; #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void convertStreamData3ALT4Turn(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA4 = GPIO_PIN_4; // CH02 Conv #endif uint32_t datablock; uint16_t dma_index; // convert every bit from a datablock (match register timer) // // i = datablock size // j = streamData index // // set dma_index dma_index = 0; // 1.Turn // Data0 000-028 Datablocks + 000 Offset = 000-028 Datablocks // Data1 000-028 Datablocks + 116 Offset = 116-144 Datablocks // Data2 000-028 Datablocks + 232 Offset = 232-260 Datablocks // Data3 000-028 Datablocks + 348 Offset = 348-376 Datablocks // 2.Turn // Data0 029-057 Datablocks + 000 Offset = 029-057 Datablocks // Data1 029-057 Datablocks + 116 Offset = 145-173 Datablocks // Data2 029-057 Datablocks + 232 Offset = 261-289 Datablocks // Data3 029-057 Datablocks + 348 Offset = 377-405 Datablocks // 3.Turn // Data0 058-086 Datablocks + 000 Offset = 058-086 Datablocks // Data1 058-086 Datablocks + 116 Offset = 174-202 Datablocks // Data2 058-086 Datablocks + 232 Offset = 290-318 Datablocks // Data3 058-086 Datablocks + 348 Offset = 406-434 Datablocks // 4.Turn (+ RESET CODE) // Data0 087-115 Datablocks + 000 Offset = 087-115 Datablocks // Data1 087-115 Datablocks + 116 Offset = 203-231 Datablocks // Data2 087-115 Datablocks + 232 Offset = 319-347 Datablocks // Data3 087-115 Datablocks + 348 Offset = 435-463 Datablocks <---- // ^ // | // for the for loop + 1 ---+ // for (int i = 435; i < 464; i++) { datablock = ((streamData->pixelData[i][0] << 16) | (streamData->pixelData[i][1] << 8) | (streamData->pixelData[i][2])); for (int j = (24 - 1); j >= 0; j--) { if (datablock & (1 << j)) { streamData->streamData_ALT[3][dma_index] = 30; } else { streamData->streamData_ALT[3][dma_index] = 70; } dma_index++; } } // put reset code and the end streamData->streamData_ALT[3][dma_index] = 98; #ifndef DEBUG_OFF DEBUG_PA4 = 0; // CH02 Conv #endif } void startStreamPri(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA5 = GPIO_PIN_5; // CH03 Pri #endif MAP_uDMAChannelTransferSet(4 | UDMA_PRI_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_PRI[0], (void *)(TIMER0_BASE + TIMER_O_TAMATCHR), 696); MAP_uDMAChannelTransferSet(6 | UDMA_PRI_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_PRI[1], (void *)(TIMER1_BASE + TIMER_O_TAMATCHR), 696); MAP_uDMAChannelTransferSet(7 | UDMA_PRI_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_PRI[2], (void *)(TIMER2_BASE + TIMER_O_TAMATCHR), 696); MAP_uDMAChannelTransferSet(15 | UDMA_PRI_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_PRI[3], (void *)(TIMER3_BASE + TIMER_O_TAMATCHR), 696); MAP_uDMAChannelEnable(4 | UDMA_PRI_SELECT); MAP_uDMAChannelEnable(6 | UDMA_PRI_SELECT); MAP_uDMAChannelEnable(7 | UDMA_PRI_SELECT); MAP_uDMAChannelEnable(15 | UDMA_PRI_SELECT); for (int i = 0; i < 4; i++) { ledStreamTranferState_PRI[i] = FULL; } #ifndef DEBUG_OFF DEBUG_PA5 = 0; // CH03 Pri #endif } void startStreamAlt(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA6 = GPIO_PIN_6; // CH04 Alt #endif MAP_uDMAChannelTransferSet(4 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_ALT[0], (void *)(TIMER0_BASE + TIMER_O_TAMATCHR), 696); MAP_uDMAChannelTransferSet(6 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_ALT[1], (void *)(TIMER1_BASE + TIMER_O_TAMATCHR), 696); MAP_uDMAChannelTransferSet(7 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_ALT[2], (void *)(TIMER2_BASE + TIMER_O_TAMATCHR), 696); MAP_uDMAChannelTransferSet(15 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_ALT[3], (void *)(TIMER3_BASE + TIMER_O_TAMATCHR), 696); MAP_uDMAChannelEnable(4 | UDMA_ALT_SELECT); MAP_uDMAChannelEnable(6 | UDMA_ALT_SELECT); MAP_uDMAChannelEnable(7 | UDMA_ALT_SELECT); MAP_uDMAChannelEnable(15 | UDMA_ALT_SELECT); for (int i = 0; i < 4; i++) { ledStreamTranferState_ALT[i] = FULL; } #ifndef DEBUG_OFF DEBUG_PA6 = 0; // CH04 Alt #endif } void startStreamAltReset(streamDataDataTyp* streamData) { #ifndef DEBUG_OFF DEBUG_PA6 = GPIO_PIN_6; // CH04 Alt #endif MAP_uDMAChannelTransferSet(4 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_ALT[0], (void *)(TIMER0_BASE + TIMER_O_TAMATCHR), 697); MAP_uDMAChannelTransferSet(6 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_ALT[1], (void *)(TIMER1_BASE + TIMER_O_TAMATCHR), 697); MAP_uDMAChannelTransferSet(7 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_ALT[2], (void *)(TIMER2_BASE + TIMER_O_TAMATCHR), 697); MAP_uDMAChannelTransferSet(15 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, &streamData->streamData_ALT[3], (void *)(TIMER3_BASE + TIMER_O_TAMATCHR), 697); MAP_uDMAChannelEnable(4 | UDMA_ALT_SELECT); MAP_uDMAChannelEnable(6 | UDMA_ALT_SELECT); MAP_uDMAChannelEnable(7 | UDMA_ALT_SELECT); MAP_uDMAChannelEnable(15 | UDMA_ALT_SELECT); for (int i = 0; i < 4; i++) { ledStreamTranferState_ALT[i] = FULL; } #ifndef DEBUG_OFF DEBUG_PA6 = 0; // CH04 Alt #endif } uint8_t sendLED(streamDataDataTyp* streamData) { static uint8_t steps = 0; uint8_t retValue; // sending finished retValue = 0x00; switch (steps) { case 0: #ifndef DEBUG_OFF DEBUG_PA2 = GPIO_PIN_2; // CH00 Start LED #endif //wait reset time befor start again if (!ledResetTimeIsRunnig) { steps = 1; } break; case 1: // convert 1.Turn convertStreamData0PRI1Turn(streamData); convertStreamData1PRI1Turn(streamData); convertStreamData2PRI1Turn(streamData); convertStreamData3PRI1Turn(streamData); // start 1.Turn startStreamPri(streamData); // start timer for led stream startTimer(); steps = 2; break; case 2: // convert 2.Turn convertStreamData0ALT2Turn(streamData); convertStreamData1ALT2Turn(streamData); convertStreamData2ALT2Turn(streamData); convertStreamData3ALT2Turn(streamData); // start 2.Turn startStreamAlt(streamData); steps = 3; break; case 3: // wait 1.Turn is finished if (ledStreamTranferState_PRI[3] == EMPTY && ledStreamTranferState_PRI[2] == EMPTY && ledStreamTranferState_PRI[1] == EMPTY && ledStreamTranferState_PRI[0] == EMPTY) { // convert 3.Turn convertStreamData0PRI3Turn(streamData); convertStreamData1PRI3Turn(streamData); convertStreamData2PRI3Turn(streamData); convertStreamData3PRI3Turn(streamData); // start 3.Turn startStreamPri(streamData); steps = 4; } break; case 4: // wait 3.Turn is finished if (ledStreamTranferState_ALT[3] == EMPTY && ledStreamTranferState_ALT[2] == EMPTY && ledStreamTranferState_ALT[1] == EMPTY && ledStreamTranferState_ALT[0] == EMPTY) { // convert 4.Turn + Reset Code convertStreamData0ALT4Turn(streamData); convertStreamData1ALT4Turn(streamData); convertStreamData2ALT4Turn(streamData); convertStreamData3ALT4Turn(streamData); // start 4.Turn + Reset Code startStreamAltReset(streamData); steps = 5; } break; case 5: // wait 4.Turn is finished if (ledStreamTranferState_ALT[3] == EMPTY && ledStreamTranferState_ALT[2] == EMPTY && ledStreamTranferState_ALT[1] == EMPTY && ledStreamTranferState_ALT[0] == EMPTY) { // sending is finished retValue = 0x1; // stop timers for the led stream stopTimer(); // start reset code time ledResetTimeIsRunnig = 1; TimerEnable(WTIMER5_BASE, TIMER_B); #ifndef DEBUG_OFF DEBUG_PA2 = 0; // CH00 Start LED #endif steps = 0; } break; default: // ...error // RED LED from board have to be blinking // comes later break; } return retValue; }
iar projekt: