[En-Nut-Discussion] PPP/memory problem
Alain M.
alainm at pobox.com
Tue Oct 23 19:56:15 CEST 2007
Hi Dave and Daniel,
Thanks very much...
I hope that I can help somewhere else ;-)
Alain
p3stk4 escreveu:
> Brett,
>
> I think I can handle it. If you can send me your app, I can see what I
> can do.
>
> Daniel
>
> Dnia 23-10-2007, Wt o godzinie 22:35 +1300, Brett Abbott pisze:
>> Alain
>>
>> Not sure how best to do this. The original sample app as it stands is
>> still useful and works well as a learning tool as it is clear and
>> simple. For the extended pppdemo someone needs to spend a bit of time
>> to make it portable to gcc and tidy up the formatting - but it does give
>> some insight of what you need to consider when taking the sample to a
>> higher level of production reliability. I'd also feel better if someone
>> more familiar with the PPP engine gives it a looking over as well.
>>
>> pppdemo.c discusses restarts, error recovery, modem management using DTR
>> etc, includes client and server examples, but doesnt yet include
>> PPPPAUSE mode for interjecting modem AT commands into an active PPP
>> stream (not necessary usually but useful for 3 wire modem control). The
>> code needs a bit of prettying up and was written as a demo concept to
>> aid with learning how to use PPP on nutos rather than as an ideal coding
>> example.
>>
>> Any volunteers?
>>
>> Thanks
>> Brett
>>
>> Alain M. wrote:
>>> Could this be incorporated in main version, I intend to use PPP too!!!
>>>
>>> thanks,
>>> Alain
>>>
>>> Brett Abbott escreveu:
>>>
>>>> Daniel
>>>>
>>>> I have an extended sample app developed for nutos/PPP which didnt make
>>>> it into the released code base for some reason. This addresses a number
>>>> of bugs and gives some examples for some of the stuff you are trying to
>>>> do. You might be able to use it to cross check your own code.
>>>>
>>>> Drop me a note directly with your email address if you are interested.
>>>>
>>>> Cheers
>>>> Brett
>>>>
>>>> Michael Müller wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I also experience the same problem running the PPP stack. There seems to
>>>>> be a magic barrier of about 10kB free heap space. If the system
>>>>> (standard Ethernut 1.3 NutOS 4.3.x) under-runs this amount of free
>>>>> memory it becomes instable and crashes immediately. As it happens just
>>>>> with the first dial in and not after many dial processes the memory leak
>>>>> seems to be a different trouble maker.
>>>>>
>>>>> Kind regards
>>>>> Michael
>>>>>
>>>>>
>>>>> p3stk4 schrieb:
>>>>>
>>>>>
>>>>>> Welcome,
>>>>>>
>>>>>> I'm writting a program for device which has to connect via GPRS modem
>>>>>> send (MC35i) and some information to the server. Everything was good
>>>>>> until program become bigger. Than I've noticed a problem with PPP
>>>>>> driver. Without any reason it cannot establish connection (modem says
>>>>>> ERROR/OK) or device hangup or restart.
>>>>>> It seams to be a memory - like problem, because sometimes the
>>>>>> configuration structure in the memory is overwritten with some data.
>>>>>>
>>>>>> How can I solve this problem?
>>>>>>
>>>>>> The device is:
>>>>>> ATmega128 + 64 KB sram memory (3 wait states, one block)
>>>>>> One RS232
>>>>>> and nothing more.
>>>>>>
>>>>>> Configuration file used to build Nut/OS:
>>>>>>
>>>>>> PLATFORM = "ETHERNUT1"
>>>>>> AVR_GCC = ""
>>>>>> MCU_ATMEGA128 = ""
>>>>>> NUTMEM_START = "0x100"
>>>>>> NUTMEM_RESERVED = "64"
>>>>>> NUTXMEM_SIZE = "0xEE00"
>>>>>> NUTXMEM_START = "0x1100"
>>>>>> NUT_CPU_FREQ = "16000000"
>>>>>>
>>>>>> Software:
>>>>>> avr-gcc 4.2.1-1
>>>>>> avr-libc 1.4.5-2
>>>>>> binutils-avr 2.17
>>>>>> Nut/OS 4.4.0.0
>>>>>> Ubuntu Gutsy Gibbon RC
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> The main below.
>>>>>> Regards,
>>>>>> Daniel Lewandowski
>>>>>>
>>>>>>
>>>>>>
>>>>>> /*
>>>>>> * open modem as uart device
>>>>>> */
>>>>>> int modem_open (void)
>>>>>> {
>>>>>> u_long lctl;
>>>>>> char buffer[64];
>>>>>>
>>>>>> strcpy_P(buffer, PSTR("ppp:" PPPCOM "/"));
>>>>>> strncat(buffer, config->pppuser, PPPUSER_MAX);
>>>>>> strcat_P(buffer, PSTR("/"));
>>>>>> strncat(buffer, config->ppppass, PPPPASS_MAX);
>>>>>>
>>>>>> uart = _open(buffer, _O_RDWR | _O_BINARY);
>>>>>> if (uart == -1) {
>>>>>> return -1;
>>>>>> }
>>>>>>
>>>>>> lctl = UARTSPEED;
>>>>>> _ioctl(uart, UART_SETSPEED, &lctl);
>>>>>>
>>>>>> lctl = 1;
>>>>>> _ioctl(uart, UART_SETRAWMODE, &lctl);
>>>>>>
>>>>>> modem_rxto(UARTFSTRXTO);
>>>>>>
>>>>>> _ioctl(uart, HDLC_SETIFNET, 0);
>>>>>> NutSleep(2000);
>>>>>>
>>>>>> return 0;
>>>>>> }
>>>>>>
>>>>>>
>>>>>> /*
>>>>>> * close raw uart
>>>>>> */
>>>>>> int modem_close(void)
>>>>>> {
>>>>>> return _close(uart);
>>>>>> }
>>>>>>
>>>>>>
>>>>>> /*
>>>>>> * make a gprs connection active
>>>>>> */
>>>>>> int modem_gprs_open(void)
>>>>>> {
>>>>>> int rc;
>>>>>> u_long lctl;
>>>>>> char buffer[256];
>>>>>>
>>>>>> lctl = 0;
>>>>>> _ioctl(uart, UART_SETRAWMODE, &lctl);
>>>>>>
>>>>>> strcpy_P(buffer, PSTR("TIMEOUT 30"
>>>>>> " ABORT ERROR"
>>>>>> " ABORT 'NO CARRIER'"
>>>>>> " ABORT 'NO DIALTONE'"
>>>>>> " '' ATH OK AT&D1 OK"
>>>>>> " AT+CGDCONT=1,\"IP\",\""));
>>>>>> strncat(buffer, config->pppapn, PPPAPN_MAX);
>>>>>> strcat_P(buffer, PSTR("\" OK ATD*99***1# CONNECT"));
>>>>>>
>>>>>> rc = NutChat(uart, buffer);
>>>>>> return rc;
>>>>>> }
>>>>>>
>>>>>>
>>>>>> int modem_gprs_close(void)
>>>>>> {
>>>>>> int rc = 0;
>>>>>> u_long lctl;
>>>>>>
>>>>>> _ioctl(uart, HDLC_SETIFNET, 0);
>>>>>> NutSleep(2000);
>>>>>>
>>>>>> MODEM_PORT &= ~_BV(MODEM_DTR); // DTR low
>>>>>>
>>>>>> lctl = 1;
>>>>>> _ioctl(uart, UART_SETRAWMODE, &lctl);
>>>>>>
>>>>>> NutSleep(3000);
>>>>>>
>>>>>>
>>>>>> MODEM_PORT |= _BV(MODEM_DTR); // DTR high
>>>>>> NutSleep(500);
>>>>>>
>>>>>>
>>>>>> return rc;
>>>>>> }
>>>>>>
>>>>>>
>>>>>> /*
>>>>>> * create request frame
>>>>>> */
>>>>>> static void modem_frame_request(char *buffer);
>>>>>> static void modem_frame_alarm(char *buffer);
>>>>>> static void modem_frame_logged(char *buffer);
>>>>>> static void modem_frame_keepalive(char *buffer);
>>>>>>
>>>>>> static int send_data(u_long ip, u_short port, void *data, u_short bytes)
>>>>>> {
>>>>>> int rc;
>>>>>> u_char *msg = (u_char*)data;
>>>>>> u_long sock_to = 5000;
>>>>>> TCPSOCKET *const sock = NutTcpCreateSocket();
>>>>>>
>>>>>> if (sock == NULL) {
>>>>>> return -1;
>>>>>> }
>>>>>>
>>>>>> NutTcpSetSockOpt(sock, SO_RCVTIMEO, &sock_to, sizeof(sock_to));
>>>>>> NutTcpSetSockOpt(sock, SO_SNDTIMEO, &sock_to, sizeof(sock_to));
>>>>>>
>>>>>> rc = NutTcpConnect(sock, ip, port);
>>>>>> if (rc == 0) {
>>>>>> while(bytes > 0) {
>>>>>> rc = NutTcpSend(sock, msg, bytes);
>>>>>> if (rc > 0) {
>>>>>> bytes -= rc;
>>>>>> msg += rc;
>>>>>> }
>>>>>> else if (rc == 0) {
>>>>>> break;
>>>>>> }
>>>>>> else {
>>>>>> break;
>>>>>> }
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> rc = NutTcpCloseSocket(sock);
>>>>>> if (rc) {
>>>>>> return -1;
>>>>>> }
>>>>>>
>>>>>> return 0;
>>>>>> }
>>>>>>
>>>>>>
>>>>>> /*
>>>>>> * send string message to the server
>>>>>> */
>>>>>> static int send_msg(u_long ip, u_short port, char *msg)
>>>>>> {
>>>>>> return send_data(ip, port, msg, strlen(msg));
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> char buffer[64];
>>>>>>
>>>>>> /*
>>>>>> * main loop
>>>>>> */
>>>>>> int main (void)
>>>>>> {
>>>>>> DEVICE_STATE state;
>>>>>> int rc;
>>>>>>
>>>>>> u_char alarm_phone_index = 0;
>>>>>> u_long interval = 0;
>>>>>> u_long next_slot = 0;
>>>>>> PPPDCB *dcb;
>>>>>>
>>>>>> state = INITIALIZE;
>>>>>>
>>>>>> for(;;) {
>>>>>> NutSleep(0);
>>>>>> watchdog_clear();
>>>>>> switch (state) {
>>>>>> case INITIALIZE:
>>>>>> config_init();
>>>>>> adc_init();
>>>>>> leds_init();
>>>>>> amplifier_init();
>>>>>> buttons_init();
>>>>>> modem_init();
>>>>>>
>>>>>> modem_open();
>>>>>> modem_ignite();
>>>>>> state = IDLE;
>>>>>>
>>>>>>
>>>>>> case IDLE:
>>>>>> state = READ_SMS;
>>>>>> break;
>>>>>>
>>>>>>
>>>>>> case OPEN_GPRS:
>>>>>> NutNetIfConfig("ppp", 0, 0, 0);
>>>>>> dcb = devPpp.dev_dcb;
>>>>>> NutDnsConfig2(0, 0, dcb->dcb_ip_dns1, dcb->dcb_ip_dns2);
>>>>>> NutIpRouteAdd(0, 0, dcb->dcb_remote_ip, &devPpp);
>>>>>>
>>>>>> state = WORKING;
>>>>>> break;
>>>>>>
>>>>>>
>>>>>> case CLOSE_GPRS:
>>>>>> modem_gprs_close();
>>>>>> state = IDLE;
>>>>>> break;
>>>>>>
>>>>>>
>>>>>> case WORKING:
>>>>>> ...
>>>>>> break;
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> return 0;
>>>>>> }
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
>>>>>>
>>>>>>
>>>>>>
>>>>> _______________________________________________
>>>>> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
>>>>>
>>>>>
>>>>>
>>>>>
>>> _______________________________________________
>>> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
>>>
>>>
>>>
>> --
>> -----------------------------------------------------------------
>> Brett Abbott, Managing Director, Digital Telemetry Limited
>> Email: Brett.Abbott at digital-telemetry.com
>> PO Box 24 036 Manners Street, Wellington, New Zealand
>> Phone +64 (4) 462-3439 Mobile +64 (21) 656-144
>> ------------------- Commercial in confidence --------------------
>>
>>
>>
>> _______________________________________________
>> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
>
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
More information about the En-Nut-Discussion
mailing list