Creating a microcontroller startup file

Jens Bauer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 10 17:43:01 PDT 2015


On Friday, 10 April 2015 at 00:05:29 UTC, Mike wrote:
> On Wednesday, 8 April 2015 at 15:25:20 UTC, Jens Bauer wrote:
>
>>>> Question number 2: Is it possible to change the VectorFunc 
>>>> to be a real function pointer, rather than a void* ?
>>
>> Can you successfully cast(ISR)&_stack ?
>
> I don't know if that's a constraint of the language or a 
> limitation of the current CTFE implementation, but either way, 
> I never really liked it.
I don't really like typecasting myself, but I know a function 
pointer and a stack pointer are both pointers, thus they're the 
same size.

> I know the C folks do this stuff all the time, but I think it's 
> kinda janky.

True, but I need to write my files flexible, so that the majority 
of people will be able to use it out-of-the-box. I have to keep 
in mind that there are people who will make a part of their code 
in C during the transition phase, and I have to keep in mind that 
those who wrote the library in C, probably won't provide a 
complete library in D within the first week. ;)

I agree with you on the 'minimal' style. I too hate all the junk 
that's added. 'printf' has always been prohibited in my 
microcontroller code - I don't have a file system on my 
microcontroller; no screen, no keyboard and no harddisk, thus I 
don't want anything that has any connection to printf or a file 
system. ;)

Basically my startup.d will be very similar to the startup.s you 
already know (I translated my startup.s into a startup.c a long 
time ago - because I didn't want one for each type of assembler).

> I know of two potential alternatives:
> 1)  Do it in the linker script (my current method):

Two things makes me little fond of this solution:
1: The "LONG" type. If it had been "PTR" or "UINT32", then it 
would be more attractive, but I do not expect those types exist.
2: I like people to be able to define the stack location inside 
the sources if they want to.
That means: Typically the linker script will provide it, but some 
people need to move the stack, and I don't want them to need to 
change the linker script (if at all possible).

> 2) Use a union (See pp. 10 here:
This solution is probably more appealing to me.
I'll need to make some more tests.

My initial attempt was to create a function, which did the type 
conversion via a CTFE function, buuut it didn't like that the 
symbol was undefined and not a constant, so I'll have to make a 
few more attempts.

Thank you again for your valuable help. I hope that my fiddling 
will bring you something useful too. ;)


More information about the Digitalmars-d-learn mailing list