コード例 #1
0
ファイル: ticks.c プロジェクト: BatteryPower/smart_tft
/**
 * @function TicksGet
 * @brief return the number of the ms elapsed since TicksInit() call
 * @param none
 * @return ticks_t: ms
 */
ticks_t TicksGet(void) {
  ticks_t ticks;
  SemLock(sem);
  ticks = u64ReadableTicks;
  SemUnlock(sem);
  return ticks;
}
コード例 #2
0
ファイル: ticks.c プロジェクト: BatteryPower/smart_tft
/**
 * @function TicksInit
 * @brief initialize the aboslute 1ms reference clock
 * @param none
 * @return none
 */
void TicksInit(void) {
  u64AbsoluteTicks = u64ReadableTicks = 0;  /*time reference begin to 0ms*/
  SemUnlock(sem);
  TmrSetFrequency(TMR_1, 1000);             /*Set ticks to 1ms (1000 -> 1kHz)*/
  TmrSetCallback(TMR_1, TicksCallback);     /*Associate timer interruption to TicksCallback() function*/
  TmrLaunch(TMR_1);                         /*Start timer*/
}
コード例 #3
0
ファイル: AD5310.c プロジェクト: Griffindog/tiny-DDS
/**
 * @function AD5310_Set
 * @brief Set a new binary word to the selected DAC
 * @param uint8_t dev: #id of the DAC
 * @param uint16_t word_10bits: new word (only the 10LSB are used)
 * @return none
 */
void AD5310_Set(uint8_t dev, uint16_t word_10bits) {

  uint16_t data;

  if(dev < DAC_COUNT) {

    /*select the DAC*/
    SemLock(spiBusy);
    *(devices[dev].gpio) &= (devices[dev].mask ^ 0xFFFF);

    /*send the DAC word*/
    data = (word_10bits & 0x03FF) << 2;
    SPI_PutU16(data);

    /*un-select the DAC*/
    *(devices[dev].gpio) |= devices[dev].mask;
    SemUnlock(spiBusy);
  }
}
コード例 #4
0
ファイル: clib_log.cpp プロジェクト: koolhazz/ProxyServer
/**
 * Write log.
 *
 * @param   as_msg      Message info.
 * @param   ai_level    Level num.
 * @return              0: succ, !=0: fail.
 */
int clib_log::write( const char *as_msg,
                     int        ai_level,
                     const UIN_TYPE ai_uin)
{
    time_t t;
    struct tm tm_re;
    struct tm *ptm = NULL;
    char   s_buf[CLIB_LOG_SLEN_NORM]  = { 0 };
    char   s_msg[CLIB_LOG_SLEN_LONG]  = { 0 };
    char   s_file[CLIB_LOG_SLEN_LONG] = { 0 };
    int    i_ret = 0;

    time( &t );
    ptm = localtime_r( &t, &tm_re );

    if ( ai_level > mi_level && (ai_uin == 0 || mb_coloring == false) ) {
        i_ret = 0; //coloring is open or not; if it's open, no level is care.
    } else if ( strlen(ms_file) <= 0
                    || NULL == as_msg
                    || strlen(as_msg) <= 0 ) {
        i_ret = -1;
    } else {
    
        if (ai_uin == 0 || mb_coloring == false){ //do not coloring
            if ( strlen(ms_tformat) > 0 ) {
                strftime( s_buf, sizeof(s_buf), ms_tformat, ptm );
                snprintf( s_msg, sizeof(s_msg), "%s%s%s", s_buf, as_msg, ms_eol );
            } else {
                snprintf( s_msg, sizeof(s_msg), "%s%s", as_msg, ms_eol );
            } // if
        }

        else{

            if (setUins.find(ai_uin) == setUins.end())
            {
                return 0;
            }
        
            if ( strlen(ms_tformat) > 0 ) {
                strftime( s_buf, sizeof(s_buf), ms_tformat, ptm );
                snprintf( s_msg, sizeof(s_msg), "%s[%u]%s%s", s_buf, ai_uin, as_msg, ms_eol );
            } else {
                snprintf( s_msg, sizeof(s_msg), "[%u]%s%s", ai_uin, as_msg, ms_eol );
            } // if
        }

        strftime( s_buf,  sizeof(s_buf),  ms_logtype, ptm );
        snprintf( s_file, sizeof(s_file), "%s%s", ms_file, s_buf );
    
        //lock
        if (mi_semopen) {
            SemLock(mi_semid, NULL);
        }
        
        this->check_file( s_file );
        i_ret = clib_log_write( s_file, s_msg, strlen(s_msg) );

        //unlock
        if (mi_semopen) {
            SemUnlock(mi_semid, NULL);
        }

    } // if ( ai_level > mi_level )
    return( i_ret );
}