Tool/software: TI-RTOS
Dear sir,
We can set the system time by SecondsClock_set(), in s(seconds). But now I want to set up "ms", which API can be used.
Looking forward to your reply.
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI-RTOS
Dear sir,
We can set the system time by SecondsClock_set(), in s(seconds). But now I want to set up "ms", which API can be used.
Looking forward to your reply.
Hi User5183550,
There is no BIOS API for setting the msecs for the system time.
Best regards,
Janet
Dear Janet
I need to setting msecs,which is important for my new project, hoping your team can give some Suggestions.
Best regards,
frank
Hi Frank,
You can write your own version of SecondsClock that allows you to set the milliseconds. I wrote a very simple example that doesn't adjust for drift caused by the timer frequency not being a multiple of 1000. This may be ok for the processor you're using. I'm attaching the source file.
Best regards,
Janet
/*
* Copyright (c) 2015-2017, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== clock.c ========
*/
/* XDC module Headers */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
/* BIOS module Headers */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/hal/Hwi.h>
/* Example/Board Header files */
#include "Board.h"
Void clk0Fxn(UArg arg0);
Void clk1Fxn(UArg arg0);
Clock_Handle msecClock;
typedef struct MSecClock_Module {
UInt32 ticks;
UInt32 seconds;
} MSecClock_Module;
Void MSecClock_increment(UArg arg0);
Void tskFunc(UArg arg0, UArg arg1);
MSecClock_Module MSecClock_moduleState, *MSecClock_module;
/*
* ======== main ========
*/
int main()
{
/* Construct BIOS Objects */
Clock_Params clkParams;
/* Call driver init functions */
Board_initGeneral();
MSecClock_module = &MSecClock_moduleState;
MSecClock_module->ticks = 0;
MSecClock_module->seconds = 0;
Clock_Params_init(&clkParams);
clkParams.period = 1000000 / Clock_tickPeriod;
clkParams.startFlag = TRUE;
/* Create a Clock with period and initial timeout of 1 second */
msecClock = Clock_create((Clock_FuncPtr)MSecClock_increment,
1000000 / Clock_tickPeriod, &clkParams, NULL);
Clock_start(msecClock);
Task_create(tskFunc, NULL, NULL);
BIOS_start(); /* does not return */
return(0);
}
/*
* ======== MSecClock_increment =======
*/
Void MSecClock_increment(UArg arg0)
{
MSecClock_module->ticks = Clock_getTicks();
MSecClock_module->seconds++;
}
Void MSecClock_get(UInt32 *seconds, UInt32 *msecs)
{
UInt key;
UInt32 ticks;
key = Hwi_disable();
*seconds = MSecClock_module->seconds;
ticks = Clock_getTicks() - MSecClock_module->ticks;
Hwi_restore(key);
*msecs = ticks * (Clock_tickPeriod / 1000);
}
Void MSecClock_set(UInt32 seconds, UInt32 msecs)
{
UInt32 timeout;
UInt32 msecTicks;
UInt key;
/* If msecs >= 1000, error */
msecTicks = msecs * 1000 / Clock_tickPeriod;
Clock_stop(msecClock);
/* Set clock timeout to 1000 - msecs converted to Clock ticks */
timeout = 1000000 / Clock_tickPeriod - msecTicks;
Clock_setTimeout(msecClock, timeout);
key = Hwi_disable();
MSecClock_module->seconds = seconds;
MSecClock_module->ticks = Clock_getTicks() - msecTicks;
Clock_start(msecClock);
Hwi_restore(key);
}
Void tskFunc(UArg arg0, UArg arg1)
{
UInt32 secs, msecs;
MSecClock_set(10, 100);
/* Sleep for 2 msecs */
Task_sleep(2000 / Clock_tickPeriod);
MSecClock_get(&secs, &msecs);
System_printf("Seconds = %d, msecs = %d\n", secs, msecs);
/* Sleep for 2 seconds, 995 msecs */
Task_sleep(2995000 / Clock_tickPeriod);
MSecClock_get(&secs, &msecs);
System_printf("Seconds = %d, msecs = %d\n", secs, msecs);
BIOS_exit(0);
}