Example #1
0
/* 81 */
int calc_init_81(LPCALC lpCalc, char *version) {
	/* INTIALIZE 81 */
	//v2 is basically an 82
	if (version[0] == '2') {
		memory_init_81(&lpCalc->mem_c);
		tc_init(&lpCalc->timer_c, MHZ_2);
		CPU_init(&lpCalc->cpu, &lpCalc->mem_c, &lpCalc->timer_c);
		ClearDevices(&lpCalc->cpu);
		device_init_83(&lpCalc->cpu, 1);
	} else {
		memory_init_81(&lpCalc->mem_c);
		tc_init(&lpCalc->timer_c, MHZ_2);
		CPU_init(&lpCalc->cpu, &lpCalc->mem_c, &lpCalc->timer_c);
		ClearDevices(&lpCalc->cpu);
		device_init_81(&lpCalc->cpu);
	
	}
	/* END INTIALIZE 81 */

#ifdef WINVER // FIXME: dirty cheater!
	lpCalc->flash_cond_break = (LPBREAKPOINT *) calloc(lpCalc->mem_c.flash_size, sizeof(LPBREAKPOINT *));
	lpCalc->ram_cond_break = (LPBREAKPOINT *) calloc(lpCalc->mem_c.ram_size, sizeof(LPBREAKPOINT *));
	if (version[0] == '2') {
		lpCalc->audio			= &lpCalc->cpu.pio.link->audio;
		lpCalc->audio->enabled	= FALSE;
		lpCalc->audio->init		= FALSE;
		lpCalc->audio->timer_c	= &lpCalc->timer_c;
	}
#endif
	return TRUE;
}
Example #2
0
struct Computer *createComputer() {
	struct Computer *computer = (struct Computer *) malloc(sizeof(struct Computer));

	// REFERENCES

	computer->screen = NULL;

	// OBJECTS
	
	CPU_init(&computer->cpu);
	computer->cpu.clockRate = 6000; // 6 Khz
	computer->cpu.interruptVectorTable = computer->ram.buffer + INT_VECTOR_TABLE_ADDR;
	computer->cpu.ram = &computer->ram;
	
	GPU_init(&computer->gpu);
	computer->gpu.refreshRate = 60; // 60 Hz
	computer->gpu.vram = computer->ram.buffer + VRAM_ADDR;
	
	RAM_init(&computer->ram);
	RAM_setAccess(&computer->ram, 0, RAM_SIZE, RAM_READ | RAM_WRITE);

	DMA_init(&computer->dma);
	computer->dma.ptrIO = computer->ram.buffer + IO_DMA_ADDR;
	computer->dma.ram = &computer->ram;
		
