Esempio n. 1
0
void nano_malloc_stats(RONEARG)
{
    nano_mallinfo(RONECALL);
    fiprintf(stderr, "max system bytes = %10u\n",
             current_mallinfo.arena);
    fiprintf(stderr, "system bytes     = %10u\n",
             current_mallinfo.arena);
    fiprintf(stderr, "in use bytes     = %10u\n",
             current_mallinfo.uordblks);
}
Esempio n. 2
0
int _read(int file, char *ptr, int len) {
  if (len == 0) return 0;

  if (file == 0 || file == 1) {
    // Notice: We don't read from USB with stdio, implement the usbLine callback in stead

  } else if (file < 10) {
    // Notice: We don't read from UARTS with stdio, implement the handleUart?Line callbacks in stead

  } else {
    int fd = file-10;

    if (fd < fatFilesOpen) {
      unsigned int res;
      FRESULT rr = f_read(&fatFiles[fd].fil, 
			  ptr, len, &res);
      if (rr) {
	fiprintf(stderr, "Failed to read FAT file %d: %d\n\r", fd, rr);
	errno = EINVAL;
	return -1;
      } else {
	errno = 0;
	return res;
      }   
    }
  }

  errno = EINVAL;
  return -1;
}
Esempio n. 3
0
void __hactar_assert(const char* file, int line, const char* func,
        const char* expr)
{
    fflush(stdout);
    fiprintf(stderr, "ASSERT: %s[%i]\n%s (%s)\n", file, line, func, expr);
    while(1);
}
Esempio n. 4
0
int _close(int file) {
  if (file < 10) {
    return -1; // We don't support closing a device.

  } else {
    int fd = file-10;

    if (fd < fatFilesOpen) {
      FRESULT cr = f_close(&fatFiles[fd].fil);
      if (cr) {
	fiprintf(stderr, "Failed to close FAT file %d: %d\n\r", fd, cr);
	errno = EIO;
	return -2;

      } else {
	for (int i=fd;i<fatFilesOpen-1;i++) {
	  fatFiles[i] = fatFiles[i+1];
	}
	fatFilesOpen--;
	errno = 0;
	return 0;
      }
    }
    
    return -1;
  }
}
Esempio n. 5
0
void menuPrintConfig(FILE* file) {
    for (int i=0; i<numMenus; i++) {
        for (int j=0; j<menuList[i].numOptions; j++) {
            if (menuList[i].options[j].numValues != 0)
                fiprintf(file, "%s=%d\n", menuList[i].options[j].name, menuList[i].options[j].selection);
        }
    }
}
Esempio n. 6
0
FATFS *getFat() {
  if (!fsMounted) {
    FRESULT mr = f_mount(0, &fatFsInstance);
    if (mr) {
      fiprintf(stderr, "Failed to initialize FAT layer (f_mount() said: %d\n\r", mr);
      return 0;
    }
    fsMounted = 1;
  }
  return &fatFsInstance;
}
Esempio n. 7
0
File: main.c Progetto: cdrttn/keeper
/*
 * Application entry point.
 */
