|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--stamp.core.CPU
Utility methods for accessing the Javelin Stamp hardware core.
This class contains many of the native methods integrated into the
Javelin Stamp. There is no need to create an instance of CPU
since all of its methods and fields are declared static.
Field Summary | |
static int |
MAX_NUM_VPS
The maximum number of virtual peripherals that can be installed at once. |
static int |
pin0
A constant representing pin P0. |
static int |
pin1
A constant representing pin P1. |
static int |
pin10
A constant representing pin P10. |
static int |
pin11
A constant representing pin P11. |
static int |
pin12
A constant representing pin P12. |
static int |
pin13
A constant representing pin P13. |
static int |
pin14
A constant representing pin P14. |
static int |
pin15
A constant representing pin P15. |
static int |
pin2
A constant representing pin P2. |
static int |
pin3
A constant representing pin P3. |
static int |
pin4
A constant representing pin P4. |
static int |
pin5
A constant representing pin P5. |
static int |
pin6
A constant representing pin P6. |
static int |
pin7
A constant representing pin P7. |
static int |
pin8
A constant representing pin P8. |
static int |
pin9
A constant representing pin P9. |
static int[] |
pins
An array representing all of the pins on the module. |
static int |
PORTA
A constant representing the first I/O port on the Javelin Stamp. |
static int |
PORTB
A constant representing the second I/O port on the Javelin Stamp. |
static int |
POST_CLOCK_LSB
Specify post-clock sampling and LSB-first transmission for the shift methods. |
static int |
POST_CLOCK_MSB
Specify post-clock sampling and MSB-first transmission for the shift methods. |
static int |
PRE_CLOCK_LSB
Specify pre-clock sampling and LSB-first transmission for the shift methods. |
static int |
PRE_CLOCK_MSB
Specify pre-clock sampling and MSB-first transmission for the shift methods. |
static int |
SHIFT_LSB
Specify LSB-first transmission for the shift methods. |
static int |
SHIFT_MSB
Specify MSB-first transmission for the shift methods. |
Method Summary | |
static boolean |
carry()
Internal method. |
static int |
count(int timeout,
int portPin,
boolean edge)
Count the number of rising or falling edge transitions that occur during a set period of time. |
static void |
delay(int period)
Delays the program execution for a period of time. |
static void |
install(int routine)
Internal method. |
static void |
installVP(VirtualPeripheral vp)
Install a new Virtual Peripheral. |
static void |
message(char[] data,
int length)
Internal method. |
static void |
nap(int period)
Put the Javelin Stamp into sleep mode for a period of time. |
static int |
pulseIn(int timeout,
int portPin,
boolean pinState)
Measure the length of a single pulse. |
static void |
pulseOut(int length,
int portPin)
Generate a pulse of a specific duration.If the pin is an input then it will be changed to be an output and remain as an output when complete. |
static int |
rcTime(int timeout,
int portPin,
boolean pinState)
Measure the length of time it takes for a pin to match a desired value. |
static boolean |
readPin(int portPin)
Reads the logic value on a pin. |
static byte |
readPort(int port)
Read the value on a port. |
static int |
readRegister(int address)
Internal method. |
static int |
readSRAM(int addr)
Internal method. |
static void |
removeVP(VirtualPeripheral vp)
Remove a virtual peripheral from its slot. |
static void |
setInput(int portPin)
Make a pin an input. |
static void |
setOutput(int portPin)
Internal method. |
static int |
shiftIn(int dataPortPin,
int clockPortPin,
int bitCount,
int mode)
Read data from a synchronous serial device. |
static void |
shiftOut(int dataPortPin,
int clockPortPin,
int bitCount,
int mode,
int data)
Write data to a synchronous serial device. |
static void |
uninstall(int bank)
Internal method. |
static void |
writeObject(int address,
Object value)
Internal method. |
static void |
writePin(int portPin,
boolean value)
Set a pin to a logic state. |
static void |
writePort(int port,
byte value)
Output a value onto a port. |
static void |
writeRegister(int address,
int value)
Internal method. |
static void |
writeSRAM(int addr,
int value)
Internal method. |
Methods inherited from class java.lang.Object |
equals |
Field Detail |
public static final int pin0
public static final int pin1
public static final int pin2
public static final int pin3
public static final int pin4
public static final int pin5
public static final int pin6
public static final int pin7
public static final int pin8
public static final int pin9
public static final int pin10
public static final int pin11
public static final int pin12
public static final int pin13
public static final int pin14
public static final int pin15
public static int[] pins
public static final int PORTA
public static final int PORTB
public static final int PRE_CLOCK_MSB
public static final int POST_CLOCK_MSB
public static final int PRE_CLOCK_LSB
public static final int POST_CLOCK_LSB
public static final int SHIFT_MSB
public static final int SHIFT_LSB
public static final int MAX_NUM_VPS
Method Detail |
public static void installVP(VirtualPeripheral vp) throws IllegalArgumentException
vp
- the virtual peripheral instance to install.public static void removeVP(VirtualPeripheral vp)
vp
- the virtual peripheral to remove.public static void delay(int period)
period
- the length of time to delay for, measured in
95.48 microsecond units.public static void nap(int period)
period
- specifies the period for which the Stamp should sleep. The
following values are valid:
public static int count(int timeout, int portPin, boolean edge)
To ensure reliable detection the input signal must maintain a value for at least 8.68us. This means that a square wave must have a period of at least 17.36us and a frequency less than 57.6kHz.
timeout
- the amount of time to count transitions over. Measured in
8.68us units. The value of 32,767 allows a maximum measurement
time of 284.4ms.portPin
- the I/O pin to measure transitions on.edge
- the type of edge to count. Pass true to count rising edges,
or false to count falling edges.public static int rcTime(int timeout, int portPin, boolean pinState)
timeout
- the maximum measurable time.portPin
- the I/O pin to measure.pinState
- the pin state to wait for.public static int pulseIn(int timeout, int portPin, boolean pinState)
A pulse of less than 8.68us in duration may be missed.
timeout
- the maximum amount of time to spend in the pulseIn method.
The timeout covers the complete time of the process—both
the wait for the start of the pulse and the time of the pulse.portPin
- the I/O pin to measure the pulse on.pinState
- whether to measure a high pulse (true) or a low pulse (false).public static void pulseOut(int length, int portPin)
The time is measured in 8.68us units with a maximum value of 32767 giving a maximum pulse time of 284.4ms. A time of 0 will not cause a pulse. pulseOut can be used to generate the control pulses for a servo motor.
length
- the length of the pulse to generate, measured in 8.68us units.portPin
- the I/O to generate the pulse on.public static boolean readPin(int portPin)
portPin
- the I/O pin to read.public static void writePin(int portPin, boolean value)
portPin
- the I/O pin to write.value
- the state the set the pin to.public static int shiftIn(int dataPortPin, int clockPortPin, int bitCount, int mode)
The mode parameter selects pre/post clock sampling. Note that some devices require pre-clock sampling. When pre-clock sampling is used the data pin is sampled to obtain the first bit prior to any change of the clock pin. Clearly the device must have had a clock pulse to output the first bit and this is normally supplied by the previous call to shiftIn or shiftOut. Most synchronous serial devices require a write (shiftOut) prior to reading and so the clock for the first bit will be supplied by the shiftOut call. If the device must be read without first being written to then the first read (shiftIn) should request an extra bit to provide the initial clock pulse.
Note that the bit count can be set to higher than 16 (up to 256) if desired. When a number greater than 16 is used the last 16 bits will be returned.
dataPortPin
- the I/O pin to read data on.clockPortPin
- the I/O pin on which to provide the clock to the external device.bitCount
- the number of bits to count in (from 1 to 16). bitCount must not be 0.mode
- the shifting and clocking mode to employ. This determines whether
bits are shifted into the least-significant-bit (LSb) or most-significant-bit (MSb)
first. The clocking mode determines whether the data is sampled before or after
the first clock transition. See the description for the possible values.public static void shiftOut(int dataPortPin, int clockPortPin, int bitCount, int mode, int data)
Both the clock and data pins should be initialized before calling shiftOut. shiftOut works by inverting the pins so you can generate either idle high or idle low signals.
If LSb first is selected then the data can be passed directly. If MSb first is selected then if less than 16 bits are to be shift out, data should be shifted left to MSb justify it.
dataPortPin
- the I/O pin to write data on.clockPortPin
- the I/O pin on which to provide the clock to the external device.bitCount
- the number of bits to count out (from 1 to 16). bitCount must not be 0.mode
- the shifting mode to employ. This determines whether
bits are shifted into the least-significant-bit (LSb) or most-significant-bit (MSb)
first. Valid values are CPU.SHIFT_MSB and CPU.SHIFT_LSB.public static void writePort(int port, byte value)
This method will disturb any virtual peripherals which are using the port.
port
- the port to control. Can be either CPU.PORTA, or CPU.PORTB.value
- the value to write to the port.public static byte readPort(int port)
port
- the port to read. Can be either CPU.PORTA, or CPU.PORTB.public static void setInput(int portPin)
portPin
- the pin to make into an input.public static void writeRegister(int address, int value)
public static int readRegister(int address)
public static void writeObject(int address, Object value)
public static boolean carry()
public static void uninstall(int bank)
public static void install(int routine)
public static void message(char[] data, int length)
public static void setOutput(int portPin)
public static void writeSRAM(int addr, int value)
public static int readSRAM(int addr)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |