clock_tests.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * * Neither the name of Code Aurora nor
  12. * the names of its contributors may be used to endorse or promote
  13. * products derived from this software without specific prior written
  14. * permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  23. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  25. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. */
  29. #include <debug.h>
  30. #include <string.h>
  31. #include <app.h>
  32. #include <platform.h>
  33. #include <kernel/thread.h>
  34. #include <err.h>
  35. #if defined(WITH_LIB_CONSOLE) && defined(DEBUG_CLOCK)
  36. #include <lib/console.h>
  37. #include <clock.h>
  38. static void print_clock_list()
  39. {
  40. unsigned i;
  41. struct clk_lookup *cl;
  42. unsigned num;
  43. struct clk_list *clock_list = clk_get_list();
  44. if(!clock_list)
  45. return;
  46. cl = clock_list->clist;
  47. num = clock_list->num;
  48. if(!cl || !num)
  49. return;
  50. printf("Clock list:\n");
  51. for(i=0; i < num; i++, cl++)
  52. {
  53. printf("%s\n", cl->con_id);
  54. }
  55. }
  56. static int clock_measure(const char *id)
  57. {
  58. int ret = NO_ERROR;
  59. struct clk *cp, *mcp;
  60. unsigned long rate;
  61. /* Get clk */
  62. cp = clk_get(id);
  63. if(!cp)
  64. {
  65. ret = ERR_NOT_VALID;
  66. goto measure_error;
  67. }
  68. /* Get measure clk */
  69. mcp = clk_get("measure");
  70. if(!mcp)
  71. {
  72. ret = ERR_NOT_VALID;
  73. goto measure_error;
  74. }
  75. /* Set parent clk */
  76. clk_set_parent(mcp, cp);
  77. rate = clk_get_rate(mcp);
  78. printf("Clock %s is running at: %lu Hz.\n", id, rate);
  79. measure_error:
  80. return ret;
  81. }
  82. static int clock_tests(int argc, cmd_args *argv)
  83. {
  84. if (argc < 2) {
  85. printf("not enough arguments:\n");
  86. printf("%s <clock-name>\n", argv[0].str);
  87. printf("%s ?\n", argv[0].str);
  88. goto out;
  89. }
  90. if(argv[1].str[0] == '?')
  91. print_clock_list();
  92. else
  93. clock_measure(argv[1].str);
  94. out:
  95. return 0;
  96. }
  97. STATIC_COMMAND_START
  98. { "test_clock", "Test Clock", &clock_tests },
  99. STATIC_COMMAND_END(clocktests);
  100. #endif
  101. APP_START(clocktests)
  102. APP_END