260 likes | 275 Views
Explore the LegOS 0.2.4 Kernel's startup process, task management, interrupt handling, interprocess communication, priority scheduling, sensor integration, and more for Hitachi H8/3292 hardware. Learn about task queues, semaphores, and addressing in the LegOS Network Protocol.
E N D
LegOS 0.2.4 Kernel Highlights from the Daniel Jhin Yoo March 15, 2001
The RCX Hardware Hitachi H8/3292 16-bit Timer 16k ROM 32k RAM 8-bit Timer A/D Converter I/O Ports
The Hitachi H8 ROM • Start-up driver for Firmware • kmain( ) • Low-level subsystem routines • A/D, Motor control, …) • ROM interrupt handlers call addresses in RAM
The LegOS 0.2.4 Kernel • Kernel Initialization and Timing • kmain.c and systime.c • Task Structure and Management • tm.c • Interprocess Communication • lnp.c, lnp-logical.c and semaphore.c
LegOS Startup kmain ( ) tm_init TM MM Program LNP . . . execi idle (min) packet_consumer (max) key_handler (max)
Timer Interrupts 1 interrupt / ms 16-bit Timer ROM RAM ocia_vector systime_handler ( )
systime_handler ( ) Polling • Increment 16-bit system timer • Motor handler • Sound handler • LNP checked for timeout • . . . • Check whether we need a task switch
The Life of a LegOS Process Zombie Waiting termination wait_event ( ) free stack (scheduler) wake-up function (scheduler) Running scheduler Dead Sleeping execi( ), timeslice
Scheduler Invocation systime_handler ( ) yield ( ) systime.c tm.c tm_switcher ( ) • sv reg, SP of old • ld reg, SP of new tm.c tm_scheduler ( ) • find new task • return SP of new tm.c
Prioritized Round Robin w/ Task Queue pstruct_t pstruct_t pchain_t packet_consumer key_handler priority 20 tm.h tm.h pstruct_t pchain_t idle priority 1
Scheduling Problems • Priority inversion • Slow response to wake-up function • Wake-up conditions checked only when Scheduler is selecting next task • Checking dependent on priorities of task set
The “Vehicle Test” Stop car when you detect the line Light Sensor Car only stops 32% of the time!
Solution: Prioritized Interrupts Allow user to specify an interrupt handler to a sensor event Example: “Stop the car when light sensor falls below value X”) Detect Sensor State Change Interrupt Priority > Task priority? Run Interrupt Handler Postpone Interrupt
Interrupt Queue When do we handle postponed interrupts? tm_scheduler ( ) • find new task • handle inter. with priority > new task • return SP of new
Results Kernel Line Width TS Miss Old 1mm 6ms 68% New 1mm 6ms 8% • Detection of interrupt no longer coupled to TS or priorities of task set. • Handlingof interrupt still dependent (e.g. car stops after line)
Interprocess Communication • IR via LegOS Network Protocol • lnp.c and lnp-logical.c • Semaphores • semaphore.c
LegOS Network Protocol • Two kinds of packets/services: • Integrity (“broadcast”) • Address (“UDP”)
Integrity Packet F0 LEN DATA CHK F0: integrity packet (1 byte) LEN: length of DATA section (1 byte) DATA: payload data (0-255 bytes) CHK: checksum (1 byte)
Addressing Packet F1 LEN DEST SRC DATA CHK F1: address packet (1 byte) LEN: DEST + DATA + SRC (1 byte) DEST: destination address (1 byte) SRC: source address (1 byte) DATA: payload data (0-253 bytes) CHK: checksum (1 byte)
LNP Interrupt Driven 32 interrupts / ms 8-bit Timer ROM RAM rxi_vector txi_vector rx_handler ( ) tx_handler ( )
Life of a Packet (Sender) lnp_addressing_write ( … ) lnp_logical_write ( … ) wait_event (write_allow) enable tx; tx_state = active; tx_handler wait_event (write_complete) Byte
Life of a Packet (Receiver) echo collision detection rx_handler lnp_integrity_byte ( byte ) Byte lnp_receive_pkt ( buffer ) lnp_addr_ handler ( … )
LegOS Semaphores Task sem_wait ( ) wait_event ( )
Kernel Semaphores tx_sem- only one task can transmit at a time tm_sem- only one task can touch Task Queue mm_sem- malloc needs to be memory atomic
Other Topics • GCC Stack Frame and Subroutine Calling • Memory Management • Dealing with Priority Inversion • Communicating with Sensors and Motors