Rename singleton to initialized_singleton
Use #pragma once instead of guard definitions in every header
This commit is contained in:
parent
a4df3252f2
commit
a4c1baa410
17 changed files with 151 additions and 175 deletions
|
@ -7,15 +7,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <f4ll/initialized_singleton.h>
|
||||
#include <f4ll/packet_usart.h>
|
||||
#include <f4ll/ringbuffer.h>
|
||||
#include <f4ll/singleton.h>
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
class console_handler : public usart_core, public singleton<console_handler>
|
||||
class console_handler : public usart_core, public initialized_singleton<console_handler>
|
||||
{
|
||||
friend class singleton<console_handler>;
|
||||
friend class initialized_singleton<console_handler>;
|
||||
|
||||
public:
|
||||
void print(char const *s);
|
||||
|
|
|
@ -7,15 +7,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <f4ll/dma_helper.h>
|
||||
#include <f4ll/singleton.h>
|
||||
#include <f4ll/initialized_singleton.h>
|
||||
#include <inttypes.h>
|
||||
#include <platform/dma_ll.h>
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
class crc_handler : public singleton<crc_handler>
|
||||
class crc_handler : public initialized_singleton<crc_handler>
|
||||
{
|
||||
friend class singleton<crc_handler>;
|
||||
friend class initialized_singleton<crc_handler>;
|
||||
|
||||
public:
|
||||
struct icallback
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef LL_DMAHELPER_H_
|
||||
#define LL_DMAHELPER_H_
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <platform/dma_ll.h>
|
||||
|
@ -56,5 +55,3 @@ private:
|
|||
};
|
||||
|
||||
} /* namespace f4ll */
|
||||
|
||||
#endif /* LL_DMAHELPER_H_ */
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#ifndef __FAULT_H
|
||||
#define __FAULT_H
|
||||
#pragma once
|
||||
|
||||
#define FAULT_REASON_HARD_FAULT 1
|
||||
#define FAULT_REASON_MEMMANAGE_FAULT 2
|
||||
#define FAULT_REASON_BUS_FAULT 3
|
||||
#define FAULT_REASON_USAGE_FAULT 4
|
||||
#define FAULT_REASON_HARD_FAULT 1
|
||||
#define FAULT_REASON_MEMMANAGE_FAULT 2
|
||||
#define FAULT_REASON_BUS_FAULT 3
|
||||
#define FAULT_REASON_USAGE_FAULT 4
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -43,5 +42,3 @@ __attribute__((noreturn)) void fault_handler(uint32_t type, fault_context_t *con
|
|||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FAULT_H */
|
||||
|
|
27
inc/f4ll/initialized_singleton.h
Normal file
27
inc/f4ll/initialized_singleton.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
template <typename T> class initialized_singleton
|
||||
{
|
||||
public:
|
||||
static T &instance() { return *m_instance; }
|
||||
template <typename... args_t> static T &init(args_t &&...args)
|
||||
{
|
||||
static T instance{std::forward<args_t>(args)...};
|
||||
m_instance = &instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
protected:
|
||||
initialized_singleton() = default;
|
||||
initialized_singleton(const initialized_singleton &) = delete;
|
||||
initialized_singleton &operator=(const initialized_singleton &) = delete;
|
||||
static T *m_instance;
|
||||
};
|
||||
|
||||
template <typename T> T *initialized_singleton<T>::m_instance = nullptr;
|
||||
|
||||
} // namespace f1ll {
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef _IRQLOCK_H_INCLUDED
|
||||
#define _IRQLOCK_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stm32f4xx.h>
|
||||
|
@ -19,8 +18,6 @@ public:
|
|||
inline ~irq_lock() { __set_PRIMASK(m_primask); }
|
||||
|
||||
private:
|
||||
uint32_t m_primask;
|
||||
uint32_t m_primask;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _IRQLOCK_H_INCLUDED
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <f4ll/dma_helper.h>
|
||||
#include <f4ll/singleton.h>
|
||||
#include <f4ll/initialized_singleton.h>
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
class memcpy_dma : public singleton<memcpy_dma>, private dma_helper
|
||||
class memcpy_dma : public initialized_singleton<memcpy_dma>, private dma_helper
|
||||
{
|
||||
friend class singleton<memcpy_dma>;
|
||||
friend class initialized_singleton<memcpy_dma>;
|
||||
|
||||
public:
|
||||
void *copy(void *dst, void const *src, uint16_t length);
|
||||
|
@ -24,4 +24,4 @@ private:
|
|||
bool volatile m_busy = false;
|
||||
};
|
||||
|
||||
} /* namespace f4ll */
|
||||
} // namespace f4ll
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef LL_HSUSART_H_
|
||||
#define LL_HSUSART_H_
|
||||
#pragma once
|
||||
|
||||
#include <platform/usart_ll.h>
|
||||
|
||||
#include <f4ll/crc_handler.h>
|
||||
#include <f4ll/usart_core.h>
|
||||
#include <platform/usart_ll.h>
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
|
@ -119,4 +120,3 @@ private:
|
|||
};
|
||||
|
||||
}
|
||||
#endif /* LL_HSUSART_H_ */
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
#ifndef SINGLETON_H_
|
||||
#define SINGLETON_H_
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
template <typename T> class singleton
|
||||
{
|
||||
public:
|
||||
static T &instance()
|
||||
{
|
||||
return *m_instance;
|
||||
}
|
||||
template <typename... args_t> static T &init(args_t &&...args)
|
||||
{
|
||||
static T instance{std::forward<args_t>(args)...};
|
||||
m_instance = &instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
protected:
|
||||
singleton() = default;
|
||||
singleton(const singleton &) = delete;
|
||||
singleton &operator=(const singleton &) = delete;
|
||||
static T *m_instance;
|
||||
};
|
||||
|
||||
template <typename T> T *singleton<T>::m_instance = nullptr;
|
||||
|
||||
} // namespace f1ll {
|
||||
|
||||
#endif /* SINGLETON_H_ */
|
|
@ -5,8 +5,7 @@
|
|||
* Author: compi
|
||||
*/
|
||||
|
||||
#ifndef _STM32PLUS_STRUTIL_H_
|
||||
#define _STM32PLUS_STRUTIL_H_
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
|
@ -27,5 +26,3 @@ char tochr(const uint8_t in, const uint8_t upper);
|
|||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _STM32PLUS_STRUTIL_H_ */
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef LL_USARTCORE_H_
|
||||
#define LL_USARTCORE_H_
|
||||
#pragma once
|
||||
|
||||
#include <platform/usart_ll.h>
|
||||
|
||||
#include <f4ll/dma_helper.h>
|
||||
|
@ -44,11 +44,10 @@ private:
|
|||
virtual void tx_dma_half_transfer(void) = 0;
|
||||
virtual void tx_dma_error(dma_helper::dma_error_type reason) = 0;
|
||||
|
||||
public:
|
||||
void usart_isr();
|
||||
void rx_dma_isr();
|
||||
void tx_dma_isr();
|
||||
};
|
||||
|
||||
} /* namespace f4ll */
|
||||
|
||||
#endif /* LL_USARTCORE_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue