Document fait avec Nvu Document made with Nvu




Emulator ports driver

FORTH mini system
FORTH micro system

Instructions
Use
Example

Principle

If the ports A and B of the emulator are inputs/outputs ports addressables in the extension registers area of the FORTH core described as follows:

272 (0x110) PORT_A
273 (0x111) PORT_B

write: value[15..0]
read: (value&input)[15..0]

lit indicator if value&input=1


The driver will allow to facilitate the use of these ports while making use of the real-time kernel. The principle consists in making i possible the developer to conceive a program which is automatically called when one of the selected inputs changes state.

For the FORTH mini system, the port A is wirde on the components PCF8574 of the I2C port numeros 0 and 1 and the port B on the components PCF8574A of the port I2C numeros 0 and 1. The most significant bits are on the numero 0 the less significant bits are on the numero 1. The electrical schematic is the following:


The FORTH micro system emulator simulates 7 ports A,B,C,D,E,F and G corresponding to a full possible configuration abling to be integrated in ac MICROCHIP 16 bits processor.


Instructions

- CW_PORT_A 272

- CW_PORT_B 273

Numero of the port A and B extension registers.
These instructions do not exist in the FORTH mini system,
The access to the ports is made with the instructions
I2C_PCF8574_C@, I2C_PCF8574A_C@, I2C_PCF8574_C! and I2C_PCF8574A_C! numeros 0 and 1.
These instructions do not exist in the FORTH micro system,
the registers are not declared in order to win memory space.

TABLE_PORTS adr

This instruction is only available in the FORTH micro system and gives the address of the variables array used by all the port drivers.

adr_prg,msq SYNC_PORT_A -

adr_prg,msq SYNC_PORT_B -

Installation of the ports A and B drivers.
adr_prg is the address of the program called with the value read on the port
during the detection of the modification of one of the selected bits.
msq is the mask of the tested bits by the driver (1 for each tested bit, 0 for the others).
If adr_prg or msq is null, the driver is removed.
In the case of the FORTH micro system, each tested bit is set as open drain, the other ones are set as outputs,
moreover adr_prg is replaced by 2 16 bits words, adrh and adrl.

adrh,adrl,msq SYNC_PORT_C -

adrh,adrl,msq SYNC_PORT_D -

adrh,adrl,msq SYNC_PORT_E -

adrh,adrl,msq SYNC_PORT_F -

adrh,adrl,msq SYNC_PORT_G -

Installation of the ports C,D,E,F and G drivers only for the FORTH micro system.
adrh,adrl is the address of the program called with the value read on the port
during the detection of the modification of one of the selected bits.
msq is the mask of the tested bits by the driver (1 for each tested bit set as open drain, 0 for the others set as outputs).
If adrh and adrl or msq is null, the driver is removed.

n SORT_PORT_A -

n SORT_PORT_B -

Writing of a value on ports A and B.
N is combined with the complement of the driver mask (0 so not installed) and sent on the port.

n SORT_PORT_C -

n SORT_PORT_D -

n SORT_PORT_E -

n SORT_PORT_F -

n SORT_PORT_G -

Writing of a value on ports B,C,D,E,F and G only i, the case of the FORTH micro system.
N is combined with the complement of the driver mask (0 so not installed) and sent on the port.


Use

The driver not being integrated into the kernel, it is initially necessary to compile the source file ports_A_B.txt before being able to use it.

For the FORTH mini system, it is first necessary to compile first the I2C drivers described in the source files pcf8574.txt and pcf8574a.txt then compile ports_A_B.txt.

For the FORTH micro system, it is first necessary to compile ports_ABCDEFG.txt or ports_ABCDEFG_ep.txt depending of the used processor. In order to optimize the memory size, remove the unused port instructions before the compillation.

It is necessary to create the program called automatically by the driver by using following syntax:

: PROGRAM
 INSTRUCTION1 INSTRUCTION2 ... INSTRUCTIONn
;

WARNING: the program will have the value of the port on the data stack, one should not forget to remove this value.

It is then necessary to install the driver with the value of the desired mask:

FIND PROGRAM MASK SYNC_PORT_x

Port x is read every 20 ms and as soon as at least one of the bits corresponding to the mask changed value since the last reading, the program is called with the value read on port x. This is realized with priority 49152.

Example

The following program allows to recopy the value of the port B on the por A while having taken care to put all the switches of the port A upwards:

DECIMAL

: PROG_PORT_B
 ( The content of the port B is copied to the port A with emission of a sound )
 SORT_PORT_A 10 500 BIP ( replace "10 100 BIP" with "7 EMIT" for the FORTH micro system )
;

0 DUP ( add "DUP" for the FORTH micro system ) SYNC_PORT_A FIND PROG_PORT_B 65535 SYNC_PORT_B

To remove this program, it is enough to make:

0 DUP ( add "DUP" for the FORTH micro system ) SYNC_PORT_B 65535 SORT_PORT_A

Here is a video: