?? hello.c.bak
字號:
/***************************************************************************************************************
*
* NOKIA Lcd, ARM7, SD/MMC PROJECT
*
*
***************************************************************************************************************/
#include "globals.h"
#include "globals.c"
#include "Lcd.c"
#include "windows.c"
#include "win_resources.c"
#include "gps.c"
/* INTERRUPTS */
static cyg_interrupt int1;
static cyg_handle_t int1_handle;
/* SEMAPHORES */
static cyg_sem_t gps_data_validity;
/* DEFINES */
#define NTHREADS 5
#define STACKSIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL)
/* STATIC */
static cyg_handle_t thread[NTHREADS];
static cyg_thread thread_obj[NTHREADS];
static char stack[NTHREADS][STACKSIZE];
// Interrupt service routine for int1
cyg_uint32 interrupt_1_ISR(cyg_vector_t vector, cyg_addrword_t data)
{
cyg_interrupt_mask(vector);
cyg_interrupt_acknowledge(vector);
return(CYG_ISR_HANDLED | CYG_ISR_CALL_DSR);
}
// deferred service routine for int1
void interrupt_1_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data )
{
//cyg_semaphore_post(& );
cyg_interrupt_unmask(vector);
}
// exception handler
void system_call_exception_handler( cyg_addrword_t data,
cyg_code_t number,
cyg_addrword_t info)
{
cls();
nokia_printmessage("System Halted",1);
diag_printf("\n ERROR: System Call Exception \n");
}
// CYG_STAFF
cyg_mutex_t cliblock; /* and now a mutex to protect calls to the C library */
cyg_alarm_t test_alarm_func;
cyg_handle_t mbox_handle;
/* CYG USER START */
void cyg_user_start(void)
{
//exception
cyg_exception_handler_t *old_handler;
cyg_addrword_t old_data;
//Init LCD, eCos logo
EcosLogo();
//Init Led, Buttton
LedButInit();
//Clear lcd
cls();
cyg_vector_t int1_vector = CYGNUM_HAL_INTERRUPT_UART0;
cyg_priority_t int1_priority = 0 ;
//SEMAPHORES
//cyg_semaphore_init(&gps_data_validity,0);
//MUTEX
cyg_mutex_init(&cliblock);
// CREATE THREADS
// ATENTION! BITMAP SHEDULER!!!
cyg_thread_create(5, SER1_program, (cyg_addrword_t) 0, "ser1", (void *) stack[0], STACKSIZE, &thread[0], &thread_obj[0]);
cyg_thread_create(13, LCD_program, (cyg_addrword_t) 1, "lcd", (void *) stack[1], STACKSIZE, &thread[1], &thread_obj[1]);
cyg_thread_create(11, BTN_program, (cyg_addrword_t) 2, "btn", (void *) stack[2], CYGNUM_HAL_STACK_SIZE_MINIMUM, &thread[2], &thread_obj[2]);
cyg_thread_create(12, ALARM_program, (cyg_addrword_t) 3, "alarm", (void *) stack[3], CYGNUM_HAL_STACK_SIZE_MINIMUM, &thread[3], &thread_obj[3]);
cyg_thread_create(6, SER0_program, (cyg_addrword_t) 4, "ser0", (void *) stack[4], STACKSIZE, &thread[4], &thread_obj[4]);
//INIT INTERRUPT
cyg_interrupt_create(int1_vector, int1_priority, 0, &interrupt_1_ISR, &interrupt_1_dsr, &int1_handle, &int1);
//THREADS RESUME
//SER1
cyg_thread_resume(thread[0]);
//LCD
cyg_thread_resume(thread[1]);
//BUTTON
cyg_thread_resume(thread[2]);
//ALARM
cyg_thread_resume(thread[3]);
//SER0
cyg_thread_resume(thread[4]);
//Atach
cyg_interrupt_attach(int1_handle);
//Unmask
cyg_interrupt_unmask(int1_vector);
/*
//install the exception handler for error output:
cyg_exception_set_handler( CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION ,
&system_call_exception_handler,
0,
&old_handler,
&old_data);
*/
return;
}
void BTN_program(cyg_addrword_t index)
{
//button control
for(;;)
{
//Icone select by Button press
if(IOPIN>>SWPIN==0)
{
beep(5,2);
// 4 icons counter
if(menu_counter < ICON_COUNTER) menu_counter +=1;
else menu_counter =0x00;
// Close/Suspend windows with button press
gps_latitude_flag = 0x00;
gps_status_flag = 0x00;
draw_window=0x00;
console_msg_flag=0x00;
LED_OFF;
cyg_thread_delay(50);
}
cyg_thread_delay(10);//don't pip!
}
}
void LCD_program(cyg_addrword_t data)
{
// show on lcd. Graphic mode
lcd_key=0x00;
for(;;)
{
// show Datum on if lcd is not busy
if(!lcd_key)
{
//DRAW MAIN WINDOW
draw_picture(mainwin);
//LATITUDE /NORD/
if(gps_latitude_flag) gps_latitude();
//GPS STATUS WINDOW /system control/
if(gps_status_flag) gps_status();
//ABOUT
if(draw_window) Draw_Window(2,10,60,25,"About","GPS VER.1.0");
//CONSOLE MSG
if(console_msg_flag) {Draw_Window(2,10,79,25,"Console",&console_buff[2]);}
//SHOW THE LCD BUFF !!!!!
LcdUpdate();
}
else lcd(&console_buff[0]);
cyg_thread_delay(10); //don't pip!
}
}
void SER1_program(cyg_addrword_t data)
{
FILE * pSER1;
cyg_uint32 len = 128; /* data length */
//cyg_serial_info_t info; /* serial port config info */
//Cyg_ErrNo error; /* error output*/
//cyg_io_handle_t handle; /* mouse device handle */
/* eCos com0 open */
//error=cyg_io_lookup("dev/ser0", &handle);
//len=sizeof(info);
pSER1=fopen("/dev/ser1","r");
for(;;)
{
fgets (&ser1_buff[0], len, pSER1);
//$GPRMC
if(ser1_buff[0]=='$')
{
if(ser1_buff[1]=='G')
{
if(ser1_buff[2]=='P')
{
if(ser1_buff[3]=='R')
{
if(ser1_buff[4]=='M')
{
//Read buff
strcpy(&GPRMC[0], &ser1_buff[0] );GPRMC[127]='\0';
//CALL GPS SUB
GPS();
}
}
}
}
}
//$GPGGA
if(ser1_buff[0]=='$')
{
if(ser1_buff[1]=='G')
{
if(ser1_buff[2]=='P')
{
if(ser1_buff[3]=='G')
{
if(ser1_buff[4]=='G')
{
//Read buff
strcpy(&GPGGA[0], &ser1_buff[0] );GPGGA[127]='\0';
//CALL GPS SUB
GPS();
}
}
}
}
}
free(ser1_buff);
//fclose(pSER1);
}
}
void SER0_program(cyg_addrword_t data)
{
FILE * pSER0;
cyg_uint32 len = 127; /* data length */
//cyg_serial_info_t info; /* serial port config info */
//Cyg_ErrNo error; /* error output*/
//cyg_io_handle_t handle; /* mouse device handle */
/* eCos com0 open */
//error=cyg_io_lookup("dev/ser0", &handle);
//len=sizeof(info);
pSER0 = fopen("/dev/ser0","r");
for(;;)
{
fgets (&ser0_buff[0], len, pSER0);
//@CONSOLE
if(ser0_buff[0]=='@')
{
if(ser0_buff[1]=='c')
{
if(ser0_buff[2]=='o')
{
if(ser0_buff[3]=='n')
{
//turn_0ff gps recaiving
mode = 0x02;
//IMPORTANT : The console message must be terminated by #013#010(dec)!
strncpy(&console_buff[0], &ser0_buff[4],15); console_buff[15]='\0';
console();
}
}
}
}
free(ser0_buff);
//fclose(pSER1);
}
}
// alarm_prog() is a thread which sets up an alarm which is then handled by test_alarm_func()
void ALARM_program(cyg_addrword_t data)
{
cyg_handle_t test_counterH, system_clockH, test_alarmH;
cyg_tick_count_t ticks;
cyg_alarm test_alarm;
unsigned how_many_alarms = 0, prev_alarms = 0, tmp_how_many;
system_clockH = cyg_real_time_clock();
cyg_clock_to_counter(system_clockH, &test_counterH);
cyg_alarm_create(test_counterH, test_alarm_func, (cyg_addrword_t) &how_many_alarms, &test_alarmH, &test_alarm);
//init alarm trig.= 200, interval =2000
cyg_alarm_initialize(test_alarmH, cyg_current_time() + 200, 2000);
// get in a loop in which we read the current time and print it out
for (;;)
{
ticks = cyg_current_time();
cyg_scheduler_lock();
tmp_how_many = how_many_alarms;
cyg_scheduler_unlock();
if (prev_alarms != tmp_how_many)
{
// Code for Alarm Event
// Close/Suspend windows
if( !gps_latitude_flag ) gps_latitude_flag=0x01;
else gps_latitude_flag = 0x00;
cyg_thread_delay(500);
if( !gps_status_flag ) gps_status_flag=0x01;
else gps_status_flag = 0x00;
cyg_thread_delay(200);
if(!draw_window) draw_window=0x01;
else draw_window=0x00;
cyg_thread_delay(500);
if(console_msg_flag) console_msg_flag=0x00;
LED_OFF;
prev_alarms = tmp_how_many;
}
cyg_thread_delay(300);
}
}
/*
test_alarm_func() is invoked as an alarm handler, so
it should be quick and simple. in this case it increments
the data that is passed to it.
*/
void test_alarm_func(cyg_handle_t alarmH, cyg_addrword_t data)
{
++*((unsigned *) data);
}
void console(void)
{
unsigned char Cmd = 0x00;
unsigned char Frame = 0x00;
//led blink
LED_ON;
Frame = console_buff[0];
Cmd = console_buff[1];
// SEND CMD
cyg_mutex_lock(&cliblock);
{
printf("<console> Frame<%d>, Cmd <%d> \n", Frame, Cmd);
}
cyg_mutex_unlock(&cliblock);
switch(Cmd)
{
case '?':
{
//Console message
if(console_buff[2]!=0x00) console_msg_flag = 0x01;
else console_msg_flag = 0x00;
break;
}
case 1:
{
//Increment menu counter
beep(5,3);
// 4 icons counter
if(menu_counter < ICON_COUNTER) menu_counter +=1;
else menu_counter = 0x00;
cyg_thread_delay(40);
break;
}
case 2:
{
//Decrement menu counter
beep(5,3);
// 4 icons counter
if(menu_counter > 0) menu_counter -=1;
else menu_counter = ICON_COUNTER;
cyg_thread_delay(40);
break;
}
case 3:
{
break;
}
case 4:
{
break;
}
case 5:
{
break;
}
case 6:
{
break;
}
case 7:
{
break;
}
case 8:
{
break;
}
case 9:
{
cls();
lcd_key=0x01;
break;
}
}
return;
}
//eof
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -