Hallo liebe µC Freunde,
ich habe mich heute mal rangemacht um meinen Code vom Atmega2560
(geschrieben im AVR Studio) in Crossworks AVR 2.0 zu portieren.
Allerdings bin ich hier schon sehr früh gescheitert.
Ich wollte den Timer0 für die CTL als Timer einbinden, doch leider
funktioniert der Timer0 im Simulator garnicht.
Diese Zeilen Code funktionieren im AVRStudio mit 1ms Ticks:
1 | TCNT0 = 0;
|
2 | OCR0A = 249;
|
3 | TIMSK0 = 0x02;
|
4 | TCCR0A = 0x02;
|
5 | TCCR0B= 0x01;
|
6 | SREG |= 0x01;
|
Wenn ich die Zeilen allerdings in den Standard CTL (Code nach dem
Erstellen des CTL Projektes) einfüge, werden die Werte richtig in die
Register geschrieben, aber TCNT0 bewegt sich kein Stück.
Hier der gesamte CTL Code:
1 | #include <string.h>
|
2 | #include <ctl_api.h>
|
3 | #include <ATmega2560.h>
|
4 |
|
5 | CTL_TASK_t main_task, new_task;
|
6 |
|
7 | #define CALLSTACKSIZE 16 // this is only required for AVR builds
|
8 | #define STACKSIZE 64
|
9 | unsigned new_task_stack[1+STACKSIZE+1];
|
10 |
|
11 | void
|
12 | new_task_code(void *p)
|
13 | {
|
14 | unsigned int v=0;
|
15 |
|
16 |
|
17 |
|
18 | while (1)
|
19 | {
|
20 | // task logic goes here
|
21 | v++;
|
22 | }
|
23 | }
|
24 |
|
25 | void
|
26 | ctl_handle_error(CTL_ERROR_CODE_t e)
|
27 | {
|
28 | while (1);
|
29 | }
|
30 |
|
31 | int main(void)
|
32 | {
|
33 | unsigned int v=0;
|
34 |
|
35 | TCNT0 = 0;
|
36 | OCR0A = 249;
|
37 | TIMSK0 = 0x02;
|
38 | TCCR0A = 0x02;
|
39 | TCCR0B= 0x01;
|
40 | SREG |= 0x01;
|
41 |
|
42 | ctl_task_init(&main_task, 255, "main"); // create subsequent tasks whilst running at the highest priority.
|
43 | ctl_start_timer(ctl_increment_tick_from_isr); // start the timer
|
44 | memset(new_task_stack, 0xcd, sizeof(new_task_stack)); // write known values into the stack
|
45 | new_task_stack[0]=new_task_stack[1+STACKSIZE]=0xfacefeed; // put marker values at the words before/after the stack
|
46 | ctl_task_run(&new_task, 1, new_task_code, 0, "new_task", STACKSIZE, new_task_stack+1, CALLSTACKSIZE);
|
47 | //ctl_task_set_priority(&main_task, 0); // drop to lowest priority to start created tasks running.
|
48 |
|
49 | while (1)
|
50 | {
|
51 | // power down can go here if supported
|
52 | v++;
|
53 | }
|
54 | return 0;
|
55 | }
|
Würde mich sehr über einige Hilfestellungen freuen.
Gruß Tom