Driving with D

This is what comes to my mind when I think of D: fast, expressive, light and ... driving? That's right, I drive with D.





Here is my venerable Holden VZ Ute car . It came from the factory with a squalid four-speed automatic transmission. In 18 months of owning a car, I broke four gearboxes. At the time, I couldn't afford a new car, so I had to be creative. I bought a reinforced concrete, foolproof six-speed automatic transmission from another car. But on this I ran into a dead end. To make it work, I had to build my own PCB, control system, and firmware to control the solenoids, hydraulics, and clutches inside the gearbox, process driver commands, make gear change decisions, and interact with the car, pretending to be a four-speed automatic.






I am very proud of my decision. It can switch in 250 milliseconds, which is great for racing. It has a steep first gear for a quick start. It gave odds to some of the more powerful cars. It has handy paddle shifters, on-screen diagnostic data, and the ability to change how it works whenever I want.





Here's a very old video of how the system works. It is not indicative of the current system - that terrible blue screen has disappeared, the speedometer is working, and the gearshift has improved.





: , OLED- STM32F042, , , STM32F407. CAN (Controller Area Network). D.





D ( -betterC) - (UFCS), , C, -, , shared



@safe



. - , . D , .





D

(UFCS)





. , , . , , ECU ( ):





immutable injectorTime = airStoich(100.kpa, 25.degCelsius)
    .airMass
    .fuelMass((14.7f).afr)
    .fuelMol
    .calculateInjectorWidth;
      
      



, . .









" " (DRY) . D . CAN. :





struct CANPacket(ushort ID) {
    enum id = ID;
    ubyte[8] data;
}
alias HeartbeatPacket = CANPacket!10;
alias BeepHornPacket = CANPacket!140;
      
      



HeartbeatPacket



BeepHornPacket



, . , CANPacket



, .









HAL RTOS ; D's C . extern(C)



, .





extern(C) c_setPwm(int solenoid, void* userData); // declaration
c_setPwm(4, null); // usage, pretty easy!
      
      



-





D - . Windows, , .









, D GDC LDC. D, C++ (). LDC, - .





Shared





Shared - D () . , , , . , . , , . . shared . .





shared int sensorValue;
sensorValue = 4; // using it like a single-thread variable, error
atomicStore(sensorValue, 4); // works with atomics
      
      



SafeD





@safe



, . @safe



, , , , .









. : D . . D. , , D - , .





D - , . D . D, .





:

  1. , .





  2. -BetterC, , (GC) .





  3. , BetterC , .





  4. D ? - .





  5. D ? - .





D

LWDR (Light Weight D Runtime) v0.3.0 -





Github





DUB





()





LWDR (Light Weight D Runtime) - D, ARM Cortex-M . , API ( rtoslink.d, / RTOS).





V0.3.0 LWDR. V0.2.3, :





  1. (Thread Local Storage, TLS)





  2. Phobos, GC





  3. (opt-in)





  4. delete



    LWDR.free(...)











  5. RefCount!T



    Unique!T



    , LWDR





Thread Local Storage

, LWDR_TLS



. tdata



tbss



. , TLS RTOS (). LWDR.registerCurrentThread()



D, TLS , TCB (Thread Control Block) . TLS (.. ) __aeabi_read_tp



, .





. , GC- stdlib (Phobos). , .





(opt-in)

TypeInfo



vtables , LWDR opt-in, version D. :





  1. LWDR_TLS



     - TLS





  2. LWDR_DynamicArray



     -





  3. LWDR_TrackMem



     - (.)





delete

delete



. LWDR.free



.





- , , . ddoc.





RefCount!T Unique!T

(GC), LWDR , automem.





  1. Class allocations and deallocations (via new



     and LWDR.free



    )





  2. Struct heap allocations and deallocations (via new



     and LWDR.free



    )





  3. Invariants





  4. Asserts





  5. Contract programming





  6. Basic RTTI (via TypeInfo



     stubs)





  7. Interfaces





  8. Static Arrays





  9. Virtual functions and overrides





  10. Abstract classes





  11. Static classes





  12. Allocation and deallocation of dynamic arrays (opt in by version LWDR_DynamicArray



    )





  13. Concatenate an item to a dynamic array (opt in by version LWDR_DynamicArray



    )





  14. Concatenate two dynamic arrays together (opt in by version LWDR_DynamicArray



    )





  15. Dynamic array resizing (opt in by version LWDR_DynamicArray



    )





  16. Thread local storage (opt in by version LWDR_TLS



    )





()

  1. Exceptions and Throwables ( )





  2. Module constructors and destructors





  3. Static constructors and destructors





  4. Shared static constructors and destructors





  5. Module info





  6. There is no GC implementation (primitive memory tracking is now available with LWDR_TrackMem



    RefCount!T



     and Unique!T



     are now available)





  7. Delegates/closures





  8. Associative arrays





  9. Object monitors





  10. shared



    /synchronised







  11. Object hashing





  12. , .





- - . , - .





, , LWDR . Driving with D ( ) (. - ). LWDR Autumn of Code.





LWDR , , , ctor/dtor (, ..).








All Articles