📄 main.c
字号:
/*********************************************************************************************
* File: main.c
* Author: embest
* Desc: c main entry
* History:
*********************************************************************************************/
#include "includes.h" // uC/OS interface
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "lcd.h"
/*------------------------------------------------------------------------------------------*/
/* global variables */
/*------------------------------------------------------------------------------------------*/
#define STACKSIZE 512 //Task definition
/*------------------------------------------------------------------------------------------*/
/* extern variables */
/*------------------------------------------------------------------------------------------*/
extern const UINT8T g_ucBitmap[][76800];
/*------------------------------------------------------------------------------------------*/
/* global variables */
/*------------------------------------------------------------------------------------------*/
unsigned int Stack1[STACKSIZE];
unsigned int Stack2[STACKSIZE];
unsigned int Stack3[STACKSIZE];
unsigned int StackMain[STACKSIZE];
OS_EVENT* f_UartSem;
unsigned char f_ucErr;
char f_szDigital[10] ={0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6};
/*------------------------------------------------------------------------------------------*/
/* extern function */
/*------------------------------------------------------------------------------------------*/
extern void TickHandler(void);
/*------------------------------------------------------------------------------------------*/
/* function declare */
/*------------------------------------------------------------------------------------------*/
void target_init(void);
void target_start(void);
/*********************************************************************************************
* name: task1
* func: led on/off task
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void task1(void *Id)
{
// print task's id
OSSemPend(f_UartSem, 0, &f_ucErr);
uart_printf("Task%c Called.\n", *(char *)Id);
OSSemPost(f_UartSem);
while(1)
{
led1_on();
led2_on();
OSTimeDly(100);
led1_off();
led2_off();
OSTimeDly(100);
}
}
/*********************************************************************************************
* name: task2
* func: led8 display task
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void task2 (void *Id)
{
int i, j, k;
// print task's id
OSSemPend(f_UartSem, 0, &f_ucErr);
uart_printf("Task%c Called.\n", *(char *)Id);
OSSemPost(f_UartSem);
while(1)
{
for(j=0; j<10; j++)
{
for(i=0; i<8; i++)
{
k = 9-(i+j)%10;
iic_write(0x70, 0x10+i, f_szDigital[k]);
}
OSTimeDly(200);
}
}
}
/*********************************************************************************************
* name: task3
* func: led on/off task
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void task3 (void *Id)
{
int i;
// print task's id
OSSemPend(f_UartSem, 0, &f_ucErr);
uart_printf("Task%c Called.\n", *(char *)Id);
OSSemPost(f_UartSem);
i = 0;
while(1)
{
bitmap_view320x240x256((UINT8T*)(g_ucBitmap[i]));
OSTimeDly(800);
i++;
if(i>4) i=0;
}
}
/*********************************************************************************************
* name: TaskStart
* func:
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void TaskStart (void *i)
{
char Id1 = '1';
char Id2 = '2';
char Id3 = '3';
/*
* create the first Semaphore in the pipeline with 1
* to get the task started.
*/
f_UartSem = OSSemCreate(1);
/*
* create the tasks in uC/OS and assign decreasing
* priority to them
*/
OSTaskCreate(task1, (void *)&Id1, &Stack1[STACKSIZE - 1], 2);
OSTaskCreate(task2, (void *)&Id2, &Stack2[STACKSIZE - 1], 3);
OSTaskCreate(task3, (void *)&Id3, &Stack3[STACKSIZE - 1], 4);
target_start();
OSTaskDel(OS_PRIO_SELF);// Delete current task
}
/*********************************************************************************************
* name: main
* func: c code entry
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void Main(void)//int argc, char **argv
{
char Id0 = '4';
target_init();
/* needed by uC/OS */
OSInit();
OSTimeSet(0);
/* create the start task */
OSTaskCreate(TaskStart, (void *)0, &StackMain[STACKSIZE - 1], 0);
/* start the operating system */
OSStart();
}
/*********************************************************************************************
* name: target_init
* func: Initialize an ARM Target board
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void target_init(void)
{
sys_init(); // Initial 44B0X's Interrupt,Port and UART
uart_printf("\n*==================================*\n");
uart_printf("*= 深圳市英蓓特信息技术有限公司 =*\n");
uart_printf("*==================================*\n");
uart_printf("*========== 产品研发中心 ==========*\n");
uart_printf("*======= 86-755-25631365 ========*\n");
uart_printf("*===== support@embedinfo.com ======*\n");
uart_printf("*=== OS Version:%d ===*\n",OSVersion());
uart_printf("\n*==================================*\n");
uart_printf(" uCOS-II Running... \n") ;
uhal_init_interrupts();
uhal_init_timers();
} /* targetInit */
/*********************************************************************************************
* name: target_start
* func: start the ARM target running
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void target_start(void)
{
uhal_register_irq(HandlerTIMER0, (void *)TickHandler);
uhal_enable_int(BIT_TIMER0 | BIT_IIC);
iic_init();
lcd_init();
}
void Timer0Interrupt()
{
rI_ISPC = BIT_TIMER0;
OSTimeTick();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -