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
/**
 *******************************************************************************
 * @file     utility.c
 * @create   2024-11-01    
 * @author   Panchip BLE GROUP
 * @note
 * Copyright (c) 2022 Shanghai Panchip Microelectronics Co.,Ltd.
 *
 *******************************************************************************
 */
#include "utility.h"
#include "FreeRTOS.h"
#include "task.h"
#include "cmsis_compiler.h"
#include "app_log.h"
 
/******************************************************************************* 
 * OS Hook
 ******************************************************************************/
#if configCHECK_FOR_STACK_OVERFLOW
void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
{
    APP_LOG_ERR("task overflow:%s\r\n", pcTaskName);
    app_assert(0);
}
#endif
 
#if configUSE_MALLOC_FAILED_HOOK
void vApplicationMallocFailedHook(void)
{
    APP_LOG_ERR("OS Heap Size no enough\r\n");
    app_assert(0);
}
#endif
 
/**
 * @brief : Verify that the current program is in interrupt.
 */
bool IN_ISR(void)
{
    return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
}
 
 
/******************************************************************************* 
 * keil system call
 ******************************************************************************/
__attribute__((weak,noreturn))
void __aeabi_assert (const char *expr, const char *file, int line) {
  char str[12], *p;
 
  fputs("*** assertion failed: ", stderr);
  fputs(expr, stderr);
  fputs(", file ", stderr);
  fputs(file, stderr);
  fputs(", line ", stderr);
 
  p = str + sizeof(str);
  *--p = '\0';
  *--p = '\n';
  while (line > 0) {
    *--p = '0' + (line % 10);
    line /= 10;
  }
  fputs(p, stderr);
 
  abort();
}
 
__attribute__((weak))
void abort(void) {
  for (;;);
}