Exemple #1
0
 /*********************************************************************
 Function:        void RtccInitClock(void)

 PreCondition:    None
                  
 Input:           None
 
 Output:          None
 
 Side Effects:    Enables the secondary oscillator from Timer1
 
 Overview:        The function initializes the RTCC device. It starts the RTCC clock,
                  sets the RTCC Off and disables RTCC write. Disables the OE.
                   
 Note:            None
 ********************************************************************/
void RtccInitClock(void)
{
   // enable the Secondary Oscillator
#if defined (RTCC_SFR_V1)
	T1CONbits.SOSCEN = 1;
#else   
   T1CONbits.T1OSCEN = 1;
#endif

#if defined (RTCC_V1)
	RTCCFG = 0x0;
#else
    RTCCON1=0x0;
#endif
 	
   RTCCAL = 0x00;
   if(mRtccIsOn())
   {
      if(!mRtccIsWrEn())
      {
          RtccWrOn();
      }
       mRtccOff();
   }
   
   mRtccWrOff();
}
Exemple #2
0
void _ISRFAST _INT2Interrupt(void)
#endif
{
    //LED1 = ~LED1;
    if (SA02_VIBRA_INTPIN_IF) {
        uint8_t rtc_min;
        uint16_t rtc_sec;
        // get current time from RTC
        mRtccClearRtcPtr();
        rtc_sec = BCDToDecimal(RTCVALL);
        rtc_min = BCDToDecimal(RTCVALH);
        rtc_sec += rtc_min*SEC_IN_MIN;
        //printf("int_cnt: %lu time: %d start_time: %d\n", int_cnt, rtc_sec, sec_start);

        if (isInInterval(sec_start, rtc_sec))
        {
            // we have enough interrupts in given shaking interval
            if (int_cnt++ >= INTERRUPTS_FOR_ONE_SHAKE)
            {
                accel_int = TRUE;
                int_cnt = 0;
                //printf("=== Vibra interrupt ===\n");
            }
            delay_ms(25);
        }
        else
        {
            sec_start = rtc_sec; // save new starting time
            int_cnt = 0;
        }
        SA02_VIBRA_INTPIN_IF = 0;
    }       
    // RTC interrupt
    if ((PIR3bits.RTCCIF) && (PIE3bits.RTCCIE)) {
        PIR3bits.RTCCIF = 0;
        PIE3bits.RTCCIE = 0;
        RtccWrOn();
        mRtccOff();
        mRtccWrOff();
        //printf("RTC INT\n");
    }
    if (HW_isIRQ0Active()) {
        HW_irq0occurred();
        HW_clearIRQ0();
    }
    if (HW_isIRQ1Active()) {
        HW_irq1occurred();
        HW_clearIRQ1();
    }
    //LED1 = ~LED1;
}
Exemple #3
0
  void HW_init(void) {
    remapAllPins();

    ANCON0 = 0xFF;
    ANCON1 = 0x1F;

    IRQ0_INT_TRIS = 1;
    IRQ1_INT_TRIS = 1;

    // Config IRQ Edge = Rising
    INTCON2bits.INTEDG1 = 1;
    INTCON2bits.INTEDG2 = 1;


    PHY_IRQ0 = 0; // MRF89XA
    PHY_IRQ0_En = 1; // MRF89XA
    PHY_IRQ1 = 0; // MRF89XA
    PHY_IRQ1_En = 1; // MRF89XA    

    Data_nCS = 1;
    Config_nCS = 1;

    Data_nCS_TRIS = 0;
    Config_nCS_TRIS = 0;

    SDI_TRIS = 1;
    SDO_TRIS = 0;
    SCK_TRIS = 0;

    SSP1STAT = 0xC0;
    SSP1CON1 = 0x21;

    // reset radio
    PHY_RESETn = 1;
    PHY_RESETn_TRIS = 0;
    delay_ms(1);
    PHY_RESETn = 0;
    delay_ms(10);

    LED0_TRIS = 0;
    LED0 = 0;
    LED1_TRIS = 0;
    LED1 = 0;

    //documentation page 187
    // enabled timer,as 16 bit,internal instruction cycle, edge(x), not bypass prescaler, prescale 256
    T0CON = 0b10010111;
    TMR0H = 200; //wait more while configuration done
    INTCONbits.TMR0IE = 1;
    INTCONbits.TMR0IF = 0;
    INTCON2bits.TMR0IP = 0; //use low priority on timer0 interupts 
    
    RtccInitClock();
    RtccWrOn();
    RTCCFGbits.RTCSYNC = 1;
    RTCCALbits.CAL = 10000000;
    mRtccOn();
    mRtccWrOff();
    PIE3bits.RTCCIE = 0;

    RCONbits.IPEN = 1; //enable interupt priority levels

    INTCONbits.GIEH = 1;
    INTCONbits.GIEL = 1;
    
    spieepromInit();
    Vibra_Init();
    I2c_Init();
    
/*         
    unjoinNetwork();
    while(1);
*/    
    
    
};
Exemple #4
0
/*********************************************************************
 * Function:        BOOL RtccWriteTime(const rtccTime* pTm, BOOL di)
 *
 * PreCondition:    pTm pointing to a valid rtccTime structure having proper values:
 *                      - sec:  BCD codification, 00-59
 *                      - min:  BCD codification, 00-59
 *                      - hour: BCD codification, 00-24
 * Input:           pTm - pointer to a constant rtccTime union
 *                  di  - if interrupts need to be disabled
 * Output:          TRUE '1' : If all the values are within range
 *                  FALSE '0' : If any value is out of above mentioned range.
 * Side Effects:    None
 * Overview:        The function sets the current time of the RTCC device.
 * Note:            - The write is successful only if Wr Enable is set.
 *                  The function will enable the write itself, if needed.
 *                  Also, the Alarm will be temporarily disabled and the
 *                  device will be stopped (On set to 0) in order
 *                  to safely perform the update of the RTC time register.
 *                  However, the device status will be restored.
 *                  - Usually the disabling of the interrupts is desired, if the user has to have more
 *                  precise control over the actual moment of the time setting.
 ********************************************************************/
