##############################################################################
# Copyright (c) 2006, National ICT Australia
##############################################################################
# Copyright (c) 2007 Open Kernel Labs, Inc. (Copyright Holder).
# All rights reserved.
# 
# 1. Redistribution and use of OKL4 (Software) in source and binary
# forms, with or without modification, are permitted provided that the
# following conditions are met:
# 
#     (a) Redistributions of source code must retain this clause 1
#         (including paragraphs (a), (b) and (c)), clause 2 and clause 3
#         (Licence Terms) and the above copyright notice.
# 
#     (b) Redistributions in binary form must reproduce the above
#         copyright notice and the Licence Terms in the documentation and/or
#         other materials provided with the distribution.
# 
#     (c) Redistributions in any form must be accompanied by information on
#         how to obtain complete source code for:
#        (i) the Software; and
#        (ii) all accompanying software that uses (or is intended to
#        use) the Software whether directly or indirectly.  Such source
#        code must:
#        (iii) either be included in the distribution or be available
#        for no more than the cost of distribution plus a nominal fee;
#        and
#        (iv) be licensed by each relevant holder of copyright under
#        either the Licence Terms (with an appropriate copyright notice)
#        or the terms of a licence which is approved by the Open Source
#        Initative.  For an executable file, "complete source code"
#        means the source code for all modules it contains and includes
#        associated build and other files reasonably required to produce
#        the executable.
# 
# 2. THIS SOFTWARE IS PROVIDED ``AS IS'' AND, TO THE EXTENT PERMITTED BY
# LAW, ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED.  WHERE ANY WARRANTY IS
# IMPLIED AND IS PREVENTED BY LAW FROM BEING DISCLAIMED THEN TO THE
# EXTENT PERMISSIBLE BY LAW: (A) THE WARRANTY IS READ DOWN IN FAVOUR OF
# THE COPYRIGHT HOLDER (AND, IN THE CASE OF A PARTICIPANT, THAT
# PARTICIPANT) AND (B) ANY LIMITATIONS PERMITTED BY LAW (INCLUDING AS TO
# THE EXTENT OF THE WARRANTY AND THE REMEDIES AVAILABLE IN THE EVENT OF
# BREACH) ARE DEEMED PART OF THIS LICENCE IN A FORM MOST FAVOURABLE TO
# THE COPYRIGHT HOLDER (AND, IN THE CASE OF A PARTICIPANT, THAT
# PARTICIPANT). IN THE LICENCE TERMS, "PARTICIPANT" INCLUDES EVERY
# PERSON WHO HAS CONTRIBUTED TO THE SOFTWARE OR WHO HAS BEEN INVOLVED IN
# THE DISTRIBUTION OR DISSEMINATION OF THE SOFTWARE.
# 
# 3. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ANY OTHER PARTICIPANT BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from simulators import qemu_gta_sim

class s3c2442(arm920t):
    virtual = False
    platform = "s3c2442"
    platform_dir = "s3c2442"
    memory = arm920t.memory.copy()
    timer_driver = "s3c2442_timer"
    # rtc_driver = "s3c2442_rtc"
    serial_driver = "s3c2442_uart"
    # lcd_driver = "s3c2442_lcd"
    # touch_driver = "s3c2442_touch"
    # spi_driver = "s3c2442_spi"
    # mtd_driver = "s3c2442_nand"
    # drivers = [timer_driver, serial_driver, lcd_driver]
    drivers = [timer_driver, serial_driver]
    memory_timer = [Region(0x51000000, 0x51001000, "all", "uncached")]
    interrupt_timer = [11] # PWM timer 1 uses interupt 11
    memory_serial = [Region(0x50008000, 0x50009000, "all", "uncached")]
    interrupt_serial = [38, 39] # UART2 use sub-interrupts 6,7 
    # memory_touch = [Region(0x58000000, 0x58001000, "all", "uncached")]
    # interrupt_touch = [41, 42]
    # memory_lcd = [Region(0x4d000000, 0x4d001000, "all", "uncached")]
    # interrupt_lcd = [16]
    # memory_rtc = [Region(0x57000000, 0x57001000, "all", "uncached")]
    # interrupt_rtc = [30]
    # memory_mtd = [Region(0x4E000000, 0x4E001000, "all", "uncached")]
    # interrupt_mtd = []
    
    v2_drivers = [
                 # ("test_device", "vtest", [], [1,3]),
                 ("s3c2442_timer", "vtimer", memory_timer, interrupt_timer),
                 ("s3c2442_uart", "vserial", memory_serial, interrupt_serial),
                 # # ("s3c2442_lcd", "vlcd", memory_lcd, interrupt_lcd),
                 # ("s3c2442_rtc", "vrtc", memory_rtc, interrupt_rtc),
                 # ("s3c2442_nand", "vmtd", memory_mtd, interrupt_mtd),
                 # # ("s3c2442_spi", "vbus"),
                 # ("s3c2442_touch", "vtouch", memory_touch, interrupt_touch),
                 ]
    
    zero_bss = True	 

class gta02(s3c2442):
    virtual = False
    subplatform = "gta02"

    skyeye = "gta02.skyeye"
    device_core = "gta02"
    memory = s3c2442.memory.copy()
    memory['physical'] = [Region(0x30000000L, 0x38000000L)]
#    memory['reserved'] = [Region(0x60000000L, 0xffffffffL, "reserved")]
#    memory['sfr']      = [Region(0x48000000L, 0x60000000L, "all")]
#    memory['rom']      = [Region(0x00000000L, 0x08000000L, "all")]
#    memory['sdram']    = [Region(0x00000000L, 0x00001000L, "all")]
    
    # UART0 - gsm modem
    # UART1 - gps
    # UART2 - serial console
    cpp_defines = s3c2442.cpp_defines + [("PLATFORM_S3C2442", 1), ("SERIAL_UART", 2), ("CONFIG_C15_CLOCK","C15_CONTROL_CK_ASync"), ("CONFIG_VERBOSE_INIT"), ("CONFIG_KDB_ON_STARTUP")]

    run_methods = {
        "qemu" : qemu_gta_sim,
        "skyeye" : skyeye_sim
    }
    default_method = "qemu"

# This is the same as the original gta02, except we name some of the RAM as 'ROM' and
# use this to run the rommable regressions
class gta02_xip(gta02):
    # we choose to have 2MB of fake ROM
    memory = s3c2442.memory.copy()
    memory['rom'] = [Region(0x30000000L, 0x30200000L)]
    memory['physical'] = [Region(0x30200000L, 0x38000000L)]



