# Lattice Mico32

**URL:** <https://forums.freertos.org/t/lattice-mico32/4404>\
**Category:** Kernel\
**Created:** [May 19, 2010, 5:10pm UTC](https://forums.freertos.org/t/lattice-mico32/4404 "2010-05-19T17:10:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 19, 2010, 5:10pm UTC](https://forums.freertos.org/t/lattice-mico32/4404/1 "2010-05-19T17:10:35Z")

</div>

**[jonenst](https://sourceforge.net/u/jonenst/)** wrote on [Wednesday, May 19, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/c120031f/#b0c8):

Hi,  
I would like to use the community port of FreeRTOS on a Lattice Mico32. I downloaded the files available at [http://www.freertos.org/index.html?http://interactive.freertos.org/forums/104358-lattice](http://www.freertos.org/index.html?http://interactive.freertos.org/forums/104358-lattice). I tried to buid this with the version of FreeRTOS 4.7.0 (what it was created for).

There are some missing include files :  
#include “system\_conf.h”

#include “Timer.h”

#include “GPIO.h”

I suppose this is some lattice specific headers files, but can’t find them anywhere. Does anyone have any pointers here ?

Thanks in advance

Jon

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 19, 2010, 6:22pm UTC](https://forums.freertos.org/t/lattice-mico32/4404/2 "2010-05-19T18:22:03Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Wednesday, May 19, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/c120031f/#2a85):

Yes I think you must be right, there are not FreeRTOS files. Could it be that the version of the Lattice tools has changed since the port was posted?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 21, 2010, 5:10pm UTC](https://forums.freertos.org/t/lattice-mico32/4404/3 "2010-05-21T17:10:43Z")

</div>

**[jonenst](https://sourceforge.net/u/jonenst/)** wrote on [Friday, May 21, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/c120031f/#4248):

So I got it to compile using the following Timer.h (writtten after reading the lattice mico32 timer spec)  
#ifndef TIMER\_H  
#define TIMER\_H  
#include \<stdint.h\>

#define TIMER\_CONTROL\_INT\_BIT\_MASK&nbsp;&nbsp; 1 \<\< 0  
#define TIMER\_CONTROL\_CONT\_BIT\_MASK&nbsp; 1 \<\< 1  
#define TIMER\_CONTROL\_START\_BIT\_MASK 1 \<\< 2  
#define TIMER\_CONTROL\_STOP\_BIT\_MASK&nbsp; 1 \<\< 3

#define TIMER\_BASE\_ADDRESS 0xA0000600 // This is the timer address for my configuration, it should be changed

typedef struct {  
&nbsp; volatile uint32\_t Status;  
&nbsp; volatile uint32\_t Control;  
&nbsp; volatile uint32\_t Period;  
&nbsp; volatile uint32\_t Snapshot;  
} Timer\_t ;

#endif

However, context switching does not occur. I can see that the timer interrupt handler is called, I can see that the systick is incrementing, but it doesn’t change context. Could someone explain what normally happens when the ISR handlers executes the following functions ?  
&nbsp; vTaskIncrementTick();  
&nbsp;&nbsp; vTaskSwitchContext();

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 21, 2010, 5:46pm UTC](https://forums.freertos.org/t/lattice-mico32/4404/4 "2010-05-21T17:46:26Z")

</div>

**[jonenst](https://sourceforge.net/u/jonenst/)** wrote on [Friday, May 21, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/c120031f/#09d1):

This is what when I dump the values that are logged by the trace utility :  
…  
TickCount :14 previous :1  
TickCount :15 previous :0  
TickCount :16 previous :1  
TickCount :17 previous :0  
TickCount :18 previous :1  
…

It looks like both my tasks are beeing scheduled  
However, I am sure that when I launch two tasks, only the code from the last created task is executed. The code from the other task is not executed.  
Does anyone have any pointers …?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 26, 2010, 8:09am UTC](https://forums.freertos.org/t/lattice-mico32/4404/5 "2010-05-26T08:09:46Z")

</div>

**[jonenst](https://sourceforge.net/u/jonenst/)** wrote on [Wednesday, May 26, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/c120031f/#b634):

Ok, I had not seen the low level interrupt routine vPortInterruptHandler that saves and restores contexts… I was calling the high level IRQ directly. Now that I changed that, it works like a charm !

I had to add one line to port.c though, but maybe that’s because i’m running a simulated timer, not the real timer from lattice.

Here’s the line :  
+&nbsp;&nbsp;&nbsp; pTimer-\>Period = configCPU\_CLOCK\_HZ / configTICK\_RATE\_HZ ;  
&nbsp;&nbsp;&nbsp;&nbsp; pTimer-\>Control = TIMER\_CONTROL\_START\_BIT\_MASK | TIMER\_CONTROL\_INT\_BIT\_MASK | TIMER\_CONTROL\_CONT\_BIT\_MASK;
