Introduction
The history and development of LegOS (now evolved into BrickOS) as been a feat of amazing ingenuity and engineering prowess. However, documentation for LegOS/BrickOS for the novice user has been difficult to come by since it's inception. This is probably rooted in the fact that from the beginning, this has been an "expert's only" development; developed by hardcore hackers/ programmers/hardware gurus for those with the same inclination. Consequently, much of the documentation available has been through the automatically generated API docs, which are often difficult to wade through.
This document hopes to list and outline the basic and most useful C (User level) commands available to the BrickOS programmer to directly control the RCX via BrickOS. Lower level functions are avoided and this reference is by no means comprehensive. The information was distilled down from the Documentation for C coders document. Please consult the BrickOS Documentation at the Source Forge Repository as the definitive reference.
A few function calls and API's have changed since I last released the original version of this document for LegOS 0.2.4. It has been a long time since I've had a chance to play around with BrickOS (switched over to Mac OS X and had a heck of a time getting a working development environment up and running) and I thought going through the API's would get me back up to speed. I thought since I'm doing this for myself, why not update the old command reference? This is work in progress, any contributions/help/suggestions/corrections would be greatly appreciated. Thus, this is my humble contribution to the wonderful BrickOS community.
Enjoy,
Dave Chen
BrickOS (at) DaveChen (dot) org
(Original Document: v1.0-10/29/2000, Updated v2.0-7/28/2004)
ToDo:
static int counter __persistent = 0; static char data[] __persistent = { 0x32, 0x36, ... };
References:
Contents
(External link to the BrickOS.SourceForge.Net web site).
Main Program and Miscellaneous Information
Back
Main entry point for BrickOS programs.
This macro is used to mark initialized data (doesn't apply to uninitialized data) as `persistent' data. This data will be saved across different runs of the program.
Usage: You should insert __persistent between the variable name and equal sign followed by value, e.g:
Pause for an interval of time before executing next commands in current program thread, other program threads will continue to execute commands. Gives up CPU time for other threads.
Initiates Software Standby/Low Power mode. On/Off button will reactivate RCX
Disables Software Standby/Low Power mode so tm_idle_task ( ) can use the sleep
Erases BrickOS and returns control to ROM, ie. Cold Boot
Turns off interrupts, then issues a reset
Returns a random integer
Seeds the Random Number Generator
Current System Time (Time up from last firmware d/l and boot up) in msec. This is a 32 bit value which will overflow after 49.7 days of continuous operation
Execute Program in slot number P. An Old function, was defined in program.c from LegOS, not sure if it is still present in BrickOS
stdlib.h
system.h
time.h
unistd.h
#include unistd.h
#include dbutton.h
#include dmotor.h
int MotorSpeed = 0;
int RunMotor() {
while (!shutdown_requested())
{
motor_a_dir(MotorSpeed);
}
return 0;
}
int CheckButton() {
while (!shutdown_requested())
{
if (PRESSED(dbutton(),BUTTON_PROGRAM)) MotorSpeed = 1;
else MotorSpeed = 0;
}
return 0;
}
int main() {
execi(&CheckButton, 0, NULL, 1, DEFAULT_STACK_SIZE);
execi(&RunMotor, 0, NULL, 1, DEFAULT_STACK_SIZE);
while(!shutdown_requested())
msleep(1000);
return 0;
}
Predefined Priority Levels:
Task Status
Rotation Sensor
Reading Sensor Values (defined Macro) for each sensor pad 1, 2 or 3
Older Macros/functions from LegOS (have to check if they're still in BrickOS)
References:
dsensor.h
Set the motor Speed
Defined Constants:
References:
dmotor.h
Digit display positions are denumerated from right to left, starting with 0 for the digit right of the running man. Digit 5 is only partially present on the RCXs display.
Parameters:
Segment Masks
Current Key activity can also be derived by checking one of the following variables:
Values as defined by the following constants:
Macros for polling the state of these buttons:
BUTTON_ONOFF (0x0002) the on/off button
BUTTON_RUN (0x0004) the run button
BUTTON_VIEW (0x4000) the view button
BUTTON_PROGRAM (0x8000) the program button
References:
dkey.h
typedef struct {
unsigned char pitch; //!< note pitch, 0 ^= A_0 (~55 Hz)
unsigned char length; //!< note length in 1/16ths
} note_t;
Pre Defined Note Lengths: WHOLE, HALF, QUARTER, EIGHTH
Pre Defined Pitches (Octave X = 0-7):
References:
dsound.h
Command Reference copyright 2004 by David C. Chen (all rights reserved).