Thursday, March 31, 2005

 

Simple Keyboard Console (repeat keyboard)

This program repeats what has been typed to the Console.

// TestConsole.hcc
// TestConsole and keyboard

#define PAL_TARGET_CLOCK_RATE 25175000
#include "pal_master.hch"
#include "pal_console.hch"
#include "pal_keyboard.hch"
#include "stdlib.hch"

// Declaration
static macro expr ClockRate = PAL_ACTUAL_CLOCK_RATE;
static macro proc MyConsole(ConsolePtr, KeyboardPtr);
static macro expr VideoOut = PalVideoOutOptimalCT (ClockRate);

// Main program

void main (void)
{
PalConsole *ConsolePtr;

macro expr PS2 = PalPS2PortCT(1);
PalKeyboard *KeyboardPtr;

// Check we've got everything we need
PalVersionRequire (1, 0);
PalVideoOutRequire (1);
PalPS2PortRequire(2);

//
par
{
PalConsoleRun (&ConsolePtr, PAL_CONSOLE_FONT_NORMAL,
VideoOut, ClockRate);
PalKeyboardRun(&KeyboardPtr, PS2, ClockRate);

seq
{
PalVideoOutEnable (VideoOut);
PalConsoleEnable (ConsolePtr);
PalKeyboardEnable(KeyboardPtr);
MyConsole (ConsolePtr, KeyboardPtr);
}
}
}

static macro proc MyConsole(ConsolePtr, KeyboardPtr)
{
macro expr endl = '\n';
static unsigned int 32 unInt;
static ram unsigned char string[80] = "\n\nShaohen's Celoxica Console\n"
"======================================\n\n";

unsigned int charEntered;

// Clear the screen
PalConsoleClear (ConsolePtr);

// Print the string
PalConsolePutString (ConsolePtr, string);

while( 1 )
{
PalKeyboardReadASCII(KeyboardPtr, &charEntered);

PalConsolePutChar(ConsolePtr, charEntered);
}
}

 

Pal Keyboard Declarations

Pal Keyboard declarations in Pal_keyboard.hcl
/*
* Abstract type of keyboard drivers
*/
typedef struct _PalKeyboard PalKeyboard;

/*
* Keyboard API
*/
extern macro proc PalKeyboardRun (KeyboardPtrPtr,
DataPortHandleCT, ClockRate);
extern macro proc PalKeyboardReset (KeyboardPtr);
extern macro proc PalKeyboardEnable (KeyboardPtr);
extern macro proc PalKeyboardDisable (KeyboardPtr);
extern macro proc PalKeyboardReadScanCode (KeyboardPtr, KeyReleasedPtr,
ScanCodePtr);
extern macro proc PalKeyboardReadASCII (KeyboardPtr, CharPtr);

/*
* Keyboard scancodes
*/
#define PAL_KEY_ESCAPE 0x76
#define PAL_KEY_F1 0x05
#define PAL_KEY_F2 0x06
#define PAL_KEY_F3 0x04
#define PAL_KEY_F4 0x0C
#define PAL_KEY_F5 0x03
#define PAL_KEY_F6 0x0B
#define PAL_KEY_F7 0x83
#define PAL_KEY_F8 0x0A
#define PAL_KEY_F9 0x01
#define PAL_KEY_F10 0x09
#define PAL_KEY_F11 0x78
#define PAL_KEY_F12 0x07
#define PAL_KEY_SCROLL_LOCK 0x7E
#define PAL_KEY_PAUSE 0x77

#define PAL_KEY_OPEN_SINGLE_QUOTE 0x0E
#define PAL_KEY_1 0x16
#define PAL_KEY_2 0x1E
#define PAL_KEY_3 0x26
#define PAL_KEY_4 0x25
#define PAL_KEY_5 0x2E
#define PAL_KEY_6 0x36
#define PAL_KEY_7 0x3D
#define PAL_KEY_8 0x3E
#define PAL_KEY_9 0x46
#define PAL_KEY_0 0x45
#define PAL_KEY_UNDERSCORE 0x4E
#define PAL_KEY_EQUALS 0x55
#define PAL_KEY_BACKSPACE 0x66

#define PAL_KEY_TAB 0x0D
#define PAL_KEY_Q 0x15
#define PAL_KEY_W 0x1D
#define PAL_KEY_E 0x24
#define PAL_KEY_R 0x2D
#define PAL_KEY_T 0x2C
#define PAL_KEY_Y 0x35
#define PAL_KEY_U 0x3C
#define PAL_KEY_I 0x43
#define PAL_KEY_O 0x44
#define PAL_KEY_P 0x4D
#define PAL_KEY_OPEN_BRACKET 0x54
#define PAL_KEY_CLOSE_BRACKET 0x5B

#define PAL_KEY_CAPS_LOCK 0x58
#define PAL_KEY_A 0x1C
#define PAL_KEY_S 0x1B
#define PAL_KEY_D 0x23
#define PAL_KEY_F 0x2B
#define PAL_KEY_G 0x34
#define PAL_KEY_H 0x33
#define PAL_KEY_J 0x3B
#define PAL_KEY_K 0x42
#define PAL_KEY_L 0x4B
#define PAL_KEY_SEMI_COLON 0x4C
#define PAL_KEY_APOSTROPHE 0x52
#define PAL_KEY_HASH 0x5D
#define PAL_KEY_RETURN 0x5A

#define PAL_KEY_LEFT_SHIFT 0x12
#define PAL_KEY_BACKSLASH 0x61
#define PAL_KEY_Z 0x1A
#define PAL_KEY_X 0x22
#define PAL_KEY_C 0x21
#define PAL_KEY_V 0x2A
#define PAL_KEY_B 0x32
#define PAL_KEY_N 0x31
#define PAL_KEY_M 0x3A
#define PAL_KEY_COMMA 0x41
#define PAL_KEY_STOP 0x49
#define PAL_KEY_DIVIDE 0x4A
#define PAL_KEY_RIGHT_SHIFT 0x59

#define PAL_KEY_LEFT_CTRL 0x14
#define PAL_KEY_LEFT_WIN 0x1F
#define PAL_KEY_LEFT_ALT 0x11
#define PAL_KEY_SPACE_BAR 0x29
#define PAL_KEY_RIGHT_ALT 0x11
#define PAL_KEY_RIGHT_WIN 0x27
#define PAL_KEY_MENU 0x2F
#define PAL_KEY_RIGHT_CTRL 0x14

#define PAL_KEY_NUMLOCK 0x77
#define PAL_KEY_NUM_ASTERIX 0x7C
#define PAL_KEY_NUM_MINUS 0x7b
#define PAL_KEY_NUM_PLUS 0x79
#define PAL_KEY_NUM_0 0x70
#define PAL_KEY_NUM_1 0x69
#define PAL_KEY_NUM_2 0x72
#define PAL_KEY_NUM_3 0x7A
#define PAL_KEY_NUM_4 0x6B
#define PAL_KEY_NUM_5 0x73
#define PAL_KEY_NUM_6 0x74
#define PAL_KEY_NUM_7 0x6C
#define PAL_KEY_NUM_8 0x75
#define PAL_KEY_NUM_9 0x7D

/*
* These keys will all have the 0xE0 prefix to their scan codes. This is
* because they are they duplicate some of the functions of the other keys.
* eg. HOME (0xEO6C) is also found on the numeric keypad 7 (0x6C).
*/
#define PAL_KEY_INSERT 0x70
#define PAL_KEY_HOME 0x6C
#define PAL_KEY_PAGE_UP 0x7D
#define PAL_KEY_DELETE 0x71
#define PAL_KEY_END 0x69
#define PAL_KEY_PAGE_DOWN 0x7A
#define PAL_KEY_CURSOR_UP 0x75
#define PAL_KEY_CURSOR_LEFT 0x6B
#define PAL_KEY_CURSOR_DOWN 0x72
#define PAL_KEY_CURSOR_RIGHT 0x74
#define PAL_KEY_NUM_DIV 0x4A

#endif /* __CELOXICA_PAL_KEYBOARD_HCH__ */

 

Console Functions

Call this function in parallel with the running functions:

The declaration for the Running function

PalConsoleRun (ConsolePtrPtr, Font,  VideoOutHandleCT, ClockRate);
Example:

