2245 views|8 replies

305

Posts

0

Resources
The OP
 

[New version of Zhongke Bluexun AB32VG1 RISC-V development board] - 4: Threaded version of Blink [Copy link]

 This post was last edited by MianQi on 2021-8-12 13:37

The entire program is functionally divided into several parts in logical order:

1. Declaration, definition and instantiation of pin-related classes

2. Define the pins

3. Define the driver for the pin

4. Define the main (entry) function of the thread

5. Define the thread initialization (start) function

6. Call the function that starts the thread

7. Modify the entry function of the project (main.c)

First of all, we should point out that ( Part 2. GPIO Practice on Zhongke Bluexun AB32VG1 - https://docs.qq.com/doc/DTVVWWXpLRVl6cER2?_t=1626260921919) is inconsistent with the actual test results:

pin2 3.3v

pin1 R20 (470Ω) PA1

pin3 R17 (1kΩ) PE4

pin4 R18 (470Ω) PE1

This post is from Domestic Chip Exchange

Latest reply

Haha, compilation, awesome.   Details Published on 2021-8-18 17:48
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 

305

Posts

0

Resources
2
 
This post was last edited by MianQi on 2021-8-12 13:49

There are only three files that have been modified since the creation of the entire project:

1. Added two files "LED.c" and "LED.h" in the "applications" directory.

2. Made changes to "main.c" in the "applications" directory.

Among them, "LED.h" actually has empty valid content:

/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-08-11     MQ       the first version
 */

The contents of "main.c" are nearly empty:

/*
 * Copyright (c) 2020-2021, Bluetrum Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020/12/10     greedyhao    The first version
 */

/**
 * Notice!
 * All functions or data that are called during an interrupt need to be in RAM.
 * You can do it the way exception_isr() does.
 */

#include <rtthread.h>
#include "board.h"

int main(void)
{
/*
    uint8_t pin = rt_pin_get("PE.1");

    rt_pin_mode(pin, PIN_MODE_OUTPUT);
    rt_kprintf("Hello, world\n");
*/

    while (1)
    {
/*
        rt_pin_write(pin, PIN_LOW);
        rt_thread_mdelay(500);
        rt_pin_write(pin, PIN_HIGH);
        rt_thread_mdelay(500);
        */
    }
}

This post is from Domestic Chip Exchange
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 
 

305

Posts

0

Resources
3
 

Almost all the useful content is in "LED.c":

#include "LED.h"
#include <rtthread.h>
#include "board.h"

//定义一个结构体类型
struct LED_RGB
{
    uint8_t LED_R;
    uint8_t LED_G;
    uint8_t LED_B;
};

//实例化一个结构体对象
struct LED_RGB led_rgb;


//结构体对象的初始化
void LED_RGB_Init(void){

    //将结构体对象的成员对应到管脚
    led_rgb.LED_R = rt_pin_get("PE.1");
    led_rgb.LED_G = rt_pin_get("PE.4");
    led_rgb.LED_B = rt_pin_get("PA.1");

    //设置结构体对象的成员管脚的输出方式
    rt_pin_mode(led_rgb.LED_R, PIN_MODE_OUTPUT);
    rt_pin_mode(led_rgb.LED_G, PIN_MODE_OUTPUT);
    rt_pin_mode(led_rgb.LED_B, PIN_MODE_OUTPUT);
}

//RGB三色LED各自的驱动程序
//if(toggle==1) LED亮
//if(toggle==0) LED灭

void RGB_Red(rt_bool_t toggle){
    rt_pin_write(led_rgb.LED_G, PIN_HIGH);
    rt_pin_write(led_rgb.LED_B, PIN_HIGH);

    if(toggle){
        rt_pin_write(led_rgb.LED_R, PIN_LOW);
    } else{
        rt_pin_write(led_rgb.LED_R, PIN_HIGH);
    }
}

void RGB_Green(rt_bool_t toggle){
    rt_pin_write(led_rgb.LED_R, PIN_HIGH);
    rt_pin_write(led_rgb.LED_B, PIN_HIGH);

    if(toggle){
        rt_pin_write(led_rgb.LED_G, PIN_LOW);
    } else{
        rt_pin_write(led_rgb.LED_G, PIN_HIGH);
    }
}

void RGB_Blue(rt_bool_t toggle){
    rt_pin_write(led_rgb.LED_R, PIN_HIGH);
    rt_pin_write(led_rgb.LED_G, PIN_HIGH);

    if(toggle){
        rt_pin_write(led_rgb.LED_B, PIN_LOW);
    } else{
        rt_pin_write(led_rgb.LED_B, PIN_HIGH);
    }
}

//编写线程入口函数(主程序文件)
static void led_rgb_thread_entry(void* p){
    LED_RGB_Init();

    while(1){
        RGB_Red(1);
        rt_thread_mdelay(1000);
        RGB_Red(0);
        rt_thread_mdelay(1000);
        RGB_Red(1);
        rt_thread_mdelay(1000);
        RGB_Red(0);
        rt_thread_mdelay(1000);

        RGB_Green(1);
        rt_thread_mdelay(1000);
        RGB_Green(0);
        rt_thread_mdelay(1000);
        RGB_Green(1);
        rt_thread_mdelay(1000);
        RGB_Green(0);
        rt_thread_mdelay(1000);

        RGB_Blue(1);
        rt_thread_mdelay(1000);
        RGB_Blue(0);
        rt_thread_mdelay(1000);
        RGB_Blue(1);
        rt_thread_mdelay(1000);
        RGB_Blue(0);
        rt_thread_mdelay(1000);
    }
}

//创建线程启动函数,用于启动此前创建的线程主体
static int Thread_led_rgb(void){
    rt_thread_t thread = RT_NULL;
    thread = rt_thread_create("led_rgb", led_rgb_thread_entry, RT_NULL, 512, 10, 10);

    if(thread == RT_NULL){
        rt_kprintf("Thread_led_rgb initiate ERROR");
        return RT_ERROR;
    }

    rt_thread_startup(thread);
}

//将线程的初始化加入系统初始化,启动线程
INIT_APP_EXPORT(Thread_led_rgb);

This post is from Domestic Chip Exchange
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 
 

305

Posts

0

Resources
4
 

Demonstration effect:


This post is from Domestic Chip Exchange
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 
 

2w

Posts

74

Resources
5
 

Clear and organized, thanks for sharing.

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
Personal signature

加油!在电子行业默默贡献自己的力量!:)

 
 
 

7422

Posts

2

Resources
6
 

The while(1) can be optimized. It is so uncomfortable to read.

This post is from Domestic Chip Exchange

Comments

I want to continue the assembly style - the main thread is left empty and the tasks are completed in blocks.  Details Published on 2021-8-18 10:31
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

305

Posts

0

Resources
7
 
freebsder posted on 2021-8-17 20:37 while(1) can be optimized. This is so uncomfortable to read. . .

I want to continue the assembly style - the main thread is left empty and the tasks are completed in blocks.

This post is from Domestic Chip Exchange

Comments

Haha, compilation, awesome.  Details Published on 2021-8-18 17:48
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 
 

7422

Posts

2

Resources
8
 
MianQi posted on 2021-8-18 10:31 I want to continue the assembly style - the main thread is left empty, and the tasks are completed in blocks.

Haha, compilation, awesome.

This post is from Domestic Chip Exchange
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

305

Posts

0

Resources
9
 

I wanted to try assembly on Qinheng's board before, but the information was incomplete. This time, I saw that Bluexun's board still did not provide instruction sets and register addresses.

This post is from Domestic Chip Exchange
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list