Skip to content

Commit b2c2c62

Browse files
committed
intros: added stm32g0 port
1 parent 116b58a commit b2c2c62

File tree

4 files changed

+282
-0
lines changed

4 files changed

+282
-0
lines changed

intros/port/cortexm/device/stm32f0/osport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "osconfig.h"
3838
#endif
3939
#include "osdefs.h"
40+
#include "osmpu.h"
4041

4142
#ifdef __cplusplus
4243
extern "C" {
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/******************************************************************************
2+
3+
@file IntrOS: osport.c
4+
@author Rajmund Szymanski
5+
@date 14.10.2022
6+
@brief IntrOS port file for STM32G0 uC.
7+
8+
******************************************************************************
9+
10+
Copyright (c) 2018-2022 Rajmund Szymanski. All rights reserved.
11+
12+
Permission is hereby granted, free of charge, to any person obtaining a copy
13+
of this software and associated documentation files (the "Software"), to
14+
deal in the Software without restriction, including without limitation the
15+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16+
sell copies of the Software, and to permit persons to whom the Software is
17+
furnished to do so, subject to the following conditions:
18+
19+
The above copyright notice and this permission notice shall be included
20+
in all copies or substantial portions of the Software.
21+
22+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28+
IN THE SOFTWARE.
29+
30+
******************************************************************************/
31+
32+
#include "oskernel.h"
33+
34+
/* -------------------------------------------------------------------------- */
35+
36+
void port_sys_init( void )
37+
{
38+
#if HW_TIMER_SIZE == 0
39+
40+
/******************************************************************************
41+
Non-tick-less mode: configuration of system timer
42+
It must generate interrupts with frequency OS_FREQUENCY
43+
*******************************************************************************/
44+
45+
#if (CPU_FREQUENCY)/(OS_FREQUENCY)-1 <= SysTick_LOAD_RELOAD_Msk
46+
47+
SysTick_Config((CPU_FREQUENCY)/(OS_FREQUENCY));
48+
49+
#elif defined(ST_FREQUENCY) && \
50+
(ST_FREQUENCY)/(OS_FREQUENCY)-1 <= SysTick_LOAD_RELOAD_Msk
51+
52+
NVIC_SetPriority(SysTick_IRQn, 0xFF);
53+
54+
SysTick->LOAD = (ST_FREQUENCY)/(OS_FREQUENCY)-1;
55+
SysTick->VAL = 0U;
56+
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk|SysTick_CTRL_TICKINT_Msk;
57+
58+
#else
59+
#error Incorrect SysTick frequency!
60+
#endif
61+
62+
/******************************************************************************
63+
End of configuration
64+
*******************************************************************************/
65+
66+
#else //HW_TIMER_SIZE
67+
68+
/******************************************************************************
69+
Tick-less mode: configuration of system timer
70+
It must be rescaled to frequency OS_FREQUENCY
71+
*******************************************************************************/
72+
73+
#if (CPU_FREQUENCY)/(OS_FREQUENCY)-1 > UINT16_MAX
74+
#error Incorrect Timer frequency!
75+
#endif
76+
77+
RCC->APBENR1 |= RCC_APBENR1_TIM7EN;
78+
#if HW_TIMER_SIZE < OS_TIMER_SIZE
79+
NVIC_SetPriority(TIM7_IRQn, 0xFF);
80+
NVIC_EnableIRQ(TIM7_IRQn);
81+
#else
82+
__ISB();
83+
#endif
84+
#if HW_TIMER_SIZE > OS_TIMER_SIZE
85+
TIM7->ARR = CNT_MAX;
86+
#endif
87+
TIM7->PSC = (CPU_FREQUENCY)/(OS_FREQUENCY)-1;
88+
TIM7->EGR = TIM_EGR_UG;
89+
TIM7->CR1 = TIM_CR1_CEN;
90+
#if HW_TIMER_SIZE < OS_TIMER_SIZE
91+
TIM7->DIER = TIM_DIER_UIE;
92+
#endif
93+
94+
/******************************************************************************
95+
End of configuration
96+
*******************************************************************************/
97+
98+
#endif//HW_TIMER_SIZE
99+
}
100+
101+
/* -------------------------------------------------------------------------- */
102+
103+
#if HW_TIMER_SIZE == 0
104+
105+
/******************************************************************************
106+
Non-tick-less mode: interrupt handler of system timer
107+
*******************************************************************************/
108+
109+
void SysTick_Handler( void )
110+
{
111+
SysTick->CTRL;
112+
core_sys_tick();
113+
}
114+
115+
/******************************************************************************
116+
End of the handler
117+
*******************************************************************************/
118+
119+
#else //HW_TIMER_SIZE
120+
121+
/******************************************************************************
122+
Tick-less mode: interrupt handler of system timer
123+
*******************************************************************************/
124+
125+
#if HW_TIMER_SIZE < OS_TIMER_SIZE
126+
127+
void TIM7_IRQHandler( void )
128+
{
129+
// if (TIM7->SR & TIM_SR_UIF)
130+
{
131+
TIM7->SR = ~TIM_SR_UIF;
132+
core_sys_tick();
133+
__ISB(); // delay because of GNUCC
134+
}
135+
}
136+
137+
#endif
138+
139+
/******************************************************************************
140+
End of the handler
141+
*******************************************************************************/
142+
143+
/******************************************************************************
144+
Tick-less mode: return current system time
145+
*******************************************************************************/
146+
147+
#if HW_TIMER_SIZE < OS_TIMER_SIZE
148+
149+
cnt_t port_sys_time( void )
150+
{
151+
cnt_t cnt;
152+
uint32_t tck;
153+
154+
cnt = System.cnt;
155+
tck = TIM7->CNT;
156+
157+
if (TIM7->SR & TIM_SR_UIF)
158+
{
159+
tck = TIM7->CNT;
160+
cnt += (cnt_t)(1) << (HW_TIMER_SIZE);
161+
}
162+
163+
return cnt + tck;
164+
}
165+
166+
#endif
167+
168+
/******************************************************************************
169+
End of the function
170+
*******************************************************************************/
171+
172+
#endif//HW_TIMER_SIZE
173+
174+
/* -------------------------------------------------------------------------- */
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/******************************************************************************
2+
3+
@file IntrOS: osport.h
4+
@author Rajmund Szymanski
5+
@date 14.10.2022
6+
@brief IntrOS port definitions for STM32G0 uC.
7+
8+
******************************************************************************
9+
10+
Copyright (c) 2018-2022 Rajmund Szymanski. All rights reserved.
11+
12+
Permission is hereby granted, free of charge, to any person obtaining a copy
13+
of this software and associated documentation files (the "Software"), to
14+
deal in the Software without restriction, including without limitation the
15+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16+
sell copies of the Software, and to permit persons to whom the Software is
17+
furnished to do so, subject to the following conditions:
18+
19+
The above copyright notice and this permission notice shall be included
20+
in all copies or substantial portions of the Software.
21+
22+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28+
IN THE SOFTWARE.
29+
30+
******************************************************************************/
31+
32+
#ifndef __INTROSPORT_H
33+
#define __INTROSPORT_H
34+
35+
#include "stm32g0xx.h"
36+
#ifndef NOCONFIG
37+
#include "osconfig.h"
38+
#endif
39+
#include "osdefs.h"
40+
#include "osmpu.h"
41+
42+
#ifdef __cplusplus
43+
extern "C" {
44+
#endif
45+
46+
/* -------------------------------------------------------------------------- */
47+
48+
#ifndef CPU_FREQUENCY
49+
#define CPU_FREQUENCY 64000000 /* Hz */
50+
#endif
51+
52+
/* -------------------------------------------------------------------------- */
53+
54+
#ifndef OS_FREQUENCY
55+
#define OS_FREQUENCY 1000 /* Hz */
56+
#endif
57+
58+
/* -------------------------------------------------------------------------- */
59+
// !! WARNING! OS_TIMER_SIZE < HW_TIMER_SIZE may cause unexpected problems !!
60+
61+
#ifndef OS_TIMER_SIZE
62+
#define OS_TIMER_SIZE 32 /* bit size of system timer counter */
63+
#endif
64+
65+
/* -------------------------------------------------------------------------- */
66+
// !! WARNING! OS_TIMER_SIZE < HW_TIMER_SIZE may cause unexpected problems !!
67+
68+
#ifdef HW_TIMER_SIZE
69+
#error HW_TIMER_SIZE is an internal os definition!
70+
#elif OS_FREQUENCY > 1000
71+
#define HW_TIMER_SIZE 16 /* bit size of hardware timer */
72+
#else
73+
#define HW_TIMER_SIZE 0 /* os does not work in tick-less mode */
74+
#endif
75+
76+
/* -------------------------------------------------------------------------- */
77+
// alternate clock source for SysTick
78+
79+
#ifdef ST_FREQUENCY
80+
#error ST_FREQUENCY is an internal port definition!
81+
#else
82+
#define ST_FREQUENCY ((CPU_FREQUENCY)/8)
83+
#endif
84+
85+
/* -------------------------------------------------------------------------- */
86+
// return current system time
87+
88+
#if HW_TIMER_SIZE >= OS_TIMER_SIZE
89+
90+
__STATIC_INLINE
91+
uint32_t port_sys_time( void )
92+
{
93+
return TIM7->CNT;
94+
}
95+
96+
#endif
97+
98+
/* -------------------------------------------------------------------------- */
99+
100+
#ifdef __cplusplus
101+
}
102+
#endif
103+
104+
/* -------------------------------------------------------------------------- */
105+
106+
#endif//__INTROSPORT_H

intros/port/cortexm/device/stm32l1/osport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "osconfig.h"
3838
#endif
3939
#include "osdefs.h"
40+
#include "osmpu.h"
4041

4142
#ifdef __cplusplus
4243
extern "C" {

0 commit comments

Comments
 (0)