#include "kit_time.h"


#ifdef NO_OS
    uint32_t sys_tick = 0;
#elif defined UCOS2
    #include "ucos_ii.h"
#endif
    
    
void kitTimeTick(void)
{
#ifdef NO_OS
    sys_tick++;
#elif defined UCOS2
    OSTimeTick();
#endif
}    
    
uint32_t kit_time_get_tick(void)
{
#ifdef NO_OS
 return sys_tick;
#else
 return OSTimeGet();
#endif    
}


KitResult kit_wait_flag(volatile uint32_t *reg, uint32_t flag_bit, int32_t timeout)
{
    KitResult res = kKitResult_Ok;
    
    KIT_ASSERT_PARAM((reg != NULL) && (flag_bit != 0) && (timeout > 0));
    
    while((*reg & flag_bit) == 0)
    {
        if(timeout-- < 0)
        {           
            res = kKitResult_TimeOut;
            break;
        }
    }
    
    return res;
}


    
