//**************************************************************************** // //! AckPacket() sends an Acknowledge a packet. //! //! This function acknowledges a packet has been received from the device. //! //! \return The function returns zero to indicated success while any non-zero //! value indicates a failure. // //**************************************************************************** int AckPacket(void) { unsigned char ucAck; ucAck = COMMAND_ACK; return(UARTSendData(&ucAck, 1)); }
//**************************************************************************** // //! NakPacket() sends a No Acknowledge packet. //! //! This function sends a no acknowledge for a packet that has been //! received unsuccessfully from the device. //! //! \return The function returns zero to indicated success while any non-zero //! value indicates a failure. // //**************************************************************************** int NakPacket(void) { unsigned char ucNak; ucNak = COMMAND_NAK; return(UARTSendData(&ucNak, 1)); }
//**************************************************************************** // //! NakPacket() sends a No Acknowledge packet. //! //! This function sends a no acknowledge for a packet that has been //! received unsuccessfully from the device. //! //! \return The function returns zero to indicated success while any non-zero //! value indicates a failure. // //**************************************************************************** int32_t NakPacket(void) { uint8_t ui8Nak; ui8Nak = COMMAND_NAK; return(UARTSendData(&ui8Nak, 1)); }
//**************************************************************************** // //! AckPacket() sends an Acknowledge a packet. //! //! This function acknowledges a packet has been received from the device. //! //! \return The function returns zero to indicated success while any non-zero //! value indicates a failure. // //**************************************************************************** int32_t AckPacket(void) { uint8_t ui8Ack; ui8Ack = COMMAND_ACK; return(UARTSendData(&ui8Ack, 1)); }
int _write (int fd, char *ptr, int len) { /* Write "len" of char from "ptr" to file id "fd" * Return number of char written. * Need implementing with UART here. */ int i; for( i = 0; i < len; i++ ) UARTSendData((int)(unsigned char)ptr[i]); return len; }
/* Function to find out where the Application is and copy to DRAM */ Uint32 NOR_Copy() { volatile NOR_BOOT *hdr = 0; VUint32 *appStartAddr = 0; VUint32 count = 0; VUint32 *ramPtr = 0; Uint32 blkSize, blkAddress; UARTSendData((Uint8 *) "Starting NOR Copy...\r\n", FALSE); // Nor Initialization if (NOR_Init() != E_PASS) return E_FAIL; DiscoverBlockInfo( (gNorInfo.flashBase + UBL_IMAGE_SIZE), &blkSize, &blkAddress ); hdr = (volatile NOR_BOOT *) (blkAddress + blkSize); /* Magic number found */ if((hdr->magicNum & 0xFFFFFF00) != MAGIC_NUMBER_VALID) { return E_FAIL;/* Magic number not found */ } /* Set the Start Address */ appStartAddr = (Uint32 *)(((Uint8*)hdr) + sizeof(NOR_BOOT)); if(hdr->magicNum == UBL_MAGIC_BIN_IMG) { ramPtr = (Uint32 *) hdr->ldAddress; /* Copy data to RAM */ for(count = 0; count < ((hdr->appSize + 3)/4); count ++) { ramPtr[count] = appStartAddr[count]; } gEntryPoint = hdr->entryPoint; /* Since our entry point is set, just return success */ return E_PASS; } if(SRecDecode((Uint8 *)appStartAddr, hdr->appSize, (Uint32 *)&gEntryPoint, (Uint32 *)&count ) != E_PASS) { return E_FAIL; } return E_PASS; }
//**************************************************************************** // //! AutoBaud() performs Automatic baud rate detection. //! //! This function will send the sync pattern to the board and establish basic //! communication with the device. The call to OpenUART() in the routine //! main() set the baud rate that will be used. //! //! \return If any part of the function fails, the function will return a //! negative error code. The function will return 0 to indicate success. // //**************************************************************************** int32_t AutoBaud(void) { static uint8_t const pui8SyncPattern[]={0x55, 0x55}; uint8_t ui8Command; uint8_t ui8Ack; // // Send out the sync pattern and wait for an ack from the board. // if(UARTSendData(pui8SyncPattern, 2)) { return(-1); } // // Wait for the ACK to be received, if something besides an ACK or a zero // is received then something went wrong. // do { UARTReceiveData(&ui8Ack, 1); } while(ui8Ack == 0); if (ui8Ack != COMMAND_ACK) { return(-1); } // // Make sure we can at least communicate with the board. // ui8Command = COMMAND_PING; if(SendCommand(&ui8Command, 1) < 0) { return(-1); } return(0); }
//***************************************************************************** // //! SendPacket() sends a data packet. //! //! \param pucData is the location of the data to be sent to the device. //! \param ucSize is the number of bytes to send from puData. //! \param bAck is a boolean that is true if an ACK/NAK packet should be //! received in response to this packet. //! //! This function sends a packet of data to the device. //! //! \returns The function returns zero to indicated success while any non-zero //! value indicates a failure. // //***************************************************************************** int SendPacket(unsigned char *pucData, unsigned char ucSize, unsigned long bAck) { unsigned char ucCheckSum; unsigned char ucAck; ucCheckSum = CheckSum(pucData, ucSize); // // Make sure that we add the bytes for the size and checksum to the total. // ucSize += 2; // // Send the Size in bytes. // if(UARTSendData(&ucSize, 1)) { return(-1); } // // Send the CheckSum // if(UARTSendData(&ucCheckSum, 1)) { return(-1); } // // Now send the remaining bytes out. // ucSize -= 2; // // Send the Data // if(UARTSendData(pucData, ucSize)) { return(-1); } // // Return immediately if no ACK/NAK is expected. // if(!bAck) { return(0); } // // Wait for the acknoledge from the device. // do { if(UARTReceiveData(&ucAck, 1)) { return(-1); } } while(ucAck == 0); if(ucAck != COMMAND_ACK) { return(-1); } return(0); }
//***************************************************************************** // //! SendPacket() sends a data packet. //! //! \param pui8Data is the location of the data to be sent to the device. //! \param ui8Size is the number of bytes to send from puData. //! \param bAck is a boolean that is true if an ACK/NAK packet should be //! received in response to this packet. //! //! This function sends a packet of data to the device. //! //! \returns The function returns zero to indicated success while any non-zero //! value indicates a failure. // //***************************************************************************** int32_t SendPacket(uint8_t *pui8Data, uint8_t ui8Size, bool bAck) { uint8_t ui8CheckSum; uint8_t ui8Ack; ui8CheckSum = CheckSum(pui8Data, ui8Size); // // Make sure that we add the bytes for the size and checksum to the total. // ui8Size += 2; // // Send the Size in bytes. // if(UARTSendData(&ui8Size, 1)) { return(-1); } // // Send the CheckSum // if(UARTSendData(&ui8CheckSum, 1)) { return(-1); } // // Now send the remaining bytes out. // ui8Size -= 2; // // Send the Data // if(UARTSendData(pui8Data, ui8Size)) { return(-1); } // // Return immediately if no ACK/NAK is expected. // if(!bAck) { return(0); } // // Wait for the acknowledge from the device. // do { if(UARTReceiveData(&ui8Ack, 1)) { return(-1); } } while(ui8Ack == 0); if(ui8Ack != COMMAND_ACK) { return(-1); } return(0); }
void _ttywrch(int ch) { /* Write one char "ch" to the default console * Need implementing with UART here. */ UARTSendData(ch); }
void UARTSendStr(const char *str) { while( *str != '\0' ) UARTSendData( (int)(unsigned char)*str++ ); }
//***************************************************************************** // // This example application demonstrates the use of the timers to generate // periodic interrupts. // //***************************************************************************** int main(void) { // // Set the clocking to run directly from the crystal at 120MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // Setup for ultrasonic ranger // // Enable GPIO M // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); // // Enable GPIO pin for timer event capture (M4). // ROM_GPIOPinTypeTimer(GPIO_PORTM_BASE, GPIO_PIN_4); // // Configure 7 segment display gpio pins // sevenSegSetup(); // // Initialize timer for distance pulse measurement. // ConfigureDistancePulseTimer(); ROM_FPULazyStackingEnable(); //Enable lazy stacking for faster FPU performance ROM_FPUEnable(); //Enable FPU TimerACount = 0; TimerBCount = 0; TimerCCount = 0; TimerDCount = 0; g_temp_index = 0; g_prox_index = 0; g_light_index = 0; // // Initialize the UART and write status. // ConfigureUART(); UARTprintf("\033[2J"); //Clear screen //UARTprintf("\033[2JFinal Project Timers Example\n"); configureADC(); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Real Time Clock ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); //Temperature ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); //Proximity ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3); //Light ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5); //Timer5 is used to measure the leading edge pulses from the signal generator // Enable the A peripheral used by the Timer3 pin PA6, PA7 // Enable the B peripheral used by the Timer5 pin PB2, PB3 // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //Enable GPIO A ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Enable GPIO B //Configure the pins for its Timer functionality ROM_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2); //Enable Timer5 on PB2 //Configures the alternate function of a GPIO pin for Timer5 ROM_GPIOPinConfigure(GPIO_PB2_T5CCP0); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Configure the four 32-bit periodic timers. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); ROM_TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC); ROM_TimerConfigure(TIMER3_BASE, TIMER_CFG_PERIODIC); ROM_TimerConfigure(TIMER5_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT); // Timer5 ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ui32SysClock / 10); //RTC 100ms ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, g_ui32SysClock / 5); //Temp 200ms ROM_TimerLoadSet(TIMER2_BASE, TIMER_A, g_ui32SysClock / 2); //Proximity 500ms ROM_TimerLoadSet(TIMER3_BASE, TIMER_A, g_ui32SysClock / 10); //Light 100ms ROM_TimerLoadSet(TIMER5_BASE, TIMER_A, 65000); // Timer5 //Configure the signal edges that triggers the timer when in capture mode ROM_TimerControlEvent(TIMER5_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); // // Setup the interrupts for the timer timeouts. // ROM_IntEnable(INT_TIMER0A); //RTC ROM_IntEnable(INT_TIMER1A); //Temp ROM_IntEnable(INT_TIMER2A); //Proximity ROM_IntEnable(INT_TIMER3A); //Light ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); //RTC ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); //Temp ROM_TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); //Proximity ROM_TimerIntEnable(TIMER3_BASE, TIMER_TIMA_TIMEOUT); //Light // // Enable the timers. // ROM_TimerEnable(TIMER0_BASE, TIMER_A); //RTC ROM_TimerEnable(TIMER1_BASE, TIMER_A); //Temp ROM_TimerEnable(TIMER2_BASE, TIMER_A); //Proximity ROM_TimerEnable(TIMER3_BASE, TIMER_A); //Light ROM_TimerEnable(TIMER5_BASE, TIMER_A); //Timer5 // // Loop forever while the timers run. // while(1) { //Process data (Busy-Wait Loop) //If a flag hasn't been set by the interrupt the calc functions will simply exit //For performance it makes more sense to check flags here instead of at the beginning of the functions calcTemp(); //Calculates Temperature reading calcProx(); //Calculates Proximity reading calcLight(); //Calculates Light reading UARTSendData(); //Sends read data through UART } }