comload.c
上传用户:jankzhpno
上传日期:2022-08-03
资源大小:4763k
文件大小:2k
源码类别:

Windows CE

开发平台:

Visual C++

  1. #include "def.h"
  2. #include "2440addr.h"
  3. #include "2440lib.h"
  4. #define puts Uart_Printf
  5. #define printf Uart_Printf
  6. #define getch Uart_Getch
  7. #ifndef DEBUG_VERSION
  8. #define USE_UART_INT
  9. #endif
  10. extern U32 downloadAddress, downloadFileSize;
  11. static U8 *temp;
  12. #ifdef USE_UART_INT
  13. static void __irq Uart0RxInt(void)
  14. {
  15.     ClearSubPending(BIT_SUB_RXD0); //rSUBSRCPND = BIT_SUB_RXD0;          //Clear pending bit (Requested)
  16.     ClearPending(BIT_UART0);
  17.     *temp ++= RdURXH0(); 
  18. }
  19. #endif
  20. void call_linux(U32 a0, U32 a1, U32 a2);
  21. void comdownload(void)
  22. {
  23. U32 size;
  24. U8 *buf;
  25. U16 checksum;
  26. puts("nNow download file from uart0...n");
  27. downloadAddress = _NONCACHE_STARTADDRESS;
  28. buf  = (U8 *)downloadAddress;
  29. temp = buf-4;
  30. Uart_GetKey();
  31. #ifdef USE_UART_INT
  32. pISR_UART0 = (U32)Uart0RxInt; //串口接收数据中断
  33. ClearSubPending(BIT_SUB_RXD0);
  34. ClearPending(BIT_UART0);
  35. EnableSubIrq(BIT_SUB_RXD0);
  36. EnableIrq(BIT_UART0);
  37. #endif
  38. while((U32)temp<(U32)buf)
  39.     {
  40.  #ifdef USE_UART_INT
  41.         Led_Display(0);
  42.         Delay(1000);
  43.         Led_Display(15);
  44.         Delay(1000);
  45. #else
  46. *temp++ = Uart_Getch();
  47. #endif
  48.     } //接收文件长度,4 bytes
  49. size  = *(U32 *)(buf-4);
  50. downloadFileSize = size-6;
  51. #ifdef USE_UART_INT
  52.     printf("Download File Size = %dn", size);
  53. #endif
  54. while(((U32)temp-(U32)buf)<(size-4))
  55. {
  56. #ifdef USE_UART_INT
  57. Led_Display(0);
  58.         Delay(1000);
  59.         Led_Display(15);
  60.         Delay(1000);
  61. #else
  62. *temp++ = Uart_Getch();
  63. #endif
  64. }
  65. #ifdef USE_UART_INT
  66. DisableSubIrq(BIT_SUB_RXD0);
  67. DisableIrq(BIT_UART0);
  68. #endif
  69. #ifndef USE_UART_INT
  70. printf("Download File Size = %dn", size);
  71. #endif
  72. checksum = 0;
  73. for(size=0; size<downloadFileSize; size++)
  74. checksum += buf[size];
  75. if(checksum!=(buf[size]|(buf[size+1]<<8))) {
  76. puts("Checksum fail!n");
  77. return;
  78. }
  79. puts("Are you sure to run? [y/n]n");
  80. while(1)
  81. {
  82. U8 key = getch();
  83. if(key=='n')
  84. return;
  85. if(key=='y')
  86. break;
  87. }
  88. call_linux(0, 193, downloadAddress);
  89. }