寄存器自动化测试说明及时使用
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.

136 lines
3.8 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. while(1);
  50. }
  51. /*----------------------------------------------------------------------------*/
  52. void taskFunc(void) {
  53. Uint16 eventId;
  54. int old_intm;
  55. Uint16 err = 0;
  56. //printf("<TIMER>\n");
  57. uart_puts("<TIMER>\n");
  58. /* Temporarily disable all maskable interrupts, preserving */
  59. /* previous state of INTM */
  60. old_intm = IRQ_globalDisable();
  61. /* Open Timer 0, this returns a pointer to a Timer Handle */
  62. /* that will be used as an argument to other CSL functions */
  63. mhTimer = TIMER_open(TIMER_DEV0, TIMER_OPEN_RESET);
  64. /* Write configuration structure values to Timer control */
  65. /* registers. */
  66. TIMER_config(mhTimer, &myTConfig);
  67. /* Get Event ID associated with Timer interrupt */
  68. eventId = TIMER_getEventId(mhTimer);
  69. /* Clear any pending Timer interrupts */
  70. IRQ_clear(eventId);
  71. /* Place interrupt service routine address at associated vector */
  72. IRQ_plug(eventId,timerIsr);
  73. /* Enable Timer interrupt */
  74. IRQ_enable(eventId);
  75. /* Enable all maskable interrupts */
  76. IRQ_globalEnable();
  77. /* Start Timer */
  78. TIMER_start(mhTimer);
  79. /* wait for 20 timer periods */
  80. while(timer_int_cnt < 20);
  81. /* We are through with the Timer, so close it */
  82. TIMER_close(mhTimer);
  83. /* Restore old value of INTM */
  84. IRQ_globalRestore(old_intm);
  85. if (timer_int_cnt < 20)
  86. ++err;
  87. //printf("%s\n",err?"TEST FAILED":"TEST PASSED");
  88. //printf("<DONE>\n");
  89. if (err)
  90. uart_puts("TEST FAILED\n");
  91. else
  92. uart_puts("TEST PASSED\n");
  93. uart_puts("<DONE>\n");
  94. }
  95. /*----------------------------------------------------------------------------*/
  96. /* Timer ISR - will be called by DSP/BIOS dispatcher */
  97. interrupt void timerIsr(void) {
  98. TIMER_stop(mhTimer);
  99. timer_int_cnt = timer_int_cnt + 1;
  100. if (timer_int_cnt < 20) {
  101. TIMER_start(mhTimer);
  102. }
  103. uart_puts("Entry Timer Isr function...\n");
  104. }