void main(){ unsigned int int_val; unsigned int prev_temp, curr_temp = 0; /* Configure INTC */ intc_config(); /* Configure timer or PWM */ pwm_config(time); /* Clear all GPO values */ __R30 = 0x00000000; /* Detect interrupt from Slave PRU that configuration complete */ while((__R31 & 0x80000000) == 0){ } /* Clear system event */ CT_INTC.SECR0 = (1 << PRU_SLAVE_MASTER_EVT); /* Kick off PWM timer */ CT_ECAP.ECCTL2 |= 0x10; // Run counter (TSCTRSTOP = 1) while(1){ /* Detect interrupt */ while((__R31 & 0x80000000) == 0){ } /* Identify highest priority event */ int_val = CT_INTC.HIPIR1; /* PRU eCAP event */ if(int_val == PRU_ECAP_EVT){ /* Interrupt PRU slave to issue read temp */ PRU_MASTER_SLAVE_EVT_TRIGGER; /* This line was added to enable setting a breakpoint in the the PRU slave event service routine */ CT_ECAP.ECCTL2 &= 0xFFEF; // Stop counter (TSCTRSTOP = 0) /* Clear system event */ CT_ECAP.ECCLR |= 0x40; // (PRDEQ = 1) CT_ECAP.ECCLR |= 0x1; // (INT = 1) CT_INTC.SECR0 = (1 << PRU_ECAP_EVT); } /* PRU slave event */ if(int_val == PRU_SLAVE_MASTER_EVT){ /* Clear system event */ CT_INTC.SECR0 = (1 << PRU_SLAVE_MASTER_EVT); /* Read temperature value in Shared RAM */ curr_temp = (((unsigned int)TEMP_SENSOR_BUF.MSB << 8) | (unsigned int)TEMP_SENSOR_BUF.LSB); /* Compare current temp with previous temp */ /* Temperature rising */ if(curr_temp > prev_temp){ /* Set red LED */ __R30 &= ~(GPIO_BLUE); __R30 ^= GPIO_RED; } /* Temperature falling */ if(curr_temp < prev_temp){ /* Set blue LED */ __R30 &= ~(GPIO_RED); __R30 ^= GPIO_BLUE; } /* Temperature constant */ if(curr_temp == prev_temp){ /* Turn off all LEDs */ __R30 &= ~(GPIO_RED); __R30 &= ~(GPIO_BLUE); } /* Store current temp as previous temp */ prev_temp = curr_temp; /* This line was added to enable setting a breakpoint in the the PRU slave event service routine */ CT_ECAP.CAP1_bit.CAP1 = time * 200000000; CT_ECAP.ECCTL2 |= 0x10; // Run counter (TSCTRSTOP = 1) } } }
void main(void) { int i = 0; volatile uint16_t dataA = 0; volatile uint16_t dataB = 0; /* Clear SYSCFG[STANDBY_INIT] to enable OCP master port */ CT_CFG.SYSCFG_bit.STANDBY_INIT = 0; /* Select OCP_CLK as IEP clock source */ CT_CFG.IEPCLK_bit.OCP_EN = 0x1; iep_timer_config(); intc_config(); CT_IEP.TMR_GLB_CFG_bit.CNT_EN = 0x1; /* Setting PRU1 GPO Clk Dividers to 12.5 and 2 to get 8 MHz CLK */ CT_CFG.GPCFG1_bit.PRU1_GPO_DIV0 = 0x17; CT_CFG.GPCFG1_bit.PRU1_GPO_DIV1 = 0x02; /* Init the configure registers and put them in shift out mode */ CT_CFG.GPCFG1_bit.PRU1_GPO_MODE = PRU1_GPO_MODE_SERIAL; /* Init PRU1 GPO to 0 */ __R30 = 0x0; SH0_Load(0); SH1_Load(0); /* Enable PRU1 GPO shift out */ __R30 |= SHIFT_ENABLE_FLAG << SHIFT_ENABLE_SHIFT; while (1) { for (i = 0; i < 0xFF; i++) { /* Poll until R31.30 is set */ do { while ((__R31 & 0x40000000) == 0) { } /* Verify that the IEP is the source of the interrupt */ } while (CT_INTC.HIPIR0 != PRU_IEP_EVT); /* Clear Compare0 status */ CT_IEP.TMR_CMP_STS = 0x1; __delay_cycles(2); /* Clear the status of the interrupt */ CT_INTC.SECR0 = (1 << PRU_IEP_EVT); /* Format sine wave data for DAC */ dataA = DAC_Cmd(DAC_A_ADDRESS, WRITE_NO_UPDATE, SineRaw[i]); /* Swap data endian from LSB first to MSB first per DAC format*/ dataA = Endian_Swap(dataA); /* Load data into Shadow Register 0 */ SH0_Load(dataA); while (!(CT_CFG.GPCFG1 & PRU1_GPO_SH_SEL_MASK)); /* Wait for SH Flag to indicate SH0 being output */ while ((CT_CFG.GPCFG1 & PRU1_GPO_SH_SEL_MASK)); /* Generate sync signal */ __R30 |= 0x0004; __delay_cycles(2); __R30 &= ~0x4; /* Format sine wave data for DAC */ dataB = DAC_Cmd(DAC_B_ADDRESS, WRITE_UPDATE, SineRaw[i]); /* Swap data endian from LSB first to MSB first per DAC format */ dataB = Endian_Swap(dataB); /* Load data into Shadow Register 1 */ SH1_Load(dataB); /* Wait for SH Flag to indicate SH1 being output */ while (!(CT_CFG.GPCFG1 & PRU1_GPO_SH_SEL_MASK)); /* Generate sync signal */ __R30 |= 0x0004; __delay_cycles(2); __R30 &= ~0x4; } } }