/*********************************************************************************************************************
* 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_delay
* ˾          ɶɿƼ޹˾
* 汾Ϣ          鿴 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_delay.h"



//-------------------------------------------------------------------------------------------------------------------
//        systemʱ
//  ˵      time            ʱһֵʱ䣨λΪ룬÷Χ0-20000000
//  ˵      num             ʱ
//  ز      void
//  ʹʾ      ûãûʹhļеĺ궨
//-------------------------------------------------------------------------------------------------------------------
void system_delay (uint32 time, uint32 num)
{
    uint32 stm_clk;
    uint32 delay_time;
    stm_clk = IfxStm_getFrequency(IfxStm_getAddress((IfxStm_Index)(IfxCpu_getCoreId())));
    delay_time = (uint32)(stm_clk/1000000*time/1000);

    while(num--)
    {
        IfxStm_waitTicks(IfxStm_getAddress((IfxStm_Index)(IfxCpu_getCoreId())), delay_time);
    }
}


//-------------------------------------------------------------------------------------------------------------------
//        system ΢ ʱ
//  ˵      time            ʱʱ  λus
//  ز      void
//  ʹʾ      system_delay_us(100);  // ʱ100΢
//-------------------------------------------------------------------------------------------------------------------
void system_delay_us (uint32 time)
{
    system_delay(time*1000, 1);
}

//-------------------------------------------------------------------------------------------------------------------
//        system  ʱ
//  ˵      time            ʱʱ  λms
//  ز      void
//  ʹʾ      system_delay_ms(100);  // ʱ100
//-------------------------------------------------------------------------------------------------------------------
void system_delay_ms (uint32 time)
{
    system_delay(1000000, time);
}

