Bug in Codewarrior for HC12?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bug in Codewarrior for HC12?

3,817 Views
notting
Contributor I
Hi!

I'm currently adapting a small static "multi-tasking OS" for the HC12 written in C. It was created by other students of my university with ICC12. My job is to make it work with Codewarrior (so it can be compiled there with chc12.exe (I'm currently using V-5.0.24 Build 4047) and VisualStudio can be used as editor). It is working nearly perfect - except of one little thing.
There are four modes: Round-Robin and Lottery, each with and without priorities.
In Round-Robin mode it works perfectly. In Lottery, there is a random number generator as assembler code in the C code. It creates a number from 0 to (the number of threads - 1). After that, a for-slope decrements that value to 0. Every time it decrements that value by 1, it also set the pointer from the current thread to the next one (thread number + 1; if the next thread number doesn't exists -> thread number = 0) so the next thread is chosen randomly.

---- piece of C code ----

asm(" LDAA random\n ROLA\n ROLA\n ROLA\n EORA random\n COMA\n ROLA\n LDAA random\n ROLA\n STAA random"); /* Generate random number */

jumps=random%NUMBER_OF_THREADS;

for(;jumps>0;jumps--){ /* Chose next thread randomly */
ThreadRunPtr=ThreadRunPtr->Next;
}

---- piece of C code ----

But that doesn't work! One thread is chosen at the very beginning which runs all the time.
Now the funny thing: With a "NOP" for example as first instruction within the for-slope it works perfectly!
The disassembled programs without and with that NOP are looking pretty similar, at least at the beginning. But there is also a significant difference: In first case there is a "bset" and in second case at the same address there is a "call".

Could that be the reason for the problem? A bug in Codewarrior?

But I don't know how I should update. I can't find that page with Codewarrior for HC12 and the link to the 32k student license on www.metrowerks.com anymore. And the updater doesn't show suitable updates as far I understand that (and sometimes it doesn't work although I really don't have any problems with my internet connection).

Because I don't know if you prefere the complete C code or the disassembled program, please tell me if and what you need to tell me more.

TIA!
Labels (1)
Tags (1)
0 Kudos
5 Replies

500 Views
rocco
Senior Contributor II
Hi, notting:

It looks like a mistake in your asm code. The first seven instructions do a good job of juggling bits, but the eighth instruction undoes what the first seven did, rendering the first seven instructions as a long, drawn-out nop.

The net result is:

LDAA random
ROLA
STAA random

. . . which isn't very random at all.
0 Kudos

500 Views
notting
Contributor I
Hi rocco!

I found the same random generator at http://pubpages.unh.edu/~cmg/ece612/CMG3.LST

;Random number generator
1051 b6 30 00 RANDOM: LDAA $3000
1054 45 ROLA
1055 45 ROLA
1056 45 ROLA
1057 b8 30 00 EORA $3000 ;XOR 4TH & 7TH BITS
105a 41 COMA ;COMPLEMENT A
105b 45 ROLA ;7TH BIT INTO CARRY
105c b6 30 00 LDAA $3000 ;RESTORE THE NUMBER
105f 45 ROLA ;RESULT IS THE NEW RND #
1060 7a 30 00 STAA $3000 ;SAVE THE CURRENT RND
1063 3d RTS

But when it works, it's randomly enough for that job :smileyhappy:

notting
0 Kudos

500 Views
rocco
Senior Contributor II
Oops, sorry notting, I didn't look close enough. my bad.

The result of the first seven instructions is actually in the carry bit, and is then propagated into the final result in the ninth instruction.

It really helps when the code is commented.
0 Kudos

500 Views
CompilerGuru
NXP Employee
NXP Employee
HC12 V4.5 can be downloaded from the Freescale web site.
This version contains the "HC12 V-5.0.30 Build 6037, Feb 7 2006" compiler.

About your problem, I'm not sure its a bug. The best would be a as simple as possible, compilable and runnable sample with a description what you see, and what you expect.

Daniel
0 Kudos

500 Views
notting
Contributor I
Hi CompilerGuru!



CompilerGuru wrote:
HC12 V4.5 can be downloaded from the Freescale web site.
This version contains the "HC12 V-5.0.30 Build 6037, Feb 7 2006" compiler.

About your problem, I'm not sure its a bug. The best would be a as simple as possible, compilable and runnable sample with a description what you see, and what you expect.

Daniel




Ok, then I'll try the new version if there is no other way (I hope I'll find it on the website until then...).

