コード例 #1
0
ファイル: display.c プロジェクト: Tregan/JTI-2.3-A3-IMC
/* ����������������������������������������������������������������������� */
void LcdWriteTitle(char text[])
{
    title = text;
    if(titlebool == 0)
    {
        NutThreadSetPriority(1);
        NutThreadCreate("LcdA", TitleThread, text, 1024);
        NutThreadSetPriority(0);
    }
    titlebool = 1;
}
コード例 #2
0
ファイル: display.c プロジェクト: Tregan/JTI-2.3-A3-IMC
/* ����������������������������������������������������������������������� */
void LcdWriteSecondLine(char text[])
{    
    secondline = text;
    if(secondlinebool == 0)
    {
        NutThreadSetPriority(1);
        NutThreadCreate("LcdB", SecondLineThread, text, 1024);
        NutThreadSetPriority(0);
    }
    secondlinebool = 1;
}
コード例 #3
0
THREAD(Uart0KeyEvents, arg)
{
    //LogMsg_P(LOG_INFO, PSTR("UART-Thread Start"));

    NutThreadSetPriority(200);  // low prio
    for (;;)
    {
        char *result = "";
        char rst[] = "reset\n";

        if (stream==NULL)
        {
            //LogMsg_P(LOG_INFO, PSTR("Stream is NULL!"));
            NutSleep(2000);           //Mhe
            continue;
        }

        result = fgets(result, 16, stream);
        short _reset_received = strcmp(rst, result);

        if (_reset_received == 0){
            LogMsg_P(LOG_INFO, PSTR(">>>>>> RESET COMMAND RECEIVED"));
            //RESET SIR!
            WatchDogStart(0);
        }
    }
}
コード例 #4
0
ファイル: scanner.c プロジェクト: niziak/ethernut-4.9
/*
 * Background thread for playing stream.
 */
THREAD(Scanner, arg)
{
    TCPSOCKET *sock;
    RADIOSTATION *rsp;
    uint8_t rs;
    uint32_t rx_to = 10000UL;

    NutThreadSetPriority(128);
    NutSleep(10000);
    for (;;) {
        for (rs = 0; rs < MAXNUM_STATIONS; rs++) {
            NutSleep(2000);
            if (rs == radio.rc_rstation || rs == radio.rc_cstation)
                continue;
            rsp = &station[rs];
            if (rsp->rs_ip == 0 || rsp->rs_port == 0 || radio.rc_off) {
                continue;
            }

            /* Delay if this isn't the first connection. */
            if (rsp->rs_name) {
                printf("%lu bytes free\n", NutHeapAvailable());
                NutSleep(30000);
            }

            /* Create a socket. */
            if ((sock = NutTcpCreateSocket()) == 0) {
                break;
            }
            NutTcpSetSockOpt(sock, SO_RCVTIMEO, &rx_to, sizeof(rx_to));

            /* Connect the stream server. */
            printf("[Scan %s:%u]\n", inet_ntoa(rsp->rs_ip), rsp->rs_port);
            if (NutTcpConnect(sock, rsp->rs_ip, rsp->rs_port) == 0) {
                /* Process header from server. */
                if (ScanStreamHeader(sock, rsp) == 0) {
                    if (rsp->rs_scantitle) {
                        free(rsp->rs_scantitle);
                        rsp->rs_scantitle = 0;
                    }
                    if (rsp->rs_metaint) {
                        if ((rsp->rs_scantitle = ReadMetaTitle(sock, rsp->rs_metaint)) != 0) {
                            printf("%03u: %s\n", rs, rsp->rs_scantitle);
                            rsp->rs_scandead = 0;
                        } else
                            rsp->rs_scandead = 1;
                    } else
                        rsp->rs_scandead = 0;
                } else
                    rsp->rs_scandead = 1;
            } else {
                rsp->rs_scandead = 1;
                printf("[SERR=%d]\n", NutTcpError(sock));
            }
            NutTcpCloseSocket(sock);
        }
    }
    NutSleep(30000);
}
コード例 #5
0
ファイル: rs232d.c プロジェクト: niziak/ethernut-4.9
/*
 * From RS232 to socket.
 */
