Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Someone
Sunday, November 19th, 2006 at 2:25:33pm UTC 

  1. /***************************************************************************
  2.  *             __________               __   ___.
  3.  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  4.  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  5.  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  6.  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  7.  *                     \/            \/     \/    \/            \/
  8.  * $Id: main.c,v 1.195 2006-11-07 19:03:29 learman Exp $
  9.  *
  10.  * Copyright (C) 2002 by Björn Stenberg
  11.  *
  12.  * All files in this archive are subject to the GNU General Public License.
  13.  * See the file COPYING in the source tree root for full license agreement.
  14.  *
  15.  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  16.  * KIND, either express or implied.
  17.  *
  18.  ****************************************************************************/
  19. #include "config.h"
  20.  
  21. #include "ata.h"
  22. #include "ata_idle_notify.h"
  23. #include "disk.h"
  24. #include "fat.h"
  25. #include "lcd.h"
  26. #include "rtc.h"
  27. #include "debug.h"
  28. #include "led.h"
  29. #include "kernel.h"
  30. #include "button.h"
  31. #include "tree.h"
  32. #include "panic.h"
  33. #include "menu.h"
  34. #include "system.h"
  35. #include "usb.h"
  36. #include "powermgmt.h"
  37. #include "adc.h"
  38. #include "i2c.h"
  39. #ifndef DEBUG
  40. #include "serial.h"
  41. #endif
  42. #include "audio.h"
  43. #include "mp3_playback.h"
  44. #include "thread.h"
  45. #include "settings.h"
  46. #include "backlight.h"
  47. #include "status.h"
  48. #include "debug_menu.h"
  49. #include "version.h"
  50. #include "sprintf.h"
  51. #include "font.h"
  52. #include "language.h"
  53. #include "gwps.h"
  54. #include "playlist.h"
  55. #include "buffer.h"
  56. #include "rolo.h"
  57. #include "screens.h"
  58. #include "power.h"
  59. #include "talk.h"
  60. #include "plugin.h"
  61. #include "misc.h"
  62. #include "database.h"
  63. #include "dircache.h"
  64. #ifdef HAVE_TAGCACHE
  65. #include "tagcache.h"
  66. #include "tagtree.h"
  67. #endif
  68. #include "lang.h"
  69. #include "string.h"
  70. #include "splash.h"
  71. #include "eeprom_settings.h"
  72. #include "scrobbler.h"
  73.  
  74. #if (CONFIG_CODEC == SWCODEC)
  75. #include "playback.h"
  76. #include "pcmbuf.h"
  77. #else
  78. #define pcmbuf_init()
  79. #endif
  80. #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
  81. #include "pcm_record.h"
  82. #define SETTINGS_RESET BUTTON_REC
  83. #endif
  84.  
  85. #ifdef CONFIG_TUNER
  86. #include "radio.h"
  87. #endif
  88. #ifdef HAVE_MMC
  89. #include "ata_mmc.h"
  90. #endif
  91.  
  92. #ifdef HAVE_REMOTE_LCD
  93. #include "lcd-remote.h"
  94. #endif
  95.  
  96. #if CONFIG_USBOTG == USBOTG_ISP1362
  97. #include "isp1362.h"
  98. #endif
  99.  
  100. #if CONFIG_USBOTG == USBOTG_M5636
  101. #include "m5636.h"
  102. #endif
  103.  
  104. /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
  105.  
  106. const char appsversion[]=APPSVERSION;
  107.  
  108. void init(void);
  109.  
  110.  
  111. void app_main(void)
  112. {
  113.     init();
  114.     browse_root();
  115. }
  116.  
  117. int init_dircache(bool preinit)
  118. {
  119. #ifdef HAVE_DIRCACHE
  120.     int result = 0;
  121.     bool clear = false;
  122.    
  123.     if (preinit)
  124.         dircache_init();
  125.    
  126.     if (global_settings.dircache)
  127.     {
  128. # ifdef HAVE_EEPROM_SETTINGS
  129.         if (firmware_settings.initialized && firmware_settings.disk_clean
  130.             && preinit)
  131.         {
  132.             result = dircache_load(DIRCACHE_FILE);
  133.             remove(DIRCACHE_FILE);
  134.             if (result < 0)
  135.             {
  136.                 firmware_settings.disk_clean = false;
  137.                 if (global_settings.dircache_size >= 0)
  138.                     dircache_build(global_settings.dircache_size);
  139.             }
  140.  
  141.             return result;
  142.         }
  143. # endif
  144.        
  145.         if (preinit)
  146.             return -1;
  147.        
  148.         if (!dircache_is_enabled()
  149.             && !dircache_is_initializing())
  150.         {
  151.             if (global_settings.dircache_size <= 0)
  152.             {
  153.                 gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING));
  154.                 clear = true;
  155.             }
  156.             result = dircache_build(global_settings.dircache_size);
  157.         }
  158.        
  159.         if (result < 0)
  160.             gui_syncsplash(0, true, "Failed! Result: %d", result);
  161.        
  162.         if (clear)
  163.         {
  164.             backlight_on();
  165.             show_logo();
  166.         }
  167.     }
  168.    
  169.     return result;
  170. #else
  171.     (void)preinit;
  172.     return 0;
  173. #endif
  174. }
  175.  
  176. #ifdef HAVE_TAGCACHE
  177. void init_tagcache(void)
  178. {
  179.     bool clear = false;
  180.  
  181.     tagcache_init();
  182.    
  183.     while (!tagcache_is_initialized())
  184.     {
  185. #ifdef HAVE_LCD_CHARCELLS
  186.         char buf[32];
  187. #endif
  188.         int ret = tagcache_get_commit_step();
  189.  
  190.         if (ret > 0)
  191.         {
  192. #ifdef HAVE_LCD_BITMAP
  193.             gui_syncsplash(0, true, "%s [%d/%d]",
  194.                                     str(LANG_TAGCACHE_INIT), ret, 7);
  195. #else
  196.             lcd_double_height(false);
  197.             snprintf(buf, sizeof(buf), " TC [%d/%d]", ret, 7);
  198.             lcd_puts(0, 1, buf);
  199. #endif
  200.             clear = true;
  201.         }
  202.         sleep(HZ/4);
  203.     }
  204.     tagtree_init();
  205.  
  206.     if (clear)
  207.     {
  208.         backlight_on();
  209.         show_logo();
  210.     }
  211. }
  212. #endif
  213.  
  214. #ifdef SIMULATOR
  215.  
  216. void init(void)
  217. {
  218.     init_threads();
  219.     buffer_init();
  220.     lcd_init();
  221. #ifdef HAVE_REMOTE_LCD
  222.     lcd_remote_init();
  223. #endif
  224.     font_init();
  225.     show_logo();
  226.     button_init();
  227.     backlight_init();
  228.     lang_init();
  229. #if CONFIG_CODEC == SWCODEC
  230.     audio_preinit();    /* Must be done before settings_apply() */
  231. #endif
  232.     /* Must be done before any code uses the multi-screen APi */
  233.     screen_access_init();
  234.     gui_syncstatusbar_init(&statusbars);
  235.     settings_reset();
  236.     settings_calc_config_sector();
  237.     settings_load(SETTINGS_ALL);
  238.     gui_sync_wps_init();
  239.     settings_apply();
  240.     init_dircache(true);
  241.     init_dircache(false);
  242. #ifdef HAVE_TAGCACHE
  243.     init_tagcache();
  244. #endif
  245.     sleep(HZ/2);
  246.     tree_init();
  247.     playlist_init();
  248.     mp3_init( global_settings.volume,
  249.               global_settings.bass,
  250.               global_settings.treble,
  251.               global_settings.balance,
  252.               global_settings.loudness,
  253.               global_settings.avc,
  254.               global_settings.channel_config,
  255.               global_settings.stereo_width,
  256.               global_settings.mdb_strength,
  257.               global_settings.mdb_harmonics,
  258.               global_settings.mdb_center,
  259.               global_settings.mdb_shape,
  260.               global_settings.mdb_enable,
  261.               global_settings.superbass);
  262.  
  263.     scrobbler_init();
  264.    
  265.     /* audio_init must to know the size of voice buffer so init voice first */
  266. #if CONFIG_CODEC == SWCODEC
  267.     talk_init();
  268. #endif
  269.  
  270.     audio_init();
  271.     button_clear_queue(); /* Empty the keyboard buffer */
  272. }
  273.  
  274. #else
  275.  
  276. void init(void)
  277. {   
  278.     volatile unsigned int* ptr;
  279.     ptr = (volatile unsigned int*)0x70000020;
  280.    
  281.     int rc;
  282.     bool mounted = false;
  283. #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
  284.     /* if nobody initialized ATA before, I consider this a cold start */
  285.     bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */
  286. #endif
  287.         *ptr |= (1 << 13);
  288.     system_init();
  289.     *ptr &= ~(1 << 13);
  290.     kernel_init();
  291.         *ptr |= (1 << 13);
  292. #ifdef HAVE_ADJUSTABLE_CPU_FREQ
  293.     set_cpu_frequency(CPUFREQ_NORMAL);
  294. #ifdef CPU_COLDFIRE
  295.     coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS);
  296. #endif
  297.     cpu_boost_id(true, CPUBOOSTID_MAININIT);
  298. #endif
  299.    
  300.     buffer_init();
  301.  
  302.     settings_reset();
  303.  
  304.     power_init();
  305.  
  306.     set_irq_level(0);
  307.     /*lcd_init();*/ /*Turn it off for debug*/
  308.    
  309. #ifdef HAVE_REMOTE_LCD
  310.     lcd_remote_init();
  311. #endif
  312.     font_init();
  313.     show_logo();
  314.     lang_init();
  315.  
  316. #ifdef DEBUG
  317.     debug_init();
  318. #else
  319. #ifndef HAVE_MMC  /* FIXME: This is also necessary for debug builds
  320.                    * (do debug builds on the Ondio make sense?) */
  321.     serial_setup();
  322. #endif
  323. #endif
  324.  
  325.     i2c_init();
  326.  
  327. #ifdef CONFIG_RTC
  328.     rtc_init();
  329. #endif
  330. #ifdef HAVE_RTC_RAM
  331.     settings_load(SETTINGS_RTC); /* early load parts of global_settings */
  332. #endif
  333.  
  334.     adc_init();
  335.    
  336.     usb_init();
  337. #if CONFIG_USBOTG == USBOTG_ISP1362
  338.     isp1362_init();
  339. #elif CONFIG_USBOTG == USBOTG_M5636
  340.     m5636_init();
  341. #endif
  342.  
  343.     backlight_init();
  344.  
  345.     button_init();
  346.  
  347.     powermgmt_init();
  348.    
  349. #if CONFIG_CODEC == SWCODEC
  350.     audio_preinit();
  351. #endif
  352.  
  353. #ifdef CONFIG_TUNER
  354.     radio_init();
  355. #endif
  356.  
  357.     /* Must be done before any code uses the multi-screen APi */
  358.     screen_access_init();
  359.     gui_syncstatusbar_init(&statusbars);
  360.  
  361. #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
  362.     if (coldstart && charger_inserted()
  363.         && !global_settings.car_adapter_mode
  364. #ifdef ATA_POWER_PLAYERSTYLE
  365.         && !ide_powered() /* relies on probing result from bootloader */
  366. #endif
  367.         )
  368.     {
  369.         rc = charging_screen(); /* display a "charging" screen */
  370.         if (rc == 1)            /* charger removed */
  371.             power_off();
  372.         /* "On" pressed or USB connected: proceed */
  373.         show_logo();  /* again, to provide better visual feedback */
  374.     }
  375. #endif
  376.  
  377.     ata_idle_notify_init();
  378.     rc = ata_init();
  379.     if(rc)
  380.     {
  381. #ifdef HAVE_LCD_BITMAP
  382.         char str[32];
  383.         lcd_clear_display();
  384.         snprintf(str, 31, "ATA error: %d", rc);
  385.         lcd_puts(0, 1, str);
  386.         lcd_puts(0, 3, "Press ON to debug");
  387.         lcd_update();
  388.         while(!(button_get(true) & BUTTON_REL)); /*DO NOT CHANGE TO ACTION SYSTEM */
  389.         dbg_ports();
  390. #endif
  391.         panicf("ata: %d", rc);
  392.     }
  393.  
  394. #ifdef HAVE_EEPROM_SETTINGS
  395.     eeprom_settings_init();
  396. #endif
  397.    
  398.     usb_start_monitoring();
  399.     while (usb_detect())
  400.     {   
  401. #ifdef HAVE_EEPROM_SETTINGS
  402.         firmware_settings.disk_clean = false;
  403. #endif
  404.         /* enter USB mode early, before trying to mount */
  405.         if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
  406. #ifdef HAVE_MMC
  407.             if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED))
  408. #endif
  409.             {
  410.                 usb_screen();
  411.                 mounted = true; /* mounting done @ end of USB mode */
  412.             }
  413. #ifdef HAVE_USB_POWER
  414.         if (usb_powered())      /* avoid deadlock */
  415.             break;
  416. #endif
  417.     }
  418.  
  419.     if (!mounted)
  420.     {
  421.         rc = disk_mount_all();
  422.         if (rc<=0)
  423.         {
  424.             lcd_clear_display();
  425.             lcd_puts(0, 0, "No partition");
  426.             lcd_puts(0, 1, "found.");
  427. #ifdef HAVE_LCD_BITMAP
  428.             lcd_puts(0, 2, "Insert USB cable");
  429.             lcd_puts(0, 3, "and fix it.");
  430.             lcd_update();
  431. #endif
  432.             while(button_get(true) != SYS_USB_CONNECTED) {};
  433.             usb_screen();
  434.             system_reboot();
  435.         }
  436.     }
  437.  
  438.     settings_calc_config_sector();
  439.    
  440. #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IRIVER_H10_PAD)
  441. #ifdef SETTINGS_RESET
  442.     /* Reset settings if holding the rec button. */
  443.     if ((button_status() & SETTINGS_RESET) == SETTINGS_RESET)
  444. #else
  445.     /* Reset settings if the hold button is turned on */
  446.     if (button_hold())
  447. #endif
  448.     {
  449.         gui_syncsplash(HZ*2, true, str(LANG_RESET_DONE_CLEAR));
  450.         settings_reset();
  451.     }
  452.     else
  453. #endif
  454.         settings_load(SETTINGS_ALL);
  455.  
  456.     if (init_dircache(true) < 0)
  457.     {
  458. #ifdef HAVE_TAGCACHE
  459.         remove(TAGCACHE_STATEFILE);
  460. #endif
  461.     }
  462.    
  463.     gui_sync_wps_init();
  464.     settings_apply();
  465.     init_dircache(false);
  466. #ifdef HAVE_TAGCACHE
  467.     init_tagcache();
  468. #endif
  469.  
  470. #ifdef HAVE_EEPROM_SETTINGS
  471.     if (firmware_settings.initialized)
  472.     {
  473.         /* In case we crash. */
  474.         firmware_settings.disk_clean = false;
  475.         eeprom_settings_store();
  476.     }
  477. #endif
  478.     status_init();
  479.     playlist_init();
  480.     tree_init();
  481.     scrobbler_init();
  482.  
  483.     /* No buffer allocation (see buffer.c) may take place after the call to
  484.        audio_init() since the mpeg thread takes the rest of the buffer space */
  485.     mp3_init( global_settings.volume,
  486.               global_settings.bass,
  487.               global_settings.treble,
  488.               global_settings.balance,
  489.               global_settings.loudness,
  490.               global_settings.avc,
  491.               global_settings.channel_config,
  492.               global_settings.stereo_width,
  493.               global_settings.mdb_strength,
  494.               global_settings.mdb_harmonics,
  495.               global_settings.mdb_center,
  496.               global_settings.mdb_shape,
  497.               global_settings.mdb_enable,
  498.               global_settings.superbass);
  499.  
  500.      /* audio_init must to know the size of voice buffer so init voice first */
  501.     talk_init();
  502.  
  503.     audio_init();
  504. #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
  505.     pcm_rec_init();
  506. #endif
  507.  
  508.     /* runtime database has to be initialized after audio_init() */
  509.     cpu_boost_id(false, CPUBOOSTID_MAININIT);
  510.  
  511. #ifdef AUTOROCK
  512.     {
  513.         int fd;
  514.         static const char filename[] = PLUGIN_DIR "/autostart.rock";
  515.  
  516.         fd = open(filename, O_RDONLY);
  517.         if(fd >= 0) /* no complaint if it doesn't exist */
  518.         {
  519.             close(fd);
  520.             plugin_load((char*)filename, NULL); /* start if it does */
  521.         }
  522.     }
  523. #endif /* #ifdef AUTOROCK */
  524.  
  525. #ifdef CONFIG_CHARGING
  526.     car_adapter_mode_init();
  527. #endif
  528. }
  529.  
  530. #ifdef CPU_PP
  531. void cop_main(void)
  532. {
  533. /* This is the entry point for the coprocessor
  534.    Anyone not running an upgraded bootloader will never reach this point,
  535.    so it should not be assumed that the coprocessor be usable even on
  536.    platforms which support it.
  537.  
  538.    At present all we do is send the COP to sleep if anything wakes it. */
  539.     while(1) {
  540.         COP_CTL = PROC_SLEEP;
  541.     }
  542. }
  543. #endif
  544.  
  545. int main(void)
  546. {
  547.     app_main();
  548.  
  549.     while(1) {
  550. #if CONFIG_LED == LED_REAL
  551.         led(true); sleep(HZ/10);
  552.         led(false); sleep(HZ/10);
  553. #endif
  554.     }
  555.     return 0;
  556. }
  557. #endif

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right
worth-right