Esempio n. 1
0
void _exit(int status)
{
  _write(STDERR_FILENO, "exit", 4);
  do {} while (1);
}
Esempio n. 2
0
size_t __cdecl fwrite (
#endif
    const void *buffer,
    size_t size,
    size_t num,
    FILE *stream
)
{
    const char *data;		/* point to where data comes from next */
    unsigned total; 		/* total bytes to write */
    unsigned count; 		/* num bytes left to write */
    unsigned bufsize;		/* size of stream buffer */
    unsigned nbytes;		/* number of bytes to write now */
    unsigned nwritten;		/* number of bytes written */
    int c;				/* a temp char */

    /* initialize local vars */
    data = buffer;
    count = total = size * num;
    if (0 == count)
        return 0;

    if (anybuf(stream))
        /* already has buffer, use its size */
        bufsize = stream->_bufsiz;
    else
#if	defined(_M_M68K) || defined(_M_MPPC)
        /* assume will get BUFSIZ buffer */
        bufsize = BUFSIZ;
#else	/* ndef defined(_M_M68K) || defined(_M_MPPC) */
        /* assume will get _INTERNAL_BUFSIZ buffer */
        bufsize = _INTERNAL_BUFSIZ;
#endif	/* defined(_M_M68K) || defined(_M_MPPC) */

    /* here is the main loop -- we go through here until we're done */
    while (count != 0) {
        /* if the buffer is big and has room, copy data to buffer */
        if (bigbuf(stream) && stream->_cnt != 0) {
            /* how much do we want? */
            nbytes = (count < (unsigned)stream->_cnt) ? count : stream->_cnt;
            memcpy(stream->_ptr, data, nbytes);

            /* update stream and amt of data written */
            count -= nbytes;
            stream->_cnt -= nbytes;
            stream->_ptr += nbytes;
            data += nbytes;
        }
        else if (count >= bufsize) {
            /* If we have more than bufsize chars to write, write
               data by calling write with an integral number of
               bufsiz blocks.  If we reach here and we have a big
               buffer, it must be full so _flush it. */

            if (bigbuf(stream)) {
                if (_flush(stream)) {
                    /* error, stream flags set -- we're out
                       of here */
                    return (total - count) / size;
                }
            }

            /* calc chars to read -- (count/bufsize) * bufsize */
            nbytes = ( bufsize ? (count - count % bufsize) :
                       count );

#ifdef	_POSIX_
            nwritten = write(fileno(stream), data, nbytes);
#else
            nwritten = _write(_fileno(stream), data, nbytes);
#endif
            if (nwritten == (unsigned)EOF) {
                /* error -- out of here */
                stream->_flag |= _IOERR;
                return (total - count) / size;
            }

            /* update count and data to reflect write */

            count -= nwritten;
            data += nwritten;

            if (nwritten < nbytes) {
                /* error -- out of here */
                stream->_flag |= _IOERR;
                return (total - count) / size;
            }
        }
        else {
            /* buffer full and not enough chars to do direct write,
               so do a _flsbuf. */
            c = *data;  /* _flsbuf write one char, this is it */
            if (_flsbuf(c, stream) == EOF) {
                /* error or eof, stream flags set by _flsbuf */
                return (total - count) / size;
            }

            /* _flsbuf wrote a char -- update count */
            ++data;
            --count;

            /* update buffer size */
            bufsize = stream->_bufsiz > 0 ? stream->_bufsiz : 1;
        }
    }

    /* we finished successfully, so just return num */
    return num;
}
int
__flushbuf(int c, FILE * stream)
{
	_clean = __cleanup;
	if (fileno(stream) < 0) return (unsigned char) c;
	if (!io_testflag(stream, _IOWRITE)) return EOF;
	if (io_testflag(stream, _IOREADING) && !feof(stream)) return EOF;

	stream->_flags &= ~_IOREADING;
	stream->_flags |= _IOWRITING;
	if (!io_testflag(stream, _IONBF)) {
		if (!stream->_buf) {
			if (stream == stdout && _isatty(fileno(stdout))) {
				if (!(stream->_buf =
					    (unsigned char *) malloc(BUFSIZ))) {
					stream->_flags |= _IONBF;
				} else {
					stream->_flags |= _IOLBF|_IOMYBUF;
					stream->_bufsiz = BUFSIZ;
					stream->_count = -1;
				}
			} else {
				if (!(stream->_buf =
					    (unsigned char *) malloc(BUFSIZ))) {
					stream->_flags |= _IONBF;
				} else {
					stream->_flags |= _IOMYBUF;
					stream->_bufsiz = BUFSIZ;
					if (!io_testflag(stream, _IOLBF))
						stream->_count = BUFSIZ - 1;
					else	stream->_count = -1;
				}
			}
			stream->_ptr = stream->_buf;
		}
	}

	if (io_testflag(stream, _IONBF)) {
		char c1 = c;

		stream->_count = 0;
		if (io_testflag(stream, _IOAPPEND)) {
			if (_lseek(fileno(stream), 0L, SEEK_END) == -1) {
				stream->_flags |= _IOERR;
				return EOF;
			}
		}
		if (_write(fileno(stream), &c1, 1) != 1) {
			stream->_flags |= _IOERR;
			return EOF;
		}
		return (unsigned char) c;
	} else if (io_testflag(stream, _IOLBF)) {
		*stream->_ptr++ = c;
		/* stream->_count has been updated in putc macro. */
		if (c == '\n' || stream->_count == -stream->_bufsiz) {
			int count = -stream->_count;

			stream->_ptr  = stream->_buf;
			stream->_count = 0;

			if (io_testflag(stream, _IOAPPEND)) {
				if (_lseek(fileno(stream), 0L, SEEK_END) == -1) {
					stream->_flags |= _IOERR;
					return EOF;
				}
			}
			if (! do_write(fileno(stream), (char *)stream->_buf,
					count)) {
				stream->_flags |= _IOERR;
				return EOF;
			}
		}
	} else {
		int count = stream->_ptr - stream->_buf;

		stream->_count = stream->_bufsiz - 1;
		stream->_ptr = stream->_buf + 1;

		if (count > 0) {
			if (io_testflag(stream, _IOAPPEND)) {
				if (_lseek(fileno(stream), 0L, SEEK_END) == -1) {
					stream->_flags |= _IOERR;
					return EOF;
				}
			}
			if (! do_write(fileno(stream), (char *)stream->_buf, count)) {
				*(stream->_buf) = c;
				stream->_flags |= _IOERR;
				return EOF;
			}
		}
		*(stream->_buf) = c;
	}
	return (unsigned char) c;
}
Esempio n. 4
0
void _exit(int status) {
    _write(1, "exit", 4);
    while (1) {
        ;
    }
}
Esempio n. 5
0
void inline
Writer::_writeFloat(float value) {
    assert(sizeof value == 4);
    _write((const char *)&value, sizeof value);
}
 //---------------------------------------------------------------------
 void Writer::writeString(const String& string)
 {
     uint32 numChars = string.length();
     writeInts(&numChars);
     _write(string.c_str(), sizeof(String::value_type), numChars);
 }
Esempio n. 7
0
/**
 * @brief
 * @note
 * @param
 * @retval
 */
size_t UIPClient::write(uint8_t c) {
    return _write(data, &c, 1);
}
Esempio n. 8
0
size_t
UIPClient::write(uint8_t c)
{
  return _write(_uip_conn, &c, 1);
}
Esempio n. 9
0
size_t
UIPClient::write(const uint8_t *buf, size_t size)
{
  return _write(_uip_conn, buf, size);
}
/*!
 * \brief Write a string to a stream.
 *
 * \param stream Pointer to a previously opened stream.
 * \param string String to write.
 *
 * \return A non-negative value if successful or EOF to indicate an error.
 *
 * \warning The function will not check, if the stream pointer points
 *          to a valid stream.
 */
    int fputs(CONST char *string, FILE * stream)
{
    return _write(stream->iob_fd, string, strlen(string));
}
Esempio n. 11
0
int main(int argc, char * argv[], char * env[])
{
	char line[128], command[128], pathname[128];
	int ID;
	
	// DEVICE SELECT
	get_device();

	// INITIALIZE 
	init();
	
	// MOUNT ROOT
	mount_root();

	// PROCESS LOOP
	while(1)
	{
		strcpy(line, "");
		strcpy(command, "");
		strcpy(pathname, "");
		strcpy(completePath, "");

		printf("\n\ninput a command (type help for more info): ");
		//read a line containting  command [pathname]; // [ ] means optional
		fgets(line, 256, stdin);
		line[strlen(line)-1] = '\0';

		//Find the command string and call the corresponding function;
		parseString(line, arg1, command, pathname);

		compPath(pathname);
		
		
		printf("PATHNAME: %s\n", pathname);
		ID = findCommand(command);
		switch(ID)
		{
			case -1 : printDir(running->cwd->ino);	break;
			case  0 : _menu  (arg1, pathname);	break;
			case  1 : _ls    (arg1, pathname);	break;
			case  2 : _cd    (arg1, pathname);	break;
			case  3 : _mkdir (arg1, pathname);	break;
			case  4 : _rmdir (arg1, pathname);	break;
			case  5 : _pwd   (arg1, pathname);	break;
			case  6 : _creat0(arg1, pathname);	break;
			case  7 : _rm    (arg1, pathname);	break;
			case  8 : _stat  (arg1, pathname);	break;
			case  9 : compPath(arg1); _link(arg1, pathname); break;
			case  10: _unlink(arg1, pathname); break;
			case  11: compPath(arg1); _symlink(arg1, pathname); break;
			case  12: _touch (arg1, pathname);	break;
			case  13: _chmod (arg1, pathname);	break;
			case  14: _chown (arg1, pathname);	break;
			case  15: _chgrp (arg1, pathname);	break;
			case  16: _open  (arg1, pathname);	break;
			case  17: _close (arg1, pathname);	break;
			case  18: _read  (arg1, pathname);	break;
			case  19: _write (arg1, pathname);	break;
			case  20: _pfd   (arg1, pathname);	break;
			case  21: _lseek (arg1, pathname);	break;
			case  22: _cat   (arg1, pathname);	break;
			case  23: _cp    (arg1, pathname);	break;
			case  24: _mv    (arg1, pathname);	break;
			case  25: __exit (arg1, pathname);	break;
		}
	}
	
	quit();
	return 0;
}
Esempio n. 12
0
void inline
Writer::_writeByte(char c) {
    _write(&c, 1);
}
Esempio n. 13
0
void inline
Writer::_writeString(const char *str) {
    size_t len = strlen(str);
    _writeUInt(len);
    _write(str, len);
}
Esempio n. 14
0
void inline
Writer::_writeDouble(double value) {
    assert(sizeof value == 8);
    _write((const char *)&value, sizeof value);
}
Esempio n. 15
0
int fputc (int c, FILE *fp)
{
	return _write(fp->_file, (char*) &c, 1);	
}
Esempio n. 16
0
/**
 * Interrupt 80h. Handles the system calls.
 *
 *  @param regs Pointer to struct containing micro's registers.
 */
void int80(registers* regs) {

    switch (regs->eax) {

        case _SYS_READ:
            regs->eax = _read((unsigned int)regs->ebx, (char*)translate(regs->ecx), (size_t)regs->edx);
            break;
        case _SYS_WRITE:
            regs->eax = _write((unsigned int)regs->ebx, (const char*)translate(regs->ecx), (size_t)regs->edx);
            break;
        case _SYS_TIME:
            regs->eax = _time((time_t*)translate(regs->ebx));
            break;
        case _SYS_IOCTL:
            regs->eax = _ioctl(regs->ebx, regs->ecx, (void*)translate(regs->edx));
            break;
        case _SYS_TICKS:
            regs->eax = _getTicksSinceStart();
            break;
        case _SYS_YIELD:
            // This just makes sure we call the scheduler again, for now
            break;
        case _SYS_EXIT:
            _exit();
            break;
        case _SYS_GETPID:
            regs->eax = _getpid();
            break;
        case _SYS_GETPPID:
            regs->eax = _getppid();
            break;
        case _SYS_RUN:
            regs->eax = _run((EntryPoint) translate(regs->ebx), (char*) translate(regs->ecx), regs->edx);
            break;
        case _SYS_WAIT:
            regs->eax = _wait();
            break;
        case _SYS_KILL:
            _kill((pid_t) regs->ebx);
            break;
        case _SYS_PINFO:
            regs->eax = _pinfo((struct ProcessInfo*)translate(regs->ebx), (size_t)regs->ecx);
            break;
        case _SYS_SLEEP:
            _sleep(regs->ebx);
            break;
        case _SYS_NICE:
            regs->eax = _nice(regs->ebx);
            break;
        case _SYS_RENICE:
            regs->eax = _renice(regs->ebx, regs->ecx);
            break;
        case _SYS_CLOSE:
            regs->eax = _close(regs->ebx);
            break;
        case _SYS_OPEN:
            regs->eax = _open((char*)translate(regs->ebx), regs->ecx, regs->edx);
            break;
        case _SYS_CREAT:
            regs->eax = _creat((char*)translate(regs->ebx), regs->ecx);
            break;
        case _SYS_MKDIR:
            regs->eax = _mkdir((const char*)translate(regs->ebx), regs->ecx);
            break;
        case _SYS_RMDIR:
            regs->eax = _rmdir((const char*)translate(regs->ebx));
            break;
        case _SYS_UNLINK:
            regs->eax = _unlink((const char*)translate(regs->ebx));
            break;
        case _SYS_RENAME:
            regs->eax = _rename((const char*)translate(regs->ebx), (const char*)translate(regs->ecx));
            break;
        case _SYS_CHDIR:
            regs->eax = _chdir((const char*)translate(regs->ebx));
            break;
        case _SYS_GETCWD:
            regs->eax = _getcwd((char*)translate(regs->ebx), (size_t)regs->ecx);
            break;
        case _SYS_READDIR:
            regs->eax = _readdir(regs->ebx, (struct fs_DirectoryEntry*)translate(regs->ecx), regs->edx);
            break;
        case _SYS_SETPPERSONA:
            _setProcessPersona(regs->ebx, regs->ecx, regs->edx);
            break;
        case _SYS_GETPPERSONA:
            _getProcessPersona(regs->ebx, (int*)translate(regs->ecx), (int*) translate(regs->edx));
            break;
        case _SYS_SYMLINK:
            regs->eax = _symlink((const char *)translate(regs->ebx), (const char *)translate(regs->ecx));
            break;
        case _SYS_MKFIFO:
            regs->eax = _mkfifo((const char*)translate(regs->ebx));
            break;
        case _SYS_CHMOD:
            regs->eax = _chmod(regs->ebx, (const char*)translate(regs->ecx));
            break;
        case _SYS_STAT:
            regs->eax = _stat((const char*)translate(regs->ebx), (struct stat*)translate(regs->ecx));
            break;
        case _SYS_CHOWN:
            regs->eax = _chown((const char*)translate(regs->ebx));
            break;
        case _SYS_LOG:
            _loglevel(regs->ebx);
            break;
        case _SYS_STACKSIZE:
            regs->eax = _stacksize();
    }
}
Esempio n. 17
0
int exec_cmd(int under_glob, int under_until)
	{
	register int status;
	register char *p;
	int n;

	if((status = getrange()) <= ERROR)
		return( status );
	status = ERROR9;

	switch( *lp++ ) {

	case 'i':
		laddr2 = prevln(laddr2);

	case 'a':
		status = append(laddr2, under_glob);
		break;

	case 'b':
			if(!under_glob  &&  !under_until)
				status = branch();
		break;

	case 'c':
		if((status = delete(laddr1, laddr2, SAVE)) == OK)
			status = append(prevln(laddr1), under_glob);
		break;

	case 'd':
		if((status = delete(laddr1, laddr2, SAVE)) == OK && nextln(curln) != 0)
			curln = nextln(curln);
		break;

	case 'e':
		if(lastln  &&  dirty  &&  *lp != 'e') {
			status = ERROR4;
			break;
			}

		if(*lp == 'e')
			++lp;

		if(nladdrs == 0  &&  !under_glob  &&  !under_until  &&
			(status = getfn()) == OK) {
			set_fn(curfile, lp);
			if(lastln != 0)
				delete(1, lastln, NOSAVE);
			num_delete_lines = 0;
			if((status = _read( lp, 0, 0)) == OK) {
				dirty = 0;
				if(lastln)
					curln = 1;
				}
			}
		lp = "\n";
		break;

	case 'f':
		if(nladdrs == 0  &&  (status = getfn()) == OK) {
			set_fn(curfile, lp);
			putmsg(curfile);
			lp = "\n";
			}
		change_state(CMD);
		break;

	case 'g':
		if(!under_glob) {
			if(*lp == '^') {
				++lp;
				n = 0;
				}
			else
				n = 1;
			status = exec_glob(n, under_until);
			}
		break;

	case 'h':
		n = getint();
#ifndef __STDC__
		while(n--)
			for(n1 = 0; n1 < 10; ++n1)
				time_slice();
#endif
		status = OK;
		break;

	case 'j':
		status = join(laddr2);
		break;

	case 'k':
		if((status = get_laddr_expr(&n)) == OK)
			status = kopy(n);
		break;

	case 'l':
		if(nladdrs == 0)
			status = learn();
		break;

	case 'm':
		if((status = get_laddr_expr(&n)) == OK)
			status = move(n);
		break;

	case 'o':
		status = option();
		break;

	case 'p':
	case 'P':
		status = prnt(laddr1, laddr2);
		break;

	case 'q':
		if(nladdrs==0 && !under_glob) {
			if((*lp=='\n' && !dirty) || *lp=='q'  ||  lastln == 0)
				status = EOF;
			else
				status = ERROR4;
		}
		break;

	case 'r':
		if(!under_glob  &&  !under_until  &&  (status = getfn()) == OK)
			status = _read(lp, laddr2, 0);
		lp = "\n";
		break;

	case 's':
		n = getint(); /* read occurance if present */
		if((status=getpat()) == OK  &&  (status=getsubst_str(tbuff)) == OK)
			status = substitute(tbuff, under_glob, n);
		break;

	case 't':
	case 'T':
		if(nladdrs == 0)
			status = translate(*(lp - 1) == 't');
		break;

	case 'u':
		status = until(laddr1, laddr2, under_glob);
		break;

	case 'v':
		if(nladdrs <= 1)
			status = view(laddr1);
		break;

	case 'w':
		n = 0;
		if(*lp == 'w') {
			n |= 2;
			++lp;
			}
		if(*lp == 'a') {
			n |= 1;
			++lp;
			}

		if((status = getfn()) == OK) {
			if(nladdrs == 0) {
				if(curfile[0] == '\0')
					set_fn(curfile, lp);
				else {
					if((n & 2) == 0  &&  strcmp(curfile, lp) != 0) {
						for(p = lp ; *p ; ++p)
							if(*p == '$')
								goto ok;
						puterr(-19);
						lp = "\n";
						break;
						}
					}
				ok:
				if((status = _write(lp, 1, lastln, n & 1, 0)) == OK)
					dirty = 0;
				}
			} else {
				status = _write(lp, laddr1, laddr2, n & 1, 0);
			}
		lp = "\n";
		break;

    case 'x':
		if(!under_glob  &&  !under_until  &&  (status = getfn()) == OK)
			if(nladdrs == 0)
				status = exec_file(lp, under_glob, under_until);
		lp = "\n";
		break;

	case 'y':
		status = yut();
		break;

	case 'z':
		status = zap();
		break;

	case '\n':
		--lp; /* put back newline for main */
		if(laddr2 < 0  ||  laddr2 > lastln)
			status = lastln ? ERROR5 : OK;
		else {
			curln = laddr2;
			status = OK;
			}
		break;

	case ' ':
	case '\t':
	case CMD_CHAR:
		status = OK;
		break;

	case '=':
		dtoc(rbuff, laddr2);
		if(under_glob)
			prnt_screen(rbuff, 1);
		else
			putmsg(rbuff);
		status = OK;
		break;

	case '"':
		lp = "\n";	/* Ignore rest of line */
		status = OK;
		break;

	case '!':
		if(escape_char == 0  ||  restrict_flag) {
			putmsg("Escape from ED inhibited");
			status = NOTHING;
			}
		else
			status = exec_sys_cmd(under_glob, under_until);
		break;

	default:
		status = ERROR2;
		}
	return(status);
	}
Esempio n. 18
0
void romsave(char *path, char *rom, int size)
{
	int fp = _open(path, _O_RDWR | _O_BINARY | _O_CREAT, _S_IREAD | _S_IWRITE);
	_write(fp, rom, size);
	_close(fp);
}
Esempio n. 19
0
 //---------------------------------------------------------------------
 void Writer::writeData(const void* data, size_t size)
 {
     _write(data, size, 1);
 }
Esempio n. 20
0
/**
 * Initialisation of the Aptina MT9V117 CMOS sensor
 * (1/6 inch VGA, bottom camera)
 */
void mt9v117_init(void)
{
  struct timespec tim;
  char test[2];

  /* Start PWM 9 (Which probably is the clock of the MT9V117) */
  int pwm9 = open("/sys/class/pwm/pwm_9/run", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  write(pwm9, "0", 1);
  write(pwm9, "1", 1);
  close(pwm9);

  tim.tv_sec = 0;
  tim.tv_nsec = 50000000;
  nanosleep(&tim, NULL);

  /* We open the i2c-0 (because else I needed to convert the strace) */
  int fd_i2c = open("/dev/i2c-0", O_RDWR);
  if (fd_i2c < 0) {
    printf("[MT9V117] Could not open i2c-0\n");
    return;
  }
  if (ioctl(fd_i2c, 0x703, 0x5d) < 0) {
    printf("[MT9V117] Could not change the i2c address to 0x5d\n");
    return;
  }

  /* First reset the device */
  write_reg(fd_i2c, "\x00\x1a\x00\x01", 4);
  write_reg(fd_i2c, "\x00\x1a\x00\x00", 4);
  tim.tv_sec = 0;
  tim.tv_nsec = 100000000;
  nanosleep(&tim, NULL);

  /* Now initialize the device */
  write_reg(fd_i2c, "\x30\x1a\x10\xd0", 4);
  write_reg(fd_i2c, "\x31\xc0\x14\x04", 4);
  write_reg(fd_i2c, "\x3e\xd8\x87\x9c", 4);
  write_reg(fd_i2c, "\x30\x42\x20\xe1", 4);
  write_reg(fd_i2c, "\x30\xd4\x80\x20", 4);
  write_reg(fd_i2c, "\x30\xc0\x00\x26", 4);
  write_reg(fd_i2c, "\x30\x1a\x10\xd4", 4);
  write_reg(fd_i2c, "\xa8\x02\x00\xd3", 4);
  write_reg(fd_i2c, "\xc8\x78\x00\xa0", 4);
  write_reg(fd_i2c, "\xc8\x76\x01\x40", 4);
  write_reg(fd_i2c, "\xbc\x04\x00\xfc", 4);
  write_reg(fd_i2c, "\xbc\x38\x00\x7f", 4);
  write_reg(fd_i2c, "\xbc\x3a\x00\x7f", 4);
  write_reg(fd_i2c, "\xbc\x3c\x00\x7f", 4);
  write_reg(fd_i2c, "\xbc\x04\x00\xf4", 4);

  _write(fd_i2c, "\x09\x82\x00\x01", 4);
  _write(fd_i2c, "\x09\x8a\x70\x00", 4);
  _write(fd_i2c,
         "\xf0\x00\x72\xcf\xff\x00\x3e\xd0\x92\x00\x71\xcf\xff\xff\xf2\x18\xb1\x10\x92\x05\xb1\x11\x92\x04\xb1\x12\x70\xcf\xff\x00\x30\xc0\x90\x00\x7f\xe0\xb1\x13\x70\xcf\xff\xff\xe7\x1c\x88\x36\x09\x0f\x00\xb3",
         50);
  _write(fd_i2c,
         "\xf0\x30\x69\x13\xe1\x80\xd8\x08\x20\xca\x03\x22\x71\xcf\xff\xff\xe5\x68\x91\x35\x22\x0a\x1f\x80\xff\xff\xf2\x18\x29\x05\x00\x3e\x12\x22\x11\x01\x21\x04\x0f\x81\x00\x00\xff\xf0\x21\x8c\xf0\x10\x1a\x22",
         50);
  _write(fd_i2c,
         "\xf0\x60\x10\x44\x12\x20\x11\x02\xf7\x87\x22\x4f\x03\x83\x1a\x20\x10\xc4\xf0\x09\xba\xae\x7b\x50\x1a\x20\x10\x84\x21\x45\x01\xc1\x1a\x22\x10\x44\x70\xcf\xff\x00\x3e\xd0\xb0\x60\xb0\x25\x7e\xe0\x78\xe0",
         50);
  _write(fd_i2c,
         "\xf0\x90\x71\xcf\xff\xff\xf2\x18\x91\x12\x72\xcf\xff\xff\xe7\x1c\x8a\x57\x20\x04\x0f\x80\x00\x00\xff\xf0\xe2\x80\x20\xc5\x01\x61\x20\xc5\x03\x22\xb1\x12\x71\xcf\xff\x00\x3e\xd0\xb1\x04\x7e\xe0\x78\xe0",
         50);
  _write(fd_i2c,
         "\xf0\xc0\x70\xcf\xff\xff\xe7\x1c\x88\x57\x71\xcf\xff\xff\xf2\x18\x91\x13\xea\x84\xb8\xa9\x78\x10\xf0\x03\xb8\x89\xb8\x8c\xb1\x13\x71\xcf\xff\x00\x30\xc0\xb1\x00\x7e\xe0\xc0\xf1\x09\x1e\x03\xc0\xc1\xa1",
         50);
  _write(fd_i2c,
         "\xf0\xf0\x75\x08\x76\x28\x77\x48\xc2\x40\xd8\x20\x71\xcf\x00\x03\x20\x67\xda\x02\x08\xae\x03\xa0\x73\xc9\x0e\x25\x13\xc0\x0b\x5e\x01\x60\xd8\x06\xff\xbc\x0c\xce\x01\x00\xd8\x00\xb8\x9e\x0e\x5a\x03\x20",
         50);
  _write(fd_i2c,
         "\xf1\x20\xd9\x01\xd8\x00\xb8\x9e\x0e\xb6\x03\x20\xd9\x01\x8d\x14\x08\x17\x01\x91\x8d\x16\xe8\x07\x0b\x36\x01\x60\xd8\x07\x0b\x52\x01\x60\xd8\x11\x8d\x14\xe0\x87\xd8\x00\x20\xca\x02\x62\x00\xc9\x03\xe0",
         50);
  _write(fd_i2c,
         "\xf1\x50\xc0\xa1\x78\xe0\xc0\xf1\x08\xb2\x03\xc0\x76\xcf\xff\xff\xe5\x40\x75\xcf\xff\xff\xe5\x68\x95\x17\x96\x40\x77\xcf\xff\xff\xe5\x42\x95\x38\x0a\x0d\x00\x01\x97\x40\x0a\x11\x00\x40\x0b\x0a\x01\x00",
         50);
  _write(fd_i2c,
         "\xf1\x80\x95\x17\xb6\x00\x95\x18\xb7\x00\x76\xcf\xff\xff\xe5\x44\x96\x20\x95\x15\x08\x13\x00\x40\x0e\x1e\x01\x20\xd9\x00\x95\x15\xb6\x00\xff\xa1\x75\xcf\xff\xff\xe7\x1c\x77\xcf\xff\xff\xe5\x46\x97\x40",
         50);
  _write(fd_i2c,
         "\xf1\xb0\x8d\x16\x76\xcf\xff\xff\xe5\x48\x8d\x37\x08\x0d\x00\x81\x96\x40\x09\x15\x00\x80\x0f\xd6\x01\x00\x8d\x16\xb7\x00\x8d\x17\xb6\x00\xff\xb0\xff\xbc\x00\x41\x03\xc0\xc0\xf1\x0d\x9e\x01\x00\xe8\x04",
         50);
  _write(fd_i2c,
         "\xf1\xe0\xff\x88\xf0\x0a\x0d\x6a\x01\x00\x0d\x8e\x01\x00\xe8\x7e\xff\x85\x0d\x72\x01\x00\xff\x8c\xff\xa7\xff\xb2\xd8\x00\x73\xcf\xff\xff\xf2\x40\x23\x15\x00\x01\x81\x41\xe0\x02\x81\x20\x08\xf7\x81\x34",
         50);
  _write(fd_i2c,
         "\xf2\x10\xa1\x40\xd8\x00\xc0\xd1\x7e\xe0\x53\x51\x30\x34\x20\x6f\x6e\x5f\x73\x74\x61\x72\x74\x5f\x73\x74\x72\x65\x61\x6d\x69\x6e\x67\x20\x25\x64\x20\x25\x64\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         50);
  _write(fd_i2c, "\xf2\x40\xff\xff\xe8\x28\xff\xff\xf0\xe8\xff\xff\xe8\x08\xff\xff\xf1\x54", 18);
  _write(fd_i2c, "\x09\x8e\x00\x00", 4);
  _write(fd_i2c, "\xe0\x00\x05\xd8", 4);
  _write(fd_i2c, "\xe0\x02\x04\x03", 4);
  _write(fd_i2c, "\xe0\x04\x00\x43\x01\x04", 6);

  // Do while succeeded?
  _write(fd_i2c, "\x00\x40\x80\x01", 4);
  while (test[0] != 0xFF || test[1] != 0XF8) {
    tim.tv_sec = 0;
    tim.tv_nsec = 100000000;
    nanosleep(&tim, NULL);
    write(fd_i2c, "\x00\x40", 2);
    read(fd_i2c, test, 2);
    printf("Da: %X%X\n", test[0], test[1]);

    /*if(test[1] == 0XFB) {
      // restart all over??
      mt9v117_init();
      return;
    }*/
  }

  _write(fd_i2c, "\xac\x40\x00\x00\xc3\x50", 6);
  write_reg(fd_i2c, "\xa4\x04\x00\x00", 4);
  //write(fd_i2c, "\x00\x30", 2);
  //read(fd_i2c, "\x04\x00", 2);

  write_reg(fd_i2c, "\x00\x30\x06\x01", 4);
  write_reg(fd_i2c, "\xc8\x00\x00\x0c", 4); //0x0008
  write_reg(fd_i2c, "\xc8\x02\x00\x10", 4);
  write_reg(fd_i2c, "\xc8\x04\x01\xf3", 4); //0x01f5
  write_reg(fd_i2c, "\xc8\x06\x02\x97", 4);
  write_reg(fd_i2c, "\xc8\x08\x01\x11", 4);
  write_reg(fd_i2c, "\xc8\x0a\x00\xa4", 4);
  write_reg(fd_i2c, "\xc8\x0c\x02\xfa", 4);
  write_reg(fd_i2c, "\xc8\x12\x00\x31", 4);
  write_reg(fd_i2c, "\xc8\x14\x01\xe3", 4); //0x00f3
  write_reg(fd_i2c, "\xc8\x28\x00\x03", 4); //0x0007
  write_reg(fd_i2c, "\xc8\x4c\x02\x80", 4);
  write_reg(fd_i2c, "\xc8\x4e\x01\xe0", 4); //240 (0x00f0)
  write_reg(fd_i2c, "\xc8\x50\x03", 3);

  write_reg(fd_i2c, "\xc8\x54\x02\x80", 4); //320 (0x0140)
  write_reg(fd_i2c, "\xc8\x56\x01\xe0", 4); //240 (0x00f0)

  write_reg(fd_i2c, "\xc8\xec\x00\x00", 4);
  write_reg(fd_i2c, "\xc8\xee\x00\x00", 4);
  write_reg(fd_i2c, "\xc8\xf0\x02\x7f", 4); //0x013f
  write_reg(fd_i2c, "\xc8\xf2\x01\xdf", 4); //0x00ef
  write_reg(fd_i2c, "\xc8\xf4\x00\x02", 4);
  write_reg(fd_i2c, "\xc8\xf6\x00\x02", 4);
  write_reg(fd_i2c, "\xc8\xf8\x00\x7f", 4); //0x003f
  write_reg(fd_i2c, "\xc8\xfa\x00\x5f", 4); //0x002f
  write_reg(fd_i2c, "\xc8\x10\x03\x52", 4); //0x0400 (0x045e??)
  write_reg(fd_i2c, "\xc8\x0e\x01\xff", 4); //0x0140 (0x0143??)
  write_reg(fd_i2c, "\xc8\x16\x00\xd4", 4); //0x00b0 (0x00a1??)
  write_reg(fd_i2c, "\xc8\x18\x00\xfe", 4); //0x00d3 (0x00c1??)
  write_reg(fd_i2c, "\xc8\x1a\x00\x01", 4);
  write_reg(fd_i2c, "\xc8\x1c\x00\x02", 4); //0x0001
  write_reg(fd_i2c, "\xc8\x1e\x00\x01", 4);
  write_reg(fd_i2c, "\xc8\x20\x00\x02", 4); //0x0001

  write(fd_i2c, "\xc8\x58", 2);
  read(fd_i2c, test, 2);
  write_reg(fd_i2c, "\xc8\x58\x00\x18", 4);
  write_reg(fd_i2c, "\xdc\x00\x28", 3);

  // Dow while succeeded?
  _write(fd_i2c, "\x00\x40\x80\x02", 4);
  test[0] = 0;
  test[1] = 0;
  while (test[0] != 0xFF || test[1] != 0XF8) {
    tim.tv_sec = 0;
    tim.tv_nsec = 100000000;
    nanosleep(&tim, NULL);
    write(fd_i2c, "\x00\x40", 2);
    read(fd_i2c, test, 2);
    printf("Dt: %X%X\n", test[0], test[1]);
  }

  printf("Done!\n");
  close(fd_i2c);
}
Esempio n. 21
0
/**
 * @brief
 * @note
 * @param
 * @retval
 */
size_t UIPClient::write(const uint8_t* buf, size_t size) {
    return _write(data, buf, size);
}
Esempio n. 22
0
/**
 * The write function writes up to size bytes from buffer to the file with descriptor 
 * identifier. 
 * The return value is the number of bytes actually written. This is normally the same 
 * as size, but might be less (for example, if the persistent storage being written to
 * fills up).
 */
int pcsl_file_write(void *handle, unsigned char* buffer, long length)
{
    return _write((int)handle, buffer, length);
}
Esempio n. 23
0
size_t
mm_io_c::write(const void *buffer,
               size_t size) {
  return _write(buffer, size);
}
Esempio n. 24
0
static int
task_main(int argc, char *argv[])
{
	work_q_item_t *work;

	/* inform about start */
	warnx("Initializing..");

	/* Initialize global variables */
	g_key_offsets[0] = 0;

	for (unsigned i = 0; i < (DM_KEY_NUM_KEYS - 1); i++)
		g_key_offsets[i + 1] = g_key_offsets[i] + (g_per_item_max_index[i] * k_sector_size);

	unsigned max_offset = g_key_offsets[DM_KEY_NUM_KEYS - 1] + (g_per_item_max_index[DM_KEY_NUM_KEYS - 1] * k_sector_size);

	for (unsigned i = 0; i < dm_number_of_funcs; i++)
		g_func_counts[i] = 0;

	/* Initialize the item type locks, for now only DM_KEY_MISSION_STATE supports locking */
	sem_init(&g_sys_state_mutex, 1, 1); /* Initially unlocked */
	for (unsigned i = 0; i < DM_KEY_NUM_KEYS; i++)
		g_item_locks[i] = NULL;
	g_item_locks[DM_KEY_MISSION_STATE] = &g_sys_state_mutex;

	g_task_should_exit = false;

	init_q(&g_work_q);
	init_q(&g_free_q);

	sem_init(&g_work_queued_sema, 1, 0);

	/* See if the data manage file exists and is a multiple of the sector size */
	g_task_fd = open(k_data_manager_device_path, O_RDONLY | O_BINARY);
	if (g_task_fd >= 0) {
		/* File exists, check its size */
		int file_size = lseek(g_task_fd, 0, SEEK_END);
		if ((file_size % k_sector_size) != 0) {
			warnx("Incompatible data manager file %s, resetting it", k_data_manager_device_path);
			close(g_task_fd);
			unlink(k_data_manager_device_path);
		}
		else
			close(g_task_fd);
	}

	/* Open or create the data manager file */
	g_task_fd = open(k_data_manager_device_path, O_RDWR | O_CREAT | O_BINARY);

	if (g_task_fd < 0) {
		warnx("Could not open data manager file %s", k_data_manager_device_path);
		sem_post(&g_init_sema); /* Don't want to hang startup */
		return -1;
	}

	if ((unsigned)lseek(g_task_fd, max_offset, SEEK_SET) != max_offset) {
		close(g_task_fd);
		warnx("Could not seek data manager file %s", k_data_manager_device_path);
		sem_post(&g_init_sema); /* Don't want to hang startup */
		return -1;
	}

	fsync(g_task_fd);

	/* see if we need to erase any items based on restart type */
	int sys_restart_val;
	if (param_get(param_find("SYS_RESTART_TYPE"), &sys_restart_val) == OK) {
		if (sys_restart_val == DM_INIT_REASON_POWER_ON) {
			warnx("Power on restart");
			_restart(DM_INIT_REASON_POWER_ON);
		}
		else if (sys_restart_val == DM_INIT_REASON_IN_FLIGHT) {
			warnx("In flight restart");
			_restart(DM_INIT_REASON_IN_FLIGHT);
		}
		else
			warnx("Unknown restart");
	}
	else
		warnx("Unknown restart");

	/* We use two file descriptors, one for the caller context and one for the worker thread */
	/* They are actually the same but we need to some way to reject caller request while the */
	/* worker thread is shutting down but still processing requests */
	g_fd = g_task_fd;

	warnx("Initialized, data manager file '%s' size is %d bytes", k_data_manager_device_path, max_offset);

	/* Tell startup that the worker thread has completed its initialization */
	sem_post(&g_init_sema);

	/* Start the endless loop, waiting for then processing work requests */
	while (true) {

		/* do we need to exit ??? */
		if ((g_task_should_exit) && (g_fd >= 0)) {
			/* Close the file handle to stop further queuing */
			g_fd = -1;
		}

		if (!g_task_should_exit) {
			/* wait for work */
			sem_wait(&g_work_queued_sema);
		}

		/* Empty the work queue */
		while ((work = dequeue_work_item())) {

			/* handle each work item with the appropriate handler */
			switch (work->func) {
			case dm_write_func:
				g_func_counts[dm_write_func]++;
				work->result =
					_write(work->write_params.item, work->write_params.index, work->write_params.persistence, work->write_params.buf, work->write_params.count);
				break;

			case dm_read_func:
				g_func_counts[dm_read_func]++;
				work->result =
					_read(work->read_params.item, work->read_params.index, work->read_params.buf, work->read_params.count);
				break;

			case dm_clear_func:
				g_func_counts[dm_clear_func]++;
				work->result = _clear(work->clear_params.item);
				break;

			case dm_restart_func:
				g_func_counts[dm_restart_func]++;
				work->result = _restart(work->restart_params.reason);
				break;

			default: /* should never happen */
				work->result = -1;
				break;
			}

			/* Inform the caller that work is done */
			sem_post(&work->wait_sem);
		}

		/* time to go???? */
		if ((g_task_should_exit) && (g_fd < 0))
			break;
	}

	close(g_task_fd);
	g_task_fd = -1;

	/* The work queue is now empty, empty the free queue */
	for (;;) {
		if ((work = (work_q_item_t *)sq_remfirst(&(g_free_q.q))) == NULL)
			break;
		if (work->first)
			free(work);
	}

	destroy_q(&g_work_q);
	destroy_q(&g_free_q);
	sem_destroy(&g_work_queued_sema);
	sem_destroy(&g_sys_state_mutex);

	return 0;
}