########################################################################
### FILE: tbc.mod
### PURPOSE: Thermal Block Controller setup
### SCOPE: Top Level
###
### Copyrights (C) 2010 Life Technologies. All rights reserved.
########################################################################
### Load required initialization functions
MODule tbcregisters.mod
MODule tbcalgoregs.mod
### Command to add and populate TBC branch
DEFINT TBC+ $Node$
### Create TBC branch
BRANch+ -type=TBC -replaceExisting TBC
TBC:BASe= $Node$ 0x0000
TBC:MODule aliases.mod
### Set up TBC event handling
LLAC:DEVice= $Node$ TBC
LLAC:EventTABLe< $Node$ tbcevents.ini events
### Wait for few seconds due to TBC bug/race condition
WAIT 5
### Create registers on TBC board
TBCMap TBC $Node$
### Create Algorithm-specific TBC zone registers
TBCZoneAlgorithmTable TBC
### Initialize TBC zones, sensors, drivers
TBC:MODule tbcinit.mod
TBC:INITialize
### Set number of flow chips
IF $[ $(TBC:NVRAM? 0x801F REAL) == 1.0 ] 'VAR NumFlowChips 1'
ELSE 'VAR NumFlowChips 2'
### Update TBC state
STATe:SETTing tbc True
### Command to remove TBC branch
DEFINT TBC- $Node$
### Update TBC state
STATe:SETTing tbc False
### Stop polling for temperatures
POLL-
LLAC:DEVice~ $Node$
LLAC:EventTable~ $Node$
BRANch- -ignoreMissing TBC
### Methods to start/stop temperature polling
DEFINT POLL+
TBC:POLL+ Temperatures -replaceExisting -topic=Temperature \
-decimals=1 -retries=2 \
-sample=SampleTemperatures? \
-heatsink=HeatSinkTemperatures? \
-chiller=:FLUidics:Zone:Chiller:CURRentTEMPerature? \
-interior=:ACB:SENSor:A2D_InteriorTemp:READing? \
-exterior=:ACB:SENSor:A2D_ExteriorTemp:READing?
DEFINT POLL-
TBC:POLL- Temperatures -ignoreMissing
### State management
STATe:NEW TBC
STATe:NEW ThermalControl:Ready -requires=tbc,instrument:safe
STATe:TRIGger -states=ThermalControl:Ready -edge=set TBCStart
TBC:START
POLL+
STATe:TRIGger -states=ThermalControl:Ready -edge=clear TBCStop
POLL-
UNLess $(STATe? -errorState=True TBC) TBC:STOP
STATe:DEPendency+ Instrument:Online -requires=TBC
STATe:DEPendency+ Instrument:Initialized -requires=ThermalControl:Ready