Beispiel #1
0
//------------------------------------------------------------------------------
/// Currnet time is returned with packed into a DWORD value.
/// The bit field is as follows:
///   bit31:25  Year from 1980 (0..127)
///   bit24:21  Month (1..12)
///   bit20:16  Day in month(1..31)
///   bit15:11  Hour (0..23)
///   bit10:5   Minute (0..59)
///   bit4:0    Second / 2 (0..29)
//------------------------------------------------------------------------------
DWORD get_fattime(void)
{
	U32 time;

	time = ((RTC_GetYear()+2000-1980)<<25) | (RTC_GetMonth()<<21) | (RTC_GetDate()<<16) | (RTC_GetHour()<<11) | (RTC_GetMinute()<<5) | ((RTC_GetSec()/2)<<0);
	return time;
}
/*******************************************************************************
* Function Name: WriteSkierResult
********************************************************************************
*
* Summary:
*  Start log system(mount fat)
*
* Parametrs:
*   *data - pointer from result skiers
* Return:
*   resultF - result mount FAT system (from enum FRESULT)
*
*******************************************************************************/
uint32_t WriteSkierResult(skierDB_El *data)
{
    uint8 resultF;
    uint count;
    
    uint32_t nameYear;
    uint32_t nameMonth;
    uint32_t nameDay;
    uint32_t date;
    
    /*get date from RTC*/
    date = RTC_GetDate();
    nameYear = RTC_GetYear(date)-2000;
    nameMonth = RTC_GetMonth(date);
    nameDay = RTC_GetDay(date);
    
    /*Construct name of file in format dd_mm_yyyy*/
    sprintf(nameFile,"%02d_%02d_%d.txt",nameDay,nameMonth,nameYear);
    createFlag = 0;
    resultF = f_open(&fileO, nameFile, FA_WRITE | FA_OPEN_APPEND, &createFlag);
    
    if(resultF == RES_OK)
    {
        /*Construct save data*/
        char start[LEN_DATA];
        char finish[LEN_DATA];
        char result[LEN_DATA];
        char writeData[LEN_DATA_ALL];
        
        RTC_DATE_TIME time;
        
        
        /*read unix time*/
        RTC_UnixToDateTime(&time, data->unixStartSkier, RTC_24_HOURS_FORMAT);
        sprintf(start, "\t\t%02lu:%02lu:%02lu:%03u",RTC_GetHours(time.time),RTC_GetMinutes(time.time),RTC_GetSecond(time.time),data->millsStartSkier);
        RTC_UnixToDateTime(&time, data->unixFinishSkier, RTC_24_HOURS_FORMAT);
        sprintf(finish, "\t\t%02lu:%02lu:%02lu:%03u",RTC_GetHours(time.time),RTC_GetMinutes(time.time),RTC_GetSecond(time.time),data->millsFinishSkier);
        sprintf(result, "\t\t%02lu:%03u",(uint32)data->secondsWay,data->millsWay);
        sprintf(writeData,"\n\r%d%s%s%s\n\r",position, start, finish, result);
              
        if((position == 1) || (createFlag == 1))
        {
            /*write new "cap"*/
            uint32_t tmpTime ;
            
            tmpTime = RTC_GetTime();
            f_printf(&fileO,"\r\nSystem started %02d:%02d:%02d\n\r", RTC_GetHours(tmpTime),RTC_GetMinutes(tmpTime),RTC_GetSecond(tmpTime));
            f_printf(&fileO,"--------------------------------------------------\n\r");
            f_printf(&fileO,"NUM\t\tSTART\t\t\tFINISH\t\t\tRESULT\n\r");
            f_printf(&fileO,"--------------------------------------------------\n\r");
            
        }
        
        /*write data*/
        resultF = f_write(&fileO, writeData, strlen(writeData),&count);
        resultF = f_close(&fileO);
        position++;
    }
    
    return resultF;
}
Beispiel #3
0
UINT32 RTC_GetSecondsSinceEpoch()
{
    UINT32 nowDays = RTC_GetTotalDays((RTC_GetCentury() * 100) + RTC_GetYear(), RTC_GetMonth(), RTC_GetDayOfTheMonth());
    UINT32 epochDays = RTC_GetTotalDays(1970, 1, 1);
    return ((nowDays - epochDays) * 24 * 60 * 60) + (RTC_GetHour() * 60 * 60) + (RTC_GetMinute() * 60) + RTC_GetSecond();
}
Beispiel #4
0
/* Send RTC Date value to hyperterminal */
void demo0(void)
{
    /* Get RTC Date value */
    Year = RTC_GetYear();
    Month = RTC_GetMonth();
    Date = RTC_GetDate(RTC_CLOCK_MODE);
    Day = RTC_GetDay(RTC_CLOCK_MODE);
    /* Set UART0 display */
    /* Dispaly year */
    RTC_Disp_YMD[0] = ' ';
    RTC_Disp_YMD[1] = (Year / 10U) + 0x30U;
    RTC_Disp_YMD[2] = (Year % 10U) + 0x30U;
    RTC_Disp_YMD[3] = '-';
    /* Display month */
    RTC_Disp_YMD[4] = (Month / 10U) + 0x30U;
    RTC_Disp_YMD[5] = (Month % 10U) + 0x30U;
    RTC_Disp_YMD[6] = '-';
    /* Display date */
    RTC_Disp_YMD[7] = (Date / 10U) + 0x30U;
    RTC_Disp_YMD[8] = (Date % 10U) + 0x30U;

    RTC_Disp_YMD[9] = ' ';
    RTC_Disp_YMD[10] = ' ';
    RTC_Disp_YMD[11] = ' ';
    /* Display day */
    switch (Day) {
    case RTC_SUN:
        RTC_Disp_YMD[12] = 'S';
        RTC_Disp_YMD[13] = 'U';
        RTC_Disp_YMD[14] = 'N';
        break;
    case RTC_MON:
        RTC_Disp_YMD[12] = 'M';
        RTC_Disp_YMD[13] = 'O';
        RTC_Disp_YMD[14] = 'N';
        break;
    case RTC_TUE:
        RTC_Disp_YMD[12] = 'T';
        RTC_Disp_YMD[13] = 'U';
        RTC_Disp_YMD[14] = 'E';
        break;
    case RTC_WED:
        RTC_Disp_YMD[12] = 'W';
        RTC_Disp_YMD[13] = 'E';
        RTC_Disp_YMD[14] = 'D';
        break;
    case RTC_THU:
        RTC_Disp_YMD[12] = 'T';
        RTC_Disp_YMD[13] = 'H';
        RTC_Disp_YMD[14] = 'U';
        break;
    case RTC_FRI:
        RTC_Disp_YMD[12] = 'F';
        RTC_Disp_YMD[13] = 'R';
        RTC_Disp_YMD[14] = 'I';
        break;
    case RTC_SAT:
        RTC_Disp_YMD[12] = 'S';
        RTC_Disp_YMD[13] = 'A';
        RTC_Disp_YMD[14] = 'T';
        break;
    default:
        /* Do nothing */
        break;
    }
    RTC_Disp_YMD[15] = '\0';
	UART_Print(UART, RTC_Disp_YMD);
}