	return computer;
}
Example #3
0
/*  82 83 */
static BOOL calc_init_83(LPCALC lpCalc, char *os) {
	/* INTIALIZE 83 */
	memory_init_83(&lpCalc->mem_c);
	tc_init(&lpCalc->timer_c, MHZ_6);
	CPU_init(&lpCalc->cpu, &lpCalc->mem_c, &lpCalc->timer_c);
	ClearDevices(&lpCalc->cpu);
	if (lpCalc->model == TI_82) {
		if (memcmp(os, "19.006", 6)==0) {
			device_init_83(&lpCalc->cpu, 0);
		} else {
			device_init_83(&lpCalc->cpu, 1);
		}
	} else {
		device_init_83(&lpCalc->cpu, 0);
	}
	/* END INTIALIZE 83 */

#ifdef WINVER // FIXME: dirty cheater!
	lpCalc->flash_cond_break = (LPBREAKPOINT *) calloc(lpCalc->mem_c.flash_size, sizeof(LPBREAKPOINT *));
	lpCalc->ram_cond_break = (LPBREAKPOINT *) calloc(lpCalc->mem_c.ram_size, sizeof(LPBREAKPOINT *));
	lpCalc->audio			= &lpCalc->cpu.pio.link->audio;
	lpCalc->audio->enabled	= FALSE;
	lpCalc->audio->init		= FALSE;
	lpCalc->audio->timer_c	= &lpCalc->timer_c;
#endif
	return TRUE;
}
Example #4
0
File: acme.c Project: Jedzia/acm3
// guess what
int main(int argc, const char *argv[]) {
	// if called without any arguments, show usage info (not full help)
	if(argc == 1)
		show_help_and_exit();
	msg_stream = stderr;
	cliargs_init(argc, argv);
	DynaBuf_init();// inits *global* dynamic buffer - important, so first
	// Init platform-specific stuff.
	// For example, this could read the library path from an
	// environment variable, which in turn may need DynaBuf already.
	PLATFORM_INIT;
	// init some keyword trees needed for argument handling
	CPUtype_init();
	Outputfile_init();
	// handle command line arguments
	cliargs_handle_options(short_option, long_option);
	// generate list of files to process
	cliargs_get_rest(&toplevel_src_count, &toplevel_sources,
		"No top level sources given");
	// Init modules (most of them will just build keyword trees)
	ALU_init();
	Basics_init();
	CPU_init();
	Encoding_init();
	Flow_init();
	Input_init();
	Label_init();
	Macro_init();
	Mnemo_init();
	Output_init(fill_value);
	Section_init();
	if(do_actual_work())
		save_output_file();
	return(ACME_finalize(EXIT_SUCCESS));	// dump labels, if wanted
}
Example #5
0
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));

}
Example #6
0
void main (void){

    CPU_init();
    CPU_extCLK();

    // Get the id (even/odd)
    id_init();

    // Encoder input
    //fps_init();
    
    // uC synchro
    sync_init();

    // Leds!
    led_init();

    // Serial coms, over bluetooth
    serial_init();

    EnableInterrupts;


    /* --------- TEST ---------- *
    FTM2_setMod(0x0200); // clk/2**12 = bus/2**20
    FTM2_init(7); // bus/2**8
    
    FTM2_enableInterrupts(seg);

	SPI_init(SPI_BAUDS,SPI_MASTER|SPI_INVERTCLK);

    // Negated
    LED_OUT_EN = 0;
    LED_OUT_EN_PORT = 1;
    // Rising
    LED_OUT_CLK = 0;
    LED_OUT_CLK_PORT = 1;

    /* -------- /TEST ---------- */

    for(;;){
        // Polls for UART input
    	serial_update();
    	//__RESET_WATCHDOG();	/* feeds the dog */
    }
}
Example #7
0
/* 83+se 84+se */
int calc_init_83pse(LPCALC lpCalc) {
	/* INTIALIZE 83+se */
	memory_init_83pse(&lpCalc->mem_c);
	tc_init(&lpCalc->timer_c, MHZ_6);
	CPU_init(&lpCalc->cpu, &lpCalc->mem_c, &lpCalc->timer_c);
	ClearDevices(&lpCalc->cpu);
	device_init_83pse(&lpCalc->cpu);
	/* END INTIALIZE 83+se */
#ifdef WINVER // FIXME: dirty cheater!
	lpCalc->flash_cond_break = (LPBREAKPOINT *) calloc(lpCalc->mem_c.flash_size, sizeof(LPBREAKPOINT *));
	lpCalc->ram_cond_break = (LPBREAKPOINT *) calloc(lpCalc->mem_c.ram_size, sizeof(LPBREAKPOINT *));
	lpCalc->audio			= &lpCalc->cpu.pio.link->audio;
	lpCalc->audio->enabled	= FALSE;
	lpCalc->audio->init		= FALSE;
	lpCalc->audio->timer_c	= &lpCalc->timer_c;
#endif
	return 0;
}
Example #8
0
/* 84+ */
int calc_init_84p(LPCALC lpCalc) {
	/* INTIALIZE 84+ */
	memory_init_84p(&lpCalc->mem_c);
	tc_init(&lpCalc->timer_c, MHZ_6);
	CPU_init(&lpCalc->cpu, &lpCalc->mem_c, &lpCalc->timer_c);
	ClearDevices(&lpCalc->cpu);
	device_init_83pse(&lpCalc->cpu);
#ifdef WITH_BACKUPS
	init_backups();
#endif
	/* END INTIALIZE 84+ */

#ifdef WINVER // FIXME: dirty cheater!
	lpCalc->flash_cond_break = (breakpoint_t **) calloc(lpCalc->mem_c.flash_pages, PAGE_SIZE);
	lpCalc->ram_cond_break = (breakpoint_t **) calloc(lpCalc->mem_c.ram_pages, PAGE_SIZE);
	lpCalc->audio			= &lpCalc->cpu.pio.link->audio;
	lpCalc->audio->enabled	= FALSE;
	lpCalc->audio->init		= FALSE;
	lpCalc->audio->timer_c	= &lpCalc->timer_c;
#endif
	return 0;
}
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
//   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
Example #11
0
//#pragma vector=RESET_VECTOR
//#define PROGRAMDEBUG  1
int main(void)
{
  INT16U i,temp,second;
  INT16U count,oldDI;
  INT8U RUN;
  //RUNRECORD runlog;
  unsigned char old__second;
	unsigned char old__minute;
	unsigned char old__hour;
	unsigned char old__day;
	unsigned char minute_counter=0;
	//unsigned char hour_counter=0;
  unsigned int DI_Convert=0;

  char checkcode[6]="vh11+\0";
	char DI_C[4]="DI=\0";
	char d[5];

	unsigned int Prog_Circle=0;
	//unsigned char cps[]="DataTime=\0";
	INT8U DI_Alter=0;
  INT8U Save_Hourdata=0;
  INT8U Save_Daydata=0;

  //INT8U a[16]="123456789ABCDEF";
  //INT8U b[17];
   // INT8U c[3]={0xf8,0x10,0x10};
  INT8U checknum[7];
  /***********************************************
                     device initializing
  ************************************************/
  CPU_init();
  P4OUT |=BIT0;   //flash rst
  GPRS_POWERON;
  RealData.R_D.DO=0;
  DIInput();
	DOOutput(RealData.R_D.DO);
   init_lcd ();
   clrram();
   LCD_light_ON;
   disp_img(0x01e0+960,30,64,zimo240128);
   //MemoryClear(Modbustore,sizeof(Modbustore));
   Modbustore =0;
   MemoryClear(local_mma_H,sizeof(local_mma_H));
   MemoryClear(local_mma_D,sizeof(local_mma_D));
   MemoryClear(local_mma_M,sizeof(local_mma_M));//100504
   MemoryClear(dev_mma_D,sizeof(dev_mma_D));
   MemoryClear(dev_mma_H,sizeof(dev_mma_H));
   MemoryClear(dev_mma_M,sizeof(dev_mma_M));  //100504
   MemoryClear(Hour_COD_avg,sizeof(Hour_COD_avg));
   MemoryClear(Hour_B01_avg,sizeof(Hour_B01_avg));
	delay11(3200);
  //GPRS_POWEROFF;
 //test

#ifdef PROGRAMDEBUG
 char c[3]={0x00,0,0};
 char aa='A';
 FlashBufferWrite(c,"abcdefg",7,0);
 //c[0]=0xf0;
 //FlashBuffertoMemory(c,0);
 Delay_N_mS(20000);
 c[0]=0;
 FlashBufferRead(c,checknum,5,0);
 checknum[0]=0;

 c[0]=0xf0;
 FlashMemorytoBuffer(c,0);
 c[0]=0;
 FlashBufferRead(c,checknum,5,0);
 checknum[0]=0;
 c[0]=0xf0;
 FlashMemoryRead(c,checknum,5);
 //FlashMemoryWrite(c,checkcode,5,0);
 Delay_N_mS(20000);
   //c[2]=0x05;
 //FlashMemoryWrite(c,&aa,1,0);
 Delay_N_mS(20000);
 c[2]=0;
 FlashMemoryRead(c,checknum,5);
#endif
 //---------------------------
 /****************************************************
                  system initializing
 ****************************************************/
 AT24C64_RS(checknum,0x00,6);
 Delay_N_mS(2000);
 AT24C64_RS(checknum,0x00,6);
 if(strcmp(checknum,checkcode)!=0)
	{
    v_charge1302();
		v_Set1302();
		
		for(count=0;count<6;count++)
			SPARA.pw[count]=(count+1)|0x30;  //初始密码123456
		
		for(count=0;count<9;count++)
		{
			SPARA.mn[count]=(count+1)|0x30;  //mn 12345678901234
			ml_mn[count]=parameter.sys_parameter.mn[count];
		}
			
		for(count=0;count<5;count++)
		{
			SPARA.mn[count+9]=count|0x30;
			ml_mn[count+9]=parameter.sys_parameter.mn[count+9];
		}
		
		SPARA.st[0]='3';             //st 32
		SPARA.st[1]='2';
		ml_st[0]='3';
		ml_st[1]='2';
		for(count=0;count<9;count++)
			SPARA.sim[count]=(count+1)|0x30;  //sim 123456789
		
		SPARA.rd_interval[0]='3';     //实时数据上报时间 60秒
		SPARA.rd_interval[1]='0';
		SPARA.rd_interval[2]='0';
		
		for(count=0;count<5;count++)
			SPARA.overtime[count]='0';    //超时时间 5秒
		SPARA.overtime[4]='5';
		SPARA.resendtime[0]='0';		//重发次数 3次
		SPARA.resendtime[1]='3';
		for(count=0;count<5;count++)
			SPARA.warntime[count]='0';    //报警时间 5
		SPARA.warntime[4]='5';
		
		for(count=0;count<4;count++)
			SPARA.reporttime[count]='0';	//上报时间 5
		SPARA.reporttime[3]='5';
		for(count=0;count<2;count++)
			SPARA.alarmtarge[count]=0x30+count;		//仪表污染物编号
		SPARA.alarmtarge[2]='\0';
		SPARA.alarmtarge[3]='\0';
							
		for(count=0;count<8;count++)
		{
			//ADPARA(count).po_id[0]='P';
			//ADPARA(count).po_id[1]=0x31+count;
			//ADPARA(count).po_id[2]='\0';
                        ADPARA(count).po_id[0]='0';
			ADPARA(count).po_id[1]='0';
			ADPARA(count).po_id[2]='0';
			ADPARA(count).ADUV.b=16.0;
			ADPARA(count).ADLV.b=0.0;
			ADPARA(count).U_Alarmlimt.b=10.0;
			ADPARA(count).L_Alarmlimt.b=0.0;
			ADPARA(count).rate.b=(16.0-0.0)/0x666;
					
			ADPARA(count).AI_Type=2;
			
		}
    for(count=0;count<6;count++)
    SPARA.Serial_Baud[count]=0;
		//LCD_Baud=0;
		for(checknum[0]=0;checknum[0]<6;checknum[0]++)
			for(count=0;count<16;count++)
				SPARA.PO_SerialNum[checknum[0]][count]=0xff;		

    SPARA.PO_SerialNum[0][0]=0x05;
		
    for(count=0;count<6;count++)
		{
			SPARA.PO_Type[count]=0;
			Channel_Num[count]=0;
		}
    SPARA.PO_Type[0]=1; //水,哈希
			Channel_Num[0]=1;
		SPARA.alarmtarge[10]=0;//baud rate
    SPARA.LCD_Backtime=1;
		
		AT24C64_W(parameter.sys_setting,0x10,sizeof(PARAMETER));	
                /*初始化历史数据标志组结构体,存储于Flash第一页(页地址0x00)*/
                INT8U  Rdaddr[3]={0,0,0};
                INT16U pageaddr=0;
                HISDATAFLAGS Sighisdata;
                MemoryClear(&Sighisdata,sizeof(Sighisdata));
                for(count=0;count<7;)
                {
                  Sighisdata.page =0x10+count*31*24;
                  Rdaddr[1]=(INT8U)(pageaddr>>8);
                  Rdaddr[2]=(INT8U)(pageaddr);
                  FlashBufferWrite(Rdaddr,&Sighisdata,sizeof(Sighisdata),FLASHBUFFER1);
                  FlashBufferWrite(Rdaddr,&Sighisdata,sizeof(Sighisdata),FLASHBUFFER1);
                  count++;
                  pageaddr=count*120;
                }
                Rdaddr[0]=0;
                Rdaddr[1]=0;
                Rdaddr[2]=0;
                FlashBuffertoMemory(Rdaddr,FLASHBUFFER1);

                HISDATAFLAGS_D sig_d;
                pageaddr=0;
                MemoryClear(&sig_d,sizeof(sig_d));
                for(count=0;count<13;)
                {
                  sig_d.page =5400+count*31;
                  Rdaddr[0]=0;
                  Rdaddr[1]=((INT8U)(pageaddr>>8))|0x28;  //page 5
                  Rdaddr[2]=(INT8U)(pageaddr);
                  FlashBufferWrite(Rdaddr,&sig_d,sizeof(sig_d),FLASHBUFFER1);
                  count++;
                  pageaddr=count*80;
                }
                Rdaddr[0]=0;
                Rdaddr[1]=0x28;
                Rdaddr[2]=0;
                FlashBuffertoMemory(Rdaddr,FLASHBUFFER1);

                HISDATAFLAGS_R sig_r;
                MemoryClear(&sig_r,sizeof(sig_r));
                pageaddr=0;
                for(count=0;count<3;)
                {
                  sig_r.page =6000+count*24*12;
                  Rdaddr[0]=0;
                  Rdaddr[1]=((INT8U)(pageaddr>>8))|0x50;
                  Rdaddr[2]=(INT8U)(pageaddr);
                  FlashBufferWrite(Rdaddr,&sig_r,sizeof(sig_r),FLASHBUFFER1);
                  count++;
                  pageaddr=count*200;
                }
                Rdaddr[0]=0;
                Rdaddr[1]=0x50; // page 10
                Rdaddr[2]=0;
                FlashBuffertoMemory(Rdaddr,FLASHBUFFER1);
                
                //运行日志存储于8190页(1FFE)
                RUNRECORD runlog;
                MemoryClear(&runlog,sizeof(runlog));
                pageaddr=0; 
                for(count=0;count<10;count++)
                {
                  pageaddr=count*64;
                  Rdaddr[0]=0xff;
                  Rdaddr[1]=((INT8U)(pageaddr>>8))|0xf0;
                  Rdaddr[2]=(INT8U)(pageaddr);
                  FlashBufferWrite(Rdaddr,&runlog,sizeof(runlog),FLASHBUFFER1);
                }
                Rdaddr[0]=0xff;
                Rdaddr[1]=0xf0;
                Rdaddr[2]=0;
                FlashBuffertoMemory(Rdaddr,FLASHBUFFER1);
                
                //Sighisdata.page =0;
                //FlashBufferWrite(Rdaddr,&Sighisdata,sizeof(Sighisdata),FLASHBUFFER1);
		AT24C64_W(checkcode,0x00,6);


	}
Example #12
0
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));
    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);
    }

}
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");
    }
}
Example #15
0
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++)
        {
        }
    }
}