void avnet_console_manualtap_command( avnet_console_t *pConsole, int cargc, char ** cargv ) { int bDispSyntax = 0; unsigned uManualTap; if ( cargc > 1 && !strcmp(cargv[1],"help") ) { bDispSyntax = 1; } else if ( cargc > 1 ) { scandec(cargv[1], &uManualTap); pdemo->uManualTap = uManualTap; } pConsole->io_hprintf( pConsole->io_handle, "\tuManualTap = %d\r\n", pdemo->uManualTap ); if ( bDispSyntax ) { pConsole->io_hprintf( pConsole->io_handle, "\tSyntax :\r\n" ); pConsole->io_hprintf( pConsole->io_handle, "\t\tmanualtap # => Set manual tap (0-31)\r\n" ); } return; }
value sml_word_of_dec(value s) { value v; long res; char * p; /* The argument s has form 0w[0-9]+ */ p = String_val(s); /* skip 0w in s */ p += 2; res = (long)scandec(p, 2 * (unsigned long)MIN_TAGGED_LONG); v = LONG_TO_VAL((long)res); return v; }
value sml_int_of_string(value s) { value v; long res; int sign; char * p; p = String_val(s); sign = 1; if (*p == '~') { sign = -1; p++; } res = sign * scandec(p, (unsigned long) MIN_TAGGED_LONG); v = LONG_TO_VAL(res); if( VAL_TO_LONG(v) != res ) goto raise_failure; return v; raise_failure: failwith("sml_int_of_string"); return Val_unit; /* Can't reach return */ }
void avnet_console_samplepoint_command( avnet_console_t *pConsole, int cargc, char ** cargv ) { int bDispSyntax = 0; unsigned uSamplePoint; if ( cargc > 1 && !strcmp(cargv[1],"help") ) { bDispSyntax = 1; } else if ( cargc > 1 ) { scandec(cargv[1], &uSamplePoint); pdemo->uSamplePoint = uSamplePoint; { u16 uSensorReg; #define VITA_SPI_SEQ1_QTY 8 extern Xuint16 vita_spi_seq1[VITA_SPI_SEQ1_QTY][3]; // reg32 at [1] #define VITA_SPI_SEQ3_QTY 3 extern Xuint16 vita_spi_seq3[VITA_SPI_SEQ3_QTY][3]; // reg32 at [1] #define VITA_SPI_SEQ5_QTY 9 extern Xuint16 vita_spi_seq5[VITA_SPI_SEQ5_QTY][3]; // reg32 at [0] xil_printf( "\tuvita_spi_seq1[1][2] = %08X\n\r", vita_spi_seq1[1][2] ); uSensorReg = vita_spi_seq1[1][2]; uSensorReg = uSensorReg & 0x8FFF; uSensorReg = uSensorReg | (pdemo->uSamplePoint << 12); vita_spi_seq1[1][2] = uSensorReg; xil_printf( "\tuvita_spi_seq1[1][2] = %08X\n\r", vita_spi_seq1[1][2] ); xil_printf( "\tvita_spi_seq3[1][2] = %08X\n\r", vita_spi_seq3[1][2] ); uSensorReg = vita_spi_seq3[1][2]; uSensorReg = uSensorReg & 0x8FFF; uSensorReg = uSensorReg | (pdemo->uSamplePoint << 12); vita_spi_seq3[1][2] = uSensorReg; xil_printf( "\tvita_spi_seq3[1][2] = %08X\n\r", vita_spi_seq3[1][2] ); xil_printf( "\tvita_spi_seq5[0][2] = %08X\n\r", vita_spi_seq5[0][2] ); uSensorReg = vita_spi_seq5[0][2]; uSensorReg = uSensorReg & 0x8FFF; uSensorReg = uSensorReg | (pdemo->uSamplePoint << 12); vita_spi_seq5[0][2] = uSensorReg; xil_printf( "\tvita_spi_seq5[0][2] = %08X\n\r", vita_spi_seq5[0][2] ); } } pConsole->io_hprintf( pConsole->io_handle, "\tuSamplePoint = %d\r\n", pdemo->uSamplePoint ); if ( bDispSyntax ) { pConsole->io_hprintf( pConsole->io_handle, "\tSyntax :\r\n" ); pConsole->io_hprintf( pConsole->io_handle, "\t\tsamplepoint # => Set PYTHON sample point (0-31)\r\n" ); } return; }
struct prsstack *gettok() /*;gettok*/ { /* Gettok: Scan and return the next token in the adafile, adding the */ /* token to namelist. */ static int nextcanbeprime = 0; /* The next token can be a prime */ static int canbeprime; /* The current token can be a prime */ struct prsstack *tok; /* Token to be returned */ while (1) { while (1) { while (*line == ' ' || *line == '\t') { colno += (*line == '\t') ? (8 - ((colno - 1) % 8)) : 1; line++; } if (!*line || *line == '-' && line[1] == '-') break; canbeprime = nextcanbeprime; nextcanbeprime = 0; if (isalpha(*line)) { /* Scan identifiers */ char id[MAXLINE + 1]; int idind = 0, chread = 0; int tokind, toksym; scanidorint(id, &idind, &chread, isletterordigit, 0); if (id[idind - 1] == '_') idind--; id[idind] = '\0'; convtoupper(id); tokind = namemap(id, idind); toksym = MIN(tokind, ID_SYM); tok = newtoken(toksym, tokind, lineno, colno); nextcanbeprime = toksym == ID_SYM || toksym == RANGE_SYM || toksym == ALL_SYM; colno += chread; line += chread; return(tok); } else if (isdigit(*line) || *line == '.' && isdigit(line[1])) { /* Scan numeric literals */ char num[MAXLINE + 3]; int ind = 0, chread = 0, result; char ch; /* ind is the index into the num string */ /* chread is the index into the line input string */ result = scandec(num, &ind, &chread, isdecimal); ch = line[chread]; if (result == 1 && (ch == '#' || ch == ':')) { /* Scan for the rest of a based literal */ num[ind++] = '#'; chread++; if (!scandec(num, &ind, &chread, ishex)) { lexerr(lineno, colno + chread - 1, colno + chread - 1, "Incomplete based number"); num[ind++] = '0'; } num[ind++] = '#'; if (line[chread] != ch) { if (line[chread] == '#' + ':' - ch) { lexerr(lineno, colno + chread, colno + chread, "Expect #'s or :'s in based number to match"); chread++; } else { char msg[50]; sprintf(msg, "Expect '%c' after last digit", ch); lexerr(lineno, colno + chread - 1, colno + chread - 1, msg); } } else chread++; checkbased(num, &ind); } scanexp(num, &ind, &chread); if (isalpha(line[chread])) lexerr(lineno, colno, colno + chread - 1, "Number should be separated from adjacent identifier"); num[ind] = '\0'; tok = newtoken(NUMBER_SYM, namemap(num, ind), lineno, colno); colno += chread; line += chread; return(tok); } else if (*line == '\'') { int err = 0; if (line[1] != '\0' && line[2] == '\'' && (!canbeprime || line[1] != '(')) { /* Scan a character literal */ char str[4]; int len = 3; strcpy(str, "' '"); if (!isprint(line[1]) && line[1] != ' ') { char msg[80]; sprintf(msg, "Invalid character %s in character literal replaced by space", nonprintingmsg[line[1]]); lexerr(lineno, colno + 1, colno + 1, msg); len = (line[1] == '\t') ? (10 - (colno % 8)) : 2; } else str[1] = line[1]; tok = newtoken(CHAR_SYM, namemap(str, 3), lineno, colno); colno += len; line += 3; return(tok); } else if (!canbeprime) { /* Possibly a single quote delimited string */ int ind; if (line[1] == '\'') ind = 1; else { ind = 3; while (line[ind]) { if (line[ind] == '\'') { if (line[ind + 1] && line[ind + 2] == '\'') { ind = -1; break; } else { if (line[ind + 1] != '\'') break; ind++; } } ind++; } } if (ind > -1 && line[ind]) { err = 1; lexerr(lineno, colno, colno + ind, "Expect double quotes to delimit a character string"); do if (line[ind] == '\'') line[ind] = '"'; while (ind--); } } if (!err) { /* A prime */ int ind = namemap("'", 1); tok = newtoken(ind, ind, lineno, colno); colno++; line++; return(tok); } } else if (*line == '"' || *line == '%') { /* Scan a string literal */ int col = colno; int oldindex = 0, newindex = -1; char bracket = *line; char nxtchr ; char tmpstr[MAXLINE + 1]; int save_col; /* these are maintained to restore line */ char *save_line; /* in case of missing string bracket */ int save_newindex; if ( (strchr(line+1, bracket)) == 0 ) { char bracket_str[2]; *bracket_str = bracket; *(bracket_str + 1) = '\0'; tok = newtoken(ERROR_SYM, namemap(bracket_str, 1), lineno, colno); line++; colno++; return(tok); } while (1) { save_line = line + oldindex + 1; save_col = col + 1; save_newindex = newindex + 1; do { col++; oldindex++; newindex++; nxtchr = line[oldindex] ; tmpstr[newindex] = nxtchr ; } /* test separately for bracket for use of % as delimiter */ while (nxtchr != bracket && IS_STRING_CHAR(nxtchr)); if (line[oldindex] == bracket) { if (line[oldindex + 1] == bracket) { tmpstr[newindex] = bracket ; oldindex++; col++; } else { tmpstr[newindex] = '\0'; tok = newtoken(STRING_SYM, namemap(tmpstr, newindex), lineno, colno+1); colno = col + 1; line += oldindex + 1; return(tok); } } else if (line[oldindex] == '"') { oldindex++; lexerr(lineno, col, col, "% delimited string contains \", being ignored"); } else if (line[oldindex] == '\0') { lexerr(lineno, colno, colno, "Missing string bracket"); /* restore values of line and colno to values prior to * last set of string characters */ line = save_line; colno = save_col; /* insert a closing string bracket */ tmpstr[save_newindex] = bracket; tmpstr[save_newindex + 1] = '\0'; tok = newtoken(STRING_SYM, namemap(tmpstr, save_newindex + 1), lineno, colno); return(tok); } /* else if (isprint(line[oldindex]) || line[oldindex] == ' ') tmpstr[newindex] = line[oldindex]; */ else { char msg[80]; sprintf(msg, "Invalid character %s in string deleted", nonprintingmsg[line[oldindex++]]); lexerr(lineno, col, col, msg); col += (line[oldindex] == '\t') ? 7 - ((col-1)%8) : -1; } } } else if (ISDELIMITER(*line)) /* Scan a delimiter */ { int len = 1, ind; char str[3]; switch (*line) { case '=' : if (line[1] == '>') len = 2; break; case '*' : if (line[1] == '*') len = 2; break; case ':' : case '/' : if (line[1] == '=') len = 2; break; case '>' : if (line[1] == '=' || line[1] == '>') len = 2; break; case '<' : if (line[1] == '=' || line[1] == '<' || line[1] == '>') len = 2; break; case '.' : if (line[1] == '.') len = 2; break; case '!' : *line = '|'; break; case '[' : /* Change to a "(" */ lexerr(lineno, colno, colno, "Bad character \"[\", replaced by \"(\".") ; line[0] = '(' ; break ; case ']' : /* Change to a ")" */ /* Note that this case falls through to the next one */ lexerr(lineno, colno, colno, "Bad character \"]\", replaced by \")\".") ; line[0] = ')' ; case ')' : nextcanbeprime = 1; break; } strncpy(str, line, len); str[len] = '\0'; ind = namemap(str, len); tok = newtoken(ind, ind, lineno, colno); colno += len; line += len; return(tok); } else if (*line == '_') { /* An error- an underline _ */ lexerr(lineno, colno, colno, "Break character misplaced"); colno++; line++; } else { /* An error- an unknown character */ char msg[80]; char ch[2]; *ch = *line; ch[1] = '\0'; sprintf(msg, "Bad character in file ignored: %s", (isprint(*line)) ? ch : nonprintingmsg[*line]); lexerr(lineno, colno, colno, msg); if (isprint(*line)) colno++; line++; } } if (getline() == EOF) return(newtoken(EOFT_SYM, EOFT_SYM, lineno, colno)); } }