NIOS2 essay--ucos-ii Real-time operating system

Source: Internet
Author: User

1. Overview

This design uses NIOS2 32-bit processor, realizes the use of Ucos-ii real-time operating system, realizes two tasks running simultaneously, one led flashes, one serial port prints. The hardware platform uses the Etree Development Board (a treasure provided) as shown in:

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/A6/8D/wKioL1nS7XvzbilaAADr3SzO-vA834.jpg-wh_500x0-wm_ 3-wmp_4-s_4288452506.jpg "title=" f01.jpg "width=" "height=" 323 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width : 400px;height:323px; "alt=" Wkiol1ns7xvzbilaaadr3szo-va834.jpg-wh_50 "/>

2. Ucos-ii Introduction

Μc/os and μc/Os are specifically designed for computer embedded applications, and most of the code is written in C.

The UC/OS-II can support up to 64 tasks, each corresponding to the priority 0~63, where 0 is the highest priority. The system retains 4 highest-priority tasks and 4 lowest-priority tasks, with 56 tasks available to all users.

UC/OS-II provides a variety of function calls for task management, including creating tasks, deleting tasks, changing the priority of tasks, suspending and resuming tasks, and so on.

For the uc/os-ii to function properly, the processor must meet the following requirements:

    • The C compiler of the processor can generate reentrant code;

    • The processor supports interrupts and can generate timer interrupts;

    • C language can be switched on/off interrupt;

    • The processor has a certain number of data memory;

    • The processor has instructions to read the contents of the stack pointer and other CPU registers, and store them in the stack or in memory.

Obviously the NIOS2 processor meets the above requirements, from the processor hardware point of view the NIOS2 requires a certain amount of memory space (SDRAM space is large enough), a timer (add Timer component) is required.

3. Qsys Platform Construction

Add the interval Timer component on the Qsys platform and configure the relevant parameters as shown in.

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/07/DC/wKiom1nS7syyOzRjAACB0GUPRxQ001.jpg-wh_500x0-wm_ 3-wmp_4-s_3402366564.jpg "title=" f01_timer.jpg "alt=" Wkiom1ns7syyozrjaacb0guprxq001.jpg-wh_50 "/>

finished adding Timer component's Qsys The system looks like this.

650) this.width=650; "src=" https://s3.51cto.com/wyfs02/M02/07/DC/wKiom1nS7yHhDC4FAAD5RVbGNuY808.jpg "title=" f01_ Timer_qss.jpg "alt=" Wkiom1ns7yhhdc4faad5rvbgnuy808.jpg "/>

4. NIOS2 Software Design

Create a new Nios SBT project, enter the software engineering name ' Nios2_ucos ' and select ' Hello-microc/os-ii ' in project template as shown in.

650) this.width=650; "src=" https://s3.51cto.com/wyfs02/M00/A6/8D/wKioL1nS71njytQ0AAEVDmO85AA375.jpg "title=" f01_ Ucos.jpg "alt=" Wkiol1ns71njytq0aaevdmo85aa375.jpg "/>

software design two tasks, one task to make the LED flash every second, another task every second in the serial terminal printing "Hello from task2\n", the specific code is as follows:

#include  <stdio.h> #include   "includes.h" #include  <io.h> #include  <system.h >/* definition of task stacks */#define    TASK_STACKSIZE        2048OS_STK    task1_stk[TASK_STACKSIZE];OS_STK     task2_stk[task_stacksize];/* definition of task priorities */# define task1_priority      1#define task2_priority       2/* Prints  "Hello world"  and sleeps for three  Seconds */void task1 (Void* pdata) {  while  (1)   {    &NBSP;&NBSP;&NBSP;&NBSP;IOWR (pio_0_base,0,1);         //led  ON&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;OSTIMEDLYHMSM (0, 0, 0, 500);   //hour/minute/ Second/millisecond   &nbsP;&NBSP;&NBSP;IOWR (pio_0_base,0,0);         //led off  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;OSTIMEDLYHMSM (0, 0, 0, 500);   //hour/minute/second/ millisecond  }}/* prints  "Hello world"  and sleeps for three  Seconds */void task2 (Void* pdata) {  while  (1)   {      printf ("hello from task2\n");     ostimedlyhmsm (0, 0, 1,  0);  }}/* the main function creates two task and  Starts multi-tasking */int main (void) {    ostaskcreateext (task1,                   null,                    ( void *) &task1_stk[task_stacksize-1],                   TASK1_PRIORITY,                   TASK1_PRIORITY,                   task1_stk,                   TASK_STACKSIZE,                   NULL,                   0);                  ostaskcreateext (Task2,                    null,                   (void *) &task2_stk[TASK_STACKSIZE-1] ,                   task2_priority,                   TASK2_PRIORITY,                   task2_stk,                   TASK_STACKSIZE,                   NULL,                   0);   osstart ();   return 0;}

5. Compile and run the

Right-click the project Nios2_ucos and select Build Project. After compiling, download the FPGA configuration file, then right-click on the project Nios2_ucos and select Run as | Nios II Hardware. The FPGA Development Board LEDs Flash every second, and the Nios II console prints "Hello from Task2" every second.

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/07/DC/wKiom1nS8H6Sa_AuAAByeZHymrw510.jpg-wh_500x0-wm_ 3-wmp_4-s_2163378071.jpg "title=" f01_ucos.jpg "alt=" Wkiom1ns8h6sa_auaabyezhymrw510.jpg-wh_50 "/>



This article is from the "Shugenyin blog" blog, make sure to keep this source http://shugenyin.blog.51cto.com/4259554/1970272

NIOS2 essay--ucos-ii Real-time operating system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.