Add register_core1

This commit is contained in:
zhaozhongxiang 2018-10-10 11:08:27 +08:00
parent 2fa2a5bd57
commit aeb2380869
4 changed files with 44 additions and 12 deletions

View File

@ -25,13 +25,15 @@
#include "syslog.h"
#include "uarths.h"
extern volatile uint64_t g_wake_up[2];
core_instance_t core1_instance;
volatile char * const ram = (volatile char*)RAM_BASE_ADDR;
extern char _heap_start[];
extern char _heap_end[];
extern volatile uint64_t g_wake_up[2];
void thread_entry(int core_id)
{
while (!atomic_read(&g_wake_up[core_id]));
@ -43,6 +45,16 @@ void core_enable(int core_id)
atomic_set(&g_wake_up[core_id], 1);
}
int register_core1(core_function func, void *ctx)
{
if(func == NULL)
return -1;
core1_instance.callback = func;
core1_instance.ctx = ctx;
core_enable(1);
return 0;
}
int __attribute__((weak)) os_entry(int core_id, int number_of_cores, int (*user_main)(int, char**))
{
/* Call main if there is no OS */
@ -68,19 +80,22 @@ void _init_bsp(int core_id, int number_of_cores)
/* Init libc array for C++ */
__libc_init_array();
}
int ret = 0;
if (core_id == 0)
{
core1_instance.callback = NULL;
core1_instance.ctx = NULL;
ret = os_entry(core_id, number_of_cores, main);
}
else
{
thread_entry(core_id);
if(core1_instance.callback == NULL)
asm volatile ("wfi");
else
ret = core1_instance.callback(core1_instance.ctx);
}
if (core_id == 0)
{
/* Enable Core 1 to run main */
core_enable(1);
}
int ret = os_entry(core_id, number_of_cores, main);
exit(ret);
}

7
lib/bsp/include/bsp.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _KENDRYTE_BSP_H
#define _KENDRYTE_BSP_H
#include "atomic.h"
#include "entry.h"
#include "sleep.h"
#include "encoding.h"
#endif

View File

@ -23,6 +23,16 @@
extern "C" {
#endif
typedef int (*core_function)(void *ctx);
typedef struct _core_instance_t
{
core_function callback;
void *ctx;
} core_instance_t;
int register_core1(core_function func, void *ctx);
static inline void init_lma(void)
{
extern unsigned int _data_lma;

View File

@ -14,7 +14,7 @@
*/
#include <stdio.h>
#include "sleep.h"
#include "encoding.h"
#include "bsp.h"
int main()
{
uint64_t core_id = current_coreid();