private void DefineChannelRegisters(int channel, Registers valueRegister, Registers currentValueRegister, Registers controlRegister) { valueRegister.Define(this) .WithValueField(0, 32, name: "TMR_VAL - Timer Value", changeCallback: (x, value) => timers[channel].ValueSet = value, valueProviderCallback: (value) => timers[channel].ValueSet); currentValueRegister.Define(this) .WithValueField(0, 32, FieldMode.Read, name: "TMR_CUR_VAL - Current Timer Value", valueProviderCallback: (value) => timers[channel].Enabled ? (uint)timers[channel].Value : uint.MaxValue); controlRegister.Define(this) .WithFlag(0, name: "T_EN - Timer Enable", changeCallback: (x, value) => timers[channel].SetTimerEnabled(value), valueProviderCallback: (value) => timers[channel].Enabled) .WithTaggedFlag("CHAIN - Chain Channel", 1) .WithEnumField <DoubleWordRegister, OperationModes>(2, 2, name: "MODE - Timer Operation Mode", changeCallback: (x, value) => timers[channel].OperationMode = value, valueProviderCallback: (value) => timers[channel].OperationMode) .WithReservedBits(4, 12) .WithTaggedFlag("TSOT - Timer Start On Trigger", 16) .WithFlag(17, name: "TSOI - Timer Stop On Interrupt", changeCallback: (x, value) => timers[channel].Mode = value ? WorkMode.OneShot : WorkMode.Periodic, valueProviderCallback: (value) => timers[channel].Mode == WorkMode.OneShot) .WithTaggedFlag("TROT - Timer Reload On Trigger", 18) .WithReservedBits(19, 4) .WithEnumField <DoubleWordRegister, TriggerModes>(23, 1, name: "TRG_SRC - Trigger Source", changeCallback: (x, value) => timers[channel].TriggerMode = value, valueProviderCallback: (value) => timers[channel].TriggerMode) .WithTag("TRG_SEL - Trigger Select", 24, 4) .WithReservedBits(28, 4); }
private void DefineTask(Registers register, Action callback, string name) { register.Define(this, name: name) .WithFlag(0, FieldMode.Write, writeCallback: (_, value) => { if (value) { callback(); } }) .WithReservedBits(1, 31) ; }
private void DefineEvent(Registers register, Action callbackOnSet, Events @event, string name) { register.Define(this, name: name) .WithFlag(0, out events[(int)@event], writeCallback: (_, value) => { if (value) { callbackOnSet(); } else { interruptManager.SetInterrupt(@event, false); } }) .WithReservedBits(1, 31) ; }