#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "utility.h"
#include "at32f403a_407_int.h"
#include <stdio.h>


#if 1
// OS stack overflow hook
#if (configCHECK_FOR_STACK_OVERFLOW > 0)
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
{
    NVIC_SystemReset();
}
#endif
#endif

// OS malloc failed hook
#if (configUSE_MALLOC_FAILED_HOOK > 0)
void vApplicationMallocFailedHook(void)
{
    NVIC_SystemReset();
    while(1);
}
#endif


//
void print_binary_byte(uint8_t val)
{
    for (int i = 7; i >= 0; i--) {
        if (val & (1 << i))
            printf("1");
        else
            printf("0");
        if (i == 4)
            printf(" ");
    }
    printf("\r\n");
}

//
void print_binary_half_word(uint16_t val)
{
    for (int i = 15; i >= 0; i--) {
        if (val & (1 << i))
            printf("1");
        else
            printf("0");
        if ((i == 12) || (i == 8) || (i == 4))
            printf(" ");
    }
    printf("\r\n");
}