Testing basic multithread core on a Silicon Labs 8051F300, for a larger project.
System Specifications:
Clock Speed: 24.5MHz
RAM: 256 bytes
ISP FLASH: 8kb
System Memory Resources Used:
Memory Management For 32 Memory Blocks: 4 bytes
Four System Wait Timers: 16 bytes
Eight Port State Monitors (High & Low): 34 bytes
System RAM Used In This Example: 2 bytes; 1 wait count, 1 process ID
Operation:
There are two separate processes, one monitoring the button state and one controlling the LED state.
Initially, the button state process makes a system call to the button state change system. This system call is blocking, resulting in suspension of the button state process until the button changes state. When the button process initially detects a button press, it spawns an instance of the LED control process via a fork.
The LED control process acts independently, changing the LED state approximately once per second. To accomplish LED timing, the LED control process invokes a blocking millisecond wait system call requiring no processor time.
While the LED control process is running, the button control process enters into a blocked state. When the button is pressed, the button control process gains control of the processor, kills the LED control process, and enters the initial state of waiting for a button state change.
Work continues on this project.
;TEST CODE
PORTTEST:
;WAIT FOR INITIAL (START BLINK) BUTTON PRESS
ORL PSW, 018H ;SELECT REGISTER BANK 3
MOV A, 003H ;ENSURE P0.3 IS HIGH
CALL ONPORTHI
MOV A, 003H ;WAIT FOR P0.3 TO GO LOW
CALL ONPORTLOW
;BUTTON PRESSED, SPAWN LED CONTROL PROCESS VIA WAIT CALL
MOV R6, 004H ;LOAD WAIT COUNT
MOV A, 0FAH ;WAIT 250 MILLISECONDS; SPAWN LED CONTROL PROCESS
CALL WAITFORK
JC PORTTESTERR ;CHECK FOR ERROR
JZ PORTTESTCHILD ;JUMP IF CHILD (LED CONTROL PROCESS)
;WAIT FOR SECOND (STOP BLINK) BUTTON PRESS
MOV R7, B ;SAVE WAIT ID
MOV A, 003H ;WAIT FOR P0.3 TO GO HIGH
CALL ONPORTHI
MOV A, 003H
CALL ONPORTLOW ;WAIT FOR P0.3 TO GO LOW
;BUTTON PRESSED, KILL LED CONTROL PROCESS
MOV A, R7 ;KILL LED CONTROL PROCESS
CALL WAITKILL
JMP PORTTEST ;WAIT FOR INITIAL BUTTON PRESS
PORTTESTCHILD:
;LED CONTROL PROCESS CODE
DJNZ R6, PORTTESTB ;DECREMENT MILLISECOND WAIT COUNTER
CPL P0.2 ;TOGGLE LED STATE
MOV R6, 004H ;RELOAD MILLISECOND WAIT COUNTER
PORTTESTB:
MOV A, 0FAH ;WAIT 250 MILLISECONDS
CALL WAITFORK
JC PORTTESTERR ;CHECK FOR ERROR
JZ PORTTESTCHILD
MOV R7, B
CALL PRONGTERM ;KILL THIS PRONG OF FORK
PORTTESTERR:
;ERROR HANDLER
JMP INIT ;RESET SYSTEM IF ERROR