diff --git a/BaS_gcc/include/bas_types.h b/BaS_gcc/include/bas_types.h index 0635603..a77d287 100644 --- a/BaS_gcc/include/bas_types.h +++ b/BaS_gcc/include/bas_types.h @@ -29,9 +29,7 @@ #define BAS_TYPES_H_ #ifndef __cplusplus -typedef int bool; -#define TRUE 1 -#define FALSE 0 +#include #endif /* __cplusplus */ diff --git a/BaS_gcc/include/wait.h b/BaS_gcc/include/wait.h index ca7ec9f..7b33306 100644 --- a/BaS_gcc/include/wait.h +++ b/BaS_gcc/include/wait.h @@ -29,10 +29,10 @@ #include -typedef uint32_t (*checker_func)(void); +typedef bool (*checker_func)(void); extern __inline__ void wait(uint32_t) __attribute__((always_inline)); -extern __inline__ uint32_t waitfor(uint32_t us, checker_func condition) __attribute__((always_inline)); +extern __inline__ bool waitfor(uint32_t us, checker_func condition) __attribute__((always_inline)); /* * wait for the specified number of us on slice timer 0. Replaces the original routines that had * the number of useconds to wait for hardcoded in their name. @@ -48,7 +48,7 @@ extern __inline__ void wait(uint32_t us) * the same as above, with a checker function which gets called while * busy waiting and allows for an early return if it returns true */ -extern __inline__ uint32_t waitfor(uint32_t us, checker_func condition) +extern __inline__ bool waitfor(uint32_t us, checker_func condition) { uint32_t target = MCF_SLT_SCNT(0) - (us * 132); uint32_t res; @@ -58,6 +58,6 @@ extern __inline__ uint32_t waitfor(uint32_t us, checker_func condition) if ((res = (*condition)())) return res; } while (MCF_SLT_SCNT(0) > target); - return 0; + return false; } #endif /* _WAIT_H_ */ diff --git a/BaS_gcc/sources/BaS.c b/BaS_gcc/sources/BaS.c index 0bcc9cb..ebaca7a 100644 --- a/BaS_gcc/sources/BaS.c +++ b/BaS_gcc/sources/BaS.c @@ -56,23 +56,23 @@ extern uint8_t _EMUTOS_SIZE[]; /* * check if it is possible to transfer data to PIC */ -static inline uint32_t pic_txready(void) +static inline bool pic_txready(void) { if (MCF_PSC3_PSCSR & MCF_PSC_PSCSR_TXRDY) - return TRUE; + return true; - return FALSE; + return true; } /* * check if it is possible to receive data from PIC */ -static inline uint32_t pic_rxready(void) +static inline bool pic_rxready(void) { if (MCF_PSC3_PSCSR & MCF_PSC_PSCSR_RXRDY) - return TRUE; + return true; - return FALSE; + return false; } void write_pic_byte(uint8_t value) diff --git a/BaS_gcc/sources/mmc.c b/BaS_gcc/sources/mmc.c index 0b50a37..78ca486 100644 --- a/BaS_gcc/sources/mmc.c +++ b/BaS_gcc/sources/mmc.c @@ -138,7 +138,7 @@ static void xmit_spi_multi(const uint8_t *buff, uint32_t btx) #endif -static uint32_t card_ready(void) +static bool card_ready(void) { uint8_t d; diff --git a/BaS_gcc/sources/sysinit.c b/BaS_gcc/sources/sysinit.c index fe34395..43ca3b9 100644 --- a/BaS_gcc/sources/sysinit.c +++ b/BaS_gcc/sources/sysinit.c @@ -31,6 +31,7 @@ #include "sysinit.h" #include "bas_printf.h" #include "bas_types.h" +#include "wait.h" extern void xprintf_before_copy(const char *fmt, ...); #define xprintf xprintf_before_copy @@ -41,32 +42,6 @@ extern void flush_and_invalidate_caches_before_copy(void); extern volatile long _VRAM; /* start address of video ram from linker script */ -/* - * wait for the specified number of us on slice timer 0. Replaces the original routines that had - * the number of useconds to wait for hardcoded in their name. - */ -inline __attribute__((always_inline)) void wait(uint32_t us) -{ - uint32_t target = MCF_SLT_SCNT(0) - (us * 132); - - while (MCF_SLT_SCNT(0) > target); -} - -/* - * the same as above, with a checker function which gets called while - * busy waiting and allows for an early return if it returns true - */ -inline __attribute__((always_inline)) bool waitfor(uint32_t us, int (*condition)(void)) -{ - uint32_t target = MCF_SLT_SCNT(0) - (us * 132); - - do - { - if ((*condition)()) - return TRUE; - } while (MCF_SLT_SCNT(0) > target); - return FALSE; -} /* * init SLICE TIMER 0 * all = 32.538 sec = 30.736mHz @@ -519,9 +494,9 @@ void test_upd720101(void) static bool i2c_transfer_finished(void) { if (MCF_I2C_I2SR & MCF_I2C_I2SR_IIF) - return TRUE; + return true; - return FALSE; + return false; } static void wait_i2c_transfer_finished(void)