macros.h (3258B)
1 // PingPongOS - PingPong Operating System 2 // © Prof. Carlos A. Maziero, DINF UFPR 3 // Versão 2.1 -- 06/2026 4 5 // ATENÇÃO: ESTE ARQUIVO NÃO DEVE SER ALTERADO; 6 // ALTERAÇÕES SERÃO DESCARTADAS NA CORREÇÃO. 7 8 #ifndef __MACROS__ 9 #define __MACROS__ 10 11 // este código deve ser compilado em sistemas UNIX-like 12 #ifndef __linux__ 13 #error "Este codigo foi planejado para ambientes Linux." 14 #endif 15 16 #include "hardware/cpu.h" 17 #include "lib/pplibc.h" 18 19 // códigos de cor ANSI (terminal) 20 #define FONT_NORMAL "\x1B[0m" 21 #define FONT_BLACK "\x1B[30m" 22 #define FONT_RED "\x1B[31m" 23 #define FONT_GREEN "\x1B[32m" 24 #define FONT_YELLOW "\x1B[33m" 25 #define FONT_BLUE "\x1B[34m" 26 #define FONT_MAGENTA "\x1B[35m" 27 #define FONT_CYAN "\x1B[36m" 28 #define FONT_WHITE "\x1B[37m" 29 #define BACK_BLACK "\x1B[40m" 30 #define BACK_RED "\x1B[41m" 31 #define BACK_GREEN "\x1B[42m" 32 #define BACK_YELLOW "\x1B[43m" 33 #define BACK_BLUE "\x1B[44m" 34 #define BACK_MAGENTA "\x1B[45m" 35 #define BACK_CYAN "\x1B[46m" 36 #define BACK_WHITE "\x1B[47m" 37 38 // Imprime mensagem de depuração se DEBUG estiver definido; 39 // Uso igual ao printk: ppos_debug(format, arg1, arg2, ...) 40 #ifdef DEBUG 41 #define ppos_debug(...) \ 42 do \ 43 { \ 44 printk(FONT_CYAN "DEBUG: "); \ 45 printk(__VA_ARGS__); \ 46 printk(FONT_NORMAL); \ 47 } while (0) 48 #else 49 #define ppos_debug(...) // não faz nada 50 #endif 51 52 // Imprime mensagem de aviso, com arquivo e linha do código. 53 // Uso igual ao printk: ppos_warn(format, arg1, arg2, ...) 54 #define ppos_warn(...) \ 55 do \ 56 { \ 57 printk(BACK_YELLOW "WARN (%s:%d)" FONT_NORMAL ": ", \ 58 __FILE__, __LINE__); \ 59 printk(__VA_ARGS__); \ 60 } while (0) 61 62 // Imprime mensagem de erro com arquivo e linha do código e encerra. 63 // Uso igual ao printk: ppos_panic(format, arg1, arg2, ...) 64 #define ppos_panic(...) \ 65 do \ 66 { \ 67 printk(BACK_RED "PANIC (%s:%d)" FONT_NORMAL ": ", \ 68 __FILE__, __LINE__); \ 69 printk(__VA_ARGS__); \ 70 hw_poweroff(1); \ 71 } while (0) 72 73 // Testa parâmetros de funções, imprime mensagem e retorna erro. 74 // Uso: check_parm(value < 0, "invalid value", NULL); 75 #define check_parm(error_cond, error_msg, ret_val) \ 76 if (error_cond) \ 77 { \ 78 printk(BACK_YELLOW); \ 79 printk("Error in %s():", __func__); \ 80 printk(FONT_NORMAL); \ 81 printk(" %s\n", error_msg); \ 82 return ret_val; \ 83 } 84 85 #endif