Skip to content

Commit

Permalink
soc: sdk: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
redchenjs committed May 23, 2023
1 parent 0b962f1 commit 45dfc24
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 103 deletions.
51 changes: 18 additions & 33 deletions sdk/projects/apps/wujian100_open-app0/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,59 @@
#include <stdint.h>
#include <string.h>

#include <time.h>
#include <syslog.h>

#include "pmu.h"
#include "spi.h"
#include "pwm.h"
#include "pmp.h"
#include "pwm.h"
#include "mbox.h"

// Core Functions
extern void mdelay(uint32_t ms);

int main(void)
{
int loop_count = 100;
uint8_t loop = 100;
uint8_t mail_id = 0;
uint8_t mail_buff[1024] = {0};

pmu_set_reset(0);

pwm_init();
pmp_init();
mailbox_init(0);
pwm_init();
mbox_init(0);

printf("app0: started.\n");

pmu_set_reset(1);

printf("app0: start core 1...\n");

snprintf((char *)mail_buff, sizeof(mail_buff), "Hello from core 0! The message id is %u", loop_count);
snprintf((char *)mail_buff, sizeof(mail_buff), "Hello from core 0! The message id is %u", loop);

while (mailbox_send_message(loop_count, mail_buff, strlen((char *)mail_buff)) < 0) {
mdelay(625);
if (mbox_send_message(loop, mail_buff, strlen((char *)mail_buff)) >= 0) {
printf("app0: mail %u is sent to remote core\n", loop);
}

printf("app0: mail %u is sent to remote core\n", loop_count);

do {
loop_count++;
loop_count %= 256;

printf("app0: loop count: %d\n", loop_count);
printf("app0: loop count: %d\n", loop++);

pwm_test();

if (mailbox_check_acked()) {
printf("app0: mail %u is acked by remote core\n", mailbox_read_ack());

snprintf((char *)mail_buff, sizeof(mail_buff), "Hello from core 0! The message id is %u", loop_count);
if (mbox_check_acked()) {
snprintf((char *)mail_buff, sizeof(mail_buff), "Hello from core 0! The message id is %u", loop);

while (mailbox_send_message(loop_count, mail_buff, strlen((char *)mail_buff)) < 0) {
mdelay(625);
if (mbox_send_message(loop, mail_buff, strlen((char *)mail_buff)) >= 0) {
printf("app0: mail %u is acked by remote core\n", mbox_read_ack());
printf("app0: mail %u is sent to remote core\n", loop);
}

printf("app0: mail %u is sent to remote core\n", loop_count);
}

if (mailbox_check_pending()) {
mailbox_read_message(&mail_id, mail_buff, sizeof(mail_buff));
if (mbox_check_pending()) {
if (mbox_send_ack(mail_id) >= 0) {
mbox_read_message(&mail_id, mail_buff, sizeof(mail_buff));

printf("app0: mail %u is received: %s\n", mail_id, (char *)mail_buff);

while (mailbox_send_ack(mail_id) < 0) {
mdelay(625);
printf("app0: mail %u is received: %s\n", mail_id, (char *)mail_buff);
printf("app0: mail %u is acked\n", mail_id);
}

printf("app0: mail %u is acked\n", mail_id);
}

if (pmp_get_err(0)) {
Expand Down
48 changes: 17 additions & 31 deletions sdk/projects/apps/wujian100_open-app1/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,50 @@
#include <stdint.h>
#include <string.h>

#include <time.h>
#include <syslog.h>

#include "mbox.h"
#include "gpio.h"
#include "mbox.h"

// Core Functions
extern void mdelay(uint32_t ms);

int main(void)
{
int loop_count = 200;
uint8_t loop = 200;
uint8_t mail_id = 0;
uint8_t mail_buff[1024] = {0};

gpio_init();
mailbox_init(1);
mbox_init(1);

printf("app1: started.\n");

snprintf((char *)mail_buff, sizeof(mail_buff), "Hello from core 1! The message id is %u", loop_count);
snprintf((char *)mail_buff, sizeof(mail_buff), "Hello from core 1! The message id is %u", loop);

while (mailbox_send_message(loop_count, mail_buff, strlen((char *)mail_buff)) < 0) {
mdelay(625);
if (mbox_send_message(loop, mail_buff, strlen((char *)mail_buff)) >= 0) {
printf("app1: mail %u is sent to remote core\n", loop);
}

printf("app1: mail %u is sent to remote core\n", loop_count);

do {
loop_count++;
loop_count %= 256;

printf("app1: loop count: %d\n", loop_count);
printf("app1: loop count: %d\n", loop++);

gpio_toggle();

if (mailbox_check_acked()) {
printf("app1: mail %u is acked by remote core\n", mailbox_read_ack());
if (mbox_check_acked()) {
snprintf((char *)mail_buff, sizeof(mail_buff), "Hello from core 1! The message id is %u", loop);

snprintf((char *)mail_buff, sizeof(mail_buff), "Hello from core 1! The message id is %u", loop_count);

while (mailbox_send_message(loop_count, mail_buff, strlen((char *)mail_buff)) < 0) {
mdelay(625);
if (mbox_send_message(loop, mail_buff, strlen((char *)mail_buff)) >= 0) {
printf("app1: mail %u is acked by remote core\n", mbox_read_ack());
printf("app1: mail %u is sent to remote core\n", loop);
}

printf("app1: mail %u is sent to remote core\n", loop_count);
}

if (mailbox_check_pending()) {
mailbox_read_message(&mail_id, mail_buff, sizeof(mail_buff));
if (mbox_check_pending()) {
if (mbox_send_ack(mail_id) >= 0) {
mbox_read_message(&mail_id, mail_buff, sizeof(mail_buff));

printf("app1: mail %u is received: %s\n", mail_id, (char *)mail_buff);

while (mailbox_send_ack(mail_id) < 0) {
mdelay(625);
printf("app1: mail %u is received: %s\n", mail_id, (char *)mail_buff);
printf("app1: mail %u is acked\n", mail_id);
}

printf("app1: mail %u is acked\n", mail_id);
}

mdelay(1000);
Expand Down
4 changes: 1 addition & 3 deletions sdk/projects/apps/wujian100_open-boot/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
* Author: Jack Chen <[email protected]>
*/

#include <time.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

#include <time.h>
#include <syslog.h>

#include "pmu.h"
#include "spi.h"
#include "pwm.h"
Expand Down
14 changes: 7 additions & 7 deletions sdk/projects/apps/wujian100_open-driver/include/mbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
#include <stdint.h>
#include <stdbool.h>

extern void mailbox_init(uint8_t core_id);
extern void mbox_init(uint8_t core_id);

extern bool mailbox_check_acked(void);
extern bool mailbox_check_pending(void);
extern bool mbox_check_acked(void);
extern bool mbox_check_pending(void);

extern int mailbox_read_ack(void);
extern int mailbox_read_message(uint8_t *id, void *buff, uint32_t buff_size);
extern int mbox_read_ack(void);
extern int mbox_read_message(uint8_t *id, void *buff, uint32_t buff_size);

extern int mailbox_send_ack(uint8_t id);
extern int mailbox_send_message(uint8_t id, const void *buff, uint32_t len);
extern int mbox_send_ack(uint8_t id);
extern int mbox_send_message(uint8_t id, const void *buff, uint32_t len);

#endif /* INC_DRIVER_MBOX_H_ */
18 changes: 9 additions & 9 deletions sdk/projects/apps/wujian100_open-driver/mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ uint8_t mail_id = 0;
bool mail_acked = false;
bool mail_pending = false;

void mailbox_irq_handler(void)
void mbox_irq_handler(void)
{
if (MBOX_L_CTRL_REG & MBOX_RESP_BIT) {
mail_acked = true;
Expand All @@ -50,7 +50,7 @@ void mailbox_irq_handler(void)
MBOX_L_CTRL_REG &=~MBOX_INTR_BIT;
}

void mailbox_init(uint8_t core_id)
void mbox_init(uint8_t core_id)
{
if (core_id == 0) {
MBOX_L_CTRL_REG_BASE = (volatile uint32_t *)MBOX_0_CTRL_REG_BASE;
Expand All @@ -68,21 +68,21 @@ void mailbox_init(uint8_t core_id)

MBOX_L_CTRL_REG = 0x00000000;

drv_irq_register(MAILBOX_IRQ_NUM, mailbox_irq_handler);
drv_irq_register(MAILBOX_IRQ_NUM, mbox_irq_handler);
drv_irq_enable(MAILBOX_IRQ_NUM);
}

bool mailbox_check_acked(void)
bool mbox_check_acked(void)
{
return mail_acked;
}

bool mailbox_check_pending(void)
bool mbox_check_pending(void)
{
return mail_pending;
}

int mailbox_read_ack(void)
int mbox_read_ack(void)
{
uint8_t id = MBOX_L_CTRL_REG & 0xff;

Expand All @@ -93,7 +93,7 @@ int mailbox_read_ack(void)
return id;
}

int mailbox_read_message(uint8_t *id, void *buff, uint32_t buff_size)
int mbox_read_message(uint8_t *id, void *buff, uint32_t buff_size)
{
uint16_t size = (MBOX_L_CTRL_REG & 0x7fff00) >> 8;

Expand All @@ -112,7 +112,7 @@ int mailbox_read_message(uint8_t *id, void *buff, uint32_t buff_size)
return size;
}

int mailbox_send_ack(uint8_t id)
int mbox_send_ack(uint8_t id)
{
if (MBOX_R_CTRL_REG & MBOX_FULL_BIT) {
return -1;
Expand All @@ -123,7 +123,7 @@ int mailbox_send_ack(uint8_t id)
return 0;
}

int mailbox_send_message(uint8_t id, const void *buff, uint32_t len)
int mbox_send_message(uint8_t id, const void *buff, uint32_t len)
{
if (MBOX_R_CTRL_REG & MBOX_FULL_BIT) {
return -1;
Expand Down
12 changes: 6 additions & 6 deletions sdk/projects/apps/wujian100_open-driver/pmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdint.h>
#include <stdbool.h>

// PMP Functions
// IOPMP Functions
#define PMP_ERROR_BIT (0x00000200)
#define PMP_RESET_BIT (0x00000100)

Expand Down Expand Up @@ -122,17 +122,17 @@ void pmp_init(void)
PMP_CONF_1_2_MASK_REG = 0xFFFF0000; // 0x40010000 - 0x4001FFFF
PMP_CONF_1_3_BASE_REG = 0x40020000; // MAILBOX_1
PMP_CONF_1_3_MASK_REG = 0xFFFF0000; // 0x40020000 - 0x4002FFFF
PMP_CONF_1_4_BASE_REG = 0x60028000; // USI_1
PMP_CONF_1_4_MASK_REG = 0xFFFFF000; // 0x60028000 - 0x60028FFF
PMP_CONF_1_5_BASE_REG = 0x60018000; // GPIO
PMP_CONF_1_5_MASK_REG = 0xFFFFF000; // 0x60029000 - 0x60029FFF
PMP_CONF_1_4_BASE_REG = 0x60018000; // GPIO
PMP_CONF_1_4_MASK_REG = 0xFFFFF000; // 0x60018000 - 0x60018FFF
PMP_CONF_1_5_BASE_REG = 0x60028000; // USI_1
PMP_CONF_1_5_MASK_REG = 0xFFFFF000; // 0x60028000 - 0x60028FFF
PMP_CONF_1_6_BASE_REG = 0x00000000;
PMP_CONF_1_6_MASK_REG = 0x00000000;
PMP_CONF_1_7_BASE_REG = 0x00000000;
PMP_CONF_1_7_MASK_REG = 0x00000000;

PMP_CTRL_0_REG = 0x00;
PMP_CTRL_1_REG = 0x7f;
PMP_CTRL_1_REG = 0x3f;
}

bool pmp_get_err(uint8_t idx)
Expand Down
1 change: 1 addition & 0 deletions sdk/projects/apps/wujian100_open-tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ clean:
@$(RM) -f rsa_sign
@echo RM rsa_verify
@$(RM) -f rsa_verify
@$(RM) -f flash.bin
@$(RM) -rf $(OBJDIR)
2 changes: 1 addition & 1 deletion soc/core_top.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
*/
module core_top #(
parameter IBUS_BASE = 12'h000,
parameter IBUS_MASK = 12'h000,
parameter IBUS_MASK = 12'he00,
parameter RESET_VECTOR = 32'h0000_0000
) (
apb0_dummy1_intr,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//Copyright 1986-2023 Xilinx, Inc. All Rights Reserved.
//--------------------------------------------------------------------------------
//Tool Version: Vivado v.2022.2.2 (win64) Build 3788238 Tue Feb 21 20:00:34 MST 2023
//Date : Wed May 24 02:05:51 2023
//Date : Wed May 24 02:42:23 2023
//Host : ThinPC running 64-bit major release (build 9200)
//Command : generate_target design_1_wrapper.bd
//Design : design_1_wrapper
Expand Down
10 changes: 5 additions & 5 deletions wujian100_open.srcs/sources_1/bd/design_1/design_1.bda
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
<data key="VT">PM</data>
</node>
<node id="n1">
<data key="VH">2</data>
<data key="VM">design_1</data>
<data key="VT">BC</data>
<data key="VT">VR</data>
</node>
<node id="n2">
<data key="VH">2</data>
<data key="VM">design_1</data>
<data key="VT">VR</data>
<data key="VT">BC</data>
</node>
<edge id="e0" source="n1" target="n2"/>
<edge id="e1" source="n2" target="n0"/>
<edge id="e0" source="n2" target="n1"/>
<edge id="e1" source="n1" target="n0"/>
</graph>
</graphml>
14 changes: 7 additions & 7 deletions wujian100_open.xpr
Original file line number Diff line number Diff line change
Expand Up @@ -409,20 +409,20 @@
<Attr Name="UsedIn" Val="implementation"/>
<Attr Name="UsedIn" Val="simulation"/>
</FileInfo>
<CompFileExtendedInfo CompFileName="design_1.bd" FileRelPathName="ip/design_1_clk_wiz_0_0/design_1_clk_wiz_0_0.xci">
<Proxy FileSetName="design_1_clk_wiz_0_0"/>
</CompFileExtendedInfo>
<CompFileExtendedInfo CompFileName="design_1.bd" FileRelPathName="ip/design_1_wujian100_open_top_0_0/design_1_wujian100_open_top_0_0.xci">
<Proxy FileSetName="design_1_wujian100_open_top_0_0"/>
</CompFileExtendedInfo>
<CompFileExtendedInfo CompFileName="design_1.bd" FileRelPathName="ip/design_1_util_vector_logic_1_0/design_1_util_vector_logic_1_0.xci">
<Proxy FileSetName="design_1_util_vector_logic_1_0"/>
</CompFileExtendedInfo>
<CompFileExtendedInfo CompFileName="design_1.bd" FileRelPathName="ip/design_1_clk_wiz_0_0/design_1_clk_wiz_0_0.xci">
<Proxy FileSetName="design_1_clk_wiz_0_0"/>
<CompFileExtendedInfo CompFileName="design_1.bd" FileRelPathName="ip/design_1_util_vector_logic_2_0/design_1_util_vector_logic_2_0.xci">
<Proxy FileSetName="design_1_util_vector_logic_2_0"/>
</CompFileExtendedInfo>
<CompFileExtendedInfo CompFileName="design_1.bd" FileRelPathName="ip/design_1_processing_system7_0_0/design_1_processing_system7_0_0.xci">
<Proxy FileSetName="design_1_processing_system7_0_0"/>
</CompFileExtendedInfo>
<CompFileExtendedInfo CompFileName="design_1.bd" FileRelPathName="ip/design_1_util_vector_logic_2_0/design_1_util_vector_logic_2_0.xci">
<Proxy FileSetName="design_1_util_vector_logic_2_0"/>
<CompFileExtendedInfo CompFileName="design_1.bd" FileRelPathName="ip/design_1_util_vector_logic_1_0/design_1_util_vector_logic_1_0.xci">
<Proxy FileSetName="design_1_util_vector_logic_1_0"/>
</CompFileExtendedInfo>
</File>
<File Path="$PGENDIR/sources_1/bd/design_1/hdl/design_1_wrapper.v">
Expand Down

0 comments on commit 45dfc24

Please sign in to comment.