Merge pull request #117 from DavidLin1577/patch-2

Improve readability of codes
This commit is contained in:
Arthur
2020-03-07 10:47:51 +08:00
committed by GitHub
3 changed files with 57 additions and 67 deletions

View File

@@ -1,9 +1,9 @@
#include "stdio.h"
#include "NuMicro.h"
#include "tos_k.h"
#define task1_size 240 // size of task1 stack
#define task2_size 240
k_task_t task1; //structure of task1
#define task1_size 240 // size of task1 stack
#define task2_size 240
k_task_t task1; // structure of task1
k_task_t task2;
k_stack_t task1_stack[task1_size]; //stack of task1
@@ -14,23 +14,23 @@ void SYS_Init(void)
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Unlock protected registers */
/* Unlock protected registers */
SYS_UnlockReg();
/* Set XT1_OUT(PF.2) and XT1_IN(PF.3) to input mode to prevent leakage */
/* Set XT1_OUT(PF.2) and XT1_IN(PF.3) to input mode to prevent leakage */
PF->MODE &= ~(GPIO_MODE_MODE2_Msk | GPIO_MODE_MODE3_Msk);
/* Disable digital input path of analog pin XT1_OUT to prevent leakage */
GPIO_DISABLE_DIGITAL_PATH(PF, BIT2 | BIT3);
/* Enable<EFBFBD><EFBFBD> HXT clock */
/* Enable£¬ HXT clock */
CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
/* Switch HCLK clock source to external */
CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HXT, CLK_CLKDIV0_HCLK(1)); //here switch zhe MCU clock to external
/*Set the core clock freq*/
CLK_SetCoreClock(FREQ_32MHZ); //set the core clock freq,should not higher than your HCLK clock freq
/*Set the core clock freq*/
CLK_SetCoreClock(FREQ_32MHZ); //set the core clock freq,should not higher than your HCLK clock freq
/* Enable UART module clock */
CLK_EnableModuleClock(UART0_MODULE);
@@ -59,37 +59,35 @@ void UART0_Init()
//task1 function
void task1_fun(void *Parameter)
{
while(1)
{
printf("Task1 <20><>Thansplant CORTEX-M23 Succeed\r\n");
PB14 =~ PB14;
tos_task_delay(1000);
}
while(1)
{
printf("Task1: Thansplant CORTEX-M23 Succeed\r\n");
PB14 =~ PB14;
tos_task_delay(1000);
}
}
void task2_task(void *Parameter)
{
k_err_t err;
while(1)
{
printf("Task2: hello world, hello Nuvoton \r\n");
tos_task_delay(100);
}
k_err_t err;
while(1)
{
printf("Task2: hello world, hello Nuvoton \r\n");
tos_task_delay(100);
}
}
int main()
{
k_err_t err;
/* Unlock protected registers */
k_err_t err;
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, peripheral clock and multi-function I/O */
SYS_Init();
tos_knl_init(); //tos init ,include SystickInit,should init after protected registers unlock
/* tos init ,include SystickInit,should init after protected registers unlock */
tos_knl_init();
/* Lock protected registers */
SYS_LockReg();
@@ -97,35 +95,32 @@ int main()
/* Init UART0 for printf */
UART0_Init();
printf("system clock to %d Hz, PLL clock to %d Hz...................... ", SystemCoreClock, CLK_SetCoreClock(FREQ_32MHZ));
printf("system clock to %d Hz, PLL clock to %d Hz...................... ", SystemCoreClock, CLK_SetCoreClock(FREQ_32MHZ));
GPIO_SetMode(PB, BIT14, GPIO_MODE_OUTPUT);
GPIO_SetMode(PB, BIT14, GPIO_MODE_OUTPUT);
err = tos_task_create(
&task1,
"Task1",
task1_fun,
NULL,
2,
task1_stack,
task1_size,
100
);
err = tos_task_create(
&task2,
"display",
task2_task,
NULL,
2,
task2_stack,
task2_size,
100);
if(err != K_ERR_NONE)
printf("TenentOS creat task fail! code is %d\r\n",err);
tos_knl_start(); //Start TOS TINY
err = tos_task_create(
&task1,
"Task1",
task1_fun,
NULL,
2,
task1_stack,
task1_size,
100);
err = tos_task_create(
&task2,
"display",
task2_task,
NULL,
2,
task2_stack,
task2_size,
100);
if(err != K_ERR_NONE)
printf("TencentOS create task fail! errcode is %d\r\n",err);
tos_knl_start(); //Start TOS TINY
}

View File

@@ -140,23 +140,18 @@ void Uart0DefaultMPF(void)
{
/* Set GPB multi-function pins for UART0 RXD and TXD */
SYS->GPA_MFPL = (SYS->GPA_MFPL & ~SYS_GPA_MFPL_PA0MFP_Msk) | SYS_GPA_MFPL_PA0MFP_UART0_RXD;
SYS->GPA_MFPL = (SYS->GPA_MFPL & ~SYS_GPA_MFPL_PA0MFP_Msk) | SYS_GPA_MFPL_PA0MFP_UART0_RXD;
SYS->GPA_MFPL = (SYS->GPA_MFPL & ~SYS_GPA_MFPL_PA1MFP_Msk) | SYS_GPA_MFPL_PA1MFP_UART0_TXD;
}
//systick interrupt Handler function
void SysTick_Handler(void)
{
if (tos_knl_is_running())
{
tos_knl_irq_enter();
tos_tick_handler();
tos_knl_irq_leave();
}
if (tos_knl_is_running())
{
tos_knl_irq_enter();
tos_tick_handler();
tos_knl_irq_leave();
}
}

View File

@@ -176,7 +176,7 @@ int main()
oled_size, //任务堆栈大小
100); //时间片轮转机制下当前任务的时间片大小。当timeslice为0时任务调度时间片会被设置为默认大小TOS_CFG_CPU_TICK_PER_SECOND / 10系统时钟滴答systick数 / 10。
if(err != K_ERR_NONE)
printf("TenentOS creat task fail! code is %d\r\n",err);
printf("TencentOS create task fail! code is %d\r\n",err);
tos_knl_start(); //Start TOS TINY
}
@@ -236,4 +236,4 @@ void SysTick_Handler(void)
![打印](https://img-blog.csdnimg.cn/20191025092727795.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMwMDc4NzUx,size_16,color_FFFFFF,t_70)
到这里TencentOS tiny 移植新塘M251 cortex-M23内核成功
到这里TencentOS tiny 移植新塘M251 cortex-M23内核成功