void rtc_get_alarm(int *h, int *m) { char buf[2]; pcf50605_read_multiple(0x12, buf, sizeof(buf)); /* Convert from BCD */ *m = BCD2DEC(buf[0]); *h = BCD2DEC(buf[1]); }
/* read out the current alarm time */ void rtc_get_alarm(int *h, int *m) { unsigned char data; data = rtc_read(0x0c); *h = BCD2DEC(data & 0x3f); data = rtc_read(0x0d); *m = BCD2DEC(data & 0x7f); }
void rtc_get_alarm(int *h, int *m) { unsigned char buf[4]={0}; /* get alarm preset */ i2c_readbytes(RTC_ADDR, RTC_ALARM_MINUTES, 4 ,buf); *m = BCD2DEC(buf[0] & 0x7f); *h = BCD2DEC(buf[0] & 0x3f); }
int rtc_read_datetime(struct tm *tm) { unsigned int i; int rc, oldlevel; unsigned char buf[7]; oldlevel = disable_irq_save(); if (get_pmu_type() == PCF50606) rc = pcf50606_read_multiple(PCF5060X_RTCSC, buf, sizeof(buf)); else rc = pcf50635_read_multiple(PCF5063X_REG_RTCSC, buf, sizeof(buf)); restore_irq(oldlevel); for (i = 0; i < sizeof(buf); i++) buf[i] = BCD2DEC(buf[i]); tm->tm_sec = buf[0]; tm->tm_min = buf[1]; tm->tm_hour = buf[2]; tm->tm_wday = buf[3]; tm->tm_mday = buf[4]; tm->tm_mon = buf[5] - 1; tm->tm_year = buf[6] + 100; return rc; }
int rtc_read_datetime(struct tm *tm) { tm->tm_sec = BCD2DEC(BCDSEC); tm->tm_min = BCD2DEC(BCDMIN); tm->tm_hour = BCD2DEC(BCDHOUR); tm->tm_wday = BCD2DEC(BCDDAY) - 1; /* timefuncs wants 0..6 for wday */ tm->tm_mday = BCD2DEC(BCDDATE); tm->tm_mon = BCD2DEC(BCDMON) - 1; tm->tm_year = BCD2DEC(BCDYEAR) + 100; return 1; }
void mcp7941x_get_date_time(struct rtc_time *t) { static char cmd[] = {MCP7941X_RTCC_TCR_SECONDS}; char reg[] = {0,0,0,0,0,0,0}; mcp7941x_setup(); bcm2835_i2c_write(cmd, sizeof(cmd)/sizeof(char)); bcm2835_i2c_read(reg, sizeof(reg)/sizeof(char)); t->tm_sec = BCD2DEC(reg[MCP7941X_RTCC_TCR_SECONDS] & 0x7f); t->tm_min = BCD2DEC(reg[MCP7941X_RTCC_TCR_MINUTES] & 0x7f); t->tm_hour = BCD2DEC(reg[MCP7941X_RTCC_TCR_HOURS] & 0x3f); t->tm_wday = BCD2DEC(reg[MCP7941X_RTCC_TCR_DAY] & 0x07); t->tm_mday = BCD2DEC(reg[MCP7941X_RTCC_TCR_DATE] & 0x3f); t->tm_mon = BCD2DEC(reg[MCP7941X_RTCC_TCR_MONTH] & 0x1f); t->tm_year = BCD2DEC(reg[MCP7941X_RTCC_TCR_YEAR]); }
int rtc_read_datetime(struct tm *tm) { int read; unsigned char buf[7]; read = i2c_readbytes(RTC_ADDR, 0x02, sizeof(buf), buf); /* convert from bcd, avoid getting extra bits */ tm->tm_sec = BCD2DEC(buf[0] & 0x7f); tm->tm_min = BCD2DEC(buf[1] & 0x7f); tm->tm_hour = BCD2DEC(buf[2] & 0x3f); tm->tm_mday = BCD2DEC(buf[3] & 0x3f); tm->tm_wday = BCD2DEC(buf[4] & 0x7); tm->tm_mon = BCD2DEC(buf[5] & 0x1f) - 1; tm->tm_year = BCD2DEC(buf[6]) + 100; return read; }
/** * @brief 获取RTC中的时间,秒:分:时:周:日:月:年 * @param[in] * @return 0 获取时间成功 * -1 获取时间失败 * @note 输出: */ int SD2068A_GetTime(unsigned char *TimeBuff) { if(SD2068A_I2CReadDate(TimeBuff) != 0) { return -1; } // BCD转10进制 TimeBuff[0] = BCD2DEC(TimeBuff[0]); // 秒 TimeBuff[1] = BCD2DEC(TimeBuff[1]); // 分 TimeBuff[2] = BCD2DEC(TimeBuff[2]); // 时 TimeBuff[3] = BCD2DEC(TimeBuff[3]); // 周 TimeBuff[4] = BCD2DEC(TimeBuff[4]); // 日 TimeBuff[5] = BCD2DEC(TimeBuff[5]); // 月 TimeBuff[6] = BCD2DEC(TimeBuff[6]); // 年 return 0; }
int rtc_read_datetime(struct tm *tm) { unsigned int i; int rc; unsigned char buf[7]; rc = pcf50605_read_multiple(0x0a, buf, sizeof(buf)); for (i = 0; i < sizeof(buf); i++) buf[i] = BCD2DEC(buf[i]); tm->tm_sec = buf[0]; tm->tm_min = buf[1]; tm->tm_hour = buf[2]; tm->tm_mday = buf[4]; tm->tm_mon = buf[5] - 1; tm->tm_year = buf[6] + 100; tm->tm_yday = 0; /* Not implemented for now */ set_day_of_week(tm); return rc; }
int rtc_read_datetime(struct tm *tm) { unsigned int i; unsigned char buf[7]; pmu_read_rtc(buf); for (i = 0; i < sizeof(buf); i++) buf[i] = BCD2DEC(buf[i]); tm->tm_sec = buf[0]; tm->tm_min = buf[1]; tm->tm_hour = buf[2]; tm->tm_mday = buf[4]; tm->tm_mon = buf[5] - 1; tm->tm_year = buf[6] + 100; tm->tm_yday = 0; /* Not implemented for now */ set_day_of_week(tm); return 0; }
int rtc_read_datetime(struct tm *tm) { int rc; unsigned char buf[7]; rc = rtc_read_multiple(1, buf, sizeof(buf)); /* convert from bcd, avoid getting extra bits */ tm->tm_sec = BCD2DEC(buf[0] & 0x7f); tm->tm_min = BCD2DEC(buf[1] & 0x7f); tm->tm_hour = BCD2DEC(buf[2] & 0x3f); tm->tm_wday = BCD2DEC(buf[3] & 0x7); tm->tm_mday = BCD2DEC(buf[4] & 0x3f); tm->tm_mon = BCD2DEC(buf[5] & 0x1f) - 1; tm->tm_year = BCD2DEC(buf[6]) + 100; /* Adjust weekday */ if (tm->tm_wday == 7) tm->tm_wday = 0; return rc; }
int ps2time_init( void ) { CdvdClock_t clock; struct tm tm_time; static unsigned int monthdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // query the RTC cdInit(CDVD_INIT_NOCHECK); if( !cdReadClock(&clock) ) return -1; tm_time.tm_sec = BCD2DEC(clock.second); tm_time.tm_min = BCD2DEC(clock.minute); tm_time.tm_hour = BCD2DEC(clock.hour); // hour in Japan (GMT + 9) tm_time.tm_mday = BCD2DEC(clock.day); tm_time.tm_mon = BCD2DEC(clock.month) - 1; // RTC months range from 1 - 12 tm_time.tm_year = BCD2DEC(clock.year) + 100; // RTC returns year less 2000 if( tm_time.tm_hour < 9 ) { // go back to last month if( tm_time.tm_mday == 1 ) { // go back to last year if month is january if( tm_time.tm_mon == 0 ) { tm_time.tm_mon = 11; tm_time.tm_year = tm_time.tm_year - 1; } else { tm_time.tm_mon = tm_time.tm_mon - 1; } // if going back to february and year is a leapyear if( tm_time.tm_mon == 1 && IS_LEAP_YEAR(tm_time.tm_year + 1900)) { tm_time.tm_mday = 29; } else { tm_time.tm_mday = monthdays[ tm_time.tm_mon ]; } } else { tm_time.tm_mday = tm_time.tm_mday - 1; } tm_time.tm_hour = (24 - (9 - tm_time.tm_hour)) % 24; } else { tm_time.tm_hour -= 9; } g_ps2time_start = ps2time_mktime(&tm_time); // setup EE timer1 *T1_MODE = 0x0000; // enable the overflow interrupt handler g_interruptID = AddIntcHandler(T1_INTC, ps2time_intr_handler, 0); EnableIntc(T1_INTC); g_interruptCount = 0; *T1_COUNT = 0; *T1_MODE = Tn_MODE(0x02, 0, 0, 0, 0, 0x01, 0, 0x01, 0, 0); // set the timezone as offset in minutes from GMT ps2time_setTimezone( configGetTimezone() ); return 0; }
/* read out the current alarm time */ void rtc_get_alarm(int *h, int *m) { *m = BCD2DEC(ALMMIN); *h = BCD2DEC(ALMHOUR); }
INT32 si_sdtt_parser(UINT8 *section, INT32 length, struct section_parameter *param) { INT32 i,j; // sec_offset; UINT16 current_ver; //UINT16 program_number; struct sdtt_section*info; struct sdtt_content *content; //struct program_map *maps; struct sdtt_section_info *s_info = (struct sdtt_section_info *)param->priv; //?? if (section==NULL) { // s_info->map_counter = 0; return SI_SUCCESS; } //get current version current_ver=SYS_SW_VERSION; info = (struct sdtt_section *)section; content = (struct sdtt_content *)(section+sizeof(struct sdtt_section)); for(i=0;i<info->numer_of_content;i++) { UINT16 cont_desc_len,sche_desc_len,trg_ver,new_ver,sch_time_N; UINT32 down_desc_total_len,down_desc_pase_size; struct sch_time *sched_time; struct SDTT_DL_CONT_DESC_1 *down_desc; cont_desc_len = content->content_ds_len_lo|(((UINT16)content->content_ds_len_hi)<<4); sche_desc_len = content->schedule_ds_len_lo|(((UINT16)content->schedule_ds_len_hi)<<4); sch_time_N = (sche_desc_len/sizeof(struct sch_time)); down_desc_total_len = cont_desc_len - sche_desc_len; sched_time = (struct sch_time *)(((UINT8 *)content)+sizeof(struct sdtt_content)); down_desc = (struct SDTT_DL_CONT_DESC_1 *)(((UINT8 *)sched_time)+sche_desc_len); for(down_desc_pase_size=0;down_desc_pase_size<down_desc_total_len;) { UINT16 desc_len; UINT8 *desc_point; if(down_desc->compab_flag!=1) goto NEXT_CONT; //I can't check the model inf, skip it... desc_point = (((UINT8 *)down_desc) + sizeof(struct SDTT_DL_CONT_DESC_1)); desc_len = si_sdtt_parser_compab_desc((struct SDTT_COMPAB_DESC_1 *)desc_point); if(desc_len==0) //Error parsering Compatibility Desc table goto NEXT_CONT; down_desc_pase_size += (sizeof(struct SDTT_DL_CONT_DESC_1) + desc_len); desc_point += desc_len; if(down_desc->mod_inf_flag==1) { desc_len = st_sdtt_parser_module_desc(desc_point); down_desc_pase_size += desc_len; desc_point += desc_len; } //Private data desc_len = (*desc_point); desc_point += (desc_len+1); down_desc_pase_size += (desc_len+1); //text info if(down_desc->txt_inf_flag==1) { desc_point += 3; //3 Bytes, ISO_639_Lang_code desc_len = (*desc_point); desc_point += (desc_len+1); down_desc_pase_size += (desc_len+1+3); } down_desc = (struct SDTT_DL_CONT_DESC_1 *)desc_point; //Point to next download cont desc... } //check version trg_ver = SDTT_MERG_UINT16(content->target_ver_hi,content->target_ver_lo); new_ver = SDTT_MERG_UINT16(content->new_ver_hi,content->new_ver_lo); switch(content->ver_indicator) { case SDTT_VER_INDICAT_ALL: //Do Nothing... break; case SDTT_VER_INDICAT_LATER: if(trg_ver<current_ver) goto NEXT_CONT; break; case SDTT_VER_INDICAT_EARLIER: if(current_ver<trg_ver) goto NEXT_CONT; break; case SDTT_VER_INDICAT_ONLY: if(trg_ver!=current_ver) goto NEXT_CONT; break; } { //Set Timer date_time dtSet,dtGet; UINT32 mjd_time,set_dur_time,get_dur_time = 0,fForce; UINT8 temp; P_NODE p_node; T_NODE t_node; fForce = content->download_level; if(sch_time_N>0) { for(j=0;j<sch_time_N;j++) { #define BCD2DEC(a) ((a>>4)*10+(a&0x0F)) mjd_time =( (((UINT32)sched_time[j].sch_time_start[0])<<8) | (((UINT32)sched_time[j].sch_time_start[1])) ); dtSet.hour = BCD2DEC(sched_time[j].sch_time_start[2]); dtSet.min = BCD2DEC(sched_time[j].sch_time_start[3]); dtSet.sec = BCD2DEC(sched_time[j].sch_time_start[4]); set_dur_time =( (((UINT32)sched_time[j].sch_time_duration[0])<<16) | (((UINT32)sched_time[j].sch_time_duration[1])<<8) | (((UINT32)sched_time[j].sch_time_duration[2])) ); mjd_to_ymd(mjd_time,&dtSet.year,&dtSet.month,&dtSet.day,&temp); api_ota_check_timerinfo(&dtSet,&set_dur_time,&fForce); dtGet = dtSet; get_dur_time = set_dur_time; } } else { //Update Now... get_local_time(&dtSet); convert_time_by_offset2(&dtGet,&dtSet,0,0,3); //Set time as 3 second later... get_dur_time = 1; } if (get_prog_at(m_SdttChanIndex, &p_node) != SUCCESS) return SI_SUCCESS; get_tp_by_id(p_node.tp_id, &t_node); sys_data_set_ota_band(t_node.bandwidth*1000); sys_data_set_ota_freq(t_node.frq); api_ota_timer_open(dtGet,get_dur_time,fForce); } NEXT_CONT: content = (struct sdtt_content *)((UINT8 *)content + sizeof(struct sdtt_content) + cont_desc_len); } #if 0 info->numer_of_content=*(section+sizeof(struct section_header)+6); //get number of content sec_offset=sizeof(struct section_header)+7; //move to start of content for(i=0; i<info->numer_of_content; i++) { content=(struct sdtt_content *)(section+sec_offset); //if (SI_MERGE_UINT16(content->group) ==0x1234) //match group? { //-->It should be fixed!! if (( (current_ver <=(SI_MERGE_UINT16(content->target_ver_hi))) && (content->ver_indicator)==2) || ((current_ver >=(SI_MERGE_UINT16(content->target_ver_hi))) && (content->ver_indicator)==1) || ((current_ver ==(SI_MERGE_UINT16(content->target_ver_hi))) && (content->ver_indicator)==3) || ((content->ver_indicator)==0) ) { // match download // start to get schedule information } } sec_offset+=(4+SI_MERGE_UINT16(content->schedule_ds_len_hi)); } #endif return SI_SUCCESS; }