void uart0Init (uint32_t baudRate) { rbInit(&rxBuf); rbInit(&txBuf); const uint32_t UARTCLKDIV=1; /* Setup the clock and reset UART0 */ LPC_SYSCON->UARTCLKDIV = UARTCLKDIV; // NVIC_DisableIRQ(UART0_IRQn); LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 14); LPC_SYSCON->PRESETCTRL &= ~(1 << 3); LPC_SYSCON->PRESETCTRL |= (1 << 3); /* Configure UART0 */ SystemCoreClockUpdate(); uint32_t clk = SystemCoreClock / UARTCLKDIV; LPC_USART0->CFG = UART_DATA_LENGTH_8 | UART_PARITY_NONE | UART_STOP_BIT_1; LPC_USART0->BRG = clk / 16 / baudRate - 1; LPC_SYSCON->UARTFRGDIV = 0xFF; LPC_SYSCON->UARTFRGMULT = (((clk / 16) * (LPC_SYSCON->UARTFRGDIV + 1)) / (baudRate * (LPC_USART0->BRG + 1))) - (LPC_SYSCON->UARTFRGDIV + 1); /* Clear the status bits */ LPC_USART0->STAT = UART_STATUS_CTSDEL | UART_STATUS_RXBRKDEL; /* Enable UART0 interrupt */ NVIC_EnableIRQ(UART0_IRQn); /* Enable UART0 */ LPC_USART0->CFG |= UART_ENABLE; }
int testBuffer() { printf("Ring buffer test:\n\n"); RingBuffer_t rb; rbInit(&rb, 5); printf("Is empty: %d\n", rbIsEmpty(&rb)); int i; for(i = 1; i <= rb.size; i++) { rbWrite(&rb, i); } printf("Is empty: %d\n", rbIsEmpty(&rb)); for(i = 0; i < rb.size; i++) { printf("read value %d:%d\n", i, rbRead(&rb, i)); } printf("\n"); rbWrite(&rb, rb.size+1); for(i = 0; i < rb.size; i++) { printf("read value %d:%d\n", i, rbRead(&rb, i)); } printf("\nfree\n"); rbFree(&rb); printf("Is empty: %d\n", rbIsEmpty(&rb)); return 0; }
/** * @brief Initialises IOs, Motor driver, watchdog, UART, filtered ADC * */ void init(void) { error_reg = 0x00; //! Error Register //! Defining the Outputs DDR_DRV |= DRV_EN | DRV_MODE | DRV_PHASE | DRV_SLEEP; DDR_LIMIT_A_OUT |= LIMIT_A_OUT; DDR_LIMIT_B_OUT |= LIMIT_B_OUT; DDR_DIR_A_LED |= DIR_A_LED; DDR_DIR_B_LED |= DIR_B_LED; DDR_ERR_LED |= DIR_ERR_LED; DDR_PWR_LED |= PWR_LED; SET_PWR_LED; //! Set Power LED MOTOR_BREAK; //! Engine on brake if (MCUCSR & (1<<WDRF)) //! Checking the watchdog-flag { error_reg |= ERR_WATCHDOG; //! If a watchdog reset occurs, set the bit 6 of the error register high MCUCSR = ~(1<<WDRF); //! Delete the watchdog flag } init_uart(); //! Call the UART init ADC_init (); //! Call the ADC init pRbUFuse= &rbUFuse; pRbU24 = &rbU24; pRbIDrv = &rbIDrv; rbInit(pRbUFuse); //! Init ring buffers for median rbInit(pRbU24); rbInit(pRbIDrv); Interrupt_init(); //! Call Interrupt init WDT_init (); //! Call watchdog init return; //! Return }
void main(void) { // Configure cpu and mandatory peripherals cpuInit(); // Configure the CPU // we do it later // systickInit(CFG_SYSTICK_DELAY_IN_MS); // Start systick timer // cpuInit already calls this // gpioInit(); // Enable GPIO pmuInit(); // Configure power management adcInit(); // Config adc pins to save power // initialise basic badge functions rbInit(); initUUID(); // Cache UUID values. lcdInit(); // display lcdFill(0); lcdDisplay(); switch(getInputRaw()){ case BTN_ENTER: lcdPrint("ISP active"); lcdRefresh(); ReinvokeISP(); break; case BTN_DOWN: lcdPrint("MSC active"); lcdRefresh(); usbMSCInit(); while(1); break; }; fsInit(); if( getInputRaw() == BTN_UP ){ // Reset config saveConfig(); } wrapper(); // see applications/ subdirectory }
int main(void) { // Configure cpu and mandatory peripherals cpuInit(); // Configure the CPU // we do it later // systickInit(CFG_SYSTICK_DELAY_IN_MS); // Start systick timer // cpuInit already calls this // gpioInit(); // Enable GPIO pmuInit(); // Configure power management adcInit(); // Config adc pins to save power // initialise basic badge functions rbInit(); fsInit(); lcdInit(); // display lcdFill(0); lcdDisplay(); wrapper(); // see module/ subdirectory }
int main(void) { cpuInit(); systickInit(CFG_SYSTICK_DELAY_IN_MS); pmuInit(); // adcInit(); #ifdef R0KET rbInit(); #else badge_init(); #endif FATFS fs; f_mount(0, &fs); #ifdef USBONLY if(badge_input_raw() & BADGE_EVENT_KEY_LEFT) { gpioSetValue(HOB_PORT(HOB_LED_LEFT), HOB_PIN(HOB_LED_LEFT) , 1); } if(badge_input_raw() & BADGE_EVENT_KEY_RIGHT) { gpioSetValue(HOB_PORT(HOB_LED_RIGHT), HOB_PIN(HOB_LED_RIGHT) , 1); } for(;;) usbmode(); #else if(badge_input_raw() & BADGE_EVENT_KEY_DOWN) { usbmode(); } badge_event_start(); badge_vanity_show(); main_menu(); #endif return 0; }
int main() { unsigned int ret; tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA; printf("\n--Test of ring buffer functionality--\n"); printf("Initializing PRU..."); prussdrv_init(); printf("\t\t\t\tDone\n"); ret = prussdrv_open(PRU_EVTOUT_0); printf("Checking prussdrv_open()..."); if (ret) { printf("prussdrv_open failed!\n"); printf("Aborting application!\n"); return (ret); } printf("\t\t\tDone\n"); printf("Initializing INTC..."); prussdrv_pruintc_init(&pruss_intc_initdata); printf("\t\t\t\tDone\n"); //map PRU shared RAM to userspace printf("Mapping PRU memory to userspace..."); prussdrv_map_prumem(PRUSS0_SHAREDRAM, &sharedMem); printf("\t\t\tDone\n"); //create and initialize ring buffer printf("Initializing ring buffer in PRU shared memory..."); sharedMem_rbint = (unsigned int *) sharedMem; rbInit(sharedMem_rbint, DEF_RB_SIZE); printf("\t\t\t\tDone\n"); //printf("Loading test program...\n"); //prussdrv_exec_program(PRU_NUM, "./boneclamp.bin"); prussdrv_exec_program(PRU_NUM, "./test.bin"); /* read stuff from ring buffer */ /* data *currentDatapoint = calloc(1, sizeof(data)); while(1) { if (!rbIsEmpty(buffer)) { rbRead(buffer, currentDatapoint); printf("Channel: %i Value: %i", currentDatapoint->channelNumber, currentDatapoint->datap); if (currentDatapoint->datap == 20) { break; } } else printf("Buffer currently empty"); } */ //free(currentDatapoint); //rbFree(sharedMem_rb); //wait until PRU program is completed printf("Test complete. Do the results make sense?\n"); prussdrv_pru_wait_event(PRU_EVTOUT_0); prussdrv_pru_clear_event(PRU_EVTOUT_0); //shut down the pru printf("Shutting down the PRU..."); prussdrv_pru_disable(PRU_NUM); prussdrv_exit(); //close(mem_fd); printf("\t\t\t\tDone\n"); return 0; }
_INIT void Init(void) { rbInit(&myRB, ringBuffer, RB_SIZE); }