So I start a fresh XC-2 project (I've checked that it is an XC-2 project) and copy the code into it, but the program produces garbled output on the terminal emulator (I've checked the baud rate and other settings). It appears that I can't produce a good bitstream with the XC-2, even when I slow things down to 38400.
I'm not convinced that something hasn't changed with my compiler settings, so I created another fresh XC-1 project and copied the same code into it. I then hooked up my XC-1, put it into "program mode" and started the app. Everything runs perfectly on the XC-1.
Is there some corresponding "program mode" setting for the XC-2 that I'm missing?
Here's the top-level code.
Code: Select all
#include <platform.h>
#include "uartlib.h"
on stdcore[0]: port term_port_rx = PORT_UART_RX;
on stdcore[0]: port term_port_tx = PORT_UART_TX;
void Generator(chanend output) {
for(int i=0; i < 100000; i++){
if (!(i%10000)) {
output <: i;
}
}
}
void Status(chanend input, chanend fromTerminal, chanend toTerminal) {
int data;
chputs(toTerminal, "\n\rYellowFin\n\r");
while(1){
input :> data;
chputi(toTerminal, data);
chputs(toTerminal, "\n\r");
}
}
int main(void) {
chan toTerm;
chan fromTerm;
chan toStatus;
par {
on stdcore[0]: uartHandler(toTerm, fromTerm, term_port_tx, term_port_rx, 38400);
on stdcore[1]: Status(toStatus, fromTerm, toTerm);
on stdcore[1]: Generator(toStatus);
}
return 0;
}
Code: Select all
#include "uartlib.h"
void uartHandler(chanend transmitChannel, chanend receiveChannel,
port transmitPort, port receivePort,
unsigned baudrate)
{
uart_1thread(transmitPort, transmitChannel, receivePort, receiveChannel, baudrate);
}
void chputs(chanend output, char s[]){
int i=0;
while(s[i] != 0){
output <: (unsigned) (s[i]);
i++;
}
}
void chputi(chanend output, int n){
unsigned msb=1;
unsigned digit;
if (n < 0) {
output <: (unsigned)'-';
n = -n;
}
// determine the msb position
while(n/(msb * 10)) {
msb *= 10;
}
while(msb) {
// get most significant digit, convert to ascii, and output
digit = n / msb;
output <: digit + (unsigned)'0';
n -= digit * msb;
msb /= 10;
}
}