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 using System; 9 using Antmicro.Renode.Peripherals.Bus; 10 using Antmicro.Renode.Logging; 11 using Antmicro.Renode.Core; 12 13 namespace Antmicro.Renode.Peripherals.GPIOPort 14 { 15 public class EFMGPIOPort : BaseGPIOPort, IDoubleWordPeripheral, IKnownSize 16 { EFMGPIOPort(IMachine machine)17 public EFMGPIOPort(IMachine machine) : base(machine, 6*16) 18 { 19 20 } 21 22 public long Size 23 { 24 get 25 { 26 return 0x140; 27 } 28 } 29 ReadDoubleWord(long offset)30 public uint ReadDoubleWord(long offset) 31 { 32 this.LogUnhandledRead(offset); 33 return 0; 34 } 35 WriteDoubleWord(long offset, uint value)36 public void WriteDoubleWord(long offset, uint value) 37 { 38 var portNumber = (int)(offset / 0x24); 39 if(portNumber <= 6) 40 { 41 offset %= 0x24; 42 switch((Offset)offset) 43 { 44 case Offset.Set: 45 DoPinOperation(portNumber, Operation.Set, value); 46 break; 47 case Offset.Clear: 48 DoPinOperation(portNumber, Operation.Clear, value); 49 break; 50 case Offset.Toggle: 51 DoPinOperation(portNumber, Operation.Toggle, value); 52 break; 53 default: 54 this.LogUnhandledWrite(offset, value); 55 break; 56 } 57 } 58 else 59 { 60 this.LogUnhandledWrite(offset, value); 61 } 62 } 63 DoPinOperation(int portNumber, Operation operation, uint value)64 private void DoPinOperation(int portNumber, Operation operation, uint value) 65 { 66 for(var i = 0; i < 15; i++) 67 { 68 var pinNumber = portNumber * 16 + i; 69 if((value & 1) != 0) 70 { 71 switch(operation) 72 { 73 case Operation.Set: 74 Connections[pinNumber].Set(); 75 break; 76 case Operation.Clear: 77 Connections[pinNumber].Unset(); 78 break; 79 case Operation.Toggle: 80 Connections[pinNumber].Toggle(); 81 break; 82 } 83 } 84 value >>= 1; 85 } 86 } 87 88 private enum Operation 89 { 90 Set, 91 Clear, 92 Toggle 93 } 94 95 private enum Offset : uint 96 { 97 Set = 0x10, 98 Clear = 0x14, 99 Toggle = 0x18 100 } 101 } 102 } 103 104