0
本帖最后由 lee_st 于 2018-4-20 07:36 编辑
前个帖子实现了中断通信,本帖主要实现非中断情况下的互斥通信。
在前一帖子代码的基础上稍加更改,把M4核和M0+核的中断去除,
在M4核中更改的代码有
/* Init Mailbox */
MAILBOX_Init(MAILBOX);
/* Boot source for Core 1 from flash */
SYSCON->CPBOOT = SYSCON_CPBOOT_BOOTADDR(*(uint32_t *)((uint8_t *)CORE1_BOOT_ADDRESS + 0x4));
SYSCON->CPSTACK = SYSCON_CPSTACK_STACKADDR(*(uint32_t *)CORE1_BOOT_ADDRESS);
int32_t temp = SYSCON->CPCTRL;
temp |= 0xc0c48000;
SYSCON->CPCTRL = (temp | SYSCON_CPCTRL_CM0RSTEN_MASK);
SYSCON->CPCTRL = (temp);
delay();
MAILBOX_SetValue(MAILBOX, kMAILBOX_CM0Plus, (uint32_t)&g_msg);
while (1)
{
/* Stop secondary core execution. */
if (!GPIO_ReadPinInput(BOARD_SW1_GPIO, BOARD_SW1_GPIO_PORT, BOARD_SW1_GPIO_PIN))
{
MCMGR_StopCore(kMCMGR_Core1);
PRINTF("Stopped Secondary core.n");
delay();
}
/* Start core from reset vector */
if (!GPIO_ReadPinInput(BOARD_SW2_GPIO, BOARD_SW2_GPIO_PORT, BOARD_SW2_GPIO_PIN))
{
PRINTF("Started Secondary core.n");
MCMGR_StartCore(kMCMGR_Core1, CORE1_BOOT_ADDRESS, 5, kMCMGR_Start_Synchronous);
delay();
}
PRINTF("M4 receive:%drn",M0_TO_M4_R);
delay();
M4_TO_M0_T++;
/* Get Mailbox mutex */
while (MAILBOX_GetMutex(MAILBOX) == 0)
;
/* The core0 has mutex, can change shared variable _XiaoMaGe */
g_msg++;
PRINTF("M4 : mailbox mutex,the data is: %dn", g_msg);
/* Set mutex to allow access other core to shared variable */
MAILBOX_SetMutex(MAILBOX);
}
在M0+内核更改的代码
/* Init Mailbox */
MAILBOX_Init(MAILBOX);
while (1)
{
delay();
M0_TO_M4_T++;
PRINTF("M0receive:%drn",M4_TO_M0_R);
GPIO_TogglePinsOutput(GPIO, 0u, 1u << 15u);
GPIO_TogglePinsOutput(GPIO, 0u, 1u << 19u);
GPIO_TogglePinsOutput(GPIO, 0u, 1u << 21u);
GPIO_TogglePinsOutput(GPIO, 0u, 1u << 22u);
GPIO_TogglePinsOutput(GPIO, 0u, 1u << 25u);
GPIO_TogglePinsOutput(GPIO, 0u, 1u << 26u);
GPIO_TogglePinsOutput(GPIO, 0u, 1u << 29u);
GPIO_TogglePinsOutput(GPIO, 0u, 1u << 30u);
/* Get Mailbox mutex */
while (MAILBOX_GetMutex(MAILBOX) == 0)
;
g_msg = (uint32_t *)MAILBOX_GetValue(MAILBOX, kMAILBOX_CM0Plus);
/* The core1 has mutex, can change shared variable _XiaoMaGe */
if (g_msg != NULL)
{
(*g_msg)++;
PRINTF("M0 : mailbox mutex,the data is :%dn", *g_msg);
}
/* Set mutex to allow access other core to shared variable */
MAILBOX_SetMutex(MAILBOX);
}
编译下载,串口助手观察通信见下图
|
评分
-
查看全部评分
|