<?xml version="1.0"?>
<project name="CC1352P ALS" version="2.3.0.684">
    <desc><![CDATA[Demonstrates use of the bit-banged I2C master interface by sampling the OPT3001 light sensor on the CC2650 SensorTag.

The application is woken if the light sensor output value changes by more than a configurable amount:
- If decreasing, the application blinks the red LED on the SensorTag.
- If increasing, the application blinks the green LED on the SensorTag.

See the header in the application source file ("main.c" or similar) for further details and instructions. This file is located in the source code output directory.]]></desc>
    <pattr name="Apply default power mode">0</pattr>
    <pattr name="Board">CC1352P* LaunchPad</pattr>
    <pattr name="Chip name">CC1352P1F3</pattr>
    <pattr name="Chip package">QFN48 7x7 RGZ</pattr>
    <pattr name="Chip revision">-</pattr>
    <pattr name="Clock in active mode">1</pattr>
    <pattr name="Code prefix"></pattr>
    <pattr name="Default power mode">0</pattr>
    <pattr name="Operating system">TI-RTOS</pattr>
    <pattr name="Output directory">./source</pattr>
    <pattr name="RTC tick interval (16.16 format)">2000</pattr>
    <pattr name="Run-time logging UART RX pin"></pattr>
    <pattr name="Run-time logging UART TX pin"></pattr>
    <task name="cc1352Pals">
        <desc><![CDATA[Samples the OPT3001 light sensor on the CC2650 SensorTag. This light sensor integrates over longer periods of time to minimize the effect of 50 and 60 Hz noise sources.

Each iteration of the I2C Light Sensor task:
- Runs the Execution Code: The light sensor configured for 100 ms integration, and a single measurement is started. The timer based event trigger is enabled (100 ms + margin).
- Runs the Event Handler Code: The light sensor value is read and processed.

The light sensor output is converted from floating-point (12-bit mantissa, 4-bit exponent) to fixed-point (16-bit). The system CPU is alerted if the value is above or below configurable thresholds.

Note that OPT3001 implements a timeout for I2C accesses, and will NACK I2C TX operations if a task debugging session halts execution in the middle of an I2C transaction.]]></desc>
        <tattr name="ALS_CFG_ONE_SHOT" desc="OPT3001 configuration triggering 100 ms single conversion" type="hex" content="const" scope="task" min="0000" max="ffff">c210</tattr>
        <tattr name="ALS_CFG_RESET" desc="OPT3001 configuration at reset (shutdown)" type="hex" content="const" scope="task" min="0000" max="ffff">c810</tattr>
        <tattr name="ALS_I2C_ADDR" desc="OPT3001 I2C address" type="hex" content="const" scope="task" min="0000" max="ffff">0088</tattr>
        <tattr name="ALS_REG_CFG" desc="OPT3001 configuration register" type="dec" content="const" scope="task" min="0" max="65535">1</tattr>
        <tattr name="ALS_REG_RESULT" desc="OPT3001 result register" type="dec" content="const" scope="task" min="0" max="65535">0</tattr>
        <tattr name="cfg.highThreshold" desc="High alert threshold" type="dec" content="struct" scope="task" min="0" max="65535">65535</tattr>
        <tattr name="cfg.lowThreshold" desc="Low alert threshold" type="dec" content="struct" scope="task" min="0" max="65535">0</tattr>
        <tattr name="output.value" desc="Light sensor output value" type="dec" content="struct" scope="task" min="0" max="65535">0</tattr>
        <resource_ref name="ADC" enabled="0"/>
        <resource_ref name="AON Domain Functionality" enabled="0"/>
        <resource_ref name="Accumulator-Based Math" enabled="0"/>
        <resource_ref name="Analog Open-Drain Pins" enabled="0"/>
        <resource_ref name="Analog Open-Source Pins" enabled="0"/>
        <resource_ref name="Analog Pins" enabled="0"/>
        <resource_ref name="COMPA" enabled="0"/>
        <resource_ref name="COMPA Event Trigger" enabled="0"/>
        <resource_ref name="COMPB" enabled="0"/>
        <resource_ref name="COMPB Event Trigger" enabled="0"/>
        <resource_ref name="Delay Insertion" enabled="0"/>
        <resource_ref name="Differential Output Pins" enabled="0"/>
        <resource_ref name="Digital Input Pins" enabled="0"/>
        <resource_ref name="Digital Open-Drain Pins" enabled="0"/>
        <resource_ref name="Digital Open-Source Pins" enabled="0"/>
        <resource_ref name="Digital Output Pins" enabled="0"/>
        <resource_ref name="Dynamic Power Control" enabled="0"/>
        <resource_ref name="GPIO Event Trigger" enabled="0"/>
        <resource_ref name="I2C Master" enabled="1">
            <rattr name="SCL frequency">0</rattr>
            <rattr name="SCL stretch timeout">10</rattr>
            <io_usage>
                <uattr name="SCL pin/0000">DIO22</uattr>
                <uattr name="SDA pin/0000">DIO5</uattr>
            </io_usage>
        </resource_ref>
        <resource_ref name="ISRC" enabled="0"/>
        <resource_ref name="Math and Logic" enabled="0"/>
        <resource_ref name="Multi-Buffered Output Data Exchange" enabled="0">
            <rattr name="Buffer count">2</rattr>
            <rattr name="Indicate overflow at buffer check">1</rattr>
            <rattr name="Indicate overflow at buffer switch">0</rattr>
            <rattr name="Prevent overflow at buffer switch">1</rattr>
        </resource_ref>
        <resource_ref name="Peripheral Sharing" enabled="0"/>
        <resource_ref name="Pulse Counter" enabled="0"/>
        <resource_ref name="RTC Multi-Event Capture" enabled="0"/>
        <resource_ref name="RTC-Based Execution Scheduling" enabled="1"/>
        <resource_ref name="Reference DAC" enabled="0"/>
        <resource_ref name="Run-Time Logging" enabled="0"/>
        <resource_ref name="SPI Chip Select" enabled="0"/>
        <resource_ref name="SPI Data Transfer" enabled="0">
            <rattr name="Bit rate">0</rattr>
            <rattr name="MISO configuration when inactive">-1</rattr>
            <rattr name="MOSI configuration on initialization">0</rattr>
            <rattr name="MOSI configuration on uninitialization">0</rattr>
            <rattr name="SCLK configuration on initialization">0</rattr>
            <rattr name="SCLK configuration on uninitialization">0</rattr>
            <io_usage>
                <uattr name="MISO pin/0000"></uattr>
                <uattr name="MOSI pin/0000"></uattr>
                <uattr name="SCLK pin/0000"></uattr>
            </io_usage>
        </resource_ref>
        <resource_ref name="Signal Observation" enabled="0"/>
        <resource_ref name="System CPU Alert" enabled="1"/>
        <resource_ref name="System Event Trigger" enabled="0"/>
        <resource_ref name="TDC" enabled="0"/>
        <resource_ref name="Timer 0" enabled="0"/>
        <resource_ref name="Timer 0 Event Trigger" enabled="0"/>
        <resource_ref name="Timer 1" enabled="0"/>
        <resource_ref name="Timer 1 Event Trigger" enabled="0"/>
        <resource_ref name="Timer 2" enabled="0"/>
        <resource_ref name="Timer 2 Event Trigger" enabled="0"/>
        <resource_ref name="UART Emulator" enabled="0">
            <rattr name="RX buffer size">64</rattr>
            <rattr name="Required idle period before enabling RX">11</rattr>
            <rattr name="TX buffer size">64</rattr>
            <io_usage>
                <uattr name="RX pin/0000"></uattr>
                <uattr name="TX pin/0000"></uattr>
            </io_usage>
        </resource_ref>
        <sccode name="event0" init_power_mode="0"><![CDATA[// If a measurement was successfully started during the last execution ...
if (state.i2cStatus == 0x0000) {

    // Select the result register
    i2cStart();
    i2cTx(I2C_OP_WRITE | ALS_I2C_ADDR);
    i2cTx(ALS_REG_RESULT);

    // If successful ...
    if (state.i2cStatus == 0x0000) {
        U16 resultRegH;
        U16 resultRegL;

        // Read the result
        i2cRepeatedStart();
        i2cTx(I2C_OP_READ | ALS_I2C_ADDR);
        i2cRxAck(resultRegH);
        i2cRxNack(resultRegL);
        i2cStop();

        // Convert the result (4-bit exponent + 12-bit mantissa) into 16-bit fixed-point
        U16 exp = resultRegH >> 4;
        U16 mant = (resultRegH << 12) | (resultRegL << 4);
        // The exponent is in range 0 to 11
        U16 value = mant >> (11 - exp);
        output.value = value;

        // Notify the application with the result is below the low threshold or above the high threshold
        if (value < cfg.lowThreshold) {
            fwGenAlertInterrupt();
        }
        if (value > cfg.highThreshold) {
            fwGenAlertInterrupt();
        }

    } else {
        i2cStop();
    }
}]]></sccode>
        <sccode name="event1" init_power_mode="0"><![CDATA[]]></sccode>
        <sccode name="event2" init_power_mode="0"><![CDATA[]]></sccode>
        <sccode name="event3" init_power_mode="0"><![CDATA[]]></sccode>
        <sccode name="execute" init_power_mode="0"><![CDATA[// Configure and start the next measurement
i2cStart();
i2cTx(I2C_OP_WRITE | ALS_I2C_ADDR);  //
i2cTx(ALS_REG_CFG);
i2cTx(ALS_CFG_ONE_SHOT >> 8);
i2cTx(ALS_CFG_ONE_SHOT >> 0);
i2cStop();


//setting the most significant two bits of the low-limit register (LE[3:2] from the Low-Limit Register) to 11b to enable end of mode
//i2cStart();
//i2cTx(I2C_OP_WRITE | ALS_I2C_ADDR);
//i2cTx(2);
//i2cTx(0xC0);
//i2cTx(0x00);
//i2cStop();

// Read the result after 100 milliseconds + a 20% margin
//evhSetupTimer1Trigger(0, 120, 2);//RTC??1??

// Schedule the next execution
fwScheduleTask(1);]]></sccode>
        <sccode name="initialize" init_power_mode="0"><![CDATA[// Schedule the first execution
fwScheduleTask(1);]]></sccode>
        <sccode name="terminate" init_power_mode="0"><![CDATA[// Shut down the light sensor
i2cStart();
i2cTx(I2C_OP_WRITE | ALS_I2C_ADDR);
i2cTx(ALS_REG_CFG);
i2cTx(ALS_CFG_RESET >> 8);
i2cTx(ALS_CFG_RESET >> 0);
i2cStop();

// Cancel the potentially active event trigger
//evhCancelTrigger(0);]]></sccode>
        <event_trigger active_count="1">0,1,2,3</event_trigger>
        <tt_iter>run_execute,run_event0</tt_iter>
        <tt_struct>output.value,state.i2cStatus</tt_struct>
        <rtl_struct></rtl_struct>
        <rtl_task_sel en="1" struct_log_list="output"/>
    </task>
</project>
