📄 main.c
字号:
/*
** Copyright (C) 2006 Tamir Michael
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <XC167.h>
#include "general_definitions.h"
#include "rtos_services.h"
#include "system_messages.h"
#include "synchronization.h"
#include "queue.h"
#include "stdio.h"
#include "usb.h"
#include "priority_queue.h"
#include "trace_buffer.h"
static stacktype task1_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task2_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task3_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task4_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task5_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task6_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task7_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task8_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static int16s m1, m2, m3, t1id, t2id, t3id, t4id, t5id, t6id, t7id, t8id, t9id, t10id, s1 ;
static int16s t1, t2, t3, t4, t5 ;
static int16s rxMsg = 0, txMsg = 0 ;
void ISR0x25callback()
{
printf("ISR0x25callback\n") ;
}
void timer1(int32s param)
{
param = 0 ;
//P6 = ( ((P6 & 1) == 1) ? (P6 & 0xFFFE) : (P6 | 1) ) ;
//scheduler_set_task_priority(t1id, PRIORITY_0) ;
}
void timer2(int32s param)
{
param = 0 ;
}
void s_system_failure_callback(int32s p)
{
p ;
trace_buffer_flush() ;
}
static void s_idle_hook(int32s p)
{
p ;
}
void task8()
{
while (1)
{
if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
{
printf("task8\n") ;
//scheduler_task_wait( MILLISECONDS(1)) ;
// scheduler_task_wait( MILLISECONDS(100)) ;
rtos_mutex_unlock(m1) ;
}
}
}
void task7()
{
while (1)
{
if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
{
printf("task7\n") ;
//scheduler_task_wait( MILLISECONDS(1)) ;
// scheduler_task_wait( MILLISECONDS(100)) ;
rtos_mutex_unlock(m1) ;
}
}
}
void task6()
{
while (1)
{
if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
{
//printf("task6\n") ;
//scheduler_task_wait( MILLISECONDS(1)) ;
// scheduler_task_wait( MILLISECONDS(100)) ;
// rtos_mutex_unlock(m2) ;
printf("task6\n") ;
rtos_mutex_unlock(m1) ;
}
}
}
void task5()
{
while (1)
{
if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
{
//printf("task5\n") ;
//scheduler_task_wait( MILLISECONDS(1)) ;
// scheduler_task_wait( MILLISECONDS(100)) ;
// rtos_mutex_unlock(m2) ;
printf("task5\n") ;
rtos_mutex_unlock(m1) ;
}
}
}
void task4()
{
scheduler_unregister_idle_hook() ;
while (1)
{
if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
{
printf("task4\n") ;
// scheduler_task_wait( MILLISECONDS(100)) ;
// rtos_mutex_unlock(m2) ;
//printf("task4\n") ;
rtos_mutex_unlock(m1) ;
}
}
}
void task3()
{
//int l_count = 0 ;
if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
{
printf("task3 initialized\n") ;
rtos_mutex_unlock(m1) ;
}
while (1)
{
if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
{
//int32s msg ;
printf("task3\n") ;
//rtos_msg_wait(&msg, SECONDS(100)) ;
rtos_mutex_unlock(m1) ;
}
//rtos_disable_scheduler() ;
//rtos_interrupt_wait(0x25, ISR0x25callback, 0) ;
scheduler_task_wait(MILLISECONDS(5)) ;
}
}
void task2()
{
//static int32s msg = 1975 ;
//rtos_take_task_snapshot() ;
if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
{
printf("task2 initialized\n") ;
rtos_mutex_unlock(m1) ;
}
while (1)
{
if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
{
printf("task2\n") ;
//scheduler_task_wait(SECONDS(1)) ;
rtos_mutex_unlock(m1) ;
}
//rtos_interrupt_wait(0x11, ISR0x25callback, 0) ;
//rtos_msg_wait(&msg, HOURS(1) ) ;
//scheduler_task_suspend(t2id) ;
//scheduler_task_wait(SECONDS(1)) ;
//rtos_msg_wait(&msg, MINUTES(10)) ;
}
}
void task1()
{
//int32s msg = 0 ;
//t1 = rtos_allocate_timer() ;
//scheduler_task_wait(MILLISECONDS(250)) ;
//rtos_restore_task_snapshot() ;
int counter = 0 ;
if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
{
printf("task1 initialized\n") ;
rtos_mutex_unlock(m1) ;
}
while (1)
{
if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
{
printf("task1\n") ;
//scheduler_task_wait(SECONDS(3)) ;
rtos_mutex_unlock(m1) ;
}
if ( (++counter) == 50)
{
scheduler_set_task_priority(t3id, PRIORITY_2) ;
counter = 0 ;
//rtos_post_task_msg(t3id, 1975) ;
}
if ( (counter) == 25)
{
scheduler_set_task_priority(t3id, PRIORITY_7) ;
}
/*if (counter == 220)
{
rtos_enable_scheduler() ;
} */
//rtos_interrupt_wait(0x25, ISR0x25callback, 0) ;
//rtos_msg_wait(&msg, HOURS(1) ) ;
//scheduler_task_suspend(t2id) ;
//scheduler_task_wait(SECONDS(1)) ;
//rtos_msg_wait(&msg, MILLISECONDS(10)) ;
}
}
void main()
{
/*unsigned int x = 0 ;
priority_queue_info l_queue ;
rtos_init(s_system_failure_callback) ;
priority_queue_init(&l_queue) ;
priority_queue_insert(&l_queue, 6, 3) ;
priority_queue_insert(&l_queue, 5, 99) ;
priority_queue_insert(&l_queue, 4, 321) ;
priority_queue_insert(&l_queue, 3, 1975) ;
priority_queue_insert(&l_queue, 2, 19) ;
priority_queue_insert(&l_queue, 1, 846) ;
while (x++ < 6)
{
printf("minimum key=%d\n", priority_queue_minimum_key(&l_queue) ) ;
printf("minimum data=%d\n", priority_queue_minimum_data(&l_queue) ) ;
printf("extract minimum=%d\n", priority_queue_minimum_data_extract(&l_queue) ) ;
}
while (1) ;*/
rtos_init(s_system_failure_callback) ;
scheduler_register_idle_hook(s_idle_hook, 1975) ;
t1id = scheduler_create_task(task1, PRIORITY_1, task1_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
t2id = scheduler_create_task(task2, DEFAULT_TASK_PRIORITY, task2_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
t3id = scheduler_create_task(task3, DEFAULT_TASK_PRIORITY, task3_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
t4id = scheduler_create_task(task4, DEFAULT_TASK_PRIORITY, task4_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
/*t5id = scheduler_create_task(task5, DEFAULT_TASK_PRIORITY, task5_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
t6id = scheduler_create_task(task6, DEFAULT_TASK_PRIORITY, task6_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
t7id = scheduler_create_task(task7, DEFAULT_TASK_PRIORITY, task7_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
t8id = scheduler_create_task(task8, DEFAULT_TASK_PRIORITY, task8_stack, DEFUALT_STACK_SIZE, eTaskReady) ;*/
// //t9id = scheduler_create_task(task9, DEFAULT_TASK_PRIORITY, task9_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
//t10id = scheduler_create_task(task10, DEFAULT_TASK_PRIORITY, task10_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
DP6 = 0xFF ;
P6 = 0 ;
GPT12E_T5CON = 0x0007; // load timer 5 control register
GPT12E_T5 = 0x676A; // load timer 5 register
GPT12E_T5IC = IC_IE(1) | IC_ILVL(2) | IC_GLVL(5) ;
GPT12E_T5IC_IR = 0; // timer 5 run bit is set
m1 = rtos_allocate_mutex() ;
m2 = rtos_allocate_mutex() ;
//s1 = rtos_allocate_semaphore(2) ;
t1 = rtos_allocate_timer() ;
//t2 = rtos_allocate_timer() ;
//t3 = rtos_allocate_timer() ;
//t4 = rtos_allocate_timer() ;
//t5 = rtos_allocate_timer() ;
//rtos_callback_timer_inform_every(t1, SECONDS(1), timer1, 0) ;
//rtos_callback_timer_inform_every(t2, MILLISECONDS(100), timer2) ;
//rtos_callback_timer_inform_every(t3, MILLISECONDS(100), timer1) ;
//rtos_callback_timer_inform_every(t4, MILLISECONDS(100), timer2) ;
rtos_callback_timer_inform_every(t5, MILLISECONDS(100), timer1, 0) ;
scheduler_start() ;
/*queue_info q, q2 ;
int32s e ;
queue_init(&q) ;
queue_init(&q2) ;
P3 |= 0x0400;
DP3 |= 0x0400;
DP3 &= 0xF7FF;
S0TIC = 0x80;
S0RIC = 0x00;
S0BG = 0x20;
S0CON = 0x8011;
queue_enqueue(&q, 19) ;
queue_enqueue(&q, 3) ;
while(1)
{
if (e)
{
queue_move(&q, &q2, 19) ;
//queue_move(&q, &q2, 3) ;
e = 0 ;
queue_print(&q) ;
queue_print(&q2) ;
printf("\n********************\n") ;
}
else
{
queue_move(&q2, &q, 19) ;
//queue_move(&q2, &q, 3) ;
e = 1 ;
queue_print(&q) ;
queue_print(&q2) ;
printf("\n********************\n") ;
}
}*/
}
/*queue_info q ;
int32s e ;
queue_init(&q) ;
P3 |= 0x0400;
DP3 |= 0x0400;
DP3 &= 0xF7FF;
S0TIC = 0x80;
S0RIC = 0x00;
S0BG = 0x20;
S0CON = 0x8011;
queue_enqueue(&q, 19) ;
queue_enqueue(&q, 3) ;
queue_enqueue(&q, 1975) ;
queue_enqueue(&q, 185) ;
queue_enqueue(&q, 7) ;
queue_empty(&q) ;
printf("%d\n", queue_dequeue(&q) ) ;
printf("%d\n", queue_dequeue(&q) ) ;
printf("%d\n", queue_dequeue(&q) ) ;
printf("%d\n", queue_dequeue(&q) ) ;
printf("%d\n", queue_dequeue(&q) ) ;
printf("%d\n", queue_dequeue(&q) ) ;
queue_enqueue(&q, 74) ;
printf("%d\n", queue_dequeue(&q) ) ;
while (1)
{
}
////////////////////////////////////////////////////////////////
queue_info q, q2 ;
int32s e ;
queue_init(&q) ;
queue_init(&q2) ;
P3 |= 0x0400;
DP3 |= 0x0400;
DP3 &= 0xF7FF;
S0TIC = 0x80;
S0RIC = 0x00;
S0BG = 0x20;
S0CON = 0x8011;
queue_enqueue(&q, 19) ;
queue_enqueue(&q, 3) ;
queue_enqueue(&q, 1975) ;
queue_enqueue(&q, 45) ;
queue_enqueue(&q, 7) ;
queue_enqueue(&q, 17) ;
queue_enqueue(&q, -7) ;
queue_enqueue(&q, 37) ;
queue_enqueue(&q, 47) ;
queue_print(&q) ;
queue_print(&q2) ;
printf("\n") ;
queue_move(&q, &q2, 3) ;
queue_print(&q) ;
queue_print(&q2) ;
printf("\n") ;
queue_move(&q, &q2, 7) ;
queue_print(&q) ;
queue_print(&q2) ;
printf("\n") ;
queue_move(&q, &q2, 19) ;
queue_print(&q) ;
queue_print(&q2) ;
printf("\n") ;
queue_move(&q, &q2, 45) ;
queue_print(&q) ;
queue_print(&q2) ;
printf("\n") ;
queue_move(&q, &q2, 1975) ;
queue_print(&q) ;
queue_print(&q2) ;
printf("\n") ;
queue_move(&q, &q2, 3) ;
queue_print(&q) ;
queue_print(&q2) ;
printf("\n") ;
queue_move(&q, &q2, 7) ;
queue_print(&q) ;
queue_print(&q2) ;
printf("\n") ;
printf("%d\n", queue_dequeue(&q2) ) ;
printf("%d\n", queue_dequeue(&q2) ) ;
printf("%d\n", queue_dequeue(&q2) ) ;
printf("%d\n", queue_dequeue(&q2) ) ;
printf("%d\n", queue_dequeue(&q2) ) ;
queue_enqueue(&q2, 74) ;
printf("%d\n", queue_dequeue(&q2) ) ;
while (1)
{
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -