69 volatile unsigned cprog;
77 const unsigned char min_length[]={
90 static unsigned char* buffer_ptr;
91 volatile unsigned char packet_len;
92 volatile unsigned char packet_src;
94 static sem_t packet_sem;
97 #define debugs(a) { cputs(a); msleep(500); } 98 #define debugw(a) { cputw(a); msleep(500); } 105 int lrkey_handler(
unsigned int etype,
unsigned int key);
124 static void program_run(
unsigned nr) {
142 static void packet_producer(
const unsigned char *data,
143 unsigned char length,
147 if(packet_len>0 || length==0)
153 buffer_ptr =
malloc(length);
154 memcpy(buffer_ptr,data,length);
161 static int packet_consumer(
int argc,
char *argv[]) {
178 debugw(*(
size_t*)buffer_ptr);
183 if (cmd>=
CMDlast || packet_len<min_length[cmd])
188 if (buffer_ptr[1]==0) {
189 debugs(
"nearmodeIR");
272 size_t offset=*(
size_t*)(buffer_ptr+2);
273 if(offset<=prog->downloaded) {
275 memcpy(prog->
text+offset,buffer_ptr+4,packet_len-4);
356 #ifdef CONF_LR_HANDLER 364 int key_handler(
int argc,
char *argv[]) {
377 debugs(
"key "); debugw(c);
418 if( (++
cprog)>=PROG_MAX)
476 #if defined(CONF_DSENSOR) 481 #endif // CONF_DSENSOR 495 #if defined(CONF_LR_HANDLER) 496 int lrkey_handler(
unsigned int etype,
unsigned int key) {
498 unsigned char pnr = 0;
517 #endif // CONF_DSOUND 540 #ifndef CONF_LCD_REFRESH 552 #if defined(CONF_DMOTOR) 578 #endif // CONF_DMOTOR 583 #ifndef CONF_LCD_REFRESH 593 #if defined(CONF_DMOTOR) 609 #endif // CONF_DMOTOR 627 #ifndef CONF_LCD_REFRESH 644 #ifdef CONF_LR_HANDLER 661 #ifdef CONF_LR_HANDLER 666 #endif // CONF_PROGRAM int mm_free_mem(void)
how many bytes of memory are free?
void cls()
clear user portion of LCD
#define KEY_PRGM
the program key is pressed
#define KEY_RUN
the run key is pressed
a key on the remote was released
int program_valid(unsigned nr)
check if a given program is valid.
#define LRKEY_BEEP
Beep Key.
#define LNP_DUMMY_ADDRESSING
dummy addressing layer packet handler
int getchar()
wait for keypress and return key code.
#define LRKEY_B2
Motor-B reverse (down)
#define CONF_LNP_HOSTMASK
LNP host mask.
Interface: string functions.
#define LRKEY_P5
Run Program 5.
void lr_set_handler(lr_handler_t handler)
set a new handler for LEGO IR Remote messages
int get_battery_mv()
get current battery voltage
void * data
origin of data segment (imm. after text)
void free(void *ptr)
return the allocated memory to memory management.
size_t start
offset from text segment to start into.
void motor_b_dir(MotorDirection dir)
set motor B direction to dir
size_t downloaded
number of bytes downloaded so far.
Interface: console input / output.
void dsound_stop(void)
stop playing sound
Internal Interface: direct motor control.
Internal Interface: direct sensor access.
volatile unsigned int nb_tasks
number of tasks
void lnp_set_hostaddr(unsigned char host)
set new LNP host address
#define LRKEY_STOP
Stop key.
void program_init()
initialize program support
#define LRKEY_P1
Run Program 1.
volatile unsigned cprog
the current program
int sem_wait(sem_t *sem)
Wait for semaphore (blocking)
volatile unsigned int nb_system_tasks
void cputc_0(unsigned c)
write ASCII char to position 0 of LCD
void lnp_addressing_set_handler(unsigned char port, lnp_addressing_handler_t handler)
set an addressing layer packet handler for a port.
int sem_destroy(sem_t *sem)
We're done with the semaphore, destroy it.
Internal LNP Interface: link networking protocol logical layer.
void * text
origin of text segment
Internal Interface: battery handling.
a key on the remote was pressed
wakeup_t dkey_released(wakeup_t data)
wakeup if all of the given keys are released.
#define LRKEY_A1
Motor-A forward (up)
void shutdown_tasks(tflags_t flags)
void program_shutdown()
shutdown program support
size_t bss_size
bss segment size in bytes
Internal Interface: program data structures and functions.
void motor_c_dir(MotorDirection dir)
set motor C direction to dir
int lnp_addressing_write(const unsigned char *data, unsigned char length, unsigned char dest, unsigned char srcport)
send a LNP addressing layer packet of given length
atomic_t sem_t
the semaphore data-type
#define LRKEY_A2
Motor-A reverse (down)
Internal Interface: task management.
void lr_init(void)
initialize the LEGO IR Remote subsystem
size_t text_size
text segment size in bytes
void * bss
origin of bss segment (imm. after data)
void cputs(char *s)
Write string s to LCD (Only first 5 chars)
Interface: reduced UNIX standard library.
void killall(priority_t p)
#define KEY_VIEW
the view key is pressed
void lr_shutdown(void)
stop the LEGO IR Remote subsystem
#define PRIO_HIGHEST
The highest possible task priority.
Internal Interface: memory management.
#define LRKEY_P2
Run Program 2.
#define lcd_int(i)
display an integer in decimal
tdata_t * ctid
ptr to current process data
tflags_t tflags
task flags
#define T_KERNEL
task flags
priority_t prio
priority to run this program at
#define LRKEY_C1
Motor-C forward (up)
tid_t execi(int(*code_start)(int, char **), int argc, char **argv, priority_t priority, size_t stack_size)
void motor_a_dir(MotorDirection dir)
set motor A direction to dir
#define PROG_MAX
maximum number of programs
The program control structure.
unsigned char lnp_hostaddr
LNP host address.
void lnp_init(void)
Initialise protocol handlers.
void * memcpy(void *dest, const void *src, size_t size)
copy memory block from src to dest.
void lnp_logical_range(int far)
Set the IR transmitter range.
void * malloc(size_t size)
allocate and return pointer to uninitialized memory
Interface: POSIX 1003.1b semaphores for task synchronization.
void ds_init(void)
initialize sensor a/d conversion
void lcd_refresh(void)
refresh the entire LCD display
void lr_startup(void)
start the LEGO IR Remote subsystem
Interface: LEGO Infrared Remote Control.
int sem_post(sem_t *sem)
Post a semaphore.
#define KEY_ONOFF
the on/off key is pressed
void dm_init(void)
initialize motors
#define KEY_ANY
any of the keys
#define T_SHUTDOWN
shutdown requested
size_t data_size
data segment size in bytes
#define LRKEY_B1
Motor-B forward (up)
static void dsound_system(unsigned nr)
play a system sound
Interface: reduced standard C library.
unsigned int msleep(unsigned int msec)
1+>3: b[nr] s[offset] array[data]
void * memset(void *s, int c, size_t n)
fill memory block with a byte value.
#define LRKEY_C2
Motor-C reverse (down)
Internal LNP Interface: link networking protocol.
1+12: b[nr] s[textsize] s[datasize]
wakeup_t wait_event(wakeup_t(*wakeup)(wakeup_t), wakeup_t data)
#define shutdown_requested()
test to see if task has been asked to shutdown
void cputc_hex_0(unsigned nibble)
write HEX digit to position 0 of LCD
void cputw(unsigned word)
Write a HEX word to LCD.
#define LRKEY_P4
Run Program 4.
size_t stack_size
stack segment size in bytes
void * data_orig
origin of backup copy of data segment
#define LRKEY_P3
Run Program 3.
void program_stop(int flag)
stop program
int sem_init(sem_t *sem, int pshared, unsigned int value)
Initialize a semaphore.
#define DEFAULT_STACK_SIZE
that's enough.