寄存器自动化测试说明及时使用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.7 KiB

  1. /*
  2. * Copyright 2002 by Texas Instruments Incorporated.
  3. * All rights reserved. Property of Texas Instruments Incorporated.
  4. * Restricted rights to use, duplicate or disclose this code are
  5. * granted through contract.
  6. *
  7. */
  8. /* "@(#) DSP/BIOS 4.80.188 12-06-02 (bios,dsk5416-a11)" */
  9. /******************************************************************************\
  10. * Copyright (C) 2000 Texas Instruments Incorporated.
  11. * All Rights Reserved
  12. *------------------------------------------------------------------------------
  13. * FILENAME...... timer.c
  14. * DATE CREATED.. 01/11/2000
  15. * LAST MODIFIED. 12/29/2000
  16. \******************************************************************************/
  17. #include <stdio.h>
  18. #include <csl.h>
  19. #include <csl_irq.h>
  20. #include <csl_timer.h>
  21. #include "uart.h"
  22. /*----------------------------------------------------------------------------*/
  23. /* In this exmaple, we are simply setting the timer to interrupt */
  24. /* every 0x800 clock cycles. All timer setup will be done in a */
  25. /* TASK function that executes after exit from "main" */
  26. /* Create a timer control structure */
  27. TIMER_Config myTConfig = {
  28. TIMER_TCR_RMK(
  29. TIMER_TCR_SOFT_WAITZERO,
  30. TIMER_TCR_FREE_NOSOFT,
  31. TIMER_TCR_TRB_RESET,
  32. TIMER_TCR_TSS_START,
  33. TIMER_TCR_TDDR_OF(0)
  34. ), /* TCR0 */
  35. 0x0800u /* PRD0 */
  36. };
  37. /* Global declarations */
  38. TIMER_Handle mhTimer;
  39. volatile Uint16 timer_int_cnt = 0;
  40. interrupt void timerIsr(void);
  41. void taskFunc(void);
  42. /*----------------------------------------------------------------------------*/
  43. void main() {
  44. uart_puts("C5416 Timer Test Start...\n");
  45. /* Initialize CSL library, this step is required */
  46. CSL_init();
  47. /* Call example task/function */
  48. taskFunc();
  49. }
  50. /*----------------------------------------------------------------------------*/
  51. void taskFunc(void) {
  52. Uint16 eventId;
  53. int old_intm;
  54. Uint16 err = 0;
  55. //printf("<TIMER>\n");
  56. uart_puts("<TIMER>\n");
  57. /* Temporarily disable all maskable interrupts, preserving */
  58. /* previous state of INTM */
  59. old_intm = IRQ_globalDisable();
  60. /* Open Timer 0, this returns a pointer to a Timer Handle */
  61. /* that will be used as an argument to other CSL functions */
  62. mhTimer = TIMER_open(TIMER_DEV0, TIMER_OPEN_RESET);
  63. /* Write configuration structure values to Timer control */
  64. /* registers. */
  65. TIMER_config(mhTimer, &myTConfig);
  66. /* Get Event ID associated with Timer interrupt */
  67. eventId = TIMER_getEventId(mhTimer);
  68. /* Clear any pending Timer interrupts */
  69. IRQ_clear(eventId);
  70. /* Place interrupt service routine address at associated vector */
  71. IRQ_plug(eventId,timerIsr);
  72. /* Enable Timer interrupt */
  73. IRQ_enable(eventId);
  74. /* Enable all maskable interrupts */
  75. IRQ_globalEnable();
  76. /* Start Timer */
  77. TIMER_start(mhTimer);
  78. /* wait for 20 timer periods */
  79. while(timer_int_cnt < 20);
  80. /* We are through with the Timer, so close it */
  81. TIMER_close(mhTimer);
  82. /* Restore old value of INTM */
  83. IRQ_globalRestore(old_intm);
  84. if (timer_int_cnt < 20)
  85. ++err;
  86. //printf("%s\n",err?"TEST FAILED":"TEST PASSED");
  87. //printf("<DONE>\n");
  88. if (err)
  89. uart_puts("TEST FAILED\n");
  90. else
  91. uart_puts("TEST PASSED\n");
  92. uart_puts("<DONE>\n");
  93. }
  94. /*----------------------------------------------------------------------------*/
  95. /* Timer ISR - will be called by DSP/BIOS dispatcher */
  96. interrupt void timerIsr(void) {
  97. TIMER_stop(mhTimer);
  98. timer_int_cnt = timer_int_cnt + 1;
  99. if (timer_int_cnt < 20) {
  100. TIMER_start(mhTimer);
  101. }
  102. uart_puts("Entry Timer Isr function...\n");
  103. }