1 // 2 // Copyright (c) 2010-2018 Antmicro 3 // Copyright (c) 2011-2015 Realtime Embedded 4 // 5 // This file is licensed under the MIT License. 6 // Full license text is available in 'licenses/MIT.txt'. 7 // 8 9 using Antmicro.Renode.Core; 10 using Antmicro.Renode.Peripherals.Bus; 11 using Antmicro.Renode.Utilities; 12 using Antmicro.Renode.Peripherals.Timers; 13 using System; 14 using Antmicro.Renode.Logging; 15 using Antmicro.Renode.Time; 16 17 namespace Antmicro.Renode.Peripherals.Timers 18 { 19 public class OMAP_GPTimer : LimitTimer, IDoubleWordPeripheral 20 { OMAP_GPTimer(IMachine machine)21 public OMAP_GPTimer(IMachine machine) : base (machine.ClockSource, (38400000), direction: Direction.Ascending, limit: (0xFFFFFFFF), enabled: true) 22 { // TODO: hack - 10 times slower, because of Stopwatch limitation 23 AutoUpdate = true; 24 IRQ = new GPIO(); 25 } 26 27 public GPIO IRQ { get; private set; } 28 OnLimitReached()29 protected override void OnLimitReached() 30 { 31 this.NoisyLog("Alarm!!!"); 32 if(it_ena > 0) 33 { 34 this.NoisyLog("generate interrupt"); 35 IRQ.Set(true); 36 } 37 } 38 ReadDoubleWord(long offset)39 public uint ReadDoubleWord(long offset) 40 { 41 if(offset == 0x10) 42 { 43 return config; 44 } // TIOCP_CFG 45 if(offset == 0x14) 46 { 47 return 1; 48 } //(uint)((this.Value*10) & 0xFFFFFFFF); 49 if(offset == 0x2c) 50 { 51 return load_val; 52 } 53 if(offset == 0x28) 54 { 55 return (uint)this.Value; 56 } // TCRR 57 return 0; 58 } 59 WriteDoubleWord(long offset, uint value)60 public void WriteDoubleWord(long offset, uint value) 61 { 62 if(offset == 0x10) 63 { 64 config = value & 0x33d; 65 } 66 if(offset == 0x1c) 67 { 68 it_ena = value & 0x7; 69 } 70 if(offset == 0x24) 71 { 72 if((value & (1 << 5)) > 0) 73 { 74 Divider = (int)Math.Pow(2, (((value >> 2) & 7) + 1)); 75 } 76 else 77 { 78 Divider = (int)Math.Pow(2, 0); 79 } 80 Enabled = ((value & 1) > 0); 81 } 82 if(offset == 0x2C) 83 { 84 this.Limit = 0xFFFFFFFF - value; 85 load_val = value; 86 } 87 if(offset == 0x18) 88 { 89 IRQ.Set(false); 90 } 91 if(offset == 0x28) 92 { 93 this.NoisyLog("timer is at {0} of {1}", this.Value, this.Limit); 94 } 95 } 96 97 uint config = 0; 98 uint load_val = 0; 99 uint it_ena = 0; 100 } 101 } 102 103