static uint_32 __psp_ticks_to_nanoseconds ( /* [IN] Ticks to be converted */ PSP_TICK_STRUCT_PTR tick_ptr, /* [OUT] pointer to where the overflow boolean is to be written */ boolean _PTR_ overflow_ptr, /* [IN] boolean to control rounding or truncating */ boolean round ) { /* Body */ PSP_128_BIT_UNION tmp; KERNEL_DATA_STRUCT_PTR kernel_data; _GET_KERNEL_DATA(kernel_data); #if (PSP_ENDIAN == MQX_BIG_ENDIAN) tmp.LLW[1] = tick_ptr->TICKS[0]; tmp.LLW[0] = 0; #else tmp.LLW[0] = tick_ptr->TICKS[0]; tmp.LLW[1] = 0; #endif /* Convert ticks to hardware ticks */ _psp_mul_128_by_32(&tmp, kernel_data->HW_TICKS_PER_TICK, &tmp); /* Add in hardware ticks */ _psp_add_element_to_array(tmp.LW, tick_ptr->HW_TICKS[0], sizeof(PSP_128_BIT_UNION) / sizeof(uint_32), tmp.LW); /* ** Convert hardware ticks to ns. (H / (T/S * H/T) * 1000000000) ** Multiply by an extra 10 for rounding purposes. */ _psp_mul_128_by_32(&tmp, 1000000000, &tmp); _psp_mul_128_by_32(&tmp, 10, &tmp); _psp_div_128_by_32(&tmp, kernel_data->TICKS_PER_SECOND, &tmp); _psp_div_128_by_32(&tmp, kernel_data->HW_TICKS_PER_TICK, &tmp); /* Round OR Truncate*/ if (round) { _psp_add_element_to_array(tmp.LW, 5, sizeof(PSP_128_BIT_UNION) / sizeof(uint_32), tmp.LW); } _psp_div_128_by_32(&tmp, 10, &tmp); #if (PSP_ENDIAN == MQX_BIG_ENDIAN) *overflow_ptr = tmp.LLW[0] || tmp.LW[2]; return tmp.LW[3]; #else *overflow_ptr = tmp.LLW[1] || tmp.LW[1]; return tmp.LW[0]; #endif } /* Endbody */
/*! * \brief This function converts picoseconds into ticks. Note, there is no way to * represent MAX_UINT_16 picoseconds in terms of ticks. * * \param[in] psecs The number of picoseconds to convert * \param[out] tick_ptr Pointer to tick structure where the result will be stored */ void _psp_psecs_to_ticks ( /* [IN] The number of picoseconds to convert */ _mqx_uint psecs, /* [OUT] Pointer to tick structure where the result will be stored */ PSP_TICK_STRUCT_PTR tick_ptr ) { /* Body */ PSP_128_BIT_UNION tmp; KERNEL_DATA_STRUCT_PTR kernel_data; _GET_KERNEL_DATA(kernel_data); #if PSP_ENDIAN == MQX_LITTLE_ENDIAN tmp.LLW[1] = 0; tmp.LLW[0] = (uint64_t)psecs * kernel_data->TICKS_PER_SECOND; tick_ptr->TICKS[0] = tmp.LLW[0] / (1000ULL * 1000 * 1000 * 1000); /* Calculate the remaining picoticks */ tmp.LLW[0] %= (1000ULL * 1000 * 1000 * 1000); #else tmp.LLW[0] = 0; tmp.LLW[1] = (uint64_t)psecs * kernel_data->TICKS_PER_SECOND; tick_ptr->TICKS[0] = tmp.LLW[1] / (1000ULL * 1000 * 1000 * 1000); /* Calculate the remaining picoticks */ tmp.LLW[1] %= (1000ULL * 1000 * 1000 * 1000); #endif /* Convert to hardware ticks */ _psp_mul_128_by_32(&tmp, kernel_data->HW_TICKS_PER_TICK, &tmp); _psp_div_128_by_32(&tmp, 1000UL * 1000 * 1000, &tmp); _psp_div_128_by_32(&tmp, 1000, &tmp); #if PSP_ENDIAN == MQX_LITTLE_ENDIAN tick_ptr->HW_TICKS[0] = tmp.LW[0]; #else tick_ptr->HW_TICKS[0] = tmp.LW[3]; #endif } /* Endbody */