Ejemplo n.º 1
0
void hal_tick_init(void){
    ledIsOn = false;
    handleTmr = DRV_TMR_Open(APP_TMR_DRV_INDEX, DRV_IO_INTENT_EXCLUSIVE);
    if( DRV_HANDLE_INVALID == handleTmr ){
        log_error("Timer init failed");
        return;
    }
    DRV_TMR_Alarm16BitRegister(handleTmr, APP_TMR_ALARM_PERIOD, true, (uintptr_t)NULL, sys_tick_handler);
    DRV_TMR_Start(handleTmr);
    SYS_PORTS_PinDirectionSelect(PORTS_ID_0, SYS_PORTS_DIRECTION_OUTPUT, APP_LED_PORT, APP_LED_PIN);
}
Ejemplo n.º 2
0
void SYS_TMR_Tasks ( SYS_MODULE_OBJ object )
{
    SYS_TMR_OBJECT* pTmrObject = (SYS_TMR_OBJECT*)object;

    // sanity check we're still here
    if(pTmrObject != &sSysTmrObject)
    {   // no valid handle 
        return;
    }

    switch ( sSysTmrObject.status )
    {
        case SYS_STATUS_BUSY:
            // Performing the initialization
            // Try to open a TMR driver
            sSysTmrObject.driverHandle =  DRV_TMR_Open ( sSysTmrObject.drvIndex, DRV_IO_INTENT_EXCLUSIVE );

            if ( sSysTmrObject.driverHandle == DRV_HANDLE_INVALID )
            {   // spin here until the driver is opened
                break;
            }

            // try to set up the pservice parameters
            if(!_SYS_TMR_Setup(&sSysTmrObject))
            {   // some parameter error occurred
                sSysTmrObject.status  = SYS_STATUS_ERROR;
                break;
            }

            // success
            /* Set the alarm */
            DRV_TMR_Alarm16BitRegister ( sSysTmrObject.driverHandle, sSysTmrObject.driverPeriod, true,
                                    (uintptr_t)&sSysTmrObject, _SYS_TMR_AlarmCallback );

            /* Start the timer */
            DRV_TMR_Start ( sSysTmrObject.driverHandle );

            /* Status of the state machine is changed to indicate initialization complete */
            sSysTmrObject.status = SYS_STATUS_READY;
            break;

        case SYS_STATUS_READY:

            /* If there is no activity we need not run the loop */
#if (SYS_TMR_INTERRUPT_NOTIFICATION)
            // block user access; we may delete clients
            _UserGblLock();
            _SYS_TMR_ProcessIsrClients();
            _UserGblUnlock();
#else
            if ( sSysTmrObject.alarmReceived == true )
            {
                sSysTmrObject.alarmReceived = false;
                // block user access; we may delete clients
                _UserGblLock();
                _SYS_TMR_ProcessTmrAlarm();
                _UserGblUnlock();
            }
#endif  // (SYS_TMR_INTERRUPT_NOTIFICATION)
            break;

        default:    // SYS_STATUS_ERROR
            // do nothing
            break;
    }

}
Ejemplo n.º 3
0
Archivo: app.c Proyecto: fokane/LPFgit
void APP_Tasks ( void )
{

    /* Check the application's current state. */
    switch ( appData.state )
    {
        /* Application's initial state. */
        case APP_STATE_INIT:
        {
            tmrInterruptHandle = DRV_TMR_Open(DRV_TMR_INDEX_0, DRV_IO_INTENT_EXCLUSIVE);
            
            if (DRV_HANDLE_INVALID == tmrInterruptHandle)
            {
                // Unable to open the driver
                while(1);
            }
            
            
            
            // based on 80MHz Tpb and 256 PS should be 8192Hz frequency
            DRV_TMR_AlarmRegister(tmrInterruptHandle, 38, true, 0, TimerInterruptCallback);
           
           
            // change state
            appData.state = APP_STATE_SETUP_OC;
            break;
        }

        case APP_STATE_SETUP_OC:
        {
            DRV_OC0_Enable();
            DRV_OC0_Start();
            
            // setup the Timer for OC1 module
            PLIB_TMR_PrescaleSelect(TMR_ID_2, TMR_PRESCALE_VALUE_1);
            PLIB_TMR_Period16BitSet(TMR_ID_2, 9765);
            // start Timer
            DRV_TMR_Start(tmrInterruptHandle);
            PLIB_TMR_Start(TMR_ID_2);
            
            // change state
            appData.state = APP_STATE_IDLE;
            break;
        }
        case APP_STATE_IDLE:
        {
        
            break;
        }

        /* TODO: implement your application state machine.*/
        

        /* The default state should never be executed. */
        default:
        {
            /* TODO: Handle error in application's state machine. */
            break;
        }
    }
}
Ejemplo n.º 4
0
Archivo: app.c Proyecto: hjph/Prueba1
void APP_Initialize ( void )
{
    /* Place the App state machine in its initial state. */
    appData.state = APP_STATE_INIT;
    
    // set the direction of the pins and Open the Timer                 
   MyHandleIsr = DRV_TMR_Open( DRV_TMR_INDEX_0, DRV_IO_INTENT_EXCLUSIVE );
 
   // calculate the divider value and register the ISR
   uint32_t desiredFrequency = 10 ; // 10 hertz
   uint32_t actualFrequency = DRV_TMR_CounterFrequencyGet(MyHandleIsr) ;
   uint32_t divider = actualFrequency/desiredFrequency; // cacluate divider value
   DRV_TMR_AlarmRegister(MyHandleIsr, divider, true, 0 , MyISR);
 
   // Starting the Timer   
   DRV_TMR_Start(MyHandleIsr);
    
   TRISAbits.TRISA0 = 0;
   LATAbits.LATA0 = 0;
   
   /*
    TRISCbits.TRISC2 = 1;
    ANSELCbits.ANSC2 = 1;
    
    
    AD1CAL1 = DEVADC1;                  // Writing Calibration-Data to ADC-Registers
     AD1CAL2 = DEVADC2;
     AD1CAL3 = DEVADC3;
     AD1CAL4 = DEVADC4;
     AD1CAL5 = DEVADC5;
 
    AD1CON1 = 0;                        // First Clear AD1CON1-Register
    AD1CON1bits.STRGSRC = 1;            // Scan Trigger Src = Global Software Trigger (GSWTRG)
    AD1CON1bits.FILTRDLY = 0b11111 ;
    
    AD1CON2 = 0;                        // Clear AD1CON2-Register
     AD1CON2bits.ADCSEL = 1;             // ADC Clock-Src = SYSCLK (200 MHz)
     AD1CON2bits.ADCDIV = 4;             // Clock Divider 4 means (8*TQ) = 25 MHz
     AD1CON2bits.SAMC = 32;              // S&H-Sample Time = 32TAD
 
    AD1CON3 = 0;                        // Clear AD1CON3-Register
 
    AD1CON3bits.VREFSEL = 3;
    AD1IMOD = 0;                        // All SampleAndHold-Units set to Standard-values
                                         // Single-ended Inputs with unsigned integer-Format, Standard-Inputs
     //AD1IMODbits.SH3ALT = 1;             // Alternate Input for Sample And Hold 3 (uses normalla AN3, now AN48 - maybe this has blocked AN3??)
 
    AD1GIRQEN1 = 0;                     // No Interrupts used
     AD1GIRQEN2 = 0;                     // No Interrupts
 
    AD1CSS1 = 0;                        // First Clear all Channel-Scan-Select-Bits (Register 1)
     AD1CSS2 = 0;                        // Clear all CSS-Bits of Register 2
     //AD1CSS1bits.CSS21 = 1;               // Select CSS3 = AN3 for ChannelScan
 
    AD1CMPCON1 = 0;                     // No Comperator-Functions
     AD1CMPCON2 = 0;
     AD1CMPCON3 = 0;
     AD1CMPCON4 = 0;
     AD1CMPCON5 = 0;
     AD1CMPCON6 = 0;
 
    AD1FLTR1 = 0;                       // No Filter / Oversampling
     AD1FLTR2 = 0;
     AD1FLTR3 = 0;
     AD1FLTR4 = 0;
     AD1FLTR5 = 0;
     AD1FLTR6 = 0;

    AD1TRG1 = 0;                        // No Triggers
     AD1TRG2 = 0;                        // No Triggers
     AD1TRG3 = 0;                        // No Triggers

    AD1TRG2bits.TRGSRC7 = 1;            // Trigger for AN3 = STRIG (because AN3 is a Channel1-Input!)

    AD1CON1bits.ADCEN = 1;              // Enable ADC
 
    while (AD1CON2bits.ADCRDY == 0);    // Wait for end of Calibration
    */
    /* TODO: Initialize your application's state machine and other
     * parameters.
     */
}
Ejemplo n.º 5
0
void FLIR_Tasks ( void )
{
    LEP_RESULT result;
    /* Check the application's current state. */
    switch ( flirData.state )
    {
        /* Application's initial state. */
        case FLIR_STATE_INIT:
        {
            bool appInitialized = true;
       
            if (flirData.handleTmrDrv == DRV_HANDLE_INVALID)
            {
                flirData.handleTmrDrv = DRV_TMR_Open(FLIR_TMR_DRV, DRV_IO_INTENT_EXCLUSIVE);
                appInitialized &= ( DRV_HANDLE_INVALID != flirData.handleTmrDrv );
            }
        
            if (appInitialized)
            {
                TimerSetup();
                BSP_LEDOn(BSP_LED_1);
                flirData.state = FLIR_OPEN_PORT;
            }
            break;
        }
        case FLIR_OPEN_PORT:
        {
            BSP_LEDOn(BSP_LED_2);
            result = LEP_OpenPort(0,
                                  LEP_CCI_TWI,
                                    #ifdef BB_ENABLED
                                        DRV_I2C_BIT_BANG_BAUD_RATE_IDX0
                                    #else
                                        DRV_I2C_BAUD_RATE_IDX0
                                    #endif
                                  /1000,&flirData.lepton.cameraPort);
            if(result != LEP_OK)
            {
                flirData.state = FLIR_ERROR;
            }
            else
            {
                BSP_LEDOff(BSP_LED_1);
                BSP_LEDOff(BSP_LED_2);
                BSP_LEDOff(BSP_LED_3);
                BSP_LEDOn(BSP_LED_4);
                flirData.state = FLIR_STATE_SERVICE_TASKS;
            }
            break;
        }
        case FLIR_STATE_SERVICE_TASKS:
        {
            LedTask();
        
            break;
        }

        /* TODO: implement your application state machine.*/
        

        case FLIR_ERROR:
        default:
        {
            BSP_LEDOn(BSP_LED_1);
            BSP_LEDOn(BSP_LED_2);
            BSP_LEDOn(BSP_LED_3);
            BSP_LEDOn(BSP_LED_4);
            break;
        }
    }
}
Ejemplo n.º 6
0
void APP_Tasks ( void )
{
    switch ( appData.state )
    {
        case APP_STATE_INIT:
        {
            if(appData.status.ready)
            {
                appData.state = APP_STATE_RUN;
                break;
            }            
            if(appData.status.SPIReady==false)
            {
                appData.LED.SPIHandle = DRV_SPI_Open(DRV_SPI_INDEX_0,
                                                    DRV_IO_INTENT_EXCLUSIVE |
                                                    DRV_IO_INTENT_WRITE |
                                                    DRV_IO_INTENT_NONBLOCKING
                                               );     
                appData.status.SPIReady = ( DRV_HANDLE_INVALID != appData.LED.SPIHandle );
            }
            if(appData.status.TimerDriverReady==false)
            {
                appData.timer.driver.handle = DRV_TMR_Open(
                        DRV_TMR_INDEX_0,
                        DRV_IO_INTENT_READWRITE|DRV_IO_INTENT_EXCLUSIVE);
                appData.status.TimerDriverReady = 
                        (appData.timer.driver.handle != DRV_HANDLE_INVALID);
            }     
            if(appData.status.SPIReady && appData.status.TimerDriverReady)
            {
                appData.LED.start=0;                
                appData.state=APP_STATE_TIMER_START;
            }
            break;
        }        
        case APP_STATE_TIMER_START:
        {  
            if(DRV_TMR_AlarmRegister(appData.timer.driver.handle,
                    DRV_TMR_CounterFrequencyGet(appData.timer.driver.handle)/25,
                    true,
                    0,
                    &TimerCallback)
                )
            {                
                if(DRV_TMR_Start(appData.timer.driver.handle))
                {
                    appData.status.ready=true;
                    appData.state=APP_STATE_RUN;
                }
            }
            break;
        }        
        case APP_STATE_RUN:
        {
            if(!SendingToStrip())
            {                
                APP_TASKS_ACTIVITY_SET;
                PopulateStrip(&appData.LED);
                appData.state=APP_STATE_SEND_STRIP;
            }
            break;
        }
        case APP_STATE_SEND_STRIP:
        {
            if(appData.status.readyForNext)
            {
                appData.status.readyForNext=false;
                SendLEDStrip(&appData.LED);
                /* write each pixel out to the SPI buffer */            
                /* give the data over to the SPI system to send to the LED strip */
                appData.state=APP_STATE_WAIT;
                APP_TASKS_ACTIVITY_CLEAR;
            }
            break;
        }
        case APP_STATE_WAIT:
        {
            /* wait for the SPI transaction to finish. */
            if(SendingToStrip())
            {
                break;
            }
            appData.LED.start++;
            appData.state=APP_STATE_RUN;
            break;
        }        
        case APP_STATE_ERROR:
        {
            break;
        }
        default:
        {
            /* shouldn't get here. */
            APP_Initialize();
            break;
        }
    }
    if(appData.activityLED.blinkCount++>appData.activityLED.interval)
    {
        mActivityLEDInvert();
        appData.activityLED.blinkCount=0;
    }        
}