コード例 #1
0
ファイル: tuner.c プロジェクト: hakanjansson/psoc_nuggets
void Tuner_RunTuner(void)
{
    uint8 interruptState;
    uint8 suspended = 0;
    uint16 command;
    uint16 previousCompleteBit; /* COMPLETE_BIT in tunerCmd at time of last send to tuner host */

    Tuner_SendBuffer();

    /* Handle suspend command to avoid deadlock later in CapSense_RunTuner */
    do 
    {
        Tuner_RefreshBuffer();
        interruptState = CyEnterCriticalSection();  /* Avoid ints between read and modify tunerCmd */
        command = CapSense_dsRam.tunerCmd;
        switch (command)
        {
            case CapSense_TU_CMD_SUSPEND_E:
                suspended = 1;
                CapSense_dsRam.tunerCmd |= CapSense_TU_CMD_COMPLETE_BIT;
                CyExitCriticalSection(interruptState); /* Enable ints during SendBuffer */
                Tuner_SendBuffer(); /* Send buffer with updated COMPLETE_BIT to tuner host */
                interruptState = CyEnterCriticalSection();
                break;
                
            case CapSense_TU_CMD_RESUME_E:    
            case CapSense_TU_CMD_RESTART_E:
            case CapSense_TU_CMD_RUN_SNR_TEST_E:
                suspended = 0;
                break;
                
            default:
                break;
        }
        CyExitCriticalSection(interruptState);
    } while (suspended); 

    previousCompleteBit = CapSense_dsRam.tunerCmd & CapSense_TU_CMD_COMPLETE_BIT;
    CapSense_RunTuner(); 
    
    if ( previousCompleteBit != (CapSense_dsRam.tunerCmd & CapSense_TU_CMD_COMPLETE_BIT) )
        Tuner_SendBuffer(); /* Send buffer with updated COMPLETE_BIT to tuner host */
}
コード例 #2
0
/*******************************************************************************
* Function Name: void processCapsense( void )
********************************************************************************
*
* Summary:
*  This function steps through each capSense sensor one by one and captures its state.
*
*  For the humidity and humidity reference capacitors, the raw counts are stored 
*  and then the humidity is calculated.
*******************************************************************************/
void processCapSense(void)
{
    static uint8  state = B0;               /* CapSense sensor state machine to cycle through sensors */
    static uint16 humidityRawCounts;        /* Raw count from CapSense Component for the humidity sensor */
    static uint16 humidityRefRawCounts;     /* Raw count from CapSense Component for the Reference capacitor */
    static uint8  buttonValPrev = 0x00;     /* Previous CapSense button state */
    
    if(!CapSense_IsBusy())
    {
        switch(state) {
            case B0: /* Process Button 0, Scan Button 1 */
                CapSense_ProcessWidget(CapSense_BUTTON0_WDGT_ID);
                if(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID))
                {
                    if(capLedBase == false)
                    {
                        CBLED0_Write(LEDON);
                        
                    }      
                    LocData.buttonVal |= (BVAL_B0_MASK);
                }
                else
                {
                    if(capLedBase == false)
                    {
                        CBLED0_Write(LEDOFF);
                    }
                    LocData.buttonVal &= (~BVAL_B0_MASK);
                }
                CapSense_SetupWidget(CapSense_BUTTON1_WDGT_ID);
                state++;
                break;
            case B1: /* Process Button 1, Scan Button 2 */
                CapSense_ProcessWidget(CapSense_BUTTON1_WDGT_ID);
                if(CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID))
                {
                    if(capLedBase == false)
                    {
                        CBLED1_Write(LEDON);
                    }
                    LocData.buttonVal |= (BVAL_B1_MASK);
                }
                else
                {
                    if(capLedBase == false)
                    {
                        CBLED1_Write(LEDOFF);
                    }
                    LocData.buttonVal &= (~BVAL_B1_MASK);
                }
                
                CapSense_SetupWidget(CapSense_BUTTON2_WDGT_ID);
                state++;                
                break;
            case B2: /* Process Button 2, Scan Button 3 */
                CapSense_ProcessWidget(CapSense_BUTTON2_WDGT_ID);
                if(CapSense_IsWidgetActive(CapSense_BUTTON2_WDGT_ID))
                {
                    if(capLedBase == false)
                    {
                        CBLED2_Write(LEDON);
                    }
                    LocData.buttonVal |= (BVAL_B2_MASK);
                }
                else
                {
                    if(capLedBase == false)
                    {
                        CBLED2_Write(LEDOFF);
                    }
                    LocData.buttonVal &= (~BVAL_B2_MASK);
                }
                CapSense_SetupWidget(CapSense_BUTTON3_WDGT_ID);
                state++;
                break;
            case B3: /* Process Button 3, Scan Proximity */
                CapSense_ProcessWidget(CapSense_BUTTON3_WDGT_ID);
                if(CapSense_IsWidgetActive(CapSense_BUTTON3_WDGT_ID))
                {
                    if(capLedBase == false)
                    {
                        CBLED3_Write(LEDON);
                    }
                    LocData.buttonVal |= (BVAL_B3_MASK);
                }
                else
                {
                    if(capLedBase == false)
                    {
                        CBLED3_Write(LEDOFF);
                    }
                    LocData.buttonVal &= (~BVAL_B3_MASK);
                }
                
                /* Now that butons have all been processed, set interrupt state */
                if((LocData.buttonVal & BVAL_ALLB_MASK) != buttonValPrev) /* At least 1 CapSense button state changed */
                {
                    CSINTR_Write(1);
                    buttonValPrev = (LocData.buttonVal & BVAL_ALLB_MASK);
                }
                
                /* Setup Proximity scan */
                CapSense_SetupWidget(CapSense_PROXIMITY0_WDGT_ID);
                state++;
                break;      
            case PROX: /* Process Proximity, Scan Humidity */
                CapSense_ProcessWidget(CapSense_PROXIMITY0_WDGT_ID);
                if(CapSense_IsWidgetActive(CapSense_PROXIMITY0_WDGT_ID))
                {
                    PROXLED_Write(LEDON);
                    LocData.buttonVal |= (BVAL_PROX_MASK);
                }
                else
                {
                    PROXLED_Write(LEDOFF);
                    LocData.buttonVal &= (~BVAL_PROX_MASK);
                }
                CapSense_SetupWidget(CapSense_HUMIDITY_WDGT_ID);
                state++;
                break;
            case HUM: /* Process Humidity, Scan Button 0  and go back to start of loop */                
                humidityRawCounts =    CapSense_HUMIDITY_SNS0_RAW0_VALUE; 
                humidityRefRawCounts = CapSense_HUMIDITY_SNS1_RAW0_VALUE;
                /* Convert raw counts to capacitance */
                capacitance = CalculateCapacitance(humidityRawCounts, humidityRefRawCounts);
                /* Calculate humidity */
                humidity = CalculateHumidity(capacitance); 
                LocData.humidity = ((float32)(humidity))/10.0;
                CapSense_SetupWidget(CapSense_BUTTON0_WDGT_ID);
                state=0;
                break;
        } /* End of CapSense Switch statement */
        #ifdef ENABLE_TUNER
        CapSense_RunTuner();
        #endif
        CapSense_Scan();
    }
}