EasyManuals Logo

LEGO MINDSTORMS Robots User Manual

LEGO MINDSTORMS Robots
226 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #180 background imageLoading...
Page #180 background image
Page 199
The dir_write() function does not work in the March 30, 1999 build of legOS 0.1.7.
Two functions are provided for reading data from the IR port:
size_t dir_read(void buf, size_t len)
This method reads len bytes of data into the supplied buffer. It returns the number of bytes read or -1 if there is an error.
void dir_fflush(void)
The IR input is buffered, which means incoming data is placed in a buffer. When it fills up, it is made available to dir_read(). To force the contents of the input buffer to be available to
dir_read(), first call dir_fflush().
One of the legOS demos is tm-and-ir.c. This program listens for incoming IR data and shows it on the RCX's display. You can type into a terminal emulator on your PC and see the data show up
on the display.
Multitasking in legOS (unistd.h and sys/tm.h)
Multiple tasks are supported in legOS through a reduced version of the standard Unix libraries. The basic idea is to set up some number of tasks using the execi() function. Then the task
manager itself must be started with a call to tm_start().
pid_t execi(int (code_start)(int, char∗∗), int argc, char ∗∗argv,
priority_tpriority, size_t stack_size)
This function starts the task described by code_start. Don't worry about the nasty-looking syntax above; all you have to do is pass the name of a function. You can pass information to the task
using the argc and argv parameters. The new task has the given priority and stack size. Lower priorities take precedence over higher priorities. In general, you can pass 0 for the priority and
DEFAULT_STACK_SIZE as the stack size. This function returns a process identification number (PID). You can stop a task, as you'll see later, using this number.
If the stack size you pass to execi() is too small, all sorts of weird behavior results. If your program crashes, this is one of the first things you should check.
Remember, a function's return addresses and automatic variables (declared in the scope of the function) are stored on the stack. If you have many levels of function calls, or
many automatic variables, or large arrays as automatic variables, you may overrun your stack.
Page 200
void tm_start(void)
Use this function to start up the task manager.
Once the task manager is running, new tasks can be started (with execi()), and running tasks can be stopped with this function:
void kill(pid_t pid)
Use this function to stop the task represented by pid.
You can suspend tasks for a given amount of time with the following two functions:
unsigned int sleep(unsigned int sec)
This function suspends execution for the given number of seconds.
unsigned int msleep(unsigned int msec)
This function suspends execution for the given number of milliseconds (ms).

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the LEGO MINDSTORMS Robots and is the answer not in the manual?

LEGO MINDSTORMS Robots Specifications

General IconGeneral
Product LineLEGO MINDSTORMS
CategoryToy
Age Range10+
Batteries RequiredYes
Memory64 MB RAM, 16 MB Flash
ConnectivityBluetooth, USB
SensorsTouch, Color, Gyro
Battery TypeAA
Interactive FeaturesProgrammable, Remote Control
App CompatibilityiOS, Android
ProcessorARM9
Pieces Count601
Battery Count6
App NameLEGO MINDSTORMS EV3 Programmer App

Related product manuals