Skip to content

Commit 4c77933

Browse files
authored
Added Safe interrupt demo (FreeRTOS#685)
Add project to be used for safer interrupts
1 parent 0390b0f commit 4c77933

File tree

77 files changed

+67427
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+67427
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* FreeRTOS V202107.00
3+
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
* this software and associated documentation files (the "Software"), to deal in
7+
* the Software without restriction, including without limitation the rights to
8+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
* the Software, and to permit persons to whom the Software is furnished to do so,
10+
* subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*
22+
* http://www.FreeRTOS.org
23+
* http://aws.amazon.com/freertos
24+
*
25+
* 1 tab == 4 spaces!
26+
*/
27+
28+
/* FreeRTOS includes. */
29+
#include "FreeRTOS.h"
30+
#include"queue.h"
31+
32+
/* Interface includes. */
33+
#include "interrupt_handler_task.h"
34+
35+
/**
36+
* @brief Time to block while waiting for a interrupt request on the interrupt queue.
37+
*/
38+
#define USER_IRQ_RECEIVE_TIMEOUT ( pdMS_TO_TICKS( 1000 ) )
39+
40+
void vInterruptHandlerTask( void * pvParams )
41+
{
42+
BaseType_t xStatus;
43+
UserIrqRequest_t xIrqRequest;
44+
QueueHandle_t xInterruptQueueHandle = ( QueueHandle_t ) pvParams;
45+
46+
for( ;; )
47+
{
48+
xStatus = xQueueReceive( xInterruptQueueHandle,
49+
&( xIrqRequest ),
50+
USER_IRQ_RECEIVE_TIMEOUT );
51+
if ( xStatus != pdTRUE )
52+
{
53+
continue;
54+
}
55+
56+
/* If a valid IRQ request is received, invoke the corresponding handler
57+
* function. */
58+
xIrqRequest.xHandlerFunction( xIrqRequest.ulData );
59+
}
60+
}
61+
/*-----------------------------------------------------------*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* FreeRTOS V202107.00
3+
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
* this software and associated documentation files (the "Software"), to deal in
7+
* the Software without restriction, including without limitation the rights to
8+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
* the Software, and to permit persons to whom the Software is furnished to do so,
10+
* subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*
22+
* http://www.FreeRTOS.org
23+
* http://aws.amazon.com/freertos
24+
*
25+
* 1 tab == 4 spaces!
26+
*/
27+
28+
#ifndef INTERRUPT_HANDLER_TASK_H_
29+
#define INTERRUPT_HANDLER_H_
30+
31+
/* Standard includes. */
32+
#include <stdint.h>
33+
34+
/* The interrupt handler task serves user IRQ requests sent to the interrupt
35+
* queue. A user IRQ request comprises of the following 2 things:
36+
*
37+
* 1. Data.
38+
* 2. IRQ handler function.
39+
*/
40+
41+
/**
42+
* @brief Type of the handler function for every user IRQ request.
43+
*/
44+
typedef void ( * UserIrqHandlerFunction_t )( uint32_t ulData );
45+
46+
/**
47+
* @brief Represents user IRQ requests sent to the interrupt queue.
48+
*/
49+
typedef struct UserIrqRequest
50+
{
51+
uint32_t ulData;
52+
UserIrqHandlerFunction_t xHandlerFunction;
53+
} UserIrqRequest_t;
54+
55+
/**
56+
* @brief Function that implements the interrupt handler task.
57+
*
58+
* A FreeRTOS queue, known as interrupt queue, which holds UserIrqRequest_t items,
59+
* is passed as the parameter to this task. The interrupt handler task reads the
60+
* user IRQ requests from the interrupt queue and invokes the corresponding
61+
* handlers.
62+
*/
63+
void vInterruptHandlerTask( void * pvParams );
64+
65+
#endif /* INTERRUPT_HANDLER_H_ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* FreeRTOS V202107.00
3+
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
* this software and associated documentation files (the "Software"), to deal in
7+
* the Software without restriction, including without limitation the rights to
8+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
* the Software, and to permit persons to whom the Software is furnished to do so,
10+
* subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*
22+
* http://www.FreeRTOS.org
23+
* http://aws.amazon.com/freertos
24+
*
25+
* 1 tab == 4 spaces!
26+
*/
27+
28+
/* FreeRTOS includes. */
29+
#include "FreeRTOS.h"
30+
#include "task.h"
31+
32+
/* BSP includes. */
33+
#include "board.h"
34+
35+
/* Demo interface include. */
36+
#include "led_demo.h"
37+
38+
/**
39+
* Represents which LEDs are on or off. pdTRUE is on.
40+
*/
41+
typedef struct LedState
42+
{
43+
BaseType_t xRed;
44+
BaseType_t xGreen;
45+
BaseType_t xBlue;
46+
} LedState_t;
47+
48+
/* The following needs to be placed in the shared memory as it is accessed in
49+
* the button pressed IRQ handler which is unprivileged. */
50+
static LedState_t xLedState __attribute__( ( section( "user_irq_shared_memory" ) ) );
51+
/*-----------------------------------------------------------*/
52+
53+
/**
54+
* @brief Turn on RGB Led according to the xLedState.
55+
*/
56+
static void prvTurnOnRgbLed( void );
57+
58+
/**
59+
* @brief Turn off RGB Led.
60+
*/
61+
static void prvTurnOffRgbLed( void );
62+
/*-----------------------------------------------------------*/
63+
64+
static void prvTurnOnRgbLed( void )
65+
{
66+
/* Setting the GPIO pin activates the color in RGB LED. */
67+
if( xLedState.xRed == pdTRUE )
68+
{
69+
GPIO_PortClear( GPIO, BOARD_LED_RED_GPIO_PORT, 1u << BOARD_LED_RED_GPIO_PIN );
70+
}
71+
if( xLedState.xGreen == pdTRUE )
72+
{
73+
GPIO_PortClear( GPIO, BOARD_LED_GREEN_GPIO_PORT, 1u << BOARD_LED_GREEN_GPIO_PIN );
74+
}
75+
if( xLedState.xBlue == pdTRUE )
76+
{
77+
GPIO_PortClear( GPIO, BOARD_LED_BLUE_GPIO_PORT, 1u << BOARD_LED_BLUE_GPIO_PIN );
78+
}
79+
}
80+
/*-----------------------------------------------------------*/
81+
82+
static void prvTurnOffRgbLed( void )
83+
{
84+
/* Setting the pins high turns off the LED. */
85+
GPIO_PortSet( GPIO, BOARD_LED_RED_GPIO_PORT, 1u << BOARD_LED_RED_GPIO_PIN );
86+
GPIO_PortSet( GPIO, BOARD_LED_GREEN_GPIO_PORT, 1u << BOARD_LED_GREEN_GPIO_PIN );
87+
GPIO_PortSet( GPIO, BOARD_LED_BLUE_GPIO_PORT, 1u << BOARD_LED_BLUE_GPIO_PIN );
88+
}
89+
/*-----------------------------------------------------------*/
90+
91+
void vLedDemoTask( void * pvParams )
92+
{
93+
/* Set the initial LED state. */
94+
xLedState.xRed = pdTRUE;
95+
xLedState.xGreen = pdTRUE;
96+
xLedState.xBlue = pdFALSE;
97+
98+
/* Silence compiler warnings about unused variables. */
99+
( void ) pvParams;
100+
101+
for( ;; )
102+
{
103+
prvTurnOnRgbLed();
104+
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
105+
106+
prvTurnOffRgbLed();
107+
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
108+
}
109+
}
110+
/*-----------------------------------------------------------*/
111+
112+
void vButtonPressedIRQHandler( uint32_t ulData )
113+
{
114+
BaseType_t xPreviousRed;
115+
116+
/* Data is not used. */
117+
( void ) ulData;
118+
119+
/* Shift to the next color. */
120+
xPreviousRed = xLedState.xRed;
121+
xLedState.xRed = xLedState.xGreen;
122+
xLedState.xGreen = xLedState.xBlue;
123+
xLedState.xBlue = xPreviousRed;
124+
}
125+
/*-----------------------------------------------------------*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* FreeRTOS V202107.00
3+
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
* this software and associated documentation files (the "Software"), to deal in
7+
* the Software without restriction, including without limitation the rights to
8+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
* the Software, and to permit persons to whom the Software is furnished to do so,
10+
* subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*
22+
* http://www.FreeRTOS.org
23+
* http://aws.amazon.com/freertos
24+
*
25+
* 1 tab == 4 spaces!
26+
*/
27+
28+
#ifndef LED_DEMO_H_
29+
#define LED_DEMO_H_
30+
31+
/* Standard includes. */
32+
#include <stdint.h>
33+
34+
/**
35+
* @brief The function that implements the LED demo task.
36+
*
37+
* It periodically toggles the on board RGB led. The color of the LED changes
38+
* whenever the user presses the USER button on the NXP LPC55S69-EVK board.
39+
*/
40+
void vLedDemoTask( void * pvParams );
41+
42+
/**
43+
* @brief Handler for the button pressed IRQ.
44+
*
45+
* It changes the color of the LED.
46+
*
47+
* @param [in] ulData Not used.
48+
*/
49+
void vButtonPressedIRQHandler( uint32_t ulData );
50+
51+
#endif /* LED_DEMO_H_ */

0 commit comments

Comments
 (0)