void main(void) { Uint16 key; ICR = 0xff2e; /* IDLE Control Register */ /* mem port, io port and cpu idle active */ /* Peripheral_Reset */ CSL_SYSCTRL_REGS->PSRCR = 0x0020; CSL_SYSCTRL_REGS->PCGCR1 = 0x0000; CSL_SYSCTRL_REGS->PCGCR2 = 0x0000; CSL_SYSCTRL_REGS->PRCR = 0x00bf; /* VERY IMPORTANT !!! */ /* PPMODE1 (SPI, GPIO, UART, and I2S2): 7 signals of the SPI module, 6 GPIO signals(GP[17:12]), 4 signals of the UART module, 4 signals of the I2S2 module SP1MODE2 (GP[11:6]). 6 GPIO signals (GP[11:6]) SP0MODE0 (MMC/SD0). All 6 signals of the MMC/SD0 */ CSL_SYSCTRL_REGS->EBSR = (CSL_SYS_EBSR_PPMODE_MODE1 << 12) |(CSL_SYS_EBSR_SP1MODE_MODE2 << 10) |(CSL_SYS_EBSR_SP0MODE_MODE0 << 8); asm(" bit(ST1, #ST1_INTM) = #1"); INTR_init(); PLL_init(160*1000000L); TIMER_init(); EZDSP5535_I2C_init(); EZDSP5535_LCD_init(); aic3204_init(2, 0); EZDSP5535_GPIO_init(); EZDSP5535_I2S_init(1); // interrupt mode EZDSP5535_SAR_init(); asm(" bit(ST1, #ST1_INTM) = #0"); displayPeriod(); while(1) { key = EZDSP5535_SAR_getKey(); if(key == SW1) { if(period > 10) period--; CSL_GPIO_REGS->IOOUTDATA2 ^= 2; displayPeriod(); } if(key == SW2) { if(period < 900) period++; CSL_GPIO_REGS->IOOUTDATA2 ^= 1; displayPeriod(); } asm(" idle"); } }
void main(void) { long op1, op2; //32-bit operands char* ptr; //pointer to keypad buffer char* blanks; char kbuf[12]; //keypad buffer char c, a; int i; ptr = kbuf; blanks = " "; PLL_init(); //set system clock freq to 24MHz lcd_init(); //enable lcd keypad_enable(); //enable keypad set_lcd_addr(0x00); //display on 1st line i = 0; while(1) { c = getkey(); //read keypad a = hex2asc(c); //convert to ascii kbuf[i] = a; // and store in kbuf if(c<10) { //if 0 - 9 data8(a); // display on lcd wait_keyup(); // wait to release key i++; //increment index } else { switch(c) { case 0xE: //if enter (*) key op1 = number(ptr); //convert to binary set_lcd_addr(0x40); //display on 2nd line write_long_lcd(op1); set_lcd_addr(0x00); //clear 1st line type_lcd(blanks); wait_keyup(); //wait to release key i = 0; //reset kbuf index set_lcd_addr(0x00); //display on 2nd line break; case 0xA: //if key A op2 = number(ptr); //convert to binary op1 = op1 + op2; //compete sum set_lcd_addr(0x40); //display on 2nd line write_long_lcd(op1); set_lcd_addr(0x00); //clear 1st line type_lcd(blanks); wait_keyup(); //wait to release key i = 0; //reset kbuf index set_lcd_addr(0x00); //display on 1st line break; case 0xF: //if clear (#) key clear_lcd(); //clear lcd display wait_keyup(); //wait to release key i = 0; //reset kbuf index break; default: break; } } } }
void main() { int key = 0; int freqShift = 0; ICR = 0xff2e; /* IDLE Control Register */ /* mem port, io port and cpu idle active */ /* Peripheral_Reset */ CSL_SYSCTRL_REGS->PSRCR = 0x0020; CSL_SYSCTRL_REGS->PCGCR1 = 0x0000; CSL_SYSCTRL_REGS->PCGCR2 = 0x0000; CSL_SYSCTRL_REGS->PRCR = 0x00bf; /* VERY IMPORTANT !!! */ /* PPMODE1 (SPI, GPIO, UART, and I2S2): 7 signals of the SPI module, 6 GPIO signals(GP[17:12]), 4 signals of the UART module, 4 signals of the I2S2 module SP1MODE2 (GP[11:6]). 6 GPIO signals (GP[11:6]) SP0MODE0 (MMC/SD0). All 6 signals of the MMC/SD0 */ CSL_SYSCTRL_REGS->EBSR = (CSL_SYS_EBSR_PPMODE_MODE1 << 12) |(CSL_SYS_EBSR_SP1MODE_MODE2 << 10) |(CSL_SYS_EBSR_SP0MODE_MODE0 << 8); asm(" bit(ST1, #ST1_INTM) = #1"); PLL_init(80000000); /* CPU clock = 10MHz */ INTR_init(); /* set Interrupt vector and clean all IRs */ EZDSP5535_GPIO_init(); EZDSP5535_I2C_init(); /* Initialize I2C */ aic3204_init(2, 0); /* Initialize codec, sampling rate = 32kHz */ DMA_audio_init(4 * FFT_L); EZDSP5535_I2S_init(0); /* Initialize I2S */ EZDSP5535_SAR_init(); asm(" bit(ST1, #ST1_INTM) = #0"); while(1) { audioProcessing(freqShift); key = EZDSP5535_SAR_getKey(); if(key == SW1) { freqShift = 1; CSL_GPIO_REGS->IOOUTDATA2 &= ~0x0002; } if(key == SW2) { freqShift = 0; CSL_GPIO_REGS->IOOUTDATA2 |= 0x0002; } asm(" idle"); } }
void main(void) { PLL_init(); lcd_init(); SCI0_init(9600); SCI1_int_init(9600); // Channel to talk to ESP8266 motor0_init(); // These functions actually control PWM outputs motor1_init(); // We use them to run the RGB LED. motor2_init(); RTI_init(); SW_enable(); initq(); DDRH = 0; // PORTH is an input. result = 0; status = 'b'; // Populate binary search tree: set_lcd_addr(0); send_at_command_sci1("ATE0"); // change to ATE1 for debug status = 'i'; // Establish connection to server. send_at_command_sci1("AT+CWMODE=1"); // Set ESP to station mode send_at_command_sci1("AT+CIPMODE=0"); // Set ESP to normal transmission mode send_at_command_sci1("AT+CIPMUX=0"); // Set ESP to single-connection mode send_at_command_sci1("AT+CWJAP=\"Freynet\",\"\""); // Connect to network send_at_command_sci1("AT+CIPSTART=\"TCP\",\"fpf3.net\",12345"); // connect to server while(1){ command = '\0'; while(qempty()); command = getq(); switch (command) { case 'n': status = 'w'; result = new_sequence(); ms_delay(500); // If we finish too quickly, we open a connection the ESP thinks is already open, and it breaks. send_at_command_sci1("AT+CIPSTART=\"TCP\",\"fpf3.net\",12345"); // connect to server break; } outchar0(result); } }
//Example 1c – 7-Segment Displays using Function calls void main(void) { PLL_init(); // set system clock frequency to 24 MHz led_disable(); // disable leds seg7_enable(); // enable 7-segment displays seg7_on(0x55,2); // turn on every other segment on digit 2 for(;;) {} /* wait forever */ }
CSL_Status pll_sample() { CSL_Status status; volatile int i; status = PLL_init(&pllObj, CSL_PLL_INST_0); if (status != CSL_SOK) { return status; } hPll = (PLL_Handle)(&pllObj); PLL_reset(hPll); status = PLL_bypass(hPll); if (status != CSL_SOK) { return status; } /* Configure the PLL */ //pConfigInfo = (PLL_Config *)&pllCfg_40MHz; pConfigInfo = (PLL_Config *)&pllCfg_100MHz; //pConfigInfo = (PLL_Config *)&pllCfg_100MHz_ExtClk12Mhz; //pConfigInfo = (PLL_Config *)&pllCfg_120MHz_ExtClk12Mhz; status = PLL_config (hPll, pConfigInfo); if (status != CSL_SOK) { return(status); } status = PLL_getConfig(hPll, &pllCfg1); if (status != CSL_SOK) { return status; } /* Wait for PLL to stabilize */ for (i=0; i<100; i++); status = PLL_enable(hPll); if (status != CSL_SOK) { return status; } // set DSP_LDO to 1.05V //*(volatile ioport unsigned int *)(0x7004) |= 0x0002; return CSL_SOK; }
void main(void) { PLL_init(); // set system clock frequency to 24 MHz ad0_enable(); // enable a/d converter 0 ad1_enable(); // enable a/d converter 1 led_enable(); seg7_disable(); servo54_init(); lcd_init(); // enable lcd motor1_init(); // enable 8-bit pwm1 for computer fan while(1) { for (width = 3000; width < 14500; width = width + 150) { flame = ad0conv(3); // read flame sensor output on channel 3 adc0 range = ad0conv(5); // read range sensor output on channel 7 adc1 set_lcd_addr(0x40); if (range > 550) { type_lcd("Flame is near! "); } else { type_lcd("Out of range "); } set_servo54(width); ms_delay(10); if (flame > 1000) { set_lcd_addr(0x00); ms_delay(10); type_lcd("Flame Detected! "); if (range > 550) { ms_delay(10); //Turn the motor on for 8 seconds set_lcd_addr(0x40); ms_delay(10); type_lcd("Flame is near! "); ms_delay(10); leds_on(0b11111000); //Motor is on ms_delay(8000); motor1(speed); ms_delay(10); } } else { leds_on(0b11111100); //Motor is off set_lcd_addr(0x00); type_lcd("No Flame "); } ms_delay(10); } } }
void main(void) { /* put your own code here */ PLL_init(); // set system clock frequency to 24 MHz DDRB = 0xff; // Port B is output DDRJ = 0xff; // Port J is output DDRP = 0xff; // Port P is output PTJ = 0x00; // enable LED PTP = 0x00; // enable all 7-segment displays // turn on every other led and segment on 7-seg displays PORTB = 0x55; for(;;) {} /* wait forever */ }
void CONTROL_init(void){ CONTROL_LOG("CONTROL_LOG: spi_init()\n"); spi_init(); PLL_init(); SRC_init(); PLL_set_scko1_freq(PLL_SCKO1_16MHz); CONTROL_set_audio_data_format(CONTROL_24_bit_I2S); CONTROL_set_oversampling_freq(CONTROL_OVERSAMPLING_FREQ_44_1kHz); CONTROL_set_attunation_level(100); CONTROL_set_zero_detect_mute(PCM_enabled); CONTROL_set_monaural_mode(PCM_stereo); }
inline void setup_handles(void){ myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj)); myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj)); myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj)); mySci = SCI_init((void *)SCIA_BASE_ADDR, sizeof(SCI_Obj)); myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj)); myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj)); }
int main(void) { // Select 12MHz crystal oscillator LPC_SC ->CLKSRCSEL = 1; // Init PLL 0 to 100MHz PLL_init(25, 2, 3); // PLL_init(12, 1, 18); // 16MHz SystemCoreClockUpdate(); volatile uint32_t i = 1; while (i < (1 << 23)) { ++i; } LCD_init(); LCD_function_set(BUS_WIDTH_8, LINE_COUNT_2, FONT_5_8); i = 1; while (i < (1 << 23)) { ++i; } LCD_write('a'); LCD_write('b'); LCD_write('c'); LCD_write('d'); char c = 'e'; uint_fast8_t x = 0, y = 0; while(1) { LCD_write(c); ++c; ++x; if (x > 15) { x = 0; y ^= 1; } LCD_move_cursor(x, y); i = 1; while (i < (1 << 23)) { ++i; } } return 0; }
void main() { memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); WDOG_Handle myWDog; myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); WDOG_disable(myWDog); CLK_Handle myClk; PLL_Handle myPll; myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); CLK_setOscSrc(myClk, CLK_OscSrc_Internal); PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2); GPIO_Handle myGpio; myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_0, GPIO_Direction_Output); GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_1, GPIO_Direction_Output); GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_2, GPIO_Direction_Output); GPIO_setMode(myGpio, GPIO_Number_3, GPIO_3_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_3, GPIO_Direction_Output); GPIO_setHigh(myGpio, GPIO_Number_0); GPIO_setHigh(myGpio, GPIO_Number_1); GPIO_setHigh(myGpio, GPIO_Number_2); GPIO_setHigh(myGpio, GPIO_Number_3); while(1) { GPIO_setLow(myGpio, GPIO_Number_3); DELAY_US(1000000); GPIO_setHigh(myGpio, GPIO_Number_3); DELAY_US(1000000); } }
//////////////////////////////////////// // Initalize // // Ports, Interrupts, Motor and Servo // //////////////////////////////////////// void portInit(void){ PLL_init(); // set system clock frequency to 24 MHz //Direction registers DDRH = 0x00; // Port H is input DDRB = 0x0F; // Port B starts as output PORTB = 0x00; // turn all LED's OFF DDRT = 0xFF; // port T7 is input rest is output //motors PTT_PTT0 = 0; //default PTT_PTT1 = 0; //default PTT_PTT2 = 0; //default PTT_PTT3 = 0; //default motor0_init(); //left motor motor1_init(); //right motor //initialize a/d ad0_enable(); //enable a/d converter w/ interrupt with custom values RTI_init(); //turn on real time interrupt }
/*..........................................................................*/ void BSP_init(void) { PLL_Config pllCfg_100MHz = { 0x8BE8U, 0x8000U, 0x0806U, 0x0000U }; PLL_Obj pllObj; uint16_t i; PLL_init(&pllObj, CSL_PLL_INST_0); PLL_reset(&pllObj); PLL_config(&pllObj, &pllCfg_100MHz); QF_zero(); /* clear the QF variables, see NOTE01 */ CSL_SYSCTRL_REGS->PCGCR1 = 0U; /* enable clocks to all peripherals */ CSL_SYSCTRL_REGS->PCGCR2 = 0U; CSL_SYSCTRL_REGS->EBSR = 0x1800U; /* configure I/O muxing */ CSL_SYSCTRL_REGS->PSRCR = 0x0020U; /* reset all peripherals */ CSL_SYSCTRL_REGS->PRCR = 0x00BFU; ULED_init(); /* configure the User LEDs... */ IRQ_globalDisable(); IRQ_disableAll(); /* disable all the interrupts */ IRQ_clearAll(); /* clear any pending interrupts */ IRQ_setVecs((uint32_t)&VECSTART); /* set the vector table */ for (i = 1U; i < 32U; ++i) { /* pre-fill the Vector table */ IRQ_plug(i, &illegal_isr); /* with illegal ISR */ } /* plug in all ISRs into the vector table...*/ // IRQ_plug(TINT_EVENT, &TINT_isr); // IRQ_plug(RTC_EVENT, &RTC_isr); /* ... */ if (QS_INIT((void *)0) == 0) { /* initialize the QS software tracing */ Q_ERROR(); } QS_OBJ_DICTIONARY(&l_TINT_isr); }
void main(void) { char key; //key pressed Flag *flag = createFlag(); PLL_init(); //set system clock freq to 24MHz lcd_init(); //enable lcd display (clear display) keypad_enable(); //enable keypad led_enable(); //enable leds seg7_disable(); //turn off and disable seg7 display set_lcd_addr(0x40); //set display on 2nd line while(1){ key = getkey(); //read keypad if(flag->shift == true) //shift key was pressed shiftMode(key, flag); //operator input keys else stdMode(key, flag); //standard input keys } //end while(1) } //end main
CSL_Status pll_sample_freq(Uint16 freq) { CSL_Status status; volatile int i; status = PLL_init(&pllObj, CSL_PLL_INST_0); if (status != CSL_SOK) { return status; } hPll = (PLL_Handle)(&pllObj); PLL_reset(hPll); status = PLL_bypass(hPll); if (status != CSL_SOK) { return status; } /* Configure the PLL */ switch(freq){ case 40: pConfigInfo = (PLL_Config *)&pllCfg_40MHz; break; case 100: pConfigInfo = (PLL_Config *)&pllCfg_100MHz; break; case 120: pConfigInfo = (PLL_Config *)&pllCfg_120MHz; break; default: pConfigInfo = (PLL_Config *)&pllCfg_100MHz; } status = PLL_config (hPll, pConfigInfo); if (status != CSL_SOK) { return(status); } status = PLL_getConfig(hPll, &pllCfg1); if (status != CSL_SOK) { return status; } /* Wait for PLL to stabilize */ for (i=0; i<100; i++); status = PLL_enable(hPll); if (status != CSL_SOK) { return status; } // set DSP_LDO to 1.05V //*(volatile ioport unsigned int *)(0x7004) |= 0x0002; return CSL_SOK; }
void main(void) { int i; CPU_Handle myCpu; PLL_Handle myPll; WDOG_Handle myWDog; // Initialize all the handles needed for this application myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj)); myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj)); myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj)); myPwm2 = PWM_init((void *)PWM_ePWM2_BASE_ADDR, sizeof(PWM_Obj)); myPwm3 = PWM_init((void *)PWM_ePWM3_BASE_ADDR, sizeof(PWM_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); // Perform basic system initialization WDOG_disable(myWDog); CLK_enableAdcClock(myClk); (*Device_cal)(); CLK_disableAdcClock(myClk); //Select the internal oscillator 1 as the clock source CLK_setOscSrc(myClk, CLK_OscSrc_Internal); // Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2 PLL_setup(myPll, PLL_Multiplier_10, PLL_DivideSelect_ClkIn_by_2); // Disable the PIE and all interrupts PIE_disable(myPie); PIE_disableAllInts(myPie); CPU_disableGlobalInts(myCpu); CPU_clearIntFlags(myCpu); // If running from flash copy RAM only functions to RAM #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif // Setup a debug vector table and enable the PIE PIE_setDebugIntVectorTable(myPie); PIE_enable(myPie); // Register interrupt handlers in the PIE vector table PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_1, (intVec_t)&epwm1_timer_isr); PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_2, (intVec_t)&epwm2_timer_isr); PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_3, (intVec_t)&epwm3_timer_isr); InitEPwmTimer(); // For this example, only initialize the ePWM Timers // Initialize counters: EPwm1TimerIntCount = 0; EPwm2TimerIntCount = 0; EPwm3TimerIntCount = 0; // Enable CPU INT3 which is connected to EPWM1-6 INT CPU_enableInt(myCpu, CPU_IntNumber_3); // Enable EPWM INTn in the PIE: Group 3 interrupt 1-6 PIE_enablePwmInt(myPie, PWM_Number_1); PIE_enablePwmInt(myPie, PWM_Number_2); PIE_enablePwmInt(myPie, PWM_Number_3); // Enable global Interrupts and higher priority real-time debug events CPU_enableGlobalInts(myCpu); CPU_enableDebugInt(myCpu); for(;;) { __asm(" NOP"); for(i=1;i<=10;i++) { } } }
void main(void) { Int16 *samples; HANDLE FHandle = Not_Open_FILE; Int16 *out_words = &rawOutWords[1]; Uint8 *byte16 = &RfByte[2]; Int16 mlt_coefs[DCT_LENGTH]; Int16 mag_shift[2]; Int16 old_mag_shift[2]; Uint16 number_of_bits_per_frame; Uint16 number_of_bytes_per_frame; Uint16 number_of_16bit_words_per_frame; Int16 offset; Int16 key; Uint16 chn; // left and right channel, 0 or 1 Int16 sent_buffer_cnt = 0; Uint8 *sent_buffer; ICR = 0xff2e; /* IDLE Control Register */ /* mem port, io port and cpu idle active */ DSP_zero(xmt_l, DCT_LENGTH); DSP_zero(xmt_r, DCT_LENGTH); /* Peripheral_Reset */ CSL_SYSCTRL_REGS->PSRCR = 0x0020; CSL_SYSCTRL_REGS->PCGCR1 = 0x0000; CSL_SYSCTRL_REGS->PCGCR2 = 0x0000; CSL_SYSCTRL_REGS->PRCR = 0x00bf; CSL_SYSCTRL_REGS->EBSR = (CSL_SYS_EBSR_PPMODE_MODE1 << 12) | (0 << 8) | (2 << 10);//GPIO(11-6) asm(" bit(ST1, #ST1_INTM) = #1"); number_of_bits_per_frame = (Uint16)(BITRATE * 20); // BITRATE in kbps number_of_bytes_per_frame = (Uint16)(number_of_bits_per_frame>>3); number_of_16bit_words_per_frame = (Uint16)(number_of_bits_per_frame>>4); INTR_init(); PLL_init(); TIMER_init(); EZDSP5535_GPIO_init(); DMA_audio_init(DCT_LENGTH); EZDSP5535_I2C_init(); /* Initialize I2C */ aic3204_init(6); /* Initialize codec */ EZDSP5535_LCD_init(); EZDSP5535_I2S_init(); /* Initialize I2S */ LCD_print("G722.1 Send ", 17, 0); LCD_print("16kbps ", 8, 1); EZDSP5535_SPI_init(); Si446x_Init(); EZDSP5535_SAR_init(); DiskInit(); FileInit(); AddFileDriver(SDCammand, NULL); sam2coef_init(); coef2sam_init(); rawOutWords[0] = 0x6b21; RfByte[0] = 0x21; RfByte[1] = 0x6b; // little-endian old_mag_shift[0] = 0; old_mag_shift[1] = 0; asm(" bit(ST1, #ST1_INTM) = #0"); SpiWriteByte(CMD_GET_INT_STATUS, 0); // clear interrupt pending while(1) { if(pingpong >= 0) { offset = (pingpong>>1) * DCT_LENGTH; /******************************************************************* * LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT *******************************************************************/ chn = LEFT; samples = &rcv_l[offset]; // Read frame of samples from mem. // Convert input samples to rmlt coefs mag_shift[chn] = samples_to_rmlt_coefs(samples, mlt_coefs, chn); // Encode the mlt coefs encoder(number_of_bits_per_frame, mlt_coefs, mag_shift[chn], out_words); byte16 = &RfByte[2]; byte16[-2] = 0x6b; byte16[-1] = 0x20; DSP_word2byte(byte16, out_words, number_of_16bit_words_per_frame); // process the out_words into decoder_mlt_coefs decoder(out_words, mlt_coefs, &mag_shift[chn], &old_mag_shift[chn]); samples = &xmt_l[offset]; // Write frame of output samples // convert the decoder_mlt_coefs to samples rmlt_coefs_to_samples(mlt_coefs, samples, mag_shift[chn], chn); /******************************************************************* * RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT *******************************************************************/ chn = RIGHT; samples = &rcv_r[offset]; // Read frame of samples from mem. // Convert input samples to rmlt coefs mag_shift[chn] = samples_to_rmlt_coefs(samples, mlt_coefs, chn); // Encode the mlt coefs encoder(number_of_bits_per_frame, mlt_coefs, mag_shift[chn], out_words); byte16 = &RfByte[number_of_bytes_per_frame + 4]; byte16[-2] = 0x6b; byte16[-1] = 0x21; DSP_word2byte(byte16, out_words, number_of_16bit_words_per_frame); // process the out_words into decoder_mlt_coefs decoder(out_words, mlt_coefs, &mag_shift[chn], &old_mag_shift[chn]); samples = &xmt_r[offset]; // Write frame of output samples // convert the decoder_mlt_coefs to samples rmlt_coefs_to_samples(mlt_coefs, samples, mag_shift[chn], chn); if (FHandle != Not_Open_FILE) // Write output bitstream FileWrite(RfByte, 2*number_of_bytes_per_frame+4, FHandle); pingpong = -1; sent_buffer = RfByte; sent_buffer_cnt = 0; } if(spiIsrStatus == 1) { bApi_Set_Send(43); spiIsrStatus = 0; } if(sent_buffer_cnt < 2) { if(gpioIsrStatus == 1) { SPI_sendData(sent_buffer, number_of_bytes_per_frame+2); sent_buffer += number_of_bytes_per_frame+2; sent_buffer_cnt++; gpioIsrStatus = 0; CSL_GPIO_REGS->IOINTFLG1 = 0x0800; } } // key = EZDSP5535_SAR_getKey(); key = -1; if(key == SW1) if(FHandle == Not_Open_FILE) { LCD_print("RECORDING......", 15, 0); FHandle = FileOpen("A:\\VOICE000.TXT", FILE_FLAGS_WRITE); } if(key == SW2) if(FHandle != Not_Open_FILE) { LCD_print("SAVE VOICE000.DAT", 17, 0); FileClose(FHandle); AllCacheWriteBack(); FHandle = Not_Open_FILE; } asm(" idle"); }
void main(void) { ADC_Handle myAdc; CPU_Handle myCpu; PLL_Handle myPll; WDOG_Handle myWDog; // Initialize all the handles needed for this application myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj)); myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myComp = COMP_init((void *)COMP1_BASE_ADDR, sizeof(COMP_Obj)); myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj)); myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj)); myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); // Perform basic system initialization WDOG_disable(myWDog); CLK_enableAdcClock(myClk); (*Device_cal)(); CLK_disableAdcClock(myClk); //Select the internal oscillator 1 as the clock source CLK_setOscSrc(myClk, CLK_OscSrc_Internal); // Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2 PLL_setup(myPll, PLL_Multiplier_10, PLL_DivideSelect_ClkIn_by_2); // Disable the PIE and all interrupts PIE_disable(myPie); PIE_disableAllInts(myPie); CPU_disableGlobalInts(myCpu); CPU_clearIntFlags(myCpu); // If running from flash copy RAM only functions to RAM #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif // For this case just init GPIO pins for ePWM1 GPIO_setPullUp(myGpio, GPIO_Number_0, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_1, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A); GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B); // Setup a debug vector table and enable the PIE PIE_setDebugIntVectorTable(myPie); PIE_enable(myPie); // Register interrupt handlers in the PIE vector table PIE_registerPieIntHandler(myPie, PIE_GroupNumber_2, PIE_SubGroupNumber_1, (intVec_t)&epwm1_tzint_isr); // Enable Clock to the ADC CLK_enableAdcClock(myClk); // Comparator shares the internal BG reference of the ADC, // must be powered even if ADC is unused ADC_enableBandGap(myAdc); // Delay to allow BG reference to settle. DELAY_US(1000L); // Enable clock to the Comparator 1 block CLK_enableCompClock(myClk, CLK_CompNumber_1); // Power up Comparator 1 locally COMP_enable(myComp); // Connect the inverting input to pin COMP1B COMP_disableDac(myComp); ////////////////Uncomment following 4 lines to use DAC instead of pin COMP1B ////////////////// // // Connect the inverting input to the internal DAC // COMP_enableDac(myComp); // // Set DAC output to midpoint // COMP_setDacValue(myComp, 512); ////////////////////////////////////////////////////////////////////////////////////////////// CLK_disableTbClockSync(myClk); InitEPwm1Example(); CLK_enableTbClockSync(myClk); // Initialize counters EPwm1TZIntCount = 0; // Enable CPU INT3 which is connected to EPWM1-3 INT CPU_enableInt(myCpu, CPU_IntNumber_2); // Enable EPWM INTn in the PIE: Group 2 interrupt 1-3 PIE_enablePwmTzInt(myPie, PWM_Number_1); // Enable global Interrupts and higher priority real-time debug events CPU_enableGlobalInts(myCpu); CPU_enableDebugInt(myCpu); for(;;) { __asm(" NOP"); } }
void main(void) { CPU_Handle myCpu; PLL_Handle myPll; WDOG_Handle myWDog; // Initialize all the handles needed for this application myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj)); myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj)); myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj)); myPwm2 = PWM_init((void *)PWM_ePWM2_BASE_ADDR, sizeof(PWM_Obj)); myPwm3 = PWM_init((void *)PWM_ePWM3_BASE_ADDR, sizeof(PWM_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); // Perform basic system initialization WDOG_disable(myWDog); CLK_enableAdcClock(myClk); (*Device_cal)(); CLK_disableAdcClock(myClk); //Select the internal oscillator 1 as the clock source CLK_setOscSrc(myClk, CLK_OscSrc_Internal); // Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2 PLL_setup(myPll, PLL_Multiplier_10, PLL_DivideSelect_ClkIn_by_2); // Disable the PIE and all interrupts PIE_disable(myPie); PIE_disableAllInts(myPie); CPU_disableGlobalInts(myCpu); CPU_clearIntFlags(myCpu); // Setup a debug vector table and enable the PIE PIE_setDebugIntVectorTable(myPie); PIE_enable(myPie); // Register interrupt handlers in the PIE vector table PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_1, (intVec_t)&EPwm1_timer_isr); PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_2, (intVec_t)&EPwm2_timer_isr); PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_3, (intVec_t)&EPwm3_timer_isr); // Initialize the EPwm Timers used in this example InitEPwmTimer(); #ifdef _FLASH // Copy time critical code and Flash setup code to RAM // This includes the following ISR functions: EPwm1_timer_isr(), EPwm2_timer_isr() // and FLASH_setup(); // The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart // symbols are created by the linker. Refer to the F2280270.cmd file. memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); // Call Flash Initialization to setup flash waitstates // This function must reside in RAM FLASH_setup(myFlash); #endif // end #ifdef _FLASH // Initalize counters: EPwm1TimerIntCount = 0; EPwm2TimerIntCount = 0; EPwm3TimerIntCount = 0; LoopCount = 0; // Enable CPU INT3 which is connected to EPwm1-3 INT: CPU_enableInt(myCpu, CPU_IntNumber_3); // Enable EPwm INTn in the PIE: Group 3 interrupt 1-3. PIE_enablePwmInt(myPie, PWM_Number_1); PIE_enablePwmInt(myPie, PWM_Number_2); PIE_enablePwmInt(myPie, PWM_Number_3); // Enable global Interrupts and higher priority real-time debug events CPU_enableGlobalInts(myCpu); CPU_enableDebugInt(myCpu); // Configure GPIO so it can toggle in the idle loop GPIO_setMode(myGpio, GPIO_Number_34, GPIO_34_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_34, GPIO_Direction_Output); for(;;) { // This loop will be interrupted, so the overall // delay between pin toggles will be longer. DELAY_US(DELAY); LoopCount++; // Toggle GPIO GPIO_toggle(myGpio, GPIO_Number_34); } }
//================================================================================== //================================================================================== //================================================================================== int main() { bool ver = 0; uint8_t cnt_link = 0; PLL_init(); GPIO_init(); TIM1_init(); TIM2_init(); TIM3_init(); UART_init(); WDT_init(); EEPROM_init(); SysTick_Config(SystemCoreClock/800);//~10 ms time.t1=5; time.t2=5; time.t3=5; time.t4=5; delay_ms(100); Segment[0]=0xFF; Segment[1]=0xFF; Segment[2]=0xFF; Segment[3]=0xFF; Segment[4]=0xFF; Segment[5]=0xFF; Segment[6]=0x7F; ALARM_ON; delay_ms(100); ALARM_OFF; delay_ms(1000); // // while(1) { if( TX_st ) { TX_st = 0; if( cnt_link < LINK_COUNT ) { link_PKBA(); ++cnt_link; } else { PKDU.error = true; cnt_link = 0; } } if( RX_ok && !PKDU.error ) { uint8_t cnt_byte = 0, sum = 0; while( cnt_byte < RX_FRAME_SIZE ) { sum += ArrayRX_PKBA[cnt_byte]; ++cnt_byte; } sum += 0xAA; if( !sum ) { StatusPKBA.reg0 = ArrayRX_PKBA[0]; StatusPKBA.reg1 = ArrayRX_PKBA[1]; StatusPKBA.Error = (ArrayRX_PKBA[3]<<8) | ArrayRX_PKBA[2]; StatusPKBA.RabReg0 = ArrayRX_PKBA[4]; StatusPKBA.UGen = (ArrayRX_PKBA[6]<<8) | ArrayRX_PKBA[5]; StatusPKBA.IGen = (ArrayRX_PKBA[8]<<8) | ArrayRX_PKBA[7]; StatusPKBA.DT = ArrayRX_PKBA[9]; StatusPKBA.DM = ArrayRX_PKBA[10]; StatusPKBA.TM = ArrayRX_PKBA[11]; StatusPKBA.NDiz = (ArrayRX_PKBA[13]<<8) | ArrayRX_PKBA[12]; StatusPKBA.TBapEx = ArrayRX_PKBA[14]; StatusPKBA.TBapIn = ArrayRX_PKBA[15]; StatusPKBA.Led1 = ArrayRX_PKBA[16]; StatusPKBA.Led2 = ArrayRX_PKBA[17]; if( !ver ) { ver = true; show_ver(); delay_ms( 1500 ); Segment[ 0 ] = 0; Segment[ 1 ] = 0; Segment[ 2 ] = 0; Segment[ 3 ] = 0; Segment[ 4 ] = 0; } cnt_link=0; } RX_ok=0; } __nop(); Set_Error(); if(!PKDU.error) ShowParam(); if((PKDU.StatusKN>>4)&1) { maska_err = 0; StatusPKBA.Error=0; PKDU.error=false; cnt_link = 0; } if(((PKDU.StatusKN>>5)&1) && ((PKDU.StatusKN>>6)&1)) { Segment[0] = 0xFF; Segment[1] = 0xFF; Segment[2] = 0xFF; Segment[3] = 0xFF; Segment[4] = 0xFF; Segment[5] = 0xFF; Segment[6] = 0x7F; while(((PKDU.StatusKN>>5)&1)&&((PKDU.StatusKN>>6)&1)) IWDG_ReloadCounter(); } ControlZvonok(); write_hour(); IWDG_ReloadCounter(); } }
void main(void) { Int16 temp_cnt; ICR = 0xff2e; /* IDLE Control Register */ /* mem port, io port and cpu idle active */ /* Peripheral_Reset */ CSL_SYSCTRL_REGS->PSRCR = 0x0020; CSL_SYSCTRL_REGS->PCGCR1 = 0x0000; CSL_SYSCTRL_REGS->PCGCR2 = 0x0000; CSL_SYSCTRL_REGS->PRCR = 0x00bf; /* VERY IMPORTANT !!! */ /* PPMODE1 (SPI, GPIO, UART, and I2S2): 7 signals of the SPI module, 6 GPIO signals(GP[17:12]), 4 signals of the UART module, 4 signals of the I2S2 module SP1MODE2 (GP[11:6]). 6 GPIO signals (GP[11:6]) SP0MODE0 (MMC/SD0). All 6 signals of the MMC/SD0 */ CSL_SYSCTRL_REGS->EBSR = (CSL_SYS_EBSR_PPMODE_MODE1 << 12) |(CSL_SYS_EBSR_SP1MODE_MODE2 << 10) |(CSL_SYS_EBSR_SP0MODE_MODE0 << 8); asm(" bit(ST1, #ST1_INTM) = #1"); INTR_init(); PLL_init(3658); // system clock set to 120MHz TIMER_init(); EZDSP5535_GPIO_init(); EZDSP5535_I2C_init(); /* Initialize I2C */ Audio_init(7); /* Initialise to bandwidth=7kHz */ EZDSP5535_LCD_init(); LCD_print("G722.1 Receiver ", 17, 0); LCD_print("16kbps ", 8, 1); EZDSP5535_SPI_init(); Si446x_Init(); EZDSP5535_SAR_init(); DiskInit(); FileInit(); AddFileDriver(SDCammand, NULL); asm(" bit(ST1, #ST1_INTM) = #0"); bApi_Set_Receive(); while(1) { if(gpioIsrStatus == 1) { temp_cnt = SPI_recvData(spibuffer); gpioIsrStatus = 0; CSL_GPIO_REGS->IOINTFLG1 = 0x0800; } if(spiIsrStatus == 1) { // SpiWriteByte(CMD_FIFO_INFO, 0); SpiWriteByte(CMD_GET_INT_STATUS, 0); bApi_Set_Receive(); if(audioProcessing()) continue; spiIsrStatus = 0; } fileProcessing(); asm(" idle"); } // RemoveFileDriver(SDCammand); }
int pll_frequency_setup(unsigned int frequency) { CSL_Status status; status = PLL_init(&pllObj, CSL_PLL_INST_0); if(CSL_SOK != status) { printf("PLL init failed \n"); return (status); } hPll = (PLL_Handle)(&pllObj); PLL_reset(hPll); /* Configure the PLL for different frequencies */ if ( frequency == 1) { pConfigInfo = &pllCfg_1MHz; printf("\nLL frequency 1 MHz\n"); } else if ( frequency == 2) { pConfigInfo = &pllCfg_2MHz; printf("\nPLL frequency 2 MHz\n"); } else if ( frequency == 12) { pConfigInfo = &pllCfg_12MHz; printf("\nPLL frequency 12 MHz\n"); } else if ( frequency == 40) { pConfigInfo = &pllCfg_40MHz; printf("\nPLL frequency 40 MHz\n"); } else if ( frequency == 60) { pConfigInfo = &pllCfg_60MHz; printf("\nPLL frequency 60 MHz\n"); } else if ( frequency == 75) { pConfigInfo = &pllCfg_75MHz; printf("\nPLL frequency 75 MHz\n"); } else if ( frequency == 98) { pConfigInfo = &pllCfg_98MHz; printf("\nPLL frequency 98 MHz\n"); } else if ( frequency == 120) { pConfigInfo = &pllCfg_120MHz; printf("\nPLL frequency 120 MHz\n"); } else { pConfigInfo = &pllCfg_100MHz; printf("\nPLL frequency 100 MHz\n"); } status = PLL_config (hPll, pConfigInfo); if(CSL_SOK != status) { printf("PLL config failed\n"); return(status); } status = PLL_getConfig(hPll, &pllCfg1); if(status != CSL_SOK) { printf("TEST FAILED: PLL get config... Failed.\n"); printf ("Reason: PLL_getConfig failed. [status = 0x%x].\n", status); return(status); } printf("REGISTER --- CONFIG VALUES\n"); printf("PLL_CNTRL1 %04x --- %04x\n",pllCfg1.PLLCNTL1,hPll->pllConfig->PLLCNTL1); printf("PLL_CNTRL2 %04x --- %04x Test Lock Mon will get set after PLL is up\n", pllCfg1.PLLCNTL2,hPll->pllConfig->PLLCNTL2); printf("PLL_CNTRL3 %04x --- %04x\n",pllCfg1.PLLINCNTL,hPll->pllConfig->PLLINCNTL); printf("PLL_CNTRL4 %04x --- %04x\n",pllCfg1.PLLOUTCNTL,hPll->pllConfig->PLLOUTCNTL); status = PLL_bypass(hPll); if(CSL_SOK != status) { printf("PLL bypass failed:%d\n",CSL_ESYS_BADHANDLE); return(status); } status = PLL_enable(hPll); if(CSL_SOK != status) { printf("PLL enable failed:%d\n",CSL_ESYS_BADHANDLE); return(status); } return(CSL_TEST_PASSED); }
void main(void) { CPU_Handle myCpu; PLL_Handle myPll; WDOG_Handle myWDog; // Initialize all the handles needed for this application myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj)); myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj)); myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj)); myPwm2 = PWM_init((void *)PWM_ePWM2_BASE_ADDR, sizeof(PWM_Obj)); myPwm3 = PWM_init((void *)PWM_ePWM3_BASE_ADDR, sizeof(PWM_Obj)); myPwm4 = PWM_init((void *)PWM_ePWM4_BASE_ADDR, sizeof(PWM_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); // Perform basic system initialization WDOG_disable(myWDog); CLK_enableAdcClock(myClk); (*Device_cal)(); CLK_disableAdcClock(myClk); //Select the internal oscillator 1 as the clock source CLK_setOscSrc(myClk, CLK_OscSrc_Internal); // Setup the PLL for x12 /2 which will yield 60Mhz = 10Mhz * 12 / 2 PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2); // Disable the PIE and all interrupts PIE_disable(myPie); PIE_disableAllInts(myPie); CPU_disableGlobalInts(myCpu); CPU_clearIntFlags(myCpu); // If running from flash copy RAM only functions to RAM #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the f2802x_SysCtrl.c file. // InitSysCtrl(); // Step 2. Initialize GPIO: // This example function is found in the f2802x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example // InitEPwmGpio(); // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts // DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the f2802x_PieCtrl.c file. // InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: // IER = 0x0000; // IFR = 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in f2802x_DefaultIsr.c. // This function is found in f2802x_PieVect.c. // InitPieVectTable(); // For this case just init GPIO pins for EPwm1, EPwm2, EPwm3, EPwm4 GPIO_setPullUp(myGpio, GPIO_Number_0, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_1, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A); GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B); GPIO_setPullUp(myGpio, GPIO_Number_2, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_3, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_EPWM2A); GPIO_setMode(myGpio, GPIO_Number_3, GPIO_3_Mode_EPWM2B); GPIO_setPullUp(myGpio, GPIO_Number_4, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_5, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_4, GPIO_4_Mode_EPWM3A); GPIO_setMode(myGpio, GPIO_Number_5, GPIO_5_Mode_EPWM3B); GPIO_setPullUp(myGpio, GPIO_Number_6, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_7, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_6, GPIO_6_Mode_EPWM4A); GPIO_setMode(myGpio, GPIO_Number_7, GPIO_7_Mode_EPWM4B); // Setup a debug vector table and enable the PIE PIE_setDebugIntVectorTable(myPie); PIE_enable(myPie); // Step 4. Initialize the Device Peripherals: CLK_enablePwmClock(myClk, PWM_Number_1); CLK_enablePwmClock(myClk, PWM_Number_2); CLK_enablePwmClock(myClk, PWM_Number_3); CLK_enablePwmClock(myClk, PWM_Number_4); CLK_enableHrPwmClock(myClk); // For this example, only initialize the ePWM // Step 5. User specific code, enable interrupts: // Calling SFO() updates the HRMSTEP register with calibrated MEP_ScaleFactor. // HRMSTEP must be populated with a scale factor value prior to enabling // high resolution period control. status = SFO_INCOMPLETE; while (status== SFO_INCOMPLETE) // Call until complete { status = SFO(); if (status == SFO_ERROR) { error(); // SFO function returns 2 if an error occurs & # of MEP steps/coarse step } // exceeds maximum of 255. } // Some useful PWM period vs Frequency values // TBCLK = 60 MHz //=================== // Period Freq // 1000 30 KHz // 800 37.5 KHz // 600 50 KHz // 500 60 KHz // 250 120 KHz // 200 150 KHz // 100 300 KHz // 50 600 KHz // 30 1 MHz // 25 1.2 MHz // 20 1.5 MHz // 12 2.5 MHz // 10 3 MHz // 9 3.3 MHz // 8 3.8 MHz // 7 4.3 MHz // 6 5.0 MHz // 5 6.0 MHz //==================================================================== // ePWM and HRPWM register initialization //==================================================================== Period = 500; PeriodFine=0xFFBF; CLK_disableTbClockSync(myClk); HRPWM_Config(myPwm1, Period, 1); HRPWM_Config(myPwm2, Period, 0); HRPWM_Config(myPwm3, Period, 0); HRPWM_Config(myPwm4, Period, 0); CLK_enableTbClockSync(myClk); // Software Control variables Increment_Freq = 1; Increment_Freq_Fine = 1; IsrTicker = 0; UpdatePeriod = 0; UpdatePeriodFine = 0; // User control variables: UpdateCoarse = 0; UpdateFine = 1; // Reassign ISRs. PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_1, (intVec_t)&MainISR); // Enable PIE group 3 interrupt 1 for EPWM1_INT PIE_enableInt(myPie, PIE_GroupNumber_3, PIE_InterruptSource_EPWM1); // Enable CNT_zero interrupt using EPWM1 Time-base PWM_setIntMode(myPwm1, PWM_IntMode_CounterEqualZero); // Select INT on Zero event PWM_enableInt(myPwm1); // Enable INT PWM_setIntPeriod(myPwm1, PWM_IntPeriod_FirstEvent); // Generate INT on 3rd event PWM_clearIntFlag(myPwm1); // Enable CPU INT3 for EPWM1_INT: CPU_enableInt(myCpu, CPU_IntNumber_3); // Enable global Interrupts and higher priority real-time debug events: CPU_enableGlobalInts(myCpu); CPU_enableDebugInt(myCpu); PWM_forceSync(myPwm1); // Synchronize high resolution phase to start HR period for(;;) { // The below code controls coarse edge movement if(UpdateCoarse==1) { if(Increment_Freq==1) //Increase frequency to 600 kHz Period= Period - 1; else Period= Period + 1; //Decrease frequency to 300 kHz if(Period<100 && Increment_Freq==1) Increment_Freq=0; else if(Period>500 && Increment_Freq==0) Increment_Freq=1; UpdatePeriod=1; } // The below code controls high-resolution fine edge movement if(UpdateFine==1) { if(Increment_Freq_Fine==1) // Increase high-resolution frequency PeriodFine=PeriodFine-1; else PeriodFine=PeriodFine+1; // Decrement high-resolution frequency if(PeriodFine<=0x3333 && Increment_Freq_Fine==1) Increment_Freq_Fine=0; else if(PeriodFine>= 0xFFBF && Increment_Freq_Fine==0) Increment_Freq_Fine=1; UpdatePeriodFine=1; } // Call the scale factor optimizer lib function SFO() // periodically to track for any change due to temp/voltage. // This function generates MEP_ScaleFactor by running the // MEP calibration module in the HRPWM logic. This scale // factor can be used for all HRPWM channels. HRMSTEP // register is automatically updated by the SFO function. status = SFO(); // in background, MEP calibration module continuously updates MEP_ScaleFactor if (status == SFO_ERROR) { error(); // SFO function returns 2 if an error occurs & # of MEP steps/coarse step } // exceeds maximum of 255. } }// end main
void main(void) { CPU_Handle myCpu; PLL_Handle myPll; WDOG_Handle myWDog; // Initialize all the handles needed for this application myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj)); myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj)); myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj)); myPwm2 = PWM_init((void *)PWM_ePWM2_BASE_ADDR, sizeof(PWM_Obj)); myPwm3 = PWM_init((void *)PWM_ePWM3_BASE_ADDR, sizeof(PWM_Obj)); myPwm4 = PWM_init((void *)PWM_ePWM4_BASE_ADDR, sizeof(PWM_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); // Perform basic system initialization WDOG_disable(myWDog); CLK_enableAdcClock(myClk); (*Device_cal)(); CLK_disableAdcClock(myClk); //Select the internal oscillator 1 as the clock source CLK_setOscSrc(myClk, CLK_OscSrc_Internal); // Setup the PLL for x12 /2 which will yield 60Mhz = 10Mhz * 12 / 2 PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2); // Disable the PIE and all interrupts PIE_disable(myPie); PIE_disableAllInts(myPie); CPU_disableGlobalInts(myCpu); CPU_clearIntFlags(myCpu); // If running from flash copy RAM only functions to RAM #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the f2802x_SysCtrl.c file. // InitSysCtrl(); // Step 2. Initialize GPIO: // This example function is found in the f2802x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example // For this case, just init GPIO for EPwm1-EPwm4 // For this case just init GPIO pins for EPwm1, EPwm2, EPwm3, EPwm4 // These functions are in the f2802x_EPwm.c file // InitEPwm1Gpio(); // InitEPwm2Gpio(); // InitEPwm3Gpio(); // InitEPwm4Gpio(); // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts // DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the f2802x_PieCtrl.c file. // InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: // IER = 0x0000; // IFR = 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in f2802x_DefaultIsr.c. // This function is found in f2802x_PieVect.c. // InitPieVectTable(); // For this case just init GPIO pins for EPwm1, EPwm2, EPwm3, EPwm4 GPIO_setPullUp(myGpio, GPIO_Number_0, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_1, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A); GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B); GPIO_setPullUp(myGpio, GPIO_Number_2, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_3, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_EPWM2A); GPIO_setMode(myGpio, GPIO_Number_3, GPIO_3_Mode_EPWM2B); GPIO_setPullUp(myGpio, GPIO_Number_4, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_5, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_4, GPIO_4_Mode_EPWM3A); GPIO_setMode(myGpio, GPIO_Number_5, GPIO_5_Mode_EPWM3B); GPIO_setPullUp(myGpio, GPIO_Number_6, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_7, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_6, GPIO_6_Mode_EPWM4A); GPIO_setMode(myGpio, GPIO_Number_7, GPIO_7_Mode_EPWM4B); // Setup a debug vector table and enable the PIE PIE_setDebugIntVectorTable(myPie); PIE_enable(myPie); CLK_enablePwmClock(myClk, PWM_Number_1); CLK_enablePwmClock(myClk, PWM_Number_2); CLK_enablePwmClock(myClk, PWM_Number_3); CLK_enablePwmClock(myClk, PWM_Number_4); // For this example, only initialize the EPwm // Step 4. User specific code, enable interrupts: update =1; DutyFine =0; CLK_disableTbClockSync(myClk); // Some useful Period vs Frequency values // SYSCLKOUT = 60 MHz 40 MHz // -------------------------------------- // Period Frequency Frequency // 1000 60 kHz 40 kHz // 800 75 kHz 50 kHz // 600 100 kHz 67 kHz // 500 120 kHz 80 kHz // 250 240 kHz 160 kHz // 200 300 kHz 200 kHz // 100 600 kHz 400 kHz // 50 1.2 Mhz 800 kHz // 25 2.4 Mhz 1.6 MHz // 20 3.0 Mhz 2.0 MHz // 12 5.0 MHz 3.3 MHz // 10 6.0 MHz 4.0 MHz // 9 6.7 MHz 4.4 MHz // 8 7.5 MHz 5.0 MHz // 7 8.6 MHz 5.7 MHz // 6 10.0 MHz 6.6 MHz // 5 12.0 MHz 8.0 MHz //==================================================================== // EPwm and HRPWM register initialization //==================================================================== HRPWM1_Config(10); // EPwm1 target, Period = 10 HRPWM2_Config(20); // EPwm2 target, Period = 20 HRPWM3_Config(10); // EPwm3 target, Period = 10 HRPWM4_Config(20); // EPwm4 target, Period = 20 CLK_enableTbClockSync(myClk); while (update ==1) { PWM_setCmpAHr(myPwm1, DutyFine << 8); PWM_setCmpAHr(myPwm2, DutyFine << 8); PWM_setCmpAHr(myPwm3, DutyFine << 8); PWM_setCmpAHr(myPwm4, DutyFine << 8); } }
void main(void) { CPU_Handle myCpu; PLL_Handle myPll; WDOG_Handle myWDog; // Initialize all the handles needed for this application myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj)); myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj)); myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj)); myPwm2 = PWM_init((void *)PWM_ePWM2_BASE_ADDR, sizeof(PWM_Obj)); myPwm3 = PWM_init((void *)PWM_ePWM3_BASE_ADDR, sizeof(PWM_Obj)); myPwm4 = PWM_init((void *)PWM_ePWM4_BASE_ADDR, sizeof(PWM_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); // Perform basic system initialization WDOG_disable(myWDog); CLK_enableAdcClock(myClk); (*Device_cal)(); CLK_disableAdcClock(myClk); //Select the internal oscillator 1 as the clock source CLK_setOscSrc(myClk, CLK_OscSrc_Internal); // Setup the PLL for x12 /2 which will yield 60Mhz = 10Mhz * 12 / 2 PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2); // Disable the PIE and all interrupts PIE_disable(myPie); PIE_disableAllInts(myPie); CPU_disableGlobalInts(myCpu); CPU_clearIntFlags(myCpu); // If running from flash copy RAM only functions to RAM #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the f2802x_SysCtrl.c file. // InitSysCtrl(); // Step 2. Initialize GPIO: // This example function is found in the f2802x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example // InitEPwmGpio(); // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts // DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the f2802x_PieCtrl.c file. // InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: // IER = 0x0000; // IFR = 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in f2802x_DefaultIsr.c. // This function is found in f2802x_PieVect.c. // InitPieVectTable(); // For this case just init GPIO pins for EPwm1, EPwm2, EPwm3, EPwm4 GPIO_setPullUp(myGpio, GPIO_Number_0, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_1, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A); GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B); GPIO_setPullUp(myGpio, GPIO_Number_2, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_3, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_EPWM2A); GPIO_setMode(myGpio, GPIO_Number_3, GPIO_3_Mode_EPWM2B); GPIO_setPullUp(myGpio, GPIO_Number_4, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_5, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_4, GPIO_4_Mode_EPWM3A); GPIO_setMode(myGpio, GPIO_Number_5, GPIO_5_Mode_EPWM3B); GPIO_setPullUp(myGpio, GPIO_Number_6, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_7, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_6, GPIO_6_Mode_EPWM4A); GPIO_setMode(myGpio, GPIO_Number_7, GPIO_7_Mode_EPWM4B); // Setup a debug vector table and enable the PIE PIE_setDebugIntVectorTable(myPie); PIE_enable(myPie); CLK_enablePwmClock(myClk, PWM_Number_1); CLK_enablePwmClock(myClk, PWM_Number_2); CLK_enablePwmClock(myClk, PWM_Number_3); CLK_enablePwmClock(myClk, PWM_Number_4); CLK_enableHrPwmClock(myClk); // For this example, only initialize the ePWM // Step 4. User specific code, enable interrupts: UpdateFine = 1; PeriodFine = 0; status = SFO_INCOMPLETE; // Calling SFO() updates the HRMSTEP register with calibrated MEP_ScaleFactor. // HRMSTEP must be populated with a scale factor value prior to enabling // high resolution period control. while (status== SFO_INCOMPLETE) // Call until complete { status = SFO(); if (status == SFO_ERROR) { error(); // SFO function returns 2 if an error occurs & # of MEP steps/coarse step } // exceeds maximum of 255. } // Some useful Period vs Frequency values // SYSCLKOUT = 60 MHz 40 MHz // -------------------------------------- // Period Frequency Frequency // 1000 60 kHz 40 kHz // 800 75 kHz 50 kHz // 600 100 kHz 67 kHz // 500 120 kHz 80 kHz // 250 240 kHz 160 kHz // 200 300 kHz 200 kHz // 100 600 kHz 400 kHz // 50 1.2 Mhz 800 kHz // 25 2.4 Mhz 1.6 MHz // 20 3.0 Mhz 2.0 MHz // 12 5.0 MHz 3.3 MHz // 10 6.0 MHz 4.0 MHz // 9 6.7 MHz 4.4 MHz // 8 7.5 MHz 5.0 MHz // 7 8.6 MHz 5.7 MHz // 6 10.0 MHz 6.6 MHz // 5 12.0 MHz 8.0 MHz //==================================================================== // ePWM and HRPWM register initialization //==================================================================== CLK_disableTbClockSync(myClk); HRPWM_Config(myPwm1, 30); // ePWMx target HRPWM_Config(myPwm2, 30); // ePWMx target HRPWM_Config(myPwm3, 30); // ePWMx target HRPWM_Config(myPwm4, 30); // ePWMx target CLK_enableTbClockSync(myClk); PWM_forceSync(myPwm1); PWM_forceSync(myPwm2); PWM_forceSync(myPwm3); PWM_forceSync(myPwm4); for(;;) { // Sweep PeriodFine as a Q16 number from 0.2 - 0.999 for(PeriodFine = 0x3333; PeriodFine < 0xFFBF; PeriodFine++) { if(UpdateFine) { /* // Because auto-conversion is enabled, the desired // fractional period must be written directly to the // TBPRDHR (or TBPRDHRM) register in Q16 format // (lower 8-bits are ignored) EPwm1Regs.TBPRDHR = PeriodFine; // The hardware will automatically scale // the fractional period by the MEP_ScaleFactor // in the HRMSTEP register (which is updated // by the SFO calibration software). // Hardware conversion: // MEP delay movement = ((TBPRDHR(15:0) >> 8) * HRMSTEP(7:0) + 0x80) >> 8 */ // for(i=1;i<PWM_CH;i++) // { // (*ePWM[i]).TBPRDHR = PeriodFine; //In Q16 format // } PWM_setPeriodHr(myPwm1, PeriodFine); PWM_setPeriodHr(myPwm2, PeriodFine); PWM_setPeriodHr(myPwm3, PeriodFine); PWM_setPeriodHr(myPwm4, PeriodFine); } else { // No high-resolution movement on TBPRDHR. // for(i=1;i<PWM_CH;i++) // { // (*ePWM[i]).TBPRDHR = 0; // } PWM_setPeriodHr(myPwm1, 0); PWM_setPeriodHr(myPwm2, 0); PWM_setPeriodHr(myPwm3, 0); PWM_setPeriodHr(myPwm4, 0); } // Call the scale factor optimizer lib function SFO() // periodically to track for any change due to temp/voltage. // This function generates MEP_ScaleFactor by running the // MEP calibration module in the HRPWM logic. This scale // factor can be used for all HRPWM channels. HRMSTEP // register is automatically updated by the SFO function. status = SFO(); // in background, MEP calibration module continuously updates MEP_ScaleFactor if (status == SFO_ERROR) { error(); // SFO function returns 2 if an error occurs & # of MEP steps/coarse step } // exceeds maximum of 255. } // end PeriodFine for loop } // end infinite for loop } // end main
void main(void) { ICR = 0xff2e; /* IDLE Control Register */ /* mem port, io port and cpu idle active */ /* Peripheral_Reset */ CSL_SYSCTRL_REGS->PSRCR = 0x0020; CSL_SYSCTRL_REGS->PRCR = 0x00bf; EZDSP5535_waitusec(5); /* Peripheral Clock Gating Configuration Register1 0: active, 1: disable SYSCLKDIS I2S2 TMR2 TMR1 X TMR0 I2S1 I2S0 MMCSD1 I2C X MMCSD0 DMA0 UART SPI I2S3 */ CSL_SYSCTRL_REGS->PCGCR1 = 0x0000; /* Peripheral Clock Gating Configuration Register2 X X X X X X X X X X ANAREG DMA3 DMA2 DMA1 USB SAR LCD */ CSL_SYSCTRL_REGS->PCGCR2 = 0x0000; /* VERY IMPORTANT !!! */ /* PPMODE1 (SPI, GPIO, UART, and I2S2): 7 signals of the SPI module, 6 GPIO signals(GP[17:12]), 4 signals of the UART module, 4 signals of the I2S2 module SP1MODE2 (GP[11:6]). 6 GPIO signals (GP[11:6]) SP0MODE0 (MMC/SD0). All 6 signals of the MMC/SD0 */ CSL_SYSCTRL_REGS->EBSR = (CSL_SYS_EBSR_PPMODE_MODE1 << 12) |(CSL_SYS_EBSR_SP1MODE_MODE2 << 10) |(CSL_SYS_EBSR_SP0MODE_MODE0 << 8); asm(" bit(ST1, #ST1_INTM) = #1"); PLL_init(200000000); /* 100MHz */ INTR_init(); /* set Interrupt vector and clean all IRs */ TIMER_init(); /* Timer interrupt */ EZDSP5535_GPIO_init(); /* Enable GPIO LED */ // RTC_reset(); EZDSP5535_I2C_init(); /* Initialize I2C */ EZDSP5535_UART_init(); /* Initialize UART */ Audio_init(7); /* Initialise set to BandWidth=7kHz */ File_init(); EZDSP5535_LCD_init(); /* Initialise LCD */ LCD_print("G722.1 recorder", 0); LCD_print("start", 1); SCHEDULE_init(); BoardUSB_init(); asm(" bit(ST1, #ST1_INTM) = #0"); while(1) { while(taskList) { audioProcessing(); uartProcessing(); alarmProcessing(); usbProcessing(); } asm(" idle"); } }