Skip to content

Commit 6acf3a2

Browse files
committed
Added a small example to test PendSV operation,
The example is implemented using a variable stored on the stack and a couple of procedures. Everything is located in the files sch_context_change.h and sch_context_change.s
1 parent 4b57c92 commit 6acf3a2

5 files changed

Lines changed: 63 additions & 13 deletions

File tree

examples/stm32f4x/app/src/main.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ void sch_task_init(sch_task_t* task);
1919
void echo_task_dispatch(sch_task_t* task);
2020
void echo_task_init(sch_task_t* task);
2121

22+
/*--External objects-----------------------------------------------------------*/
23+
24+
extern volatile uint8_t sch_context_change_interrupt_check;
25+
2226
int main(void)
2327
{
2428
HAL_Init();
2529
SystemClock_Config();
2630
MX_GPIO_Init();
2731
MX_USART2_UART_Init();
2832

29-
sch_task_t first_task;
33+
/*sch_task_t first_task;
3034
sch_task_t second_task;
3135
sch_task_t echo_data;
3236
sch_task_t another_system_task;
@@ -37,16 +41,29 @@ int main(void)
3741
sch_task_create(&second_task, 3, 0, sch_task_dispatch, sch_task_init);
3842
sch_task_activate(&second_task);
3943
40-
sch_task_create(&another_system_task, 2, 0, sch_task_dispatch, sch_task_init);
41-
sch_task_activate(&second_task);
44+
sch_task_create(&another_system_task, 4, 0, sch_task_dispatch, sch_task_init);
45+
sch_task_activate(&another_system_task);
4246
4347
sch_task_create(&echo_data, -4, 3, echo_task_dispatch, echo_task_init);
4448
sch_task_activate(&echo_data);
45-
sch_task_run(&echo_data, NULL);
49+
sch_task_run(&echo_data, NULL);*/
50+
51+
/*char buf[40] = {0};
52+
snprintf(buf, sizeof(buf), "%d\r\n", sch_find_most_significant_task(sch_preempt_tasks_ready_set));
53+
HAL_UART_Transmit(&huart2, (uint8_t*)buf, strlen(buf), HAL_MAX_DELAY);*/
54+
55+
sch_context_change_interrupt_check = 1;
56+
sch_context_change();
57+
if (sch_context_change_interrupt_check == 0)
58+
{
59+
HAL_UART_Transmit(&huart2, (uint8_t*)"sch_context_change_interrupt_check = 0", \
60+
strlen("sch_context_change_interrupt_check = 0"), HAL_MAX_DELAY);
61+
} else
62+
{
63+
HAL_UART_Transmit(&huart2, (uint8_t*)"sch_context_change_interrupt_check != 0", \
64+
strlen("sch_context_change_interrupt_check != 0"), HAL_MAX_DELAY);
65+
}
4666

47-
char buf[40] = {0};
48-
snprintf(buf, sizeof(buf), "%d\r\n", sch_find_most_significant_task(sch_system_tasks_ready_set));
49-
HAL_UART_Transmit(&huart2, (uint8_t*)buf, strlen(buf), HAL_MAX_DELAY);
5067

5168
while (1)
5269
{

examples/stm32f4x/platform/startup/startup_stm32f401xe.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ g_pfnVectors:
138138
.word SVC_Handler
139139
.word DebugMon_Handler
140140
.word 0
141-
.word PendSV_Handler
141+
.word sch_context_change_interrupt_handler
142142
.word SysTick_Handler
143143

144144
/* External Interrupts */

sch/inc/sch_context_change.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ extern "C" {
77

88
#include "sch_common.h"
99

10+
/*--Fucntions for debugging the work of interrupt of changing the context----*/
11+
12+
/**
13+
* @brief Function for handling the interrupt of command of
14+
* changing the context
15+
*
16+
* @return void
17+
*/
18+
__WEAK void sch_context_change_interrupt_handler(void);
19+
20+
/*--Objects for defug--------------------------------------------------------*/
21+
22+
extern volatile uint8_t sch_context_change_interrupt_check;
23+
24+
/*---------------------------------------------------------------------------*/
25+
1026
/**
1127
* @brief Function for finding the most significant task flag
1228
* in the "registry" what'd been imaged in variable
@@ -22,7 +38,7 @@ uint8_t sch_find_most_significant_task(uint32_t sch_system_tasks_ready_set);
2238
void sch_context_change(void);
2339

2440
/**
25-
* @brief Function for planning goddammit
41+
* @brief Function for calling the dispatch function
2642
*
2743
*/
2844
void sch_call_dispatch(uint8_t sch_most_significant_task);

sch/port/stm32f4xx/sch_context_change.s

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@
66
.equ __sch_icsr, (__sch_scs_base + __sch_icsr_offset)
77
.equ __sch_icsr_pendvset, (1 << 28)
88

9-
.section .text.sch_context_change
9+
@ -----------------------------------------------------------------------------
1010

11-
.type sch_context_change, %function
12-
.type sch_call_dispatch, %function
11+
.section .data
12+
.global sch_context_change_interrupt_check
13+
.align 2
14+
sch_context_change_interrupt_check:
15+
.byte 1
16+
.align 2
1317

18+
@ -----------------------------------------------------------------------------
1419

20+
.section .text.sch_context_change
21+
22+
.type sch_call_dispatch, %function
1523
.global sch_call_dispatch
1624
sch_call_dispatch:
1725
ldr r1, =sch_task_registry
@@ -22,10 +30,18 @@ sch_call_dispatch:
2230
blx r3
2331
bx lr
2432

25-
33+
.type sch_context_change, %function
2634
.global sch_context_change
2735
sch_context_change:
2836
ldr r0, =__sch_icsr
2937
ldr r1, =__sch_icsr_pendvset
3038
str r1, [r0]
3139
bx lr
40+
41+
.type sch_context_change_interrupt_handler, %function
42+
.global sch_context_change_interrupt_handler
43+
sch_context_change_interrupt_handler:
44+
ldr r0, =sch_context_change_interrupt_check
45+
mov r1, #0
46+
str r1, [r0]
47+
bx lr

sch/port/stm32f4xx/sch_find_most_significant_task.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ sch_find_most_significant_task:
88
cbz r0, .is_data_zero
99
clz r0, r0
1010
rsb r0, r0, #31
11+
add r0, #1
1112
bx lr
1213

1314
.is_data_zero:

0 commit comments

Comments
 (0)