original files of m241

This commit is contained in:
neelimap
2026-07-30 11:19:44 +05:30
parent 170c2b3f3a
commit afc7070c1f
12254 changed files with 7655111 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
# Makefile - makefile for building demos
#
# Copyright (c) 1996-2006 Wind River Systems, Inc.
#
# The right to copy, distribute, modify or otherwise make use
# of this software may be licensed only pursuant to the terms
# of an applicable Wind River license agreement.
#
# modification history
# --------------------
# 01g,18nov06,lei added color and smp to SUBDIRS
# 01f,18aug05,pee added rdepend target to support top level rdepend
# 01e,02dec97,jmp added synopsis rules to avoid top level synopsis build
# failure.
# 01d,20feb97,jank use $(MAKE) -C color intead of (cd color; ...)
# 01c,06nov96,yp added TGT_DIR support, brought default to top
# 01b,04nov96,p_m added man rule to avoid top leval man build to stop.
# 01a,18jun96,yp created from 01c of MakeSkel
#
# DESCRIPTION
# This file contains the makefile rules for building the demo objects
#
#*/
TGT_DIR= $(WIND_BASE)/target
CPU=MC68020
TOOL=gnu
SUBDIRS = color smp
include $(TGT_DIR)/h/make/rules.library
#default:
# $(MAKE) -C color CPU=$(CPU) TOOL=$(TOOL) TGT_DIR=$(TGT_DIR)
#rclean:
# $(MAKE) -C color CPU=$(CPU) TOOL=$(TOOL) TGT_DIR=$(TGT_DIR) clean
#rdepend:
# $(MAKE) -C color CPU=$(CPU) TOOL=$(TOOL) TGT_DIR=$(TGT_DIR) depend
#man:
#synopsis:
#clean_synopsis:
#release : default
+111
View File
@@ -0,0 +1,111 @@
/* b_ball.h - class declarations for the ball demo */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#if !defined( _BALL_H )
#define _BALL_H
/****************************************************************
A point or position in the grid.
A point has coordinates and can be added to another point.
****************************************************************/
class POINT
{
public:
int x;
int y;
POINT operator +( POINT );
POINT( int, int );
POINT();
};
typedef class POINT POINT;
/****************************************************************
A generic ball. Each ball has a position and a vector of
change for the next move.
Each ball is on two linked lists. The first is the link
of all ball objects and the second is of all ball objects
at the same grid position.
Each ball can Move(), determine collisions of incoming
balls (Collide()), and affect the change vector of
incoming balls (Bounce()). Specific ball types can
override the default functions in order to provide
unique balls on the grid. (spinning, hard, soft, etc. )
****************************************************************/
class BALL
{
BALL *grid_next; // link to next ball at same position
BALL *grid_prev; // link to previous ball at same position
POINT position; // position of ball on the grid
POINT change; // change vector of the ball
public:
BALL *Next(); // get next ball on the grid list
BALL *Previous(); // get previous ball on the grid list
void Next( BALL * ); // set pointer to next ball on the grid list
void Previous( BALL * ); // set pointer to previous ball on the grid list
static BALL *list; // list of all balls on the grid.
BALL *next; // pointer to next ball on the list
BALL(); // standard constructor
BALL(int); // constructor for balls not on the list of balls to move
virtual char Show(); // return character to show for this ball type.
virtual void Move(); // move the ball
virtual int Collide(); // answer query for whether collision affects incoming change vector
virtual POINT Bounce( POINT & ) = 0; // change the incoming vector
};
/****************************************************************
Width and height of the grid on which the bouncing balls
will be shown.
****************************************************************/
#define WIDTH 16
#define HEIGHT 10
/****************************************************************
A LIST object represents a list of balls. It is used
at each position of the grid to keep track of the
balls at each position.
****************************************************************/
class LIST
{
BALL *head;
BALL *last;
public:
LIST();
void Add( BALL * );
void Remove( BALL * );
void Init();
BALL *First();
BALL *Last();
};
/****************************************************************
The grid represents the collection of all balls which
are the walls or are moving.
****************************************************************/
class GRID
{
char data [ HEIGHT ][ WIDTH ]; // characters representing the balls
LIST balls[ HEIGHT ][ WIDTH ]; // lists of balls at each position
public:
GRID();
void Add( BALL *, const POINT & ); // add ball to grid at specified position
void Delete( BALL *, POINT & ); // delete ball from specified position
int Check( POINT & ); // is there a ball a specified position?
BALL *Ball( POINT & ); // return the ball at specified position
} ;
extern GRID grid; // the grid itself
#endif
+162
View File
@@ -0,0 +1,162 @@
/* b_grid.cpp - implements the grid, list and wall objects */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
/****************************************************************
Grid and List functionality for the ball program.
****************************************************************/
#include "b_ball.h"
#include "b_wall.h"
GRID grid;
/****************************************************************
Grid constructor: Initialize data area, balls, and walls.
****************************************************************/
GRID::GRID()
{
int r, c;
for( r = 0; r < HEIGHT; r++ )
{
for( c = 0; c < WIDTH; c++ )
{
data[ r ][ c ] = ' ';
balls[ r ][ c ].Init();
}
}
for( r = 0; r < HEIGHT; r++ )
{
Add( new WALLX(0), POINT(0, r) );
Add( new WALLX(0), POINT(WIDTH - 1, r) );
}
for( c = 0; c < WIDTH; c++ )
{
Add( new WALLY(0), POINT( c, 0 ) );
Add( new WALLY(0), POINT( c, HEIGHT - 1 ) );
}
}
/****************************************************************
Add ball to the grid at specified point.
****************************************************************/
void GRID::Add( BALL *bp, const POINT &pt )
{
balls[pt.y][pt.x].Add( bp );
data[ pt.y ][ pt.x ] = bp -> Show();
}
/****************************************************************
Delete ball from the grid at specified point.
****************************************************************/
void GRID::Delete( BALL *bp, POINT &pt )
{
balls[pt.y][pt.x].Remove( bp );
if( balls[pt.y][pt.x].First() == 0 )
data[ pt.y ][ pt.x ] = ' ';
else
data[ pt.y ][ pt.x ] = balls[ pt.y][pt.x].First() -> Show();
}
/****************************************************************
Get the first ball from the grid at specified point.
****************************************************************/
BALL *GRID::Ball( POINT &pt )
{
return balls[pt.y][pt.x].First();
}
/****************************************************************
Return nonzero if balls exist in grid at specified point.
****************************************************************/
int GRID::Check( POINT &pt )
{
return balls[pt.y][pt.x].First() != 0;
}
/****************************************************************
List functionality.
****************************************************************/
void LIST::Init()
{
head = last = 0;
}
LIST::LIST()
{
Init();
}
BALL *LIST::First()
{
return head;
}
BALL *LIST::Last()
{
return last;
}
void LIST::Add( BALL *bp )
{
bp -> Next( 0 );
bp -> Previous( last );
if( last )
last = bp;
else
{
head = last = bp;
}
}
void LIST::Remove( BALL *bp )
{
if( bp -> Next() )
bp -> Next() -> Previous( bp -> Previous() );
else
last = bp -> Previous();
if( bp -> Previous() )
bp -> Previous() -> Next( bp -> Next() );
else
head = bp -> Next();
}
/****************************************************************
Wall functionality.
****************************************************************/
POINT WALLX::Bounce( POINT &pt )
{
return POINT( -pt.x, pt.y );
}
char WALLX::Show()
{
return '|';
}
WALLX::WALLX( int x ) : HARD(x) {}
POINT WALLY::Bounce( POINT &pt )
{
return POINT( pt.x, -pt.y );
}
char WALLY::Show()
{
return '-';
}
WALLY::WALLY( int x ) : HARD(x) {}
+26
View File
@@ -0,0 +1,26 @@
/* b_hard.h - class declarations for the hard object */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#include "b_ball.h"
/****************************************************************
A hard ball deflects the incoming ball. It has a special
constructor so that walls made from hard balls can be created
and not put on the list of balls to move.
****************************************************************/
class HARD : public BALL
{
public:
HARD();
HARD(int );
int Collide();
virtual char Show();
virtual POINT Bounce( POINT & );
};
+200
View File
@@ -0,0 +1,200 @@
/* b_main.cpp - implements the bouncing ball demo */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
/****************************************************************
This is the bouncing ball C++ demo program.
You can watch "grid.data" to see the bouncing balls as you step.
****************************************************************/
#include <stdlib.h>
#include "b_soft.h"
#include "b_hard.h"
#include "b_spin.h"
#include "b_ball.h"
int finished = 0;
int num_hard = 2;
int num_soft = 2;
int num_spin = 2;
int main()
{
int i;
for( i = 0; i < num_soft; i++ )
new SOFT;
for( i = 0; i < num_hard; i++ )
new HARD;
for( i = 0; i < num_spin; i++ )
new SPIN;
while( ! finished )
{
for( BALL *p = BALL::list; p; p = p -> next )
p -> Move();
}
return 0;
}
/****************************************************************
Hard ball characteristics.
****************************************************************/
int HARD::Collide()
{
return 1;
}
POINT HARD::Bounce( POINT &pt )
{
return POINT( -pt.x, -pt.y );
}
char HARD::Show()
{
return '*';
}
HARD::HARD(){}
HARD::HARD( int x ) : BALL(x) {}
/****************************************************************
Soft ball characteristics.
****************************************************************/
//int SOFT::Collide()
//{
// return 0;
//}
char SOFT::Show()
{
return 'O';
}
/****************************************************************
Spinning ball characteristics.
****************************************************************/
int SPIN::Collide()
{
return 1;
}
POINT SPIN::Bounce( POINT &pt )
{
return POINT( pt.y, -pt.x );
}
char SPIN::Show()
{
return '@';
}
/****************************************************************
General ball functionality.
****************************************************************/
char BALL::Show()
{
return '@';
}
BALL::BALL( int )
{
grid_next = grid_prev = 0;
}
BALL::BALL()
{
next = list;
list = this;
position.x = ( rand() % ( WIDTH - 2 ) ) + 1;
position.y = ( rand() % ( HEIGHT - 2 ) ) + 1;
change.x = ( rand() % 3 ) - 1;
change.y = ( rand() % 3 ) - 1;
grid_next = grid_prev = 0;
grid.Add( this, position );
}
BALL *BALL::list;
int BALL::Collide()
{
return 0;
}
void BALL::Move()
{
POINT new_position;
new_position = position + change;
if( grid.Check( new_position ) )
{
if( grid.Ball( new_position ) -> Collide() )
{
change = grid.Ball( new_position ) -> Bounce( change );
new_position = new_position + change;
}
}
grid.Delete( this, position );
position = new_position;
grid.Add( this, position );
}
BALL * BALL::Next()
{
return grid_next;
}
void BALL::Next( BALL *bp )
{
grid_next = bp;
}
BALL * BALL::Previous()
{
return grid_prev;
}
void BALL::Previous( BALL *bp )
{
grid_prev = bp;
}
/****************************************************************
Point functionality.
****************************************************************/
POINT::POINT( int a, int b )
{
x = a;
y = b;
}
POINT::POINT()
{
x = 0;
y = 0;
}
POINT POINT::operator+( POINT pt )
{
POINT retval( pt.x, pt.y );
retval.x = x + pt.x;
retval.y = y + pt.y;
while( retval.x < 0 )
retval.x += WIDTH;
while( retval.y < 0 )
retval.y += HEIGHT;
retval.x %= WIDTH;
retval.y %= HEIGHT;
return retval;
}
+25
View File
@@ -0,0 +1,25 @@
/* b_soft.h - class declarations for the soft object */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#include "b_ball.h"
/****************************************************************
A soft ball does not affect anything colliding with it.
i.e. the incoming vector of change is not affected.
Soft balls can bounce off of walls.
****************************************************************/
class SOFT : public BALL
{
public:
//int Collide();
POINT Bounce( POINT & pt ){return pt; }
char Show();
};
+22
View File
@@ -0,0 +1,22 @@
/* b_spin.h - class declarations for the spin object */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#include "b_ball.h"
/****************************************************************
A spinnin ball deflects the incoming ball and turns it.
****************************************************************/
class SPIN : public BALL
{
public:
int Collide();
virtual char Show();
virtual POINT Bounce( POINT & );
};
+35
View File
@@ -0,0 +1,35 @@
/* b_wall.h - class declarations for wall objects */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#include "b_hard.h"
/****************************************************************
A wall in the X direction is a vertical wall that deflects
balls by changing the X component of their change vector.
****************************************************************/
class WALLX : public HARD
{
public:
WALLX(int);
POINT Bounce( POINT & );
char Show();
};
/****************************************************************
A wall in the Y direction is a horizontal wall that deflects
balls by changing the Y component of their change vector.
****************************************************************/
class WALLY : public HARD
{
public:
WALLY(int);
POINT Bounce( POINT & );
char Show();
};
@@ -0,0 +1,2 @@
project.type=DownloadableKernelModuleProject
platform.id=VxWorks
@@ -0,0 +1,17 @@
The Ball Demonstration Program
-------------------------------
The Ball program simulates a series of bouncing balls. A
variable named "grid" displays as a two-dimensional grid on
which the balls bounce. The balls are represented using an array
of ASCII characters.
Three kinds of balls are simulated:
* *A soft ball:* This ball bounces off walls. The soft ball does
not affect the other balls it collides with. The soft ball is
represented by the character '0'.
* *A hard ball:* This ball deflects any ball it collides with. It is
represented by the character '*'.
* *A spinning ball:* This ball deflects and turns any ball it collides with.
It is represented by the character '@'.
+121
View File
@@ -0,0 +1,121 @@
/* addone.s - Assembly routine to increment a passed in value */
/*
* Copyright (c) 2004-2006, 2011 Wind River Systems, Inc.
*
* The right to copy, distribute or otherwise make use of this software
* may be licensed only pursuant to the terms of an applicable Wind River
* license agreement. No license to Wind River intellectual property rights
* is granted herein. All rights not licensed by Wind River are reserved
* by Wind River.
*/
/*
modification history
--------------------
01g,19jan11,pee WIND00251395
01f,07jan11,mcm Added support for X86_64
01e,25apr06,rec added coldfire support (SPR-117923)
01d,01feb05,h_k added SH and ARM support. (SPR #105984)
01c,15nov05,gvm Fix for SPR102730: using C style comments for SIMSPARCSOLARIS
01b,08nov04,pes added #include "asm.h"
01a,07oct04,f_b added
*/
#define _ASMLANGUAGE
#include <vxWorks.h>
#ifndef _VX_CPU_FAMILY
#error build error: -DVX_CPU=yourCPU missing
#endif
#include "asm.h"
.text
.align 4
/*
* Increment the passed in parameter by one.
*/
#if (_VX_CPU_FAMILY == _VX_PPC)
.globl addone
addone:
addi r3,r3,1 # increment parameter...
bclr 20,0 # go back
#elif (_VX_CPU_FAMILY == _VX_SIMNT || _VX_CPU_FAMILY == _VX_SIMLINUX || \
_VX_CPU_FAMILY == _VX_SIMPENTIUM || _VX_CPU_FAMILY == _VX_I80X86 )
.globl addone
addone:
#if defined(_WRS_CONFIG_LP64)
movl %edi, %eax
addl $1, %eax
#else
movl 4(%esp), %eax
incl %eax
#endif
ret
#elif (_VX_CPU_FAMILY==_VX_SIMSPARCSUNOS || \
_VX_CPU_FAMILY==_VX_SIMSPARCSOLARIS)
#include "arch/simsolaris/asmSimsolaris.h"
.global GTEXT(addone)
FUNC_LABEL(addone)
retl /* deferred return, return value follows */
add %o0,1,%o0 /* increment parameter... */
#elif (_VX_CPU_FAMILY==_VX_MIPS)
.globl addone
.ent addone
addone:
addi v0, a0, 1 # increment parameter...
jr ra
nop
.end addone
#elif (_VX_CPU_FAMILY==_VX_SH)
.global GTEXT(addone)
FUNC_LABEL(addone)
mov r4,r0
rts
add #1,r0
#elif (_VX_CPU_FAMILY==_VX_ARM)
.globl FUNC(addone)
_ARM_FUNCTION_CALLED_FROM_C(addone)
ADD r0, r0, #1
#if (ARM_THUMB)
BX lr
#else
MOV pc, lr
#endif
#elif (_VX_CPU_FAMILY==_VX_COLDFIRE)
/* externals */
.text
.globl FUNC(addone)
FUNC_LABEL(addone)
movel a7@(SP_ARG1), d0 /* argument passed */
addql #1, d0 /* increment */
rts
#else
#error Unknown VX_CPU Family
#endif
@@ -0,0 +1,305 @@
/* calendar.c - implements general calender functions */
/*
* Copyright (c) 2004, 2011 Wind River Systems, Inc.
*
* The right to copy, distribute or otherwise make use of this software
* may be licensed only pursuant to the terms of an applicable Wind River
* license agreement. No license to Wind River intellectual property rights
* is granted herein. All rights not licensed by Wind River are reserved
* by Wind River.
*/
/*
modification history
--------------------
01b,07jan11,mcm Added support for X86_64
01a,07oct04,f_b added
*/
#include "strutils.h"
/*
* Local Defines
*/
#define TWELVE_MONTHS 12 /* General Defines */
#define STRING_MATCH 0
#define LEGITIMATE_DAYNUM 0
#define INITIALIZED 0x1234
/*
* Global Definitions
*/
struct month{ /* Array of 'month' structs */
char *monthName; /* (the values are for 1997) */
short numOfDays;
char *startDay;
} MONTH[] = {
{"January", 31, "Wednesday"},
{"February", 28, "Saturday" },
{"March", 31, "Saturday" },
{"April", 30, "Tuesday" },
{"May", 31, "Thursday" },
{"June", 30, "Sunday" },
{"July", 31, "Tuesday" },
{"August", 31, "Friday" },
{"September",30, "Monday" },
{"October", 31, "Wednesday"},
{"November", 30, "Saturday" },
{"December", 31, "Monday" }
};
struct year { /* year struct for 1997 */
char *yearName; /* string title */
struct month *month; /* pointer to array of month structs */
short initId; /* initialization indicator */
} year1997;
struct date {
char *monthName;
short date;
};
struct date glbMonthDate; /* global monthDate struct */
/*
* Forward References/Prototypes
*/
int dayOfYear( struct date * );
int dateForDayNum( int, struct date * );
int daysBetween(struct date *,struct date *);
/*
* External References
*/
int abs( int );
/***********************************************************************
* Function: calendar()
* Description: Illustrates some general calendar functions.
************************************************************************/
int calendar( int callParm )
{
volatile char *temp;
volatile short days;
volatile int status;
volatile int dayNumber, numOfDays;
struct date firstDate, secondDate; /* Local month date structures */
struct date lclMonthDate;
/*
* Initialize the year1997 structure
*/
year1997.yearName = "1997";
year1997.month = &MONTH[0];
year1997.initId = INITIALIZED;
/*
* Setup 'temp' and 'days', useful to use as watch-window variables while stepping through the
* next set of instructions to illustrate how the structure is arranged.
*/
temp = year1997.yearName;
temp = year1997.month[0].monthName;
days = year1997.month[0].numOfDays;
temp = year1997.month[0].startDay;
temp = year1997.month[4].monthName;
days = year1997.month[4].numOfDays;
temp = year1997.month[4].startDay;
temp = year1997.month[10].monthName;
days = year1997.month[10].numOfDays;
temp = year1997.month[10].startDay;
/*
* Given a specific date, determine the 'day of the year'.
* For example, January 1, is day number one, December 31 is
* day 365 in 1997. If dayOfYear() returns a -1, then the year1997 structure
* was never properly initialized, that is, an error condition.
*/
glbMonthDate.monthName = "January";
glbMonthDate.date = 15;
dayNumber = dayOfYear( &glbMonthDate );
glbMonthDate.monthName = "October";
glbMonthDate.date = 13;
dayNumber = dayOfYear( &glbMonthDate );
glbMonthDate.monthName = "WINDober"; /* error case */
glbMonthDate.date = 30;
dayNumber = dayOfYear( &glbMonthDate );
/*
* Do the inverse operation of the operation above, that is,
* given a specific 'day number', calculate the month and day.
* For example, for day number 16, dateForDayNum returns
* January, 16th. This function returns a 'status' that indicates
* if the date argument is legal. The month information is returned
* via the lclMonthDate argument.
*/
dayNumber = 134; /* getting date for a legal day number */
status = dateForDayNum( dayNumber, &lclMonthDate );
/*
* The locals window view of 'status' shows a valid dayNumber arugmnet.
* Also, either view the contents of lclMonthDate or view
* the temp and days variables below.
*/
temp = lclMonthDate.monthName;
days = lclMonthDate.date;
/*
* Try an invalid day number and check status in the local window.
*/
dayNumber = 366;
status = dateForDayNum( dayNumber, &lclMonthDate );
/*
* Given two dates, calculate the number of days between them,
* excluding the boundary dates. For example, the number of days
* between January 1 and January 3, is one day, excluding the boundary dates.
*/
firstDate.monthName = "June";
firstDate.date = 17;
secondDate.monthName = "September";
secondDate.date = 23;
numOfDays = daysBetween( &firstDate, &secondDate );
return ((int) *temp);
}
/***********************************************************************
* Function: dayOfYear()
* Description: return the 'day number' given a month's day date.
************************************************************************/
int dayOfYear( struct date *monthDate )
{
int n, daySum, status;
/*
* Insure that the year1997 has been initialized, if not
* just return an error status.
*/
if ( year1997.initId != INITIALIZED )
return -1;
/*
* Find the month in the global year1997 structure
*/
for ( n=0, daySum=0; n < TWELVE_MONTHS ;n++ )
{
/*
* From the beginning of the year, accumulate the number of days
* in each month until the month name string argument matches
* the 1997 month string. Then then add in the month date argument
* to the running 1997 month total.
*/
status = strcmp( monthDate->monthName, year1997.month[n].monthName );
if ( status == STRING_MATCH )
{
/*
* Now add in the day offset. Check the desired date to
* insure it lies within the month. If not then return an error.
*/
if ( monthDate->date <= year1997.month[n].numOfDays )
{
daySum += monthDate->date;
break; /* break out of for( ) loop */
}
else
return -1;
}
else
daySum = daySum + year1997.month[n].numOfDays;
}
/*
* Check that the desired month was found in the above
* for() loop. If not return an error.
*/
daySum = ( n >= TWELVE_MONTHS ) ? -1 : daySum;
return daySum;
}
/***********************************************************************
* Function: dateForDayNum()
* Description: Returns month information given a specific day-number.
************************************************************************/
int dateForDayNum( int dayNumber, struct date *monthDate )
{
int n;
int badstatus = -1;
/*
* Check the dayNumber to make sure it's legal, returning an error if
* out of range.
*/
if ((dayNumber < 0) || (dayNumber > 365))
return badstatus;
/*
* Find the month for the dayNumber, implemented by subtracting off the number
* of days when cycling through the months until dayNumber is less than or equal to
* the new dayNumber.
*/
for ( n=0; n < TWELVE_MONTHS ;n++ )
{
if ( dayNumber > year1997.month[n].numOfDays )
dayNumber -= year1997.month[n].numOfDays;
else
break;
}
/*
* Make sure we have a reasonable answer.
*/
if ( n >= TWELVE_MONTHS )
return badstatus;
/*
* It looks like we found the month.
*/
monthDate->monthName = year1997.month[n].monthName;
monthDate->date = (short)dayNumber;
return LEGITIMATE_DAYNUM;
}
/***********************************************************************
* Function: daysBetween()
* Description: Returns the number of days between two given dates.
***********************************************************************/
int daysBetween( struct date *firstDate, struct date *secondDate )
{
int numOfDays;
int dayNum1, dayNum2;
/*
* Use 'dayOfYear()' function to calculate
* the number of days between the two date arguments.
*/
dayNum1 = dayOfYear( firstDate );
dayNum2 = dayOfYear( secondDate );
/*
* Validate both arguments.
*/
if ((dayNum1 == -1) || (dayNum2 == -1))
numOfDays = -1;
else
numOfDays = abs( dayNum2 - dayNum1 );
return numOfDays;
}
+84
View File
@@ -0,0 +1,84 @@
/* date.c - implements date handling routines */
/*
* Copyright (c) 2004-2010 Wind River Systems, Inc.
*
* The right to copy, distribute, modify, or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
--------------------
01b,07jul10,jc0 rename global index to indexDate (WIND00220095).
01a,07oct04,f_b added
*/
#include "stdio.h"
#include "float.h"
#include "strutils.h"
char months[12][4] = {
"JAN","FEB","MAR",
"APR","MAY","JUN",
"JUL","AUG","SEP",
"OCT","NOV","DEC"
};
typedef struct ttime {
int year;
char month[10];
char *day;
int hour;
int minute;
int second;
} TIME;
typedef struct division {
float div;
float quo;
double result;
} DIVISION;
int indexDate;
TIME clocker[1];
DIVISION division[1];
long send_month (char *sptr)
{
char *index = "Test" \
" Locals";
if ((strcmp(sptr, index)) != 0) return 0;
if ((strcmp(sptr, "MAR")) == 0) return 0;
return 1;
}
char date()
{
TIME *full_time = (TIME *) &clocker ;
DIVISION *ptr = (DIVISION *) &division;
volatile long val = 0;
indexDate = 7;
val = send_month ( months[1]);
full_time->year = 1996;
strcpy (full_time->month, months[1]);
full_time->day = "Friday";
full_time->hour = 8;
full_time->minute = 30;
full_time->second = 15;
ptr->quo = 12.02;
ptr->div = 12.45;
ptr->result = 1.00357737;
return 'A';
}
@@ -0,0 +1,97 @@
/* engineer.c - implements 'Engineer Structure' routines */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#include "strutils.h"
/*
* Definitions
*/
#define MAX_NAME 10 /* Engineer information */
#define END_LIST -1
typedef int ENGINEER_ID;
typedef char ENGINEER_NAME;
struct engineer_struct { /* Structure 'template/tag' */
ENGINEER_ID id;
ENGINEER_NAME name[MAX_NAME];
};
/* Global array of engineer_structs */
struct engineer_struct hw_engineer[] = { {1, "Dick" },
{2, "Al" },
{3, "Charlie"},
{END_LIST,"END"} };
/* Global array of pointers to engineer_structs */
struct engineer_struct *test_engineer[3];
struct engineer_struct TestEngineer = { 1, "Nick" };
struct engineer_struct SeniorTestEngineer = { 2, "Kirk" };
struct engineer_struct End = { END_LIST, "END" };
/************************************************************************
* Function: engineers()
* Description: Manipulates the engineer structures.
* Notes: - callParm is returned unaltered
*************************************************************************/
int engineers( volatile int callParm )
{
ENGINEER_NAME engineer_name[MAX_NAME];
volatile ENGINEER_ID engineer_id;
struct engineer_struct sw_eng1, sw_eng2;
struct engineer_struct *sw_engineer[2];
int n;
/*
* Examine the global hardware engineer array of structs,
* and the locals engineer_name and engineer_id.
* The array of hardware engineer structs is delimited by an end
* record, equal to END_LIST.
*
*/
for (n=0; hw_engineer[n].id != END_LIST ;n++ )
{
strcpy (engineer_name, hw_engineer[n].name );
engineer_id = hw_engineer[n].id;
}
/* Setup a software engineer array of pointers to engineer_structs */
sw_eng1.id = 4; /* initialize the first struct */
strcpy(sw_eng1.name,"Dennis");
sw_eng2.id = 5;
strcpy(sw_eng2.name,"JCC"); /* initialize the second struct */
sw_engineer[0] = &sw_eng1; /* initialize array of pointers */
sw_engineer[1] = &sw_eng2;
/* Examine the locals with the debugger */
strcpy(engineer_name, sw_engineer[0]->name);
engineer_id = sw_engineer[0]->id;
strcpy(engineer_name, sw_engineer[1]->name);
engineer_id = sw_engineer[1]->id;
/* Setup a global test engineer array of pointers to engineer_struct */
test_engineer[0] = &TestEngineer;
test_engineer[1] = &SeniorTestEngineer;
test_engineer[2] = &End; /* End-of-list terminator */
/* Examine the locals */
for (n=0; test_engineer[n]->id != END_LIST ;n++ )
{
strcpy(engineer_name, test_engineer[n]->name);
engineer_id = test_engineer[n]->id;
}
return callParm;
} /* end of engineerStructs() */
@@ -0,0 +1,217 @@
/* linklist.c - implements link list demonstration */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
/*
* Definitions
*/
#define NULL ( void *)0
/*
* Cell Structure Template
*/
struct cell_struct {
int IdNum; /* cell ID number */
char IdLetter; /* cell ID letter */
struct cell_struct *next; /* pointer to next */
struct cell_struct *prev; /* pointer to previous */
};
/*
* Global cell_structs
*/
struct cell_struct cell_1, cell_2, cell_3; /* Uninitialized */
struct cell_struct cell_4 = { 4, 'D', NULL, NULL }; /* Initialized */
/*
* Forward References
*/
void addCell ( struct cell_struct *, struct cell_struct * );
void swapCells ( struct cell_struct *, struct cell_struct * );
/************************************************************************
* Function: linklist()
* Description: Manipulates Link Lists
************************************************************************/
int linkList( int callParm )
{
struct cell_struct *cell_ptr; /* local pointer to cell list */
volatile struct cell_struct cell; /* local cell structure (note1) */
volatile int genLocal; /* (note2) */
int n;
genLocal = callParm; /* callParm is examined, but not used */
/*
* Initialize and arrange the cells into a doubly-linked circular list.
* The debugger can be used to verify each initialization step.
* However, be careful of uninitialized values. For example, the 'next'
* and 'prev' values are pointers that may point to illegal memory areas
* prior to initialization.
*/
cell_1.IdNum = 1;
cell_1.IdLetter = 'A';
cell_1.next = &cell_2;
cell_1.prev = &cell_3;
cell_2.IdNum = 2;
cell_2.IdLetter = 'B';
cell_2.next = &cell_3;
cell_2.prev = &cell_1;
cell_3.IdNum = 3;
cell_3.IdLetter = 'C';
cell_3.next = &cell_1;
cell_3.prev = &cell_2;
/*
* Now that all of the elements have been initialized, the debugger can be
* used to examine some items. For example, highlighting 'cell_3' will
* display all of cell_3's elements. Highlighting 'cell_3.prev' will
* display all of cell_2's elements. Highlighting 'cell_3.next' will
* display cell_1's elements -- recall it is a circular list.
*/
/*
* We can also use a local cell_struct pointer to cycle through the
* list automatically. Since the last cell is linked back to the first,
* there is no 'end' to the list.
*
* One way of setting up the debugger to view these steps is to have
* 'cell' and/or 'cell_ptr' as watch-window variables.
*/
cell_ptr = &cell_1; /* point to the first cell */
for (n=0; n < 6 ;n++)
{
cell.IdNum = cell_ptr->IdNum;
cell.IdLetter = cell_ptr->IdLetter;
cell.next = cell_ptr->next;
cell.prev = cell_ptr->prev;
cell_ptr = cell.next; /* point to the next cell in the list */
}
/*
* Add a new cell and then rearrange the order of the link list.
*/
/*
* First, add one more cell to the end of the list -- cell_4.
* The cells will now be numbered: 1, 2, 3, and 4. Recall, cell_4 was
* initialized at declaration time.
*
* addCell() uses pointer-to-pointer constructs to add the new
* cell. 'step into' the function to see how this done.
*/
addCell( &cell_4, &cell_3 );
/*
* Second, swap cells #2 and #3 in the link order. The cells will
* now be numbered: 1, 3, 2, and 4.
*
* WARNING: Do not step into this function, it contains complex
* data constructs.
*/
swapCells( &cell_2, &cell_3);
/*
* Now, let's sequence through the linked list, once, to insure
* the above operations have been performed.
*/
cell_ptr = &cell_1; /* point to the first cell */
for (n=0; n < 4 ;n++)
{
cell.IdNum = cell_ptr->IdNum;
cell.IdLetter = cell_ptr->IdLetter;
cell.next = cell_ptr->next;
cell.prev = cell_ptr->prev;
cell_ptr = cell.next; /* point to the next cell in the list */
}
/*
* If you did not step into the addCell() or swapCells() functions, you
* may have missed the pointer-to-pointer examples. Let's use a similar
* concept here to view the cell information of where the next cell in the
* sequence 'points to'. Recall, the current list order is 1,3,2,4. Assuming
* the current cell is the first cell, cell_1, then it is easy to view
* cell_3's information via cell_1's 'next' pointer. However, we can also
* view cell_2's information from cell_1 via a pointer-pointer:
* i.e. cell_1->next->next->element construct.
*
* (Ok, you caught me, this is actually a pointer to a structure which
* has a pointer that points to another structure, which also has a
* pointer to yet another structure --- or a pointer-pointer-pointer)
*
* Like the previous steps, having 'cell' and 'cell_ptr' as watch-window
* variables are useful for viewing the results.
*/
cell_ptr = &cell_1; /* point to the first cell */
cell.IdNum = cell_ptr->next->next->IdNum; /* peek at the values */
cell.IdLetter = cell_ptr->next->next->IdLetter;
cell.next = cell_ptr->next->next->next;
cell.prev = cell_ptr->next->next->prev;
return callParm;
} /* end of linklist() */
/*************************************************************************
* Function: addCell()
* Description: Adds a new cell into the linked list
* Notes: - The first argument of addCell is a pointer to the
* new cell and the section argument is a pointer to the
* cell that the new one will be added after.
*/
void addCell( struct cell_struct *new_cell, struct cell_struct *old_cell )
{
new_cell->next = old_cell->next;
new_cell->prev = old_cell;
old_cell->next->prev = new_cell; /* pointer-pointer example */
old_cell->next = new_cell;
}
/*************************************************************************
* Function: swapCells()
* Description: swaps the two cells passed in.
* - To swap two cells:
* a.) for both cells, adjust the previous cell's 'next'
* pointer. Use a pointer-pointer.
* b.) for both cells, adjust the next cell's 'prev'
* pointer. Use a pointer-pointer.
* c.) swap both cells internal next and prev pointers.
* Use a temp variable to hold intermediate values.
*************************************************************************/
void swapCells( struct cell_struct *cellA, struct cell_struct *cellB )
{
struct cell_struct *ptemp;
/* !!! I KNEW YOU COULDN'T RESIST !!! */
cellA->prev->next = cellB; /* step a */
cellB->prev->next = cellA;
cellA->next->prev = cellB; /* step b */
cellB->next->prev = cellA;
ptemp = cellA->next; /* step c */
cellA->next = cellB->next;
cellB->next = ptemp;
ptemp = cellA->prev;
cellA->prev = cellB->prev;
cellB->prev = ptemp;
}
+208
View File
@@ -0,0 +1,208 @@
/* main.c - main routine of C demo program */
/*
* Copyright (c) 2004, 2011 Wind River Systems, Inc.
*
* The right to copy, distribute or otherwise make use of this software
* may be licensed only pursuant to the terms of an applicable Wind River
* license agreement. No license to Wind River intellectual property rights
* is granted herein. All rights not licensed by Wind River are reserved
* by Wind River.
*/
/*
modification history
--------------------
01b,07jan11,mcm Added support for X86_64
01a,07oct04,f_b added
*/
#include "strutils.h"
/*
* General Definitions
*/
#define FOREVER 1
#define BELL_CHAR '\007'
#define MAX_LOCAL_STRING 5
typedef enum {red, yellow, blue} color_type;
typedef struct {
short a;
char b[16];
int c;
color_type color;
} REC_TYPE1;
REC_TYPE1 recordvar = {-1, "Wind River Tools", 987654321L, blue};
typedef struct test {
int long_integer;
short short_integer;
int integer_array[4];
char *string_pointer;
} REC_TYPE2;
REC_TYPE2 rectest;
/*
* Externals
*/
extern int addone( int );
extern char date( void );
extern int engineers( int ), linkList ( int );
extern int factorial( int ), fibonacci( int );
extern void factorialDemo( void ), fibonacciDemo( void );
extern int calendar( int );
/*
* General Global Declarations
*/
short quick_index;
int status, globalInt1;
int globalLong1;
int wait_count, wait_index;
int initval; /* initialization value for calculation */
char *globalstring[3]; /* Uninitializeded array of string pointers */
char bell[2] = {BELL_CHAR, '\0'};
/************************************************************************
* Function: main()
* Description: Main entry point for the demonstration
*************************************************************************/
int main()
{
volatile int demo_counter;
volatile int pfa_demo=0;
int sum = 0;
volatile char cvar; /* sample char variable */
REC_TYPE1 q;
volatile int localInt1;
volatile int localLong1;
/* Setup the global string array */
globalstring[0] = "zero";
globalstring[1] = "one";
globalstring[2] = "two";
/* Initialize the rectest structure */
rectest.long_integer = 0xFFFFEEEE;
rectest.short_integer = 5555;
rectest.integer_array[0] = 0;
rectest.integer_array[1] = 10;
rectest.integer_array[2] = 20;
rectest.integer_array[3] = 30;
rectest.string_pointer = "Wind River's Tools Product Family";
/*
* Fill a table with factorials using recursive calls.
*/
factorialDemo( );
/*
* Fill a table with the fibonnacci sequence using recursive calls.
*/
fibonacciDemo( );
/* set a local variable */
pfa_demo = 3;
/*
* Infinite Loop ...
* Could use demo_counter as a modulo-maxcount-for-sizeof(int)
* to count the iterations of the demo loop and view in a watch window.
*/
for ( demo_counter=0; FOREVER ;demo_counter++ )
{
/*
* Setup and examine 'engineer structure'. This function illustrates
* arrays of structures and pointers to array of structures.
*/
status = engineers( 0x1234 );
/*
* Setup and examine link-list structure. This function illustrates
* structure pointers and pointer-to-pointers.
*/
status = linkList( 0x5678 );
/*
* Calculate the factorial of a number. Since factorials
* get very large quickly, only calculate the factorial
* of the number 3 once every 25 iterations using the C modulo operator
* to detect 25th iteration in the infinite loop.
*
* Add 'demo_counter' in a watch window and set a breakpoint
* on the 'localInt1=factorial(3);' line. If there are no other
* enabled breakpoints in the loop, then every time the
* run button is pressed, the demo_counter is updated. But
* the modulo operator filters calls to the factorial function
* only once every 25 iterations through the loop.
*/
if ( !(demo_counter % 25) )
localInt1 = factorial( 3 );
/*
* Calculate the fibonacci of a fixed number, 5,
* once every 100th iteration of the main test loop.
*/
if ( !(demo_counter % 100) )
globalInt1 = fibonacci( 5 );
/*
* Demonstrate some calendar functions.
*/
localLong1 = 0x12345678;
globalLong1 = calendar( localLong1 );
/*
* Manipulate some local and global structures.
*/
q.a = 55;
strcpy(q.b,"December");
q.c = 12345678L;
q.color = red;
sum = 0;
wait_index = 0;
wait_count = 5;
quick_index = 5;
recordvar.color = red;
/*
* Call a function written in assembler
*/
while (wait_index < wait_count)
{
wait_index = addone(wait_index);
sum = sum + 1;
}
cvar = date();
recordvar.a = 0;
for (quick_index = 0; quick_index <= 4 ;++quick_index) {
++recordvar.a;
}
recordvar.color = blue;
/*
* Before starting the demo_count loop once again, increment
* pfa_demo counter variable using a ternary condition operator.
* Also, maintain a modulo-3 range on its value.
*/
if (pfa_demo==3) {
pfa_demo=0;
} else {
++pfa_demo;
}
}
return 0;
}
+153
View File
@@ -0,0 +1,153 @@
/* math.c - implements math demonstration functions */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
/*
* General Definitions
*/
#define MAX_FACTORIAL 10
#define MAX_FIBONACCI 10
/*
* General Global Declarations
*/
int fact_table[MAX_FACTORIAL];
int num_fibs; /* table of fibonacci numbers */
int fib_table[MAX_FIBONACCI];
/*
* Forward References
*/
int factorial( int );
int fibonacci( int );
/************************************************************************
* Function: factorialDemo()
* Description: Use a recursive function to generates a table of factorials.
*************************************************************************/
void factorialDemo( void )
{
int sum; /* will be the sum of factorials from 0 to 9 */
int clear_index; /* general local variables */
int loopvar;
loopvar = 0;
/*
* Start by zero'ing out the factorial array table. This table
* will be used to store a calculated factorial sequence.
*/
for (clear_index = 0; clear_index < MAX_FACTORIAL; ++clear_index)
{
fact_table[clear_index] = 0;
}
/*
* Calculate and store the factorial sequence.
*/
for (sum=0, loopvar=0; loopvar < MAX_FACTORIAL; ++loopvar)
{
fact_table[ loopvar ] = factorial( loopvar );
/*
* Keep a running sum of the calculated factorials.
*/
sum += fact_table[loopvar];
}
} /* end of factorialDemo() */
/************************************************************************
* Function: fibonacciDemo()
* Description: Use a recursive function to generates the fibonacci sequence.
* Each fibonacci number is the sum of the, that is,
* ( 0,1,1,2,3,5,8,13,....)
* The algorithm is given by:
* F(0) = 0
* F(1) = 1
* F(i) = F(i-1) + F(i-2) , i >= 2
************************************************************************/
void fibonacciDemo( void )
{
int sum; /* will be the sum of the fibonacci series */
int clear_index; /* general local variables */
int loopvar;
volatile int temp;
loopvar = 0;
sum = 0;
/*
* Let's start by zero'ing out the fibonacci array table. This table
* will be used to store a calculated fibonacci sequence.
*/
for (clear_index = 0; clear_index < MAX_FIBONACCI; ++clear_index)
{
fib_table[clear_index] = 0;
}
/*
* Calculate and store the fibonacci sequence.
*/
for (loopvar = 0; loopvar < MAX_FIBONACCI; loopvar++)
{
temp = fibonacci( loopvar );
fib_table[ loopvar ] = temp;
/*
* Keep a running sum of the calculated fibonacci sequence.
*/
sum += fib_table[loopvar];
}
} /* end of fibonacciDemo() */
/************************************************************************
* Function: Compute the factorial of a number
*************************************************************************/
int factorial( int num)
{
if ( num < 2 )
return(1);
num *= factorial( num-1 );
return (num);
}
/************************************************************************
* Function: fibonacci()
* Description: Computes the fibonacci of a number
************************************************************************/
int fibonacci( int num)
{
if ( num >= 2 )
{
num = fibonacci( num-1 ) + fibonacci( num-2 );
}
return num;
}
/************************************************************************
* Function: abs( )
* Description: Computes the absolute value of the passed in int.
************************************************************************/
int abs( int num)
{
return ( num >= 0 ) ? num : (num *= -1);
}
@@ -0,0 +1,2 @@
project.type=DownloadableKernelModuleProject
platform.id=VxWorks
@@ -0,0 +1,28 @@
The C demo Demonstration Program
----------------------------------
The C demo program demonstrates various C language features including
structures, character arrays, linked lists, and recursion. You can
build and download this program to your VxWorks target.
Features
--------
The following features are demonstrated from main():
* *Factorials:* The factorialDemo() function generates a factorial
table from 0! to 9!. Set a watch on fact_table to see the
creation of the table. This function calls the recursive function
factorial().
* *Fibonacci Sequence:* The fibonacciDemo() function creates a
fibonacci sequence with ten terms. Set a watch on fib_table to
see the creation of the sequence. This function calls the
recursive function fibonacci().
* *Structures, Arrays, and Linked Lists:* The remainder of the
program is a loop that demonstrates pointers, arrays,
structures, and linked lists. Set watches on cell_1, cell_2,
cell_3, and cell_4 to see the linked list operations. Set a watch
on the test_engineer[] array to see an array of structures.
@@ -0,0 +1,45 @@
/* strutils.c - implements string manipulating utilities */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
/************************************************************************
* Function: strcpy()
* Description: String copy utility
* Notes: Copy *s2 to *s1
*/
char *strcpy(char *s1, const char *s2)
{
char *result;
char *ps1;
char *ps2;
ps1 = s1;
ps2 = (char*)s2;
result = s1;
while ((*ps1++ = *ps2++) != '\0')
;
return (result);
}
/************************************************************************
* Function: strcpm()
* Description: String compare utility
* Notes:
*/
int strcmp(register const char *s1, register const char *s2)
{
while ((*s1 == *s2) && *s1) {
s1++;
s2++;
}
return (*s1 - *s2);
}
@@ -0,0 +1,17 @@
/* strutils.h - declarations for string manipulating utilities */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#ifndef _STRUTILS_H
#define _STRUTILS_H
char *strcpy(char *s1, const char *s2);
int strcmp(register const char *s1, register const char *s2);
#endif
@@ -0,0 +1,619 @@
/* sample_Daytona.c - Sample application using Windnet 1.4 CAN api */
/* Copyright */
/*
modification history
---------------------
01e,06oct05,lsg ensure case in included file names
01d,20may05,lsg Add graceful exits from functions
01c,18apr05,lsg fix bug in ISR callback
01b,25jun04,lsg added macros for bit timing specific to Daytona board
01a,4Oct02,lsg created sample application for techpubs
*/
/*
DESCRIPTION
This module is a sample application provided with the Windnet CAN api
documentation. The purpose is to demonstrate the use of CAN api, and
the sequence in which they must be called.
INCLUDE FILES:
*/
/* includes */
#include <vxWorks.h>
#include <stdio.h>
#include <errnoLib.h>
#include <CAN/wnCAN.h>
#include <assert.h>
#include <logLib.h>
/* defines */
/**************************************************************************/
#define DEMO_BOARD WNCAN_DAYTONA
#define DEMO_CTRL0 0
#define DEMO_CTRL1 1
#define NUM_CTRLRS 2
#define DEMO_ID0 0x180
#define DEMO_ID1 0x190
#define DEMO_TSEG1 4
#define DEMO_TSEG2 5
#define DEMO_BAUD_RATE_PRESCALAR 7
#define DEMO_SJW 2
#define DEMO_SAMPLES_BOOL 0
#define DEMO_BAUD_RATE 125000
#define DEMO_PROP_SEG 7
/**************************************************************************/
/* globals */
struct WNCAN_Device *pDev0=NULL;
struct WNCAN_Device *pDev1=NULL;
int flagAwake0;
ULONG id0[100];
BOOL extFlag0[100];
int ArrayIndex0;
int flagAwake1;
ULONG id1[100];
BOOL extFlag1[100];
int ArrayIndex1;
/* forward declarations */
void test_isr0(struct WNCAN_Device *pDev1, WNCAN_IntType intstatus,
UCHAR channelNum);
void test_isr1(struct WNCAN_Device *pDev1, WNCAN_IntType intStatus,
UCHAR channelNum);
int releaseNode(int);
/**************************************************************************
*
* setupNode - Set up CAN ctrlr.
*
* This routine does the following:
* 1. Get device pointer.
* 2. Initialize CAN controller.
* 3. Set bit timing values to enable baud rate of 125K
* 4. Set interrupt mask to enable all interrupts.
* 5. Enable Interrupts.
* 6. Set global receive filter to receive all standard identifiers.
* 7. Assign a channel for reception.
* 8. Set local filter for channel number 14 (channels numbered 0 to 14)
* to receive all extended identifiers
* 9. Enable channel 14 for reception of extended identifiers.
* 10.Exit without bringing CAN controller online.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int setupNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG testBaudRate;
UINT samplePoint;
STATUS retCode = OK;
UCHAR channelRx;
/*default settings*/
if(ctrlr == 1)
{
pDev1 = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL1);
assert(pDev1);
CAN_InstallISRCallback(pDev1, test_isr1);
pDev = pDev1;
ArrayIndex1 = 0;
}
else
{
pDev0 = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL0);
assert(pDev0);
CAN_InstallISRCallback(pDev0, test_isr0);
pDev = pDev0;
ArrayIndex0 = 0;
}
CAN_Init(pDev);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("Resetting baud to %d\n", DEMO_BAUD_RATE,0,0,0,0,0);
CAN_SetBitTiming(pDev, DEMO_TSEG1, DEMO_TSEG2, DEMO_BAUD_RATE_PRESCALAR,
DEMO_SJW, DEMO_SAMPLES_BOOL);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("**Unable to set %d baud with selected bit timing parameters \
.\n", DEMO_BAUD_RATE,0,0,0,0,0);
logMsg("**If baud rate is off by a factor of 2, check the UMCR \
HSPEED bit setting\n",0,0,0,0,0,0);
logMsg("**Adjust macro DEMO_BAUD_RATE_PRESCALAR defined at the \
begining of this file accordingly\n",0,0,0,0,0,0);
releaseNode(ctrlr);
return ERROR;
}
}
/* Enable interrupts */
CAN_SetIntMask(pDev, WNCAN_INT_ALL);
CAN_EnableInt(pDev);
/* Set up global filter to receive all standard messages */
retCode = CAN_SetGlobalRxFilter(pDev, 0, FALSE);
if(retCode != OK)
logMsg("Error: Set Global filter failed \n",0,0,0,0,0,0);
/* Set up receive message buffer */
CAN_GetRxChannel(pDev, &channelRx);
/*
* If set global filter failed, perhaps this controller has a local filter
* that we could use.
*/
if (retCode != OK)
CAN_SetLocalMsgFilter(pDev, channelRx, 0, FALSE);
retCode = CAN_WriteID(pDev, channelRx, 0, FALSE);
if(retCode != OK)
{
logMsg("Error: Write ID failed on channel %d \n",channelRx,0,0,0,0,0);
return ERROR;
}
CAN_EnableChannel(pDev, channelRx, WNCAN_INT_RX);
/* pick chn#14 to receive all, because on some ctrls, it's the only
** channel that will receive using the filters.
*/
/*Enable channel 14 to receive messages*/
CAN_SetMode(pDev, 14, WNCAN_CHN_RECEIVE);
/* Set up local filter to receive all extended messages */
CAN_SetLocalMsgFilter(pDev, 14, 0, TRUE);
retCode = CAN_WriteID(pDev, 14, 0, TRUE);
if(retCode != OK)
logMsg("Error: Write ID failed on channel 14 \n",0,0,0,0,0,0);
CAN_EnableChannel(pDev, 14, WNCAN_INT_RX);
return OK;
}
/**************************************************************************
*
* transmitMsg - Transmit message using CAN_TxMsg
*
* This function gets transmit channel and transmits message with standard
* id 0x180, with eight data bytes.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int transmitMsg
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG id=DEMO_ID0;
STATUS retCode;
UCHAR channelTx;
UCHAR data[8]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
if(ctrlr == 1)
{
pDev = pDev1;
id = DEMO_ID1;
}
else
pDev = pDev0;
retCode = CAN_GetTxChannel(pDev, &channelTx);
if(retCode != OK)
{
logMsg("Transmitter not available\n",0,0,0,0,0,0);
return ERROR;
}
CAN_EnableChannel(pDev, channelTx, WNCAN_INT_TX);
retCode = CAN_TxMsg(pDev, channelTx, id, FALSE, data, 8);
if(retCode != OK)
{
logMsg("error in tx msg setup \n",0,0,0,0,0,0);
return ERROR;
}
return OK;
}
/**************************************************************************
*
* stopNode - Bring CAN controller offline
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int stopNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
CAN_Stop(pDev);
return OK;
}
/**************************************************************************
*
* startNode - Bring CAN controller online
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int startNode(int ctrlr)
{
struct WNCAN_Device *pDev;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Start(pDev);
return OK;
}
/**************************************************************************
*
* releaseNode - Release device pointer to CAN controller
*
* This function does the following:
*
* 1. Abort all pending transmissions
* 2. Bring CAN controller offline
* 3. Disable and Free all channels
* 4. Disable interrupts
* 5. Give up device pointer
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int releaseNode
(
int ctrlr
)
{
int i;
if(ctrlr == 1)
{
/*Check if pDev1 is valid*/
if(NULL==pDev1){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_TxAbort(pDev1);
CAN_Stop(pDev1);
for(i=0;i<pDev1->pCtrl->numChn;i++)
{
CAN_DisableChannel(pDev1, i);
CAN_FreeChannel(pDev1, i);
}
CAN_DisableInt(pDev1);
CAN_Close(pDev1);
pDev1=NULL;
}
else
{
/*Check if pDev0 is valid*/
if(NULL==pDev0){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_TxAbort(pDev0);
CAN_Stop(pDev0);
for(i=0;i<pDev0->pCtrl->numChn;i++)
{
CAN_DisableChannel(pDev0, i);
CAN_FreeChannel(pDev0, i);
}
CAN_DisableInt(pDev0);
CAN_Close(pDev0);
pDev0=NULL;
}
return OK;
}
/**************************************************************************
*
* statusNode - Print bus Status to stdout
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int statusNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
WNCAN_BusStatus busStatus;
long globalMask;
long localMask;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
busStatus = CAN_GetBusStatus(pDev);
if(busStatus == WNCAN_BUS_OFF)
logMsg("Bus status is BUS OFF \n",0,0,0,0,0,0);
else if(busStatus == WNCAN_BUS_WARN)
logMsg("Bus status is BUS WARNING, more than 96 transmit errors have \
occured \n",0,0,0,0,0,0);
else
logMsg("Bus status is BUS OK, error active \n",0,0,0,0,0,0);
globalMask = CAN_GetGlobalRxFilter(pDev, 0);
logMsg("Global Filter is %x \n",globalMask,0,0,0,0,0);
localMask = CAN_GetLocalMsgFilter(pDev, 14, 1);
logMsg("Local Filter is %x \n",localMask,0,0,0,0,0);
return OK;
}
/**************************************************************************
*
* printRxMsg - Print all the received message identifiers and data to stdout
*
* Received message ids are recorded in an array by the ISR call back function.
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int printRxMsg
(
int ctrlr
)
{
int i;
if(ctrlr == 1)
{
for(i=0;i<ArrayIndex1;i++)
{
logMsg("Id[%d] = %x and extFlag is %d \n", i, id1[i], extFlag1[i],0,0,0);
}
}
else
{
for(i=0;i<ArrayIndex0;i++)
{
logMsg("Id[%d] = %x and extFlag is %d \n", i, id0[i], extFlag0[i],0,0,0);
}
}
return OK;
}
/**************************************************************************
*
* ISR call back function for ctrlr 0
*
*/
void test_isr0(struct WNCAN_Device *pDev, WNCAN_IntType intStatus, UCHAR channelNum)
{
WNCAN_BusError busErr;
STATUS retCode;
if(intStatus == WNCAN_INT_WAKE_UP)
flagAwake0++;
if(intStatus == WNCAN_INT_TX)
{
retCode = CAN_DisableChannel(pDev, channelNum);
retCode = CAN_FreeChannel(pDev, channelNum);
}
if(intStatus == WNCAN_INT_RX)
{
id0[ArrayIndex0] = CAN_ReadID(pDev, channelNum, &extFlag0[ArrayIndex0]);
(ArrayIndex0 >= 99)?ArrayIndex0=0:ArrayIndex0++;
}
if(intStatus == WNCAN_INT_ERROR)
{
logMsg("CAN bus error occurred: ",0,0,0,0,0,0);
busErr = CAN_GetBusError(pDev);
switch(busErr)
{
case WNCAN_ERR_BIT:
logMsg("WNCAN_ERR_BIT \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_ACK:
logMsg("WNCAN_ERR_ACK \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_CRC:
logMsg("WNCAN_ERR_CRC \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_FORM:
logMsg("WNCAN_ERR_FORM \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_STUFF:
logMsg("WNCAN_ERR_STUFF \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_NONE:
logMsg("WNCAN_ERR_NONE \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_UNKNOWN:
default:
logMsg("WNCAN_ERR_UNKNOWN \n",0,0,0,0,0,0);
break;
}
}
if(intStatus == WNCAN_INT_BUS_OFF)
releaseNode(0);
}
/**************************************************************************
*
* ISR call back function for ctrlr 1
*
*/
void test_isr1(struct WNCAN_Device *pDev, WNCAN_IntType intStatus, UCHAR channelNum)
{
WNCAN_BusError busErr;
STATUS retCode;
if(intStatus == WNCAN_INT_WAKE_UP)
flagAwake1++;
if(intStatus == WNCAN_INT_TX)
{
retCode = CAN_DisableChannel(pDev, channelNum);
retCode = CAN_FreeChannel(pDev, channelNum);
}
if(intStatus == WNCAN_INT_RX)
{
id1[ArrayIndex1] = CAN_ReadID(pDev, channelNum, &extFlag1[ArrayIndex1]);
(ArrayIndex1 >= 99)?ArrayIndex1=0:ArrayIndex1++;
}
if(intStatus == WNCAN_INT_ERROR)
{
logMsg("CAN bus error occurred: ",0,0,0,0,0,0);
busErr = CAN_GetBusError(pDev);
switch(busErr)
{
case WNCAN_ERR_BIT:
logMsg("WNCAN_ERR_BIT \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_ACK:
logMsg("WNCAN_ERR_ACK \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_CRC:
logMsg("WNCAN_ERR_CRC \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_FORM:
logMsg("WNCAN_ERR_FORM \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_STUFF:
logMsg("WNCAN_ERR_STUFF \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_NONE:
logMsg("WNCAN_ERR_NONE \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_UNKNOWN:
default:
logMsg("WNCAN_ERR_UNKNOWN \n",0,0,0,0,0,0);
break;
}
}
if(intStatus == WNCAN_INT_BUS_OFF)
releaseNode(1);
}
@@ -0,0 +1,634 @@
/* sample_ESDPC104_200.c - Sample application using Windnet 1.4 CAN api */
/* Copyright */
/*
modification history
---------------------
01e,06oct05,lsg make sure include file names are case-sensitive for Linux
hosts
01d,20may05,lsg Add graceful exits from functions
01c,18apr05,lsg fix bug is ISR callback
01b,25jun04,lsg added macros for bit timing specific to ESD PC104 200 board
01a,4Oct02,lsg created sample application for techpubs
*/
/*
DESCRIPTION
This module is a sample application provided with the Windnet CAN api
documentation. The purpose is to demonstrate the use of CAN api, and
the sequence in which they must be called.
INCLUDE FILES:
*/
/* includes */
#include <vxWorks.h>
#include <stdio.h>
#include <errnoLib.h>
#include <CAN/wnCAN.h>
#include <CAN/sja1000Offsets.h>
#include <CAN/i82527Offsets.h>
#include <assert.h>
#include <logLib.h>
/* defines */
/**************************************************************************/
#define DEMO_BOARD WNCAN_ESD_PC104_200
#define DEMO_CTRL0 0
#define DEMO_CTRL1 1
#define NUM_CTRLRS 2
#define DEMO_ID0 0x180
#define DEMO_ID1 0x190
#define DEMO_TSEG1 0xc
#define DEMO_TSEG2 1
#define DEMO_BAUD_RATE_PRESCALAR 3
#define DEMO_SJW 2
#define DEMO_SAMPLES_BOOL 0
#define DEMO_BAUD_RATE 125000
#define DEMO_PROP_SEG 0
/**************************************************************************/
/* globals */
struct WNCAN_Device *pDev0=NULL;
struct WNCAN_Device *pDev1=NULL;
int flagAwake0;
ULONG id0[100];
BOOL extFlag0[100];
int ArrayIndex0;
int flagAwake1;
ULONG id1[100];
BOOL extFlag1[100];
int ArrayIndex1;
/* forward declarations */
void test_isr0(struct WNCAN_Device *pDev1, WNCAN_IntType intstatus,
UCHAR channelNum);
void test_isr1(struct WNCAN_Device *pDev1, WNCAN_IntType intStatus,
UCHAR channelNum);
int releaseNode(int);
/**************************************************************************
*
* setupNode - Set up CAN ctrlr.
*
* This routine does the following:
* 1. Get device pointer.
* 2. Initialize CAN controller.
* 3. Set bit timing values to enable baud rate of 125K
* 4. Set interrupt mask to enable all interrupts.
* 5. Enable Interrupts.
* 6. Set global receive filter to receive all standard identifiers.
* 7. Assign a channel for reception.
* 8. Set local filter for channel number 14 (channels numbered 0 to 14)
* to receive all extended identifiers
* 9. Enable channel 14 for reception of extended identifiers.
* 10.Exit without bringing CAN controller online.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int setupNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG testBaudRate;
UINT samplePoint;
STATUS retCode = OK;
UCHAR channelRx;
/*default settings*/
if(ctrlr == 1)
{
pDev1 = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL1);
assert(pDev1);
CAN_InstallISRCallback(pDev1, test_isr1);
pDev = pDev1;
ArrayIndex1 = 0;
}
else
{
pDev0 = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL0);
assert(pDev0);
CAN_InstallISRCallback(pDev0, test_isr0);
pDev = pDev0;
ArrayIndex0 = 0;
}
CAN_Init(pDev);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("Resetting baud to %d\n", DEMO_BAUD_RATE,0,0,0,0,0);
CAN_SetBitTiming(pDev, DEMO_TSEG1, DEMO_TSEG2, DEMO_BAUD_RATE_PRESCALAR,
DEMO_SJW, DEMO_SAMPLES_BOOL);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("**Unable to set %d baud with selected bit timing parameters \
\n", DEMO_BAUD_RATE,0,0,0,0,0);
logMsg("**If baud rate is off by a factor of 2, check the UMCR \
HSPEED bit setting\n",0,0,0,0,0,0);
logMsg("**Adjust macro DEMO_BAUD_RATE_PRESCALAR defined at the \
begining of this file accordingly\n",0,0,0,0,0,0);
releaseNode(ctrlr);
return ERROR;
}
}
/* Enable interrupts */
CAN_SetIntMask(pDev, WNCAN_INT_ALL);
CAN_EnableInt(pDev);
/* Set up global filter to receive all standard messages */
retCode = CAN_SetGlobalRxFilter(pDev, 0, FALSE);
if(retCode != OK)
logMsg("Error: Set Global filter failed \n",0,0,0,0,0,0);
/* Set up receive message buffer */
CAN_GetRxChannel(pDev, &channelRx);
/*
* If set global filter failed, perhaps this controller has a local filter
* that we could use.
*/
if (retCode != OK)
CAN_SetLocalMsgFilter(pDev, channelRx, 0, FALSE);
retCode = CAN_WriteID(pDev, channelRx, 0, FALSE);
if(retCode != OK)
{
logMsg("Error: Write ID failed on channel %d \n",channelRx,0,0,0,0,0);
return ERROR;
}
CAN_EnableChannel(pDev, channelRx, WNCAN_INT_RX);
/* pick chn#14 to receive all, because on some ctrls, it's the only
** channel that will receive using the filters.
*/
/*Enable channel 14 to receive messages*/
CAN_SetMode(pDev, 14, WNCAN_CHN_RECEIVE);
/* Set up local filter to receive all extended messages */
CAN_SetLocalMsgFilter(pDev, 14, 0, TRUE);
CAN_WriteID(pDev, 14, 0, TRUE);
CAN_EnableChannel(pDev, 14, WNCAN_INT_RX);
return OK;
}
/**************************************************************************
*
* transmitMsg - Transmit message using CAN_TxMsg
*
* This function gets transmit channel and transmits message with standard
* id 0x180, with eight data bytes.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int transmitMsg
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG id=DEMO_ID0;
STATUS retCode;
UCHAR channelTx;
UCHAR data[8]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
if(ctrlr == 1)
{
pDev = pDev1;
id = DEMO_ID1;
}
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
retCode = CAN_GetTxChannel(pDev, &channelTx);
if(retCode != OK)
{
logMsg("Transmitter not available\n",0,0,0,0,0,0);
return ERROR;
}
CAN_EnableChannel(pDev, channelTx, WNCAN_INT_TX);
retCode = CAN_TxMsg(pDev, channelTx, id, FALSE, data, 8);
if(retCode != OK)
{
logMsg("error in tx msg setup \n",0,0,0,0,0,0);
return ERROR;
}
return OK;
}
/**************************************************************************
*
* stopNode - Bring CAN controller offline
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int stopNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Stop(pDev);
return OK;
}
/**************************************************************************
*
* startNode - Bring CAN controller online
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int startNode(int ctrlr)
{
struct WNCAN_Device *pDev;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Start(pDev);
return OK;
}
/**************************************************************************
*
* releaseNode - Release device pointer to CAN controller
*
* This function does the following:
*
* 1. Abort all pending transmissions
* 2. Bring CAN controller offline
* 3. Disable and Free all channels
* 4. Disable interrupts
* 5. Give up device pointer
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int releaseNode
(
int ctrlr
)
{
int i;
if(ctrlr == 1)
{
/*Check if pDev1 is valid*/
if(NULL==pDev1){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_TxAbort(pDev1);
CAN_Stop(pDev1);
for(i=0;i<pDev1->pCtrl->numChn;i++)
{
CAN_DisableChannel(pDev1, i);
CAN_FreeChannel(pDev1, i);
}
CAN_DisableInt(pDev1);
CAN_Close(pDev1);
pDev1=NULL;
}
else
{
/*Check if pDev0 is valid*/
if(NULL==pDev0){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_TxAbort(pDev0);
CAN_Stop(pDev0);
for(i=0;i<pDev0->pCtrl->numChn;i++)
{
CAN_DisableChannel(pDev0, i);
CAN_FreeChannel(pDev0, i);
}
CAN_DisableInt(pDev0);
CAN_Close(pDev0);
pDev0=NULL;
}
return OK;
}
/**************************************************************************
*
* statusNode - Print bus Status to stdout
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int statusNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
WNCAN_BusStatus busStatus;
long globalMask;
long localMask;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
busStatus = CAN_GetBusStatus(pDev);
if(busStatus == WNCAN_BUS_OFF)
logMsg("Bus status is BUS OFF \n",0,0,0,0,0,0);
else if(busStatus == WNCAN_BUS_WARN)
logMsg("Bus status is BUS WARNING, more than 96 transmit errors have \
occured \n",0,0,0,0,0,0);
else
logMsg("Bus status is BUS OK, error active \n",0,0,0,0,0,0);
globalMask = CAN_GetGlobalRxFilter(pDev, 0);
logMsg("Global Filter is %x \n",globalMask,0,0,0,0,0);
localMask = CAN_GetLocalMsgFilter(pDev, 14, 1);
logMsg("Local Filter is %x \n",localMask,0,0,0,0,0);
return OK;
}
/**************************************************************************
*
* printRxMsg - Print all the received message identifiers and data to stdout
*
* Received message ids are recorded in an array by the ISR call back function.
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int printRxMsg
(
int ctrlr
)
{
int i;
if(ctrlr == 1)
{
for(i=0;i<ArrayIndex1;i++)
{
logMsg("Id[%d] = %x and extFlag is %d \n", i, id1[i], extFlag1[i],0,0,0);
}
}
else
{
for(i=0;i<ArrayIndex0;i++)
{
logMsg("Id[%d] = %x and extFlag is %d \n", i, id0[i], extFlag0[i],0,0,0);
}
}
return OK;
}
/**************************************************************************
*
* ISR call back function for ctrlr 0
*
*/
void test_isr0(struct WNCAN_Device *pDev, WNCAN_IntType intStatus, UCHAR channelNum)
{
WNCAN_BusError busErr;
if(intStatus == WNCAN_INT_WAKE_UP)
flagAwake0++;
if(intStatus == WNCAN_INT_TX)
{
CAN_DisableChannel(pDev, channelNum);
CAN_FreeChannel(pDev, channelNum);
}
if(intStatus == WNCAN_INT_RX)
{
id0[ArrayIndex0] = CAN_ReadID(pDev, channelNum, &extFlag0[ArrayIndex0]);
(ArrayIndex0 >= 99)?ArrayIndex0=0:ArrayIndex0 ++;
}
if(intStatus == WNCAN_INT_ERROR)
{
logMsg("CAN bus error occurred: ",0,0,0,0,0,0);
busErr = CAN_GetBusError(pDev);
switch(busErr)
{
case WNCAN_ERR_BIT:
logMsg("WNCAN_ERR_BIT \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_ACK:
logMsg("WNCAN_ERR_ACK \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_CRC:
logMsg("WNCAN_ERR_CRC \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_FORM:
logMsg("WNCAN_ERR_FORM \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_STUFF:
logMsg("WNCAN_ERR_STUFF \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_NONE:
logMsg("WNCAN_ERR_NONE \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_UNKNOWN:
default:
logMsg("WNCAN_ERR_UNKNOWN \n",0,0,0,0,0,0);
break;
}
}
if(intStatus == WNCAN_INT_BUS_OFF)
releaseNode(0);
}
/**************************************************************************
*
* ISR call back function for ctrlr 1
*
*/
void test_isr1(struct WNCAN_Device *pDev, WNCAN_IntType intStatus, UCHAR channelNum)
{
WNCAN_BusError busErr;
if(intStatus == WNCAN_INT_WAKE_UP)
flagAwake1++;
if(intStatus == WNCAN_INT_TX)
{
CAN_DisableChannel(pDev, channelNum);
CAN_FreeChannel(pDev, channelNum);
}
if(intStatus == WNCAN_INT_RX)
{
id1[ArrayIndex1] = CAN_ReadID(pDev, channelNum, &extFlag1[ArrayIndex1]);
(ArrayIndex1 >= 99)?ArrayIndex1=0:ArrayIndex1 ++;
}
if(intStatus == WNCAN_INT_ERROR)
{
logMsg("CAN bus error occurred: ",0,0,0,0,0,0);
busErr = CAN_GetBusError(pDev);
switch(busErr)
{
case WNCAN_ERR_BIT:
logMsg("WNCAN_ERR_BIT \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_ACK:
logMsg("WNCAN_ERR_ACK \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_CRC:
logMsg("WNCAN_ERR_CRC \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_FORM:
logMsg("WNCAN_ERR_FORM \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_STUFF:
logMsg("WNCAN_ERR_STUFF \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_NONE:
logMsg("WNCAN_ERR_NONE \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_UNKNOWN:
default:
logMsg("WNCAN_ERR_UNKNOWN \n",0,0,0,0,0,0);
break;
}
}
if(intStatus == WNCAN_INT_BUS_OFF)
releaseNode(1);
}
@@ -0,0 +1,627 @@
/* sample_ESDPCI200.c - Sample application using Windnet 1.4 CAN api */
/* Copyright */
/*
modification history
---------------------
01e,06oct05,lsg Make sure include file names are case-sensitive for Linux
hosts
01d,20may05,lsg Add graceful exits from functions
01c,16apr05,lsg fix bug in isr callback
01b,25jun04,lsg added macros for bit timing specific to ESD PCI 200
01a,4Oct02,lsg created sample application for techpubs
*/
/*
DESCRIPTION
This module is a sample application provided with the Windnet CAN api
documentation. The purpose is to demonstrate the use of CAN api, and
the sequence in which they must be called.
INCLUDE FILES:
*/
/* includes */
#include <vxWorks.h>
#include <stdio.h>
#include <errnoLib.h>
#include <CAN/wnCAN.h>
#include <CAN/sja1000Offsets.h>
#include <assert.h>
#include <logLib.h>
/* defines */
/**************************************************************************/
#define DEMO_BOARD WNCAN_ESD_PCI_200
#define DEMO_CTRL0 0
#define DEMO_CTRL1 1
#define NUM_CTRLRS 2
#define DEMO_ID0 0x180
#define DEMO_ID1 0x190
#define DEMO_TSEG1 0xc
#define DEMO_TSEG2 0x1
#define DEMO_BAUD_RATE_PRESCALAR 0x3
#define DEMO_SJW 2
#define DEMO_SAMPLES_BOOL 0
#define DEMO_BAUD_RATE 125000
#define DEMO_PROP_SEG 7
/**************************************************************************/
/* globals */
struct WNCAN_Device *pDev0=NULL;
struct WNCAN_Device *pDev1=NULL;
int flagAwake0;
ULONG id0[100];
BOOL extFlag0[100];
int ArrayIndex0;
int flagAwake1;
ULONG id1[100];
BOOL extFlag1[100];
int ArrayIndex1;
/* forward declarations */
void test_isr0(struct WNCAN_Device *pDev1, WNCAN_IntType intstatus,
UCHAR channelNum);
void test_isr1(struct WNCAN_Device *pDev1, WNCAN_IntType intStatus,
UCHAR channelNum);
int releaseNode(int);
/**************************************************************************
*
* setupNode - Set up CAN ctrlr.
*
* This routine does the following:
* 1. Get device pointer.
* 2. Initialize CAN controller.
* 3. Set bit timing values to enable baud rate of 125K
* 4. Set interrupt mask to enable all interrupts.
* 5. Enable Interrupts.
* 6. Set global receive filter to receive all standard identifiers.
* 7. Assign a channel for reception.
* 8. Set local filter for channel number 14 (channels numbered 0 to 14)
* to receive all extended identifiers
* 9. Enable channel 14 for reception of extended identifiers.
* 10.Exit without bringing CAN controller online.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int setupNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG testBaudRate;
UINT samplePoint;
STATUS retCode = OK;
UCHAR channelRx;
/*default settings*/
if(ctrlr == 1)
{
pDev1 = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL1);
assert(pDev1);
CAN_InstallISRCallback(pDev1, test_isr1);
pDev = pDev1;
ArrayIndex1 = 0;
}
else
{
pDev0 = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL0);
assert(pDev0);
CAN_InstallISRCallback(pDev0, test_isr0);
pDev = pDev0;
ArrayIndex0 = 0;
}
CAN_Init(pDev);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("Resetting baud to %d\n", DEMO_BAUD_RATE,0,0,0,0,0);
CAN_SetBitTiming(pDev, DEMO_TSEG1, DEMO_TSEG2, DEMO_BAUD_RATE_PRESCALAR,
DEMO_SJW, DEMO_SAMPLES_BOOL);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("**Unable to set %d baud with selected bit timing parameters \
.\n", DEMO_BAUD_RATE,0,0,0,0,0);
logMsg("**If baud rate is off by a factor of 2, check the UMCR \
HSPEED bit setting\n",0,0,0,0,0,0);
logMsg("**Adjust macro DEMO_BAUD_RATE_PRESCALAR defined at the \
begining of this file accordingly\n",0,0,0,0,0,0);
releaseNode(ctrlr);
return ERROR;
}
}
/* Enable interrupts */
CAN_SetIntMask(pDev, WNCAN_INT_ALL);
CAN_EnableInt(pDev);
/* Set up global filter to receive all standard messages */
retCode = CAN_SetGlobalRxFilter(pDev, 0, FALSE);
if(retCode != OK)
logMsg("Error: Set global Rx filter failed \n",0,0,0,0,0,0);
/* Set up receive message buffer */
CAN_GetRxChannel(pDev, &channelRx);
/*
* If set global filter failed, perhaps this controller has a local filter
* that we could use.
*/
if (retCode != OK)
CAN_SetLocalMsgFilter(pDev, channelRx, 0, FALSE);
retCode = CAN_WriteID(pDev, channelRx, 0, FALSE);
if(retCode != OK)
{
logMsg("Error: Write ID failed on channel %d \n",channelRx,0,0,0,0,0);
return ERROR;
}
CAN_EnableChannel(pDev, channelRx, WNCAN_INT_RX);
/* pick chn#14 to receive all, because on some ctrls, it's the only
** channel that will receive using the filters.
*/
/*Enable channel 14 to receive messages*/
CAN_SetMode(pDev, 14, WNCAN_CHN_RECEIVE);
/* Set up local filter to receive all extended messages */
CAN_SetLocalMsgFilter(pDev, 14, 0, TRUE);
CAN_WriteID(pDev, 14, 0, TRUE);
CAN_EnableChannel(pDev, 14, WNCAN_INT_RX);
return OK;
}
/**************************************************************************
*
* transmitMsg - Transmit message using CAN_TxMsg
*
* This function gets transmit channel and transmits message with standard
* id 0x180, with eight data bytes.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int transmitMsg
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG id=DEMO_ID0;
STATUS retCode;
UCHAR channelTx;
UCHAR data[8]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
if(ctrlr == 1)
{
pDev = pDev1;
id = DEMO_ID1;
}
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
retCode = CAN_GetTxChannel(pDev, &channelTx);
if(retCode != OK)
{
logMsg("Transmitter not available\n",0,0,0,0,0,0);
return ERROR;
}
CAN_EnableChannel(pDev, channelTx, WNCAN_INT_TX);
retCode = CAN_TxMsg(pDev, channelTx, id, FALSE, data, 8);
if(retCode != OK)
{
logMsg("error in tx msg setup \n",0,0,0,0,0,0);
return ERROR;
}
return OK;
}
/**************************************************************************
*
* stopNode - Bring CAN controller offline
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int stopNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Stop(pDev);
return OK;
}
/**************************************************************************
*
* startNode - Bring CAN controller online
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int startNode(int ctrlr)
{
struct WNCAN_Device *pDev;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Start(pDev);
return OK;
}
/**************************************************************************
*
* releaseNode - Release device pointer to CAN controller
*
* This function does the following:
*
* 1. Abort all pending transmissions
* 2. Bring CAN controller offline
* 3. Disable and Free all channels
* 4. Disable interrupts
* 5. Give up device pointer
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int releaseNode
(
int ctrlr
)
{
int i;
if(ctrlr == 1)
{
/*Check if pDev1 is valid*/
if(NULL==pDev1){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_TxAbort(pDev1);
CAN_Stop(pDev1);
for(i=0;i<pDev1->pCtrl->numChn;i++)
{
CAN_DisableChannel(pDev1, i);
CAN_FreeChannel(pDev1, i);
}
CAN_DisableInt(pDev1);
CAN_Close(pDev1);
pDev1=NULL;
}
else
{
/*Check if pDev1 is valid*/
if(NULL==pDev0){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_TxAbort(pDev0);
CAN_Stop(pDev0);
for(i=0;i<pDev0->pCtrl->numChn;i++)
{
CAN_DisableChannel(pDev0, i);
CAN_FreeChannel(pDev0, i);
}
CAN_DisableInt(pDev0);
CAN_Close(pDev0);
pDev0=NULL;
}
return OK;
}
/**************************************************************************
*
* statusNode - Print bus Status to stdout
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int statusNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
WNCAN_BusStatus busStatus;
long globalMask;
long localMask;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
busStatus = CAN_GetBusStatus(pDev);
if(busStatus == WNCAN_BUS_OFF)
logMsg("Bus status is BUS OFF \n",0,0,0,0,0,0);
else if(busStatus == WNCAN_BUS_WARN)
logMsg("Bus status is BUS WARNING, more than 96 transmit errors have \
occured \n",0,0,0,0,0,0);
else
logMsg("Bus status is BUS OK, error active \n",0,0,0,0,0,0);
globalMask = CAN_GetGlobalRxFilter(pDev, 0);
logMsg("Global Filter is %x \n",globalMask,0,0,0,0,0);
localMask = CAN_GetLocalMsgFilter(pDev, 14, 1);
logMsg("Local Filter is %x \n",localMask,0,0,0,0,0);
return OK;
}
/**************************************************************************
*
* printRxMsg - Print all the received message identifiers and data to stdout
*
* Received message ids are recorded in an array by the ISR call back function.
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int printRxMsg
(
int ctrlr
)
{
int i;
if(ctrlr == 1)
{
for(i=0;i<ArrayIndex1;i++)
{
logMsg("Id[%d] = %x and extFlag is %d \n", i, id1[i], extFlag1[i],0,0,0);
}
}
else
{
for(i=0;i<ArrayIndex0;i++)
{
logMsg("Id[%d] = %x and extFlag is %d \n", i, id0[i], extFlag0[i],0,0,0);
}
}
return OK;
}
/**************************************************************************
*
* ISR call back function for ctrlr 0
*
*/
void test_isr0(struct WNCAN_Device *pDev, WNCAN_IntType intStatus, UCHAR channelNum)
{
WNCAN_BusError busErr;
if(intStatus == WNCAN_INT_WAKE_UP)
flagAwake0++;
if(intStatus == WNCAN_INT_TX)
{
CAN_DisableChannel(pDev, channelNum);
CAN_FreeChannel(pDev, channelNum);
}
if(intStatus == WNCAN_INT_RX)
{
id0[ArrayIndex0] = CAN_ReadID(pDev, channelNum, &extFlag0[ArrayIndex0]);
(ArrayIndex0 >= 99)?ArrayIndex0=0:ArrayIndex0++;
}
if(intStatus == WNCAN_INT_ERROR)
{
logMsg("CAN bus error occurred: ",0,0,0,0,0,0);
busErr = CAN_GetBusError(pDev);
switch(busErr)
{
case WNCAN_ERR_BIT:
logMsg("WNCAN_ERR_BIT \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_ACK:
logMsg("WNCAN_ERR_ACK \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_CRC:
logMsg("WNCAN_ERR_CRC \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_FORM:
logMsg("WNCAN_ERR_FORM \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_STUFF:
logMsg("WNCAN_ERR_STUFF \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_NONE:
logMsg("WNCAN_ERR_NONE \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_UNKNOWN:
default:
logMsg("WNCAN_ERR_UNKNOWN \n",0,0,0,0,0,0);
break;
}
}
if(intStatus == WNCAN_INT_BUS_OFF)
releaseNode(0);
}
/**************************************************************************
*
* ISR call back function for ctrlr 1
*
*/
void test_isr1(struct WNCAN_Device *pDev, WNCAN_IntType intStatus, UCHAR channelNum)
{
WNCAN_BusError busErr;
if(intStatus == WNCAN_INT_WAKE_UP)
flagAwake1++;
if(intStatus == WNCAN_INT_TX)
{
CAN_DisableChannel(pDev, channelNum);
CAN_FreeChannel(pDev, channelNum);
}
if(intStatus == WNCAN_INT_RX)
{
id1[ArrayIndex1] = CAN_ReadID(pDev, channelNum, &extFlag1[ArrayIndex1]);
(ArrayIndex1 >= 99)?ArrayIndex1=0:ArrayIndex1++;
}
if(intStatus == WNCAN_INT_ERROR)
{
logMsg("CAN bus error occurred: ",0,0,0,0,0,0);
busErr = CAN_GetBusError(pDev);
switch(busErr)
{
case WNCAN_ERR_BIT:
logMsg("WNCAN_ERR_BIT \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_ACK:
logMsg("WNCAN_ERR_ACK \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_CRC:
logMsg("WNCAN_ERR_CRC \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_FORM:
logMsg("WNCAN_ERR_FORM \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_STUFF:
logMsg("WNCAN_ERR_STUFF \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_NONE:
logMsg("WNCAN_ERR_NONE \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_UNKNOWN:
default:
logMsg("WNCAN_ERR_UNKNOWN \n",0,0,0,0,0,0);
break;
}
}
if(intStatus == WNCAN_INT_BUS_OFF)
releaseNode(1);
}
@@ -0,0 +1,485 @@
/* sample_MCF5282.c - Sample application using Windnet 1.4 CAN api */
/* Copyright */
/*
modification history
---------------------
01e,06oct05,lsg make sure include file names are case-sensitive for Linux
hosts
01d,20may05,lsg add graceful return from some functions
01c,18apr05,lsg fix bug in ISR callback
01b,25jun04,lsg added macros for bit timing specific to MCF5282 FlexCAN
01a,4Oct02,lsg created sample application for techpubs
*/
/*
DESCRIPTION
This module is a sample application provided with the Windnet CAN api
documentation. The purpose is to demonstrate the use of CAN api, and
the sequence in which they must be called.
INCLUDE FILES:
*/
/* includes */
#include <vxWorks.h>
#include <stdio.h>
#include <errnoLib.h>
#include <CAN/wnCAN.h>
#include <CAN/flexcanOffsets.h>
#include <assert.h>
#include <logLib.h>
/* defines */
/**************************************************************************/
#define DEMO_BOARD WNCAN_MCF5282
#define DEMO_CTRL0 0
#define NUM_CTRLRS 1
#define DEMO_ID0 0x180
#define DEMO_TSEG1 4
#define DEMO_TSEG2 5
#define DEMO_BAUD_RATE_PRESCALAR 7
#define DEMO_SJW 2
#define DEMO_SAMPLES_BOOL 0
#define DEMO_BAUD_RATE 125000
#define DEMO_PROP_SEG 7
/**************************************************************************/
/* globals */
struct WNCAN_Device *pDev=NULL;
int flagAwake;
ULONG id[100];
BOOL extFlag[100];
int ArrayIndex;
/* forward declarations */
void test_isr(struct WNCAN_Device *pDev1, WNCAN_IntType intstatus,
UCHAR channelNum);
int releaseNode(int);
/**************************************************************************
*
* setupNode - Set up CAN ctrlr.
*
* This routine does the following:
* 1. Get device pointer.
* 2. Initialize CAN controller.
* 3. Set bit timing values to enable baud rate of 125K
* 4. Set interrupt mask to enable all interrupts.
* 5. Enable Interrupts.
* 6. Set global receive filter to receive all standard identifiers.
* 7. Assign a channel for reception.
* 8. Set local filter for channel number 14 (channels numbered 0 to 14)
* to receive all extended identifiers
* 9. Enable channel 14 for reception of extended identifiers.
* 10.Exit without bringing CAN controller online.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int setupNode
(
int ctrlr
)
{
ULONG testBaudRate;
UINT samplePoint;
STATUS retCode = OK;
UCHAR channelRx;
/*default settings*/
pDev = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL0);
assert(pDev);
CAN_InstallISRCallback(pDev, test_isr);
ArrayIndex = 0;
CAN_Init(pDev);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("Resetting baud to %d\n", DEMO_BAUD_RATE,0,0,0,0,0);
CAN_SetBitTiming(pDev, DEMO_TSEG1, DEMO_TSEG2, DEMO_BAUD_RATE_PRESCALAR,
DEMO_SJW, DEMO_SAMPLES_BOOL);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("**Unable to set %d baud with selected bit timing parameters \
.\n", DEMO_BAUD_RATE,0,0,0,0,0);
logMsg("**If baud rate is off by a factor of 2, check the UMCR \
HSPEED bit setting\n",0,0,0,0,0,0);
logMsg("**Adjust macro DEMO_BAUD_RATE_PRESCALAR defined at the \
begining of this file accordingly\n",0,0,0,0,0,0);
releaseNode(ctrlr);
return ERROR;
}
}
/* Enable interrupts */
CAN_SetIntMask(pDev, WNCAN_INT_ALL);
CAN_EnableInt(pDev);
/* Set up global filter to receive all standard messages */
retCode = CAN_SetGlobalRxFilter(pDev, 0, FALSE);
if(retCode != OK)
logMsg("Error: Set global Rx filter failed \n",0,0,0,0,0,0);
/* Set up receive message buffer */
CAN_GetRxChannel(pDev, &channelRx);
/*
* If set global filter failed, perhaps this controller has a local filter
* that we could use.
*/
if (retCode != OK)
CAN_SetLocalMsgFilter(pDev, channelRx, 0, FALSE);
retCode = CAN_WriteID(pDev, channelRx, 0, FALSE);
if(retCode != OK)
{
logMsg("Error: Write ID failed on channel %d \n",channelRx,0,0,0,0,0);
return ERROR;
}
CAN_EnableChannel(pDev, channelRx, WNCAN_INT_RX);
/* pick chn#14 to receive all, because on some ctrls, it's the only
** channel that will receive using the filters.
*/
/*Enable channel 14 to receive messages*/
CAN_SetMode(pDev, 14, WNCAN_CHN_RECEIVE);
/* Set up local filter to receive all extended messages */
CAN_SetLocalMsgFilter(pDev, 14, 0, TRUE);
CAN_WriteID(pDev, 14, 0, TRUE);
CAN_EnableChannel(pDev, 14, WNCAN_INT_RX);
return OK;
}
/**************************************************************************
*
* transmitMsg - Transmit message using CAN_TxMsg
*
* This function gets transmit channel and transmits message with standard
* id 0x180, with eight data bytes.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int transmitMsg
(
int ctrlr
)
{
ULONG id=DEMO_ID0;
STATUS retCode;
UCHAR channelTx;
UCHAR data[8]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
retCode = CAN_GetTxChannel(pDev, &channelTx);
if(retCode != OK)
{
logMsg("Transmitter not available\n",0,0,0,0,0,0);
return ERROR;
}
CAN_EnableChannel(pDev, channelTx, WNCAN_INT_TX);
retCode = CAN_TxMsg(pDev, channelTx, id, FALSE, data, 8);
if(retCode != OK)
{
logMsg("error in tx msg setup \n",0,0,0,0,0,0);
return ERROR;
}
return OK;
}
/**************************************************************************
*
* stopNode - Bring CAN controller offline
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int stopNode
(
int ctrlr
)
{
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Stop(pDev);
return OK;
}
/**************************************************************************
*
* startNode - Bring CAN controller online
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int startNode(int ctrlr)
{
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Start(pDev);
return OK;
}
/**************************************************************************
*
* releaseNode - Release device pointer to CAN controller
*
* This function does the following:
*
* 1. Abort all pending transmissions
* 2. Bring CAN controller offline
* 3. Disable and Free all channels
* 4. Disable interrupts
* 5. Give up device pointer
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int releaseNode
(
int ctrlr
)
{
int i;
/*Check if pDev1 is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_TxAbort(pDev);
CAN_Stop(pDev);
for(i=0;i<pDev->pCtrl->numChn;i++)
{
CAN_DisableChannel(pDev, i);
CAN_FreeChannel(pDev, i);
}
CAN_DisableInt(pDev);
CAN_Close(pDev);
pDev=NULL;
return OK;
}
/**************************************************************************
*
* statusNode - Print bus Status to stdout
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int statusNode
(
int ctrlr
)
{
WNCAN_BusStatus busStatus;
long globalMask;
long localMask;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
busStatus = CAN_GetBusStatus(pDev);
if(busStatus == WNCAN_BUS_OFF)
logMsg("Bus status is BUS OFF \n",0,0,0,0,0,0);
else if(busStatus == WNCAN_BUS_WARN)
logMsg("Bus status is BUS WARNING, more than 96 transmit errors have \
occured \n",0,0,0,0,0,0);
else
logMsg("Bus status is BUS OK, error active \n",0,0,0,0,0,0);
globalMask = CAN_GetGlobalRxFilter(pDev, 0);
logMsg("Global Filter is %x \n",globalMask,0,0,0,0,0);
localMask = CAN_GetLocalMsgFilter(pDev, 14, 1);
logMsg("Local Filter is %x \n",localMask,0,0,0,0,0);
return OK;
}
/**************************************************************************
*
* printRxMsg - Print all the received message identifiers and data to stdout
*
* Received message ids are recorded in an array by the ISR call back function.
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int printRxMsg
(
int ctrlr
)
{
int i;
for(i=0;i<ArrayIndex;i++)
{
logMsg("\r\n",0,0,0,0,0,0);
logMsg("Id[%d] = %x and extFlag is %d \n", i, id[i], extFlag[i],0,0,0);
}
return OK;
}
/**************************************************************************
*
* ISR call back function for ctrlr
*
*/
void test_isr(struct WNCAN_Device *pDev, WNCAN_IntType intStatus, UCHAR channelNum)
{
WNCAN_BusError busErr;
if(intStatus == WNCAN_INT_WAKE_UP)
flagAwake++;
if(intStatus == WNCAN_INT_TX)
{
CAN_DisableChannel(pDev, channelNum);
CAN_FreeChannel(pDev, channelNum);
}
if(intStatus == WNCAN_INT_RX)
{
id[ArrayIndex] = CAN_ReadID(pDev, channelNum, &extFlag[ArrayIndex]);
(ArrayIndex >= 99)?ArrayIndex=0:ArrayIndex ++;
}
if(intStatus == WNCAN_INT_ERROR)
{
logMsg("CAN bus error occurred: ",0,0,0,0,0,0);
busErr = CAN_GetBusError(pDev);
switch(busErr)
{
case WNCAN_ERR_BIT:
logMsg("WNCAN_ERR_BIT \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_ACK:
logMsg("WNCAN_ERR_ACK \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_CRC:
logMsg("WNCAN_ERR_CRC \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_FORM:
logMsg("WNCAN_ERR_FORM \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_STUFF:
logMsg("WNCAN_ERR_STUFF \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_NONE:
logMsg("WNCAN_ERR_NONE \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_UNKNOWN:
default:
logMsg("WNCAN_ERR_UNKNOWN \n",0,0,0,0,0,0);
break;
}
}
if(intStatus == WNCAN_INT_BUS_OFF)
releaseNode(0);
}
@@ -0,0 +1,639 @@
/* sample_MSMCAN.c - Sample application using Windnet 1.4 CAN api */
/* Copyright */
/*
modification history
---------------------
01e,06oct05,lsg make sure include file names are case-sensitive for Linux
hosts
01d,20may05,lsg Add graceful exits from functions
01c,18apr05,lsg fix bug in ISR callback
01b,25jun04,lsg added macros for bit timing specific to MSMCAN board
01a,4Oct02,lsg created sample application for techpubs
*/
/*
DESCRIPTION
This module is a sample application provided with the Windnet CAN api
documentation. The purpose is to demonstrate the use of CAN api, and
the sequence in which they must be called.
INCLUDE FILES:
*/
/* includes */
#include <vxWorks.h>
#include <stdio.h>
#include <errnoLib.h>
#include <CAN/wnCAN.h>
#include <CAN/i82527Offsets.h>
#include <assert.h>
#include <logLib.h>
/* defines */
/**************************************************************************/
#define DEMO_BOARD WNCAN_MSMCAN
#define DEMO_CTRL0 0
#define DEMO_CTRL1 0xff /*not applicable*/
#define NUM_CTRLRS 1
#define DEMO_ID0 0x180
#define DEMO_ID1 0 /*not applicable*/
#define DEMO_TSEG1 0xc
#define DEMO_TSEG2 0x1
#define DEMO_BAUD_RATE_PRESCALAR 3
#define DEMO_SJW 0
#define DEMO_SAMPLES_BOOL 0
#define DEMO_BAUD_RATE 125000
#define DEMO_PROP_SEG 0 /*not applicable*/
/**************************************************************************/
/* globals */
struct WNCAN_Device *pDev0=NULL;
struct WNCAN_Device *pDev1=NULL;
int flagAwake0;
ULONG id0[100];
BOOL extFlag0[100];
int ArrayIndex0;
int flagAwake1;
ULONG id1[100];
BOOL extFlag1[100];
int ArrayIndex1;
/* forward declarations */
void test_isr0(struct WNCAN_Device *pDev1, WNCAN_IntType intstatus,
UCHAR channelNum);
void test_isr1(struct WNCAN_Device *pDev1, WNCAN_IntType intStatus,
UCHAR channelNum);
int releaseNode(int);
/**************************************************************************
*
* setupNode - Set up CAN ctrlr.
*
* This routine does the following:
* 1. Get device pointer.
* 2. Initialize CAN controller.
* 3. Set bit timing values to enable baud rate of 125K
* 4. Set interrupt mask to enable all interrupts.
* 5. Enable Interrupts.
* 6. Set global receive filter to receive all standard identifiers.
* 7. Assign a channel for reception.
* 8. Set local filter for channel number 14 (channels numbered 0 to 14)
* to receive all extended identifiers
* 9. Enable channel 14 for reception of extended identifiers.
* 10.Exit without bringing CAN controller online.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int setupNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG testBaudRate;
UINT samplePoint;
STATUS retCode = OK;
UCHAR channelRx;
/*default settings*/
if(ctrlr == 1)
{
pDev1 = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL1);
assert(pDev1);
CAN_InstallISRCallback(pDev1, test_isr1);
pDev = pDev1;
ArrayIndex1 = 0;
}
else
{
pDev0 = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL0);
assert(pDev0);
CAN_InstallISRCallback(pDev0, test_isr0);
pDev = pDev0;
ArrayIndex0 = 0;
}
CAN_Init(pDev);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("Resetting baud to %d\n", DEMO_BAUD_RATE,0,0,0,0,0);
CAN_SetBitTiming(pDev, DEMO_TSEG1, DEMO_TSEG2, DEMO_BAUD_RATE_PRESCALAR,
DEMO_SJW, DEMO_SAMPLES_BOOL);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("**Unable to set %d baud with selected bit timing parameters \
.\n", DEMO_BAUD_RATE,0,0,0,0,0);
logMsg("**If baud rate is off by a factor of 2, check the UMCR \
HSPEED bit setting\n",0,0,0,0,0,0);
logMsg("**Adjust macro DEMO_BAUD_RATE_PRESCALAR defined at the \
begining of this file accordingly\n",0,0,0,0,0,0);
releaseNode(ctrlr);
return ERROR;
}
}
/* Enable interrupts */
CAN_SetIntMask(pDev, WNCAN_INT_ALL);
CAN_EnableInt(pDev);
/* Set up global filter to receive all standard messages */
retCode = CAN_SetGlobalRxFilter(pDev, 0, FALSE);
if(retCode != OK)
logMsg("Global Rx Filter could not be set \n",0,0,0,0,0,0);
/* Set up receive message buffer */
CAN_GetRxChannel(pDev, &channelRx);
/*
* If set global filter failed, perhaps this controller has a local filter
* that we could use.
*/
if (retCode != OK)
CAN_SetLocalMsgFilter(pDev, channelRx, 0, FALSE);
retCode = CAN_WriteID(pDev, channelRx, 0, FALSE);
if(retCode != OK)
return ERROR;
CAN_EnableChannel(pDev, channelRx, WNCAN_INT_RX);
/* pick chn#14 to receive all, because on some ctrls, it's the only
** channel that will receive using the filters.
*/
/*Enable channel 14 to receive messages*/
CAN_SetMode(pDev, 14, WNCAN_CHN_RECEIVE);
/* Set up local filter to receive all extended messages */
CAN_SetLocalMsgFilter(pDev, 14, 0, TRUE);
retCode = CAN_WriteID(pDev, 14, 0, TRUE);
if(retCode != OK)
logMsg("Error in writing ID to channel number %d \n",14,0,0,0,0,0);
CAN_EnableChannel(pDev, 14, WNCAN_INT_RX);
return OK;
}
/**************************************************************************
*
* transmitMsg - Transmit message using CAN_TxMsg
*
* This function gets transmit channel and transmits message with standard
* id 0x180, with eight data bytes.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int transmitMsg
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG id=DEMO_ID0;
STATUS retCode;
UCHAR channelTx;
UCHAR data[8]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
if(ctrlr == 1)
{
pDev = pDev1;
id = DEMO_ID1;
}
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
retCode = CAN_GetTxChannel(pDev, &channelTx);
if(retCode != OK)
{
logMsg("Transmitter not available\n",0,0,0,0,0,0);
return ERROR;
}
CAN_EnableChannel(pDev, channelTx, WNCAN_INT_TX);
retCode = CAN_TxMsg(pDev, channelTx, id, FALSE, data, 8);
if(retCode != OK)
{
logMsg("error in tx msg setup \n",0,0,0,0,0,0);
return ERROR;
}
return OK;
}
/**************************************************************************
*
* stopNode - Bring CAN controller offline
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int stopNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Stop(pDev);
return OK;
}
/**************************************************************************
*
* startNode - Bring CAN controller online
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int startNode(int ctrlr)
{
struct WNCAN_Device *pDev;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Start(pDev);
return OK;
}
/**************************************************************************
*
* releaseNode - Release device pointer to CAN controller
*
* This function does the following:
*
* 1. Abort all pending transmissions
* 2. Bring CAN controller offline
* 3. Disable and Free all channels
* 4. Disable interrupts
* 5. Give up device pointer
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int releaseNode
(
int ctrlr
)
{
int i;
if(ctrlr == 1)
{
/*Check if pDev1 is valid*/
if(NULL==pDev1){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_TxAbort(pDev1);
CAN_Stop(pDev1);
for(i=0;i<pDev1->pCtrl->numChn;i++)
{
CAN_DisableChannel(pDev1, i);
CAN_FreeChannel(pDev1, i);
}
CAN_DisableInt(pDev1);
CAN_Close(pDev1);
pDev1=NULL;
}
else
{
/*Check if pDev0 is valid*/
if(NULL==pDev0){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_TxAbort(pDev0);
CAN_Stop(pDev0);
for(i=0;i<pDev0->pCtrl->numChn;i++)
{
CAN_DisableChannel(pDev0, i);
CAN_FreeChannel(pDev0, i);
}
CAN_DisableInt(pDev0);
CAN_Close(pDev0);
pDev0=NULL;
}
return OK;
}
/**************************************************************************
*
* statusNode - Print bus Status to stdout
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int statusNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
WNCAN_BusStatus busStatus;
long globalMask;
long localMask;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
busStatus = CAN_GetBusStatus(pDev);
if(busStatus == WNCAN_BUS_OFF)
logMsg("Bus status is BUS OFF \n",0,0,0,0,0,0);
else if(busStatus == WNCAN_BUS_WARN)
logMsg("Bus status is BUS WARNING, more than 96 transmit errors have \
occured \n",0,0,0,0,0,0);
else
logMsg("Bus status is BUS OK, error active \n",0,0,0,0,0,0);
globalMask = CAN_GetGlobalRxFilter(pDev, 0);
logMsg("Global Filter is %x \n",globalMask,0,0,0,0,0);
localMask = CAN_GetLocalMsgFilter(pDev, 14, 1);
logMsg("Local Filter is %x \n",localMask,0,0,0,0,0);
return OK;
}
/**************************************************************************
*
* printRxMsg - Print all the received message identifiers and data to stdout
*
* Received message ids are recorded in an array by the ISR call back function.
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int printRxMsg
(
int ctrlr
)
{
int i;
if(ctrlr == 1)
{
for(i=0;i<ArrayIndex1;i++)
{
logMsg("Id[%d] = %x and extFlag is %d \n", i, id1[i], extFlag1[i],0,0,0);
}
}
else
{
for(i=0;i<ArrayIndex0;i++)
{
logMsg("Id[%d] = %x and extFlag is %d \n", i, id0[i], extFlag0[i],0,0,0);
}
}
return OK;
}
/**************************************************************************
*
* ISR call back function for ctrlr 0
*
*/
void test_isr0(struct WNCAN_Device *pDev, WNCAN_IntType intStatus, UCHAR channelNum)
{
WNCAN_BusError busErr;
STATUS retCode;
if(intStatus == WNCAN_INT_WAKE_UP)
flagAwake0++;
if(intStatus == WNCAN_INT_TX)
{
retCode = CAN_DisableChannel(pDev, channelNum);
if(retCode)
logMsg("Error: disable channel failed \n",0,0,0,0,0,0);
retCode = CAN_FreeChannel(pDev, channelNum);
if(retCode)
logMsg("Error: free channel failed \n",0,0,0,0,0,0);
}
if(intStatus == WNCAN_INT_RX)
{
id0[ArrayIndex0] = CAN_ReadID(pDev, channelNum, &extFlag0[ArrayIndex0]);
(ArrayIndex0 >= 99)?ArrayIndex0=0:ArrayIndex0++;
}
if(intStatus == WNCAN_INT_ERROR)
{
logMsg("CAN bus error occurred: ",0,0,0,0,0,0);
busErr = CAN_GetBusError(pDev);
switch(busErr)
{
case WNCAN_ERR_BIT:
logMsg("WNCAN_ERR_BIT \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_ACK:
logMsg("WNCAN_ERR_ACK \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_CRC:
logMsg("WNCAN_ERR_CRC \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_FORM:
logMsg("WNCAN_ERR_FORM \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_STUFF:
logMsg("WNCAN_ERR_STUFF \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_NONE:
logMsg("WNCAN_ERR_NONE \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_UNKNOWN:
default:
logMsg("WNCAN_ERR_UNKNOWN \n",0,0,0,0,0,0);
break;
}
}
if(intStatus == WNCAN_INT_BUS_OFF)
releaseNode(0);
}
/**************************************************************************
*
* ISR call back function for ctrlr 1
*
*/
void test_isr1(struct WNCAN_Device *pDev, WNCAN_IntType intStatus, UCHAR channelNum)
{
WNCAN_BusError busErr;
STATUS retCode;
if(intStatus == WNCAN_INT_WAKE_UP)
flagAwake1++;
if(intStatus == WNCAN_INT_TX)
{
retCode = CAN_DisableChannel(pDev, channelNum);
if(retCode)
logMsg("Error: disable channel failed \n",0,0,0,0,0,0);
retCode = CAN_FreeChannel(pDev, channelNum);
if(retCode)
logMsg("Error: Free channel failed \n",0,0,0,0,0,0);
}
if(intStatus == WNCAN_INT_RX)
{
id1[ArrayIndex1] = CAN_ReadID(pDev, channelNum, &extFlag1[ArrayIndex1]);
(ArrayIndex1 >= 99)?ArrayIndex1=0:ArrayIndex1++;
}
if(intStatus == WNCAN_INT_ERROR)
{
logMsg("CAN bus error occurred: ",0,0,0,0,0,0);
busErr = CAN_GetBusError(pDev);
switch(busErr)
{
case WNCAN_ERR_BIT:
logMsg("WNCAN_ERR_BIT \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_ACK:
logMsg("WNCAN_ERR_ACK \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_CRC:
logMsg("WNCAN_ERR_CRC \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_FORM:
logMsg("WNCAN_ERR_FORM \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_STUFF:
logMsg("WNCAN_ERR_STUFF \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_NONE:
logMsg("WNCAN_ERR_NONE \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_UNKNOWN:
default:
logMsg("WNCAN_ERR_UNKNOWN \n",0,0,0,0,0,0);
break;
}
}
if(intStatus == WNCAN_INT_BUS_OFF)
releaseNode(1);
}
@@ -0,0 +1,632 @@
/* sample_PPC5xx.c - Sample application using Windnet 1.4 CAN api */
/* Copyright */
/*
modification history
---------------------
01e,06oct05,lsg make sure include file names are case-sensitive for Linux
hosts
01d,20may05,lsg Add graceful exits from functions
01c,18apr05,lsg fix bug in ISR callback
01b,24jun04,lsg added macros for bit timing specific to PPC5xx TouCAN
01a,4Oct02,lsg created sample application for techpubs
*/
/*
DESCRIPTION
This module is a sample application provided with the Windnet CAN api
documentation. The purpose is to demonstrate the use of CAN api, and
the sequence in which they must be called.
INCLUDE FILES:
*/
/* includes */
#include <vxWorks.h>
#include <stdio.h>
#include <errnoLib.h>
#include <CAN/wnCAN.h>
#include <CAN/toucanOffsets.h>
#include <assert.h>
#include <logLib.h>
/* defines */
/**************************************************************************/
#define DEMO_BOARD WNCAN_PPC5XX
#define DEMO_CTRL0 0
#define DEMO_CTRL1 1
#define NUM_CTRLRS 2
#define DEMO_ID0 0x180
#define DEMO_ID1 0x190
#define DEMO_TSEG1 7
#define DEMO_TSEG2 2
/*Adjust the value of baud rate prescalar according to UMCR_HSPEED setting */
/*Assuming UMCR HSPEED is 0 */
#define DEMO_BAUD_RATE_PRESCALAR 0xf
#define DEMO_SJW 0
#define DEMO_SAMPLES_BOOL 0
#define DEMO_BAUD_RATE 125000
#define DEMO_PROP_SEG 7
/**************************************************************************/
/* globals */
struct WNCAN_Device *pDev0=NULL;
struct WNCAN_Device *pDev1=NULL;
int flagAwake0;
ULONG id0[100];
BOOL extFlag0[100];
int ArrayIndex0;
int flagAwake1;
ULONG id1[100];
BOOL extFlag1[100];
int ArrayIndex1;
/* forward declarations */
void test_isr0(struct WNCAN_Device *pDev1, WNCAN_IntType intstatus,
UCHAR channelNum);
void test_isr1(struct WNCAN_Device *pDev1, WNCAN_IntType intStatus,
UCHAR channelNum);
int releaseNode(int);
/**************************************************************************
*
* setupNode - Set up CAN ctrlr.
*
* This routine does the following:
* 1. Get device pointer.
* 2. Initialize CAN controller.
* 3. Set bit timing values to enable baud rate of 125K
* 4. Set interrupt mask to enable all interrupts.
* 5. Enable Interrupts.
* 6. Set global receive filter to receive all standard identifiers.
* 7. Assign a channel for reception.
* 8. Set local filter for channel number 14 (channels numbered 0 to 14)
* to receive all extended identifiers
* 9. Enable channel 14 for reception of extended identifiers.
* 10.Exit without bringing CAN controller online.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int setupNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG testBaudRate;
UINT samplePoint;
STATUS retCode = OK;
UCHAR channelRx;
/*default settings*/
if(ctrlr == 1)
{
pDev1 = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL1);
assert(pDev1);
CAN_InstallISRCallback(pDev1, test_isr1);
pDev = pDev1;
ArrayIndex1 = 0;
}
else
{
pDev0 = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL0);
assert(pDev0);
CAN_InstallISRCallback(pDev0, test_isr0);
pDev = pDev0;
ArrayIndex0 = 0;
}
CAN_Init(pDev);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("Resetting baud to %d\n", DEMO_BAUD_RATE,0,0,0,0,0);
CAN_SetBitTiming(pDev, DEMO_TSEG1, DEMO_TSEG2, DEMO_BAUD_RATE_PRESCALAR,
DEMO_SJW, DEMO_SAMPLES_BOOL);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("**Unable to set %d baud with selected bit timing parameters \
.\n", DEMO_BAUD_RATE,0,0,0,0,0);
logMsg("**If baud rate is off by a factor of 2, check the UMCR \
HSPEED bit setting\n",0,0,0,0,0,0);
logMsg("**Adjust macro DEMO_BAUD_RATE_PRESCALAR defined at the \
begining of this file accordingly\n",0,0,0,0,0,0);
releaseNode(ctrlr);
return ERROR;
}
}
/* Enable interrupts */
CAN_SetIntMask(pDev, WNCAN_INT_ALL);
CAN_EnableInt(pDev);
/* Set up global filter to receive all standard messages */
retCode = CAN_SetGlobalRxFilter(pDev, 0, FALSE);
if(retCode != OK)
logMsg("Error: Set global Rx filter failed \n",0,0,0,0,0,0);
/* Set up receive message buffer */
CAN_GetRxChannel(pDev, &channelRx);
/*
* If set global filter failed, perhaps this controller has a local filter
* that we could use.
*/
if (retCode != OK)
CAN_SetLocalMsgFilter(pDev, channelRx, 0, FALSE);
retCode = CAN_WriteID(pDev, channelRx, 0, FALSE);
if(retCode != OK)
{
logMsg("Error: Write ID failed on channel %d \n",channelRx,0,0,0,0,0);
return ERROR;
}
CAN_EnableChannel(pDev, channelRx, WNCAN_INT_RX);
/* pick chn#14 to receive all, because on some ctrls, it's the only
** channel that will receive using the filters.
*/
/*Enable channel 14 to receive messages*/
CAN_SetMode(pDev, 14, WNCAN_CHN_RECEIVE);
/* Set up local filter to receive all extended messages */
CAN_SetLocalMsgFilter(pDev, 14, 0, TRUE);
CAN_WriteID(pDev, 14, 0, TRUE);
CAN_EnableChannel(pDev, 14, WNCAN_INT_RX);
return OK;
}
/**************************************************************************
*
* transmitMsg - Transmit message using CAN_TxMsg
*
* This function gets transmit channel and transmits message with standard
* id 0x180, with eight data bytes.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int transmitMsg
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG id=DEMO_ID0;
STATUS retCode;
UCHAR channelTx;
UCHAR data[8]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
if(ctrlr == 1)
{
pDev = pDev1;
id = DEMO_ID1;
}
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
retCode = CAN_GetTxChannel(pDev, &channelTx);
if(retCode != OK)
{
logMsg("Transmitter not available\n",0,0,0,0,0,0);
return ERROR;
}
CAN_EnableChannel(pDev, channelTx, WNCAN_INT_TX);
retCode = CAN_TxMsg(pDev, channelTx, id, FALSE, data, 8);
if(retCode != OK)
{
logMsg("error in tx msg setup \n",0,0,0,0,0,0);
return ERROR;
}
return OK;
}
/**************************************************************************
*
* stopNode - Bring CAN controller offline
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int stopNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Stop(pDev);
return OK;
}
/**************************************************************************
*
* startNode - Bring CAN controller online
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int startNode(int ctrlr)
{
struct WNCAN_Device *pDev;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Start(pDev);
return OK;
}
/**************************************************************************
*
* releaseNode - Release device pointer to CAN controller
*
* This function does the following:
*
* 1. Abort all pending transmissions
* 2. Bring CAN controller offline
* 3. Disable and Free all channels
* 4. Disable interrupts
* 5. Give up device pointer
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int releaseNode
(
int ctrlr
)
{
int i;
if(ctrlr == 1)
{
/*Check if pDev1 is valid*/
if(NULL==pDev1){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_TxAbort(pDev1);
CAN_Stop(pDev1);
for(i=0;i<pDev1->pCtrl->numChn;i++)
{
CAN_DisableChannel(pDev1, i);
CAN_FreeChannel(pDev1, i);
}
CAN_DisableInt(pDev1);
CAN_Close(pDev1);
pDev1=NULL;
}
else
{
/*Check if pDev0 is valid*/
if(NULL==pDev0){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_TxAbort(pDev0);
CAN_Stop(pDev0);
for(i=0;i<pDev0->pCtrl->numChn;i++)
{
CAN_DisableChannel(pDev0, i);
CAN_FreeChannel(pDev0, i);
}
CAN_DisableInt(pDev0);
CAN_Close(pDev0);
pDev0=NULL;
}
return OK;
}
/**************************************************************************
*
* statusNode - Print bus Status to stdout
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int statusNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
WNCAN_BusStatus busStatus;
long globalMask;
long localMask;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
busStatus = CAN_GetBusStatus(pDev);
if(busStatus == WNCAN_BUS_OFF)
logMsg("Bus status is BUS OFF \n",0,0,0,0,0,0);
else if(busStatus == WNCAN_BUS_WARN)
logMsg("Bus status is BUS WARNING, more than 96 transmit errors have \
occured \n",0,0,0,0,0,0);
else
logMsg("Bus status is BUS OK, error active \n",0,0,0,0,0,0);
globalMask = CAN_GetGlobalRxFilter(pDev, 0);
logMsg("Global Filter is %x \n",globalMask,0,0,0,0,0);
localMask = CAN_GetLocalMsgFilter(pDev, 14, 1);
logMsg("Local Filter is %x \n",localMask,0,0,0,0,0);
return OK;
}
/**************************************************************************
*
* printRxMsg - Print all the received message identifiers and data to stdout
*
* Received message ids are recorded in an array by the ISR call back function.
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int printRxMsg
(
int ctrlr
)
{
int i;
if(ctrlr == 1)
{
for(i=0;i<ArrayIndex1;i++)
{
logMsg("Id[%d] = %x and extFlag is %d \n", i, id1[i], extFlag1[i],0,0,0);
}
}
else
{
for(i=0;i<ArrayIndex0;i++)
{
logMsg("Id[%d] = %x and extFlag is %d \n", i, id0[i], extFlag0[i],0,0,0);
}
}
return OK;
}
/**************************************************************************
*
* ISR call back function for ctrlr 0
*
*/
void test_isr0(struct WNCAN_Device *pDev, WNCAN_IntType intStatus, UCHAR channelNum)
{
WNCAN_BusError busErr;
if(intStatus == WNCAN_INT_WAKE_UP)
flagAwake0++;
if(intStatus == WNCAN_INT_TX)
{
CAN_DisableChannel(pDev, channelNum);
CAN_FreeChannel(pDev, channelNum);
}
if(intStatus == WNCAN_INT_RX)
{
id0[ArrayIndex0] = CAN_ReadID(pDev, channelNum, &extFlag0[ArrayIndex0]);
(ArrayIndex0 >= 99)?ArrayIndex0=0:ArrayIndex0++;
}
if(intStatus == WNCAN_INT_ERROR)
{
logMsg("CAN bus error occurred: ",0,0,0,0,0,0);
busErr = CAN_GetBusError(pDev);
switch(busErr)
{
case WNCAN_ERR_BIT:
logMsg("WNCAN_ERR_BIT \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_ACK:
logMsg("WNCAN_ERR_ACK \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_CRC:
logMsg("WNCAN_ERR_CRC \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_FORM:
logMsg("WNCAN_ERR_FORM \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_STUFF:
logMsg("WNCAN_ERR_STUFF \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_NONE:
logMsg("WNCAN_ERR_NONE \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_UNKNOWN:
default:
logMsg("WNCAN_ERR_UNKNOWN \n",0,0,0,0,0,0);
break;
}
}
if(intStatus == WNCAN_INT_BUS_OFF)
releaseNode(0);
}
/**************************************************************************
*
* ISR call back function for ctrlr 1
*
*/
void test_isr1(struct WNCAN_Device *pDev, WNCAN_IntType intStatus, UCHAR channelNum)
{
WNCAN_BusError busErr;
if(intStatus == WNCAN_INT_WAKE_UP)
flagAwake1++;
if(intStatus == WNCAN_INT_TX)
{
CAN_DisableChannel(pDev, channelNum);
CAN_FreeChannel(pDev, channelNum);
}
if(intStatus == WNCAN_INT_RX)
{
id1[ArrayIndex1] = CAN_ReadID(pDev, channelNum, &extFlag1[ArrayIndex1]);
(ArrayIndex1 >= 99)?ArrayIndex1=0:ArrayIndex1++;
}
if(intStatus == WNCAN_INT_ERROR)
{
logMsg("CAN bus error occurred: ",0,0,0,0,0,0);
busErr = CAN_GetBusError(pDev);
switch(busErr)
{
case WNCAN_ERR_BIT:
logMsg("WNCAN_ERR_BIT \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_ACK:
logMsg("WNCAN_ERR_ACK \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_CRC:
logMsg("WNCAN_ERR_CRC \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_FORM:
logMsg("WNCAN_ERR_FORM \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_STUFF:
logMsg("WNCAN_ERR_STUFF \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_NONE:
logMsg("WNCAN_ERR_NONE \n",0,0,0,0,0,0);
break;
case WNCAN_ERR_UNKNOWN:
default:
logMsg("WNCAN_ERR_UNKNOWN \n",0,0,0,0,0,0);
break;
}
}
if(intStatus == WNCAN_INT_BUS_OFF)
releaseNode(1);
}
@@ -0,0 +1,364 @@
/* sample_TolapaiCan.c - Sample application using Windnet 1.4 CAN api */
/*
* Copyright (c) 2007 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
--------------------
01a,04Dec07,d_z written
*/
/*
DESCRIPTION
This module is a sample application provided with the Windnet CAN api
documentation. The purpose is to demonstrate the use of CAN api, and
the sequence in which they must be called.
INCLUDE FILES:
*/
/* includes */
#include <vxWorks.h>
#include <stdio.h>
#include <errnoLib.h>
#include <CAN/wnCAN.h>
#include <assert.h>
#include <logLib.h>
#include "CAN/icp_can.h"
/* defines */
/**************************************************************************/
#define DEMO_BOARD WNCAN_BRD_TOLAPAI
#define DEMO_CTRL0 0
#define DEMO_CTRL1 1
#define NUM_CTRLRS 2
#define DEMO_ID0 0x180
#define DEMO_ID1 0x190
#define DEMO_TSEG1 12
#define DEMO_TSEG2 1
#define DEMO_BAUD_RATE_PRESCALAR 249/*19*/
#define DEMO_SJW 0
#define DEMO_SAMPLES_BOOL 0
#define DEMO_BAUD_RATE 10000/*125000*/
#define DEMO_PROP_SEG 7
/**************************************************************************/
/* globals */
struct WNCAN_Device *pDev0=NULL;
struct WNCAN_Device *pDev1=NULL;
int flagAwake0;
ULONG id0[100];
BOOL extFlag0[100];
int ArrayIndex0;
int flagAwake1;
ULONG id1[100];
BOOL extFlag1[100];
int ArrayIndex1;
/* forward declarations */
int closeNode (int ctrlr);
/**************************************************************************
*
* openNode - Open CAN ctrlr.
*
* This routine does the following:
* 1. Get device pointer.
* 2. Initialize CAN controller.
* 3. Set bit timing values to enable baud rate of 125K
* 4. Set interrupt mask to enable all interrupts.
* 5. Enable Interrupts.
* 6. Set global receive filter to receive all standard identifiers.
* 7. Assign a channel for reception.
* 8. Set local filter for channel number 14 (channels numbered 0 to 14)
* to receive all extended identifiers
* 9. Enable channel 14 for reception of extended identifiers.
* 10.Exit without bringing CAN controller online.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int openNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG testBaudRate;
UINT samplePoint;
/*default settings*/
if(ctrlr == 1)
{
pDev = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL1);
assert(pDev);
pDev1 = pDev;
}
else
{
pDev = CAN_Open(DEMO_BOARD, 0, DEMO_CTRL0);
assert(pDev);
pDev0 = pDev;
}
if(!pDev)
{
printf("failed to open node");
return ERROR;
}
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("Resetting baud to %d\n", DEMO_BAUD_RATE,0,0,0,0,0);
CAN_SetBitTiming(pDev, DEMO_TSEG1, DEMO_TSEG2, DEMO_BAUD_RATE_PRESCALAR,
DEMO_SJW, DEMO_SAMPLES_BOOL);
testBaudRate = CAN_GetBaudRate(pDev, &samplePoint);
if(testBaudRate != DEMO_BAUD_RATE)
{
logMsg("**Unable to set %d baud with selected bit timing parameters \
.\n", DEMO_BAUD_RATE,0,0,0,0,0);
logMsg("**If baud rate is off by a factor of 2, check the UMCR \
HSPEED bit setting\n",0,0,0,0,0,0);
logMsg("**Adjust macro DEMO_BAUD_RATE_PRESCALAR defined at the \
begining of this file accordingly\n",0,0,0,0,0,0);
closeNode(ctrlr);
return ERROR;
}
}
CAN_Start(pDev);
return OK;
}
/**************************************************************************
*
* transmitMsg - Transmit message using CAN_TxMsg
*
* This function gets transmit channel and transmits message with standard
* id 0x180, with eight data bytes.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
*/
int transmitMsg
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
ULONG id;
STATUS retCode;
UCHAR channelTx;
UCHAR data[8]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
if(ctrlr == 1)
{
pDev = pDev1;
id = DEMO_ID1;
}
else if(ctrlr == 0)
{
pDev = pDev0;
id = DEMO_ID0;
}
else
{
logMsg("invalid arguments \n",0,0,0,0,0,0);
return ERROR;
}
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
retCode = CAN_TxMsg(pDev, channelTx, id, FALSE, data, 8);
if(retCode != OK)
{
logMsg("error in tx msg setup \n",0,0,0,0,0,0);
return ERROR;
}
return OK;
}
/**************************************************************************
*
* closeNode - Release device pointer to CAN controller
*
* This function does the following:
*
* 1. Abort all pending transmissions
* 2. Bring CAN controller offline
* 3. Disable and Free all channels
* 4. Disable interrupts
* 5. Give up device pointer
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int closeNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev1 is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
CAN_Close(pDev);
if(ctrlr == 1)
pDev1=NULL;
else
pDev0=NULL;
return OK;
}
/**************************************************************************
*
* statusNode - Print bus Status to stdout
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int statusNode
(
int ctrlr
)
{
struct WNCAN_Device *pDev;
WNCAN_BusStatus busStatus;
long globalMask;
long localMask;
if(ctrlr == 1)
pDev = pDev1;
else
pDev = pDev0;
/*Check if pDev is valid*/
if(NULL==pDev){
logMsg("Call setupNode first \n",0,0,0,0,0,0);
return ERROR;
}
busStatus = CAN_GetBusStatus(pDev);
if(busStatus == WNCAN_BUS_OFF)
logMsg("Bus status is BUS OFF \n",0,0,0,0,0,0);
else if(busStatus == WNCAN_BUS_WARN)
logMsg("Bus status is BUS WARNING, more than 96 transmit errors have \
occured \n",0,0,0,0,0,0);
else
logMsg("Bus status is BUS OK, error active \n",0,0,0,0,0,0);
globalMask = CAN_GetGlobalRxFilter(pDev, 0);
logMsg("Global Filter is %x \n",globalMask,0,0,0,0,0);
localMask = CAN_GetLocalMsgFilter(pDev, 14, 1);
logMsg("Local Filter is %x \n",localMask,0,0,0,0,0);
return OK;
}
/**************************************************************************
*
* printRxMsg - Print all the received message identifiers and data to stdout
*
* Received message ids are recorded in an array by the ISR call back function.
*
* RETURNS: OK
*
* ERRNO: N/A
*
*/
int printRxMsg
(
int ctrlr
)
{
int i;
icp_can_msg_t msg;
int len;
struct WNCAN_Device *pDev;
STATUS retCode;
if(ctrlr == 1)
{
pDev = pDev1;
}
else if(ctrlr == 0)
{
pDev = pDev0;
}
else
{
logMsg("invalid arguments \n",0,0,0,0,0,0);
return ERROR;
}
retCode = CAN_ReadData(pDev, 0, &msg, &len, NULL);
if(retCode == OK)
{
printf("Id = %x and extFlag is %d rtr is %d size is %d\n", msg.id, msg.ide, msg.rtr, msg.dlc);
printf("data is ");
for (i=0; i<msg.dlc; i++)
printf("0x%x ", (UCHAR)msg.data[i]);
printf("\n");
}
return OK;
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+342
View File
@@ -0,0 +1,342 @@
/* cobble.c - source for sample VxWorks downloadable kernel application */
/* This code is intentionally left buggy! */
/*
modification history
--------------------
01c,01apr06,dlk Documentation updates.
01b,01apr01,ems better badness & cripser cleanups (with gracious help of wsl)
01a,01apr99,ems written (with gracious help of dlk)
*/
/*
DESCRIPTION:
This module is used as a simple example multitask application
in the form of a downloadable VxWorks kernel module. It is
intended to help the new Wind River Workbench user quickly become
familiar with various tools that are available for debugging such
applications.
The program simulates a data collection system in which
data is retrieved from an external source (e.g. a device
which generates interrupts as data come in). A task simulating
the ISR gives a semaphore each time a new datum arrives. (This
task could easily be replaced by a VxWorks watchdog timer.)
The data are processed in two stages. First, a sample consisting
of NUM_SAMPLE data is collected. Second, various arcane
arithmetical operations are performed on the sample to obtain
a result value. Each stage is represented by a task; the
first task gives a binary semaphore when the second task should
begin the second stage work.
The value of the result of the processing is monitored by yet
another task, which prints a warning message whenever the result
is out of the safety range.
INCLUDE FILES: None.
*/
/* includes */
#include "vxWorks.h"
#include "stdio.h"
#include "stdlib.h"
#include "semLib.h"
#include "taskLib.h"
/* defines */
#define NUM_SAMPLE 10
#define LUCKY 7
#define HOT 20
#define DELAY_TICKS 4
#define STACK_SIZE 20000
/* typedefs */
typedef struct byLightning
{
int data;
int nodeNum;
struct byLightning * pPrevNode;
} LIST_NODE;
/* globals */
int tidCosmos; /* Task IDs */
int tidSchlep;
int tidCrunch;
int tidMonitor;
int cosmicData = 0; /* Holds a datum available to read */
int result = 0; /* Holds result of calculation */
LIST_NODE * pCurrNode = NULL; /* head of list of data */
SEM_ID dataSemId; /* Given when a datum is available */
SEM_ID syncSemId; /* Given when a data sample can be crunched */
SEM_ID nodeListGuardSemId; /* Given when pointer to current node can
be accessed */
/* forward declarations */
void cosmos (void);
void nodeAdd (int data, int nodeNum);
void schlep (void);
void nodeScrap (void);
void crunch (void);
void monitor (void);
void progStop (void);
/*************************************************************************
*
* progStart - start the sample program.
*
* Create various semaphores and spawn various tasks, while doing
* incredibly little error checking.
*
* RETURNS: OK
*/
STATUS progStart (void)
{
syncSemId = semBCreate (SEM_Q_FIFO, SEM_EMPTY);
dataSemId = semBCreate (SEM_Q_FIFO, SEM_EMPTY);
nodeListGuardSemId = semMCreate ( SEM_Q_PRIORITY
| SEM_INVERSION_SAFE
| SEM_DELETE_SAFE);
pCurrNode = NULL; /* just in case */
/* get started */
tidCosmos = taskSpawn ("tCosmos", 200, 0, STACK_SIZE,
(FUNCPTR) cosmos,0,0,0,0,0,0,0,0,0,0);
tidSchlep = taskSpawn ("tSchlep", 220, 0, STACK_SIZE,
(FUNCPTR) schlep,0,0,0,0,0,0,0,0,0,0);
/*
* priority mis-assignment provides desired educational
* malfunction of not allowing tCrunch to run because
* tMonitor is higher priority
*/
tidCrunch = taskSpawn ("tCrunch", 240, 0, STACK_SIZE,
(FUNCPTR) crunch,0,0,0,0,0,0,0,0,0,0);
tidMonitor = taskSpawn ("tMonitor", 230, 0, STACK_SIZE,
(FUNCPTR) monitor,0,0,0,0,0,0,0,0,0,0);
return (OK);
}
/*************************************************************************
*
* cosmos - simulate data arrival interrupt
*
* This routine is executed by a task which serves as a replacement for
* an ISR which signals the availability of data from some device.
* It periodically gives the semaphore dataSemId to indicate that a
* datum is available and may be read from the cosmicData variable.
*/
void cosmos (void)
{
int nadaNichtsIdx = 0;
FOREVER
{
if (nadaNichtsIdx != LUCKY)
cosmicData = rand ();
else
{
cosmicData = 0; /* because you can't wait forever for nothing */
nadaNichtsIdx = 0;
}
++nadaNichtsIdx;
/* semaphore and delay ensure only new data will be read */
semGive (dataSemId);
taskDelay (DELAY_TICKS);
}
}
/*************************************************************************
*
* nodeAdd - link a new node to front of data chain.
*
* Allocates and initializes a node, puts it onto the data chain.
*
* RETURNS: N/A
*/
void nodeAdd
(
int data,
int nodeNum
)
{
LIST_NODE * node;
if ( (node = (LIST_NODE *) malloc (sizeof (LIST_NODE))) != NULL)
{
node->data = data;
node->nodeNum = nodeNum;
semTake (nodeListGuardSemId, WAIT_FOREVER);
node->pPrevNode = pCurrNode;
pCurrNode = node;
semGive (nodeListGuardSemId);
}
else
{
printf ("cobble: Out of Memory.\n");
taskSuspend (0);
}
return;
}
/*************************************************************************
*
* schlep - collect data into a sample to be processed
*
* Repeatedly, wait for and place NUM_SAMPLE data onto the list,
* then awaken the cruncher.
*/
void schlep (void)
{
int nodeIdx;
FOREVER
{
for (nodeIdx = 0; nodeIdx < NUM_SAMPLE; nodeIdx++)
{
semTake (dataSemId, WAIT_FOREVER); /* Wait for datum */
nodeAdd (cosmicData, nodeIdx);
}
semGive (syncSemId); /* Give entire sample to cruncher! */
}
}
/*************************************************************************
*
* nodeScrap - relegate a node to the dust bin of history
*
*/
void nodeScrap (void)
{
LIST_NODE * pTmpNode;
pTmpNode = pCurrNode;
pCurrNode = pCurrNode->pPrevNode;
free (pTmpNode);
return;
}
/*************************************************************************
*
* crunch - process data samples
*
* Applies dubious transformations to data.
* But first it waits for the schlepper to send it a sample.
*/
void crunch (void)
{
int sampleSum = 0;
int div;
int * pDiv = &div;
FOREVER
{
semTake (syncSemId, WAIT_FOREVER); /* Wait for dinner */
semTake (nodeListGuardSemId, WAIT_FOREVER); /* reserve access to
pCurrNode */
while (pCurrNode != NULL)
{
sampleSum += pCurrNode->data;
div = pCurrNode->data;
nodeScrap ();
}
semGive (nodeListGuardSemId); /* release access to pCurrNode */
/* Oh! Woe! Errant exclamation point! */
if (!(pDiv = NULL) && (*pDiv != 0))
/* if ((pDiv != NULL) && (*pDiv != 0)) */
result = sampleSum / (*pDiv);
sampleSum = 0; /* Clean up for the next round. */
}
}
/*************************************************************************
*
* monitor - monitors results of calculation
*
* Checks results of calculation and prints warning if too hot.
*/
void monitor (void)
{
int isHot = FALSE;
FOREVER
{
if (!isHot && result >= HOT)
{
isHot = TRUE;
printf ("WARNING: HOT!\n");
}
else if (isHot && result < HOT)
{
isHot = FALSE;
printf ("cool\n");
}
}
}
/*************************************************************************
*
* progStop - stops the program
*
* Call this routine to end it all.
*/
void progStop (void)
{
taskDelete (tidCosmos);
taskDelete (tidSchlep);
taskDelete (tidCrunch);
taskDelete (tidMonitor);
semDelete (dataSemId);
semDelete (syncSemId);
semDelete (nodeListGuardSemId);
while (pCurrNode != NULL)
nodeScrap();
/* My, aren't we tidy! */
printf ("BYE!TSCHUESS!ADIEU!\n");
return;
}
@@ -0,0 +1,2 @@
project.type=DownloadableKernelModuleProject
platform.id=VxWorks
@@ -0,0 +1,9 @@
The Cobble Demonstration Program
--------------------------------
The program simulates a data collection system in which
data is retrieved from an external source (e.g. a device
which generates interrupts as data come in). A task simulating
the ISR gives a semaphore each time a new datum arrives.
The program is intentionally flawed to provide a debugging
exercise using Workbench tools.
@@ -0,0 +1,59 @@
# Makefile - makefile skeleton for demo/vxColor
#
# Copyright 1984-1998, 2007 Wind River Systems, Inc.
#
# The right to copy, distribute or otherwise make use of this software
# may be licensed only pursuant to the terms of an applicable Wind River
# license agreement.
#
# modification history
# --------------------
# 01m,19may09,mze moving the library into a test directory
# 01l,06jun07,kk added LIB_BASE_NAME to allow the directory to build,
# removed -fstrength-reduce option to avoid warnings on DIAB.
# 01k,27nov98,p_m Get rid of vxColor2.c since we don't need a buggy vxColor
# now that the whirlwind tour is gone
# 01j,20feb97,jank added subst / to \ using DIRCHAR in CP line for WIN32 builds
# 01i,12nov96,p_m added TGT_DIR
# 01h,31oct96,yp added clean and release rules
# 01g,15nov95,jcf consolidated old and new versions of demo here.
# 01f,15nov95,jcf changed name to vxColor.o.
# 01e,13nov95,p_m used DEMO_DIR in order to build on Unix and WIN32.
# 01d,11nov95,p_m changed mv to cp and added rm.
# 01c,11nov95,jeh undoing last change.
# 01b,11nov95,jeh changed 'mv' command to $(CP)
# 01a,21sep95,jco written.
# +yp
#
# DESCRIPTION
# This file contains rules for building the vxColor demo for the desired
# architecture.
#
# The file vxColor.c contains the actual demo, and builds its object into
# the file named target/lib/.../vxColor.o. The host portion of the demo,
# vxColor, references this resultant object module.
#
# INCLUDES
# makeTarget
#*/
TGT_DIR=$(WIND_BASE)/target
DOC_FILES =
LIB_BASE_NAME=vxTestV2
LIBDIRNAME=test/obj$(CPU)$(TOOL_SPECIFIC_DIR)test
OBJS= vxColor.o
include $(TGT_DIR)/h/make/rules.library
#CC_OPTIM = -g -fstrength-reduce -fno-builtin
CC_OPTIM = -g -fno-builtin
# The normal end when using makeLibrary is to create a lib, but here, we
# don't need lib creation. The following settings prevent lib creation.
AR=echo
RANLIB=echo
File diff suppressed because it is too large Load Diff
+158
View File
@@ -0,0 +1,158 @@
/* vxColor.h - header file for vxColor2.c program */
/* Copyright 1984-1998 Wind River Systems, Inc. */
/*
modification history
--------------------
01f,09apr98,dbt increased stack size for solaris simulator.
01e,15nov95,jcf renamed vxColor2.h to vxColor.h. sigh.
01d,15nov95,jcf renamed vxColor.h to vxColor2.h.
01c,27sep95,jco re coding convention revision, removed rev field in GNODE.
01b,06sep95,p_m fixed coding convention problems.
01a,03aug95,jco written.
*/
/* WARNING: DEMO_EOLM MUST BE SUPERIOR TO MAX_NODE! If DEMO_EOLM is changed
* here, it MUST also be changed in $WIND_BASE/host/src/demo/color/demoHost.tk.
*/
/* defines */
#define MAX_NODE 100 /* maximum node number in a graph */
#define MAX_CONNEX 10 /* maximum node connectivity number */
#define MAX_MSG 1 /* maximum number of message in queue */
#define MSG_SIZE sizeof (NODE_ATTRIB) /* message size */
#define MAX_COLOR 6 /* maximum number of color */
#define MAX_OUTDEGREE 5 /* maximum node outdegree */
#define OUTDEGREE_INIT (MAX_OUTDEGREE + 1)
#define PAUSE_CLK_RATIO 10 /* clckRate divisor (N sec for Pause) */
#define DEMO_EOLM 127 /* connexions file endOfLine marker */
#define CONT_PRIORITY 200 /* controler's task priority */
#define NODE_PRIORITY 200 /* node's tasks priority */
#define NODE_STBL_INIT -1 /* initial value for stable field */
#define NODE_UNSTABLE 0 /* unstable value for stable field */
#define NODE_STABLE 1 /* stable value for stable field */
/*
* stackSize defines according to cpu type and debug mode boolean
*/
#if (defined (CPU_FAMILY) && (CPU_FAMILY==MC680X0))
#define NODE_STACK 500 /* node task stack size */
#define NODE_STACK_DBG 1000 /* node task stack size for debug */
#define CONT_STACK 500 /* graphControl task stack size */
#define CONT_STACK_DBG 1000 /* graphControl stack size for debug */
#endif /* CPU_FAMILY == MC680X0 */
#if (defined (CPU_FAMILY) && (CPU_FAMILY==SIMSPARCSUNOS))
#define NODE_STACK 2500 /* node task stack size */
#define NODE_STACK_DBG 5000 /* node task stack size for debug */
#define CONT_STACK 2500 /* graphControl task stack size */
#define CONT_STACK_DBG 5000 /* graphControl stack size for debug */
#endif /* CPU_FAMILY == SPARC */
#if (defined (CPU_FAMILY) && (CPU_FAMILY==I80X86))
#define NODE_STACK 500 /* node task stack size */
#define NODE_STACK_DBG 1000 /* node task stack size for debug */
#define CONT_STACK 500 /* graphControl task stack size */
#define CONT_STACK_DBG 1000 /* graphControl stack size for debug */
#endif /* CPU_FAMILY == I80X86 */
#if (defined (CPU_FAMILY) && (CPU_FAMILY==I960))
#define NODE_STACK 1000 /* node task stack size */
#define NODE_STACK_DBG 2000 /* node task stack size for debug */
#define CONT_STACK 1000 /* graphControl task stack size */
#define CONT_STACK_DBG 2000 /* graphControl stack size for debug */
#endif /* CPU_FAMILY == I960 */
#if (defined (CPU_FAMILY) && (CPU_FAMILY==SIMSPARCSOLARIS))
#define NODE_STACK 5000 /* node task stack size */
#define NODE_STACK_DBG 10000 /* node task stack size for debug */
#define CONT_STACK 5000 /* graphControl task stack size */
#define CONT_STACK_DBG 10000 /* graphControl stack size for debug */
#endif /* CPU_FAMILY == SIMSPARCSOLARIS */
/* default values */
#ifndef NODE_STACK
#define NODE_STACK 2500 /* node task stack size */
#define NODE_STACK_DBG 5000 /* node task stack size for debug */
#define CONT_STACK 2500 /* graphControl task stack size */
#define CONT_STACK_DBG 5000 /* graphControl stack size for debug */
#endif /* not def NODE_STACK */
#if (defined (CPU_FAMILY) && (CPU_FAMILY==I960) && (defined __GNUC__))
#pragma align 1 /* tell gcc960 not to optimize alignments */
#endif /* CPU_FAMILY==I960 */
/* typedefs */
typedef struct ids /* IDS */
{
INT32 tid; /* task id */
INT32 nid; /* node id */
} IDS; /* task/node id */
typedef struct node_attrib /* NODE_ATTRIB */
{
INT32 color; /* node color */
INT32 Xvalue; /* node Xvalue */
} NODE_ATTRIB; /* node attributes */
typedef struct connect_info /* CONNECT_INFO */
{
INT32 dir; /* direction: +=to connected -=from connected */
IDS tnid; /* connected node tid & nid */
NODE_ATTRIB att; /* connected node attributes */
MSG_Q_ID wMQId; /* write (toNeighbor) mesg queue id */
MSG_Q_ID rMQId; /* read (toNeighbor) mesg queue id */
} CONNECT_INFO; /* connected node info */
typedef struct gnode_st /* GNODE */
{
INT32 stable; /* color stability flag */
IDS tnid; /* node tid & nid */
NODE_ATTRIB att; /* node col & Xval */
INT32 pc; /* node Prog Counter */
INT32 oD; /* node outDegree */
INT32 cNum; /* node connexions # */
CONNECT_INFO cArray [MAX_CONNEX]; /* node connexions array */
struct gnode_st * pNext; /* pointer to pNext gnode */
} GNODE; /* global node info */
typedef struct control /* CONTROL */
{
char steadyState; /* flag on if graph is stable */
char controlAlive; /* flag on if control task is alive */
char coloringStop; /* flag on when stop requested */
char pauseOn; /* flag on when pause requested */
INT32 graphControlId; /* graphControl task Id */
INT32 nodeFailure; /* flag on if a node task in error */
SEM_ID nodeJobDoneSem; /* synchro for controler */
SEM_ID createAckSem; /* Ack for each node creation */
SEM_ID restartSem; /* StartColoring and control synchro */
SEM_ID connexionsDoneSem; /* connexions established synchro */
SEM_ID controlerFlushSem; /* controler flush semaphore */
SEM_ID dataBaseMutex; /* data base mutex semaphore */
} CONTROL; /* global control info */
typedef struct data_base /* DATA_BASE */
{
CONTROL cT; /* control info block */
INT32 nNum; /* graph node # */
GNODE * pFirstGnode; /* pointer to first gnode */
} DATA_BASE; /* global graph info */
/* turn off alignment requirement for i960 cpu family */
#if (defined (CPU_FAMILY) && (CPU_FAMILY==I960) && (defined __GNUC__))
#pragma align 0
#endif /* CPU_FAMILY==I960 */
/* forward declarations defining the demo GUI API */
INT32 graphColorUpdate (DATA_BASE * pdB, char * colorMemBlkAdd);
INT32 graphInit (INT32 nodNumber, char * colorMemBlkAdd, BOOL debugMode);
INT32 graphStartColoring (DATA_BASE * pdB);
INT32 graphStop (DATA_BASE * pdB);
@@ -0,0 +1,397 @@
/* factory.cpp - implements an object factory */
/*
* Copyright (c) 1998, 2004, 2009-2010, 2014 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
--------------------
01e,18sep14,jpb VXW6-83491: Fixed error handling issues.
01d,04may10,mcm Fixing compilation error - cast from 'object_t*' to 'int'
loses precision.
01c,30jun09,mcm Fixing signature of main
01b,01oct04,job Updated to WR docs format
01a,05oct98,sn wrote
*/
/*
SYNOPSIS
\cs
factory.vxe
\ce
DESCRIPTION
We implement an "object factory". The first step is to give
classes human-readable names by registering them with a
"global class registry". Then objects of a named type may be
created and registered with an "object registry".
This gives us an opportunity to exercise various C++ features:
* Standard Template Library
A "map" is used as the basis for the various registries.
* User defined templates
The class registry and object registry are both based on a
generic registry type.
* Run Time Type Checking
We provide a function to determine the type of a registered
object using "dynamic_cast".
* Exception Handling
If we attempt to cast to the "wrong" type we have to handle a
C++ exception.
We provide a C interface to facilitate easy testing from the Wind Shell.
Here is an example test run (you can run this whole test through the function
testFactory()):
\cs
-> classRegistryShow
Showing Class Registry ...
Name Address
=========================================================
blue_t 0x6b1c7a0
green_t 0x6b1c790
red_t 0x6b1c7b0
-> objectRegistryShow
Showing Object Registry ...
Name Address
=========================================================
-> objectCreate "green_t", "bob"
Creating an object called 'bob' of type 'green_t'
-> objectCreate "red_t", "bill"
Creating an object called 'bill' of type 'red_t'
-> objectRegistryShow
Showing Object Registry ...
Name Address
=========================================================
bill 0x6b1abf8
bob 0x6b1ac18
-> objectTypeShowByName "bob"
Looking up object 'bob'
Attempting to ascertain type of object at 0x6b1ac18
Attempting a dynamic_cast to red_t ...
dynamic_cast threw an exception ... caught here!
Attempting a dynamic_cast to blue_t ...
dynamic_cast threw an exception ... caught here!
Attempting a dynamic_cast to green_t ...
Cast to green_t succeeded!
green.
\ce
\NOROUTINES
*/
/* includes */
#include "factory.h"
#include <stdio.h>
/* locals */
/* pointer to the global class registry */
LOCAL class_registry_t* pClassRegistry;
/* pointer to the global object registry */
LOCAL object_registry_t* pObjectRegistry;
extern void testFactory ();
/******************************************************************************
*
* testFactory - an example test run
*
*/
void testFactory ()
{
cout << "classRegistryShow ()" << endl;
classRegistryShow ();
cout << "objectRegistryShow ()" << endl;
objectRegistryShow ();
cout << "objectCreate (\"green_t\", \"bob\")" << endl;
objectCreate ((char *)"green_t", (char *)"bob");
cout << "objectCreate (\"red_t\", \"bill\")" << endl;
objectCreate ((char *)"red_t", (char *)"bill");
cout << "objectRegistryShow ()" << endl;
objectRegistryShow ();
cout << "objectTypeShowByName (\"bob\")" << endl;
objectTypeShowByName ((char *)"bob");
}
int main(int argc, char * argv[])
{
try
{
testFactory();
return 0;
}
catch (exception)
{
cout << "exception caught" << endl;
return -1;
}
}
/******************************************************************************
*
* class_registry_t::create - create an object of type className
*
* Look up 'className' in this registry. If it exists then
* create an object of this type by using the registered class factory;
* otherwise return NULL.
*
* RETURNS : pointer to new object of type className or NULL.
*/
object_t* class_registry_t::create
(
string className
)
{
object_factory_t* pFactory = lookup (className);
if (pFactory != NULL)
{
return lookup (className)-> create ();
}
else
{
cout << "No such class in Class Registry. " << endl;
return NULL;
}
}
/******************************************************************************
*
* classRegistryGet - get a reference to the global class registry
*
* Create and populate a new class registry if necessary.
*
* RETURNS : a reference to the global class registry
*/
LOCAL class_registry_t& classRegistryGet ()
{
if (pClassRegistry == NULL)
{
pClassRegistry = new class_registry_t;
pClassRegistry -> insert ("red_t", new red_factory_t);
pClassRegistry -> insert ("blue_t", new blue_factory_t);
pClassRegistry -> insert ("green_t", new green_factory_t);
}
return *pClassRegistry;
}
/******************************************************************************
*
* objectRegistryGet - get a reference to the global object registry
*
* Create a new object registry if necessary.
*
* RETURNS : a reference to the global object registry
*/
LOCAL object_registry_t& objectRegistryGet ()
{
if (pObjectRegistry == NULL)
{
pObjectRegistry = new object_registry_t;
}
return *pObjectRegistry;
}
/******************************************************************************
*
* objectCreate - create an object of a given type
*
* Use the class factory registered in the global class registry
* under 'className' to create a new object. Register this object
* in the global object registry under 'object name'.
*
* RETURNS : object of type className
*/
object_t* objectCreate
(
char* className,
char* objectName
)
{
cout << "Creating an object called '" << objectName << "'"
<< " of type '" << className << "'" << endl;
object_t* pObject = classRegistryGet().create (className);
if (pObject != NULL)
{
objectRegistryGet().insert(objectName, pObject);
}
else
{
cout << "Could not create object. Sorry. " << endl;
}
return pObject;
}
/******************************************************************************
*
* isBlue - is anObject a reference to an object of the specified type?
* isRed
* isGreen
*
* Try a dynamic_cast. If this succeeds then return TRUE. If it fails
* then catch the resulting exception and return FALSE.
*
* RETURNS : TRUE or FALSE
*/
LOCAL BOOL isRed
(
object_t& anObject
)
{
try
{
cout << "Attempting a dynamic_cast to red_t ..." << endl;
dynamic_cast<red_t&> (anObject);
cout << "Cast to red_t succeeded!" << endl;
return TRUE;
}
catch (exception)
{
cout << "dynamic_cast threw an exception ... caught here!" << endl;
return FALSE;
}
}
LOCAL BOOL isBlue
(
object_t& anObject
)
{
try
{
cout << "Attempting a dynamic_cast to blue_t ..." << endl;
dynamic_cast<blue_t&> (anObject);
cout << "Cast to blue_t succeeded!" << endl;
return TRUE;
}
catch (exception)
{
cout << "dynamic_cast threw an exception ... caught here!" << endl;
return FALSE;
}
}
LOCAL BOOL isGreen
(
object_t& anObject
)
{
try
{
cout << "Attempting a dynamic_cast to green_t ..." << endl;
dynamic_cast<green_t&> (anObject);
cout << "Cast to green_t succeeded!" << endl;
return TRUE;
}
catch (exception)
{
cout << "dynamic_cast threw an exception ... caught here!" << endl;
return FALSE;
}
}
/******************************************************************************
*
* objectTypeShow - ascertain the type of an object
*
* Use dynamic type checking to determine the type of an object.
*
* RETURNS : N/A
*/
LOCAL void objectTypeShow
(
object_t* pObject
)
{
cout << "Attempting to ascertain type of object at " << "0x" << hex
<< (intptr_t) pObject << dec << endl;
if (isRed (*pObject))
{
cout << "red." << endl;
}
else if (isBlue (*pObject))
{
cout << "blue." << endl;
}
else if (isGreen (*pObject))
{
cout << "green." << endl;
}
}
/******************************************************************************
*
* objectTypeShowByName - ascertain the type of a registered object
*
* Lookup 'objectName' in the global object registry and
* print the type of the associated object.
*
* RETURNS : N/A
*/
void objectTypeShowByName
(
char* objectName
)
{
cout << "Looking up object '" << objectName << "'" << endl;
object_t *pObject = objectRegistryGet ().lookup (objectName);
if (pObject != NULL)
{
objectTypeShow (pObject);
}
else
{
cout << "No such object in the Object Registry." << endl;
}
}
/******************************************************************************
*
* objectRegistryShow - show contents of global object registry
*
* RETURNS : N/A
*/
void objectRegistryShow ()
{
cout << "Showing Object Registry ..." << endl;
objectRegistryGet ().list ();
}
/******************************************************************************
*
* classRegistryShow - show contents of global class registry
*
* RETURNS : N/A
*/
void classRegistryShow ()
{
cout << "Showing Class Registry ..." << endl;
classRegistryGet ().list ();
}
@@ -0,0 +1,212 @@
/* factory.h - class declarations for the object factory */
/*
* Copyright (c) 1998, 2010, 2014 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
--------------------
01c,18sep14,jpb VXW6-83491: Fixed error handling issues.
01b,04may10,mcm Fixing compilation error - cast from 'object_t*' to 'int'
loses precision.
01a,05oct98,sn wrote
*/
#ifdef __vxworks
#ifndef __VXWORKS__
#define __VXWORKS__
#endif
#endif
#ifdef __VXWORKS__
#include <vxWorks.h>
#else
typedef int BOOL;
#define TRUE 1
#define FALSE 0
#define LOCAL static
#endif
#include <iostream>
#include <string>
#include <typeinfo>
#include <map>
using namespace std;
/*
* object_t hierarchy
*
* object_t
* |
* +------------+------------+
* | | |
* red_t blue_t green_t
*
*/
struct object_t
{
virtual void method () {}
};
struct red_t : object_t
{
};
struct blue_t : object_t
{
};
struct green_t : object_t
{
};
/*
* object_factory_t hierarchy
*
*
* object_factory_t
* |
* +--------------------+--------------------+
* | | |
* red_factory_t blue_factory_t green_factory_t
*/
struct object_factory_t
{
virtual object_t* create () = 0;
};
struct red_factory_t : object_factory_t
{
red_t* create () { return new red_t; }
};
struct blue_factory_t : object_factory_t
{
blue_t* create () { return new blue_t; }
};
struct green_factory_t : object_factory_t
{
green_t* create () { return new green_t; }
};
/*
* registry_t<T> - a registry of objects of type T
*
* The registry maps user readable names to pointers to objects.
*
*/
template <class T> class registry_t
{
private:
typedef map <string, T*> map_t;
map_t registry;
public:
void insert (string objectName, T* pObject);
T* lookup (string objectName);
void list ();
};
/* object_registry_t - a registry of objects derived from object_t */
typedef registry_t <object_t> object_registry_t;
/* class_registry_t - a registry of object factories ('classes') */
class class_registry_t : public registry_t <object_factory_t>
{
public:
object_t* create (string className) ;
};
/*
* template method definitions
*
* It is common to put template method definitions in header
* files so that they may be instantiated whenever necessary.
*
*/
/******************************************************************************
*
* registry_t<T>::insert - register an object
*
* Register object pointed to by pObject under 'objectName'.
*
* RETURNS : N/A
*/
template <class T>
void registry_t<T>::insert
(
string objectName,
T* pObject
)
{
registry [objectName] = pObject;
}
/******************************************************************************
*
* registry_t<T>::lookup - lookup an object by name
*
* Lookup 'objectName' in this registry and return a pointer
* to the corresponding object.
*
* RETURNS : a pointer to an object or NULL
*/
template <class T>
T* registry_t<T>::lookup
(
string objectName
)
{
return registry [objectName];
}
/******************************************************************************
*
* registry_t<T>::list - list objects in this registry
*
* RETURNS : N/A
*/
template <class T>
void registry_t<T>::list ()
{
cout << "Name \t" << "Address" << endl;
cout << "=========================================================" << endl;
for (typename map_t::iterator i = registry.begin ();
i != registry.end (); ++i)
{
cout << i -> first << " \t"
<< "0x" << hex << (intptr_t) i -> second << dec << endl;
}
}
/* function declarations */
/* objectCreate - create an object of a given type */
object_t* objectCreate (char* className, char* objectName);
/* objectTypeShowByName - ascertain the type of a registered object */
void objectTypeShowByName (char* objectName);
/* objectRegistryShow - show contents of global object registry */
void objectRegistryShow ();
/* classRegistryShow - show contents of global class registry */
void classRegistryShow ();
@@ -0,0 +1,61 @@
/* allocator.cpp - implements simple memory allocator class */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#include "allocator.h"
Allocator *theAllocator;
Allocator::Allocator()
{
theAllocator = this;
initialize();
} /* Allocator::Allocator */
Allocator::~Allocator()
{
theAllocator = 0;
} /* Allocator::~Allocator */
void *
Allocator::allocate( unsigned long size )
{
unsigned char *p = pointer;
size += ((size+7uL)/8uL) * 8uL;
if( size > remaining_size )
outOfMemory();
pointer += size;
return (void *)p;
} /* Allocator::allocate */
void *
Allocator::allocate( unsigned long elements, unsigned long size )
{
return allocate( size * elements );
} /* Allocator::allocate */
void
Allocator::initialize()
{
static unsigned char buffer[2048];
pointer = buffer;
remaining_size = sizeof(buffer);
} /* Allocator::initialize */
void
Allocator::outOfMemory()
{
while( 1 )
;
} /* Allocator::outOfMemory */
@@ -0,0 +1,42 @@
/* allocator.h - declarations for memory allocator class */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
/**********************************************************************
*
* Copyright (c) 2004 Wind River Systems, Inc.
*
***********************************************************************/
#ifndef _ALLOCATOR_H
#define _ALLOCATOR_H
class Allocator {
public:
Allocator();
~Allocator();
void *allocate( unsigned long size );
void *allocate( unsigned long elements, unsigned long size );
void initialize();
private:
Allocator( const Allocator & );
const Allocator &operator =( const Allocator & );
void outOfMemory();
unsigned long remaining_size;
unsigned char *pointer;
};
extern Allocator *theAllocator;
#endif /* _ALLOCATOR_H */
@@ -0,0 +1,51 @@
/* array.cpp - implements simple integer array class */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#include "array.h"
#include "allocator.h"
IntArray::IntArray(unsigned sz)
{
init (sz, 0);
}
IntArray::IntArray(unsigned sz, int x)
{
init (sz, x);
}
IntArray::~IntArray()
{
value = 0;
size = 0;
}
void IntArray::init(unsigned sz, int x)
{
value = (int *)theAllocator->allocate( sz, sizeof(int) );
if (value == 0)
return;
for (unsigned i = 0; i < sz; i++)
{
value[i] = x;
}
size = sz;
} /* IntArray::init */
void IntArray::clear()
{
value = 0;
size = 0;
} /* IntArray::clear */
@@ -0,0 +1,91 @@
/* array.h - declarations for array classes */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01b,14mar06,mcm Fix for SPR#118178
01a,07oct04,f_b added
*/
#ifndef _ARRAY_H
#define _ARRAY_H
#include "allocator.h"
class IntArray
{
private:
int *value;
unsigned size;
public:
// Constructors
IntArray(unsigned sz);
IntArray(unsigned sz, int x);
// Destructor
~IntArray();
void clear();
// Overload the [] operator
inline int& operator [] (unsigned index)
{
return value[index];
}
inline unsigned getSize() const
{
return size;
}
private:
void init(unsigned sz, int v);
};
/*************************************************************************
*
* Array template class
*
*************************************************************************
*/
template <class Type>
class Array
{
public:
/* Setup a array */
Array(unsigned sz)
{
size = sz;
parray = (Type *)theAllocator->allocate( sz, sizeof(Type) );
}
~Array ()
{
}
// Overload the [] operator
inline Type & operator [] (unsigned index);
inline unsigned getSize() const
{
return size;
}
private:
unsigned size;
Type *parray;
};
// Overload the [] operator
template <class Type>
inline
Type & Array<Type>::operator [] (unsigned index)
{
return parray[index];
}
#endif /* _ARRAY_H */
@@ -0,0 +1,29 @@
/* exception.cpp - implements function that generates a C++ exception */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
void exceptionDemo()
{
//#if 0
/* On all the compilers, this requires extensive
* runtime support. You must turn on exception support
* before compiling this block.
*/
int value = 0;
try {
throw 'A';
} catch( char a ) {
value = 1;
}
value++;
//#endif
}
@@ -0,0 +1,146 @@
/* list.cpp - implements linked list classes */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#include "list.h"
void ListItem::addBefore(ListItem & item)
{
/* Place "item" before "this" in the list.
*/
item.previous = this->previous;
item.next = this;
if (this->previous != 0)
this->previous->next = &item;
this->previous = &item;
}
void ListItem::addAfter(ListItem & item)
{
/* Place "item" after "this" in the list.
*/
item.previous = this;
item.next = this->next;
this->next = &item;
}
/* The default for adding an item to the end of the list.
*/
void List::add(ListItem &item)
{
/* Place item at the end of the list.
*/
if (itemCount == 0)
{
head = tail = &item;
}
else
{
tail->addAfter(item);
tail = &item;
}
itemCount++;
}
/* This will remove an item from the list whose value matched "item".
* It will return a pointer to the item removed, or 0 if not found.
*/
void List::remove(ListItem &item)
{
ListItem *p, *n;
/* Make sure item is in the list.
*/
for (p = getFirst(); p != &item; p = p->getNext())
{
if (p == 0)
return;
}
p = item.getPrevious();
n = item.getNext();
item.setPrevious(0);
item.setNext(0);
itemCount--;
/* If this is the last item in the list then clear out everything.
*/
if (itemCount == 0)
{
head = tail = 0;
return;
}
if (p != 0)
{
p->setNext(n);
if (n == 0)
{
tail = p;
}
}
if (n != 0)
{
n->setPrevious(p);
if (p == 0)
{
head = n;
}
}
}
ListItem * List::getFirst(void)
{
return head;
}
/*-------------------------------------------------------------------
*
* SortedList class functions
*
*-------------------------------------------------------------------
*/
void SortedList::add (ListItem &item)
{
ListItem *curr;
/* Place item at the end of the list.
*/
if (itemCount == 0)
{
head = tail = &item;
}
else
{
/* Find a place to add this item.
*/
for (curr = head; curr != 0; curr = curr->getNext() )
{
if (curr->compare(item) == -1)
break;
}
/* curr now should point to the item we want to add before.
* If it is 0, then we want this add this to the end of the list.
*/
if (curr == 0)
{
tail->addAfter(item);
tail = &item;
}
else
{
curr->addBefore(item);
if (curr == head)
head = &item;
}
}
itemCount++;
}
+165
View File
@@ -0,0 +1,165 @@
/* list.h - declarations for linked list classes */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#ifndef _LIST_H
#define _LIST_H
/* ListItem is a base class. It doesn't have any function by
* itself, it's main purpose is to provide list functions for the
* derived class.
*/
class ListItem
{
private:
ListItem *previous;
ListItem *next;
public:
//* Constructor
ListItem() :
previous(0),
next(0)
{ }
void addBefore(ListItem & item);
void addAfter(ListItem & item);
ListItem * getPrevious() { return previous; }
ListItem * getNext() { return next; }
void setPrevious(ListItem *p) { previous = p; }
void setNext(ListItem *p) { next = p; }
/* Compare will compare the current item with one passed and return:
* -1 - item passed in is less than "this" item
* 0 - items are equal
* 1 - item passed in is greater than "this" item.
*
* This is a "pure virtual" function; derived classes must over ride
* this function.
*/
virtual int compare(const ListItem &) = 0; // { return 0; }
/* This function is used for displaying the value
*/
virtual void displayValue() = 0; // { }
};
/* The List class defines a list of elements ListItem
*/
class List
{
protected:
ListItem *head;
ListItem *tail;
int itemCount;
public:
List() :
head(0),
tail(0),
itemCount(0)
{ }
/* Make the following a virtual function so that derived classes
* can override it.
*/
/* add - adds a item to the end of the list (default; but may
* over ridden
* remove - removes selected item from list.
*/
virtual void add(ListItem &item);
virtual void remove(ListItem &item);
virtual ListItem *getFirst(void);
};
/* Now define some real lists.
*/
class IntListItem : public ListItem
{
private:
int value;
public:
IntListItem() :
value(0)
{ }
IntListItem(int v) :
value (v)
{ }
int getValue() const { return value; }
int compare(const ListItem &l)
{
IntListItem *p = (IntListItem *)&l;
if (p->value < value)
return -1;
else if (p->value == value)
return 0;
else
return 1;
}
void displayValue()
{
}
};
class FloatListItem : public ListItem
{
private:
float value;
public:
FloatListItem() :
value(0.0f)
{ }
FloatListItem(float v) :
value (v)
{ }
float getValue() const { return value; }
int compare(const ListItem &l)
{
FloatListItem *p = (FloatListItem *)&l;
if (p->value < value)
return -1;
else if (p->value == value)
return 0;
else
return 1;
}
void displayValue()
{
}
};
/* Now lets define a sorted list based on List
*/
class SortedList : public List
{
public:
void add(ListItem &item);
};
#endif /* _LIST_H */
@@ -0,0 +1,388 @@
/* main.cpp - main module of C++ demo program */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#include "array.h"
#include "list.h"
#include "string.h"
#include "allocator.h"
/* prototypes/forward references */
void staticDemo();
void stringDemo();
void simpleClassDemo();
void templateClassDemo();
void inheritanceClassDemo();
void multipleInheritanceDemo();
void largeClassDemo();
void partialTypesDemo();
void virtualBaseDemo();
void exceptionDemo();
/**********************************************************************
* Function: main()
* Description: main driver loop for C++ Demo program
*/
int main()
{
while (1)
{
Allocator allocator;
/* Create a simple object.
*/
simpleClassDemo();
/* Create inherited objects.
*/
inheritanceClassDemo();
multipleInheritanceDemo();
/* Demonstrate static member variables.
*/
staticDemo();
/* Demonstrate templates.
*/
templateClassDemo();
/* Create a larget object.
*/
largeClassDemo();
/* Create some incomplete types.
*/
partialTypesDemo();
/* Demonstrate virtual base classes.
*/
virtualBaseDemo();
/* Demonstrate strings.
*/
stringDemo();
/* Demonstrate exceptions.
*/
exceptionDemo();
}
}
/**********************************************************************
* Function: simpleClassDemo()
* Description: shows how the debugger handles creation of objects.
*/
void simpleClassDemo()
{
/* Object construction. Please step into the constructor for IntArray.
*/
IntArray a(10);
/* Now initialize it. This should go into the operator [] function.
* This function is inline and defined in the include file.
*/
for (unsigned i = 0; i < a.getSize(); i++)
{
a[i] = i;
}
/* Test construction and initialization.
*/
IntArray b(5, 0xA);
}
/**********************************************************************
* Function: templateClassDemo()
* Description: demonstrate template classes.
*
***********************************************************************
*/
void templateClassDemo()
{
unsigned i;
/* We will create two arrays using template class "Array".
* The first array will be an integer and the second array
* will be a floating point array. Please step through the
* next two lines to see how this is done.
*/
Array<int> iarray(10);
Array<float> farray(20);
/* To see how the template class is initialized, please step through
* the following two loops. The first loop will initialize the
* array of integers and the second loop will initialize the array
* of floating point numbers.
*/
for (i = 0; i < iarray.getSize(); i++)
{
iarray[i] = i;
}
float f = 0.0f;
for (i = 0; i < farray.getSize(); i++)
{
farray[i] = f;
f += (float)1.1;
}
}
/**********************************************************************
* Function: inheritanceClassDemo()
* Description: shows inhertance.
*
* We will create two linked lists. The first will be of
* integers and the second will be of floats. We will also
* create two types of lists, one where the new item is
* added to the end of the list and the other where the
* item is added to the list in order.
*/
/* Create some integer items to be added to the list
*/
IntListItem intItem1(1);
IntListItem intItem2(2);
IntListItem intItem3(3);
IntListItem intItem4(4);
IntListItem intItem5(5);
FloatListItem floatItem1(1.1);
FloatListItem floatItem2(2.2);
FloatListItem floatItem3(3.3);
FloatListItem floatItem4(4.4);
FloatListItem floatItem5(5.5);
void inheritanceClassDemo()
{
ListItem *item;
/* Lets see how the items are created. Please use step into the
* see how the next instruction creates an element.
*/
IntListItem intItem0(0);
/* Now lets see it create a different type of item. Please use
* step into the see this go to the FloatListItem constructor.
*/
FloatListItem floatItem0(1.0);
/* Now we will start adding items to lists. We will create one
* list that may contain either Integers or Floats.
*/
List linkedList;
/* Let's start adding to the list. Items will be added to the end
* of the list.
*/
linkedList.add(intItem0);
linkedList.add(intItem1);
linkedList.add(intItem2);
linkedList.add(floatItem0);
linkedList.add(floatItem1);
linkedList.add(floatItem2);
/* Display the contents of the linked list. Notice a mixture of integers
* and floating numbers are inserted into the list. The "displayValue"
* function for these items will be resolved at runtime since "item" is a
* pointer to the base class ListItem.
*/
for (item = linkedList.getFirst();
item != 0;
item = item->getNext())
{
item->displayValue();
}
/* Remove the items from the list.
*/
while (linkedList.getFirst() != 0)
{
linkedList.remove(*(linkedList.getFirst()));
}
/* If you stepped into during the adds, you would have seen how
* that the member function "add" for List was called. Now we will
* create another list that is sorted using SortedList which
* derives from List, but changes the add function to sort the
* list.
*
* NOTE: We will be using the overridded member function "compare"
* in the ListItem for each of the derived classes
* "IntListItem" and "FloatListItem". Since these cannot be
* compared between each other we will create two classes;
* one for integers and one for floats.
*/
SortedList intList;
SortedList floatList;
/* Add the first items. Please step into the next instructions to
* see how the "compare" member function get called for
* IntListItem and FloatListItem. Also notice how the "add" member
* function get called in the SortedList Class.
*/
intList.add(intItem1);
floatList.add(floatItem1);
/* Now lets add something to the front of the list.
*/
intList.add(intItem0);
floatList.add(floatItem0);
/* Now to the end of the list.
*/
intList.add(intItem3);
floatList.add(floatItem3);
/* Now in the middle.
*/
intList.add(intItem2);
floatList.add(floatItem2);
/* Display the contents of the sorted integer linked list.
*/
for (item = intList.getFirst();
item != 0;
item = item->getNext())
{
item->displayValue();
}
/* Display the contents of the sorted floating linked list.
*/
for (item = floatList.getFirst();
item != 0;
item = item->getNext())
{
item->displayValue();
}
}
/**********************************************************************
* Function: stringDemo()
* Description: string manipulation routine
*/
void stringDemo()
{
String s1 = "Wind River "; // String Constructor, initialized to a
// string value
String s1copy = s1; // Copy construstor
String s2; // Create a blank string
s2 = s1; // Overload the "=" operator
String s3 = "String ";
String s4 = "Simulation";
String s5 = s1 + s3 + s4; // Demo the + overload
// Object destructors execute when
} // going out of scope
/**********************************************************************
* Function: largeClassDemo()
* Description: shows how debugger handles large structures:
* - enumerations
*/
class LargeEnum
{
enum PARMS {
RATE = 1,
RSP,
AR1_S,
AR1_D,
AR1_M,
CV1_M,
IC1_M,
LA1_M,
LV1_S,
LV1_D,
LV1_M,
P1_S,
P1_D,
P1_M,
PA1_S,
PA1_D,
PA1_M,
RA1_M,
RV1_S,
RV1_D,
RV1_M,
AR2_S,
AR2_D,
AR2_M,
CV2_M,
IC2_M,
LA2_M,
LV2_S,
LV2_D,
LV2_M,
P2_S,
P2_D,
P2_M,
PA2_S,
PA2_D,
PA2_M,
RA2_M,
RV2_S,
RV2_D,
RV2_M,
NBP_S,
NBP_D,
NBP_M,
SPO2,
SPO2_PPR,
T1,
T2,
TOP_PARM = RATE,
MAX_PARM = T2
};
int data1;
public:
LargeEnum();
};
LargeEnum::LargeEnum()
: data1(0)
{
}
void largeClassDemo()
{
LargeEnum DemoObj;
}
class UnknownIncompleteClass *unknownClassPtr;
struct UnknownIncompleteStruct *unknownStructPtr;
union UnknownIncompleteUnion *unknownUnionPtr;
union UnknownIncompleteEnum *unknownEnumPtr;
void partialTypesDemo()
{
/* Incomplete types are valid, examine the pointer
* and what they point to.
*/
unknownClassPtr = 0;
unknownStructPtr = 0;
unknownUnionPtr = 0;
unknownEnumPtr = 0;
}
@@ -0,0 +1,135 @@
/* multipleInhert.cpp - implements multiple inheritance demo */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
class Radio
{
public:
Radio() :
freq(88.3),
freqStep(0.2),
volume(2)
{}
void setFreq(float f)
{
freq = f;
}
float getFreq() const
{
return freq;
}
void setFreqStep(float f)
{
freqStep = f;
}
float getFreqStep() const
{
return freqStep;
}
void setVolume(int v)
{
volume = v;
}
int getVolume() const
{
return volume;
}
private:
float freq;
float freqStep;
int volume;
};
class Clock
{
public:
typedef unsigned long time_type;
Clock()
{
clockTime = time_type(&clockTime);
}
void setTime(time_type t)
{
clockTime = t;
}
time_type getTime() const
{
return clockTime;
}
virtual void tick()
{
clockTime++;
}
private:
time_type clockTime;
};
/* This class derives from both the Clock class and Radio classes to
* make a ClockRadio class.
*/
class ClockRadio : public Clock, public Radio
{
public:
void setAlarm(time_type t)
{
alarm = t;
}
time_type getAlarm() const
{
return alarm;
}
/* This will override the tick member function from the Clock class.
*/
void tick()
{
time_type t = getTime();
setTime(t+1);
chkAlarm();
}
bool chkAlarm() const
{
if (getTime() == alarm)
return true;
else
return false;
}
private:
time_type alarm;
};
/* Now the demo.
*/
void multipleInheritanceDemo()
{
ClockRadio cr;
/* Setting the Freq will call into the Radio class.
*/
cr.setFreq(94.5);
/* The time will be read from the Clock class.
*/
ClockRadio::time_type t = cr.getTime();
/* The alarm will be set in the ClockRadio class.
*/
cr.setAlarm(t+2);
/* The ClockRadio class overrides the tick function to
* also check for an alarm.
*/
cr.tick();
cr.tick();
cr.tick();
cr.tick();
} /* multipleInheritanceDemo */
@@ -0,0 +1,2 @@
project.type=DownloadableKernelModuleProject
platform.id=VxWorks
@@ -0,0 +1,32 @@
C++ Demonstration Program
-------------------------
This C++ demo program demonstrates various C++ language features
including classes, templates, inheritance, function overloading,
exceptions, strings, and linked lists. You can build and download this
program to your VxWorks target.
This program should be run at a priority lower than the system tasks. The
priority of the task should be less than that of the network tasks to avoid
interfering with the network. When run from the shell, host or target shell,
it is advisable to run this program as a task (i.e. "-> sp main") rather than
directly invoking teh program (i.e. "-> main").
Features
--------
The main() function includes a loop that calls the following functions to
demonstrate various C++ features:
* simpleClassDemo() - construction, operating overloading, and
initialization
* inheritanceClassDemo() - single inheritance
* multipleInheritanceDemo() - multiple inheritance
* staticDemo() - static variables in a class
* templateClassDemo() - an array template class
* largeClassDemo() - a class with a large enumeration
* partialTypesDemo() - pointers to undefined types
* virtualBaseDemo() - multiple inheritance with a virtual base
class
* stringDemo() - a string class
* exceptionDemo() - exception handling
@@ -0,0 +1,88 @@
/* static.cpp - implements static class member demo */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
/**************************************************************************
*
* This demo will show how static members are handled within a
* Class. Static members are common to all instances of the class and
* derived classes, in which the static member is defined.
*
* StaticClass defines a class with only static member variables. All
* instances of StaticClass will share the static members. There will
* be no data allocated when a new instance of StaticClass is created
* because the static members are allocated in global memory space,
* but only accessable from within the class.
*
* Classes derived from a base class with static members inherit those
* static members. Both the base class and the derived class will
* access the same member variables.
*
**************************************************************************
*/
class StaticClass
{
public:
void setMemberA(int m) { a = m; }
int getMemberA() const { return a; }
void setMemberB(int m) { b = m; }
int getMemberB() const { return b; }
private:
static int a;
static int b;
};
/* Derived class of StaticClass.
*/
class DerivedStaticClass : public StaticClass
{
public:
static void setMemberC(int m) { c = m; }
static int getMemberC() { return c; }
private:
static int c;
};
int StaticClass::a = 0;
int StaticClass::b = 0;
int DerivedStaticClass::c = 0;
void staticDemo()
{
// We will create an instance of the StaticClass class. This
// class contains only static members.
StaticClass static1;
DerivedStaticClass static2;
// Try viewing the members of both these classes. They should all
// be zero 0.
// We will set the values of the members so we can see that the
// values changed for the base class and the derived class. If
// you look at these member 'a' should be 1, 'b' should be 2 and
// 'c' should be 3. The derived class should also show these
// values.
static1.setMemberA(1);
static1.setMemberB(2);
static2.setMemberC(3);
// Now we will change all the value from the derived class. Notice
// how the values for 'a' and 'b' in the base class reflect the
// values changed in the derived class. This is because the
// instances of both the base class and the derived class share
// the members 'a' and 'b'.
static2.setMemberA(3);
static2.setMemberB(2);
static2.setMemberC(1);
} /* staticDemo */
@@ -0,0 +1,163 @@
/* string.cpp - implements simple string class */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#include <string>
#include "string.h"
#include "allocator.h"
//---------------------------------------------------------------------------
// Default Constructor
//
//---------------------------------------------------------------------------
String::String()
{
buf = 0;
length = 0;
}
//---------------------------------------------------------------------------
// Constructor
//
// Takes a char pointer for input.
//
//---------------------------------------------------------------------------
String::String( const char *s )
{
length = (unsigned)strlen( s );
buf = createBuffer( length + 1 );
strcpy( buf, s );
}
//---------------------------------------------------------------------------
// Constructor
//
// Takes a char pointer and a count
//
//---------------------------------------------------------------------------
String::String( char c, unsigned n )
{
length = n;
buf = createBuffer( length + 1 );
memset( buf, c, length );
buf[length] = '\0';
}
//---------------------------------------------------------------------------
// Copy Constructor
//
//---------------------------------------------------------------------------
String::String( const String &other )
{
length = other.length;
buf = createBuffer( length + 1 );
strcpy( buf, other.buf );
}
//---------------------------------------------------------------------------
// Assignment operator overload
//
//---------------------------------------------------------------------------
String &String::operator=( const String &other )
{
if (&other != this) {
length = other.length;
buf = createBuffer( length+1 );
strcpy( buf, other.buf );
}
return *this;
}
//---------------------------------------------------------------------------
// append
//
// Appends a String to another String.
//
//---------------------------------------------------------------------------
void String::append( const char *addition )
{
char *temp;
length += strlen( addition );
temp = createBuffer( length + 1 ); // Allocate a new buffer
strcpy( temp, buf ); // Copy contents of old buffer
strcat( temp, addition ); // Append new String
buf = temp;
}
//---------------------------------------------------------------------------
// append
//
// Appends a String to another String.
//
//---------------------------------------------------------------------------
void String::append( const String &addition )
{
char *temp;
length += addition.getLength();
temp = createBuffer( length + 1 ); // Allocate a new buffer
strcpy( temp, buf ); // Copy contents of old buffer
strcat( temp, addition.buf ); // Append new String
buf = temp;
}
//---------------------------------------------------------------------------
// appendOverloading the '+' operator to append one string to another
//---------------------------------------------------------------------------
String& String::operator +(const String &s)
{
append(s);
return *this;
}
//---------------------------------------------------------------------------
// Destructor
//
//---------------------------------------------------------------------------
String::~String()
{
}
//---------------------------------------------------------------------------
// empty
//
// Makes a String empty.
//
//---------------------------------------------------------------------------
void String::empty()
{
length = 0;
buf = 0;
}
//---------------------------------------------------------------------------
// operator [] overload
//
//---------------------------------------------------------------------------
char String::operator[]( unsigned index ) const
{
// If index is not within the String then return null char. This also
// works if the string length == 0.
if( index >= length )
return '\0';
else
return buf[index];
}
//---------------------------------------------------------------------------
// operator [] overload
//
//---------------------------------------------------------------------------
char *String::createBuffer( unsigned index ) const
{
return (char *)theAllocator->allocate( index );
}
@@ -0,0 +1,44 @@
/* string.h - declarations for string class */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#ifndef _STRING_H
#define _STRING_H
class String
{
public:
String();
String( const char *s );
String( char c, unsigned n );
String( const String &other ); // Copy Constructor
~String();
String &operator=( const String &other ); // Assignment operator
inline unsigned getLength() const { return length; }
inline bool isempty() const { return length == 0 ? true : false; }
void append( const char *addition );
void append( const String &addition );
String& operator + (const String &s);
void empty();
char operator [] ( unsigned index ) const;
private:
char *createBuffer( unsigned length ) const;
unsigned length;
char *buf;
};
#endif /* _STRING_H */
@@ -0,0 +1,55 @@
/* virtualBase.cpp - implements virtual base classes class demo */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
/**************************************************************************
*
* This demo will show how virtual base classes are used in a class.
* The purpose of a virtual base class is to create 1 definition of
* a common class.
*
**************************************************************************
*/
class BaseClass
{
public:
char baseMember;
};
class DerivedClass1 : public virtual BaseClass
{
public:
char derivedClass1Member;
};
class DerivedClass2 : public virtual BaseClass
{
public:
char derivedClass2Member;
};
class UltimateDerivedClass : public DerivedClass2, public DerivedClass1
{
};
void virtualBaseDemo()
{
// We will create an instance of the StaticMember class. This
// class contains only static members.
UltimateDerivedClass ultimate;
ultimate.derivedClass1Member = '1';
ultimate.derivedClass2Member = '2';
ultimate.baseMember = 'B';
// Try viewing the members of ultimate. There should
// be three members, set as indicated above.
ultimate.baseMember++;
}
+36
View File
@@ -0,0 +1,36 @@
# Makefile - for datagram demo.
#
# modification history
# --------------------
# 01b,13nov95,p_m adapted to Tornado.
# 01a,12feb93,jcf written.
#
# DESCRIPTION
# This file contains the makefile rules for building the host and target
# side of the VxWorks demo dg.
#
# SUBSTITUTION
# The following constant will be substitued:
# CPU cpu/architecture
# TOOL tool chain used for build
# WIND_HOST_TYPE host type; controls building of host-specific tools
#*/
CPU = MC68020
TOOL = gnu
include $(WIND_BASE)/target/h/make/defs.bsp
include $(WIND_BASE)/target/h/make/make.$(CPU)$(TOOL)
include $(WIND_BASE)/target/h/make/defs.$(WIND_HOST_TYPE)
default : $(DEMO_DIR)
$(DEMO_DIR) : .neverbuilt
$(CC) $(CFLAGS) -c dgTest.c
$(CP) dgTest.o $@
exe :
.neverbuilt :
+17
View File
@@ -0,0 +1,17 @@
This directory contains a simple datagram demonstration program.
To build the VxWorks object for that demo use:
% make CPU=<CPU_TYPE>
eg:
% make CPU=SPARC
This will install the VxWorks objects "dgTest.o" in the
$WIND_BASE/target/lib/objSPARCgnutest/ directory.
To rebuilt the Unix programs dgSender and dgReceiver do:
% cc -o dgSender dgMain.c dgTest.c
% cc -o dgReceiver dgMain.c dgTest.c
NOTE: This demo is not available on WIN32 platform.
+279
View File
@@ -0,0 +1,279 @@
/* dgMain.c - UNIX main for datagram test sender/receiver demo */
/*
modification history
--------------------
01d,31oct91,rrr passed through the ansification filter
-changed includes to have absolute path from h/
-fixed #else and #endif
-changed VOID to void
-changed copyright notice
01c,15oct91,ajm made mips look to bsd includes
01b,25oct90,lpf #ifdef <sys/socket.h>.
put back bzero() for HP.
01a,10jun88,gae written based on rdc's test programs.
*/
/*
DESCRIPTION
This demonstration module shows how to send and receive UDP packets
from VxWorks to UNIX and any combination thereof.
Firstly, a receiver, or receivers, are initiated on VxWorks and/or
UNIX. It will wait for packets on an agreed port number.
Then a sender, again on either UNIX or VxWorks, begins sending packets.
The receiver will terminate after an agreed number of packets are sent.
EXAMPLE
% dgReciver -v
% dgSender -h localhost -v
... output from dgReceiver
OPTIONS
-v verbose flag causes extra diagnostics to be printed.
-b broadcast flag causes dgSender to broadcast the packets.
-h <host> host name flag indicates the network to send on.
-p <port> selects the port number (default is 1101).
-n <#> is the number of packets to send (default 5).
-help shows the options.
*/
#if 0
#include "vxWorks.h"
#include "sys/types.h"
#include "netdb.h"
#include "inetLib.h"
#include "in.h"
#else
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#define IMPORT extern
#define LOCAL static
#define BOOL int
#define ERROR -1
#define NULL 0
#endif
#if !defined(HOST_HP)
#include <sys/socket.h> /* Do not include this file for HP/UX 7.0 */
#endif
#if !defined(HOST_MIPS)
#include <sys/ioctl.h>
#else
#include <bsd43/sys/ioctl.h>
#endif
#define TORF(x) ((x) ? "True" : "False")
#define PACKET_NUM 500 /* maximum number of packets */
IMPORT BOOL broadcast; /* when TRUE dgSender will broadcast */
IMPORT BOOL verbose; /* when TRUE extra diagnostics are displayed */
IMPORT int dgPort;
IMPORT int dgPackets;
IMPORT BOOL is42; /* SUNOS 3.4 is not completely 4.3 compatible */
#ifdef POLL
IMPORT int fionread; /* FIONREAD value (different from VxWorks) */
#endif
IMPORT int errno;
char sysBootHost [40]; /* VxWorks boot host name / our host name */
/* UNIX program must be called either: */
#define SENDNAME "dgSender"
#define RECVNAME "dgReceiver"
LOCAL char *toolname;
LOCAL char *dgSendUsage =
"usage: %s [-help] [-b] [-h host] [-p port] [-n packets] [-v]\n";
LOCAL char *dgRecvUsage =
"usage: %s [-help] [-p port] [-n packets] [-v]\n";
LOCAL char *dgSendHelp =
"show defaults\n\
-b broadcast = %s\n\
-h host = %s\n\
-p port number = %d\n\
-n number of packets = %d\n\
-v verbose = %s\n";
LOCAL char *dgRecvHelp =
"show defaults\n\
-p port number = %d\n\
-n number of packets = %d\n\
-v verbose = %s\n";
#if defined(HOST_HP)
void bzero (s, n)
char *s;
int n;
{
memset (s, '\0', n);
}
#endif
/*******************************************************************************
*
* main - send/recieve UDP datagrams
*
* -help show defaults
* -b (broadcast [send only])
* -h host (broadcast [send only])
* -n port (1101)
* -p packets (5)
* -v (verbose)
*/
void main (argc, argv)
int argc;
char *argv [];
{
char **argp = argv;
BOOL send;
toolname = *argp;
send = strcmp (SENDNAME, toolname) == 0;
gethostname (sysBootHost, sizeof (sysBootHost));
while (--argc > 0)
{
argp++;
switch (argp [0][0])
{
case '-':
if (strcmp (*argp, "-help") == 0)
{
if (send)
printf (dgSendHelp, TORF(broadcast), sysBootHost,
dgPort, dgPackets, TORF(verbose));
else
printf (dgRecvHelp,
dgPort, dgPackets, TORF(verbose));
exit (0);
}
switch (argp [0][1])
{
case 'b':
if (!send)
goto l_usage;
broadcast = !broadcast;
break;
case 'h':
if (!send)
goto l_usage;
if (argc-- > 0)
strcpy (sysBootHost, *++argp);
else
{
printf ("%s: missing <%s>\n", toolname, "host");
goto l_usage;
}
break;
case 'n':
if (argc-- > 0)
{
dgPackets = atoi (*++argp);
if (dgPackets > PACKET_NUM)
{
printf ("%s: too many packets <%d>\n",
toolname, dgPackets);
goto l_usage;
}
}
else
{
printf ("%s: missing <%s>\n", toolname, "packet");
goto l_usage;
}
break;
case 'p':
if (argc-- > 0)
dgPort = atoi (*++argp);
else
{
printf ("%s: missing <%s>\n", toolname, "port");
goto l_usage;
}
break;
case 'v':
verbose = !verbose;
break;
default:
printf ("%s: bad flag <%s>\n", toolname, *argp);
goto l_usage;
}
break;
default:
printf ("%s: no such option <%s>\n", toolname, *argp);
goto l_usage;
}
}
if (argc > 0)
{
printf ("%s: no such option <%s> ...\n", toolname, *argp);
goto l_usage;
}
#ifdef POLL
fionread = FIONREAD; /* VxWorks differs */
#endif
#ifndef SO_BROADCAST
/* BSD 4.2 doesn't have or require turning on of broadcasting */
is42 = TRUE;
#endif /* SO_BROADCAST */
if (send)
dgSender (sysBootHost, dgPort, dgPackets);
else
dgReceiver (dgPort, dgPackets);
exit (0);
l_usage:
printf ((send ? dgSendUsage : dgRecvUsage), toolname);
exit (0);
}
/*******************************************************************************
*
* hostGetByName - VxWorks compatible function to return inet address as long
*/
long hostGetByName (hostname)
char *hostname;
{
struct hostent *destHost;
/* get the internet address for the given host */
if ((destHost = (struct hostent *) gethostbyname (hostname)) == NULL)
{
printf ("%s:non existant host <%s>\n", toolname, hostname);
return ((u_long)ERROR);
}
return (*(u_long *)destHost->h_addr);
}
/*******************************************************************************
*
* errnoGet - VxWorks compatible function to return errno
*/
int errnoGet ()
{
return (errno);
}
+334
View File
@@ -0,0 +1,334 @@
/* dgTest.c - datagram test sender/receiver demo */
/*
modification history
--------------------
01e,25may95,jcf new environment variables
01d,16mar94,yao fixed to support IRIX 4.0.5 tool.
01c,15feb93,jcf added mixed endian support.
01b,31oct91,rrr passed through the ansification filter
-removed include of netdb.h
-changed includes to have absolute path from h/
-fixed #else and #endif
-changed VOID to void
-changed copyright notice
01a,10jun88,gae written based on rdc's test programs.
*/
/*
DESCRIPTION
This demonstration module shows how to send and receive UDP packets
from VxWorks to UNIX and any combination thereof.
Firstly, a receiver, or receivers, are initiated on VxWorks and/or
UNIX. It will wait for packets on an agreed port number.
Then a sender, again on either UNIX or VxWorks, begins sending packets.
The receiver will terminate after an agreed number of packets are sent.
EXAMPLE
-> sp dgReceiver
-> dgSender "127.1"
... output from dgReceiver
-> dgHelp
A few global variables are defined: verbose, terminate, and broadcast.
If verbose is true then extra diagnostics are printed.
If terminate is set to true while dgReceiver is running then it will
exit gracefully (after the first packet).
If broadcast is set to true then dgSender will broadcast the packets.
*/
#ifdef CPU
#include "vxWorks.h"
#include "sys/types.h"
#include "ioLib.h"
#include "fioLib.h"
#include "stdio.h"
#include "unistd.h"
#include "string.h"
#include "usrLib.h"
#include "errnoLib.h"
#include "hostLib.h"
#include "sockLib.h"
#include "socket.h"
#include "inetLib.h"
#include "in.h"
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define BOOL int
#define LOCAL static
#define IMPORT extern
#define ERROR -1
#define NULL 0
#define TRUE 1
#define FALSE 0
#endif
#define TORF(x) ((x) ? "True" : "False")
#define PACKET_SIZE 100 /* size of UDP packets */
#define PACKET_NUM 500 /* maximum number of packets */
IMPORT char sysBootHost[]; /* VxWorks boot hostname */
typedef struct /* PACKET */
{
int sequence;
int spare;
char data [PACKET_SIZE - 2 * sizeof (int)];
} PACKET;
BOOL broadcast = FALSE; /* when TRUE dgSender will broadcast */
BOOL verbose = FALSE; /* when TRUE extra diagnostics are displayed */
BOOL terminate = FALSE; /* when TRUE dgReceiver will quit */
BOOL is42 = FALSE; /* when FALSE socket is set for broadcast */
int dgPort = 1101; /* default */
int dgPackets = 5; /* default */
#ifdef POLL
int fionread = FIONREAD;/* VxWorks value (different from UNIX) */
#endif
/*******************************************************************************
*
* dgSender - send UDP datagrams
*/
void dgSender (host, port, packets)
char *host; /* NULL = use default */
int port; /* 0 = use default */
int packets; /* 0 = use default */
{
struct in_addr destNet;
u_long inetaddr;
struct sockaddr_in sockaddr;
int optval = 1;
PACKET packet;
int ix;
int s;
if (host == NULL)
host = sysBootHost;
if ((inetaddr = hostGetByName (host)) == ERROR &&
(inetaddr = inet_addr (host)) == ERROR)
{
printf ("invalid host: <%s>\n", host);
return;
}
if (broadcast)
{
#ifdef CPU
struct in_addr tmp;
tmp.s_addr = inetaddr;
destNet = inet_makeaddr (inet_netof (tmp), INADDR_BROADCAST);
inetaddr = destNet.s_addr;
#else
#if (WIND_HOST_TYPE==iris)
struct in_addr tmp;
tmp.s_addr = inetaddr;
destNet = inet_makeaddr (inet_netof (tmp), INADDR_BROADCAST);
inetaddr = destNet.s_addr;
#else
destNet = inet_makeaddr (inet_netof (inetaddr), INADDR_BROADCAST);
#endif /* WIND_HOST_TYPE==iris */
#endif
if (verbose)
printf ("broadcast ");
}
if (verbose)
printf ("inet address = %#x\n", htonl(inetaddr));
s = socket (AF_INET, SOCK_DGRAM, 0); /* get a udp socket */
if (s < 0)
{
printf ("socket error (errno = %#x)\n", errnoGet ());
return;
}
if (!is42)
{
/* BSD 4.2 doesn't have or require turning on of broadcasting */
if (setsockopt (s, SOL_SOCKET, SO_BROADCAST,
(caddr_t) &optval, sizeof (optval)) < 0)
{
printf ("setsockopt error (errno = %#x)\n", errnoGet ());
return;
}
}
if (port == 0)
port = dgPort;
if (packets == 0)
packets = dgPackets;
bzero ((char *) &packet, sizeof (PACKET));
bzero ((char *) &sockaddr, sizeof (sockaddr));
sockaddr.sin_family = AF_INET;
sockaddr.sin_addr.s_addr = inetaddr;
sockaddr.sin_port = htons (port);
/* send the datagrams */
for (ix = 0; ix < packets; ix++)
{
packet.sequence = htonl (ix);
/* send it */
if (sendto (s, (caddr_t) &packet, sizeof (packet), 0,
(struct sockaddr *)&sockaddr, sizeof (sockaddr)) == -1)
{
printf ("sendto error on packet # %d (errno = %#x)\n",
ix, errnoGet ());
close (s);
return;
}
}
printf ("sent %d packets\n", ix);
close (s);
}
/*******************************************************************************
*
* dgReceiver -
*/
void dgReceiver (port, packets)
int port;
int packets;
{
struct sockaddr_in sockaddr;
int sockaddrLen = sizeof (sockaddr);
int nBytes;
int ix;
BOOL missing;
char packetList [PACKET_NUM]; /* boolean array of received packets */
PACKET packet;
int nPacketsReceived = 0;
int s = socket (AF_INET, SOCK_DGRAM, 0);
if (s < 0)
{
printf ("socket error (errno = %#x)\n", errnoGet ());
return;
}
#ifdef REUSE
if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR,
(caddr_t) &optval, sizeof (optval)) < 0)
{
printf ("setsockopt error (errno = %#x)\n", errnoGet ());
return;
}
#endif /* REUSE */
if (port == 0)
port = dgPort;
if (packets == 0)
packets = dgPackets;
/* clear out the packetList */
bzero ((char *) packetList, sizeof (packetList));
bzero ((char *) &sockaddr, sizeof (sockaddr));
sockaddr.sin_family = AF_INET;
sockaddr.sin_port = htons (port);
if (bind (s, (struct sockaddr *) &sockaddr, sizeof (sockaddr)) == ERROR)
{
printf ("bind error (errno = %#x)\n", errnoGet ());
return;
}
if (getsockname (s, (struct sockaddr *) &sockaddr, &sockaddrLen) == ERROR)
{
printf ("getsockname error (errno = %#x)\n", errnoGet ());
return;
}
terminate = FALSE;
while (packets > nPacketsReceived)
{
#ifdef POLL
if (ioctl (s, fionread, &nBytes) == ERROR)
{
printf ("ioctl error (errno = %#x)\n", errnoGet ());
close (s);
return;
}
if (nBytes > 0)
#endif /* POLL */
{
nBytes = recvfrom (s, (caddr_t) &packet, sizeof (PACKET), 0,
(struct sockaddr *) &sockaddr, &sockaddrLen);
if (verbose)
printf ("received packet # %d\n", ntohl(packet.sequence));
packetList [ntohl(packet.sequence)] = TRUE;
nPacketsReceived++;
}
if (terminate)
{
printf ("terminated\n");
break;
}
}
missing = FALSE;
nPacketsReceived = 0;
for (ix = 0; ix < packets; ix++)
{
if (packetList[ix] == TRUE)
nPacketsReceived++;
else
{
missing = TRUE;
printf ("%d\n", ix);
}
}
printf ("\n%smissing packets\n", missing ? "" : "no ");
printf ("%d packets received\n", nPacketsReceived);
close (s);
}
/*******************************************************************************
*
* dgHelp -
*/
void dgHelp ()
{
printf ("dgHelp show this list\n");
printf ("dgReceiver [port],[packets] receive datagrams\n");
printf ("dgSender [host],[port],[packets] send datagrams\n");
printf ("\n");
printf ("broadcast = %s\n", TORF(broadcast));
printf ("host = %s\n", sysBootHost);
printf ("port number = %d\n", dgPort);
printf ("number of packets = %d\n", dgPackets);
printf ("verbose = %s\n", TORF(verbose));
printf ("\n");
}
@@ -0,0 +1,17 @@
/* hello.c - hello world example */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,07oct04,f_b added
*/
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
@@ -0,0 +1,2 @@
project.type=DownloadableKernelModuleProject
platform.id=VxWorks
@@ -0,0 +1,4 @@
The Hello World Demonstration Program
-------------------------------------
This is the classic "Hello World" program written in C.
@@ -0,0 +1,50 @@
# BsdSockEventSet.scp - WindView event points for BSD socket layer
#
# modification history
# --------------------
# 01a,12dec97,spm created.
#
# DESCRIPTION
# Add instrumentation for BSD socket layer (user events 37-50, inclusive).
# *(bsdSockFunc.acceptRtn)
e (*(&bsdSockFunc + 4), 37, 0, 0, 0);
# *(bsdSockFunc.bindRtn)
e (*(&bsdSockFunc + 8), 38, 0, 0, 0);
# *(bsdSockFunc.connectRtn)
e (*(&bsdSockFunc + 12), 39, 0, 0, 0);
# *(bsdSockFunc.connectWithTimeoutRtn)
e (*(&bsdSockFunc + 16), 40, 0, 0, 0);
# *(bsdSockFunc.getpeernameRtn)
e (*(&bsdSockFunc + 20), 41, 0, 0, 0);
# *(bsdSockFunc.getsocknameRtn)
e (*(&bsdSockFunc + 24), 42, 0, 0, 0);
# *(bsdSockFunc.listenRtn)
e (*(&bsdSockFunc + 28), 43, 0, 0, 0);
# *(bsdSockFunc.recvRtn)
e (*(&bsdSockFunc + 32), 44, 0, 0, 0);
# *(bsdSockFunc.recvfromRtn)
e (*(&bsdSockFunc + 36), 45, 0, 0, 0);
# *(bsdSockFunc.recvmsgRtn)
e (*(&bsdSockFunc + 40), 46, 0, 0, 0);
# *(bsdSockFunc.sendRtn)
e (*(&bsdSockFunc + 44), 47, 0, 0, 0);
# *(bsdSockFunc.sendtoRtn)
e (*(&bsdSockFunc + 48), 48, 0, 0, 0);
# *(bsdSockFunc.sendmsgRtn)
e (*(&bsdSockFunc + 52), 49, 0, 0, 0);
# *(bsdSockFunc.shutdownRtn)
e (*(&bsdSockFunc + 56), 50, 0, 0, 0);
@@ -0,0 +1,20 @@
# IpEventSet.scp - WindView event points for network layer
#
# modification history
# --------------------
# 01a,12dec97,spm created.
#
# DESCRIPTION
# Add basic instrumentation for network layer (IP, ICMP, and IGMP).
e (ip_ctloutput, 20, 0, 0, 0);
e (ip_output, 21, 0, 0, 0);
e (ip_slowtimo, 22, 0, 0, 0);
e (ip_drain, 23, 0, 0, 0);
# The ICMP and IGMP events can only be added if the pointers are not NULL.
#e (_icmpErrorHook, 24, 0, 0, 0);
#e (_igmpJoinGrpHook, 25, 0, 0, 0);
#e (_igmpLeaveGrpHook, 26, 0, 0, 0);
@@ -0,0 +1,16 @@
# MuxEventSet.scp - WindView event points for MUX layer
#
# modification history
# --------------------
# 01a,12dec97,spm created.
#
# DESCRIPTION
# Add basic instrumentation for MUX layer.
e (muxDevLoad, 0, 0, 0, 0)
e (muxDevStart, 1, 0, 0, 0)
e (muxSend, 2, 0, 0, 0)
e (muxPollSend, 3, 0, 0, 0)
e (muxReceive, 4, 0, 0, 0)
e (muxPollReceive, 5, 0, 0, 0)
e (muxDevStop, 6, 0, 0, 0)
e (muxDevUnload, 7, 0, 0, 0)
@@ -0,0 +1,32 @@
# NetBufEventSet.scp - WindView event points for network buffer management.
#
# modification history
# --------------------
# 01a,12dec97,spm created.
#
# DESCRIPTION
# Add basic instrumentation for network buffers (user events 12-19, inclusive).
# _pNetPoolFuncTbl->pMblkFreeRtn
e ( *(_pNetPoolFuncTbl + 4), 12, 0, 0, 0);
# _pNetPoolFuncTbl->pClBlkFreeRtn
e ( *(_pNetPoolFuncTbl + 8), 13, 0, 0, 0);
# _pNetPoolFuncTbl->pClFreeRtn
e ( *(_pNetPoolFuncTbl + 12), 14, 0, 0, 0);
# _pNetPoolFuncTbl->pMblkClFreeRtn
e ( *(_pNetPoolFuncTbl + 16), 15, 0, 0, 0);
# _pNetPoolFuncTbl->pMblkGetRtn
e ( *(_pNetPoolFuncTbl + 20), 16, 0, 0, 0);
# _pNetPoolFuncTbl->pClBlkGetRtn
e ( *(_pNetPoolFuncTbl + 24), 17, 0, 0, 0);
# _pNetPoolFuncTbl->pClGetRtn
e ( *(_pNetPoolFuncTbl + 28), 18, 0, 0, 0);
# _pNetPoolFuncTbl->pMblkClGetRtn
e ( *(_pNetPoolFuncTbl + 32), 19, 0, 0, 0);
@@ -0,0 +1,35 @@
This directory includes a set of scripts which will add event points
to the network stack for use with the WindView visualization tool. Each
script is executed from the Tornado Shell. Executing the commands in
the WvNetSetup.scp file alters the options of the network task to enable
the use of event points. Similarly, executing the WvNetCleanup.scp file will
restore the original settings.
The remaining script files will set event points for particular
components of the network stack as follows:
Script File Component
----------- ---------
MuxEventSet.scp MUX interface
RouteEventSet.scp Routing library
NetBufEventSet.scp Network pool manager
IpEventSet.scp IP network protocol
UdpEventSet.scp UDP transport protocol
TcpEventSet.scp TCP transport protocol
BsdSockEventSet.scp BSD sockets API
Each of these scripts should only be executed if the corresponding
stack component is actually present. In addition, the IpEventSet.scp file
contains commands to add event points for three optional routines in the
ICMP and IGMP network protocols (icmpErrorHook, igmpJoinGrpHook, and
igmpLeaveGrpHook). If any of those routines are installed, the commment mark
preceding the associated command may be removed to allow recording of the
event.
The events in these scripts are assigned the first 51 user event
identifiers (user events 0 - 50, inclusive). The eventlist.text file
lists the event identifiers assigned to each of the monitored functions
in the network stack. A similar listing is contained in the eventlist.ps
file, which includes the user-defined icons for each event. These icons
can be made available to WindView either by copying the files to the
WindView resources directory or by setting the WV_USER_ICONS environment
variable appropriately. For complete instructions on using these icons, see
the WindView User's Guide.
@@ -0,0 +1,13 @@
# RouteEventSet.scp - WindView event points for routing interface
#
# modification history
# --------------------
# 01a,12dec97,spm created.
#
# DESCRIPTION
# Add basic instrumentation for routing library.
e (rtalloc1, 8, 0, 0, 0);
e (rtredirect, 9, 0, 0, 0);
e (rtfree, 10, 0, 0, 0);
e (rtioctl, 11, 0, 0, 0);
@@ -0,0 +1,16 @@
# TcpEventSet.scp - WindView event points for TCP protocol
#
# modification history
# --------------------
# 01a,12dec97,spm created.
#
# DESCRIPTION
# Add basic instrumentation for transport layer (TCP).
e (tcp_input, 30, 0, 0, 0);
e (tcp_ctlinput, 31, 0, 0, 0);
e (tcp_ctloutput, 32, 0, 0, 0);
e (tcp_usrreq, 33, 0, 0, 0);
e (tcp_fasttimo, 34, 0, 0, 0);
e (tcp_drain, 35, 0, 0, 0);
e (tcp_timers, 36, 0, 0, 0);
@@ -0,0 +1,12 @@
# UdpEventSet.scp - WindView event points for UDP protocol
#
# modification history
# --------------------
# 01a,12dec97,spm created.
#
# DESCRIPTION
# Add basic instrumentation for transport layer (UDP).
e (udp_input, 27, 0, 0, 0);
e (udp_ctlinput, 28, 0, 0, 0);
e (udp_usrreq, 29, 0, 0, 0);
@@ -0,0 +1,9 @@
# WvNetCleanup.scp - restore changed settings to original state
#
# modification history
# --------------------
# 01a,12dec97,spm created.
#
# DESCRIPTION
# Return tNetTask to original settings (disables breakpoint debugging).
taskOptionsSet (netTaskId, 2, 0);
@@ -0,0 +1,9 @@
# WvNetSetup.scp - initialize network for WindView event tracking
#
# modification history
# --------------------
# 01a,12dec97,spm created.
#
# DESCRIPTION
# Enable breakpoint debugging to support event points for tNetTask
taskOptionsSet (netTaskId, 2, 0);
@@ -0,0 +1,8 @@
#define event0_width 20
#define event0_height 20
static unsigned char event0_bits[] = {
0xf0, 0x7f, 0x00, 0x08, 0x80, 0x00, 0x04, 0x00, 0x01, 0x02, 0x00, 0x02,
0x45, 0x15, 0x05, 0x6d, 0xa5, 0x04, 0x55, 0x45, 0x04, 0x55, 0xa5, 0x04,
0x45, 0x17, 0x05, 0x01, 0x00, 0x04, 0x01, 0x02, 0x04, 0x01, 0x07, 0x04,
0x81, 0x0a, 0x04, 0x41, 0x12, 0x04, 0x02, 0x02, 0x02, 0x04, 0x02, 0x01,
0x08, 0x82, 0x00, 0x10, 0x40, 0x00, 0xe0, 0x3f, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define /brisbane1/stephenm/tempbits/event1.new_width 20
#define /brisbane1/stephenm/tempbits/event1.new_height 20
static unsigned char /brisbane1/stephenm/tempbits/event1.new_bits[] = {
0x00, 0x00, 0x00, 0x44, 0x15, 0x01, 0x6c, 0xa5, 0x00, 0x54, 0x45, 0x00,
0x54, 0xa5, 0x00, 0x44, 0x17, 0x01, 0x00, 0x00, 0x00, 0xc0, 0x1f, 0x00,
0x20, 0x20, 0x00, 0x10, 0x40, 0x00, 0x08, 0x84, 0x00, 0x08, 0x88, 0x00,
0x08, 0x90, 0x00, 0xc8, 0xbf, 0x00, 0x08, 0x90, 0x00, 0x08, 0x88, 0x00,
0x08, 0x84, 0x00, 0x10, 0x40, 0x00, 0x20, 0x20, 0x00, 0xc0, 0x1f, 0x00};
@@ -0,0 +1,8 @@
#define event10_width 20
#define event10_height 20
static unsigned char event10_bits[] = {
0xf1, 0x7f, 0x00, 0x0a, 0x80, 0x00, 0x04, 0x00, 0x01, 0x0a, 0x00, 0x02,
0x79, 0xf7, 0x04, 0x69, 0x12, 0x04, 0x79, 0x72, 0x04, 0xa9, 0x12, 0x04,
0x49, 0xf3, 0x04, 0x01, 0x02, 0x04, 0x21, 0x24, 0x04, 0x11, 0x48, 0x04,
0xf9, 0xff, 0x04, 0x11, 0x60, 0x04, 0x22, 0x60, 0x02, 0x04, 0x80, 0x01,
0x08, 0x80, 0x01, 0x10, 0x40, 0x02, 0xe0, 0x3f, 0x04, 0x00, 0x00, 0x08};
@@ -0,0 +1,8 @@
#define event11_width 20
#define event11_height 20
static unsigned char event11_bits[] = {
0x00, 0x00, 0x00, 0xf0, 0xee, 0x01, 0x90, 0x24, 0x00, 0x70, 0xe4, 0x00,
0x50, 0x24, 0x00, 0x90, 0xe4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x04, 0x00, 0x02,
0xe4, 0x2e, 0x02, 0x24, 0x24, 0x02, 0x24, 0x24, 0x02, 0xe4, 0x64, 0x02,
0x04, 0x00, 0x02, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define event12_width 20
#define event12_height 20
static unsigned char event12_bits[] = {
0xf1, 0x7f, 0x00, 0x0a, 0x80, 0x00, 0x04, 0x00, 0x01, 0x0a, 0x00, 0x02,
0x59, 0xf7, 0x05, 0x79, 0x41, 0x08, 0x69, 0x43, 0x08, 0xc9, 0x41, 0x08,
0x49, 0x47, 0x08, 0x01, 0x02, 0x08, 0x89, 0x2e, 0x0a, 0xd9, 0x6a, 0x0b,
0xa9, 0xb6, 0x0a, 0xa9, 0xa2, 0x0a, 0x8a, 0x6e, 0x0a, 0x04, 0x80, 0x04,
0x08, 0x00, 0x03, 0x10, 0x00, 0x03, 0xe0, 0xff, 0x04, 0x00, 0x00, 0x08};
@@ -0,0 +1,8 @@
#define event13_width 20
#define event13_height 20
static unsigned char event13_bits[] = {
0xf1, 0x7f, 0x00, 0x0a, 0x80, 0x00, 0x04, 0x00, 0x01, 0x0a, 0x00, 0x02,
0x59, 0xf7, 0x05, 0x79, 0x41, 0x08, 0x69, 0x43, 0x08, 0xc9, 0x41, 0x08,
0x49, 0x47, 0x08, 0x01, 0x02, 0x08, 0x89, 0x2e, 0x0a, 0xd9, 0x6a, 0x0b,
0xa9, 0xb6, 0x0a, 0xa9, 0xa2, 0x0a, 0x8a, 0x6e, 0x0a, 0x04, 0x80, 0x04,
0x08, 0x00, 0x03, 0x10, 0x00, 0x03, 0xe0, 0xff, 0x04, 0x00, 0x00, 0x08};
@@ -0,0 +1,8 @@
#define event14_width 20
#define event14_height 20
static unsigned char event14_bits[] = {
0xf1, 0x7f, 0x00, 0x0a, 0x80, 0x00, 0x04, 0x00, 0x01, 0x0a, 0x00, 0x02,
0x59, 0xf7, 0x05, 0x79, 0x41, 0x08, 0x69, 0x43, 0x08, 0xc9, 0x41, 0x08,
0x49, 0x47, 0x08, 0x01, 0x02, 0x08, 0x89, 0x2e, 0x0a, 0xd9, 0x6a, 0x0b,
0xa9, 0xb6, 0x0a, 0xa9, 0xa2, 0x0a, 0x8a, 0x6e, 0x0a, 0x04, 0x80, 0x04,
0x08, 0x00, 0x03, 0x10, 0x00, 0x03, 0xe0, 0xff, 0x04, 0x00, 0x00, 0x08};
@@ -0,0 +1,8 @@
#define event15_width 20
#define event15_height 20
static unsigned char event15_bits[] = {
0xf1, 0x7f, 0x00, 0x0a, 0x80, 0x00, 0x04, 0x00, 0x01, 0x0a, 0x00, 0x02,
0x59, 0xf7, 0x05, 0x79, 0x41, 0x08, 0x69, 0x43, 0x08, 0xc9, 0x41, 0x08,
0x49, 0x47, 0x08, 0x01, 0x02, 0x08, 0x89, 0x2e, 0x0a, 0xd9, 0x6a, 0x0b,
0xa9, 0xb6, 0x0a, 0xa9, 0xa2, 0x0a, 0x8a, 0x6e, 0x0a, 0x04, 0x80, 0x04,
0x08, 0x00, 0x03, 0x10, 0x00, 0x03, 0xe0, 0xff, 0x04, 0x00, 0x00, 0x08};
@@ -0,0 +1,8 @@
#define event16_width 20
#define event16_height 20
static unsigned char event16_bits[] = {
0xf0, 0x7f, 0x00, 0x08, 0x80, 0x00, 0x04, 0x00, 0x01, 0x02, 0x00, 0x02,
0x49, 0xf7, 0x05, 0x59, 0x41, 0x08, 0x69, 0x43, 0x08, 0x49, 0x41, 0x08,
0x49, 0x47, 0x08, 0x01, 0x00, 0x08, 0x89, 0x2e, 0x0a, 0xd9, 0x62, 0x0b,
0xa9, 0xa6, 0x0a, 0xa9, 0xa2, 0x0a, 0x8a, 0x2e, 0x0a, 0x04, 0x00, 0x04,
0x08, 0x00, 0x02, 0x10, 0x00, 0x01, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define event17_width 20
#define event17_height 20
static unsigned char event17_bits[] = {
0xf0, 0x7f, 0x00, 0x08, 0x80, 0x00, 0x04, 0x00, 0x01, 0x02, 0x00, 0x02,
0x49, 0xf7, 0x05, 0x59, 0x41, 0x08, 0x69, 0x43, 0x08, 0x49, 0x41, 0x08,
0x49, 0x47, 0x08, 0x01, 0x00, 0x08, 0x89, 0x2e, 0x0a, 0xd9, 0x62, 0x0b,
0xa9, 0xa6, 0x0a, 0xa9, 0xa2, 0x0a, 0x8a, 0x2e, 0x0a, 0x04, 0x00, 0x04,
0x08, 0x00, 0x02, 0x10, 0x00, 0x01, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define event18_width 20
#define event18_height 20
static unsigned char event18_bits[] = {
0xf0, 0x7f, 0x00, 0x08, 0x80, 0x00, 0x04, 0x00, 0x01, 0x02, 0x00, 0x02,
0x49, 0xf7, 0x05, 0x59, 0x41, 0x08, 0x69, 0x43, 0x08, 0x49, 0x41, 0x08,
0x49, 0x47, 0x08, 0x01, 0x00, 0x08, 0x89, 0x2e, 0x0a, 0xd9, 0x62, 0x0b,
0xa9, 0xa6, 0x0a, 0xa9, 0xa2, 0x0a, 0x8a, 0x2e, 0x0a, 0x04, 0x00, 0x04,
0x08, 0x00, 0x02, 0x10, 0x00, 0x01, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define event19_width 20
#define event19_height 20
static unsigned char event19_bits[] = {
0xf0, 0x7f, 0x00, 0x08, 0x80, 0x00, 0x04, 0x00, 0x01, 0x02, 0x00, 0x02,
0x49, 0xf7, 0x05, 0x59, 0x41, 0x08, 0x69, 0x43, 0x08, 0x49, 0x41, 0x08,
0x49, 0x47, 0x08, 0x01, 0x00, 0x08, 0x89, 0x2e, 0x0a, 0xd9, 0x62, 0x0b,
0xa9, 0xa6, 0x0a, 0xa9, 0xa2, 0x0a, 0x8a, 0x2e, 0x0a, 0x04, 0x00, 0x04,
0x08, 0x00, 0x02, 0x10, 0x00, 0x01, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define event2_width 20
#define event2_height 20
static unsigned char event2_bits[] = {
0x00, 0x00, 0x00, 0x44, 0x15, 0x01, 0x6c, 0xa5, 0x00, 0x54, 0x45, 0x00,
0x54, 0xa5, 0x00, 0x44, 0x17, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x11, 0x80, 0x00, 0x11, 0x00, 0x01,
0x11, 0x00, 0x02, 0xfd, 0xff, 0x07, 0x11, 0x00, 0x02, 0x11, 0x00, 0x01,
0x11, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define event20_width 20
#define event20_height 20
static unsigned char event20_bits[] = {
0x00, 0x00, 0x00, 0x7c, 0x0f, 0x00, 0x10, 0x09, 0x00, 0x10, 0x0f, 0x00,
0x10, 0x01, 0x00, 0x7c, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x00,
0x04, 0x80, 0x00, 0x74, 0x97, 0x00, 0x14, 0x92, 0x00, 0x14, 0x92, 0x00,
0x74, 0xb2, 0x00, 0x04, 0x80, 0x00, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x04, 0x80, 0xff, 0x0f, 0x00, 0x00, 0x04, 0x00, 0x00, 0x02};
@@ -0,0 +1,8 @@
#define event21_width 20
#define event21_height 20
static unsigned char event21_bits[] = {
0x00, 0x00, 0x00, 0x7c, 0x0f, 0x00, 0x10, 0x09, 0x00, 0x10, 0x0f, 0x00,
0x10, 0x01, 0x00, 0x10, 0x01, 0x00, 0x7c, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x11, 0x80, 0x00, 0x11, 0x00, 0x01,
0x11, 0x00, 0x02, 0xfd, 0xff, 0x07, 0x11, 0x00, 0x02, 0x11, 0x00, 0x01,
0x11, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define user22_width 20
#define user22_height 20
static unsigned char user22_bits[] = {
0x00, 0x00, 0x00, 0x7c, 0x0f, 0x00, 0x10, 0x09, 0x00, 0x10, 0x0f, 0x00,
0x10, 0x01, 0x00, 0x7c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00,
0x40, 0x40, 0x00, 0x20, 0x82, 0x00, 0x10, 0x22, 0x01, 0x10, 0x12, 0x01,
0x10, 0x0a, 0x01, 0x10, 0x06, 0x01, 0x10, 0x02, 0x01, 0x10, 0x00, 0x01,
0x10, 0x00, 0x01, 0x20, 0x80, 0x00, 0x40, 0x40, 0x00, 0x80, 0x3f, 0x00};
@@ -0,0 +1,8 @@
#define user23_width 20
#define user23_height 20
static unsigned char user23_bits[] = {
0x00, 0x00, 0x00, 0x7c, 0x0f, 0x00, 0x10, 0x09, 0x00, 0x10, 0x0f, 0x00,
0x10, 0x01, 0x00, 0x10, 0x01, 0x00, 0x7c, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x11, 0x28, 0x00, 0x11, 0x50, 0x00,
0x11, 0xa0, 0x00, 0xfd, 0xff, 0x01, 0x11, 0xa0, 0x00, 0x11, 0x50, 0x06,
0x11, 0x28, 0x0a, 0x1f, 0x00, 0x0a, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x06};
@@ -0,0 +1,8 @@
#define user24_width 20
#define user24_height 20
static unsigned char user24_bits[] = {
0x00, 0x00, 0x00, 0xee, 0xa2, 0x07, 0x24, 0xb6, 0x04, 0x24, 0xaa, 0x07,
0x24, 0xaa, 0x00, 0xee, 0xa2, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x1f, 0x00,
0x20, 0x20, 0x00, 0x10, 0x42, 0x00, 0x08, 0x82, 0x00, 0x08, 0x82, 0x00,
0x08, 0x82, 0x00, 0x08, 0x82, 0x00, 0x08, 0x80, 0x00, 0x08, 0x82, 0x00,
0x08, 0x82, 0x00, 0x10, 0x40, 0x00, 0x20, 0x20, 0x00, 0xc0, 0x1f, 0x00};
@@ -0,0 +1,8 @@
#define user25_width 20
#define user25_height 20
static unsigned char user25_bits[] = {
0x00, 0x00, 0x00, 0xee, 0x45, 0x0f, 0x24, 0x6c, 0x09, 0xa4, 0x55, 0x0f,
0x24, 0x55, 0x01, 0xee, 0x45, 0x01, 0x00, 0x00, 0x00, 0xc0, 0x1f, 0x00,
0x20, 0x20, 0x00, 0x10, 0x42, 0x00, 0x08, 0x87, 0x00, 0x88, 0x8a, 0x00,
0x48, 0x92, 0x00, 0x08, 0x82, 0x00, 0x08, 0x82, 0x00, 0x08, 0x82, 0x00,
0x08, 0x82, 0x00, 0x10, 0x40, 0x00, 0x20, 0x20, 0x00, 0xc0, 0x1f, 0x00};
@@ -0,0 +1,8 @@
#define user26_width 20
#define user26_height 20
static unsigned char user26_bits[] = {
0x00, 0x00, 0x00, 0xee, 0x45, 0x0f, 0x24, 0x6c, 0x09, 0xa4, 0x55, 0x0f,
0x24, 0x55, 0x01, 0xee, 0x45, 0x01, 0x00, 0x00, 0x00, 0xc0, 0x1f, 0x00,
0x20, 0x20, 0x00, 0x10, 0x42, 0x00, 0x08, 0x82, 0x00, 0x08, 0x82, 0x00,
0x08, 0x82, 0x00, 0x48, 0x92, 0x00, 0x88, 0x8a, 0x00, 0x08, 0x87, 0x00,
0x08, 0x82, 0x00, 0x10, 0x40, 0x00, 0x20, 0x20, 0x00, 0xc0, 0x1f, 0x00};
@@ -0,0 +1,8 @@
#define user27_width 20
#define user27_height 20
static unsigned char user27_bits[] = {
0x00, 0x00, 0x00, 0xa4, 0xf3, 0x00, 0xa4, 0x94, 0x00, 0xa4, 0x94, 0x00,
0xa4, 0xf4, 0x00, 0xa4, 0x14, 0x00, 0xbc, 0x13, 0x00, 0x00, 0x00, 0x00,
0xff, 0x03, 0x00, 0x01, 0x02, 0x00, 0x41, 0x02, 0x00, 0x21, 0x02, 0x00,
0x11, 0x02, 0x00, 0xf9, 0xff, 0x07, 0x11, 0x02, 0x00, 0x21, 0x02, 0x00,
0x41, 0x02, 0x00, 0x01, 0x02, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define user28_width 20
#define user28_height 20
static unsigned char user28_bits[] = {
0x00, 0x00, 0x00, 0x48, 0xe7, 0x01, 0x48, 0x29, 0x01, 0x48, 0xe9, 0x01,
0x48, 0x29, 0x00, 0x78, 0x27, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x00,
0x04, 0x80, 0x00, 0x74, 0x97, 0x00, 0x14, 0x92, 0x00, 0x14, 0x92, 0x00,
0x74, 0xb2, 0x00, 0x04, 0x80, 0x00, 0xfc, 0xff, 0x00, 0x00, 0x02, 0x00,
0x00, 0x01, 0x00, 0x80, 0xff, 0x0f, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00};
@@ -0,0 +1,8 @@
#define user29_width 20
#define user29_height 20
static unsigned char user29_bits[] = {
0x00, 0x00, 0x00, 0x48, 0xe7, 0x01, 0x48, 0x29, 0x01, 0x48, 0xe9, 0x01,
0x48, 0x29, 0x00, 0x78, 0x27, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x07,
0x04, 0x00, 0x04, 0x04, 0x00, 0x04, 0x94, 0xee, 0x05, 0x94, 0x22, 0x05,
0x94, 0xee, 0x05, 0x94, 0xa8, 0x04, 0xf4, 0x2e, 0x05, 0x04, 0x00, 0x04,
0x04, 0x00, 0x04, 0xfc, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define event3_width 20
#define event3_height 20
static unsigned char event3_bits[] = {
0x00, 0x00, 0x00, 0x44, 0x15, 0x01, 0x6c, 0xa5, 0x00, 0x54, 0x45, 0x00,
0x54, 0xa5, 0x00, 0x44, 0x17, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3f, 0x00, 0x00, 0x21, 0x80, 0x07, 0x21, 0x88, 0x04, 0x21, 0x10, 0x04,
0x21, 0x20, 0x02, 0xfd, 0x7f, 0x02, 0x21, 0x20, 0x00, 0x21, 0x10, 0x02,
0x21, 0x08, 0x00, 0x21, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define user30_width 20
#define user30_height 20
static unsigned char user30_bits[] = {
0x00, 0x00, 0x00, 0xbe, 0xf7, 0x00, 0x88, 0x90, 0x00, 0x88, 0x90, 0x00,
0x88, 0xf0, 0x00, 0x88, 0x10, 0x00, 0x88, 0x17, 0x00, 0x00, 0x00, 0x00,
0xff, 0x03, 0x00, 0x01, 0x02, 0x00, 0x41, 0x02, 0x00, 0x21, 0x02, 0x00,
0x11, 0x02, 0x00, 0xf9, 0xff, 0x07, 0x11, 0x02, 0x00, 0x21, 0x02, 0x00,
0x41, 0x02, 0x00, 0x01, 0x02, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define user31_width 20
#define user31_height 20
static unsigned char user31_bits[] = {
0x00, 0x00, 0x00, 0x7c, 0xef, 0x01, 0x10, 0x21, 0x01, 0x10, 0xe1, 0x01,
0x10, 0x21, 0x00, 0x10, 0x2f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x00,
0x04, 0x80, 0x00, 0x74, 0x97, 0x00, 0x14, 0x92, 0x00, 0x14, 0x92, 0x00,
0x74, 0xb2, 0x00, 0x04, 0x80, 0x00, 0xfc, 0xff, 0x00, 0x00, 0x02, 0x00,
0x00, 0x01, 0x00, 0x80, 0xff, 0x0f, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00};
@@ -0,0 +1,8 @@
#define user32_width 20
#define user32_height 20
static unsigned char user32_bits[] = {
0x00, 0x00, 0x00, 0x7c, 0xef, 0x01, 0x10, 0x21, 0x01, 0x10, 0xe1, 0x01,
0x10, 0x21, 0x00, 0x10, 0x2f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x00,
0x04, 0x80, 0x00, 0x74, 0x97, 0x00, 0x14, 0x92, 0x00, 0x14, 0x92, 0x00,
0x74, 0xb2, 0x00, 0x04, 0x80, 0x00, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x04, 0x80, 0xff, 0x0f, 0x00, 0x00, 0x04, 0x00, 0x00, 0x02};
@@ -0,0 +1,8 @@
#define user33_width 20
#define user33_height 20
static unsigned char user33_bits[] = {
0x00, 0x00, 0x00, 0x7c, 0xef, 0x01, 0x10, 0x21, 0x01, 0x10, 0xe1, 0x01,
0x10, 0x21, 0x00, 0x10, 0x2f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x07,
0x04, 0x00, 0x04, 0x04, 0x00, 0x04, 0x94, 0xee, 0x05, 0x94, 0x22, 0x05,
0x94, 0xee, 0x05, 0x94, 0xa8, 0x04, 0xf4, 0x2e, 0x05, 0x04, 0x00, 0x04,
0x04, 0x00, 0x04, 0xfc, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@@ -0,0 +1,8 @@
#define user34_width 20
#define user34_height 20
static unsigned char user34_bits[] = {
0x00, 0x00, 0x00, 0x7c, 0xef, 0x01, 0x10, 0x21, 0x01, 0x10, 0xe1, 0x01,
0x10, 0x21, 0x00, 0x10, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00,
0x40, 0x40, 0x00, 0x20, 0x82, 0x00, 0x10, 0x22, 0x01, 0x10, 0x12, 0x01,
0x10, 0x0a, 0x01, 0x10, 0x06, 0x01, 0x10, 0x02, 0x01, 0x10, 0x00, 0x01,
0x10, 0x00, 0x01, 0x20, 0x80, 0x00, 0x40, 0x40, 0x00, 0x80, 0x3f, 0x00};

Some files were not shown because too many files have changed in this diff Show More