コード例 #1
0
ファイル: main.c プロジェクト: kees2125/C-enbeded-software
	int main(void) {
		//audioInit();
		//setVolume(254);
		WatchDogDisable();		//disable watchdog
		NutDelay(100);			//wait for it to disable
		SysInitIO();			//initialise input and output
		SPIinit();				//initialise SPI-registers (speed, mode)
		LedInit();				//initialise led
		initLCD();				//initialise lcd
		Uart0DriverInit();		//initialise Universal asynchronous receiver/transmitter  
		Uart0DriverStart();		//start Uart
		printf("\n\n\n\nHardware initialization done\n\n");
		LogInit();				//initialise ability to log
		CardInit();				//initialise cardreader
		printf("\n----------------------------------------------START OF PROGRAM------------------------------------------------------------\n");

		if (NutSegBufInit(8192) == 0) {
			puts("NutSegBufInit: Fatal error");
		}
		
		/*
		* Initialize the MP3 decoder hardware.
		*/
		if (VsPlayerInit() || VsPlayerReset(0)) {
			puts("VsPlayer: Fatal error");
		}
		
		if(X12Init() == -1){
			printf("error initializing RTC");	//initialise X12RTC 
		}				
		tm gmt;
		if (X12RtcGetClock(&gmt) == 0) {
			LogMsg_P(LOG_INFO, PSTR("local storage time [%02d:%02d:%02d] (in RTC)\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec);
		}

		if (At45dbInit() == AT45DB041B) {
			// ......
		}

		RcInit();					//Initialise the Remote Control module
		KbInit();					//Initialise keyboard
		initMenu();					//Initialise menu
		NutThreadCreate("Bh", ButtonHandlerThread, NULL, 512);	//create thread to handle button presses
		printf("\nInitialization done.\n");
		initAlarms();
		SysControlMainBeat(ON); 	//enable 4.4 msecs heartbeat interrupt
		printf("Heartbeat on.\n");
		NutThreadSetPriority(1);	//Increase our priority so we can feed the watchdog.
		sei();						//enable global interrupts
		NutThreadCreate("Bg", TimeSyncThread, NULL, 512);
		NutThreadCreate("Bq", RefreshSceenThread, NULL, 512);
		NutThreadCreate("Bl", AlarmCheckerThread, NULL, 512);
		printf("\nEntering main loop.\n");
		LcdBackLight(LCD_BACKLIGHT_ON);
		for(;;){
			NutSleep(100);
			WatchDogRestart();			//restart watchdog
		}
		
		return(0);
	}
コード例 #2
0
ファイル: audiostream.c プロジェクト: Bluepr1nt/C-huiswerk
    /*
 * \brief Play MP3 stream.
 *
 * \param stream Socket stream to read MP3 data from.
 */
    void PlayMp3Stream(FILE *stream, u_long metaint) {
        size_t rbytes;
        u_char *mp3buf;
        u_char ief;
        int got = 0;
        u_long last;
        u_long mp3left = metaint;

        /*
         * Initialize the MP3 buffer. The NutSegBuf routines provide a global
         * system buffer, which works with banked and non-banked systems.
         */
        if (NutSegBufInit(8192) == 0) {
            puts("Error: MP3 buffer init failed");
            return;
        }

        /*
         * Initialize the MP3 decoder hardware.
         */
        if (VsPlayerInit() || VsPlayerReset(0)) {
            puts("Error: MP3 hardware init failed");
            return;
        }
        VsSetVolume(0, 0);

        /*
         * Reset the MP3 buffer.
         */
        ief = VsPlayerInterrupts(0);
        NutSegBufReset();
        VsPlayerInterrupts(ief);
        last = NutGetSeconds();

        for (; ;) {

            if(STOP_THREAD){
                STOP_THREAD = 0;
                return;
            }

            /*
             * Query number of byte available in MP3 buffer.
             */
            ief = VsPlayerInterrupts(0);
            mp3buf = NutSegBufWriteRequest(&rbytes);
            VsPlayerInterrupts(ief);

            /*
             * If the player is not running, kick it.
             */
            if (VsGetStatus() != VS_STATUS_RUNNING) {
                if (rbytes < 1024 || NutGetSeconds() - last > 4UL) {
                    last = NutGetSeconds();
                    puts("Kick player");
                    VsPlayerKick();
                }
            }

            /*
             * Do not read pass metadata.
             */
            if (metaint && rbytes > mp3left) {
                rbytes = mp3left;
            }

            /*
             * Read data directly into the MP3 buffer.
             */
            while (rbytes) {
                if ((got = fread(mp3buf, 1, rbytes, stream)) > 0) {
                    ief = VsPlayerInterrupts(0);
                    mp3buf = NutSegBufWriteCommit(got);
                    VsPlayerInterrupts(ief);

                    if (metaint) {
                        mp3left -= got;
                        if (mp3left == 0) {
                            ProcessMetaData(stream);
                            mp3left = metaint;
                        }
                    }

                    if (got < rbytes && got < 512) {
                        printf("%lu buffered\n", NutSegBufUsed());
                        NutSleep(250);
                    }
                    else {
                        NutThreadYield();
                    }
                } else {
                    break;
                }
                rbytes -= got;
            }

            if (got <= 0) {
                break;
            }

            NutSleep(100);
        }
    }
コード例 #3
0
THREAD(StreamPlayer, arg)
{
	FILE *stream = (FILE *)arg;
	size_t rbytes = 0;
	char *mp3buf;
	int result = NOK;
	int nrBytesRead = 0;
	unsigned char iflag;

	//
	// Init MP3 buffer. NutSegBuf is een globale, systeem buffer
	//
	if (0 != NutSegBufInit(8192))
	{
		// Reset global buffer
		iflag = VsPlayerInterrupts(0);
		NutSegBufReset();
		VsPlayerInterrupts(iflag);

		result = OK;
	}

	// Init the Vs1003b hardware
	if (OK == result)
	{
		if (-1 == VsPlayerInit())
		{
			if (-1 == VsPlayerReset(0))
			{
				result = NOK;
			}
		}
	}

	for (;;)
	{
		/*
		* Query number of byte available in MP3 buffer.
		*/
		iflag = VsPlayerInterrupts(0);
		mp3buf = NutSegBufWriteRequest(&rbytes);
		VsPlayerInterrupts(iflag);

		// Bij de eerste keer: als player niet draait maak player wakker (kickit)
		if (VS_STATUS_RUNNING != VsGetStatus())
		{
			if (rbytes < 1024)
			{
				printf("VsPlayerKick()\n");
				VsPlayerKick();
			}
		}

		while (rbytes)
		{
			// Copy rbytes (van 1 byte) van stream naar mp3buf.
			nrBytesRead = fread(mp3buf, 1, rbytes, stream);

			if (nrBytesRead > 0)
			{
				iflag = VsPlayerInterrupts(0);
				mp3buf = NutSegBufWriteCommit(nrBytesRead);
				VsPlayerInterrupts(iflag);
				if (nrBytesRead < rbytes && nrBytesRead < 512)
				{
					NutSleep(250);
				}
			}
			else
			{
				break;
			}
			rbytes -= nrBytesRead;

			if (nrBytesRead <= 0)
			{
				break;
			}
		}
	}
}