int main(void)
{
#if 0
	static const evhandler_t evhndl[] = {
		InsertHandler,
		RemoveHandler
	};
#endif
	/*
	* System initializations.
	* - HAL initialization, this also initializes the configured device drivers
	*   and performs the board-specific initializations.
	* - Kernel initialization, the main() function becomes a thread and the
	*   RTOS is active.
	*/
	halInit();
	chSysInit();
	crypto_init();
	buttons_init();

	chHeapInit(fast_heap, FAST_HEAP_ADDR, FAST_HEAP_SIZE);

	sdStart(&SD2, NULL);
	palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
	palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
	lcd_init();

	setvbuf(stdin, NULL, _IONBF, 0);

	mmcObjectInit(&MMCD1);
	mmcStart(&MMCD1, &mmccfg);
	mount_card();

	pwmStart(&PWMD1, &lcd_pwmcfg);
	palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(1));

	// XXX moveme
	palSetPadMode(GPIOB, 6, PAL_MODE_INPUT_PULLUP);
	palSetPadMode(GPIOB, 15, PAL_MODE_INPUT_PULLUP);
	palSetPadMode(GPIOB, 14, PAL_MODE_INPUT_PULLUP);
	palSetPadMode(GPIOC, 10, PAL_MODE_INPUT_PULLUP);
	palSetPadMode(GPIOC, 11, PAL_MODE_INPUT_PULLUP);

	fiprintf(lcd_stdout, "HIHI");
	while (TRUE) {
		console_cmd_loop();
		//chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS));
	}

	return 0;
}
Esempio n. 8
0
int main(void) {
  fiprintf(stderr, "Power Up!\n\r");
  
  while (1) {
    GPIO_SET(IO_LED);
    GPIO_SET(IO_ASSIST_AIR);
    GPIO_CLEAR(IO_EXHAUST);
    GPIO_CLEAR(IO_LASER_FIRE);
    delay(500);

    GPIO_CLEAR(IO_LED);
    GPIO_CLEAR(IO_ASSIST_AIR);
    GPIO_SET(IO_EXHAUST);
    GPIO_SET(IO_LASER_FIRE);
    delay(500);

    fiprintf(stderr, "USB connected: %d\n\r", usbConnected());
    if (usbConnected()) {
      usbSendFlush(TESTHEST, sizeof(TESTHEST));
    }

    fiprintf(stderr, "Airflow: %d (%d %%)\n\r", READ_ADC(IO_AIRFLOW), airflow());

    fprintf(stderr, "T out:   %d (%f Ohm, %f degC)\n\r",
	   READ_ADC(IO_TEMP_OUT),
	   readNTCres(IO_CHAN(IO_TEMP_OUT)),
	   readNTCcelcius(IO_CHAN(IO_TEMP_OUT))
	   );

    fprintf(stderr, "T in:    %f degC\n\r", readNTCcelcius(IO_CHAN(IO_TEMP_IN)));
    fprintf(stderr, "T inter: %f degC\n\r", readNTCcelcius(IO_CHAN(IO_TEMP_INTERNAL)));
    fiprintf(stderr, "Supply:  %d mv\n\r", supplyVoltage());        
    
    unsigned int err0 = errorUART(IO_DEBUG_RX);
    if (err0) {
      fiprintf(stderr, "Debug UART Error: %x\n\r", err0);        
    }

    err0 = errorUART(IO_WATCHDOG_RX);
    if (err0) {
      fiprintf(stderr, "Watchdog UART Error: %x\n\r", err0);        
    }
    err0 = errorUART(IO_CHILLER_RX);
    if (err0) {
      fiprintf(stderr, "Chiller UART Error: %x\n\r", err0);        
    }
  }
}
Esempio n. 9
0
int _write(int file, char *ptr, int len) {
  if (len == 0) return 0;

  if (file == 0 || file == 1) {
    usbSend(ptr, len);
    return len;

  } else if (file < 10) {
    unsigned int port = UART_FD[file];
    if (port) {
      int totalSent = 0;
      while (len > 0) {
	int sent = sendUART(port, ptr, len);
	len -= sent;
	ptr += sent;
	totalSent += sent;
      }
      return totalSent;
    } else {
      return -1;
    }

  } else {
    int fd = file-10;

    if (fd < fatFilesOpen) {
      unsigned int res;
      if (fatFiles[fd].append) {
	_lseek(file, 0, SEEK_END);
      }
      FRESULT rr = f_write(&fatFiles[fd].fil, ptr, len, &res);
      if (rr) {
	fiprintf(stderr, "Failed to write FAT file %d (bytes: %d): %d\n\r", fd, len, rr);
	errno = EINVAL;
	return -1;
      } else {
	errno = 0;
	return res;
      }   
    }
  }  
  errno = EINVAL;
  return -1;
}
Esempio n. 10
0
int _lseek(int file, int ptr, int dir) {
  int fd = file-10;
  if (fd < fatFilesOpen) {
    
    int cur = f_tell(&fatFiles[fd].fil);

    if (dir == SEEK_CUR) {
      ptr -= cur;

    } else if (dir == SEEK_END) {
      ptr = f_size(&fatFiles[fd].fil) - ptr;

    } /* else if (dir == SEEK_SET) {
      // ptr is ready to go.
    }
    */

    if (ptr == cur) {
      errno = 0;
      return ptr;
    }

    FRESULT sr = f_lseek(&fatFiles[fd].fil, ptr);
    if (sr) {
      fiprintf(stderr, "Failed to seek FAT file %d: %d\n\r", fd, sr);
      errno = EINVAL;
      return -1;
    } else {
      errno = 0;
      return ptr;
    }   
  }

  errno = EINVAL;
  return -1;
}
Esempio n. 11
0
/*-------------------------------------------------------------------
 * This POST handler will process the incoming application file
 * and reprogram the NetBurner device's application flash memory.
 * If the reboot checkbox was checked, it will reboot the NetBurner
 * device.
 * ----------------------------------------------------------------*/
int MyDoPost( int sock, char *url, char *pData, char *rxBuffer )
{
    char tmp[MAX_PATH_LEN];
    BOOL bReboot = FALSE;
    BOOL bSuccess = FALSE;

    // Look for reboot checkbox
    int rv = ExtractPostData( "cbox", pData, tmp, MAX_PATH_LEN );
    if ( rv > 0 ) {
        bReboot = TRUE;
    }

    SendHTMLHeader( sock );
    clrsockoption( sock, SO_NOPUSH );
    writestring( sock, "<HTML><BODY><B>Starting to examine uploaded file<BR>" );

    // Process application file
    int fd = ExtractPostFile( "userfile1", pData, NULL );
    if ( fd > 0 ) {
        int rv = read( fd, tmp, 2 );
        if ( ( rv == 2 ) && ( tmp[0] == 'S' ) && ( tmp[1] == '0' ) ) {
            int n = 0;
            writestring( sock, "Found S0 record <BR>" );
            char *cp = tmp;
            while ( ( rv == 1 ) && ( n < 20 ) ) {
                rv = read( fd, cp, 1 );
                n++;
                if ( *cp == '\r' ) {
                    *cp = 0;
                    if ( strcmp( tmp, PlatformName ) == 0 ) {
                        writestring( sock,
                                    "File platforms match<BR>Beginning to program app file<BR>"
                                    );
                        if ( ReadS19ApplicationCodeFromStream( fd ) == STREAM_UP_OK ) {
                            writestring( sock, "<BR><BR>File update worked<BR>" );
                            bSuccess = TRUE;
                            if ( bReboot ) {
                                FILE *fpo = fdopen( sock, "w" );
                                PBYTE ipb = ( PBYTE ) & EthernetIP;
                                fiprintf( fpo, "Board will complete reboot in %d second<BR>\r\n",
                                          gConfigRec.wait_seconds + 2
                                        );
                                fiprintf( fpo,
                                          "To load the new web page click "
                                          "<A HREF=\"http://%d.%d.%d.%d\">here</a><BR>\r\n",
                                          ( int ) ipb[0],
                                          ( int ) ipb[1],
                                          ( int ) ipb[2],
                                          ( int ) ipb[3]
                                        );
                                fclose( fpo );
                            }
                            else {
                                writestring( sock,
                                             "The board was not rebooted, you must reboot for "
                                             "the change to take effect.<BR>"
                                            );
                            }
                        }
                        else {
                            writestring( sock, "<H1>File update failed</H1><BR>" );
                        }
                    }
                    else {
                        writestring( sock, "File platforms fail to match, wanted:" );
                        writestring( sock, PlatformName );
                        writestring( sock, " Got " );
                        writestring( sock, tmp );
                        writestring( sock, "<BR>" );
                    }
                    break;
                }
                if ( rv == 1 ) {
                    cp++;
                }
            }

        }
        else {
            writestring( sock, "Failed to find S0 record <BR>" );
        }
        close( fd );
    }
    else {
        writestring( sock, "Failed to extract file<BR>" );
    }

    writestring( sock, "</B></BODY></HTML>" );

    close( sock );

    if ( ( bReboot ) && ( bSuccess ) ) {
        OSTimeDly( TICKS_PER_SECOND * 2 );
        ForceReboot();
    }
    return 0;
}
Esempio n. 12
0
static int nastylog_stderr(const char *tag, const char *format, va_list args) {
    fiprintf(stderr, "%s: ", tag);
    vfiprintf(stderr, format, args);
    return 0;
}
Esempio n. 13
0
void handleUart3Line(const char *line, int lineLength) {
  if (lineLength) {
    fiprintf(stderr, "WD said: %s\n\r", line);
  }
}
Esempio n. 14
0
int _open(const char *name, int flags, int mode) {

  if (!strcmp(name, "/dev/stdin")) {
    return 0;

  } else if (!strcmp(name, "/dev/stdout")) {
    return 1;
    
  } else if (!strcmp(name, "/dev/stderr")) {
    return 2;

  } else if (!strcmp(name, "/dev/watchdog")) {
    return 3;

  } else if (!strcmp(name, "/dev/chiller")) {
    return 4;

  } else if (!strncmp(name, SD, sizeof(SD)-1)) {

    if (fatFilesOpen >= MAX_FAT_FILES) {
      errno = EMFILE;
      return -3;
    }
    
    if (!getFat()) {
      errno = ENODEV;
      return -4;
    }

    const char *ffn = name+sizeof(SD)-2; // chop off "/sd", but leave the leading /

    char fflags = 0;
    if (flags & O_RDONLY) {
      fflags |= FA_READ;

    } else if (flags & O_WRONLY) {
      fflags |= FA_WRITE;

    } else /* if (flags & O_RDWR) */ {
      fflags |= FA_READ | FA_WRITE;      
    }

    if (flags & O_CREAT) {
      fflags |= FA_OPEN_ALWAYS;

    } else if (flags & O_TRUNC) {
      fflags |= FA_CREATE_ALWAYS;    

    } else {
      fflags |= FA_OPEN_EXISTING;          
    }

    int fd = fatFilesOpen;
    FRESULT or = f_open(&fatFiles[fd].fil, ffn, fflags);
    
    if (!or) {      
      fatFilesOpen++;
      fatFiles[fd].append = flags & O_APPEND;      
      errno = 0;
      return fd+10;
    }

    if (or == FR_EXIST) {
      errno = EEXIST;

    } else if (or == FR_TOO_MANY_OPEN_FILES) {
      errno = ENFILE;

    } else if (or == FR_NO_FILE || or == FR_NO_PATH || or == FR_INVALID_NAME) {
      errno = ENOENT;

    } else {
      fiprintf(stderr, "Failed to open FAT file %s: %d\n\r", ffn, or);
      errno = EIO;
    }

    return -5;
  }

  return -1;
}