📄 ucos_dso.c
字号:
/******************************************************************************
* Copyright ? 2004 Altera Corporation, San Jose, California, USA. *
* All rights reserved. All use of this software and documentation is *
* subject to the License Agreement located at the end of this file below. *
*******************************************************************************
* This example demonstrates the use of the MicroC/OS-II Messagebox feature. *
* In addition it is to serve as a good starting point for designs using *
* uC/OS-II with NIOSII. MicroC/OS-II Message boxes are very simular to Message*
* Queues and Event Flags *
* *
* Three different tasks are setup to "Pend" on a different message. Once a *
* task receives the message it increments the contents and "Posts" the message*
* for the next task to receive and increment. *
* *
* See the Readme.txt for additional details on the design and the minimum *
* requirements for the design to function correctly *
* *
******************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include "includes.h"
#include "alt_ucosii_simple_error_check.h"
#include "sys/alt_irq.h"
#include "GUI.H"
#include "system.h"
#include "alt_types.h"
#include "altera_avalon_spi_regs.h"
#include "button.h"
#define PROGRAM_EXIT 0xff
#define DSO_RUN 0x01
#define LCD_DISP 0x02
#define RUN_SETUP_DIALOG 0xaa
#define KEY_F1 60
#define KEY_F2 61
#define KEY_F3 62
#define MSG_QUEUE_SIZE 20
typedef struct {
INT8U type; //Msg type
INT8U value; //Msg cost
}msg;
//messge flag
#define KEY_MSG 0x01
#define AD9288_MSG 0x02
#define FREQ_MSG 0x03
//dso
#define disWidth 160
#define disHight 112
#define XOFFSET 0
#define YOFFSET 16
/* Definition of Task Stacks */
#define TASK_STACKSIZE 2048
OS_STK initialize_task_stk[TASK_STACKSIZE];
OS_STK task1_stk[TASK_STACKSIZE];
OS_STK task2_stk[TASK_STACKSIZE];
OS_STK task3_stk[TASK_STACKSIZE];
OS_STK task4_stk[TASK_STACKSIZE];
/* Definition of Task Prioities */
#define INITIALIZE_TASK_PRIORITY 6
#define TASK1_PRIORITY 7
#define TASK2_PRIORITY 8
#define TASK3_PRIORITY 9
#define TASK4_PRIORITY 10
/* Definition of Three Message Boxes*/
OS_EVENT *mailbox1;
OS_EVENT *mailbox2;
OS_EVENT *mailbox3;
OS_EVENT *mailbox4;
OS_EVENT *setup_dialog_mailbox;
//OS_EVENT *Fifo; // Message queue pointer
//msg FifoTbl[ MSG_QUEUE_SIZE]; // Storage for messages
INT8U xy[4][2];
GUI_RECT button_rect[3];
/* Local Function Prototypes */
int initOSDataStructs(void);
int initCreateTasks(void);
void task1(void* pdata);
/* The next three tasks Pend for a message in a mailbox. Once the message is
* received, the task increments the message and then deposits the message in
* a different message box for the next task to receive. Task 3 is slightly
* different in that there is a delay inserted. The delay is only for the
* purpose of proper message display on the terminal.
*/
extern GUI_BITMAP bmrun;
extern GUI_BITMAP bmplay;
extern GUI_BITMAP bmsetup;
extern GUI_BITMAP bmhelp;
extern GUI_BITMAP bmarrow;
extern GUI_BITMAP bmenter;
extern GUI_BITMAP bmarrw;
extern void Display_LCD();
static GUI_BITMAP * MyBmp[] = {
&bmrun,
&bmplay,
&bmsetup,
&bmhelp
};
static GUI_BITMAP * DSOBmp[] = {
&bmarrow,
&bmenter,
&bmenter,
};
const unsigned char str[5][20]={{0x20,0xca,0xbe,0xb2,0xa8,0xc6,0xf7,0x20},
{0x20,0xca,0xfd,0xbe,0xdd,0xb7,0xd6,0xce,0xf6,0x20},
{0x20,0xcf,0xb5,0xcd,0xb3,0xc9,0xe8,0xd6,0xc3,0x20},
{0xb0,0xef,0xd6,0xfa,0x20},
{0xca,0xd6,0xb3,0xd6,0xca,0xbe,0xb2,0xa8,0xb1,0xed,0x20}
};
/*const unsigned char button_name[3][5]={{0xd2,0xc6,0xb6,0xaf,0x20},
{0xc9,0xe8,0xd6,0xc3,0x20},{0xb9,0xe2,0xb1,0xea,0x20}
};*/
const char * button_name[]={"Move","Setup","CURSOR"};
const char * button_key_name[]={"F1","F2","F3"};
//Draw main desktop
void DrawDeskTop(void)
{
INT8U i,j,h,n;
GUI_RECT rect;
GUI_Clear();
GUI_SetColor(GUI_BLACK);
GUI_SetBkColor(GUI_WHITE);
h=75;
n=0;
GUI_SetTextMode(GUI_TEXTMODE_NORMAL);
GUI_DrawRect(0,0,159,158);
GUI_SetFont(&GUI_FontHZ12);
rect.x0=0;rect.y0=0;
rect.x1=160;rect.y1=14;
GUI_FillRectEx(&rect);
GUI_SetTextMode(GUI_TEXTMODE_REV);
GUI_DispStringInRect(str[4],&rect,GUI_TA_CENTER|GUI_TA_VCENTER);
GUI_SetTextMode(GUI_TEXTMODE_NORMAL);
for(i=0;i<2;i++)
for(j=0;j<2;j++)
{
GUI_DrawBitmap(MyBmp[n], j*h+(h-32)/2,i*h+(h-32)/2);
// GUI_DispStringAt(str[n],j*h+(h-32)/2-12,i*h+(h-32)/2+34);
xy[n][0]=j*h;
xy[n][1]=i*h+(h-32)/2+34;
n++;
}
}
void Draw_Gridding(int xofst,int yofst,int site)
{
unsigned int h_st,v_st,i,j;
v_st=disWidth/10;
h_st=disHight/8;
GUI_ClearRect (xofst, yofst,xofst+disWidth,yofst+disHight);
for(i=0;i<9;i++)
{ //draw ____line .
for(j=0;j<disWidth;j+=4)
GUI_DrawPoint(j+xofst,h_st*i+yofst);
}
// for(j=0;j<disWidth;j+=4)
// SetPixel(j+xofst,h_st*8-1+yofst,1);
for(i=0;i<10;i++)
{
//draw | line .
for(j=0;j<disHight;j+=4)
GUI_DrawPoint(i*v_st+xofst,j+yofst);
}
for(j=0;j<=disHight;j+=3)
GUI_DrawPoint(10*v_st-1+xofst,j+yofst);
GUI_DrawBitmap(&bmarrw,1,yofst+site-3);
}
void DrawDSOdeskTop(int site)
{ INT8U i,j;
GUI_RECT rect;
GUI_Clear();
GUI_SetColor(GUI_BLACK);
GUI_SetBkColor(GUI_WHITE);
//draw dso
GUI_SetTextMode(GUI_TEXTMODE_NORMAL);
GUI_SetFont(&GUI_Font6x8);
GUI_DispCharAt('A',2,1);
GUI_DrawRect(0,0,8,8);
rect.x0=8;
rect.y0=2;
rect.x1=rect.x0+5*10+2;
rect.y1=2+16;
GUI_SetFont(&GUI_Font8x16);
GUI_DispStringInRect("224.5",&rect,GUI_TA_CENTER);
GUI_SetFont(&GUI_Font6x8);
GUI_DispStringAt("rms",rect.x1+2,0);
GUI_DispStringAt("V~",rect.x1+2,8);
GUI_SetFont(&GUI_Font8x16);
rect.x0=rect.x1+3*7+10 ;rect.y0=2;
rect.x1=rect.x0+5*8;rect.y1=2+16;
GUI_DispStringInRect("999.9",&rect,GUI_TA_CENTER);
GUI_SetFont(&GUI_Font6x8);
GUI_DispStringAt("Hz",rect.x1+2,8);
Draw_Gridding(XOFFSET,YOFFSET,site);
//GUI_SetFont(&GUI_Font4x6);
GUI_DispStringAt("100mV/d 10mS/d Trig:A ",0,YOFFSET+disHight+2);
j=159/3;
for(i=0;i<3;i++)
{ button_rect[i].x0=i*j;button_rect[i].y0=YOFFSET+disHight+10;
button_rect[i].x1=i*j+j;button_rect[i].y1=158;
GUI_DrawRectEx(&button_rect[i]);
}
}
void task3(void *pdata)
{
INT8U mbox_contents;
INT8U return_code = OS_NO_ERR;
while(1)
{ mbox_contents = (INT8U )OSMboxPend(mailbox4, 0, &return_code);
if(mbox_contents==LCD_DISP);
Display_LCD() ;
}
}
void DrawSetupDialog(INT8U select,INT8U sel1,INT8U sel2)
{ GUI_RECT rect,rcTemp;
rect.x0=20;
rect.y0=30;
rect.x1=145;
rect.y1=95;
GUI_SetColor(GUI_BLACK);
GUI_SetBkColor(GUI_WHITE);
GUI_SetTextMode(GUI_TEXTMODE_NORMAL);
GUI_SetFont(&GUI_Font6x8);
GUI_ClearRect(rect.x0,rect.y0,rect.x1,rect.y1);
GUI_DrawRectEx(&rect);
//GUI_SetFont(&GUI_Font6x8);
rcTemp.x0=rect.x0+1;rcTemp.y0=rect.y0+1;
rcTemp.x1=rect.x1-1;rcTemp.y1=rcTemp.y0+8;
GUI_DispStringInRect("A/D module setup",&rcTemp,GUI_TA_LEFT);
GUI_InvertRect(rcTemp.x0,rcTemp.y0,rcTemp.x1,rcTemp.y1);
GUI_DrawRect(rect.x0+3,rect.y0+15,rect.x0+62,rect.y0+48);
GUI_DispStringAt("F1=OK",rect.x0+4,rect.y0+54);
GUI_DispStringAt("F3=Cancel",rect.x0+69,rect.y0+54);
GUI_ClearRect(rect.x0+1,rect.y0+9,rect.x1-1,rect.y0-53);
GUI_DrawRect(rect.x0+3,rect.y0+15,rect.x0+62,rect.y0+48);
GUI_ClearRect(rect.x0+17,rect.y0+12,rect.x0+17+36,rect.y0+12+8);
GUI_DispStringAt("Select",rect.x0+17,rect.y0+12);
if(sel1)
{GUI_FillRect(rect.x0+9,rect.y0+24,rect.x0+17,rect.y0+31);
GUI_DrawRect(rect.x0+9,rect.y0+37,rect.x0+17,rect.y0+44);
}
else
{GUI_DrawRect(rect.x0+9,rect.y0+24,rect.x0+17,rect.y0+31);
GUI_FillRect(rect.x0+9,rect.y0+37,rect.x0+17,rect.y0+44);
}
GUI_DispStringAt("Signal",rect.x0+24,rect.y0+24);
GUI_DispStringAt("Gnd",rect.x0+24,rect.y0+37);
GUI_DrawRect(rect.x0+70,rect.y0+15,rect.x0+121,rect.y0+48);
GUI_ClearRect(rect.x0+80,rect.y0+12,rect.x0+80+30,rect.y0+12+8);
GUI_DispStringAt("AC/DC",rect.x0+80,rect.y0+12);
if(sel2){
GUI_FillRect(rect.x0+76,rect.y0+24,rect.x0+84,rect.y0+31);
GUI_DrawRect(rect.x0+76,rect.y0+37,rect.x0+84,rect.y0+44);
}else{
GUI_DrawRect(rect.x0+76,rect.y0+24,rect.x0+84,rect.y0+31);
GUI_FillRect(rect.x0+76,rect.y0+37,rect.x0+84,rect.y0+44);
}
GUI_DispStringAt("AC",rect.x0+92,rect.y0+24);
GUI_DispStringAt("DC",rect.x0+92,rect.y0+37);
switch(select)
{case 0:
rcTemp.x0=rect.x0+22;rcTemp.y0=rect.y0+22;
rcTemp.x1=rect.x0+58;rcTemp.y1=rect.y0+33;
break;
case 2:
rcTemp.x0=rect.x0+22;rcTemp.y0=rect.y0+35;
rcTemp.x1=rect.x0+45;rcTemp.y1=rect.y0+46;
break;
case 1:
rcTemp.x0=rect.x0+88;rcTemp.y0=rect.y0+22;
rcTemp.x1=rect.x0+112;rcTemp.y1=rect.y0+33;
break;
case 3:
rcTemp.x0=rect.x0+88;rcTemp.y0=rect.y0+35;
rcTemp.x1=rect.x0+112;rcTemp.y1=rect.y0+46;
break;
}
GUI_SetLineStyle(GUI_LS_DOT);
GUI_DrawRectEx(&rcTemp);
GUI_SetLineStyle(GUI_LS_SOLID);
}
void task4(void * pdata)
{
INT8U key,sel1,sel2;
INT8U return_code = OS_NO_ERR;
INT8S select;
// msg * in;
sel1=1;sel2=1;
select=0;
while( (key = (INT8U )OSMboxPend(setup_dialog_mailbox, 0,&return_code))
!=RUN_SETUP_DIALOG);
while(1){
DrawSetupDialog(select,sel1,sel2);
OSMboxPost(mailbox4,(void*)LCD_DISP);
key = (INT8U )OSMboxPend(mailbox1, 0, &return_code);
// in=(msg * ) OSMboxPend(mailbox1, 0, &return_code);
// in=(msg *)OSQPend(Fifo, 0, return_code);
alt_ucosii_check_return_code(return_code);
// if(in->type==KEY_MSG)
{
// switch(in->value)
switch(key)
{
case KEY_F1:
//Save value
OSMboxPost(mailbox3,(void*)DSO_RUN); /* Post to Mailbox2 */
while( key = (INT8U )OSMboxPend(setup_dialog_mailbox, 0, &return_code)!=RUN_SETUP_DIALOG);
break;
case KEY_F2:
break;
case KEY_F3:
// not save value
OSMboxPost(mailbox3,(void*)DSO_RUN); /* Post to Mailbox2 */
while( key = (INT8U )OSMboxPend(setup_dialog_mailbox, 0, &return_code)!=RUN_SETUP_DIALOG);
break;
case GUI_KEY_LEFT:
select--;
if(select<0)
select=0;
break;
case GUI_KEY_RIGHT:
select++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -