[939a68]: modules / lms2012 / lms2012 / source / lms2012.h Maximize Restore History

Download this file

lms2012.h    1542 lines (1191 with data), 50.0 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
/*
* LEGO速 MINDSTORMS EV3
*
* Copyright (C) 2010-2013 The LEGO Group
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*! \page debug Terminal Configuration
*
\verbatim
TERMINAL CONFIGURATION (in top of "lms2012.h")
Normal release: DEBUG not defined, TERMINAL_ENABLED = 0, DEBUG_UART = 4
Printf working: DEBUG not defined, TERMINAL_ENABLED = 0, DEBUG_UART = 0
Development with debug messages: DEBUG defined, TERMINAL_ENABLED = 1, DEBUG_UART = 0
*/
//#define DEBUG //!< When defined debug messages is output on standard I/O (d_uart is different)
#define TERMINAL_ENABLED 0 //!< DEBUG terminal enabled (0 = disabled, 1 = enabled)
#define DEBUG_UART 4 //!< UART used for debug (0 = port1, 1 = port2, ... 4 = none)
/* \endverbatim */
//#define DEBUG_VM
//#define DEBUG_TRACE_TASK
//#define DEBUG_C_COM
//#define DEBUG_C_INPUT
//#define DEBUG_C_INPUT_DAISYCHAIN
//#define DEBUG_C_INPUT_DATALOG
//#define DEBUG_C_INPUT_FAST_DATALOG
//#define DEBUG_C_MEMORY
//#define DEBUG_C_MEMORY_LOG
//#define DEBUG_C_MEMORY_FILE
//#define DEBUG_C_MEMORY_LOW
//#define DEBUG_C_SOUND
//#define DEBUG_C_UI
//#define DEBUG_D_ANALOG
//#define DEBUG_D_POWER
//#define DEBUG_D_UART
//#define DEBUG_D_UART_ERROR
//#define DEBUG_D_UI
//#define DEBUG_D_SOUND
//#define DEBUG_D_IIC
//#define DEBUG_D_USBDEV
//#define ENABLE_TEST_ON_PORT4
//#define BUFPRINTSIZE 100000
//#define REMEMBER_TO_ENABLE_SAVE_USER_DATA
//#define REMEMBER_TO_FIX_TYPEDATA
//#define DEBUG_TRACE_USB_COMMAND
//#define DEBUG_TRACE_MODE_CHANGE
//#define DEBUG_TRACE_KEY
//#define DEBUG_TRACE_ANGLE
//#define DEBUG_TRACE_US
//#define DEBUG_TRACE_VM
//#define DEBUG_TRACE_DAISYCHAIN
//#define DEBUG_BYTECODE_TIME
//#define DEBUG_TRACE_FREEZE
//#define DEBUG_TRACE_FILENAME
//#define DEBUG_SDCARD
//#define DEBUG_USBSTICK
//#define DEBUG_VIRTUAL_BATT_TEMP
//#define DEBUG_TEMP_SHUTDOWN
//#define DEBUG_BACK_BLOCKED
#define DEBUG_RECHARGEABLE
#ifndef LMS2012_H_
#define LMS2012_H_
// HARDWARE PLATFORM
#define EP2 4 //!< Schematics revision D
#define FINALB 3 //!< Schematics revision B and C
#define FINAL 2 //!< Final prototype
#define SIMULATION 0 //!< LEGO digital simulation
#define PLATFORM_START FINAL //!< Oldest supported hardware (older versions will use this)
#define PLATFORM_END EP2 //!< Newest supported hardware (newer versions will use this)
// Will be removed when not used anymore
#define A4 -1
#define EVALBOARD -2
#define ONE2ONE 1 //!< First real size prototype
#ifdef LEGO_SIMULATION
#define HARDWARE SIMULATION
#else
#ifndef HARDWARE
#define HARDWARE FINAL //!< Actual hardware platform (must be one of above)
#endif
#endif
// Support for module parameter "HwId"
//
// Readout File int PCB
//
// V1.00 10 10 MP (h = home, e = education)
// V0.50 05 5 EP3
// V0.40 04 4 EP2
// V0.30 03 3 EP1 (FINALB) (DEFAULT if file "HwId" not found)
// V0.20 02 2 FINAL
#ifdef HW_ID_SUPPORT
char *HwId = "03";
#define HWID (((HwId[0] - '0') * 10) + (HwId[1] - '0'))
#endif
// FIRMWARE VARIANTS
//#define OLDCALL //!< Don't use optimised sub calls
//#define DISABLE_PRU_UARTS //!< Don't use port 3 and 4 for UART sensors
//#define DISABLE_OLD_COLOR //!< Don't support NXT color sensor
//#define DISABLE_ADC //!< Don't use ADC (no clock EMC test)
//#define ADC_BITBANGING //!< Don't use SPI for a/d converter
//#define DISABLE_DAISYCHAIN
//#define DISABLE_DAISYCHAIN_COM_CALL
//#define DISABLE_FAST_DATALOG_BUFFER
//#define DISABLE_BUMBED
//#define LOG_ASCII
//#define DISABLE_FIQ_IIC
#define UART1_FAKE_INTERRUPT //!< Don't use real interrupt on UART1 (linux prompt)
//#define DISABLE_LOW_VOLTAGE //!< Don't shut down on low voltage
//#define ENABLE_HIGH_CURRENT //!< Don't shut down on high current
//#define DISABLE_LOW_MEMORY //!< Don't check low memory
//#define DISABLE_UART_DATA_ERROR //!< Don't reset UART sensor if timeout or crc error
#define DISABLE_PREEMPTED_VM //!< Don't run VM as preempted
//#define DISABLE_SDCARD_SUPPORT //!< Don't use SD card
#define DISABLE_USBSTICK_SUPPORT //!< Don't use USB stick
//#define ENABLE_PERFORMANCE_TEST //!< Show performance bar in the top line
//#define ENABLE_LOAD_TEST //!< Show integrated current in the top line
//#define ENABLE_MEMORY_TEST //!< Show used memory in the top line
//#define ENABLE_STATUS_TEST
//#define DISABLE_VIRTUAL_BATT_TEMP
//#define DISABLE_SOUND
//#define DISABLE_PAR_ALIGNMENT //!< Disable possibility to align sub call parameter types
//#define DISABLE_NEW_CALL_MUTEX //!< Disable smart object switching after return from non reentrant sub call (enables blocked thread call)
//#define DISABLE_SYSTEM_BYTECODE //!< Disable the use of opSYSTEM command
//#define DISABLE_FILENAME_CHECK //!< Disable "c_memory" filename check
//#define DISABLE_AD_WORD_PROTECT //!< Disable A/D word result protection
#define TESTDEVICE 3
#ifdef Linux_X86
#define DISABLE_DAISYCHAIN
#define DISABLE_DAISYCHAIN_COM_CALL
#endif
#ifndef PCASM
#include <asm/types.h>
#endif
#include "lmstypes.h"
#include "bytecodes.h"
// Hardware
#define OUTPUTS vmOUTPUTS //!< Number of output ports in the system
#define INPUTS vmINPUTS //!< Number of input ports in the system
#define BUTTONS vmBUTTONS //!< Number of buttons in the system
#define LEDS vmLEDS //!< Number of LEDs in the system
#define LCD_WIDTH vmLCD_WIDTH //!< LCD horizontal pixels
#define LCD_HEIGHT vmLCD_HEIGHT //!< LCD vertical pixels
#define TOPLINE_HEIGHT vmTOPLINE_HEIGHT //!< Top line vertical pixels
#define LCD_STORE_LEVELS vmLCD_STORE_LEVELS //!< Store levels
// Software
#define FG_COLOR vmFG_COLOR //!< Foreground color
#define BG_COLOR vmBG_COLOR //!< Background color
#define CHAIN_DEPT vmCHAIN_DEPT //!< Number of bricks in the USB daisy chain (master + slaves)
#define EVENT_BT_PIN vmEVENT_BT_PIN
// Folders
#define MEMORY_FOLDER vmMEMORY_FOLDER
#define PROGRAM_FOLDER vmPROGRAM_FOLDER
#define DATALOG_FOLDER vmDATALOG_FOLDER
#define SDCARD_FOLDER vmSDCARD_FOLDER
#define USBSTICK_FOLDER vmUSBSTICK_FOLDER
// Files
#define DETAILS_FILE vmDETAILS_FILE //!< File containing firmware version
// Extensions
#define EXT_SOUND vmEXT_SOUND //!< Rudolf sound file
#define EXT_GRAPHICS vmEXT_GRAPHICS //!< Rudolf graphics file
#define EXT_BYTECODE vmEXT_BYTECODE //!< Rudolf byte code file
#define EXT_TEXT vmEXT_TEXT //!< Rudolf text file
#define EXT_DATALOG vmEXT_DATALOG //!< Rudolf datalog file
#define EXT_PROGRAM vmEXT_PROGRAM //!< Rudolf program byte code file
#define EXT_CONFIG vmEXT_CONFIG //!< rudolf configuration file
/*! \page system
*
* \verbatim
*/
#define PROJECT "LMS2012"
#define VERS 1.04
#define SPECIALVERS 'H' //!< Minor version (not shown if less than ASCII zero)
#define MAX_PROGRAMS SLOTS //!< Max number of programs (including UI and direct commands) running at a time
#define MAX_BREAKPOINTS 4 //!< Max number of breakpoints (opCODES depends on this value)
#define MAX_LABELS 32 //!< Max number of labels per program
#define MAX_DEVICE_TYPE 127 //!< Highest type number (positive)
#define MAX_VALID_TYPE vmMAX_VALID_TYPE //!< Highest valid type
#define MAX_DEVICE_MODES 8 //!< Max number of modes in one device
#define MAX_DEVICE_DATASETS 8 //!< Max number of data sets in one device
#define MAX_DEVICE_DATALENGTH 32 //!< Max device data length
#define MAX_DEVICE_BUSY_TIME 1200 //!< Max number of mS a device can be busy when read
#define MAX_DEVICE_TYPES ((MAX_DEVICE_TYPE + 1) * MAX_DEVICE_MODES)//!< Max number of different device types and modes (max type data list size)
#define MAX_FRAMES_PER_SEC 10 //!< Max frames per second update in display
#define CACHE_DEEPT 10 //!< Max number of programs cached (in RECENT FILES MENU)
#define MAX_HANDLES 250 //!< Max number of handles to memory pools and arrays in one program
#define MAX_ARRAY_SIZE 1000000000 //!< Max array size
#define MIN_ARRAY_ELEMENTS 0 //!< Min elements in a DATA8 array
#define INSTALLED_MEMORY 6000 //!< Flash allocated to hold user programs/data
#define RESERVED_MEMORY 100 //!< Memory reserve for system [KB]
#define LOW_MEMORY 500 //!< Low memory warning [KB]
#define LOGBUFFER_SIZE 1000 //!< Min log buffer size
#define DEVICE_LOGBUF_SIZE 300 //!< Device log buffer size (black layer buffer)
#define MIN_LIVE_UPDATE_TIME 10 //!< [mS] Min sample time when live update
#define MIN_IIC_REPEAT_TIME 10 //!< [mS] Min IIC device repeat time
#define MAX_IIC_REPEAT_TIME 1000 //!< [mS] Max IIC device repeat time
#define MAX_COMMAND_BYTECODES 64 //!< Max number of byte codes in a debug terminal direct command
#define MAX_COMMAND_LOCALS 64 //!< Max number of bytes allocated for direct command local variables
#define MAX_COMMAND_GLOBALS 1021 //!< Max number of bytes allocated for direct command global variables
#define UI_PRIORITY 20 //!< UI byte codes before switching VM thread
#define C_PRIORITY 200 //!< C call byte codes
#ifndef DISABLE_PREEMPTED_VM
#define PRG_PRIORITY 2000 //!< Prg byte codes before switching VM thread
#else
#define PRG_PRIORITY 200 //!< Prg byte codes before switching VM thread
#endif
#define BUTTON_DEBOUNCE_TIME 30
#define BUTTON_START_REPEAT_TIME 400
#define BUTTON_REPEAT_TIME 200
#define LONG_PRESS_TIME 3000 //!< [mS] Time pressed before long press recognised
#define ADC_REF 5000 //!< [mV] maximal value on ADC
#define ADC_RES 4095 //!< [CNT] maximal count on ADC
#define IN1_ID_HYSTERESIS 50 //!< [mV] half of the span one Id takes up on input connection 1 voltage
#define OUT5_ID_HYSTERESIS 100 //!< [mV] half of the span one Id takes up on output connection 5 voltage
#define DEVICE_UPDATE_TIME 1000000 //!< Min device (sensor) update time [nS]
#define DELAY_TO_TYPEDATA 10000 //!< Time from daisy chain active to upload type data [mS]
#define DAISYCHAIN_MODE_TIME 10 //!< Time for daisy chain change mode [mS]
#define MAX_FILE_HANDLES 64 //!< Max number of down load file handles
#define MIN_HANDLE 3 //!< Min file handle to close
#define ID_LENGTH 7 //!< Id length (BT MAC id) (incl. zero terminator)
#define NAME_LENGTH 12 //!< Name length (not including zero termination)
#define ERROR_BUFFER_SIZE 8 //!< Number of errors in buffer
#define PWM_DEVICE "lms_pwm" //!< PWM device name
#define PWM_DEVICE_NAME "/dev/lms_pwm" //!< PWM device file name
#define MOTOR_DEVICE "lms_motor" //!< TACHO device name
#define MOTOR_DEVICE_NAME "/dev/lms_motor" //!< TACHO device file name
#define ANALOG_DEVICE "lms_analog" //!< ANALOG device name
#define ANALOG_DEVICE_NAME "/dev/lms_analog" //!< ANALOG device file name
#define POWER_DEVICE "lms_power" //!< POWER device name
#define POWER_DEVICE_NAME "/dev/lms_power" //!< POWER device file name
#define DCM_DEVICE "lms_dcm" //!< DCM device name
#define DCM_DEVICE_NAME "/dev/lms_dcm" //!< DCM device file name
#define UI_DEVICE "lms_ui" //!< UI device name
#define UI_DEVICE_NAME "/dev/lms_ui" //!< UI device file name
#define LCD_DEVICE "lms_display" //!< DISPLAY device name
//#define LCD_DEVICE_NAME "/dev/lms_display" //!< DISPLAY device file name
#define LCD_DEVICE_NAME "/dev/fb0" //!< DISPLAY device file name
#define UART_DEVICE "lms_uart" //!< UART device name
#define UART_DEVICE_NAME "/dev/lms_uart" //!< UART device file name
#define USBDEV_DEVICE "lms_usbdev" //!< USB device
#define USBDEV_DEVICE_NAME "/dev/lms_usbdev" //!< USB device
#define USBHOST_DEVICE "lms_usbhost" //!< USB host
#define USBHOST_DEVICE_NAME "/dev/lms_usbhost" //!< USB host
#define SOUND_DEVICE "lms_sound" //!< SOUND device name
#define SOUND_DEVICE_NAME "/dev/lms_sound" //!< SOUND device
#define IIC_DEVICE "lms_iic" //!< IIC device name
#define IIC_DEVICE_NAME "/dev/lms_iic" //!< IIC device
#define BT_DEVICE "lms_bt" //!< BT device name
#define BT_DEVICE_NAME "/dev/lms_bt" //!< BT device
#define UPDATE_DEVICE "lms_update" //!< UPDATE device name
#define UPDATE_DEVICE_NAME "/dev/lms_update" //!< UPDATE device
#define TEST_PIN_DEVICE "lms_tst_pin" //!< TEST pin device name
#define TEST_PIN_DEVICE_NAME "/dev/lms_tst_pin" //!< TEST pin device file name
#define TEST_UART_DEVICE "lms_tst_uart" //!< TEST UART device name
#define TEST_UART_DEVICE_NAME "/dev/lms_tst_uart" //!< TEST UART device file name
#define DIR_DEEPT vmDIR_DEEPT //!< Max directory items allocated
// File
//***********************************************************************************************************************
//! \todo Filename sizes should only use vmPATHSIZE, vmNAMESIZE, vmEXTSIZE and vmFILENAMESIZE
#define FILENAMESIZE vmFILENAMESIZE //!< All inclusive (path, filename, extension and zero termination)
#define FILENAME_SIZE 52 //!< User filename size without extension including zero
#define FOLDERNAME_SIZE 10 //!< Folder name size relative to "lms2012" folder including zero
#define SUBFOLDERNAME_SIZE FILENAME_SIZE //!< Sub folder name size without "/" including zero
#define MAX_FILENAME_SIZE (FOLDERNAME_SIZE + SUBFOLDERNAME_SIZE + FILENAME_SIZE + 5)
//***********************************************************************************************************************
#define TYPEDATE_FILE_NAME "typedata" //!< TypeData filename
#define ICON_FILE_NAME "icon" //!< Icon image filename
#define TEXT_FILE_NAME "text" //!< Text filename
#define DEMO_FILE_NAME "../prjs/BrkProg_SAVE/Demo.rpf"
// Memory
// SD card
#ifdef Linux_X86
#define SDCARD_DEVICE1 "/dev/mmcblk0"
#define SDCARD_DEVICE2 "/dev/mmcblk0p1"
#else
#define SDCARD_DEVICE1 "/dev/mmcblk0"
#define SDCARD_DEVICE2 "/dev/mmcblk0p1"
#endif
#define SDCARD_MOUNT "./mount_sdcard"
#define SDCARD_UNMOUNT "./unmount_sdcard"
// USB stick
#ifndef Linux_X86
#define USBSTICK_DEVICE "/dev/sda"
#else
#define USBSTICK_DEVICE "/dev/sdf1"
#endif
#define USBSTICK_MOUNT "./mount_usbstick"
#define USBSTICK_UNMOUNT "./unmount_usbstick"
/*
#define DEFAULT_PRJS_FOLDER "~/lms2012/prjs" //!< Project folder name without trailing "/"
#define DEFAULT_APPS_FOLDER "~/lms2012/apps" //!< Applet folder name without trailing "/"
#define DEFAULT_TOOLS_FOLDER "~/lms2012/tools" //!< Setting folder name without trailing "/"
#define DEFAULT_SYS_FOLDER "~/lms2012/sys" //!< System folder name without trailing "/"
#define DEFAULT_SETUP_FOLDER "~/lms2012/sys" //!< Setup folder name without trailing "/"
#define DEFAULT_SD_FOLDER "~/lms2012/SD Card" //!< Sd card folder name without trailing "/"
#define DEFAULT_USB_FOLDER "~/lms2012/USB Memory"//!< USB Memory folder name without trailing "/"
*/
#define DEFAULT_FOLDER "ui" //!< Folder containing the first small programs
#define DEFAULT_UI "ui" //!< Default user interface
#define DEFAULT_VOLUME vmDEFAULT_VOLUME
#define DEFAULT_SLEEPMINUTES vmDEFAULT_SLEEPMINUTES
#define COM_CMD_DEVICE_NAME USBDEV_DEVICE_NAME //!< USB HID command pipe device file name
/*! \endverbatim
*
*/
/*! \page powermanagement Power Management
*
* This section describes various constants used in the power management
*
*
*\n
* <hr size="1"/>
* <b>Battery Indicator</b>
*\n
* <hr size="1"/>
* \verbatim
*/
#define BATT_INDICATOR_HIGH 7500 //!< Battery indicator high [mV]
#define BATT_INDICATOR_LOW 6200 //!< Battery indicator low [mV]
#define ACCU_INDICATOR_HIGH 7500 //!< Rechargeable battery indicator high [mV]
#define ACCU_INDICATOR_LOW 7100 //!< Rechargeable battery indicator low [mV]
/*! \endverbatim
* \subpage pmbattind
*\n
* <hr size="1"/>
* <b>Low Voltage Shutdown</b>
*\n
* <hr size="1"/>
* \verbatim
*/
#define LOW_VOLTAGE_SHUTDOWN_TIME 10000 //!< Time from shutdown lower limit to shutdown [mS]
#define BATT_WARNING_HIGH 6.2 //!< Battery voltage warning upper limit [V]
#define BATT_WARNING_LOW 5.5 //!< Battery voltage warning lower limit [V]
#define BATT_SHUTDOWN_HIGH 5.5 //!< Battery voltage shutdown upper limit [V]
#define BATT_SHUTDOWN_LOW 4.5 //!< Battery voltage shutdown lower limit [V]
#define ACCU_WARNING_HIGH 7.1 //!< Rechargeable battery voltage warning upper limit [V]
#define ACCU_WARNING_LOW 6.5 //!< Rechargeable battery voltage warning lower limit [V]
#define ACCU_SHUTDOWN_HIGH 6.5 //!< Rechargeable battery voltage shutdown upper limit [V]
#define ACCU_SHUTDOWN_LOW 6.0 //!< Rechargeable battery voltage shutdown lower limit [V]
/*! \endverbatim
* \subpage pmbattsd
*\n
*/
#ifdef ENABLE_HIGH_CURRENT
/*! \page powermanagement
*
* <hr size="1"/>
* <b>High Load Shutdown</b>
*\n
* <hr size="1"/>
* \verbatim
*/
#define LOAD_SHUTDOWN_FAIL 4.0 //!< Current limit for instantly shutdown [A]
#define LOAD_SHUTDOWN_HIGH 3.0 //!< Current limit for integrated current shutdown [A*S]
#define LOAD_BREAK_EVEN 1.75 //!< Current limit for integrated current break even [A*S]
#define LOAD_SLOPE_UP 0.2 //!< Current slope when current is above break even [A/S]
#define LOAD_SLOPE_DOWN 0.1 //!< Current slope when current is below break even [A/S]
/*! \endverbatim
* \subpage pmloadsd
*\n
*/
#endif
#ifndef DISABLE_VIRTUAL_BATT_TEMP
/*! \page powermanagement
*
* <hr size="1"/>
* <b>High Temperature Shutdown</b>
*\n
* <hr size="1"/>
* \verbatim
*/
#define TEMP_SHUTDOWN_FAIL 45.0 //!< Temperature rise before fail shutdown [C]
#define TEMP_SHUTDOWN_WARNING 40.0 //!< Temperature rise before warning [C]
/*! \endverbatim
* \subpage pmtempsd
*\n
*/
#endif
#define UPDATE_TIME1 2 //!< Update repeat time1 [mS]
#define UPDATE_TIME2 10 //!< Update repeat time2 [mS]
#define UPDATE_MEMORY 200 //!< Update memory size [mS]
#define UPDATE_SDCARD 500 //!< Update sdcard size [mS]
#define UPDATE_USBSTICK 500 //!< Update usbstick size [mS]
// Per start of (polution) defines
#define MAX_SOUND_DATA_SIZE 250
#define SOUND_CHUNK 250
#define SOUND_ADPCM_CHUNK 125
#define SOUND_MASTER_CLOCK 132000000
#define SOUND_TONE_MASTER_CLOCK 1031250
#define SOUND_MIN_FRQ 250
#define SOUND_MAX_FRQ 10000
#define SOUND_MAX_LEVEL 8
#define SOUND_FILE_BUFFER_SIZE SOUND_CHUNK + 2 // 12.8 mS @ 8KHz
#define SOUND_BUFFER_COUNT 3
#define SOUND_FILE_FORMAT_NORMAL 0x0100 // RSO-file
#define SOUND_FILE_FORMAT_COMPRESSED 0x0101 // RSO-file compressed
// Per end of defines
/*!
*
* \n
*/
#define VtoC(V) ((UWORD)((V * ADC_RES) / ADC_REF))
#define CtoV(C) ((UWORD)((C * ADC_REF) / ADC_RES))
#define MtoV(M) ((UWORD)((M * ADC_REF * 100) / (ADC_RES * 52)))
#define KB 1024
enum
{
FALSE = 0,
TRUE = 1,
};
// Reserved device types
typedef enum
{
// TYPE_KEEP = 0, //!< Type value that won't change type in byte codes
TYPE_NXT_TOUCH = 1, //!< Device is NXT touch sensor
TYPE_NXT_LIGHT = 2, //!< Device is NXT light sensor
TYPE_NXT_SOUND = 3, //!< Device is NXT sound sensor
TYPE_NXT_COLOR = 4, //!< Device is NXT color sensor
TYPE_TACHO = 7, //!< Device is a tacho motor
TYPE_MINITACHO = 8, //!< Device is a mini tacho motor
TYPE_NEWTACHO = 9, //!< Device is a new tacho motor
TYPE_THIRD_PARTY_START = 50,
TYPE_THIRD_PARTY_END = 99,
TYPE_IIC_UNKNOWN = 100,
TYPE_NXT_TEST = 101, //!< Device is a NXT ADC test sensor
TYPE_NXT_IIC = 123, //!< Device is NXT IIC sensor
TYPE_TERMINAL = 124, //!< Port is connected to a terminal
TYPE_UNKNOWN = 125, //!< Port not empty but type has not been determined
TYPE_NONE = 126, //!< Port empty or not available
TYPE_ERROR = 127, //!< Port not empty and type is invalid
}
TYPE;
/*! \page connections Connections
*
* \anchor connectiontypes
*
* Following defines sets the input and output port connection type\n
*
* These connection types are evaluated in the DCM driver \ref DcmDriver "Device Detection Manager Driver"
*
* \verbatim
*/
typedef enum
{
CONN_UNKNOWN = 111, //!< Connection is fake (test)
CONN_DAISYCHAIN = 117, //!< Connection is daisy chained
CONN_NXT_COLOR = 118, //!< Connection type is NXT color sensor
CONN_NXT_DUMB = 119, //!< Connection type is NXT analog sensor
CONN_NXT_IIC = 120, //!< Connection type is NXT IIC sensor
CONN_INPUT_DUMB = 121, //!< Connection type is LMS2012 input device with ID resistor
CONN_INPUT_UART = 122, //!< Connection type is LMS2012 UART sensor
CONN_OUTPUT_DUMB = 123, //!< Connection type is LMS2012 output device with ID resistor
CONN_OUTPUT_INTELLIGENT = 124, //!< Connection type is LMS2012 output device with communication
CONN_OUTPUT_TACHO = 125, //!< Connection type is LMS2012 tacho motor with series ID resistance
CONN_NONE = 126, //!< Port empty or not available
CONN_ERROR = 127, //!< Port not empty and type is invalid
}
CONN;
/*\endverbatim
*
* \n
*/
/*! \page objectstatus Object Status
*
\verbatim
Image load -> Initialize all objects
Initialize -> if TriggerCount == 0 -> RUNNING (VMTHREAD)
else -> STOPPED (waiting for 1. trigger)
1.Trigger -> Initialise -> WAITING
Triggered -> Enqueue -> RUNNING
Done -> Dequeue -> STOPPED
Program start
|
v
STOPPED -------> WAITING -------> RUNNING --------,
^ 1.trig/ n.trig/ done/ |
| Reset+Enqueue Dequeue |
| |
'----------------------------------------------'
\endverbatim
*/
/*! \enum DSPSTAT
*
* Dispatch status values
*/
typedef enum
{
NOBREAK = 0x0100, //!< Dispatcher running (looping)
STOPBREAK = 0x0200, //!< Break because of program stop
SLEEPBREAK = 0x0400, //!< Break because of sleeping
INSTRBREAK = 0x0800, //!< Break because of opcode break
BUSYBREAK = 0x1000, //!< Break because of waiting for completion
PRGBREAK = 0x2000, //!< Break because of program break
USERBREAK = 0x4000, //!< Break because of user decision
FAILBREAK = 0x8000 //!< Break because of fail
}
DSPSTAT;
typedef void (*PRIM)(void); //!< Prototype for all byte codes
/*! \page memorylayout Memory Layout
*
* RAM layout
*
*- GlobalVariables (aligned)
*
*- ObjectPointerList (aligned)
*
*- OBJ (aligned)
* - Ip (4 bytes)
* - Status (2 bytes)
* - TriggerCount/CallerId (2 bytes)
* - Local (0..MAX Bytes)\n
*
*/
/*! \struct OBJ
* Object data is used to hold the variables used for an object (allocated at image load time)
*/
typedef struct // Object
{
IP Ip; //!< Object instruction pointer
LP pLocal; //!< Local variable pointer
#ifndef DISABLE_NEW_CALL_MUTEX
UBYTE ObjStatus; //!< Object status
UBYTE Blocked;
#else
UWORD ObjStatus; //!< Object status
#endif
union //!< Different meaning for SUBCALL and BLOCKS
{
OBJID CallerId; //!< Caller id used for SUBCALL to save object id to return to
TRIGGER TriggerCount; //!< Trigger count used by BLOCK's trigger logic
}u;
VARDATA Local[]; //!< Poll of bytes used for local variables
}
OBJ;
/*! \struct BRKP
* Breakpoint data hold information used for breakpoint
*/
typedef struct
{
IMINDEX Addr; //!< Offset to breakpoint address from image start
OP OpCode; //!< Saved substituted opcode
}
BRKP;
/*! \struct PRG
* Program data hold information about a program
*/
typedef struct
{
ULONG InstrCnt; //!< Instruction counter used for performance analyses
ULONG InstrTime; //!< Instruction time used for performance analyses
ULONG StartTime; //!< Program start time [mS]
ULONG RunTime; //!< Program run time [uS]
IP pImage; //!< Pointer to start of image
GP pData; //!< Pointer to start of data
GP pGlobal; //!< Pointer to start of global bytes
OBJHEAD* pObjHead; //!< Pointer to start of object headers
OBJ** pObjList; //!< Pointer to object pointer list
IP ObjectIp; //!< Working object Ip
LP ObjectLocal; //!< Working object locals
OBJID Objects; //!< No of objects in image
OBJID ObjectId; //!< Active object id
OBJSTAT Status; //!< Program status
OBJSTAT StatusChange; //!< Program status change
RESULT Result; //!< Program result (OK, BUSY, FAIL)
BRKP Brkp[MAX_BREAKPOINTS]; //!< Storage for breakpoint logic
LABEL Label[MAX_LABELS]; //!< Storage for labels
UWORD Debug; //!< Debug flag
DATA8 Name[FILENAME_SIZE];
}
PRG;
#define TYPE_NAME_LENGTH 11
#define SYMBOL_LENGTH 4 //!< Symbol leng th (not including zero)
/*! \struct TYPES
* Device type data
*/
typedef struct // if data type changes - remember to change "cInputTypeDataInit" !
{
SBYTE Name[TYPE_NAME_LENGTH + 1]; //!< Device name
DATA8 Type; //!< Device type
DATA8 Connection;
DATA8 Mode; //!< Device mode
DATA8 DataSets;
DATA8 Format;
DATA8 Figures;
DATA8 Decimals;
DATA8 Views;
DATAF RawMin; //!< Raw minimum value (e.c. 0.0)
DATAF RawMax; //!< Raw maximum value (e.c. 1023.0)
DATAF PctMin; //!< Percent minimum value (e.c. -100.0)
DATAF PctMax; //!< Percent maximum value (e.c. 100.0)
DATAF SiMin; //!< SI unit minimum value (e.c. -100.0)
DATAF SiMax; //!< SI unit maximum value (e.c. 100.0)
UWORD InvalidTime; //!< mS from type change to valid data
UWORD IdValue; //!< Device id value (e.c. 0 ~ UART)
DATA8 Pins; //!< Device pin setup
SBYTE Symbol[SYMBOL_LENGTH + 1]; //!< SI unit symbol
UWORD Align;
}
TYPES;
#define TYPE_PARAMETERS 19 //!< Number of members in the structure above
#define MAX_DEVICE_INFOLENGTH 54 //!< Number of bytes in the structure above (can not be changed)
/*!\enum ERR
*
* Describes error numbers
*/
typedef enum
{
TOO_MANY_ERRORS_TO_BUFFER,
TYPEDATA_TABEL_FULL,
TYPEDATA_FILE_NOT_FOUND,
ANALOG_DEVICE_FILE_NOT_FOUND,
ANALOG_SHARED_MEMORY,
UART_DEVICE_FILE_NOT_FOUND,
UART_SHARED_MEMORY,
IIC_DEVICE_FILE_NOT_FOUND,
IIC_SHARED_MEMORY,
DISPLAY_SHARED_MEMORY,
UI_SHARED_MEMORY,
UI_DEVICE_FILE_NOT_FOUND,
LCD_DEVICE_FILE_NOT_FOUND,
OUTPUT_SHARED_MEMORY,
COM_COULD_NOT_OPEN_FILE,
COM_NAME_TOO_SHORT,
COM_NAME_TOO_LONG,
COM_INTERNAL,
VM_INTERNAL,
VM_PROGRAM_VALIDATION,
VM_PROGRAM_NOT_STARTED,
VM_PROGRAM_FAIL_BREAK,
VM_PROGRAM_INSTRUCTION_BREAK,
VM_PROGRAM_NOT_FOUND,
SOUND_DEVICE_FILE_NOT_FOUND,
SOUND_SHARED_MEMORY,
FILE_OPEN_ERROR,
FILE_READ_ERROR,
FILE_WRITE_ERROR,
FILE_CLOSE_ERROR,
FILE_GET_HANDLE_ERROR,
FILE_NAME_ERROR,
USB_SHARED_MEMORY,
OUT_OF_MEMORY,
ERRORS
}
ERR;
// INTERFACE FOR SHARED LIBRARIES
extern void PrimParAdvance(void); // Dummy get parameter
extern void* PrimParPointer(void); // Get pointer to primitives and system calls parameters
extern IP GetImageStart(void); // Get pointer to start of image
extern void SetDispatchStatus(DSPSTAT Status); // Set dispatch status (result from executing byte code)
extern void SetInstructions(ULONG Instructions); // Set number of instructions before VMThread change
extern PRGID CurrentProgramId(void); // Get current program id
extern OBJSTAT ProgramStatus(PRGID PrgId); // Get program status
extern OBJSTAT ProgramStatusChange(PRGID PrgId); // Get program status change
extern void ProgramEnd(PRGID PrgId);
extern OBJID CallingObjectId(void); // Get calling objects id
extern void AdjustObjectIp(IMOFFS Value); // Adjust IP
extern IP GetObjectIp(void); // Get IP
extern void SetObjectIp(IP Ip); // Set IP
extern ULONG GetTimeUS(void); // Get uS
extern ULONG GetTimeMS(void); // Get mS
extern ULONG GetTime(void); // Get actual program time
extern ULONG CurrentObjectIp(void); // Get current object ip
extern void VmPrint(char *pString); // print string
extern void SetTerminalEnable(DATA8 Value); // Terminal enable/disable
extern DATA8 GetTerminalEnable(void); // Get terminal enable state
extern void GetResourcePath(char *pString,DATA8 MaxLength);// Get resource path
extern void* VmMemoryResize(HANDLER Handle,DATA32 Elements);
extern void SetVolumePercent(DATA8 Volume);
extern DATA8 GetVolumePercent(void);
extern void SetSleepMinutes(DATA8 Minutes);
extern DATA8 GetSleepMinutes(void);
extern DSPSTAT ExecuteByteCode(IP pByteCode,GP pGlobals,LP pLocals); // Execute byte code stream (C-call)
extern DATA8 CheckSdcard(DATA8 *pChanged,DATA32 *pTotal,DATA32 *pFree,DATA8 Force);
extern DATA8 CheckUsbstick(DATA8 *pChanged,DATA32 *pTotal,DATA32 *pFree,DATA8 Force);
extern void SetUiUpdate(void);
extern RESULT ValidateChar(DATA8 *pChar,DATA8 Set);
extern RESULT ValidateString(DATA8 *pString,DATA8 Set);
extern ERR LogErrorGet(void);
#ifdef BUFPRINTSIZE
extern void BufPrint(char Cmd,char *pFormat, ...);
#endif
#define ERR_STRING_SIZE vmERR_STRING_SIZE // Inclusive zero termination
extern void LogErrorNumber(ERR Error); // Log error number
extern DATA8 LogErrorNumberExists(ERR Error);
#ifndef DISABLE_OLD_COLOR
#define COLORS 4
#define CALPOINTS 3
/*! \page NxtColorMemory
*
* <b> Shared Memory </b>
*
* <hr size="1"/>
*
*
* \verbatim
*/
typedef struct
{
ULONG Calibration[CALPOINTS][COLORS];
UWORD CalLimits[CALPOINTS - 1];
UWORD Crc;
UWORD ADRaw[COLORS];
UWORD SensorRaw[COLORS];
}
COLORSTRUCT;
/*\endverbatim
*
* \n
*/
#endif
// INTERFACE BETWEEN SHARED LIBRARIES AND MODULES
/*! \page AnalogModuleMemory
* <b> Shared Memory </b>
*
* <hr size="1"/>
*
* It is possible to get a pointer to the raw analogue values for use in userspace
* this pointer will point to a struct and the layout is following:
*
* \verbatim
*/
typedef struct
{
DATA16 InPin1[INPUTS]; //!< Analog value at input port connection 1
DATA16 InPin6[INPUTS]; //!< Analog value at input port connection 6
DATA16 OutPin5[OUTPUTS]; //!< Analog value at output port connection 5
DATA16 BatteryTemp; //!< Battery temperature
DATA16 MotorCurrent; //!< Current flowing to motors
DATA16 BatteryCurrent; //!< Current flowing from the battery
DATA16 Cell123456; //!< Voltage at battery cell 1, 2, 3,4, 5, and 6
#ifndef DISABLE_FAST_DATALOG_BUFFER
DATA16 Pin1[INPUTS][DEVICE_LOGBUF_SIZE]; //!< Raw value from analog device
DATA16 Pin6[INPUTS][DEVICE_LOGBUF_SIZE]; //!< Raw value from analog device
UWORD Actual[INPUTS];
UWORD LogIn[INPUTS];
UWORD LogOut[INPUTS];
#endif
#ifndef DISABLE_OLD_COLOR
COLORSTRUCT NxtCol[INPUTS];
#endif
DATA16 OutPin5Low[OUTPUTS]; //!< Analog value at output port connection 5 when connection 6 is low
DATA8 Updated[INPUTS];
DATA8 InDcm[INPUTS]; //!< Input port device types
DATA8 InConn[INPUTS];
DATA8 OutDcm[OUTPUTS]; //!< Output port device types
DATA8 OutConn[OUTPUTS];
#ifndef DISABLE_PREEMPTED_VM
UWORD PreemptMilliSeconds;
#endif
}
ANALOG;
/*\endverbatim
*
* \n
*/
/*! \page UartModuleMemory
*
* <b> Shared Memory </b>
*
* <hr size="1"/>
*
* It is possible to get a pointer to the uart values for use in userspace
* this pointer will point to a struct and the layout is following:
*
* \verbatim
*/
#define UART_DATA_LENGTH MAX_DEVICE_DATALENGTH
#define UART_BUFFER_SIZE 64
typedef struct
{
TYPES TypeData[INPUTS][MAX_DEVICE_MODES]; //!< TypeData
#ifndef DISABLE_FAST_DATALOG_BUFFER
UWORD Repeat[INPUTS][DEVICE_LOGBUF_SIZE];
DATA8 Raw[INPUTS][DEVICE_LOGBUF_SIZE][UART_DATA_LENGTH]; //!< Raw value from UART device
UWORD Actual[INPUTS];
UWORD LogIn[INPUTS];
#else
DATA8 Raw[INPUTS][UART_DATA_LENGTH]; //!< Raw value from UART device
#endif
DATA8 Status[INPUTS]; //!< Status
DATA8 Output[INPUTS][UART_DATA_LENGTH]; //!< Bytes to UART device
DATA8 OutputLength[INPUTS];
}
UART;
/*\endverbatim
*
* \n
*/
#define UART_PORT_CHANGED 0x01 //!< Input port changed
#define UART_DATA_READY 0x08 //!< Data is ready
#define UART_WRITE_REQUEST 0x10 //!< Write request
typedef struct
{
DATA8 Connection[INPUTS];
DATA8 Type[INPUTS];
DATA8 Mode[INPUTS];
}
DEVCON;
typedef struct
{
TYPES TypeData;
DATA8 Port;
DATA8 Mode;
}
UARTCTL;
#define UART_SET_CONN _IOWR('u',0,DEVCON)
#define UART_READ_MODE_INFO _IOWR('u',1,UARTCTL)
#define UART_NACK_MODE_INFO _IOWR('u',2,UARTCTL)
#define UART_CLEAR_CHANGED _IOWR('u',3,UARTCTL)
/* leJOS additions for RAW UART access */
typedef struct
{
DATA32 Port;
DATA32 BitRate;
}
UARTCONFIG;
#define UART_SET_CONFIG _IOWR('u',4,UARTCONFIG)
#define UART_RAW_READ _IOWR('u',5,void *)
#define UART_RAW_WRITE _IOWR('u',6,void *)
#define UART_MODE_RAW ((DATA8) -1)
/*! \page IicModuleMemory
*
* <b> Shared Memory </b>
*
* <hr size="1"/>
*
* It is possible to get a pointer to the iic values for use in userspace
* this pointer will point to a struct and the layout is following:
*
* \verbatim
*/
#define IIC_DATA_LENGTH MAX_DEVICE_DATALENGTH
#define IIC_NAME_LENGTH 8
typedef struct
{
TYPES TypeData[INPUTS][MAX_DEVICE_MODES]; //!< TypeData
#ifndef DISABLE_FAST_DATALOG_BUFFER
UWORD Repeat[INPUTS][DEVICE_LOGBUF_SIZE];
DATA8 Raw[INPUTS][DEVICE_LOGBUF_SIZE][IIC_DATA_LENGTH]; //!< Raw value from IIC device
UWORD Actual[INPUTS];
UWORD LogIn[INPUTS];
#else
DATA8 Raw[INPUTS][IIC_DATA_LENGTH]; //!< Raw value from IIC device
#endif
DATA8 Status[INPUTS]; //!< Status
DATA8 Changed[INPUTS];
DATA8 Output[INPUTS][IIC_DATA_LENGTH]; //!< Bytes to IIC device
DATA8 OutputLength[INPUTS];
}
IIC;
/*\endverbatim
*
* \n
*/
#define IIC_PORT_CHANGED 0x01 //!< Input port changed
#define IIC_DATA_READY 0x08 //!< Data is ready
#define IIC_WRITE_REQUEST 0x10 //!< Write request
typedef struct
{
TYPES TypeData;
DATA8 Port;
DATA8 Mode;
}
IICCTL;
typedef struct
{
RESULT Result;
DATA8 Port;
DATA8 Repeat;
DATA16 Time;
DATA8 WrLng;
DATA8 WrData[IIC_DATA_LENGTH];
DATA8 RdLng;
DATA8 RdData[IIC_DATA_LENGTH];
}
IICDAT;
typedef struct
{
DATA8 Port;
DATA16 Time;
DATA8 Type;
DATA8 Mode;
DATA8 Manufacturer[IIC_NAME_LENGTH + 1];
DATA8 SensorType[IIC_NAME_LENGTH + 1];
DATA8 SetupLng;
ULONG SetupString;
DATA8 PollLng;
ULONG PollString;
DATA8 ReadLng;
}
IICSTR;
#define IIC_SET_CONN _IOWR('i',2,DEVCON)
#define IIC_READ_TYPE_INFO _IOWR('i',3,IICCTL)
#define IIC_SETUP _IOWR('i',5,IICDAT)
#define IIC_SET _IOWR('i',6,IICSTR)
#define TST_PIN_LENGTH 8
typedef struct
{
DATA8 Port;
DATA8 Length;
DATA8 String[TST_PIN_LENGTH + 1];
}
TSTPIN;
#define TST_PIN_ON _IOWR('t',1,TSTPIN)
#define TST_PIN_OFF _IOWR('t',2,TSTPIN)
#define TST_PIN_READ _IOWR('t',3,TSTPIN)
#define TST_PIN_WRITE _IOWR('t',4,TSTPIN)
#define TST_UART_LENGTH UART_BUFFER_SIZE
typedef struct
{
DATA32 Bitrate;
DATA8 Port;
DATA8 Length;
DATA8 String[TST_UART_LENGTH];
}
TSTUART;
#define TST_UART_ON _IOWR('t',5,TSTUART)
#define TST_UART_OFF _IOWR('t',6,TSTUART)
#define TST_UART_EN _IOWR('t',7,TSTUART)
#define TST_UART_DIS _IOWR('t',8,TSTUART)
#define TST_UART_READ _IOWR('t',9,TSTUART)
#define TST_UART_WRITE _IOWR('t',10,TSTUART)
/*! \page UiModuleMemory
*
* <b> Shared Memory </b>
*
* <hr size="1"/>
*
* It is possible to get a pointer to the ui button states for use in userspace
* this pointer will point to a struct and the layout is following:
*
* \verbatim
*/
typedef struct
{
DATA8 Pressed[BUTTONS]; //!< Pressed status
}
UI;
/*\endverbatim
*
* \n
*/
#define LCD_BUFFER_SIZE (((LCD_WIDTH + 7) / 8) * LCD_HEIGHT)
#define LCD_TOPLINE_SIZE (((LCD_WIDTH + 7) / 8) * (TOPLINE_HEIGHT + 1))
/*! \page DisplayModuleMemory
*
* <b> Shared Memory </b>
*
* <hr size="1"/>
*
* It is possible to get a pointer to the display memory for use in userspace
* this pointer will point to a frame buffer as follows:
*
* \verbatim
*/
typedef struct
{
UBYTE Lcd[LCD_BUFFER_SIZE];
}
LCD;
/*\endverbatim
*
* \n
*/
/*! \page SoundModuleMemory
*
* <b> Shared Memory </b>
*
* <hr size="1"/>
*
* It is possible to get a pointer to the sound ready flag for use in userspace
* this pointer will point to a struct and the layout is following:
*
* \verbatim
*/
typedef struct
{
DATA8 Status; //!< Status
}
SOUND;
/*\endverbatim
*
* \n
*/
/*! \page UsbModuleMemory
*
* <b> Shared Memory </b>
*
* <hr size="1"/>
*
* It is possible to get a pointer to the USB Speed (FULL or HIGH) for use in userspace
* this pointer will point to a struct and the layout is following:
*
* \verbatim
*/
enum {
FULL_SPEED,
HIGH_SPEED
};
typedef struct
{
DATA8 Speed;
}
USB_SPEED;
/*\endverbatim
*
* \n
*/
/*! \page VmNonvolatileMemory
*
* <b> VM non volatile Memory </b>
*
* <hr size="1"/>
*
* This struct will be loaded at start up and save when closing down VM
*
* \verbatim
*/
typedef struct
{
DATA8 VolumePercent; //!< System default volume [0..100%]
DATA8 SleepMinutes; //!< System sleep [0..120min] (0 = ~)
}
NONVOL;
/*\endverbatim
*
* \n
*/
/*
* Motor/OUTPUT Typedef
*/
typedef struct
{
SLONG TachoCounts;
SBYTE Speed;
SLONG TachoSensor;
}MOTORDATA;
typedef struct
{
DATA8 Cmd;
DATA8 Nos;
DATA8 Power;
DATA32 Step1;
DATA32 Step2;
DATA32 Step3;
DATA8 Brake;
} STEPPOWER;
typedef struct
{
DATA8 Cmd;
DATA8 Nos;
DATA8 Power;
DATA32 Time1;
DATA32 Time2;
DATA32 Time3;
DATA8 Brake;
} TIMEPOWER;
typedef struct
{
DATA8 Cmd;
DATA8 Nos;
DATA8 Speed;
DATA32 Step1;
DATA32 Step2;
DATA32 Step3;
DATA8 Brake;
} STEPSPEED;
typedef struct
{
DATA8 Cmd;
DATA8 Nos;
DATA8 Speed;
DATA32 Time1;
DATA32 Time2;
DATA32 Time3;
DATA8 Brake;
} TIMESPEED;
typedef struct
{
DATA8 Cmd;
DATA8 Nos;
DATA8 Speed;
DATA16 Turn;
DATA32 Step;
DATA8 Brake;
} STEPSYNC;
typedef struct
{
DATA8 Cmd;
DATA8 Nos;
DATA8 Speed;
DATA16 Turn;
DATA32 Time;
DATA8 Brake;
} TIMESYNC;
/*
* End of Motor/OUTPUT Typedef
*/
#define PRINTBUFFERSIZE 160
typedef struct
{
NONVOL NonVol;
DATA8 FirstProgram[MAX_FILENAME_SIZE];
char PrintBuffer[PRINTBUFFERSIZE + 1];
DATA8 TerminalEnabled;
PRGID FavouritePrg;
PRGID ProgramId; //!< Program id running
PRG Program[MAX_PROGRAMS]; //!< Program[0] is the UI byte codes running
ULONG InstrCnt; //!< Instruction counter (performance test)
IP pImage; //!< Pointer to start of image
GP pGlobal; //!< Pointer to start of global bytes
OBJHEAD* pObjHead; //!< Pointer to start of object headers
OBJ** pObjList; //!< Pointer to object pointer list
IP ObjectIp; //!< Working object Ip
LP ObjectLocal; //!< Working object locals
OBJID Objects; //!< No of objects in image
OBJID ObjectId; //!< Active object id
IP ObjIpSave;
GP ObjGlobalSave;
LP ObjLocalSave;
DSPSTAT DispatchStatusSave;
ULONG PrioritySave;
long TimerDataSec;
long TimerDatanSec;
UWORD Debug;
UWORD Test;
UWORD RefCount;
ULONG TimeuS;
ULONG OldTime1;
ULONG OldTime2;
ULONG NewTime;
#ifdef ENABLE_PERFORMANCE_TEST
ULONG PerformTimer;
DATAF PerformTime;
#endif
DSPSTAT DispatchStatus; //!< Dispatch status
ULONG Priority; //!< Object priority
ULONG Value;
HANDLER Handle;
ERR Errors[ERROR_BUFFER_SIZE];
UBYTE ErrorIn;
UBYTE ErrorOut;
DATA32 MemorySize;
DATA32 MemoryFree;
ULONG MemoryTimer;
#ifndef DISABLE_SDCARD_SUPPORT
DATA32 SdcardSize;
DATA32 SdcardFree;
ULONG SdcardTimer;
DATA8 SdcardOk;
#endif
#ifndef DISABLE_USBSTICK_SUPPORT
DATA32 UsbstickSize;
DATA32 UsbstickFree;
ULONG UsbstickTimer;
DATA8 UsbstickOk;
#endif
LCD LcdBuffer; //!< Copy of last LCD update
DATA8 LcdUpdated; //!< LCD updated
ANALOG Analog;
ANALOG *pAnalog;
int AdcFile;
#ifdef ENABLE_STATUS_TEST
DATA8 Status;
#endif
#if (HARDWARE == SIMULATION)
class NXT * nxt;
#endif
}GLOBALS;
#if (HARDWARE == SIMULATION)
extern GLOBALS * gInstance;
#define VMInstance (*gInstance)
RESULT mSchedInit();
RESULT mSchedCtrl();
RESULT mSchedExit();
void setInstance(GLOBALS * _Instance);
GLOBALS * getInstance();
#else
extern GLOBALS VMInstance;
#endif
#endif /* LMS2012_H_ */