ohpocapp.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #include "includes.h"
  2. void appimg_exit(void){
  3. OSI_LOGI(0,"application image exit");
  4. }
  5. static void mainTask(void *param);
  6. ////////////////////////test start///////////////////////////
  7. void logDataCb2(const char *data,uint32 length){MSG_INFO(1, "USB get:%d");}
  8. bool logPortInit1(void){
  9. bool ret=nwy_usb_serial_reg_recv_cb(logDataCb2);
  10. if(false==ret) OSI_LOGI(0,"nwy_usb_serial_reg_recv_cb failed");
  11. else{
  12. usb_log_status=true;
  13. MSG_INFO(1,"logPortInit ok");
  14. }
  15. return ret;
  16. }
  17. static void gpioIsqActiveCb(int param){MSG_INFO(1, "GPIO_ISR:GPIO=%d,LEVEL=%d", param,nwy_gpio_get_value(param));}//打印中断管脚号及其当前电平值
  18. void testInit(void){
  19. //配置IO,运行即自行锁住电源
  20. nwy_gpio_set_direction(G_POWER_HOLD,nwy_output);//设置为输出
  21. nwy_gpio_pullup_or_pulldown(G_POWER_HOLD,1);//up
  22. nwy_gpio_set_value(G_POWER_HOLD,nwy_high);//HIGH
  23. //配置PIN79为ISR,上下延
  24. gpioInputInit(G_KEY_MIC_PTT,1,2);
  25. nwy_close_gpio(G_KEY_MIC_PTT);nwy_sleep(10000);
  26. if(nwy_open_gpio_irq_config(G_KEY_MIC_PTT,2,gpioIsqActiveCb)){//ISR 上下延
  27. nwy_gpio_open_irq_enable(G_KEY_MIC_PTT);MSG_INFO(1, "IRQ CONFIG OK");
  28. }else MSG_INFO(1, "IRQ CONFIG FAILED");
  29. nwy_gpio_pullup_or_pulldown(G_KEY_MIC_PTT,2);//no pull
  30. }
  31. void testInfo(void){MSG_INFO(1, "QueryLevel:GPIO=%d,Level:%d",G_KEY_MIC_PTT,nwy_gpio_get_value(G_KEY_MIC_PTT));}//定时读取管脚电平
  32. static void testTask(void *param){
  33. logPortInit1();testInit();
  34. for(;;){
  35. nwy_sleep(1000);
  36. testInfo();
  37. }
  38. }
  39. //////////////////////////test end////////////////////////////////
  40. /*appimg_enter cat one入口函数*/
  41. int appimg_enter(void *param){
  42. #ifdef DEBUG_ON
  43. nwy_sleep(10000);
  44. #endif
  45. nwy_set_sim_detect_mode(false);
  46. mainThreadPtr=nwy_create_thread("main", mainTask, NULL, NWY_OSI_PRIORITY_NORMAL, MAIN_TASK_THREAD_STACK, 5);
  47. if(NULL==mainThreadPtr){
  48. for(;;){
  49. OSI_LOGI(0,"main task failed");
  50. nwy_sleep(1000);
  51. }
  52. }
  53. if(NULL==nwy_create_thread("sub", subTask, NULL, NWY_OSI_PRIORITY_NORMAL, SUB_TASK_THREAD_STACK, 10)){
  54. for(;;){
  55. OSI_LOGI(0,"sub task failed");
  56. nwy_sleep(1000);
  57. }
  58. }
  59. return 0;
  60. }
  61. ///////////////////////////////////////////////////////////
  62. void ohpocRecvGet(unsigned char *msg, int len){
  63. pocCmdHandler(msg,len);
  64. }
  65. static void ohpocStart(void){
  66. if(false==ohpocInit(ohpocRecvGet, OHPOC_VERSION, OHPOC_MODLE, OHPOC_CUST)) OSI_LOGI(0,"ohpocInit failed");
  67. MSG_INFO(1,"ohpocInit Ok");
  68. }
  69. #include "nwy_audio_api.h"
  70. static int player_cb(nwy_player_status state){
  71. OSI_LOGI(0,"player_cb state:%d", state);
  72. if(0==state){//播放完毕了
  73. OSI_LOGI(0,"pcm play finished");
  74. }
  75. }
  76. void TestPlayer(void){
  77. int i;
  78. unsigned char buffer[320];
  79. OSI_LOGI(0, "[XXX]TestPlayer start");
  80. nwy_audio_recorder_close();
  81. OSI_LOGI(0, "[XXX]try rec close done");
  82. if(0!=nwy_audio_player_open(player_cb)){
  83. OSI_LOGI(0, "[xxx]plp open failed");
  84. return;
  85. }
  86. OSI_LOGI(0, "[XXX]ply open ok");
  87. for(i=0;i<10;i++){
  88. OSI_LOGI(0, "[XXX]ply frame start:%d", i);
  89. if(NWY_SUCESS!=nwy_audio_player_play(buffer,320)){
  90. OSI_LOGI(0,"[XXX]ply frame failed:%d",i);
  91. break;
  92. }else OSI_LOGI(0, "[XXX]ply frame ok:%d",i);
  93. }
  94. if(0==nwy_audio_player_stop()) OSI_LOGI(0, "[XXX]ply stop ok");
  95. else OSI_LOGI(0, "[XXX]ply stop failed");
  96. OSI_LOGI(0, "[XXX]try player close");
  97. nwy_audio_player_close();
  98. OSI_LOGI(0, "[XXX]player close done");
  99. }
  100. static void test_flash_now(void);
  101. static void mainTask(void *param){
  102. #if 0
  103. #include "spiFlash.h"
  104. #define FLASH_SIZE_BYTES (4*1024*1024)
  105. unsigned int i;
  106. bool ret;
  107. int flag=0;
  108. char info[50];
  109. SPIFLASH_INFO spiFlashInfo;
  110. boardInit();
  111. nwy_sleep(2000);
  112. MSG_INFO(1, "Test Flash start\r\n");
  113. for(i=0;i<FLASH_SIZE_BYTES/SECTOR_SIZE_BYTE;i++){
  114. MSG_INFO(1, "Test sector:%d start\r\n",i);
  115. ret=spiFlashSectorTest(i, &spiFlashInfo);
  116. MSG_INFO(1, "Test sector:%d,result:%d,id:%d\r\n",i,ret,spiFlashInfo.id);
  117. if(flag==0){
  118. flag=1;
  119. snprintf(info, sizeof(info), "ID:%08x",spiFlashInfo.id);
  120. guiShowStr(2, 30,info, FONT_MODE_12X12, REVERSED_NO,guiGetBackColor(),COLOR_STATUS_BAR);
  121. }
  122. if(ret==false){
  123. MSG_INFO(1, "Test sector:%d Error:%d\r\n",i,spiFlashInfo.errno);
  124. snprintf(info, sizeof(info), ">>%d/%d err=%d ",i+1,FLASH_SIZE_BYTES/SECTOR_SIZE_BYTE,spiFlashInfo.errno);
  125. guiShowStr(2, 50,info, FONT_MODE_12X12, REVERSED_NO,guiGetBackColor(),COLOR_STATUS_BAR);
  126. break;
  127. }
  128. snprintf(info, sizeof(info), ">>%d/%d ok",i+1,FLASH_SIZE_BYTES/SECTOR_SIZE_BYTE);
  129. guiShowStr(2, 50,info, FONT_MODE_12X12, REVERSED_NO,guiGetBackColor(),COLOR_STATUS_BAR);
  130. }
  131. MSG_INFO(1, "Test Flash end\r\n");
  132. #endif
  133. #if 0
  134. dataInit();
  135. boardInit();
  136. ohpocStart();
  137. uioStatusInit();
  138. #endif
  139. #if 1
  140. dataInit();
  141. boardInit();
  142. ohpocStart();
  143. uioStatusInit();
  144. appRun();
  145. #endif
  146. nwy_exit_thread();
  147. }
  148. #include "nwy_file.h"
  149. #include "mymd5.h"
  150. #define flash_size (4 * 1024)
  151. #define flash_addr 0x60320000
  152. #define TEST_SIZE 18912
  153. //#include <absacc.h>
  154. //const char mytext[] __at (0x60321000)= "ddddd";
  155. void test_flash_now()
  156. {
  157. #if 0
  158. unsigned char databuf[10]={'0','1','2','3','4','5','6','7','8','9'};
  159. MD5_CTX mdContext;
  160. unsigned char *md5;
  161. MD5Init(&mdContext);
  162. MD5Update(&mdContext,databuf,10);
  163. MD5Final(&mdContext);
  164. md5=mdContext.digest;
  165. OSI_LOGI(0,"md5:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
  166. md5[0],md5[1],md5[2],md5[3],
  167. md5[4],md5[5],md5[6],md5[7],
  168. md5[8],md5[9],md5[10],md5[11],
  169. md5[12],md5[13],md5[14],md5[15]);
  170. #else
  171. MD5_CTX mdContext;
  172. unsigned char *md5;
  173. int ret = -1;
  174. unsigned char data_str[flash_size] = {0};
  175. nwyspiflash_t *fp = NULL;
  176. fp = nwy_flash_open(NAME_FLASH_1);
  177. if(fp == NULL)
  178. {
  179. OSI_LOGI(0,"flash open filed");
  180. return;
  181. }
  182. OSI_LOGI(0,"flash open ok");
  183. memset(data_str,0,sizeof(data_str));
  184. MD5Init(&mdContext);
  185. int fs=TEST_SIZE;
  186. int flen;
  187. unsigned int offset=flash_addr;
  188. while(fs>0){
  189. if(fs>flash_size) flen=flash_size;
  190. else flen=fs;
  191. ret = nwy_flash_read(fp, offset, data_str, flen);
  192. if (ret == false)
  193. {
  194. OSI_LOGI(0,"nwy_flash_read filed");
  195. return;
  196. }
  197. OSI_LOGI(0,"nwy_flash_read ok:%d",flen);
  198. MD5Update(&mdContext,data_str,flen);
  199. offset += flen;
  200. fs -= flen;
  201. }
  202. MD5Final(&mdContext);
  203. md5=mdContext.digest;
  204. OSI_LOGI(0,"md5:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
  205. md5[0],md5[1],md5[2],md5[3],
  206. md5[4],md5[5],md5[6],md5[7],
  207. md5[8],md5[9],md5[10],md5[11],
  208. md5[12],md5[13],md5[14],md5[15]);
  209. #endif
  210. return;
  211. }