Skip to content

Commit

Permalink
Implement message publish and subscribe feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
At-EC committed May 24, 2024
1 parent 58def1d commit bb8996e
Show file tree
Hide file tree
Showing 21 changed files with 998 additions and 54 deletions.
6 changes: 3 additions & 3 deletions build_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
extern "C" {
#endif

#define ATOS_BUILD_TIME "2024-05-03,19:24"
#define ATOS_COMMIT_HEAD_ID "7f20839081471f9b94da1b32577e8aa28bf6b025"
#define ATOS_BUILD_TIME "2024-05-24,16:16"
#define ATOS_COMMIT_HEAD_ID "58def1d67855166c32a8bbf4ea9a153bc54df8f8"
#define ATOS_VERSION_MAJOR_NUMBER (1u)
#define ATOS_VERSION_MINOR_NUMBER (5u)
#define ATOS_VERSION_PATCH_NUMBER (1u)
#define ATOS_VERSION_PATCH_NUMBER (2u)

#define ATOS_VERSION_MAJOR_NUMBER_MASK (0x03FFu)
#define ATOS_VERSION_MAJOR_NUMBER_POS (22u)
Expand Down
149 changes: 149 additions & 0 deletions include/kernel/at_rtos.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,148 @@ static inline u32p_t os_pool_release(os_pool_id_t id, void **ppUserBuffer)
return (u32p_t)_impl_pool_release(id.val, ppUserBuffer);
}

/**
* @brief Initialize a new publish.
*
* @param pName The publish name.
*
* @return The publish unique id.
*
**
* demo usage:
*
* os_publish_id_t id = os_publish_init("sample");
* if (os_id_is_invalid(id)) {
* printf("Message publisher %s init failed\n", id.pName);
* }
*/
static inline os_publish_id_t os_publish_init(const char_t *pName)
{
extern u32_t _impl_publish_os_id_to_number(os_id_t id);
extern os_id_t _impl_publish_init(const char_t *pName);

os_publish_id_t id = {0u};

id.val = _impl_publish_init(pName);
id.number = _impl_publish_os_id_to_number(id.val);
id.pName = pName;

return id;
}

/**
* @brief Publisher Submits the report data.
*
* @param id The publish unique id.
* @param pPublishData The pointer of the data buffer address.
* @param publishSize The data buffer size.
*
* @return Value The result of the publisher data operation.
**
* demo usage:
* u8_t publish_data = 0u;
* u32p_t ret = os_publish_data_submit(id, (u8_t*)&publish_data, 1u);
* if (PC_IER(ret)) {
* printf("Publisher %d data submit failed\n", id.pName);
* }
*/
static inline u32p_t os_publish_data_submit(os_publish_id_t id, const void *pPublishData, u16_t publishSize)
{
extern u32p_t _impl_publish_data_submit(os_id_t id, const void *pPublishData, u16_t publishSize);

return _impl_publish_data_submit(id.val, pPublishData, publishSize);
}

/**
* @brief Initialize a new subscribe.
*
* @param pDataAddr The pointer of the data buffer address.
* @param dataSize The data buffer size.
* @param pName The subscribe name.
*
* @return Value The result fo subscribe init operation.
**
* demo usage:
*
* os_subscribe_id_t id = os_subscribe_init("sample");
* if (os_id_is_invalid(id)) {
* printf("Message subscriber %s init failed\n", id.pName);
* }
*/
static inline os_subscribe_id_t os_subscribe_init(void *pDataAddr, u16_t dataSize, const char_t *pName)
{
extern u32_t _impl_subscribe_os_id_to_number(os_id_t id);
extern os_id_t _impl_subscribe_init(void *pDataAddr, u16_t dataSize, const char_t *pName);

os_subscribe_id_t id = {0u};

id.val = _impl_subscribe_init(pDataAddr, dataSize, pName);
id.number = _impl_subscribe_os_id_to_number(id.val);
id.pName = pName;

return id;
}

/**
* @brief To check if the publisher submits new data and that is not applied by subscriber.
*
* @param subscribe_id The subscribe unique id.
*
* @return Value The result of subscribe data is ready.
* demo usage:
* if (!os_subscribe_data_is_ready(id)) {
* printf("subscriber %d data is not ready\n", id.pName);
* }
*/
static inline b_t os_subscribe_data_is_ready(os_subscribe_id_t id)
{
extern b_t _impl_subscribe_data_is_ready(os_id_t subscribe_id);

return _impl_subscribe_data_is_ready(id.val);
}