BOOL RtccWriteTime(const rtccTime* pTm , BOOL di)
{
    WORD_VAL tempHourWDay ;
    WORD_VAL tempMinSec ;
    UINT8  CPU_IPL;

    BOOL        wasWrEn;
    BOOL        wasOn;
    BOOL        wasAlrm=FALSE;

    if((MAX_MIN < pTm->f.min )|| (MAX_SEC < pTm->f.sec) || (MAX_HOUR < pTm->f.hour))
    {
        return(FALSE);
    }

    tempMinSec.byte.HB = pTm->f.min;
    tempMinSec.byte.LB =pTm->f.sec;        // update the desired fields

    if(di)
    {
        /* Disable Global Interrupt */
        mSET_AND_SAVE_CPU_IP(CPU_IPL,7);
    }

    if(!(wasWrEn= mRtccIsWrEn()))
    {
        RtccWrOn();            // have to allow the WRTEN in order to write the new value
    }
    if((wasOn=mRtccIsOn()))
    {
        wasAlrm= mRtccIsAlrmEnabled();
        mRtccOff();         // turn module off before updating the time
    }

    mRtccClearRtcPtr();
    mRtccSetRtcPtr(RTCCPTR_MASK_HRSWEEK);

    tempHourWDay.Val = RTCVAL;
    tempHourWDay.byte.LB = pTm->f.hour;


    mRtccClearRtcPtr();
    mRtccSetRtcPtr(RTCCPTR_MASK_HRSWEEK);

    RTCVAL = tempHourWDay.Val; // update device value
    RTCVAL = tempMinSec.Val;

    if(wasOn)
    {
        mRtccOn();
        if(wasAlrm)
        {
            mRtccAlrmEnable();
        }

        if(wasWrEn)
        {
            RtccWrOn();
        }
    }
    else
    {
        if(!wasWrEn)
        {
            mRtccWrOff();
        }
    }

    if(di)
    {
        /* Enable Global Interrupt */
        mRESTORE_CPU_IP(CPU_IPL);
    }


    return(TRUE);
}