-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtos_hooks.c
160 lines (126 loc) · 4.32 KB
/
rtos_hooks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/******************************************************************************
* Copyright (c) 2019 - Hemant Sharma - All Rights Reserved
*
* Feel free to use this Code at your own risk for your own purposes.
*
*******************************************************************************/
/******************************************************************************
* Title: RTOS Hooks Source
* Filename: rtos_hooks.c
* Author: HS
* Origin Date:
* Version:
* Notes:
*
* Change History
* --------------
*
*******************************************************************************/
/** @file: rtos_hooks.c
* @brief: This source file contains callback functions of RTOS
*/
/******************************************************************************
* Includes
*******************************************************************************/
/* Include FreeRTOS Headers */
#include <FreeRTOS.h>
#include <task.h>
/******************************************************************************
* Functions
*******************************************************************************/
/*-----------------------------------------------------------*/
#if( configCHECK_FOR_STACK_OVERFLOW > 0 )
void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName );
void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
(void) xTask;
(void) pcTaskName;
/* Check for Stack Overflow cause */
/* For Debugging only */
#if (DEBUG_ == 1U)
for( ; ; )
{
/* Halt here */
__asm("NOP");
}
#endif
}
#endif
/*-----------------------------------------------------------*/
#if( configUSE_TICK_HOOK > 0 )
void vApplicationTickHook( void );
void vApplicationTickHook( void )
{
/* Dummy Implementation */
return;
}
#endif
/*-----------------------------------------------------------*/
#if ( configUSE_IDLE_HOOK == 1 )
void vApplicationIdleHook( void );
void vApplicationIdleHook( void )
{
/* It must *NOT* attempt to block. In this case the
* idle task just sleeps or yields to lower the CPU usage. */
portYIELD();
}
#endif
/*-----------------------------------------------------------*/
#if( configUSE_MALLOC_FAILED_HOOK == 1 )
void vApplicationMallocFailedHook( void );
void vApplicationMallocFailedHook( void )
{
/* Called if a call to pvPortMalloc() fails because there is insufficient
free memory available in the FreeRTOS heap. pvPortMalloc() is called
internally by FreeRTOS API functions that create tasks, queues, software
timers, and semaphores. The size of the FreeRTOS heap is set by the
configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
/* Report malloc failed hook */
for( ; ; )
{
__asm("NOP");
}
}
#endif /* #if( configUSE_MALLOC_FAILED_HOOK == 1 ) */
/*-----------------------------------------------------------*/
/* Use by the pseudo random number generator. */
static UBaseType_t ulNextRand;
UBaseType_t uxRand( void );
UBaseType_t uxRand( void )
{
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
/* Utility function to generate a pseudo random number. */
ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
return( ( int ) ( ulNextRand >> 16UL ) & 0x7fffUL );
}
/*-----------------------------------------------------------*/
void vLoggingPrintf( const char *pcFormat, ... );
void vLoggingPrintf( const char *pcFormat, ... )
{
/* Dummy implementation */
(void) pcFormat;
}
/*
* Callback that provides the inputs necessary to generate a randomized TCP
* Initial Sequence Number per RFC 6528. In this case just a psuedo random
* number is used so THIS IS NOT RECOMMENDED FOR PRODUCTION SYSTEMS.
*/
uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
uint16_t usSourcePort, uint32_t ulDestinationAddress, uint16_t usDestinationPort );
uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress, uint16_t usSourcePort,
uint32_t ulDestinationAddress, uint16_t usDestinationPort
)
{
( void ) ulSourceAddress;
( void ) usSourcePort;
( void ) ulDestinationAddress;
( void ) usDestinationPort;
return uxRand();
}
BaseType_t xApplicationGetRandomNumber( uint32_t *pulNumber );
BaseType_t xApplicationGetRandomNumber( uint32_t *pulNumber )
{
*pulNumber = uxRand();
return pdTRUE;
}
/********************************** End of File *******************************/