Hi Nhan Tran,
I have checked your link's code, about the piece code of systick and the sleep function, I think you can change the method to write it.
As you know, LPC1549 sleep can be waked up by the interrupt.

So, even you use the code like this:
extern "C"{
void SysTick_Handler(void)
{
static int ticks = 0;
if(counter > 0) counter--;
ticks++;
if (ticks > TICKRATE_HZ) {
ticks = 0;
state = 1 - state;
}
}
}
void Sleep(int ms)
{
counter = ms;
while(counter > 0) {
__WFI();
}
}
You want to define the sleep time, but it will be waked up by the systick, then you use while enter the sleep again.
Please double think, is it good enough? You chip will enter the sleep, wake up, sleep, wakeup ...
Actually, I think you don't need to write it like that, let me tell you my thought.
As you know, systick is a Simple 24-bit timer. The timer clock source is the system clock, in LPC1549, the max system clock should be 72Mhz, let's take 72Mhz as an example.
From you code, I find the biggest sleep time you calling is 5000ms, it also in the while(1), actually, you want it always in the sleep.
In other area, you are call 10ms, 70ms.
Let's calculate the systick time, 24bit = 16777216, if you just use 72Mhz, clock no divide, then the max time should be 167726*(1/72)us=233016us, it is 233.016ms, actually, it is enough for your usage.
Each time when you want to change the sleep time, you just need to initialize the systick again, just redefine the systick time, then when the time is reached, enter the SysTick_Handler function, disable the systick, the sleep mode will waked up automatically.
If you want the systick timer longer than 233ms, you still can divide the systick clock,

Then your code will totally separate your relationship between the systick code and the sleep code.
When you want to modify the sleep time, you just need to call:
SysTick_Config(DefinedTime);
Sleep();//__WFI;
About the SysTick_Handler, you just need to clear the interrupt, and disable the systick.
Wish it helps you!
If you still have question about it, please kindly let me know!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------