Direct copy of source code from "MOD5270 PIT Application Note"
(http://www.netburner.com/downloads/mod5 ... 70-PIT.pdf) to Source window of NBEclipse IDE Rel23_RC7a - results in error message "Cannot save..." due to exotic characters.
Due to "attach file" is failed, below is content of main.cpp file after fixing the code page issues and reformatting.
_______________________________
/*********************************************************************
* This example program exercises the programmable interrupt timer *
* the MCF5270 CPU. *
*********************************************************************/
#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <smarttrap.h>
#include <taskmon.h>
#include <..\MOD5270\system\sim5270.h>
#include <cfinter.h>
#include <utils.h>
#include <pins.h>
//
// Function prototypes - Instruct the C++ compiler not to mangle the
// function names
//
extern "C"
{
void UserMain( void *pd );
//
// This function sets up the 5270 interrupt controller
//
void SetIntc( long func, int vector, int level, int prio );
}
const char *AppName = "MOD5270 PIT Example"; // App name for IPSetup
volatile DWORD pitr_count; // Global count variable
///////////////////////////////////////////////////////////////////////
// INTERRUPT - PIT interrupt service routine
//
INTERRUPT( my_pitr_func, 0x2600 )
{
static WORD led_count; // For incrementing carrier board LEDs
WORD tmp = sim.pit[1].pcsr; // Get PIT1 Control & Status Register data
// Clear PIT1 - Refer to table 21-3 for more information on what
// bits are being cleared and set
//
tmp &= 0xFF0F; // Bits 4-7 cleared
tmp |= 0x0F; // Bits 0-3 set
sim.pit[1].pcsr = tmp;
//
// You can add you ISR code here
// - Do not call any RTOS function with pend or init in the function
// name
// - Do not call any functions that perform a system I/O read,
// write, printf, iprintf, etc.
//
putleds( led_count++ ); // Increment carrier board LEDs
pitr_count++; // Increment when an interrupt occurs
//
// Toggle MOD5270 pin J2-48 to view the interrupts on an
// oscilloscope. One cycle will be twice the time period. This
// feature uses the NetBurner Pins Class, so you need to include
// pins.h.
//
if ( J2[48] ) {
J2[48] = 0;
}
else {
J2[48] = 1;
}
}
///////////////////////////////////////////////////////////////////////
// SetUpPITR PIT - setup function. See chapter 21 of the 5271 reference
// manual for details
//
void SetUpPITR( int pitr_ch, WORD clock_interval, BYTE pcsr_pre /* See
table 21-3 in the reference manual for bits 8-11 */ )
{
WORD tmp;
if ( ( pitr_ch < 1 ) || ( pitr_ch > 3 ) )
{
iprintf( "*** ERROR - PIT channel out of range ***\r\n" );
return;
}
//
// Populate the interrupt vector in the interrupt controller. The
// SetIntc() function is supplied by the NetBurner API to make the
// interrupt control register configuration easier
//
SetIntc( ( long ) &my_pitr_func, 36 + pitr_ch, 2 /* IRQ2 */, 3 );
//
// Configure the PIT for the specified time values
//
sim.pit[pitr_ch].pmr = clock_interval; // Set PIT modulus value
tmp = pcsr_pre;
tmp = ( tmp << 8 ) | 0x0F;
sim.pit[pitr_ch].pcsr = tmp; // Set system clock divisor to 16 and
// set bits [3:0] in PCSR
}
///////////////////////////////////////////////////////////////////////
// UserMain
//
void UserMain( void *pd )
{
InitializeStack();
if ( EthernetIP == 0 ) GetDHCPAddress();
OSChangePrio( MAIN_PRIO );
EnableAutoUpdate();
EnableSmartTraps();
EnableTaskMonitor();
//
// Let us make PIT happen at 1000 Hz. The base clock is
// 147,456,000 Hz, so the equation is:
//
// System_Clock_Frequency / 2
// PMR Value = ------------------------------- - 1
// Prescalar * Desired_Frequency
//
// 147456000 / 2
// PMR Value = ---------------- - 1
// 16 * 1000
//
// PMR Value = 4607
//
// Note that the PIT Count Register is a 16-bit counter, so the
// clock count maximum is 65,535
//
SetUpPITR( 1 /* Use PIT1 */, 4607 /* Wait 4607 clocks */, 4 /*
Divide by 16 from table 21-3 (2^4) */ );
iprintf( "Application started\r\n" );
pitr_count = 0;
while ( 1 )
{
OSTimeDly( TICKS_PER_SECOND );
iprintf( "PITR Count = %ld\r\n", pitr_count );
}
}
Code is incorrectly pasted from pdf of application note
Code is incorrectly pasted from pdf of application note
Yevgeni Tunik
Embedded/RealTime software engineer
https://www.linkedin.com/in/yevgenitunik/
________________________
Embedded/RealTime software engineer
https://www.linkedin.com/in/yevgenitunik/
________________________