40 #define TERMINAL_ENABLED 0
90 #define DEBUG_RECHARGEABLE
104 #define PLATFORM_START FINAL
105 #define PLATFORM_END EP2
113 #ifdef LEGO_SIMULATION
114 #define HARDWARE SIMULATION
118 #define HARDWARE FINAL
137 #define HWID (((HwId[0] - '0') * 10) + (HwId[1] - '0'))
155 #define UART1_FAKE_INTERRUPT
156 //#define DISABLE_LOW_VOLTAGE
157 //#define ENABLE_HIGH_CURRENT
158 //#define DISABLE_LOW_MEMORY
159 //#define DISABLE_UART_DATA_ERROR
160 #define DISABLE_PREEMPTED_VM
161 //#define DISABLE_SDCARD_SUPPORT
162 #define DISABLE_USBSTICK_SUPPORT
163 //#define ENABLE_PERFORMANCE_TEST
164 //#define ENABLE_LOAD_TEST
165 //#define ENABLE_MEMORY_TEST
166 //#define ENABLE_STATUS_TEST
183 #include <asm/types.h>
191 #define OUTPUTS vmOUTPUTS
192 #define INPUTS vmINPUTS
193 #define BUTTONS vmBUTTONS
196 #define LCD_WIDTH vmLCD_WIDTH
197 #define LCD_HEIGHT vmLCD_HEIGHT
198 #define TOPLINE_HEIGHT vmTOPLINE_HEIGHT
199 #define LCD_STORE_LEVELS vmLCD_STORE_LEVELS
203 #define FG_COLOR vmFG_COLOR
204 #define BG_COLOR vmBG_COLOR
206 #define CHAIN_DEPT vmCHAIN_DEPT
208 #define EVENT_BT_PIN vmEVENT_BT_PIN
212 #define MEMORY_FOLDER vmMEMORY_FOLDER
213 #define PROGRAM_FOLDER vmPROGRAM_FOLDER
214 #define DATALOG_FOLDER vmDATALOG_FOLDER
215 #define SDCARD_FOLDER vmSDCARD_FOLDER
216 #define USBSTICK_FOLDER vmUSBSTICK_FOLDER
219 #define DETAILS_FILE vmDETAILS_FILE
223 #define EXT_SOUND vmEXT_SOUND
224 #define EXT_GRAPHICS vmEXT_GRAPHICS
225 #define EXT_BYTECODE vmEXT_BYTECODE
226 #define EXT_TEXT vmEXT_TEXT
227 #define EXT_DATALOG vmEXT_DATALOG
228 #define EXT_PROGRAM vmEXT_PROGRAM
229 #define EXT_CONFIG vmEXT_CONFIG
236 #define PROJECT "LMS2012"
238 #define SPECIALVERS 'H'
241 #define MAX_PROGRAMS SLOTS
242 #define MAX_BREAKPOINTS 4
243 #define MAX_LABELS 32
244 #define MAX_DEVICE_TYPE 127
245 #define MAX_VALID_TYPE vmMAX_VALID_TYPE
246 #define MAX_DEVICE_MODES 8
247 #define MAX_DEVICE_DATASETS 8
248 #define MAX_DEVICE_DATALENGTH 32
250 #define MAX_DEVICE_BUSY_TIME 1200
252 #define MAX_DEVICE_TYPES ((MAX_DEVICE_TYPE + 1) * MAX_DEVICE_MODES)
254 #define MAX_FRAMES_PER_SEC 10
256 #define CACHE_DEEPT 10
257 #define MAX_HANDLES 250
259 #define MAX_ARRAY_SIZE 1000000000
260 #define MIN_ARRAY_ELEMENTS 0
262 #define INSTALLED_MEMORY 6000
263 #define RESERVED_MEMORY 100
264 #define LOW_MEMORY 500
266 #define LOGBUFFER_SIZE 1000
267 #define DEVICE_LOGBUF_SIZE 300
268 #define MIN_LIVE_UPDATE_TIME 10
270 #define MIN_IIC_REPEAT_TIME 10
271 #define MAX_IIC_REPEAT_TIME 1000
273 #define MAX_COMMAND_BYTECODES 64
274 #define MAX_COMMAND_LOCALS 64
275 #define MAX_COMMAND_GLOBALS 1021
277 #define UI_PRIORITY 20
278 #define C_PRIORITY 200
280 #ifndef DISABLE_PREEMPTED_VM
281 #define PRG_PRIORITY 2000
283 #define PRG_PRIORITY 200
286 #define BUTTON_DEBOUNCE_TIME 30
287 #define BUTTON_START_REPEAT_TIME 400
288 #define BUTTON_REPEAT_TIME 200
290 #define LONG_PRESS_TIME 3000
295 #define IN1_ID_HYSTERESIS 50
296 #define OUT5_ID_HYSTERESIS 100
298 #define DEVICE_UPDATE_TIME 1000000
299 #define DELAY_TO_TYPEDATA 10000
300 #define DAISYCHAIN_MODE_TIME 10
301 #define MAX_FILE_HANDLES 64
305 #define NAME_LENGTH 12
307 #define ERROR_BUFFER_SIZE 8
309 #define PWM_DEVICE "lms_pwm"
310 #define PWM_DEVICE_NAME "/dev/lms_pwm"
312 #define MOTOR_DEVICE "lms_motor"
313 #define MOTOR_DEVICE_NAME "/dev/lms_motor"
315 #define ANALOG_DEVICE "lms_analog"
316 #define ANALOG_DEVICE_NAME "/dev/lms_analog"
318 #define POWER_DEVICE "lms_power"
319 #define POWER_DEVICE_NAME "/dev/lms_power"
321 #define DCM_DEVICE "lms_dcm"
322 #define DCM_DEVICE_NAME "/dev/lms_dcm"
324 #define UI_DEVICE "lms_ui"
325 #define UI_DEVICE_NAME "/dev/lms_ui"
327 #define LCD_DEVICE "lms_display"
328 //#define LCD_DEVICE_NAME "/dev/lms_display"
329 #define LCD_DEVICE_NAME "/dev/fb0"
331 #define UART_DEVICE "lms_uart"
332 #define UART_DEVICE_NAME "/dev/lms_uart"
334 #define USBDEV_DEVICE "lms_usbdev"
335 #define USBDEV_DEVICE_NAME "/dev/lms_usbdev"
337 #define USBHOST_DEVICE "lms_usbhost"
338 #define USBHOST_DEVICE_NAME "/dev/lms_usbhost"
340 #define SOUND_DEVICE "lms_sound"
341 #define SOUND_DEVICE_NAME "/dev/lms_sound"
343 #define IIC_DEVICE "lms_iic"
344 #define IIC_DEVICE_NAME "/dev/lms_iic"
346 #define BT_DEVICE "lms_bt"
347 #define BT_DEVICE_NAME "/dev/lms_bt"
349 #define UPDATE_DEVICE "lms_update"
350 #define UPDATE_DEVICE_NAME "/dev/lms_update"
352 #define TEST_PIN_DEVICE "lms_tst_pin"
353 #define TEST_PIN_DEVICE_NAME "/dev/lms_tst_pin"
355 #define TEST_UART_DEVICE "lms_tst_uart"
356 #define TEST_UART_DEVICE_NAME "/dev/lms_tst_uart"
359 #define DIR_DEEPT vmDIR_DEEPT
366 #define FILENAMESIZE vmFILENAMESIZE
367 #define FILENAME_SIZE 52
368 #define FOLDERNAME_SIZE 10
369 #define SUBFOLDERNAME_SIZE FILENAME_SIZE
371 #define MAX_FILENAME_SIZE (FOLDERNAME_SIZE + SUBFOLDERNAME_SIZE + FILENAME_SIZE + 5)
375 #define TYPEDATE_FILE_NAME "typedata"
376 #define ICON_FILE_NAME "icon"
377 #define TEXT_FILE_NAME "text"
379 #define DEMO_FILE_NAME "../prjs/BrkProg_SAVE/Demo.rpf"
390 #define SDCARD_DEVICE1 "/dev/mmcblk0"
391 #define SDCARD_DEVICE2 "/dev/mmcblk0p1"
393 #define SDCARD_DEVICE1 "/dev/mmcblk0"
394 #define SDCARD_DEVICE2 "/dev/mmcblk0p1"
397 #define SDCARD_MOUNT "./mount_sdcard"
398 #define SDCARD_UNMOUNT "./unmount_sdcard"
403 #define USBSTICK_DEVICE "/dev/sda"
405 #define USBSTICK_DEVICE "/dev/sdf1"
408 #define USBSTICK_MOUNT "./mount_usbstick"
409 #define USBSTICK_UNMOUNT "./unmount_usbstick"
421 #define DEFAULT_FOLDER "ui"
422 #define DEFAULT_UI "ui"
424 #define DEFAULT_VOLUME vmDEFAULT_VOLUME
425 #define DEFAULT_SLEEPMINUTES vmDEFAULT_SLEEPMINUTES
427 #define COM_CMD_DEVICE_NAME USBDEV_DEVICE_NAME
446 #define BATT_INDICATOR_HIGH 7500
447 #define BATT_INDICATOR_LOW 6200
449 #define ACCU_INDICATOR_HIGH 7500
450 #define ACCU_INDICATOR_LOW 7100
462 #define LOW_VOLTAGE_SHUTDOWN_TIME 10000
464 #define BATT_WARNING_HIGH 6.2
465 #define BATT_WARNING_LOW 5.5
466 #define BATT_SHUTDOWN_HIGH 5.5
467 #define BATT_SHUTDOWN_LOW 4.5
469 #define ACCU_WARNING_HIGH 7.1
470 #define ACCU_WARNING_LOW 6.5
471 #define ACCU_SHUTDOWN_HIGH 6.5
472 #define ACCU_SHUTDOWN_LOW 6.0
478 #ifdef ENABLE_HIGH_CURRENT
488 #define LOAD_SHUTDOWN_FAIL 4.0
489 #define LOAD_SHUTDOWN_HIGH 3.0
490 #define LOAD_BREAK_EVEN 1.75
492 #define LOAD_SLOPE_UP 0.2
493 #define LOAD_SLOPE_DOWN 0.1
501 #ifndef DISABLE_VIRTUAL_BATT_TEMP
511 #define TEMP_SHUTDOWN_FAIL 45.0
512 #define TEMP_SHUTDOWN_WARNING 40.0
520 #define UPDATE_TIME1 2
521 #define UPDATE_TIME2 10
522 #define UPDATE_MEMORY 200
523 #define UPDATE_SDCARD 500
524 #define UPDATE_USBSTICK 500
528 #define MAX_SOUND_DATA_SIZE 250
529 #define SOUND_CHUNK 250
530 #define SOUND_ADPCM_CHUNK 125
531 #define SOUND_MASTER_CLOCK 132000000
532 #define SOUND_TONE_MASTER_CLOCK 1031250
533 #define SOUND_MIN_FRQ 250
534 #define SOUND_MAX_FRQ 10000
535 #define SOUND_MAX_LEVEL 8
536 #define SOUND_FILE_BUFFER_SIZE SOUND_CHUNK + 2 // 12.8 mS @ 8KHz
537 #define SOUND_BUFFER_COUNT 3
538 #define SOUND_FILE_FORMAT_NORMAL 0x0100 // RSO-file
539 #define SOUND_FILE_FORMAT_COMPRESSED 0x0101 // RSO-file compressed
549 #define VtoC(V) ((UWORD)((V * ADC_RES) / ADC_REF))
550 #define CtoV(C) ((UWORD)((C * ADC_REF) / ADC_RES))
551 #define MtoV(M) ((UWORD)((M * ADC_REF * 100) / (ADC_RES * 52)))
607 CONN_DAISYCHAIN = 117,
608 CONN_NXT_COLOR = 118,
612 CONN_INPUT_DUMB = 121,
613 CONN_INPUT_UART = 122,
615 CONN_OUTPUT_DUMB = 123,
616 CONN_OUTPUT_INTELLIGENT = 124,
617 CONN_OUTPUT_TACHO = 125,
705 #ifndef DISABLE_NEW_CALL_MUTEX
768 #define TYPE_NAME_LENGTH 11
769 #define SYMBOL_LENGTH 4
799 #define TYPE_PARAMETERS 19
800 #define MAX_DEVICE_INFOLENGTH 54
883 extern void VmPrint(
char *pString);
916 extern void BufPrint(
char Cmd,
char *pFormat, ...);
921 #define ERR_STRING_SIZE vmERR_STRING_SIZE // Inclusive zero termination
927 #ifndef DISABLE_OLD_COLOR
983 #ifndef DISABLE_FAST_DATALOG_BUFFER
990 #ifndef DISABLE_OLD_COLOR
991 COLORSTRUCT NxtCol[
INPUTS];
1002 #ifndef DISABLE_PREEMPTED_VM
1003 UWORD PreemptMilliSeconds;
1026 #define UART_DATA_LENGTH MAX_DEVICE_DATALENGTH
1027 #define UART_BUFFER_SIZE 64
1033 #ifndef DISABLE_FAST_DATALOG_BUFFER
1035 DATA8 Raw[
INPUTS][DEVICE_LOGBUF_SIZE][UART_DATA_LENGTH];
1053 #define UART_PORT_CHANGED 0x01
1054 #define UART_DATA_READY 0x08
1055 #define UART_WRITE_REQUEST 0x10
1075 #define UART_SET_CONN _IOWR('u',0,DEVCON)
1076 #define UART_READ_MODE_INFO _IOWR('u',1,UARTCTL)
1077 #define UART_NACK_MODE_INFO _IOWR('u',2,UARTCTL)
1078 #define UART_CLEAR_CHANGED _IOWR('u',3,UARTCTL)
1093 #define IIC_DATA_LENGTH MAX_DEVICE_DATALENGTH
1094 #define IIC_NAME_LENGTH 8
1100 #ifndef DISABLE_FAST_DATALOG_BUFFER
1102 DATA8 Raw[
INPUTS][DEVICE_LOGBUF_SIZE][IIC_DATA_LENGTH];
1121 #define IIC_PORT_CHANGED 0x01
1122 #define IIC_DATA_READY 0x08
1123 #define IIC_WRITE_REQUEST 0x10
1155 DATA8 Manufacturer[IIC_NAME_LENGTH + 1];
1166 #define IIC_SET_CONN _IOWR('i',2,DEVCON)
1167 #define IIC_READ_TYPE_INFO _IOWR('i',3,IICCTL)
1168 #define IIC_SETUP _IOWR('i',5,IICDAT)
1169 #define IIC_SET _IOWR('i',6,IICSTR)
1174 #define TST_PIN_LENGTH 8
1184 #define TST_PIN_ON _IOWR('t',1,TSTPIN)
1185 #define TST_PIN_OFF _IOWR('t',2,TSTPIN)
1186 #define TST_PIN_READ _IOWR('t',3,TSTPIN)
1187 #define TST_PIN_WRITE _IOWR('t',4,TSTPIN)
1192 #define TST_UART_LENGTH UART_BUFFER_SIZE
1203 #define TST_UART_ON _IOWR('t',5,TSTUART)
1204 #define TST_UART_OFF _IOWR('t',6,TSTUART)
1205 #define TST_UART_EN _IOWR('t',7,TSTUART)
1206 #define TST_UART_DIS _IOWR('t',8,TSTUART)
1207 #define TST_UART_READ _IOWR('t',9,TSTUART)
1208 #define TST_UART_WRITE _IOWR('t',10,TSTUART)
1237 #define LCD_BUFFER_SIZE (((LCD_WIDTH + 7) / 8) * LCD_HEIGHT)
1238 #define LCD_TOPLINE_SIZE (((LCD_WIDTH + 7) / 8) * (TOPLINE_HEIGHT + 1))
1330 DATA8 VolumePercent;
1419 #define PRINTBUFFERSIZE 160
1465 #ifdef ENABLE_PERFORMANCE_TEST
1476 ERR Errors[ERROR_BUFFER_SIZE];
1484 #ifndef DISABLE_SDCARD_SUPPORT
1491 #ifndef DISABLE_USBSTICK_SUPPORT
1494 ULONG UsbstickTimer;
1505 #ifdef ENABLE_STATUS_TEST
1509 #if (HARDWARE == SIMULATION)
1515 #if (HARDWARE == SIMULATION)
1517 #define VMInstance (*gInstance)
1522 void setInstance(
GLOBALS * _Instance);
Device is NXT sound sensor.
DATA8 GetVolumePercent(void)
DATAF PctMin
Percent minimum value (e.c. -100.0)
RESULT Result
Program result (OK, BUSY, FAIL)
#define OP(a, b, c, d, s, T)
DATA8 Changed[INPUTS][MAX_DEVICE_MODES]
ULONG IMINDEX
ImageData index type.
GP pGlobal
Pointer to start of global bytes.
void(* PRIM)(void)
Prototype for all byte codes.
UWORD IdValue
Device id value (e.c. 0 ~ UART)
signed char SBYTE
Basic Type used to symbolise 8 bit signed values.
IP pImage
Pointer to start of image.
LCD LcdBuffer
Copy of last LCD update.
UBYTE VARDATA
Variable base type.
void SetVolumePercent(DATA8 Volume)
OBJHEAD * pObjHead
Pointer to start of object headers.
void SetSleepMinutes(DATA8 Minutes)
SWORD DATA16
VM Type for 2 byte signed value.
OBJSTAT ProgramStatus(PRGID PrgId)
Get program status.
OBJID ObjectId
Active object id.
IP GetObjectIp(void)
Get current instruction pointer.
SLONG DATA32
VM Type for 4 byte signed value.
DATA8 GetTerminalEnable(void)
OBJSTAT StatusChange
Program status change.
DATA8 LcdUpdated
LCD updated.
DATA8 CheckUsbstick(DATA8 *pChanged, DATA32 *pTotal, DATA32 *pFree, DATA8 Force)
void PrimParAdvance(void)
Skip next encoded parameter from byte code stream.
UWORD OBJID
Object id type.
void * VmMemoryResize(HANDLER Handle, DATA32 Elements)
void LogErrorNumber(ERR Error)
OP OpCode
Saved substituted opcode.
DATA8 LogErrorNumberExists(ERR Error)
Port empty or not available.
DATA16 HANDLER
Memory list index.
UBYTE ObjStatus
Object status.
ULONG Priority
Object priority.
GP pData
Pointer to start of data.
ULONG RunTime
Program run time [uS].
OBJHEAD * pObjHead
Pointer to start of object headers.
Break because of user decision.
DSPSTAT DispatchStatus
Dispatch status.
void VmPrint(char *pString)
Break because of opcode break.
Break because of program stop.
DSPSTAT DispatchStatusSave
Device is a NXT ADC test sensor.
ULONG InstrCnt
Instruction counter (performance test)
DATAF SiMin
SI unit minimum value (e.c. -100.0)
IP Ip
Object instruction pointer.
void SetInstructions(ULONG Instructions)
Set instructions.
Port not empty but type has not been determined.
OBJID Objects
No of objects in image.
UWORD TRIGGER
TriggerCount type.
IMGDATA * IP
Instruction pointer type.
void ProgramEnd(PRGID PrgId)
Exit program nicely (freeing up memory)
DATAF RawMax
Raw maximum value (e.c. 1023.0)
DATA8 Pins
Device pin setup.
void SetTerminalEnable(DATA8 Value)
DATAF SiMax
SI unit maximum value (e.c. 100.0)
unsigned int ULONG
Basic Type used to symbolise 32 bit unsigned values.
ULONG InstrCnt
Instruction counter used for performance analyses.
DSPSTAT ExecuteByteCode(IP pByteCode, GP pGlobals, LP pLocals)
Execute byte code stream (C-call)
TYPES TypeData[INPUTS][MAX_DEVICE_MODES]
TypeData.
IP GetImageStart(void)
Get pointer to actual start of byte code image.
LP pLocal
Local variable pointer.
ULONG StartTime
Program start time [mS].
Device is NXT light sensor.
RESULT mSchedInit(int argc, char *argv[])
OBJID CallingObjectId(void)
Get calling object id.
void AdjustObjectIp(IMOFFS Value)
Adjust current instruction pointer.
#define SYMBOL_LENGTH
Symbol leng th (not including zero)
RESULT ValidateString(DATA8 *pString, DATA8 Set)
void * PrimParPointer(void)
Get next encoded parameter from byte code stream.
Break because of program break.
Port not empty and type is invalid.
TRIGGER TriggerCount
Trigger count used by BLOCK's trigger logic.
OBJID CallerId
Caller id used for SUBCALL to save object id to return to.
ULONG CurrentObjectIp(void)
void GetResourcePath(char *pString, DATA8 MaxLength)
ULONG InstrTime
Instruction time used for performance analyses.
SLONG IMOFFS
ImageData offset type.
Device is NXT IIC sensor.
OBJ ** pObjList
Pointer to object pointer list.
DATA8 CheckSdcard(DATA8 *pChanged, DATA32 *pTotal, DATA32 *pFree, DATA8 Force)
RESULT ValidateChar(DATA8 *pChar, DATA8 Set)
unsigned char UBYTE
Basic Type used to symbolise 8 bit unsigned values.
Port is connected to a terminal.
DATA8 GetSleepMinutes(void)
#define BUTTONS
Number of buttons in the system.
FLOAT DATAF
VM Type for 4 byte floating point value.
VARDATA * LP
Local variable pointer type.
unsigned short UWORD
Basic Type used to symbolise 16 bit unsigned values.
#define OUTPUTS
Number of output ports in the system.
IP ObjectIp
Working object Ip.
DATAF RawMin
Raw minimum value (e.c. 0.0)
GP pGlobal
Pointer to start of global bytes.
UWORD InvalidTime
mS from type change to valid data
Device is a mini tacho motor.
PRGID CurrentProgramId(void)
Get current program id.
UWORD PRGID
Program id type.
void SetObjectIp(IP Ip)
Set current instruction pointer.
IP pImage
Pointer to start of image.
OBJ ** pObjList
Pointer to object pointer list.
LP ObjectLocal
Working object locals.
SBYTE DATA8
VM Type for 1 byte signed value.
IP ObjectIp
Working object Ip.
Device is NXT color sensor.
IMINDEX Addr
Offset to breakpoint address from image start.
Break because of sleeping.
OBJID Objects
No of objects in image.
OBJID ObjectId
Active object id.
Device is a new tacho motor.
OBJSTAT ProgramStatusChange(PRGID PrgId)
Get program status change.
RESULT mSchedCtrl(UBYTE *pRestart)
void SetDispatchStatus(DSPSTAT Status)
Set object (dispatch) status.
OBJSTAT Status
Program status.
#define INPUTS
Number of input ports in the system.
void Error(void)
opOUTPUT_READY byte code
VARDATA * GP
global variable pointer type
Break because of waiting for completion.
#define MAX_LABELS
Max number of labels per program.
Dispatcher running (looping)
PRGID ProgramId
Program id running.
DATAF PctMax
Percent maximum value (e.c. 100.0)
Device is NXT touch sensor.
signed int SLONG
Basic Type used to symbolise 32 bit signed values.
LP ObjectLocal
Working object locals.