/*********************************************************************************************************************
* TC264 Opensourec Library TC264 Դ⣩һڹٷ SDK ӿڵĵԴ
* Copyright (c) 2022 SEEKFREE ɿƼ
*
* ļ TC264 Դһ
*
* TC264 Դ 
* Ըᷢ GPLGNU General Public License GNUͨù֤
*  GPL ĵ3棨 GPL3.0ѡģκκİ汾·/޸
*
* Դķϣܷãδκεı֤
* ûԻʺض;ı֤
* ϸμ GPL
*
* ӦյԴͬʱյһ GPL ĸ
* ûУ<https://www.gnu.org/licenses/>
*
* ע
* Դʹ GPL3.0 Դ֤Э Ϊİ汾
* Ӣİ libraries/doc ļµ GPL3_permission_statement.txt ļ
* ֤ libraries ļ ļµ LICENSE ļ
* ӭλʹò ޸ʱ뱣ɿƼİȨ
*
* ļ          zf_driver_timer
* ˾          ɶɿƼ޹˾
* 汾Ϣ          鿴 libraries/doc ļ version ļ 汾˵
*           ADS v1.9.4
* ƽ̨          TC264D
*           https://seekfree.taobao.com/
*
* ޸ļ¼
*                               ע
* 2022-09-15       pudding            first version
********************************************************************************************************************/

#include "IfxStm.h"
#include "IFXSTM_CFG.h"
#include "zf_driver_timer.h"

static uint32 systick_count[2];

//-------------------------------------------------------------------------------------------------------------------
//        systickʱ
//  ز      void
//  ʹʾ      system_start(); // ʱ¼µǰʱ
//-------------------------------------------------------------------------------------------------------------------
void system_start (void)
{
    systick_count[(IfxCpu_getCoreId())] = IfxStm_getLower(IfxStm_getAddress((IfxStm_Index)(IfxCpu_getCoreId())));
}

//-------------------------------------------------------------------------------------------------------------------
//       õǰSystem tick timerֵ
//  ز     uint32           شӿʼڵʱ(λ10ns)
//  ʹʾ     uint32 tim = system_getval();
//  עϢ     ں0ô˺ʹSTM0ģ  1ʹSTM1ģ
//-------------------------------------------------------------------------------------------------------------------
uint32 system_getval (void)
{
    uint32 time;
    uint32 stm_clk;

    stm_clk = IfxStm_getFrequency(IfxStm_getAddress((IfxStm_Index)(IfxCpu_getCoreId())));

    time = IfxStm_getLower(IfxStm_getAddress((IfxStm_Index)(IfxCpu_getCoreId())));
    time = time - systick_count[(IfxCpu_getCoreId())];
    time = (uint32)((uint64)time * 100000000 / stm_clk);

    return time;
}




