// Test reading and writing the 23K256 status register: BYTE SPIRAM_StatusRegisterTest(void) { // NOTE: SPIRAM_SEQUENTIAL_MODE|SPIRAM_PAGE_MODE is "Reserved", don't use it BYTE mode[6] = { SPIRAM_BYTE_MODE, SPIRAM_BYTE_MODE|SPIRAM_DISABLE_HOLD, SPIRAM_SEQUENTIAL_MODE, SPIRAM_SEQUENTIAL_MODE|SPIRAM_DISABLE_HOLD, SPIRAM_PAGE_MODE, SPIRAM_PAGE_MODE|SPIRAM_DISABLE_HOLD }; BYTE status; BYTE b; UART_CPutString("Status Register W/R Test: 0x "); for (b=0; b<6 ; b++) { UART_PutChar(0x08); UART_PutChar(0x08); UART_PutSHexByte(mode[b]); if (SPIRAM_WriteStatusRegister(mode[b])) { UART_CPutString("\r\nWrite of invalid Status Register value. System halted.\r\n"); M8C_Stop; } status = SPIRAM_ReadStatusRegister(); if (status != mode[b]) { UART_CPutString(" FAIL\r\n"); return(1); } } UART_CPutString("\b\b\b\b\b PASS\r\n"); // Place the SRAM back in Byte Mode SPIRAM_WriteStatusRegister(SPIRAM_BYTE_MODE|SPIRAM_DISABLE_HOLD); return(0); }
void TUART_PutChar() { UART_PutChar('h'); UART_PutChar('a'); UART_PutChar('h'); UART_PutChar('0'); simpleDelay(2000000); }
/** * \brief UART transfer with interrupt in UART loop back mode */ static void UartTransfer(void) { uint8_t *pBuffer = &pTxBuffer[0]; PMC_EnablePeripheral(BASE_ID); UART_Configure(BASE_UART, (UART_MR_PAR_NO | UART_MR_CHMODE_LOCAL_LOOPBACK), 115200, BOARD_MCK); NVIC_ClearPendingIRQ(BASE_IRQ); NVIC_SetPriority(BASE_IRQ ,1); /* Enables the UART to transfer and receive data. */ UART_SetTransmitterEnabled (BASE_UART , 1); UART_SetReceiverEnabled (BASE_UART , 1); UART_EnableIt(BASE_UART, (UART_IER_RXRDY | UART_IER_OVRE | UART_IER_FRAME | UART_IER_PARE)); /* Enable interrupt */ NVIC_EnableIRQ(BASE_IRQ); while (*pBuffer != '\0') { UART_PutChar(BASE_UART, *pBuffer); pBuffer++; } UART_PutChar(BASE_UART, *pBuffer); }
/** * Displays the content of the given buffer on the UART0. * * \param pucBuffer Pointer to the buffer to dump. * \param dwSize Buffer size in bytes. * \param dwAddress Start address to display */ extern void UART_DumpMemory( uint8_t* pucBuffer, uint32_t dwSize, uint32_t dwAddress ) { uint32_t i ; uint32_t j ; uint32_t dwLastLineStart ; uint8_t* pucTmp ; for ( i=0 ; i < (dwSize / 16) ; i++ ) { printf( "0x%08X: ", (unsigned int)(dwAddress + (i*16)) ) ; pucTmp = (uint8_t*)&pucBuffer[i*16] ; for ( j=0 ; j < 4 ; j++ ) { printf( "%02X%02X%02X%02X ", pucTmp[0], pucTmp[1], pucTmp[2], pucTmp[3] ) ; pucTmp += 4 ; } pucTmp=(uint8_t*)&pucBuffer[i*16] ; for ( j=0 ; j < 16 ; j++ ) { UART_PutChar( *pucTmp++ ) ; } printf( "\n\r" ) ; } if ( (dwSize%16) != 0 ) { dwLastLineStart=dwSize - (dwSize%16) ; printf( "0x%08X: ", (unsigned int)(dwAddress + dwLastLineStart) ) ; for ( j=dwLastLineStart ; j < dwLastLineStart+16 ; j++ ) { if ( (j!=dwLastLineStart) && (j%4 == 0) ) { printf( " " ) ; } if ( j < dwSize ) { printf( "%02X", pucBuffer[j] ) ; } else { printf(" ") ; } } printf( " " ) ; for ( j=dwLastLineStart ; j < dwSize ; j++ ) { UART_PutChar( pucBuffer[j] ) ; } printf( "\n\r" ) ; } }
// Function __readc() / __sys_readc // // Called by bottom level of scanf routine within RedLib C library to read // a character. With the default semihosting stub, this would read the character // from the debugger console window (which acts as stdin). But this version reads // the character from the LPC11C14 UART. int READFUNC (void) { char c = UART_GetChar(); UART_PutChar(c); if(c == '\r') { UART_PutChar('\n'); return (int)'\n'; } else return (int)c; }
/** * @brief Transmit a string through UART0. * * @param str: Pointer to the string terminated with '\0'. * @retval None */ void UART_PutString (const uint8_t * str) { while ((*str) != 0) { if (*str == '\n') { UART_PutChar(*str++); UART_PutChar('\r'); } else { UART_PutChar(*str++); } } }
int fgetc(FILE *f) { uint8_t tempch = UART_GetChar(); UART_PutChar(tempch); if(tempch == '\r') { UART_PutChar('\n'); return '\n'; } else return tempch; }
size_t __read(int handle,unsigned char *buf,size_t bufSize) { size_t i; for (i=0x0; i<bufSize;i++) { buf[i] = UART_GetChar(); UART_PutChar(buf[i]); if(buf[i] == '\r') { UART_PutChar('\n'); buf[i] = '\n'; } } return i; }
/** * Reads an integer * * \param pdwValue Pointer to a integer variable to contain the input value. * * \return success(1) or failure(0) */ extern uint32_t UART_GetInteger( int32_t* pdwValue ) { uint8_t ucKey ; uint8_t ucNum = 0 ; int32_t dwValue = 0 ; int32_t sign = 1 ; while ( 1 ) { ucKey=UART_GetChar() ; UART_PutChar( ucKey ) ; if ( ((ucKey == '-') || (ucKey == '+')) && (ucNum == 0) ) { if (ucKey == '-') { sign = -1; } else { sign = 1; } ucNum++; } else { if ( ucKey >= '0' && ucKey <= '9' ) { dwValue = (dwValue * 10) + (ucKey - '0'); ucNum++; } else { if ( ucKey == 0x0D || ucKey == ' ' ) { if ( ucNum == 0 ) { printf( "\n\rWrite a number and press ENTER or SPACE!\n\r" ) ; return 0 ; } else { printf( "\n\r" ) ; *pdwValue = dwValue * sign; return 1 ; } } else { printf( "\n\r'%c' not a number or sign(+/-)!\n\r", ucKey ) ; return 0 ; } } } } }
int _write(int file, char *ptr, int len) { (void) file; int n; for(n = 0; n < len; n++) { UART_PutChar(*ptr++); } return len; }
static uint32_t send(uint8_t *buf, uint32_t len) { int i; for(i=0; i<len; i++) { UART_PutChar(HW_UART0, *buf++); } return len; }
// Function __write() / __sys_write // // Called by bottom level of printf routine within RedLib C library to write // a character. With the default semihosting stub, this would write the character // to the debugger console window . But this version writes // the character to the LPC11C14 UART. int WRITEFUNC (int iFileHandle, char *pcBuffer, int iLength) { unsigned int i; for (i = 0; i<iLength; i++) { UART_PutChar(pcBuffer[i]); // print each character } return iLength; }
void processRX(uint8 input) { // Only start sending values if receive start char if (input != SERIAL_START_CHAR) { return; } // Send start char of sequence UART_PutChar(FIRST_SERIAL_RECEIVE_CHAR); // Send payload data int i; for (i = 0; i < MAT_SIZE; ++i) { UART_PutChar(adcValues[i]); //UART_PutChar(0xF0 * i); } // Send final char of sequence UART_PutChar(FINAL_SERIAL_RECEIVE_CHAR); }
void UART_PutStr( const char *str ) { while ( *str != '\0' ) { UART_PutChar( *str ); str++; } } // UART_PutStr
// This function get's a line of text. It writes data into buffer with a maximum size of bufferLen. The function returns number of bytes written // when enter is pressed. Values of buffer and strPos are continuously passed to the function. The function returns TRUE if a line was received // otherwise false if its still getting data char GetLine(char *buffer, char *strPos, char bufferLen) { char c; static char newCommand = TRUE; // Since this is static, only gets set to true once but is a global essentially if (newCommand) // If it is a new command, put a > character and set this to false { UART_PutChar('>'); newCommand = FALSE; } if ((c = UART_cReadChar())) { if (c == 0x08 || c == 0x7F) // Delete or backspace pressed { if (*strPos > 0) // Only delete if there are characters to delete { (*strPos)--; // Set the position back one UART_PutString(rubout); // Sends the rubout sequence to the serial. } } else if (c == 0x0D) // Newline enter is pressed { buffer[*strPos] = 0x00; // put the null character at the current strPos UART_PutCRLF(); // Go to another line *strPos = 0; newCommand = TRUE; // Next time GetLine is called, > will be outputted return TRUE; // This means that the program should handle the buffer } else if (c >= 0x20 && c < 0x7F) // only valid characters to the string. These are any alphabet, numeric, or symbols { if (*strPos < bufferLen) // If there is space in the buffer { buffer[(*strPos)++] = c; // Set the current character in buffer to c and then increment strPos UART_PutChar(c); // Send the character to the computer } else UART_PutChar(0x07); // Send BEL key because there is no more space left to add to the string } } return FALSE; // Data is not ready to be handled }
void UART_SendBuffer(Uart *uart, uint8_t *pBuffer, uint32_t BuffLen) { uint8_t *pData = pBuffer; uint32_t Len =0; for(Len =0; Len<BuffLen; Len++ ) { UART_PutChar(uart, *pData); pData++; } }
static int print_char(char ch) { #ifdef TEST_STDIO printf ("%c", ch); #else UART_PutChar(debug_port, ch); #endif return 0; }
int (__write)(int Handle, const unsigned char *Buf, size_t BufSize) { int i; for(i=0;i<BufSize;i++) { UART_PutChar(Buf[i]); } return BufSize; }
void init_uart(void){ ///UART//// UART_CmdReset(); UART_IntCntl(UART_ENABLE_RX_INT); UART_Start(UART_PARITY_NONE); UART_PutChar(12); #ifdef UART_VERBOSE UART_CPutString("\r\n\r\n\r\n\r\n\r\n\r\n waking up......................................."); #endif }
int main(){ UART_Init((F_CPU / (16UL * 9600)) - 1); while(1){ if(UART_DataReady()){ uint8_t byte = UART_GetChar(); toggle_led(byte); UART_PutChar(PORTC & LED_MASK); } } return 0; }
/*------------------------------------------------------------------------------ * Outputs a character. *------------------------------------------------------------------------------*/ int fputc(int ch, FILE *f) { if ((f == stdout) || (f == stderr)) { UART_PutChar( ch ) ; return ch ; } else { return EOF ; } }
// This function gets a line of text. It writes data into buffer with a maximum size of bufferLen. The function returns number of bytes written // when enter is pressed void GetLine(char *buffer, char bufferLen) { char c; char strPos = 0; // Current position in the string UART_PutChar('>'); // Print line pointer while (1) { c = UART_cReadChar(); // Use UART module to read the character user enters if (c == 0x08 || c == 0x7F) // Delete or backspace pressed { if (strPos > 0) // Only delete if there are characters to delete { strPos--; // Set the position back one UART_PutString(rubout); // Sends the rubout sequence to the serial. } } else if (c == 0x0D) // Newline enter is pressed { buffer[strPos] = 0x00; // put the null character at the current strPos UART_PutCRLF(); // Go to another line break; } else if (c >= 0x20 && c < 0x7F) // only valid characters to the string. These are any alphabet, numeric, or symbols { if (strPos < bufferLen) // If there is space in the buffer { buffer[strPos++] = c; // Set the current character in buffer to c and then increment strPos UART_PutChar(c); // Send the character to the computer } else UART_PutChar(0x07); // Send BEL key because there is no more space left to add to the string } } return; }
// This function reads characters from the serial until a character is entered that is within the min & max ASCII characters. // That character is returned char GetNumber(char min, char max) // gets passed { char c; while (1) { c = UART_cReadChar(); // Read the character if (c < ('0' + min) || c > ('0' + max)) // If the character is not within min to max range, continue the loop continue; UART_PutChar(c); // Put the character on the serial return (c - '0'); // This returns the integer number entered instead of the ASCII value } return 0; }
/** * \brief Applet main entry. This function decodes received command and executes it. * * \param argc always 1 * \param argv Address of the argument area.. */ int main(int argc, char **argv) { struct _Mailbox *pMailbox = (struct _Mailbox *) argv; uint32_t mode, crystalFreq, extClk, comType; // ---------------------------------------------------------- // INIT: // ---------------------------------------------------------- if (pMailbox->command == APPLET_CMD_INIT) { mode = pMailbox->argument.inputInit.mode; crystalFreq = pMailbox->argument.inputInit.crystalFreq; extClk = pMailbox->argument.inputInit.extClk; comType = pMailbox->argument.inputInit.comType; switch (mode) { case EK_MODE: EK_LowLevelInit(); pMailbox->status = APPLET_SUCCESS; break; case USER_DEFINED_CRYSTAL: user_defined_LowlevelInit(crystalFreq); pMailbox->status = APPLET_SUCCESS; break; case BYASS_MODE: bypass_LowLevelInit(extClk); pMailbox->status = APPLET_SUCCESS; break; default: pMailbox->status = APPLET_DEV_UNKNOWN; break; } } else { pMailbox->status = APPLET_DEV_UNKNOWN; } UART_Configure(115200, BOARD_MCK); /* Notify the host application of the end of the command processing */ pMailbox->command = ~(pMailbox->command); if (comType == DBGU_COM_TYPE) { UART_PutChar(0x6); } return 0; }
int fputc(int ch, FILE *file) { int ret = EOF; switch( file->handle ) { case STDOUT_HANDLE: UART_PutChar(ch); ret = ch; break; case STDERR_HANDLE: ret = ch; break; default: file = file; break; } return(ret); }
void main_test_display(){ UART_Start(); // initialize UART UART_PutChar(0x81); // init connection; set to 16x12 image struct disp_grid_81 disp; disp_grid_init(&disp,0x3F); // init our display grid matrix to white disp_grid_transmit(&disp); struct tic_tac_ai tta; tta_init(&tta,4,3,false,true); //first bool for player 1, second bool for player 2. true means is AI disp_grid_init_ttc(&disp, tta.game.grid); disp_grid_draw_tic(&disp,24,1,0x27); // draw tic disp_grid_draw_win(&disp,27,9,1); // draw tic disp_grid_draw_xia(&disp,26,16,0x30); // draw xia disp_grid_transmit(&disp); }
void main_play_ttc(){ LCD_Start(); // initialize lcd LCD_ClearDisplay(); UART_Start(); // initialize UART UART_PutChar(0x81); // init connection; set to 16x12 image struct disp_grid_81 disp; disp_grid_init(&disp,0x3F); // init our display grid matrix to white disp_grid_transmit(&disp); struct tic_tac_toe lolz; ttc_init(&lolz,4,3); disp_grid_init_ttc(&disp,lolz.grid); // init the board disp_grid_draw_xia(&disp,26,16,0x30); // draw xia disp_grid_transmit(&disp); int x,y,z; int Values; while (lolz.game_not_won == 0){ //Values = read_from_8255(Values); Values = Pin3_Read(); if (Values >= 0 && Values <= 63){ //integer value z = Values / 16; x = Values % 4; //get row value y = Values / 4 - z*4; // LCD_ClearDisplay(); LCD_PrintNumber(Values); LCD_PrintString(" x"); LCD_PrintNumber(x); LCD_PrintString(" y"); LCD_PrintNumber(y); LCD_PrintString(" z"); LCD_PrintNumber(z); } if (ttc_get_grid(&lolz,x,y,z) == 0){ // has not been accessed ttc_step(&disp,&lolz,x,y,z); // step & print disp_grid_transmit(&disp); } } LCD_ClearDisplay(); LCD_Position(0,0); //move to bot row LCD_PrintString("GAME OVER!"); }
void Boot_Send(Byte tx_buffer[]) { Byte data_length,frame_length, tx_index=0; data_length = tx_buffer[3]; tx_buffer[data_length+4] = 0xAA; tx_buffer[data_length+5] = 0x55; frame_length = 4 + data_length + 2; while(frame_length) { UART_PutChar(tx_buffer[tx_index]); frame_length --; tx_index++; } }
/** * Reads an integer * * \param pdwValue Pointer to the uint32_t variable to contain the input value. */ extern uint32_t UART_GetInteger( uint32_t* pdwValue ) { uint8_t ucKey ; uint8_t ucNbNb=0 ; uint32_t dwValue=0 ; while ( 1 ) { ucKey=UART_GetChar() ; UART_PutChar( ucKey ) ; if ( ucKey >= '0' && ucKey <= '9' ) { dwValue = (dwValue * 10) + (ucKey - '0'); ucNbNb++ ; } else { if ( ucKey == 0x0D || ucKey == ' ' ) { if ( ucNbNb == 0 ) { printf( "\n\rWrite a number and press ENTER or SPACE!\n\r" ) ; return 0 ; } else { printf( "\n\r" ) ; *pdwValue=dwValue ; return 1 ; } } else { printf( "\n\r'%c' not a number!\n\r", ucKey ) ; return 0 ; } } } return 0; }
/** * Reads an hexadecimal number * * \param pdwValue Pointer to the uint32_t variable to contain the input value. */ extern uint32_t UART_GetHexa32( uint32_t* pdwValue ) { uint8_t ucKey ; uint32_t dw = 0 ; uint32_t dwValue = 0 ; for ( dw=0 ; dw < 8 ; dw++ ) { ucKey = UART_GetChar() ; UART_PutChar( ucKey ) ; if ( ucKey >= '0' && ucKey <= '9' ) { dwValue = (dwValue * 16) + (ucKey - '0') ; } else { if ( ucKey >= 'A' && ucKey <= 'F' ) { dwValue = (dwValue * 16) + (ucKey - 'A' + 10) ; } else { if ( ucKey >= 'a' && ucKey <= 'f' ) { dwValue = (dwValue * 16) + (ucKey - 'a' + 10) ; } else { printf( "\n\rIt is not a hexa character!\n\r" ) ; return 0 ; } } } } printf("\n\r" ) ; *pdwValue = dwValue ; return 1 ; }