uhal.c
上传用户:jinguanrq
上传日期:2022-06-04
资源大小:724k
文件大小:5k
源码类别:

uCOS

开发平台:

C/C++

  1. #include <stdarg.h>
  2. #include <string.h>
  3. #include "uhal.h"
  4. #include "44b.h"
  5. #include "44blib.h"
  6. //#######################SLT#######################
  7. //mclk 66000000
  8. //66000000hz/4= 16500000
  9. ///16500000/100= 165000
  10. // 1/165000*SEC==> SEC*165
  11. #define _TICK 1000 //  1/1000 sec
  12. //#define _TICK 100 //  1/100 sec
  13. //#define _TICK 10 //  1/10 sec
  14. #define _CLOCK (165*(1000/_TICK))
  15. #define MAX_TBUF 2048
  16. static char tbuf[MAX_TBUF]= {0, }; //for uHALr_printf
  17. //for debugging
  18. void  BreakPoint(void);
  19. void  DebugUNDEF(void);
  20. void  DebugSWI(void);
  21. void  DebugABORT(void);
  22. void  DebugFIQ(void);
  23. //timer interrupt handler routine
  24. extern void TickHandler(void);
  25. //for interrupt enable or disable
  26. extern void ARMDisableInt(void);
  27. extern void ARMEnableInt(void);
  28. //Output through LCD or serial port to print information.
  29. extern int vsprintf(const char *format, ...);
  30. int uHALr_printf(const char *format, ...)
  31. {
  32. va_list v_list;
  33. char *ptr;
  34. int i= 0;
  35. va_start(v_list, format); // Initialize variable arguments. 
  36. vsprintf(tbuf, format, v_list ); 
  37. va_end(v_list);
  38. ptr= tbuf;
  39. while( (*ptr) && i<MAX_TBUF) {
  40. Uart_SendByte(*ptr);
  41. ptr++; i++;
  42. }//while
  43. return 1;
  44. }//uHALr_printf
  45. /*** Called by ARMTargetInit() ***/
  46. //disable memory management unit.S3C44B0X无MMU功能,函数为空
  47. void uHALr_ResetMMU(void)
  48. {
  49. }//uHALrResetMMU
  50. void (*pre_isr)(void);
  51. void *(*post_isr)(void);
  52. //Define pre & post-process routines for Interrupt.
  53. void uHALir_DefineIRQ(void *is, void *iq, void *n)
  54. {
  55. pre_isr= (void (*)(void))is;
  56. post_isr= (void *(*)(void))iq;
  57. }//uHALir_DefineIRQ
  58. //Initialze interrupts.
  59. void uHALr_InitInterrupts(void)
  60. {
  61. //set interrupt vector routine
  62. // pISR_RESET //reserved
  63. pISR_UNDEF= (unsigned) DebugUNDEF;
  64. pISR_SWI= (unsigned) DebugSWI;
  65. pISR_PABORT= (unsigned) DebugABORT;
  66. pISR_DABORT= (unsigned) DebugABORT;
  67. pISR_RESERVED= (unsigned) BreakPoint; //not used
  68. // pISR_IRQ= (unsigned) 0; //reserved
  69. pISR_FIQ= (unsigned) DebugFIQ;
  70. pISR_ADC= (unsigned) BreakPoint;
  71. pISR_RTC= (unsigned) BreakPoint;
  72. pISR_UTXD1= (unsigned) BreakPoint;
  73. pISR_UTXD0= (unsigned) BreakPoint;
  74. pISR_SIO= (unsigned) BreakPoint;
  75. pISR_IIC= (unsigned) BreakPoint;
  76. pISR_URXD1= (unsigned) BreakPoint;
  77. pISR_URXD0= (unsigned) BreakPoint;
  78. pISR_TIMER5= (unsigned) BreakPoint;
  79. pISR_TIMER4= (unsigned) BreakPoint;
  80. pISR_TIMER3= (unsigned) BreakPoint;
  81. pISR_TIMER2= (unsigned) BreakPoint;
  82. pISR_TIMER1= (unsigned) BreakPoint;
  83. pISR_TIMER0= (unsigned) TickHandler; //handler setting
  84. pISR_UERR01= (unsigned) BreakPoint;
  85. pISR_WDT= (unsigned) BreakPoint;
  86. pISR_BDMA1= (unsigned) BreakPoint;
  87. pISR_BDMA0= (unsigned) BreakPoint;
  88. pISR_ZDMA1= (unsigned) BreakPoint;
  89. pISR_ZDMA0= (unsigned) BreakPoint;
  90. pISR_TICK= (unsigned) BreakPoint;
  91. // pISR_EINT4567= (unsigned) UserIRQ;
  92. pISR_EINT3= (unsigned) BreakPoint;
  93. pISR_EINT2= (unsigned) BreakPoint;
  94. pISR_EINT1= (unsigned) BreakPoint;
  95. pISR_EINT0= (unsigned) BreakPoint;
  96. }//uHALr_InitInterrupts
  97. //Initialize timer that is used OS.
  98. void uHALr_InitTimers(void)
  99. {
  100. rTCFG0= 0x00000064;  //dead zone=0, pre0= 100
  101. rTCFG1= 0x00000001;  //all interrupt, mux0= 1/4
  102. rTCNTB0= _CLOCK;     //set T0 count
  103.     rTCON= 0x00000002;   //update T0
  104.     rINTPND = 0x00002000; /* T0 interrupt clear */
  105. rTCON= 0x00000009;   //T0,auto reload and start
  106. }//uHALr_InitTimers
  107. /*** Called by ARMTargetStart() ***/
  108. //Request the system timer.
  109. //return value 1:success   0:fail
  110. int uHALr_RequestSystemTimer(void *tick, const unsigned char *str)
  111. {
  112. return 1;
  113. }//uHALr_RequestSystemTimer
  114. //Start system timer & enable the interrupt.
  115. void uHALr_InstallSystemTimer(void)
  116. {
  117. rINTMSK=~( BIT_TIMER0 | BIT_GLOBAL); //Non maksed TIMER0
  118. }//uHALr_InstallSystemTimer
  119. /*
  120. * Sys_Interrupt: Interrupt
  121. */
  122. void SysENInterrupt(unsigned ISPC_BIT)//, void (*handler)(void))
  123. {
  124. rINTMSK &=~( ISPC_BIT | BIT_GLOBAL); //Default value=0x7ffffff
  125. }
  126. void SysDISInterrupt(unsigned ISPC_BIT)//, void (*handler)(void))
  127. {
  128. rINTMSK |= ISPC_BIT; //Default value=0x7ffffff
  129. }
  130. //////////////////////////////////////////////////////////////////
  131. //routines for debugging
  132. //////////////////////////////////////////////////////////////////
  133. void OutDebug(unsigned int num)
  134. {
  135. uHALr_printf("rn***STACK***:%drn", num);
  136. }//OutDebug
  137. void  BreakPoint(void)
  138. {
  139. char m=200;
  140. uHALr_printf("!!!Enter break point.");
  141. while(m) {
  142. Led_Display(0xf);
  143. Delay(1000);
  144. Led_Display(0x0);
  145. Delay(1000);
  146. m--;
  147. }//while
  148. }//BreakPoint
  149. //extern 
  150. int I_COUNT= 0; //作为控制用
  151. void  DebugUNDEF(void)
  152. {
  153. uHALr_printf("!!!Enter UNDEFINED. %drn", I_COUNT);
  154. BreakPoint();
  155. }
  156. void  DebugSWI(void)
  157. {
  158. uHALr_printf("!!!Enter SWI. %drn", I_COUNT);
  159. BreakPoint();
  160. }
  161. void  DebugABORT(void)
  162. {
  163. uHALr_printf("!!!Enter ABORT %drn", I_COUNT);
  164. BreakPoint();
  165. }
  166. void  DebugFIQ(void)
  167. {
  168. uHALr_printf("!!!Enter FIQ. %drn", I_COUNT);
  169. BreakPoint();
  170. }