Advertisement
Guest User

Untitled

a guest
Oct 28th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 19.39 KB | None | 0 0
  1.  
  2. #include <module.h>
  3. #include <dryos.h>
  4. #include <bmp.h>
  5. #include <menu.h>
  6. #include <../ime_base/ime_base.h>
  7.  
  8. #define TRWIFI_LETTER "B:/"
  9. #define TRWIFI_FILE_PATH TRWIFI_LETTER "ML/DATA/TRWIFI/"
  10.  
  11. /* those are the hardcoded communication file sizes. all must be a multiple of 512 byte (linux, sector size etc) */
  12. #define ML_CMD_SIZE  512
  13. #define SD_RES_SIZE  512
  14. #define ML_DATA_SIZE 1*1024*1024
  15. #define SD_DATA_SIZE 10*1024*1024
  16.  
  17. /* for tracking the card's current state */
  18. #define STATUS_UNKNOWN      0
  19. #define STATUS_READY        1
  20. #define STATUS_DATA         2
  21. #define STATUS_BUSY         3
  22. #define STATUS_NOT_RUNNING  4
  23.  
  24. /* all needed scripts are embedded */
  25. extern char _binary_DATA_busybox_size;
  26. extern char _binary_DATA_busybox_start;
  27. extern char _binary_DATA_s_trwifi_sh_size;
  28. extern char _binary_DATA_s_trwifi_sh_start;
  29. extern char _binary_DATA_s_inetd_sh_size;
  30. extern char _binary_DATA_s_inetd_sh_start;
  31. extern char _binary_tr_daemon_daemon_start;
  32. extern char _binary_tr_daemon_daemon_size;
  33.  
  34. /* file path is hardcoded */
  35. static char *file_autorun = TRWIFI_LETTER "autorun.sh";
  36. static char *file_busybox = TRWIFI_LETTER "busybox.bin";
  37.  
  38. /* these are the scripts we copy, they wont change */
  39. static char *file_trwifi = TRWIFI_FILE_PATH "EXEC/S_TRWIFI.SH";
  40. static char *file_inetd = TRWIFI_FILE_PATH "EXEC/S_INETD.SH";
  41. static char *file_daemon = TRWIFI_FILE_PATH "EXEC/DAEMON.BIN";
  42.  
  43. static char *sd_res_file = TRWIFI_FILE_PATH "COMM/SD_RES.DAT";
  44. static char *sd_data_file = TRWIFI_FILE_PATH "COMM/SD_DATA.DAT";
  45. static char *ml_cmd_file = TRWIFI_FILE_PATH "COMM/ML_CMD.DAT";
  46. static char *ml_data_file = TRWIFI_FILE_PATH "COMM/ML_DATA.DAT";
  47.  
  48.  
  49.  
  50. static uint32_t trwifi_status = STATUS_NOT_RUNNING;
  51. static uint32_t trwifi_enabled = 0;
  52. struct msg_queue *trwifi_cmd_queue = NULL;
  53.  
  54.  
  55. typedef struct
  56. {
  57.     void (*cbr)(void *ctx, char *ret, uint32_t size);
  58.     void *ctx;
  59.     char cmd;
  60. } trwifi_cmd_t;
  61.  
  62. static char trwifi_shell_cmd[64];
  63.  
  64. /* ensure that given file exists and has specified size */
  65. static void trwifi_prepare_file(char* file, uint32_t size)
  66. {
  67.     uint32_t file_size;
  68.     if((FIO_GetFileSize( file, &file_size ) == 0) && (file_size == size))
  69.     {
  70.         return;
  71.     }
  72.  
  73.     /* file does not exist or has wrong size */
  74.     FIO_RemoveFile(file);
  75.  
  76.     FILE *f = FIO_CreateFileEx(file);
  77.     if (f == INVALID_PTR)
  78.     {
  79.         return;
  80.     }
  81.     FIO_SeekFile(f, size - 1, SEEK_SET);
  82.  
  83.     if(FIO_WriteFile(f, "\000", 1) != 1)
  84.     {
  85.         FIO_CloseFile(f);
  86.         beep();
  87.         bmp_printf(FONT_MED, 0, 400, "Failed to write '%s'. Please run CHKDSK.", file);
  88.         return;
  89.     }
  90.  
  91.     FIO_CloseFile(f);
  92. }
  93.  
  94. /* this routine is to write data without resizing file */
  95. static uint32_t trwifi_write(char *file, char *data, uint32_t length)
  96. {
  97.     if(!length)
  98.     {
  99.         length = strlen(data) + 1;
  100.     }
  101.  
  102.     FILE* f = FIO_Open(file, O_WRONLY | O_SYNC);
  103.     if(f == INVALID_PTR)
  104.     {
  105.         beep();
  106.         bmp_printf(FONT_MED, 0, 400, "Failed to open '%s'", file);
  107.         return 1;
  108.     }
  109.    
  110.     FIO_SeekFile(f, 0, SEEK_SET);
  111.  
  112.     if(FIO_WriteFile(f, data, length) != length)
  113.     {
  114.         FIO_CloseFile(f);
  115.         beep();
  116.         bmp_printf(FONT_MED, 0, 400, "Failed to write '%s'", file);
  117.         return 2;
  118.     }
  119.  
  120.     FIO_CloseFile(f);
  121.  
  122.     return 0;
  123. }
  124.  
  125. static void trwifi_process_http_get_file(char *file, char *data_buf, uint32_t data_size)
  126. {
  127.     uint32_t time = get_ms_clock_value();
  128.     while(get_ms_clock_value() - time < 2000)
  129.     {
  130.         bmp_printf(FONT_MED, 20, 140, "FILE:   '%s'", file);
  131.         bmp_printf(FONT_MED, 20, 160, "DATA:   %d bytes", data_size);
  132.     }
  133.     FILE * f = NULL;
  134.  
  135.     f = FIO_CreateFileEx(file);
  136.     if (f != (void*) -1)
  137.     {
  138.         FIO_WriteFile(f, data_buf, data_size);
  139.         FIO_CloseFile(f);
  140.     }
  141. }
  142. static void trwifi_process_http_get_data(void *ctx, char *data_buf, uint32_t data_size)
  143. {
  144.     void (*cbr)(void *ctx, char *data, uint32_t length) = ctx;
  145.    
  146.     cbr(NULL, data_buf, data_size);
  147. }
  148.  
  149. static void trwifi_process_data(void *ctx, char *data_buf, uint32_t data_size)
  150. {
  151.     uint32_t time = get_ms_clock_value();
  152.     while(get_ms_clock_value() - time < 2000)
  153.     {
  154.         bmp_printf(FONT_MED, 20, 140, "DATA:   '%s'", data_buf);
  155.     }
  156. }
  157.  
  158. static void trwifi_write_cmd(char *cmd, void (*cbr)(void *ctx, char *ret, uint32_t size), void *ctx)
  159. {
  160.     trwifi_cmd_t *req = malloc(strlen(cmd) + sizeof(trwifi_cmd_t) - 1);
  161.    
  162.     req->cbr = cbr;
  163.     req->ctx = ctx;
  164.     strcpy(&req->cmd, cmd);
  165.    
  166.     msg_queue_post(trwifi_cmd_queue, req);
  167. }
  168.  
  169. static void trwifi_thread(uint32_t unused)
  170. {
  171.     trwifi_cmd_t *current_cmd = NULL;
  172.     uint32_t timeout = 200;
  173.     uint32_t last_comm_time = get_ms_clock_value();
  174.     uint32_t card_alive = 0;
  175.    
  176.     trwifi_status = STATUS_UNKNOWN;
  177.    
  178.     /* this loop will exit as soon the current msleep returns */
  179.     while(trwifi_enabled)
  180.     {
  181.         char status[SD_RES_SIZE+1];
  182.         char *size = NULL;
  183.         status[SD_RES_SIZE] = '\000';
  184.         uint32_t last_comm = get_ms_clock_value() - last_comm_time;
  185.        
  186.         if(last_comm > 30000 && !card_alive)
  187.         {
  188.             beep();
  189.             NotifyBox(5000, "Transcend WiFi-SD does not respond, exiting");
  190.             break;
  191.         }
  192.        
  193.         /* no communication the last 10 seconds -> read status every 5 seconds. might change when communication is bidirectional (wlan remote?) */
  194.         if(last_comm > 10000)
  195.         {
  196.             timeout = 5000;
  197.         }
  198.         else
  199.         {
  200.             /* there has been communication lately, so poll a bit faster */
  201.             timeout = 100;
  202.         }
  203.        
  204.         /* if there is no current command, fetch and write the command to command file */
  205.         if(!current_cmd)
  206.         {
  207.             if(!msg_queue_receive(trwifi_cmd_queue, (trwifi_cmd_t **)&current_cmd, timeout))
  208.             {
  209.                 trwifi_write(sd_res_file, "BUSY:0:", 0);
  210.                 trwifi_write(ml_cmd_file, &current_cmd->cmd, 0);
  211.                 last_comm_time = get_ms_clock_value();
  212.             }
  213.         }
  214.         else
  215.         {
  216.             /* if there is a command pending, fetch every 100 msec */
  217.             msleep(100);
  218.         }
  219.        
  220.         /* now read the card's response */
  221.         FILE* f = FIO_Open(sd_res_file, O_RDONLY | O_SYNC);
  222.         if (f == INVALID_PTR)
  223.         {
  224.             beep();
  225.             bmp_printf(FONT_MED, 0, 400, "Failed to open '%s'", sd_res_file);
  226.             break;
  227.         }
  228.  
  229.         if(FIO_ReadFile(f, status, SD_RES_SIZE) != SD_RES_SIZE)
  230.         {
  231.             FIO_CloseFile(f);
  232.             beep();
  233.             bmp_printf(FONT_MED, 0, 400, "Failed to read '%s'", sd_res_file);
  234.             break;
  235.         }
  236.         FIO_CloseFile(f);
  237.  
  238.         /* split fields at colons and terminate every element */
  239.         uint32_t field = 0;
  240.         int32_t data_size = 0;
  241.         for(int pos = 0; pos < sizeof(status); pos++)
  242.         {
  243.             if(status[pos] == ':')
  244.             {
  245.                 field++;
  246.                 status[pos] = '\000';
  247.  
  248.                 if(field == 1)
  249.                 {
  250.                     size = &status[pos + 1];
  251.                     data_size = atoi(size);
  252.                 }
  253.             }
  254.         }
  255.        
  256.         /* whats the current response? BUSY is set by us, so its the most likely response after a command was sent */
  257.         if(!strcmp(status, "BUSY"))
  258.         {
  259.             trwifi_status = STATUS_BUSY;
  260.         }
  261.         else if(!strcmp(status, "DATA"))
  262.         {
  263.             trwifi_status = STATUS_DATA;
  264.             last_comm_time = get_ms_clock_value();
  265.  
  266.             /* some sanity checks, don't to anything if there is invalid data size */
  267.             if(data_size > 0 && data_size <= SD_DATA_SIZE)
  268.             {
  269.                 char *data_buf = malloc(data_size + 1);
  270.  
  271.                 FILE* data_fd = FIO_Open(sd_data_file, O_RDONLY | O_SYNC);
  272.                 if(data_fd == INVALID_PTR)
  273.                 {
  274.                     beep();
  275.                     free(data_buf);
  276.                     bmp_printf(FONT_MED, 0, 400, "Failed to open '%s'", sd_data_file);
  277.                     return;
  278.                 }
  279.  
  280.                 if(FIO_ReadFile(data_fd, data_buf, data_size) != data_size)
  281.                 {
  282.                     FIO_CloseFile(data_fd);
  283.                     free(data_buf);
  284.                     beep();
  285.                     bmp_printf(FONT_MED, 0, 400, "Failed to read '%s'", sd_data_file);
  286.                     return;
  287.                 }
  288.                 FIO_CloseFile(data_fd);
  289.  
  290.                 /* there is for sure someone who directly prints the string (and it isn't null terminated), so terminate it just to make sure ;) */
  291.                 data_buf[data_size] = '\000';
  292.                
  293.                 /* when there was a command pending, inform it about the DATA state by calling with received data */
  294.                 if(current_cmd)
  295.                 {
  296.                     current_cmd->cbr(current_cmd->ctx, data_buf, data_size);
  297.                     free(current_cmd);
  298.                     current_cmd = NULL;
  299.                 }
  300.                 else
  301.                 {
  302.                     beep();
  303.                     bmp_printf(FONT_MED, 0, 400, "Card sent us data, but we didn't request anything?");
  304.                 }
  305.  
  306.                 free(data_buf);
  307.             }
  308.             else
  309.             {
  310.                 /* when there was a command pending, call with no data which signals that the command is finished */
  311.                 if(current_cmd)
  312.                 {
  313.                     current_cmd->cbr(current_cmd->ctx, NULL, 0);
  314.                     free(current_cmd);
  315.                     current_cmd = NULL;
  316.                 }
  317.             }
  318.            
  319.             /* reset state and request state again */
  320.             trwifi_write(sd_res_file, "BUSY:0:", 0);
  321.             trwifi_write(ml_cmd_file, "STATUS:0:", 0);
  322.         }
  323.         else if(!strcmp(status, "READY"))
  324.         {
  325.             trwifi_status = STATUS_READY;
  326.            
  327.             /* the first time inform the user about the card being ready. have to do it the other way around */
  328.             if(!card_alive)
  329.             {
  330.                 card_alive = 1;
  331.                 beep();
  332.                 NotifyBox(500, "Transcend WiFi-SD is ready");
  333.             }
  334.            
  335.             /* when there was a command pending, inform it about the READY state */
  336.             if(current_cmd)
  337.             {
  338.                 current_cmd->cbr(current_cmd->ctx, NULL, 0);
  339.                 free(current_cmd);
  340.                 current_cmd = NULL;
  341.             }
  342.         }
  343.         else if(!strcmp(status, "UNKNOWN"))
  344.         {
  345.             trwifi_status = STATUS_UNKNOWN;
  346.         }
  347.     }
  348.    
  349.     trwifi_status = STATUS_NOT_RUNNING;
  350.     trwifi_enabled = 0;
  351. }
  352.  
  353.  
  354. /* download url to the file specified */
  355. int32_t net_get_file(char *url, char *dst_file)
  356. {
  357.     char command[32];
  358.    
  359.     snprintf(command, sizeof(command), "HTTP_GET:%d:", strlen(url));
  360.    
  361.     trwifi_write(ml_data_file, url, 0);
  362.     trwifi_write_cmd(command, &trwifi_process_http_get_file, dst_file);
  363.    
  364.     return NULL;
  365. }
  366.  
  367. /* download url and call back */
  368. int32_t net_get_data(char *url, void (*cbr)(void *ctx, char *data, uint32_t length))
  369. {
  370.     char command[32];
  371.    
  372.     snprintf(command, sizeof(command), "HTTP_GET:%d:", strlen(url));
  373.    
  374.     trwifi_write(ml_data_file, url, 0);
  375.     trwifi_write_cmd(command, &trwifi_process_http_get_data, cbr);
  376.    
  377.     return NULL;
  378. }
  379.  
  380. /* execute a command on card and return buffer with returned string - to be freed using free() */
  381. char *trwifi_exec(char *cmd)
  382. {
  383.     char command[32];
  384.    
  385.     snprintf(command, sizeof(command), "EXEC:%d:", strlen(cmd));
  386.    
  387.     trwifi_write(ml_data_file, cmd, 0);
  388.     trwifi_write_cmd(command, &trwifi_process_data, NULL);
  389.    
  390.     return NULL;
  391. }
  392.  
  393. static MENU_SELECT_FUNC(trwifi_start_select)
  394. {
  395.     if(!trwifi_enabled)
  396.     {
  397.         trwifi_enabled = 1;
  398.         task_create("TRWIFI", 0x1C, 0x1000, &trwifi_thread, NULL);
  399.     }
  400.     else
  401.     {
  402.         trwifi_enabled = 0;
  403.     }
  404. }
  405.  
  406. static MENU_SELECT_FUNC(trwifi_check_select)
  407. {
  408.     trwifi_exec("mount");
  409. }
  410.  
  411. static IME_DONE_FUNC(ime_base_test_done)
  412. {
  413.     char command[32];
  414.    
  415.     snprintf(command, sizeof(command), "EXEC:%d:", strlen(trwifi_shell_cmd));
  416.    
  417.     trwifi_write(ml_data_file, trwifi_shell_cmd, 0);
  418.     trwifi_write_cmd(command, &trwifi_process_data, NULL);
  419.    
  420.     return IME_OK;
  421. }
  422.  
  423. static MENU_SELECT_FUNC(trwifi_exec_select)
  424. {
  425.     strcpy(trwifi_shell_cmd, "");
  426.     ime_base_start("Shell command", trwifi_shell_cmd, sizeof(trwifi_shell_cmd), IME_UTF8, IME_CHARSET_ANY, NULL, &ime_base_test_done, 0, 0, 0, 0);
  427. }
  428.  
  429. /*  Installation part  */
  430. static uint32_t trwifi_file_exists(char *file)
  431. {
  432.     uint32_t file_size;
  433.     if(FIO_GetFileSize( file, &file_size ) == 0)
  434.     {
  435.         return 1;
  436.     }
  437.    
  438.     return 0;
  439. }
  440.  
  441. static void trwifi_install_file(char *file, char *data, uint32_t length)
  442. {
  443.     FIO_RemoveFile(file);
  444.  
  445.     FILE *f = FIO_CreateFileEx(file);
  446.     if (f == INVALID_PTR)
  447.     {
  448.         return;
  449.     }
  450.  
  451.     if(FIO_WriteFile(f, data, length) != length)
  452.     {
  453.         FIO_CloseFile(f);
  454.         beep();
  455.         bmp_printf(FONT_MED, 0, 400, "Failed to write '%s'", file);
  456.         return;
  457.     }
  458.  
  459.     FIO_CloseFile(f);
  460. }
  461.  
  462. static void trwifi_uninstall_file(char *file)
  463. {
  464.     FIO_RemoveFile(file);
  465. }
  466.  
  467. static void trwifi_install_files()
  468. {
  469.     FIO_CreateDirectory(TRWIFI_FILE_PATH);
  470.  
  471.     //trwifi_install_file(file_autorun, &_binary_DATA_autorun_sh_start, &_binary_DATA_autorun_sh_size);
  472.     //trwifi_install_file(file_busybox, &_binary_DATA_busybox_start, _binary_DATA_busybox_size);
  473.     trwifi_install_file(file_daemon, &_binary_tr_daemon_daemon_start, (int)&_binary_tr_daemon_daemon_size);
  474.     trwifi_install_file(file_trwifi, &_binary_DATA_s_trwifi_sh_start, (int)&_binary_DATA_s_trwifi_sh_size);
  475.     trwifi_install_file(file_inetd, &_binary_DATA_s_inetd_sh_start, (int)&_binary_DATA_s_inetd_sh_size);
  476. }
  477.  
  478. static void trwifi_uninstall_files()
  479. {
  480.     //trwifi_uninstall_file(file_autorun);
  481.     //trwifi_uninstall_file(file_busybox);
  482.     trwifi_uninstall_file(file_daemon);
  483.     trwifi_uninstall_file(file_trwifi);
  484.     trwifi_uninstall_file(file_inetd);
  485. }
  486.  
  487. static void trwifi_install_status(uint32_t *missing, uint32_t *existing)
  488. {
  489.     //*missing |= !trwifi_file_exists(file_autorun);
  490.     //*missing |= !trwifi_file_exists(file_busybox);
  491.     *missing |= !trwifi_file_exists(file_daemon);
  492.     *missing |= !trwifi_file_exists(file_trwifi);
  493.     *missing |= !trwifi_file_exists(file_inetd);
  494.  
  495.     //*existing |= trwifi_file_exists(file_autorun);
  496.     //*existing |= trwifi_file_exists(file_busybox);
  497.     *existing |= trwifi_file_exists(file_daemon);
  498.     *existing |= trwifi_file_exists(file_trwifi);
  499.     *existing |= trwifi_file_exists(file_inetd);
  500. }
  501.  
  502. static MENU_UPDATE_FUNC(trwifi_start_update)
  503. {
  504.     uint32_t missing = 0;
  505.     uint32_t existing = 0;
  506.    
  507.     trwifi_install_status(&missing, &existing);
  508.    
  509.     if(!missing)
  510.     {
  511.         if(trwifi_enabled)
  512.         {
  513.             MENU_SET_NAME("Stop daemon");
  514.             MENU_SET_WARNING(MENU_WARN_INFO, "Already starting..." );
  515.         }
  516.         else
  517.         {
  518.             MENU_SET_WARNING(MENU_WARN_INFO, "Scripts seem to be installed, ready to start daemon." );
  519.         }
  520.     }
  521.     else if(existing && missing)
  522.     {
  523.         MENU_SET_WARNING(MENU_WARN_NOT_WORKING, "Scripts are partially missing. Please reinstall." );
  524.     }
  525.     else
  526.     {
  527.         MENU_SET_WARNING(MENU_WARN_NOT_WORKING, "Scripts are missing. Please install." );
  528.     }
  529. }
  530.  
  531. static MENU_UPDATE_FUNC(trwifi_check_update)
  532. {
  533.     if(trwifi_status == STATUS_READY)
  534.     {
  535.         MENU_SET_WARNING(MENU_WARN_INFO, "Card seems to be up and ready for commands." );
  536.     }
  537.     else
  538.     {
  539.         MENU_SET_WARNING(MENU_WARN_NOT_WORKING, "Either daemon was not started or card isn't perepared." );
  540.     }
  541. }
  542.  
  543. static MENU_UPDATE_FUNC(trwifi_exec_update)
  544. {
  545.     if(trwifi_status == STATUS_READY)
  546.     {
  547.         MENU_SET_WARNING(MENU_WARN_INFO, "Card seems to be up and ready for commands." );
  548.     }
  549.     else
  550.     {
  551.         MENU_SET_WARNING(MENU_WARN_NOT_WORKING, "Either daemon was not started or card isn't perepared." );
  552.     }
  553. }
  554.  
  555. static MENU_UPDATE_FUNC(trwifi_install_update)
  556. {
  557.     uint32_t missing = 0;
  558.     uint32_t existing = 0;
  559.    
  560.     trwifi_install_status(&missing, &existing);
  561.    
  562.     if(existing && missing)
  563.     {
  564.         MENU_SET_NAME("Remove Scripts");
  565.         MENU_SET_WARNING(MENU_WARN_ADVICE, "Scripts partially installed, click to remove them." );
  566.     }
  567.     else if(existing)
  568.     {
  569.         MENU_SET_NAME("Remove Scripts");
  570.         MENU_SET_WARNING(MENU_WARN_ADVICE, "Scripts are installed, click to remove them." );
  571.     }
  572.     else
  573.     {
  574.         MENU_SET_NAME("Install Scripts");
  575.         MENU_SET_WARNING(MENU_WARN_ADVICE, "Click to install Transcend Wifi scripts." );
  576.     }
  577. }
  578.  
  579. static MENU_SELECT_FUNC(trwifi_install_select)
  580. {
  581.     uint32_t missing = 0;
  582.     uint32_t existing = 0;
  583.    
  584.     trwifi_install_status(&missing, &existing);
  585.    
  586.     if(existing)
  587.     {
  588.         trwifi_uninstall_files();
  589.     }
  590.     else
  591.     {
  592.         trwifi_install_files();
  593.         NotifyBox(100000, "Installed scripts, please repower camera.");
  594.     }
  595. }
  596.  
  597. static MENU_SELECT_FUNC(trwifi_http_test_select)
  598. {
  599.     net_get_file("http://upload.g3gg0.de/pub_files/bc3ccd38fe8807eabc7e73cb036fb4ba/data.txt", "B:/TEST.GET");
  600. }
  601.  
  602. static struct menu_entry trwifi_menu[] =
  603. {
  604.     {
  605.         .name = "Transcend WiFi-SD",
  606.         .help = "",
  607.         .submenu_width = 710,
  608.         .children = (struct menu_entry[])
  609.         {
  610.             {
  611.                 .name = "Start daemon",
  612.                 .select = &trwifi_start_select,
  613.                 .update = &trwifi_start_update,
  614.             },
  615.             {
  616.                 .name = "Install scripts",
  617.                 .select = &trwifi_install_select,
  618.                 .update = &trwifi_install_update,
  619.             },
  620.             {
  621.                 .name = "Check status",
  622.                 .select = &trwifi_check_select,
  623.                 .update = &trwifi_check_update,
  624.             },
  625.             {
  626.                 .name = "HTTP test",
  627.                 .select = &trwifi_http_test_select,
  628.             },
  629.             {
  630.                 .name = "Enter shell command",
  631.                 .select = &trwifi_exec_select,
  632.                 .update = &trwifi_exec_update,
  633.             },
  634.             MENU_EOL,
  635.         },
  636.     },
  637. };
  638.  
  639.  
  640. static unsigned int trwifi_init()
  641. {
  642.     trwifi_cmd_queue = (struct msg_queue *) msg_queue_create("trwifi_cmd_queue", 100);
  643.    
  644.     trwifi_install_files();
  645.  
  646.     /* create the communication files */
  647.     trwifi_prepare_file(sd_res_file, SD_RES_SIZE);
  648.     trwifi_prepare_file(ml_cmd_file, ML_CMD_SIZE);
  649.     trwifi_prepare_file(ml_data_file, ML_DATA_SIZE);
  650.     trwifi_prepare_file(sd_data_file, SD_DATA_SIZE);
  651.    
  652.     /* init to UNKNOWN state and request a status update from card */
  653.     trwifi_write(sd_res_file, "UNKNOWN:0:", 0);
  654.     trwifi_write(ml_cmd_file, "STATUS:0:", 0);
  655.    
  656.     trwifi_enabled = 1;
  657.     task_create("TRWIFI", 0x1C, 0x1000, &trwifi_thread, NULL);
  658.    
  659.     /* still need to find a suitable menu */
  660.     menu_add("Audio", trwifi_menu, COUNT(trwifi_menu));
  661.     return 0;
  662. }
  663.  
  664. static unsigned int trwifi_deinit()
  665. {
  666.     return 0;
  667. }
  668.  
  669. MODULE_INFO_START()
  670.     MODULE_INIT(trwifi_init)
  671.     MODULE_DEINIT(trwifi_deinit)
  672. MODULE_INFO_END()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement