Ejemplo n.º 1
0
/*********************************************************************
 * @fn      Process_Command
 *
 * @brief   Process the network incoming command message.
 *
 * @param   msgBuf, len
 *
 * @return  none
 */
void Process_Command(cmd_msg_t* command/*uint8 *msgBuf*/, uint16 len) 
{
  //  uint32 cmdData;
  uint16 option = (command->option[0])<<8 + command->option[1];
  uint8  baudrate = 0x02;
  uint8 result = 0;
  unsigned char buf[1];
  
  if(len < 7) // error
  {
    return;
  }
  
  if (option==0xE101) //open Uart 0
  {
    baudrate = command->controlmsg[0];
    result = openUart(0, baudrate); // open uart 0
    buf[0] = result; // send result to BS
    App_SendSample(buf, 1, option);
  }
  else if (option==0xE102)
  {
    baudrate = command->controlmsg[0];
    result = openUart(1, baudrate); // open uart 1
    buf[0] = result;
    App_SendSample(buf, 1, option);
  }
  
  else if (option==0xE201)
  {    
    writeUart(0, command);    
  }
  else if (option==0xE202)
  {
    writeUart(1, command);
  } 
  else if (option>=0xC000 && option <=0xC0FF) // set IO
  {
    Set_IO(command);
  }
  
}
Ejemplo n.º 2
0
int main () {
    int i;
    int c;

    /* Initialize UART */
    hw_write(UARTIBRD, 0x01);
    hw_write(UARTCR, 0x0301);

    hw_write(IOSTATUS, 1);
    //printf ("Starting main\n");
    ffFull = false;

    writeUart("Testing\n");

    i = GetNextPrimes(10000000, 100);
    hw_write(IOSTATUS, 2);
    printf ("Prime is %d\n", i);

    /*asm volatile ("cpsie i");*/
    NVIC_EnableIRQ(1);

    while (true) {

        while (!ffFull) {
            //printf ("Called wfi\n");
            hw_write(IOSTATUS, 0);
            asm volatile("wfi");
            hw_write(IOSTATUS, 1);
        }

        c = hw_read(FFCOUNT);
        while (c != 0) {
            i = hw_read(FF);
            c = hw_read(FFCOUNT);
            //printf ("Read i = %d\n", i);
        }
        //printf ("Finished read loop\n");
        ffFull = false;
    }

    //printf ("Returning from main\n");
    return 0;
}
Ejemplo n.º 3
0
int sprintf(char *buf, const char *fmt, ...)
{
	va_list arglist;
	FILE str = {
		.write_buf = buf,
		.write_offset = 0,
		.write_buf_len = 0x7fffffff
	};

	va_start(arglist, fmt);
	vfprintf(&str, fmt, arglist);
	va_end(arglist);
	fputc('\0', &str);	// Null terminate

	return str.write_offset;
}

int snprintf(char *buf, size_t length, const char *fmt, ...)
{
	va_list arglist;
	FILE str = {
		.write_buf = buf,
		.write_offset = 0,
		.write_buf_len = length
	};

	va_start(arglist, fmt);
	vfprintf(&str, fmt, arglist);
	va_end(arglist);
	fputc('\0', &str);	// Null terminate

	return str.write_offset;
}

FILE __stdout = { 
	.write_buf = NULL, 
	.write_offset = 0,
	.write_buf_len = 0 
};

FILE __stdin = {
	.write_buf = NULL, 
	.write_offset = 0,
	.write_buf_len = 0 
};

FILE *stdout = &__stdout;
FILE *stderr = &__stdout;
FILE *stdin = &__stdin;

void putchar(int ch)
{
	fputc(ch, stdout);
}

void puts(const char *s)
{
	for (const char *c = s; *c; c++)
		putchar(*c);

	putchar('\n');
}

void fputc(int ch, FILE *file)
{
	if (file == stdout)
		writeUart(ch);
	else if (file->write_buf)
	{
		if (file->write_offset < file->write_buf_len)
			file->write_buf[file->write_offset++] = ch;
	}
	else
		write(file->fd, &ch, 1);
}

void fputs(const char *str, FILE *file)
{
	while (*str)
		fputc(*str++, file);
}

FILE *fopen(const char *filename, const char *mode)
{
	FILE *fptr = (FILE*) malloc(sizeof(FILE));
	fptr->write_buf = 0;
	fptr->fd = open(filename, 0);
	return fptr;
}

size_t fwrite(const void *ptr, size_t size, size_t count, FILE *file)
{
	size_t left = size * count;
	const char *out = ptr;
	while (left--)
		fputc(*out++, file);
	
	return count;
}
Ejemplo n.º 4
0
int sprintf(char *buf, const char *fmt, ...)
{
	va_list arglist;
	FILE str = {
		.write_buf = buf,
		.write_offset = 0,
		.write_buf_len = 0x7fffffff
	};

	va_start(arglist, fmt);
	vfprintf(&str, fmt, arglist);
	va_end(arglist);
	fputc('\0', &str);	// Null terminate

	return str.write_offset;
}

int snprintf(char *buf, size_t length, const char *fmt, ...)
{
	va_list arglist;
	FILE str = {
		.write_buf = buf,
		.write_offset = 0,
		.write_buf_len = length
	};

	va_start(arglist, fmt);
	vfprintf(&str, fmt, arglist);
	va_end(arglist);
	fputc('\0', &str);	// Null terminate

	return str.write_offset;
}

int vsnprintf(char *buf, size_t length, const char *fmt, va_list arglist)
{
	FILE str = {
		.write_buf = buf,
		.write_offset = 0,
		.write_buf_len = length
	};

	vfprintf(&str, fmt, arglist);
	fputc('\0', &str);	// Null terminate
	
	return str.write_offset;
}

static FILE __stdout = { 
	.write_buf = NULL, 
	.write_offset = 0,
	.write_buf_len = 0 
};

static FILE __stdin = {
	.write_buf = NULL, 
	.write_offset = 0,
	.write_buf_len = 0 
};

FILE *stdout = &__stdout;
FILE *stderr = &__stdout;
FILE *stdin = &__stdin;

int putchar(int ch)
{
	fputc(ch, stdout);
	return 1;
}

int puts(const char *s)
{
	const char *c;
	for (c = s; *c; c++)
		putchar(*c);

	putchar('\n');
	return c - s + 1;
}

int fputc(int ch, FILE *file)
{
	if (file == stdout)
		writeUart(ch);
	else if (file->write_buf)
	{
		if (file->write_offset < file->write_buf_len)
			file->write_buf[file->write_offset++] = ch;
	}
	else
		write(file->fd, &ch, 1);

	return 1;
}

int fputs(const char *str, FILE *file)
{
	const char *c;
	for (c = str; *c; c++)
		fputc(*c, file);

	return c - str;
}

int fgetc(FILE *f)
{
	unsigned char c;
	int got = read(f->fd, &c, 1);
	if (got < 0)
		return -1;
	
	return c;
}

FILE *fopen(const char *filename, const char *mode)
{
	int fd  = open(filename, 0);
	if (fd < 0)
		return NULL;
	
	FILE *fptr = (FILE*) malloc(sizeof(FILE));
	fptr->write_buf = 0;
	fptr->fd = fd;

	return fptr;
}