PalConsoleRun(&ConsolePtr, PAL_CONSOLE_FONT_NORMAL, VideoOut, ClockRate);
Call The following functions in sequence
(1) PalVideoOutEnable(VideoOut);
(2) PalConsoleEnable(ConsolePtr);
(3) MyConsole(ConsolePtr);

MyConsole(ConsolePtr) is your function to run the program




Console Functions Declaration:

typedef struct _PalConsole PalConsole;

/*
* Choice of console fonts
*/
typedef enum
{
PAL_CONSOLE_FONT_NORMAL,
PAL_CONSOLE_FONT_COMIC,
PAL_CONSOLE_FONT_ADVENTURE
}
PalConsoleFont;

/*
* Console API
*/
extern macro proc PalConsoleRun (ConsolePtrPtr, Font,
VideoOutHandleCT, ClockRate);
extern macro proc PalConsoleReset (ConsolePtr);
extern macro proc PalConsoleEnable (ConsolePtr);
extern macro proc PalConsoleDisable (ConsolePtr);
extern macro proc PalConsoleClear (ConsolePtr);
extern macro proc PalConsolePutChar (ConsolePtr, Char);
extern macro proc PalConsolePutString (ConsolePtr, String);
extern void PalConsolePutHex (PalConsole *ConsolePtr,
unsigned 32 Value);
extern void PalConsolePutUInt (PalConsole *ConsolePtr,
unsigned 32 Value);

 

Pal Console Functions

Call this function in parallel with the running functions:

The declaration for the Running function

PalConsoleRun (ConsolePtrPtr, Font,  VideoOutHandleCT, ClockRate);
Example:

PalConsoleRun(&ConsolePtr, PAL_CONSOLE_FONT_NORMAL, VideoOut, ClockRate);
Call The following functions in sequence
(1) PalVideoOutEnable(VideoOut);
(2) PalConsoleEnable(ConsolePtr);
(3) MyConsole(ConsolePtr);

MyConsole(ConsolePtr) is your function to run the program




Console Functions Declaration:

typedef struct _PalConsole PalConsole;

/*
* Choice of console fonts
*/
typedef enum
{
PAL_CONSOLE_FONT_NORMAL,
PAL_CONSOLE_FONT_COMIC,
PAL_CONSOLE_FONT_ADVENTURE
}
PalConsoleFont;

/*
* Console API
*/
extern macro proc PalConsoleRun (ConsolePtrPtr, Font,
VideoOutHandleCT, ClockRate);
extern macro proc PalConsoleReset (ConsolePtr);
extern macro proc PalConsoleEnable (ConsolePtr);
extern macro proc PalConsoleDisable (ConsolePtr);
extern macro proc PalConsoleClear (ConsolePtr);
extern macro proc PalConsolePutChar (ConsolePtr, Char);
extern macro proc PalConsolePutString (ConsolePtr, String);
extern void PalConsolePutHex (PalConsole *ConsolePtr,
unsigned 32 Value);
extern void PalConsolePutUInt (PalConsole *ConsolePtr,
unsigned 32 Value);

 

Create Console

A simple Console program to display some information about the video (LCD)

// TestVideoConsole.hcl

#define PAL_TARGET_CLOCK_RATE 25175000
#include "pal_master.hch"
#include "pal_console.hch"
#include "stdlib.hch"

// Declaration
static macro expr ClockRate = PAL_ACTUAL_CLOCK_RATE;
static macro proc MyConsole(ConsolePtr);


// Main program

void main (void)
{
PalConsole *ConsolePtr;
macro expr VideoOut = PalVideoOutOptimalCT (ClockRate);

// Check we've got everything we need
PalVersionRequire (1, 0);
PalVideoOutRequire (1);

//
par
{
PalConsoleRun (&ConsolePtr, PAL_CONSOLE_FONT_ADVENTURE,
VideoOut, ClockRate);

seq
{
PalVideoOutEnable (VideoOut);
PalConsoleEnable (ConsolePtr);
MyConsole (ConsolePtr);
}
}
}

