Digi BL1800 user manual Advantages of Cooperative Multitasking

Page 54

used to collect some operations that are helpful to do once on every pass through the loop. Place the cursor on this function name BigLoopTop() and hit <Ctrl-H>to learn more.

The statement at (3) waits for a time delay, in this case 200 ms. The costatement is being executed on each pass through the big loop. When a waitfor condition is encountered the first time, the current value of MS_TIMER is saved and then on each subsequent pass the saved value is compared to the current value. If a waitfor condition is not encoun- tered, then a jump is made to the end of the costatement (4), and on the next pass of the loop, when the execution thread reaches the beginning of the costatement, execution passes directly to the waitfor statement. Once 200 ms has passed, the statement after the waitfor is executed. The costatement has the property that it can wait for long periods of time, but not use a lot of execution time. Each costatement is a little program with its own statement pointer that advances in response to conditions. On each pass through the big loop, as little as one statement in the costatement is executed, starting at the current posi- tion of the costatement’s statement pointer. Consult the Dynamic C User’s Manual for more details.

The second costatement in the program debounces the switch and maintains the variable vswitch. Debouncing is performed by making sure that the switch is either on or off for a long enough period of time to ensure that high-frequency electrical hash generated when the switch contacts open or close does not affect the state of the switch. The abort state- ment is illustrated at (5). If executed, the internal statement pointer is set back to the first statement within the costatement, and a jump to the closing brace of the costatement is made.

At (6) a use for a shadow register is illustrated. A shadow register is used to keep track of the contents of an I/O port that is write only - it can’t be read back. If every time a write is made to the port the same bits are set in the shadow register, then the shadow register has the same data as the port register. In this case a test is made to see the state of the LED and make it agree with the state of vswitch. This test is not strictly necessary, the output regis- ter could be set every time to agree with vswitch, but it is placed here to illustrate the concept of a shadow register.

To illustrate the use of snooping, use the watch window to observe vswitch while the program is running. Add the variable vswitch to the list of watch expressions. Then tog- gle vswitch and the LED. Then type <Ctrl-U>to observe vswitch again.

4.3.1 Advantages of Cooperative Multitasking

Cooperative multitasking, as implemented with language extensions, has the advantage of being intuitive. Unlike preemptive multitasking, variables can be shared between different tasks without having to take elaborate precautions. Sharing variables between tasks is the greatest cause of bugs in programs that use preemptive multitasking. It might seem that the biggest problem would be response time because of the big loop time becoming long as the program grows. Our solution for that is a device caused slicing that is further described in the Dynamic C User’s Manual.

50

Jackrabbit (BL1800)

Image 54
Contents Jackrabbit BL1800 Programmable Single-Board ComputerTrademarks Digi International IncTable of Contents Index Schematics Features IntroductionJackrabbit Features Development and Evaluation ToolsHow to Use This Manual Additional Product InformationOnline Documentation CE Compliance ImmunityEmissions Safety Design Guidelines GeneralInterfacing the Jackrabbit to Other Devices Jackrabbit BL1800 Development Kit Contents Getting StartedDevelopment Hardware Connections Board Attach Jackrabbit to Prototyping BoardConnect Programming Cable Assemble AC AdapterConnect Power Installing Dynamic C Troubleshooting Run a Sample ProgramWhere Do I Go From Here? Real-Time ClockTechnical Support Subsystems BL1800Jackrabbit Pinouts HeadersDigital Inputs/Outputs Digital InputsDigital Outputs HV3 Sourcing OutputConfigurable High-Current Output Bidirectional I/O Changing HV3 to a Sinking OutputSchematic Diagram of A/D Converter A/D ConverterJackrabbit BL1800 Schematic Diagram of D/A Converters D/A ConvertersV ⋅ 1 e RC 1 DA1Typical DA1 Voltages for Various Duty Cycles 2 DA0 Typical DA0 Voltages for Various Duty CyclesUser’s Manual Serial Communication 1 RS-2322 RS-485 Ground recommended Programming Port 485 R16User’s Manual Changing Between Program Mode and Run Mode Programming CableMemory SramFlash Eprom Other Hardware External InterruptsClock Doubler Spectrum Spreader Jackrabbit BL1800 Software Reference An Overview of Dynamic CJackrabbit BL1800 Sample Programs Jackrabbit Sample ProgramsDEMOJR1.C Sample Program DEMOJR1.CSingle-Stepping Watch Expression Break PointSummary of Features Editing the ProgramWatching Variables Dynamically User’s Manual Other Sample Programs Illustrating Digital I/O R/W pin and DB0-DB3 on 3 RS-232 Serial Communication Sample Programs 4 RS-485 Serial Communication Sample Program Cooperative Multitasking Int vswitch Advantages of Cooperative Multitasking Jackrabbit Function Calls 1 I/O DriversVoid digOutint channel, int value Void anaOutint channel, int value Void anaInint channel, int *value Serial Communication Drivers Upgrading Dynamic C Patches and Bug FixesAdd-On Modules Appendix A. Specifications Electrical and Mechanical Specifications Figure A-1shows the mechanical dimensions for the JackrabbitTable A-1. Jackrabbit Board Specifications Exclusion Zone Exclusion ZonesFigure A-3. User Board Footprint for Jackrabbit Jumper Configurations Figure A-4. Location of Jackrabbit Configurable PositionsTable A-2. Jackrabbit Jumper Configurations Conformal Coating Conformally coated areaUse of Rabbit 2000 Parallel Ports JackrabbitTable A-3. Jackrabbit Pinout Configurations PD0 PD1 Jackrabbit BL1800 Appendix B. Prototyping Board Jackrabbit Connectors User LEDs Buzzer Prototyping Board OverviewPrototyping Board Features Mechanical Dimensions and Layout Top SideUsing the Prototyping Board Top SideDemonstration Board RelayExisting Prototyping Board Top SidePE0 VCC HV0 SM1 SM0 HV2 Stat Jackrabbit BL1800 Appendix C. Power Management Power SuppliesDcin Current mA Batteries and External Battery Connections 950 mA·h = 5.4 years 20 µABattery Backup Circuit Figure C-5shows the Jackrabbit battery backup circuitryPower to Vram Switch Reset GeneratorFigure C-7shows a schematic of the chip select circuit Chip Select CircuitJackrabbit BL1800 Index SMODE0 SMODE1RABDB01.C RABDB02.C Schematics