THREAD(Receiver, arg)
{
    CHANNEL *cdp = arg;

    for (;;) {
        if (cdp->cd_connected) {
            NutThreadSetPriority(64);
            /*
             * We are reading from the UART without any timeout. So we
             * won't return immediately when disconnected.
             */
            StreamCopy(cdp->cd_rs232, cdp->cd_tcpip, &cdp->cd_connected);
            NutThreadSetPriority(128);
        }
        NutThreadYield();
    }
}
コード例 #6
0
int main(void)
{
	tm gmt;
	WatchDogDisable();
	NutDelay(100);
	SysInitIO();
	SPIinit();
	LedInit();
	LcdLowLevelInit();
	Uart0DriverInit();
	Uart0DriverStart();
	LogInit();
	LogMsg_P(LOG_INFO, PSTR("-----------------------------------------------------------------------------------------------"));
	CardInit();
	X12Init();
	if (X12RtcGetClock(&gmt) == 0)
	{
		LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
	}
	if (At45dbInit() == AT45DB041B)
	{
		
	}
	RcInit();
	KbInit();
	SysControlMainBeat(ON);             // enable 4.4 msecs hartbeat interrupt
	NutThreadSetPriority(1);
	NutTimerInit();
	sei();

	printf("\nreading EEPROM\n");
	NutSleep(1000);
	readEEPROM();
	printf("UTC: %d\n",IMCconfig.UTC);
	NutSleep(1000);

	IMCconfig.UTC++;	
	printf("na ophoging UTC: %d\n",IMCconfig.UTC);
	saveEEPROM();
	NutSleep(1000);
	readEEPROM();
	printf("na saving en reading UTC: %d\n",IMCconfig.UTC);

	printf("\nResetting EEPROM\n");
	NutSleep(1000);
	resetEEPROM();
	NutSleep(1000);
	readEEPROM();

	for (;;)
	{
		
	}

	return(0);      // never reached, but 'main()' returns a non-void, so.....
}
コード例 #7
0
ファイル: main.c プロジェクト: aareschluchtje/C-programming
/*-------------------------------------------------------------------------*/
THREAD(StartupInit, arg)
{
    NutThreadSetPriority(5);

    NetworkInit();

    initialized = true;

    NutThreadExit();
}
コード例 #8
0
/*
 * Background thread for playing stream.
 */
THREAD(Displayer, arg)
{
    u_int step[2] = { 0, 0 };
    u_int stepmx[2] = { 0, 0 };
    char *line;
    char *sptr = 0;
    u_char scrolling = DISPLAY_LINES;
    u_char ln;

    fputs(ESC_CURSOROFF, lcd);
    NutThreadSetPriority(128);
    for (;;) {
        NutEventWait(&updevt, 125);

        for (ln = 0; ln < DISPLAY_LINES; ln++) {
            if (mticks[ln]) {
                line = mline[ln];
                mticks[ln]--;
            } else
                line = sline[ln];
            if (stepmx[ln] != strlen(line)) {
                sptr = 0;
                scrolling = DISPLAY_LINES;
                stepmx[ln] = strlen(line);
                step[ln] = 0;
            }
            fprintf(lcd, ESC_POS "%c" "\x20", ln + 32);
            if (stepmx[ln] <= 16) {
                fputs(line, lcd);
                if (stepmx[ln] < 16)
                    fputs(ESC_CLREOL, lcd);
            } else {
                if (step[ln] == stepmx[ln]) {
                    if (scrolling == DISPLAY_LINES)
                        scrolling = ln;
                    if (scrolling == ln) {
                        if (sptr == 0)
                            sptr = line;
                        else {
                            sptr++;
                            if (strlen(sptr) <= 16)
                                step[ln]++;
                        }
                        fprintf(lcd, "%.16s", sptr);
                    }
                } else if (step[ln]++ == 0) {
                    fprintf(lcd, "%.16s", line);
                    sptr = 0;
                    scrolling = DISPLAY_LINES;
                } else if (step[ln] >= stepmx[ln] + 16)
                    step[ln] = 0;
            }
        }
    }
}
コード例 #9
0
ファイル: main.c プロジェクト: aareschluchtje/C-programming
THREAD(AlarmSync, arg)
{
    NutThreadSetPriority(50);

    while(initialized == false){
        NutSleep(1000);
    }
    int dayCounter = 0;
    int counter = 0;
    while(!NtpSync() && counter < 10)
    {
        NutSleep(1000);
        counter++;
    }
    counter = 0;
    for(;;)
    {

        if((initialized == true) && (hasNetworkConnection() == true))
        {
            checkSleep();
            isAlarmSyncing = true;
            char url[49];
            sprintf(url, "/getAlarmen.php?radiomac=%s&tz=%d", getMacAdress(), getTimeZone());
            httpGet(url, parseAlarmJson);
            isAlarmSyncing = false;

            char url2[43];
            sprintf(url2, "/getTwitch.php?radiomac=%s", getMacAdress());
            httpGet(url2, parseTwitch);
            char url3[43];
            sprintf(url3,"/getTwitter.php?radiomac=%s", getMacAdress());
            httpGet(url3,TwitterParser);

            //Command que (Telegram) sync
            sprintf(url, "%s%s", "/getCommands.php?radiomac=", getMacAdress());
            httpGet(url, parseCommandQue);
        }
        while(dayCounter > 28800 && (hasNetworkConnection() == true))
        {
            while(!NtpSync() && counter < 10)
            {
                NutSleep(1000);
                counter++;
            }
            dayCounter = 28800;
            counter = 0;
        }
        dayCounter++;
        NutSleep(3000);
    }
    NutThreadExit();
}
コード例 #10
0
THREAD(idle, arg)
{
    NutTimerInit();
    NutThreadCreate("main", WebDemo, 0, 768);
    NutThreadSetPriority(254);
    for (;;) {
#ifdef HEARTBEAT_BIT
        HeartBeat();
#endif
        NutThreadYield();
    }
}
コード例 #11
0
ファイル: main.c プロジェクト: aareschluchtje/C-programming
THREAD(AlarmCheck, arg)
{
    NutThreadSetPriority(100);
    for(;;){
        if(checkAlarms() == 1){
          setCurrentDisplay(DISPLAY_Alarm, 1000);
        }


        NutSleep(1000);
    }

}
コード例 #12
0
int main(void)
{
	tm gmt;
	WatchDogDisable();
	NutDelay(100);
	SysInitIO();
	SPIinit();
	LedInit();
	LcdLowLevelInit();
	Uart0DriverInit();
	Uart0DriverStart();
	LogInit();
	LogMsg_P(LOG_INFO, PSTR("-----------------------------------------------------------------------------------------------"));
	CardInit();
	X12Init();
	if (X12RtcGetClock(&gmt) == 0)
	{
		LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
	}
	if (At45dbInit() == AT45DB041B)
	{
		
	}
	RcInit();
	KbInit();
	SysControlMainBeat(ON);             // enable 4.4 msecs hartbeat interrupt
	initMenu();
	sei();
	NutTimerInit();
	NutThreadSetPriority(1);
	int keyvalue = KbGetKey();
	int old;
	LcdBackLight(LCD_BACKLIGHT_ON);
	if(NutRegisterDevice(&DEV_ETHER, 0x8300, 5))printf("Error: No LAN device\n");
	else printf("Lan device initialized\n");
	
	for (;;)
	{
		keyvalue = KbGetKey();
		if(old != keyvalue){
			stateMenu(keyvalue);
			old = keyvalue;
		}		
		NutSleep(100);
		WatchDogRestart();
	}

	return(0);      // never reached, but 'main()' returns a non-void, so.....
}
コード例 #13
0
/*
 * Low priority background thread. 
 */
