/* includes */ #include "vxWorks.h" #include "stdio.h" #include "stdlib.h" #include "semLib.h" #include "taskLib.h" /* defines */ #define NUM_SAMPLE 10 #define LUCKY 7 #define HOT 20 #define DELAY_TICKS 4 #define STACK_SIZE 20000 #define SYSCFG 0x03FF0000 #define IOPDATA (SYSCFG + 0x5008) #define BEEPBANK *((unsigned *)IOPDATA) #define LEDBANK *((unsigned *)IOPDATA) #define LED_4_ON (LEDBANK=LEDBANK|0x00000010) #define LED_3_ON (LEDBANK=LEDBANK|0x00000020) #define LED_2_ON (LEDBANK=LEDBANK|0x00000040) #define LED_1_ON (LEDBANK=LEDBANK|0x00020000) #define LED_4_OFF (LEDBANK=LEDBANK&(~16)) #define LED_3_OFF (LEDBANK=LEDBANK&(~32)) #define LED_2_OFF (LEDBANK=LEDBANK&(~64)) #define LED_1_OFF (LEDBANK=LEDBANK&(~0x00020000)) #define BEEP_ON (BEEPBANK=BEEPBANK|0x00010000) #define BEEP_OFF (BEEPBANK=BEEPBANK^0x00010000) /*seg7*/ #ifndef _SEG7_H #define _SEG7_H #define IOPMOD (*((volatile unsigned *)(SYSCFG+0x5000))) #define SEG7_BASE 0x03fdc000 #define SEG7 (*(volatile unsigned int *)(SEG7_BASE)) #define SEG_A (0x1<<0) #define SEG_B (0x1<<1) #define SEG_C (0x1<<2) #define SEG_D (0x1<<4) #define SEG_E (0x1<<5) #define SEG_F (0x1<<6) #define SEG_G (0x1<<7) #define SEG_DP (0x1<<3) #define DISP_0 (0) #define DISP_1 (SEG_F|SEG_G) #define DISP_2 (SEG_A|SEG_C|SEG_D|SEG_E|SEG_G) #define DISP_3 (SEG_A|SEG_C|SEG_E|SEG_F|SEG_G) #define DISP_4 (SEG_B|SEG_C|SEG_F|SEG_G) #define DISP_5 (SEG_A|SEG_B|SEG_C|SEG_E|SEG_F) #define DISP_6 (SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_F) #define DISP_7 (SEG_A|SEG_F|SEG_G) #define DISP_8 (SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_F|SEG_G) #define DISP_9 (SEG_A|SEG_B|SEG_C|SEG_E|SEG_F|SEG_G) #define DISP_A (SEG_A|SEG_B|SEG_C|SEG_D|SEG_F|SEG_G) #define DISP_B (SEG_B|SEG_C|SEG_D|SEG_E|SEG_F) #define DISP_C (SEG_A|SEG_B|SEG_D|SEG_E) #define DISP_D (SEG_C|SEG_D|SEG_E|SEG_F|SEG_G) #define DISP_E (SEG_A|SEG_B|SEG_C|SEG_D|SEG_E) #define DISP_F (SEG_A|SEG_B|SEG_C|SEG_D) #endif /* define DO RE MI ... ¶ÔӦƵÂÊ hz */ #define P0 0 #define P1 264 #define P2 297 #define P3 330 #define P4 352 #define P5 396 #define P6 440 #define P7 495 int i_note[] = { P0, P1, P2, P3, P4, P5, P6, P7 }; /*com*/ #define ULCON0 (*(volatile unsigned *)0x03FFD000) #define UCON0 (*(volatile unsigned *)0x03FFD004) #define USTAT0 (*(volatile unsigned *)0x03FFD008) #define UTXBUF0 (*(volatile unsigned *)0x03FFD00c) #define URXBUF0 (*(volatile unsigned *)0x03FFD010) #define UBRDIV0 (*(volatile unsigned *)0x03FFD014) #define ULCON1 (*(volatile unsigned *)0x03FFE000) #define UCON1 (*(volatile unsigned *)0x03FFE004) #define USTAT1 (*(volatile unsigned *)0x03FFE008) #define UTXBUF1 (*(volatile unsigned *)0x03FFE00c) #define URXBUF1 (*(volatile unsigned *)0x03FFE010) #define UBRDIV1 (*(volatile unsigned *)0x03FFE014) /* typedefs */ typedef struct byLightning { int data; int nodeNum; struct byLightning * pPrevNode; } LIST_NODE; /* globals */ int tidPlay; int tidLight; int tidSong; int tidCom; int result = 0; /* Holds result of calculation */ SEM_ID dataSemId; /* Given when a datum is available */ SEM_ID syncSemId; /* Given when a data sample can be crunched */ SEM_ID nodeListGuardSemId; /* Given when pointer to current node can be accessed */ static unsigned int numeric_display [16] = { DISP_0, DISP_1, DISP_2, DISP_3, DISP_4, DISP_5, DISP_6, DISP_7, DISP_8, DISP_9, DISP_A, DISP_B, DISP_C, DISP_D, DISP_E, DISP_F }; /*music song*/ int dfh[][3] = { { 5, 2, 4 }, { 0, 0, 0 }, { 5, 2, 8 }, { 6, 2, 8 }, { 0, 0, 0 }, { 2, 2, 2 }, { 0, 0, 0 }, { 0, 0, 0 }, { 1, 2, 4 }, { 0, 0, 0 }, { 1, 2, 8 }, { 6, 1, 8 }, { 0, 0, 0 }, { 2, 2, 2 }, { 0, 0, 0 }, { 0, 0, 0 }, { 5, 2, 4 }, { 0, 0, 0 }, { 5, 2, 4 }, { 0, 0, 0 }, { 6, 2, 8 }, { 1, 4, 8 }, { 0, 0, 0 }, { 6, 2, 8 }, { 5, 2, 8 }, { 0, 0, 0 }, { 1, 2, 4 }, { 0, 0, 0 }, { 1, 2, 8 }, { 6, 1, 8 }, { 0, 0, 0 }, { 2, 2, 2 }, { 0, 0, 0 }, { 0, 0, 0 }, { 5, 2, 4 }, { 0, 0, 0 }, { 2, 2, 4 }, { 0, 0, 0 }, { 1, 2, 4 }, { 0, 0, 0 }, { 7, 1, 8 }, { 6, 1, 8 }, { 0, 0, 0 }, { 5, 1, 4 }, { 0, 0, 0 }, { 5, 2, 4 }, { 0, 0, 0 }, { 2, 2, 4 }, { 0, 0, 0 }, { 3, 2, 8 }, { 2, 2, 8 }, { 0, 0, 0 }, { 1, 2, 4 }, { 0, 0, 0 }, { 1, 2, 8 }, { 6, 1, 8 }, { 0, 0, 0 }, { 2, 2, 8 }, { 3, 2, 8 }, { 0, 0, 0 }, { 2, 2, 8 }, { 1, 2, 8 }, { 0, 0, 0 }, { 2, 2, 8 }, { 1, 2, 8 }, { 0, 0, 0 }, { 7, 1, 8 }, { 6, 1, 8 }, { 0, 0, 0 }, { 5, 1, 2 }, { 5, 1, 8 }, { 0, 0, 0 }, { 0, 0, 0 }, { -1, 0, 0 } }; int youyi[][3] = { { 5, 1, 8 }, { 0, 0, 0 }, { 1, 2, 8 }, { 1, 2, 16 }, { 0, 0, 0 }, { 1, 2, 16 }, { 0, 0, 0 }, { 1, 2, 8 }, { 3, 2, 16 }, { 0, 0, 0 }, { 2, 2, 8 }, { 2, 2, 16 }, { 1, 2, 16 }, { 0, 0, 0 }, { 2, 2, 8 }, { 3, 2, 8 }, { 0, 0, 0 }, { 1, 2, 8 }, { 1, 2, 16 }, { 0, 0, 0 }, { 1, 2, 16 }, { 0, 0, 0 }, { 3, 2, 8 }, { 5, 2, 8 }, { 0, 0, 0 }, { 6, 2, 4 }, { 6, 2, 8 }, { 0, 0, 0 }, { 0, 0, 0 }, { 6, 2, 8 }, { 0, 0, 0 }, { 5, 2, 8 }, { 5, 2, 16 }, { 0, 0, 0 }, { 3, 2, 16 }, { 0, 0, 0 }, { 3, 2, 8 }, { 1, 2, 16 }, { 0, 0, 0 }, { 2, 2, 8 }, { 2, 2, 16 }, { 1, 2, 16 }, { 0, 0, 0 }, { 2, 2, 8 }, { 3, 2, 8 }, { 0, 0, 0 }, { 1, 2, 8 }, { 1, 2, 16 }, { 0, 0, 0 }, { 6, 1, 16 }, { 0, 0, 0 }, { 6, 1, 8 }, { 5, 1, 8 }, { 0, 0, 0 }, { 1, 2, 4 }, { 1, 2, 8 }, { 0, 0, 0 }, { 0, 0, 0 }, { -1, 0, 0 } }; int mouse[][3] = { { 1, 2, 8 }, { 0, 0, 0 }, { 2, 2, 8 }, { 0, 0, 0 }, { 3, 2, 8 }, { 0, 0, 0 }, { 1, 2, 8 }, { 0, 0, 0 }, { 1, 2, 8 }, { 0, 0, 0 }, { 2, 2, 8 }, { 0, 0, 0 }, { 3, 2, 8 }, { 0, 0, 0 }, { 1, 2, 8 }, { 0, 0, 0 }, { 3, 2, 8 }, { 0, 0, 0 }, { 4, 2, 8 }, { 0, 0, 0 }, { 5, 2, 4 }, { 0, 0, 0 }, { 3, 2, 8 }, { 0, 0, 0 }, { 4, 2, 8 }, { 0, 0, 0 }, { 5, 2, 4 }, { 0, 0, 0 }, { 5, 2, 16 }, { 0, 0, 0 }, { 6, 2, 16 }, { 0, 0, 0 }, { 5, 2, 16 }, { 0, 0, 0 }, { 4, 2, 16 }, { 0, 0, 0 }, { 3, 2, 8 }, { 0, 0, 0 }, { 1, 2, 8 }, { 0, 0, 0 }, { 5, 2, 16 }, { 0, 0, 0 }, { 6, 2, 16 }, { 0, 0, 0 }, { 5, 2, 16 }, { 0, 0, 0 }, { 4, 2, 16 }, { 0, 0, 0 }, { 3, 2, 8 }, { 0, 0, 0 }, { 1, 2, 8 }, { 0, 0, 0 }, { 2, 2, 8 }, { 0, 0, 0 }, { 5, 1, 8 }, { 0, 0, 0 }, { 1, 2, 4 }, { 0, 0, 0 }, { 2, 2, 8 }, { 0, 0, 0 }, { 5, 1, 8 }, { 0, 0, 0 }, { 1, 2, 4 }, { 0, 0, 0 }, { -1, 0, 0 } }; /* forward declarations */ void progStop (void); void play_music( int psong[][3] ); void delay( int t ); void disp_seg7 (int seg); void beep( int note, int tone, int div ); void rest( void ); void play( void ); void light(void); void song(void); void InitUART(int Port,int Baudrate); void PrintUART(int Port,char *s); void com(void); /************************************************************************* * * progStart - start the sample program. * * Create various semaphores and spawn various tasks, while doing * incredibly little error checking. * * RETURNS: OK */ STATUS progStart (void) { syncSemId = semBCreate (SEM_Q_FIFO, SEM_EMPTY); dataSemId = semBCreate (SEM_Q_FIFO, SEM_EMPTY); nodeListGuardSemId = semMCreate ( SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE); /* the I/O mode is output and I/O init set bard */ *(unsigned int *)0x03ff5000 = 0xffffffff; InitUART(0,0x500); /*creat tasks*/ tidCom=taskSpawn ("com", 200, 0, STACK_SIZE, (FUNCPTR) com,0,0,0,0,0,0,0,0,0,0); tidSong = taskSpawn ("song", 210, 0, STACK_SIZE, (FUNCPTR) song,0,0,0,0,0,0,0,0,0,0); tidPlay = taskSpawn ("music", 220, 0, STACK_SIZE, (FUNCPTR) play,0,0,0,0,0,0,0,0,0,0); tidLight = taskSpawn ("light", 230, 0, STACK_SIZE, (FUNCPTR) light,0,0,0,0,0,0,0,0,0,0); return (OK); } /************************************************************************* * * progStop - stops the program * * Call this routine to end it all. */ void progStop (void) { taskDelete (tidCom); taskDelete (tidPlay); taskDelete (tidSong); taskDelete (tidLight); semDelete (dataSemId); semDelete (syncSemId); semDelete (nodeListGuardSemId); /* My, aren't we tidy! */ printf ("BYE!TSCHUESS!ADIEU!\n"); return; } /*the led is lighted one after anther*/ void light(void) { while (1) { LED_2_ON; delay(65536); LED_2_OFF; LED_3_ON; delay(65536); LED_3_OFF; LED_4_ON; delay(65536); LED_4_OFF; LED_1_ON; delay(65536); LED_1_OFF; LED_4_ON; delay(65536); LED_4_OFF; LED_3_ON; delay(65536); LED_3_OFF; } } /* delay 1/1000000 s = 0.000001 s £¬ 1/1000 ºÁÃë*/ void delay( int t ) { int i, j; for( i=0; i<10; i++ ) for ( j=0; j= 1 ) beep( psong[i][0], psong[i][1], psong[i][2] ); if( psong[i][0] == 0 ) rest(); if( psong[i][0] == -1 ) break; } } void disp_seg7 (int seg) { SEG7 = numeric_display[seg]; } void song(void) { play_music( dfh ); } void play( void ) { volatile unsigned int * status = (volatile unsigned int *)0x03ff5008; int choice ; *(volatile unsigned int *)0x03ff5000 = 0xffffbef0; while( 1 ) { if( *status & 0x00000100 ) { choice = (*status) & 0x0000000f ; switch( choice ) { case 1: play_music( dfh ); disp_seg7 ( 1 ); break; case 2: play_music( youyi ); disp_seg7 ( 2 ); break; case 3: play_music( mouse ); disp_seg7 ( 3 ); break; default : disp_seg7 ( 0xE ); break; } } } } /*a string is trasported through uart */ void com(void) { char *t,*s="Communcation Testting! \r\n"; t=s; while(1) { s=t; PrintUART(0,s); } } void InitUART(int Port,int Baudrate) { if(Port==0) { ULCON0=0x03; UCON0=0x09; UBRDIV0=Baudrate; } if(Port==1) { ULCON1=0x03; UCON1=0x09; UBRDIV1=Baudrate; } } void PrintUART(int Port,char *s) { if(Port==0) for(;*s!='\0';s++) { for(;(!(USTAT0&0x40));); UTXBUF0=*s; } if(Port==1) for(;*s!='\0';s++) { for(;(!(USTAT1&0x40));); UTXBUF1=*s; } }