/**
* @brief The subscribe register the corresponding publish.
*
* @param subscribe_id The subscribe unique id.
* @param publish_id The publish unique id.
* @param isMute The set of notification operation.
* @param pFuncHandler The notification function handler pointer.
*
* @return Value The result fo subscribe init operation.
*/
static inline u32p_t os_subscribe_register(os_subscribe_id_t subscribe_id, os_publish_id_t publish_id, b_t isMute,
pSubscribe_callbackFunc_t pNotificationHandler)
{
extern u32p_t _impl_subscribe_register(os_id_t subscribe_id, os_id_t publish_id, b_t isMute,
pSubscribe_callbackFunc_t pNotificationHandler);

return _impl_subscribe_register(subscribe_id.val, publish_id.val, isMute, pNotificationHandler);
}

/**
* @brief The subscriber wait publisher put new data with a timeout option.
*
* @param subscribe_id The subscribe unique id.
* @param pDataBuffer The pointer of data buffer.
* @param pDataLen The pointer of data buffer len.
*
* @return Value The result of subscribe init operation.
**
* demo usage:
* u8_t subscribe_data = 0u;
* u32p_t ret = os_subscribe_data_apply(id, (u8_t*)&publish_data, 1u);
* if (PC_IER(ret)) {
* printf("subscriber %d data apply failed\n", id.pName);
* }
*/
static inline u32p_t os_subscribe_data_apply(os_subscribe_id_t subscribe_id, void *pDataBuffer, u16_t *pDataLen)
{
extern u32p_t _impl_subscribe_data_apply(os_id_t subscribe_id, void *pDataBuffer, u16_t *pDataLen);

return _impl_subscribe_data_apply(subscribe_id.val, pDataBuffer, pDataLen);
}