THREAD(Low, arg)
{
    NutThreadSetPriority(96);
    for(;;) {
        puts("                  Request");
        if (NutEventWait(&mutex, 3000)) {
            puts("                  Timeout");
        }
        else {
            puts("                  Acquired");
            NutSleep(3500);
            puts("                  Release");
            NutEventPost(&mutex);
        }
    }
}
コード例 #14
0
ファイル: sensors.c プロジェクト: airborn/HAMAS_server
THREAD(sensorsReader, arg) {
    struct sensorNode* list = (struct sensorNode*) arg;
    struct sensorNode* current;
    NutThreadSetPriority(70);
    
    for (;;) {
        current = list;

        while (current != NULL) {
            current->data.value = current->data.read(current->data.params);
            current = current->next;
            NutThreadYield();
        }

        NutSleep(5000);
    }
}
コード例 #15
0
/*
 * High priority background thread. 
 */
THREAD(High, arg)
{
    NutThreadSetPriority(32);
    for(;;) {
        puts("Request");
        if (NutEventWait(&mutex, 2000)) {
            puts("Timeout");
        }
        else {
            puts("Acquired");
            NutSleep(2500);
            puts("Release");
            NutEventPost(&mutex);
        }
        NutSleep(1000);
    }
}
コード例 #16
0
/* \fn NutIdle(void *arg)
 * \brief Idle thread. 
 *
 * After initializing the timers, the idle thread switches to priority 254
 * and enters an endless loop.
 */
THREAD(NutIdle, arg)
{
    /* Initialize system timers. */
    NutTimerInit();

    /* Create the main application thread. */
    NutThreadCreate("main", main, 0, 768);

    /*
     * Run in an idle loop at the lowest priority. We can still
     * do something useful here, like killing terminated threads
     * or putting the CPU into sleep mode.
     */
    NutThreadSetPriority(254);
    for (;;) {
        NutThreadYield();
        NutThreadDestroy();
    }
}
コード例 #17
0
/*!
 * \brief Emulated idle thread.
 *
 * After initializing the timers, the idle thread switches to priority 254
 * and enters an endless loop.
 */
THREAD(NutIdle, arg)
{
    /* Initialize system timers. */
    NutTimerInit();

    /* Create the main application thread. */
    NutThreadCreate("main", NutAppMain, 0, NUT_THREAD_MAINSTACK);

    // printf("main task created, idling now..\n");
    /*
     * Run in an idle loop at the lowest priority. We can still
     * do something useful here, like killing terminated threads
     * or putting the CPU into sleep mode.
     */
    NutThreadSetPriority(254);
    for (;;) {
        NutThreadYield();
        NutThreadDestroy();

        // sleep(); ... sleeping would be fine.
    }
}
コード例 #18
0
ファイル: httpserv.c プロジェクト: niziak/ethernut-4.9
/*! \fn Service(void *arg)
 * \brief HTTP service thread.
 *
 * The endless loop in this thread waits for a client connect,
 * processes the HTTP request and disconnects. Nut/Net doesn't
 * support a server backlog. If one client has established a
 * connection, further connect attempts will be rejected.
 * Typically browsers open more than one connection in order
 * to load images concurrently. So we run this routine by
 * several threads.
 *
 */
THREAD(Service, arg)
{
    TCPSOCKET *sock;
    FILE *stream;
    uint8_t id = (uint8_t) ((uintptr_t) arg);

    /*
     * Now loop endless for connections.
     */
    for (;;) {

        /*
         * Create a socket.
         */
        if ((sock = NutTcpCreateSocket()) == 0) {
            printf("[%u] Creating socket failed\n", id);
            NutSleep(5000);
            continue;
        }

        /*
         * Listen on port 80. This call will block until we get a connection
         * from a client.
         */
        NutTcpAccept(sock, 80);
#if defined(__AVR__)
        printf("[%u] Connected, %u bytes free\n", id, NutHeapAvailable());
#else
        printf("[%u] Connected, %lu bytes free\n", id, NutHeapAvailable());
#endif

        /*
         * Wait until at least 8 kByte of free RAM is available. This will
         * keep the client connected in low memory situations.
         */
#if defined(__AVR__)
        while (NutHeapAvailable() < 8192) {
#else
        while (NutHeapAvailable() < 4096) {
#endif
            printf("[%u] Low mem\n", id);
            NutSleep(1000);
        }

        /*
         * Associate a stream with the socket so we can use standard I/O calls.
         */
        if ((stream = _fdopen((int) ((uintptr_t) sock), "r+b")) == 0) {
            printf("[%u] Creating stream device failed\n", id);
        } else {
            /*
             * This API call saves us a lot of work. It will parse the
             * client's HTTP request, send any requested file from the
             * registered file system or handle CGI requests by calling
             * our registered CGI routine.
             */
            NutHttpProcessRequest(stream);

            /*
             * Destroy the virtual stream device.
             */
            fclose(stream);
        }

        /*
         * Close our socket.
         */
        NutTcpCloseSocket(sock);
        printf("[%u] Disconnected\n", id);
    }
}
#endif /* DEV_ETHER */

/*!
 * \brief Main application routine.
 *
 * Nut/OS automatically calls this entry after initialization.
 */
int main(void)
{
    uint32_t baud = 115200;
    uint8_t i;

    /*
     * Initialize the uart device.
     */
    NutRegisterDevice(&DEV_DEBUG, 0, 0);
    freopen(DEV_DEBUG_NAME, "w", stdout);
    _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
    NutSleep(200);
    printf("\n\nNut/OS %s HTTP Daemon...", NutVersionString());

#ifdef DEV_ETHER

#ifdef NUTDEBUG
    NutTraceTcp(stdout, 0);
    NutTraceOs(stdout, 0);
    NutTraceHeap(stdout, 0);
    NutTracePPP(stdout, 0);
#endif

    /*
     * Register Ethernet controller.
     */
    if (NutRegisterDevice(&DEV_ETHER, 0, 0)) {
        puts("Registering device failed");
    }

    printf("Configure %s...", DEV_ETHER_NAME);
    if (NutNetLoadConfig(DEV_ETHER_NAME)) {
        uint8_t mac[] = MY_MAC;

        printf("initial boot...");
#ifdef USE_DHCP
        if (NutDhcpIfConfig(DEV_ETHER_NAME, mac, 60000)) 
#endif
        {
            uint32_t ip_addr = inet_addr(MY_IPADDR);
            uint32_t ip_mask = inet_addr(MY_IPMASK);
            uint32_t ip_gate = inet_addr(MY_IPGATE);

            printf("No DHCP...");
            if (NutNetIfConfig(DEV_ETHER_NAME, mac, ip_addr, ip_mask) == 0) {
                /* Without DHCP we had to set the default gateway manually.*/
                if(ip_gate) {
                    printf("hard coded gate...");
                    NutIpRouteAdd(0, 0, ip_gate, &DEV_ETHER);
                }
                puts("OK");
            }
            else {
                puts("failed");
            }
        }
    }
    else {
#ifdef USE_DHCP
        if (NutDhcpIfConfig(DEV_ETHER_NAME, 0, 60000)) {
            puts("failed");
        }
        else {
            puts("OK");
        }
#else
        if (NutNetIfConfig(DEV_ETHER_NAME, 0, 0, confnet.cdn_ip_mask)) {
            puts("failed");
        }
        else {
            puts("OK");
        }
#endif
    }
    printf("%s ready\n", inet_ntoa(confnet.cdn_ip_addr));

#ifdef USE_DISCOVERY
    NutRegisterDiscovery((uint32_t)-1, 0, DISF_INITAL_ANN);
#endif

    /*
     * Register our device for the file system.
     */
    NutRegisterDevice(&MY_FSDEV, 0, 0);

#ifdef MY_BLKDEV
    /* Register block device. */
    printf("Registering block device '" MY_BLKDEV_NAME "'...");
    if (NutRegisterDevice(&MY_BLKDEV, 0, 0)) {
        puts("failed");
        for (;;);
    }
    puts("OK");

    /* Mount partition. */
    printf("Mounting block device '" MY_BLKDEV_NAME ":1/" MY_FSDEV_NAME "'...");
    if (_open(MY_BLKDEV_NAME ":1/" MY_FSDEV_NAME, _O_RDWR | _O_BINARY) == -1) {
        puts("failed");
        for (;;);
    }
    puts("OK");
#endif

#ifdef MY_HTTPROOT
    /* Register root path. */
    printf("Registering HTTP root '" MY_HTTPROOT "'...");
    if (NutRegisterHttpRoot(MY_HTTPROOT)) {
        puts("failed");
        for (;;);
    }
    puts("OK");
#endif

    NutRegisterCgiBinPath("cgi-bin/;user/cgi-bin/;admin/cgi-bin/");


    /*
     * Register our CGI sample. This will be called
     * by http://host/cgi-bin/test.cgi?anyparams
     */
    NutRegisterCgi("test.cgi", ShowQuery);

#if defined(USE_SSI)
    /* 
     * Register a cgi included by the ssi demo. This will show how dynamic 
     * content is included in a ssi page and how the request parameters for 
     * a site are passed down to the included cgi.
     */    
    NutRegisterCgi("ssi-demo.cgi", SSIDemoCGI);
#endif

    /*
     * Register some CGI samples, which display interesting
     * system informations.
     */
    NutRegisterCgi("threads.cgi", ShowThreads);
    NutRegisterCgi("timers.cgi", ShowTimers);
    NutRegisterCgi("sockets.cgi", ShowSockets);

    /*
     * Finally a CGI example to process a form.
     */
    NutRegisterCgi("form.cgi", ShowForm);

    /*
     * Protect the cgi-bin directory with
     * user and password.
     */
    NutRegisterAuth("admin", "root:root");
    NutRegisterAuth("user", "user:user");

    /*
     * Register SSI and ASP handler
     */
#if defined(USE_SSI)
    NutRegisterSsi();
#endif
#if defined(USE_ASP)
    NutRegisterAsp();
    NutRegisterAspCallback(ASPCallback);
#endif

    /*
     * Start four server threads.
     */
    for (i = 1; i <= 4; i++) {
        char thname[] = "httpd0";

        thname[5] = '0' + i;
        NutThreadCreate(thname, Service, (void *) (uintptr_t) i, 
            (HTTPD_SERVICE_STACK * NUT_THREAD_STACK_MULT) + NUT_THREAD_STACK_ADD);
    }
#endif /* DEV_ETHER */

    /*
     * We could do something useful here, like serving a watchdog.
     */
    NutThreadSetPriority(254);
    for (;;) {
        NutSleep(60000);
    }
    return 0;
}
コード例 #19
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);
	}
コード例 #20
0
/*! \fn NicRxLanc(void *arg)
 * \brief NIC receiver thread.
 *
 */
THREAD(NicRxLanc, arg)
{
    NUTDEVICE *dev;
    IFNET *ifn;
    lanc111_nic_t *ni;
    NETBUF *nb;
    uint8_t imsk;

    dev = arg;
    ifn = (IFNET *) dev->dev_icb;
    ni = (lanc111_nic_t *) dev->dev_dcb;

    /*
     * This is a temporary hack. Due to a change in initialization,
     * we may not have got a MAC address yet. Wait until a valid one
     * has been set.
     */
    while (!ETHER_IS_UNICAST(ifn->if_mac)) {
        NutSleep(10);
    }

    /*
     * Do not continue unless we managed to start the NIC. We are
     * trapped here if the Ethernet link cannot be established.
     * This happens, for example, if no Ethernet cable is plugged
     * in.
     */
    while(NicStart(ifn->if_mac)) {
        NutSleep(1000);
    }

    //LANC111_SIGNAL_MODE();

    // Enable IRQs. Enabled on irq allocation.
    //sbi(EIMSK, LANC111_SIGNAL_IRQ);

    NutEventPost(&nic->ni_tx_rdy);

    /* Run at high priority. */
    NutThreadSetPriority(9);

    for (;;) {

        /*
         * Wait for the arrival of new packets or
         * check the receiver every two second.
         */
        NutEventWait(&ni->ni_rx_rdy, 2000);

        /*
         * Fetch all packets from the NIC's internal
         * buffer and pass them to the registered handler.
         */
        imsk = nic_inlb(NIC_MSK);
        nic_outlb(NIC_MSK, 0);
        while ((nb = NicGetPacket()) != 0) {
            if (nb != (NETBUF *) 0xFFFF) {
                ni->ni_rx_packets++;
                (*ifn->if_recv) (dev, nb);
            }
        }
        nic_outlb(NIC_MSK, imsk | INT_RCV | INT_ERCV);
    }
}
コード例 #21
0
ファイル: main.c プロジェクト: aareschluchtje/C-programming
int main(void)
{
    struct _tm timeCheck;

    WatchDogDisable();

    NutDelay(100);

    SysInitIO();

	SPIinit();

	LedInit();

	LcdLowLevelInit();

    Uart0DriverInit();
    Uart0DriverStart();
	LogInit();

    X12Init();

    VsPlayerInit();

    NtpInit();

    NutThreadCreate("BackgroundThread", StartupInit, NULL, 1024);
    NutThreadCreate("BackgroundThread", AlarmSync, NULL, 2500);
    NutThreadCreate("BackgroundThread", AlarmCheck, NULL, 256);

	KbInit();

    SysControlMainBeat(ON);             // enable 4.4 msecs heartbeat interrupt

    /*
     * Increase our priority so we can feed the watchdog.
     */
    NutThreadSetPriority(1);

	/* Enable global interrupts */
	sei();
	
	LcdBackLight(LCD_BACKLIGHT_ON);
    setCurrentDisplay(DISPLAY_DateTime, 5);

    X12RtcGetClock(&timeCheck);
    int hours;
    int mins;
    int secs;
    if(!NutNvMemLoad(100, &hours, sizeof(hours)))
    {
        printf("uren: %d", hours);
    }
    if(!NutNvMemLoad(105, &mins, sizeof(mins)))
    {
        printf(" minuten: %d", mins);
    }
    if(!NutNvMemLoad(110, &secs, sizeof(secs)))
    {
        printf(" seconden %d", secs);
    }
    printf("Welcome to Saltyradio.\nI'm using mac address:  %s\n\n\n", getMacAdress());

    for (;;)
    {
        //Key detecten
        if(KbGetKey() == KEY_01){
            setCurrentDisplay(DISPLAY_DateTime, 5);
        }
        else if(KbGetKey() == KEY_OK)
        {
            if(getCurrentDisplay() == DISPLAY_MainMenu)
            {
                clickOk();
            }
            else if(getCurrentDisplay() == DISPLAY_SettingsMenu)
            {
                clickOkSettings();
            }
            else if(getCurrentDisplay() == DISPLAY_Play || getCurrentDisplay() == DISPLAY_Song)
            {
                clickOkPlay();
            }
            else
            {
                setCurrentDisplay(DISPLAY_MainMenu, 10000);
            }
        }
        else if(KbGetKey() == KEY_LEFT)
        {
            switchLeft();
        }
        else if(KbGetKey() == KEY_RIGHT)
        {
            switchItem();
        }
        else if(KbGetKey() == KEY_DOWN){
            setCurrentDisplay(DISPLAY_Volume, 5);
            volumeDown();
        }else if(KbGetKey() == KEY_UP) {
            setCurrentDisplay(DISPLAY_Volume, 5);
            volumeUp();
        }
        refreshScreen();
        WatchDogRestart();
        NutSleep(100);
    }
    return(0);
}
コード例 #22
0
ファイル: main.c プロジェクト: jessedewaard/ati2.3a5
int main(void)
{
	
    WatchDogDisable();

    NutDelay(100);

    SysInitIO();
	
	SPIinit();
    
	LedInit();
	
	LcdLowLevelInit();
	LcdBackLight(1);
	PrintStr("Starting System");
    Uart0DriverInit();
    Uart0DriverStart();
	LogInit();

    CardInit();

	char custom[48] = ALL;
	
	LoadCustomChars(custom, 6);
	
    X12Init();
    if (X12RtcGetClock(&gmt) == 0)
    {
		LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
    }

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


    RcInit();
    
	KbInit();

    SysControlMainBeat(ON);             // enable 4.4 msecs hartbeat interrupt
	
	ClearLcdScreen();

	//Nieuwe threads aanmaken
    NutThreadCreate("t01", Thread1, NULL, 512);
	NutThreadCreate("time", TimeUpdater, NULL, 512);
	
	//Start netwerk
	int i = initNetworkDHCP();
	LogMsg_P(LOG_INFO, PSTR("Ethernet Startup Message: [%d]"),i);

	//Haal Internet tijd op
	pgmt = getNTPTime();
	X12RtcSetClock(&pgmt);
	//LogMsg_P(LOG_INFO, PSTR("New RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );

    /*
     * Increase our priority so we can feed the watchdog.
     */
    NutThreadSetPriority(1);

	/* Enable global interrupts */
	sei();

	/******************NETWERK**TEST*****************************************************/

	//Maak nieuwe socket
	TCPSOCKET *sock;
	sock = NutTcpCreateSocket();
	//Connect met google.nl
	LogMsg_P(LOG_INFO, PSTR("Connecting client"));
	clientConnect(sock);
	//Zend http req
	clientSend(sock,buffer,sizeof(buffer));

	//Ontvang response in buffer --> grotere buffer (1500)= crash-->heapsize??(8k ram)
	char rcvbuffer [500];
	int rec;
	rec = clientReceive(sock,rcvbuffer,sizeof(rcvbuffer));
	LogMsg_P(LOG_INFO, PSTR("received [%d]"),rec);

	//0 terminate buffer(string)
	//rcvbuffer[499] = 0;

	//Print buffer(http response enz)
	LogMsg_P(LOG_INFO, PSTR("received [%s]"),rcvbuffer);
	
	//Sluit connectie
	clientClose(sock);
	/***********************************************************************************/

	//Main gui besturing??
    for (;;)
    {
        NutSleep(100);
        WatchDogRestart();
    }

    return(0);      
}
コード例 #23
0
/*! \fn AhdlcRx(void *arg)
 * \brief Asynchronous HDLC receiver thread.
 *
 *
 * Running at high priority.
 */
THREAD(AhdlcRx, arg)
{
    NUTDEVICE *dev = arg;
    NUTDEVICE *netdev;
    AHDLCDCB *dcb = dev->dev_dcb;
    IFNET *ifn;
    NETBUF *nb;
    uint8_t *rxbuf;
    uint8_t *rxptr;
    uint16_t rxcnt;
    uint8_t ch;
    uint16_t tbx;
    uint8_t inframe;
    uint8_t escaped;
    uint16_t rxfcs;

    NutThreadSetPriority(9);
    for (;;) {
        /*
         * Reset variables to their initial state
         */
        rxptr = 0;
        rxcnt = 0;
        escaped = 0;
        rxfcs = AHDLC_INITFCS;
        inframe = 0;

        for (;;) {
            /*
             * Wait until the network interface has been attached.
             * This will be initiated by the application calling
             * NutNetIfConfig(), which in turn calls a HDLC_SETIFNET
             * ioctl() to store the NUTDEVICE pointer of the network
             * device in dev_icb and trigger an event on dcb_mf_evt.
             */
            while ((netdev = dev->dev_icb) == 0) {
                if (NutEventWait(&dcb->dcb_mf_evt, 1000) == 0) {
                    NutSleep(100);
                }
            }
            ifn = netdev->dev_icb;
            dcb->dcb_rtimeout = 1000;
            inframe = 0;

            /*
             * Allocate the receive buffer, if this fails, we are in a
             * low memory situation. Take a nap and see, if the
             * situation improved.
             */
            if ((rxbuf = NutHeapAlloc(dcb->dcb_rx_mru)) != 0) {
                break;
            }
            NutSleep(1000);
        }

        /*
         * Signal the link driver that we are up.
         */
        ifn->if_send = AhdlcOutput;
        netdev->dev_ioctl(netdev, LCP_LOWERUP, 0);

        for (;;) {
            /*
             * If we are still connected to a network, fetch the next
             * character from the buffer.
             */
            while (dcb->dcb_rd_idx == dcb->dcb_rx_idx) {
                if (dev->dev_icb == 0)
                    break;
                // TODO: Check for idle timeout. 
                if (NutEventWait(&dcb->dcb_rx_rdy, dcb->dcb_rtimeout)) {
                    continue;
                }
            }

            /*
             * Leave loop if network interface is detached
             */
            if (dev->dev_icb == 0)
                break;

            /*
             * If RAW mode is active, we are not allowing any data encapsulation
             * processing. So we just sleep for a while.
             */
            if (dcb->dcb_modeflags & UART_MF_RAWMODE) {
                /*
                 * It is a must to sleep here, because if we just yield it could create
                 * too much processing in here and stall processing elsewhere. This gives
                 * opportunity to other threads to process incoming data from USART.
                 */
                NutSleep(100);
                continue;
            }

            /*
             * Read next character from input buffer
             */
            ch = dcb->dcb_rx_buf[dcb->dcb_rd_idx++];

            if (inframe) {
                if (ch != AHDLC_FLAG) {
                    if (ch == AHDLC_ESCAPE) {
                        escaped = 1;
                        continue;
                    }
                    if (escaped) {
                        ch ^= AHDLC_TRANS;
                        escaped = 0;
                    }

                    /*
                     * Unless the peer lied to us about the negotiated MRU,
                     * we should never get a frame which is too long. If it
                     * happens, toss it away and grab the next incoming one.
                     */
                    if (rxcnt++ < dcb->dcb_rx_mru) {
                        /* Update calculated checksum and store character in buffer. */
                        tbx = (uint16_t) ((uint8_t) rxfcs ^ ch) << 1;
                        rxfcs >>= 8;
                        rxfcs ^= ((uint16_t) PRG_RDB(fcstab + tbx) << 8) | PRG_RDB(fcstab + tbx + 1);
                        *rxptr++ = ch;
                    } else
                        inframe = 0;
                    continue;
                }

                if (rxcnt > 6 && rxfcs == AHDLC_GOODFCS) {
                    /*
                       * If the frame checksum is valid, create a NETBUF
                       * and pass it to the network specific receive handler.
                     */
                    rxcnt -= 2;
                    if ((nb = NutNetBufAlloc(0, NBAF_DATALINK, rxcnt)) != 0) {
                        memcpy(nb->nb_dl.vp, rxbuf, rxcnt);
                        (*ifn->if_recv) (netdev, nb);
                    }
                }
            }

            /*
             * If frame flag is received, resync frame processing
             */
            if (ch == AHDLC_FLAG) {
                inframe = 1;
                escaped = 0;
                rxptr = rxbuf;
                rxcnt = 0;
                rxfcs = AHDLC_INITFCS;
            }
        }
コード例 #24
0
THREAD(bin_cmd_thread0, arg)
{
	uint8_t count = 0;
	TCPSOCKET * sock;
	char buff[256];
	uint32_t time = 15000;

	NutThreadSetPriority(TCP_BIN_SERVER_PRI);

	if(THISINFO)printf("CMD:Thraed running...\r\n");

	while(1) {
		//if(THISINFO)printf("Start Create Socket(%d)\r\n",count++);
		sock = NutTcpCreateSocket();
		if(sock == 0) {
			if(THISERROR)printf("CMD:Create socket failed!\r\n");
			continue;
		}
		NutTcpSetSockOpt(sock,SO_RCVTIMEO,&time,sizeof(uint32_t));
		if(THISINFO)printf("CMD: NutTcpAccept at port %d\r\n",gwork_port);
		if(NutTcpAccept(sock,gwork_port)) {
			NutTcpCloseSocket(sock);
			if(THISERROR)printf("CMD:NutTcpAccept Timeout! NutTcpCloseSocket and reaccept.\r\n");
			continue;
		}
		if(THISINFO)printf("CMD:Tcp Accept one connection.\r\n");
		count = 0;
		while(1) {
			int len = NutTcpReceive(sock,buff,sizeof(buff));
            if(len == 0) {
				if(THISINFO)printf("Tcp Recieve timeout.\r\n");
				if(++count == 1) {
					if(THISINFO)printf("Tcp Send Io Out Data.\r\n");
				    //NutTcpSend(sock,"OK",strlen("OK"));
					{
						//都继电器状态的模拟请求。
						uint8_t  buffer[sizeof(CmdHead)] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00};
						CmdGetIoOutValue(sock,(CmdHead *)buffer,sizeof(buffer));
					}
				}
				if(++count >= 3) {
					if(THISINFO)printf("Close Command Socket\r\n");
					break;
				}
			} else if(len == -1) {
				int error = NutTcpError(sock);
				if(THISERROR)printf("CMD:Tcp Receive ERROR(%d)\r\n",error);
				if(error == ENOTCONN)  {
					if(THISERROR)printf("CMD:Socket is not connected,break connecting\r\n");
					break;
				} else {
					if(THISERROR)printf("CMD:Socket is unknow error,break connecting\r\n");
					break;
				}
			} else if(len > 0) {
				//printf("Get One Tcp packet length(%d)\r\n",len);
				BinCmdPrase(sock,buff,len);
			}
		}
		NutTcpCloseSocket(sock);
	}
}
コード例 #25
0
ファイル: rtc.c プロジェクト: Tregan/JTI-2.3-A3-IMC
/*!
 * \brief start the alarm check thread
 * 
 * \author Matthijs
 */
void startAlarmThread(void)
{
    NutThreadSetPriority(1);
    NutThreadCreate("AlarmThread1", AlarmThread, NULL, 1024);
}