| /* |
| * Copyright (C) 2018 Synaptics Incorporated. All rights reserved. |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 as |
| * published by the Free Software Foundation. |
| * |
| * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND |
| * SYNAPTICS EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, |
| * INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| * A PARTICULAR PURPOSE, AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY |
| * INTELLECTUAL PROPERTY RIGHTS. IN NO EVENT SHALL SYNAPTICS BE LIABLE |
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, OR |
| * CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION WITH THE USE |
| * OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED AND |
| * BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS |
| * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF |
| * COMPETENT JURISDICTION DOES NOT PERMIT THE DISCLAIMER OF DIRECT |
| * DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS' TOTAL CUMULATIVE LIABILITY |
| * TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S. DOLLARS. |
| */ |
| #include "diag_common.h" |
| #include "diag_misc.h" |
| #include "apbRegBase.h" |
| #include <string.h> |
| #include <stdarg.h> |
| #include <stdio.h> |
| #include <malloc.h> |
| |
| /************************************************************ |
| Timer Service |
| ************************************************************/ |
| // using cpu generic timer for delay |
| #define TIMER_CLOCK_KHZ GENERIC_TIMER_CLOCK_KHZ_REAL |
| #define TIMER_BASE (SM_APB_TIMER0_BASE+0x00) // use SM_TIMER0, fixed 25MHz on ASIC. |
| |
| /************************************************************ |
| for performance debug |
| ************************************************************/ |
| int sys_flag_performance_meter_enable = 0; |
| |
| extern unsigned long long arm_get_CNTPCT(); |
| |
| void timer_start() |
| { |
| // always started |
| } |
| |
| unsigned int timer_get() |
| { |
| return arm_get_CNTPCT(); |
| } |
| int timer_is_enabled() |
| { |
| return 1; |
| } |
| |
| unsigned int timer_cycle2us(unsigned int cycles) |
| { |
| if (cycles > ((unsigned int)-1)/1000) |
| { |
| return (cycles/TIMER_CLOCK_KHZ) * 1000; |
| } |
| else |
| { |
| return cycles*1000/TIMER_CLOCK_KHZ; |
| } |
| } |
| |
| unsigned int timer_us2cycle(unsigned int us) |
| { |
| if (us > (0xFFFFFFFF/TIMER_CLOCK_KHZ)) |
| { |
| return us/1000*TIMER_CLOCK_KHZ; |
| } |
| else |
| { |
| return us*TIMER_CLOCK_KHZ/1000; |
| } |
| } |
| |
| // for mutil-core |
| void diag_delay_us_real(unsigned int count) |
| { |
| unsigned int start_time; |
| if (count > 50*1000) |
| { |
| count = (count/1000)*TIMER_CLOCK_KHZ; // 25MHz SM timer clock |
| } |
| else |
| { |
| count = count*TIMER_CLOCK_KHZ/1000; // 25MHz SM timer clock |
| } |
| |
| if (timer_is_enabled() == 0) |
| { |
| timer_start(); |
| } |
| start_time = timer_get(); |
| while((unsigned int)(timer_get() - start_time) < count); |
| |
| return; |
| } |
| |
| void diag_delay_us(unsigned int us) // in virtual world |
| { |
| diag_delay_us_real((us)*(CPU_CLOCK_VIRTUAL_KHZ/CPU_CLOCK_KHZ)); |
| } |
| |