/**
* @brief Check if the thread unique id if is's invalid.
*
Expand Down Expand Up @@ -993,6 +1135,13 @@ typedef struct {
u32p_t (*pool_take)(os_pool_id_t, void **, u16_t, u32_t);
u32p_t (*pool_release)(os_pool_id_t, void **);

os_publish_id_t (*publish_init)(const char_t *);
u32p_t (*publish_data_submit)(os_publish_id_t, const void *, u16_t);
os_subscribe_id_t (*subscribe_init)(void *, u16_t, const char_t *);
u32p_t (*subscribe_register)(os_subscribe_id_t, os_publish_id_t, b_t, pSubscribe_callbackFunc_t);
u32p_t (*subscribe_data_apply)(os_subscribe_id_t, void *, u16_t *);
b_t (*subscribe_data_is_ready)(os_subscribe_id_t);

b_t (*id_isInvalid)(struct os_id);
os_thread_id_t (*id_current_thread)(void);
u32p_t (*schedule_run)(void);
Expand Down
8 changes: 8 additions & 0 deletions include/kernel/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ extern "C" {
#define POOL_INSTANCE_SUPPORTED_NUMBER (1u)
#endif

#ifndef PUBLISH_INSTANCE_SUPPORTED_NUMBER
#define PUBLISH_INSTANCE_SUPPORTED_NUMBER (1u)
#endif

#ifndef SUBSCRIBE_INSTANCE_SUPPORTED_NUMBER
#define SUBSCRIBE_INSTANCE_SUPPORTED_NUMBER (1u)
#endif

#ifndef PORTAL_SYSTEM_CORE_CLOCK_MHZ
#define PORTAL_SYSTEM_CORE_CLOCK_MHZ (120u)
#endif
Expand Down
14 changes: 9 additions & 5 deletions include/kernel/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ enum {
#define KERNEL_TIMER_MEMORY_SIZE (sizeof(timer_context_t) * TIMER_INSTANCE_SUPPORTED_NUMBER)
#define KERNEL_SEMAPHORE_MEMORY_SIZE \
(sizeof(semaphore_context_t) * (SEMAPHORE_INSTANCE_SUPPORTED_NUMBER + KERNEL_APPLICATION_SEMAPHORE_INSTANCE))
#define KERNEL_MUTEX_MEMORY_SIZE (sizeof(mutex_context_t) * MUTEX_INSTANCE_SUPPORTED_NUMBER)
#define KERNEL_EVENT_MEMORY_SIZE (sizeof(event_context_t) * EVENT_INSTANCE_SUPPORTED_NUMBER)
#define KERNEL_QUEUE_MEMORY_SIZE (sizeof(queue_context_t) * QUEUE_INSTANCE_SUPPORTED_NUMBER)
#define KERNEL_POOL_MEMORY_SIZE (sizeof(pool_context_t) * POOL_INSTANCE_SUPPORTED_NUMBER)
#define KERNEL_MUTEX_MEMORY_SIZE (sizeof(mutex_context_t) * MUTEX_INSTANCE_SUPPORTED_NUMBER)
#define KERNEL_EVENT_MEMORY_SIZE (sizeof(event_context_t) * EVENT_INSTANCE_SUPPORTED_NUMBER)
#define KERNEL_QUEUE_MEMORY_SIZE (sizeof(queue_context_t) * QUEUE_INSTANCE_SUPPORTED_NUMBER)
#define KERNEL_POOL_MEMORY_SIZE (sizeof(pool_context_t) * POOL_INSTANCE_SUPPORTED_NUMBER)
#define KERNEL_PUBLISH_MEMORY_SIZE (sizeof(publish_context_t) * PUBLISH_INSTANCE_SUPPORTED_NUMBER)
#define KERNEL_SUBSCIRBE_MEMORY_SIZE (sizeof(subscribe_context_t) * SUBSCRIBE_INSTANCE_SUPPORTED_NUMBER)

#define KERNEL_MEMBER_MAP_1 (KERNEL_THREAD_MEMORY_SIZE)
#define KERNEL_MEMBER_MAP_2 (KERNEL_MEMBER_MAP_1 + KERNEL_TIMER_INTERNAL_MEMORY_SIZE)
Expand All @@ -62,7 +64,9 @@ enum {
#define KERNEL_MEMBER_MAP_6 (KERNEL_MEMBER_MAP_5 + KERNEL_EVENT_MEMORY_SIZE)
#define KERNEL_MEMBER_MAP_7 (KERNEL_MEMBER_MAP_6 + KERNEL_QUEUE_MEMORY_SIZE)
#define KERNEL_MEMBER_MAP_8 (KERNEL_MEMBER_MAP_7 + KERNEL_POOL_MEMORY_SIZE)
#define KERNEL_MEMBER_MAP_NUMBER (KERNEL_MEMBER_MAP_8 + 1u)
#define KERNEL_MEMBER_MAP_9 (KERNEL_MEMBER_MAP_8 + KERNEL_PUBLISH_MEMORY_SIZE)
#define KERNEL_MEMBER_MAP_10 (KERNEL_MEMBER_MAP_9 + KERNEL_SUBSCIRBE_MEMORY_SIZE)
#define KERNEL_MEMBER_MAP_NUMBER (KERNEL_MEMBER_MAP_10 + 1u)

thread_context_t *kernel_thread_runContextGet(void);
list_t *kernel_member_list_get(u8_t member_id, u8_t list_id);
Expand Down
46 changes: 42 additions & 4 deletions include/kernel/kstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,37 @@ typedef void (*pTimer_callbackFunc_t)(void);
typedef void (*pThread_callbackFunc_t)(os_id_t);
typedef void (*pThread_entryFunc_t)(void);
typedef void (*pEvent_callbackFunc_t)(void);
typedef void (*pSubscribe_callbackFunc_t)(const void *, u16_t);

typedef struct {
/* A common struct head to link with other context */
linker_head_t head;

u32_t refresh_count;

list_t subscribeListHead;
} publish_context_t;

typedef struct {
/* A common struct head to link with other context */
linker_head_t head;

os_id_t hold;

u32_t last_count;

u32_t isMute;

struct callSubEntry {
list_node_t node;

void *pDataAddress;

u16_t dataSize;

pSubscribe_callbackFunc_t pNotificationHandler;
} callEntry;
} subscribe_context_t;

typedef struct {
/* A common struct head to link with other context */
Expand All @@ -43,15 +74,15 @@ typedef struct {

u64_t duration_us;

struct callFunc {
struct callTimerEntry {
list_node_t node;

union {
pTimer_callbackFunc_t pTimer;
pTimer_callbackFunc_t pTimerCallEntry;

pThread_callbackFunc_t pThread;
pThread_callbackFunc_t pThreadCallEntry;
};
} call;
} callEntry;
} timer_context_t;

typedef struct {
Expand Down Expand Up @@ -243,6 +274,8 @@ enum {
KERNEL_MEMBER_EVENT,
KERNEL_MEMBER_QUEUE,
KERNEL_MEMBER_POOL,
KERNEL_MEMBER_PUBLISH,
KERNEL_MEMBER_SUBSCRIBE,
KERNEL_MEMBER_NUMBER,
};

Expand All @@ -267,6 +300,11 @@ enum {
KERNEL_MEMBER_LIST_QUEUE_INIT,

KERNEL_MEMBER_LIST_POOL_INIT,

KERNEL_MEMBER_LIST_PUBLISH_INIT,
KERNEL_MEMBER_LIST_PUBLISH_PEND,
KERNEL_MEMBER_LIST_SUBSCRIBE_INIT,

KERNEL_MEMBER_LIST_NUMBER,
};

Expand Down
2 changes: 2 additions & 0 deletions include/kernel/ktype.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ typedef struct os_id os_mutex_id_t;
typedef struct os_id os_evt_id_t;
typedef struct os_id os_msgq_id_t;
typedef struct os_id os_pool_id_t;
typedef struct os_id os_publish_id_t;
typedef struct os_id os_subscribe_id_t;

typedef struct os_priority os_priority_t;
typedef struct os_time os_time_t;
Expand Down
6 changes: 3 additions & 3 deletions include/kernel/postcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ enum {
PC_CMPT_EVENT_6,
PC_CMPT_TIMER_7,
PC_CMPT_POOL_8,

PC_CMPT_ASSERT_8,
PC_CMPT_PUBLISH_9,
PC_CMPT_ASSERT_10,

POSTCODE_COMPONENT_NUMBER,
};
Expand Down Expand Up @@ -102,7 +102,7 @@ static inline u32p_t _impl_trace_postcode_cmpt_last_failed(u32p_t postcode)
#define PC_IOK(code) PC_IOK_TC(code)
#define PC_IER(code) PC_IER_TC(code)

#define _PC_CMPT_ASSERT_FAILED PC_FAILED(PC_CMPT_ASSERT_8)
#define _PC_CMPT_ASSERT_FAILED PC_FAILED(PC_CMPT_ASSERT_10)

#define _CHECK_CONDITION(cond) \
do { \
Expand Down
8 changes: 8 additions & 0 deletions include/kernel/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ typedef struct {
u32_t timeout_ms;
} timer_snapshot_t;

typedef struct {
u32_t refresh_count;
} publish_snapshot_t;


typedef struct {
u32_t id;
const char_t *pName;
Expand All @@ -94,6 +99,8 @@ typedef struct {
pool_snapshot_t pool;

timer_snapshot_t timer;

publish_snapshot_t publish;
};
} kernel_snapshot_t;

Expand All @@ -111,6 +118,7 @@ b_t event_snapshot(u32_t instance, kernel_snapshot_t *pMsgs);
b_t queue_snapshot(u32_t instance, kernel_snapshot_t *pMsgs);
b_t pool_snapshot(u32_t instance, kernel_snapshot_t *pMsgs);
b_t timer_snapshot(u32_t instance, kernel_snapshot_t *pMsgs);
b_t publish_snapshot(u32_t instance, kernel_snapshot_t *pMsgs);

void _impl_trace_firmware_snapshot_print(void);
void _impl_trace_postcode_snapshot_print(void);
Expand Down
9 changes: 6 additions & 3 deletions include/kernel/typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,19 @@ typedef u32_t u32p_t;
#define VREG16(addr) (*(volatile u16_t *)(u32_t)(addr))
#define VREG8(addr) (*(volatile u8_t *)(u32_t)(addr))

#define SBIT(x) ((u32_t)((u32_t)0x01u << (x)))
#define SBITS(start, end) ((0xFFFFFFFFul << (start)) & (0xFFFFFFFFul >> (31u - (u32_t)(end))))
#define GBITS(regval, start, end) (((regval) & SBITS((start), (end))) >> (start))
#define SET_BIT(x) ((u32_t)((u32_t)0x01u << (x)))
#define SET_BITS(start, end) ((0xFFFFFFFFul << (start)) & (0xFFFFFFFFul >> (31u - (u32_t)(end))))
#define DUMP_BITS(regval, start, end) (((regval) & SET_BITS((start), (end))) >> (start))

#define DEQUALIFY(s, v) ((s)(u32_t)(const volatile void *)(v))
#define OFFSETOF(s, m) ((u32_t)(&((s *)0)->m))
#define CONTAINEROF(p, s, m) (DEQUALIFY(s *, ((const vu8_t *)(p)-OFFSETOF(s, m))))
#define SIZEOF(arr) (sizeof(arr))
#define DIMOF(arr) (SIZEOF(arr) / SIZEOF(arr[0]))

#define MINI(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))

#define ROUND_UP(size, align) (((u32_t)(size) + (align - 1u)) & (~(align - 1)))
#define ROUND_DOWN(size, align) (((u32_t)(size)) & (~(align - 1)))
#define RANGE_ADDRESS_CONDITION(address, pool) \
Expand Down
Loading

0 comments on commit bb8996e

Please sign in to comment.