static macro proc MyConsole(ConsolePtr)
{
macro expr VideoOut = PalVideoOutOptimalCT (ClockRate);
macro expr endl = '\n';
static unsigned int 32 unInt;
static ram unsigned char string[80] = "\n\nShaohen's Celoxica Console\n"
"======================================\n\n";
static ram unsigned char visibleXctStr[13] = "Visible Xct: ";
static ram unsigned char visibleYctStr[13] = "Visible Yct: ";
static ram unsigned char visibleXWidth[18] = "Visible X Width : ";
static ram unsigned char visibleYWidth[18] = "Visible Y Width : ";



// Clear the screen
PalConsoleClear (ConsolePtr);

// Print the string
PalConsolePutString (ConsolePtr, string);

// Visible pixels per scan line at compile time
PalConsolePutString(ConsolePtr, visibleXctStr);
//unInt = adju(PalVideoOutGetVisibleX(VideoOut, ClockRate), 32);
unInt = PalVideoOutGetVisibleXCT(VideoOut, ClockRate);
PalConsolePutUInt(ConsolePtr, unInt);
PalConsolePutChar(ConsolePtr, endl);

// Number of visible scan lines, determined at compile time
PalConsolePutString(ConsolePtr, visibleYctStr);
unInt = PalVideoOutGetVisibleYCT(VideoOut);
PalConsolePutUInt(ConsolePtr, unInt);
PalConsolePutChar(ConsolePtr, endl);

// Number of vixible pixels per scan line, determined at run time


// width needed for a variable that holds the X coordinate of a visible pixel
PalConsolePutString(ConsolePtr, visibleXWidth );
unInt = PalVideoOutGetXWidth(VideoOut);
PalConsolePutUInt(ConsolePtr, unInt);
PalConsolePutChar(ConsolePtr, endl);
}

 

Macros

Macros in Handel-C

Macro Expression

Non-parameterized (doesn't take arguments) marco expressions are of two types:

(1) Simple constant equivalent to #define
(2) a constant expression

Simple Expression
macro expr DATA_WIDTH = 15;
This form of the macro expression is similiar to #define. WHenever DATA_WIDTH appears, the compiler replaces it with 15.

Constant Expression
macro expr sum = (x + y) @ (y + z);
A real expression can be used as well.

Parameterized macro expressions
Macros with parameters can be used as well
macro expr add3(x) = x + 3;
y = add3(z);
This is equivalent to the following code:
y = z + 3;
This form of macro is simialr to #define with parameters. Everything the add3() macro is referenced, it is expanded in the manner shown above. In this example, an adder is generated in hardware every time the add3() macro is used

Macro Procedures
Macro procedures are used to replace complete statments to avoid tedius repetition while coding. It generates the hardware for the statement each time it is referenced.
macro proc Name(parameters) Statements
Macro may be prototyped (like functions) which can be declared in one file and use them in another. Macro prototype is like so:
macro proc work(x , y);
If we have local or static declarations within the macro procedure, a copy of the variable will be created for each copy of the macro.

Difference Between Macro Procedures and Pre-processor Macro
Macro procedures differ from preprocessor macros (#define) in that they are not simple text replacements. Macro procedures must be valid Handel-C statments.

This is okay as proprocessor macro:
#define test(x,y) if (x!=(y<<2))

but it is not a valid macro procedure because it is not a complete statement
 

Pal Console

To enable Console on the built in RC200E LCD

(1) Set clockrate to EXACTLY 25175000
#define PAL_TARGET_CLOCK_RATE 25175000

Thursday, March 24, 2005

 

How to program the RC200E to read from SmartMedia

In order to program the Celosica RC200E to read from the SmartMedia every time it boots

Use this command

rc200cmdftu -b -l 0x00 YourBitFile.bit


-b Writes an FPGA configuration BIT file to the SmartMedia card.

-l Locical address to write the bit file to

Sunday, March 20, 2005

 

Running the RC200CMDFTU Program

To manually transfer the bitfile to the RC200. DO this

rc200cmdftu -c BitFileName.bit

Thursday, March 10, 2005

 

Plan for Semester 2

Get the MIPS processor going.

Compile the MIPS processor to Celoxica.
Code the Wavelet Transform to MIPS assembly.

This page is powered by Blogger. Isn't yours?