Because it is probably too much, I uploaded it on the web. That link is valid until May, 21st:
http://service.gmx.net/mc/lwLILADLF7QzM7vsiLol8er2xI2ta9
Click on the image button "GMX MediaCenter starten" (I don't know if that service is able to "speak" other languages) and then click on the icon of that file (notting.zip).

I compiled everything with this command line:
C:\Programme\Metrowerks\CodeWarrior CW12_V3.1\prog\chc12.exe -prod=D:\1 -ObjN=%(OBJPATH)\main.o main.c

(also all threads)

Linker:
C:\Programme\Metrowerks\CodeWarrior CW12_V3.1\prog\linker.exe -b -prod=D:\1 -add(main.o thread1.o thread2.o thread3.o thread4.o) D:\1\prm\RAM.prm

Every thread sends its thread number (1...4) via SCI to the terminal. I uploaded the version with NOP. The result looks like this in the terminal:

>load
**
>g 829
44444444444444443333333333333333222222222222222211111111111111113333333333333333333333333333333333333333333333344444444444444443333333333333331111111111111111111111111111111111111111111111111111111111111111111111111111111222222222222222244444444444444444444444444444441111111111111111444444444444444422222222222222223333333333333332222222222222222111111111111111133333333333333334444444444444443333333333333333222222222222222244444444444444444444444444444441111111111111111444444444444444422222222222222222222222222222222222222222222222333333333333333311111111111111112222222222222222444444444444444444444444444444444444444444444441111111111111111333333333333333333333333333333344444444444444442222222222222222222222222222222333333333333333322222222222222221111111111111111444444444444444333333333333333322222222222222224444444444444444444444444444444111111111111111144444444444444443333333333333333111111111111111111111111111111122222222222222224444444444444444444444444444444444444444444444444444444444444441111111111111111444444444444444333333333333333311111111111111112222222222222222444444444444444444444444444444444444444444444444444444444444444111111111111111333333333333333344444444444444442222222222222222333333333333333111111111111111122222222222222224444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444111111111111111133333333333333334444444444444444333333333333333222222222222222244444444444444441111111111111111333333333333333444444444444444422222222222222222222222222222222333333333333333111111111111111111111111111111111111111111111111222222222222222211111111111111144444444444444443333333333333333111111111111111111111111111111111111111111111111111111111111111222222222222222244444444444444444444444444444444444444444444444111111111111111133333333333333344444444444444443333333333333333111111111111111111111111111111122222222222222224444444444444444111111111111111144444444444444422222222222222223333333333333333222222222222222244444444444444411111111111111114444444444444444333333333333333322222222222222211111111111111114444444444444444333333333333333311111111111111122222222222222221111111111111111444444444444444433333333333333311111111111111112222222222222222111111111111111133333333333333344444444444444442222222222222222333333333333333322222222222222211111111111111114444444444444444222222222222222222222222222222233333333333333331111111111111111222222222222222244444444444444444444444444444441111111111111111444444444444444422222222222222222222222222222223333333333333333222222222222222244444444444444411111111111111113333333333333333444444444444444422222222222222223333333333333332222222222222222444444444444444444444444444444444444444444444444444444444444444111111111111111144444444444444442222222222222222222222222222222333333333333333311111111111111111111111111111112222222222222222444444444444444411111111111111114444444444444443333333333333333222222222222222211111111111111113333333333333334444444444444444222222222222222233333333333333332222222222222224444444444444444111111111111111133333333333333333333333333333334444444444444444333333333333333322222222222222224444444444444441111111111111111444444444444444422222222222222222222222222222222222222222222222333333333333333322222222222222221111111111111113333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333334444444444444444333333333333333322222222222222221111111111111114444444444444444222222222222222222222222222222222222222222222223333333333333333222222222222222244444444444444444444444444444444444444444444444444444444444444444444444444444441111111111111111333333333333333333333333333333344444444444444443333ÿ


But without NOP in the for-slopes, it looks like this:

>load
**
>g 829
44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444þ

TIA!

notting
0 Kudos