USHORT Hal4D13_GetDataFromChipRam(void) { USHORT i; IOWR(USB_0_BASE,D13_COMMAND_PORT,D13CMD_DEV_RD_RAM); i = IORD(USB_0_BASE,D13_DATA_PORT); return i; }
USHORT Hal4D13_GetDevConfig(void) { USHORT i; IOWR(USB_0_BASE,D13_COMMAND_PORT,D13CMD_DEV_RD_CNFG); i = IORD(USB_0_BASE,D13_DATA_PORT); return i; }
USHORT Hal4D13_GetDMACounter(void) { USHORT i; IOWR(USB_0_BASE,D13_COMMAND_PORT,D13CMD_DMA_RD_COUNT); i = IORD(USB_0_BASE,D13_DATA_PORT); return i; }
USHORT Hal4D13_ReadChipID(void) { USHORT i; IOWR(USB_0_BASE, D13_COMMAND_PORT, D13CMD_DEV_RD_CHIPID); i=IORD(USB_0_BASE, D13_DATA_PORT); return i; }
UCHAR Hal4D13_GetEndpointStatusWOInteruptClear(UCHAR bEPIndex) { UCHAR c; IOWR(USB_0_BASE,D13_COMMAND_PORT, D13CMD_EP_RDSTS + bEPIndex); c = (UCHAR)(IORD(USB_0_BASE,D13_DATA_PORT) &0x0ff); return c; }
UCHAR Hal4D13_GetErrorCode(UCHAR bEPIndex) { UCHAR c; IOWR(USB_0_BASE,D13_COMMAND_PORT, D13CMD_EP_RD_ERR+bEPIndex); c = (UCHAR)(IORD(USB_0_BASE,D13_DATA_PORT)&0x0ff); return c; }
/** * * This function reads data from the internal registers of the Cypress * CY7C67200 USB controller. * * @param Address is the address of the register. * * @return The data read from the specified address * * @note None * ******************************************************************************/ alt_u16 UsbRead(alt_u16 Address) { //XIo_Out16(HPI_ADDR, Address); IOWR(CY7C67200_BASE,HPI_ADDR,Address); //usleep(20); return IORD(CY7C67200_BASE,HPI_DATA); }
/* Tests basic sigmoid functionality */ int test_sigmoid(void){ float M,time,result; alltypes_u input; M = 2.24; time = 3.8; result = 0; fprintf(stderr,"Starting sigmoid test....\n"); fprintf(stderr,"Sigmoid block test register returns [%X].\n", IORD(EULERBLOCK_0_BASE,3)); fprintf(stderr,"Floats have byte count of [%d].\n",(int)sizeof(float)); input.fl = M; IOWR(EULERBLOCK_0_BASE,0,input.ui); /* Check it's corrent */ input.ui = IORD(EULERBLOCK_0_BASE, 0); fprintf(stderr,"Inputs are M=[%4.2f], time=[%4.2f].\n",M,time); fprintf(stderr,"IORD returns [%4.8f].\n", input.fl); sigmoid(M, time, &result); fprintf(stderr,"Sigmoid returned [%4.8f].\n", result); return 0; }
USHORT Hal4D13_ReadCurrentFrameNumber(void) { USHORT i; IOWR(USB_0_BASE,D13_COMMAND_PORT, D13CMD_RD_FRMNUM); i= IORD(USB_0_BASE,D13_DATA_PORT); return i; }
UCHAR Hal4D13_GetEndpointConfig(UCHAR bEPIndex) { UCHAR c; IOWR(USB_0_BASE,D13_COMMAND_PORT, D13CMD_EP_RD_CNFG+bEPIndex); c = (UCHAR)(IORD(USB_0_BASE,D13_DATA_PORT) & 0x0ff); return c; }
/* Parses user input string and performs relevant method. */ void processCommand(char * userInput, int userInputLength) { int userParams [50]; int nParams = 0; int error = 0; if(userInputLength > 0) { nParams = getUserParams(userInput, userParams); if(strncmp(userInput, "help",4) == 0) printHelp(); else if(strncmp(userInput, "wc ", 3) == 0) if(nParams == 2) { IOWR(CONTROL_BASE, userParams[0], userParams[1]); printf("%s\n", userInput); } else { error = 1; } else if(strncmp(userInput, "rc ", 3) == 0) if(nParams == 1) { userParams[4] = IORD(CONTROL_BASE, userParams[0]); printf("%s: %d %x\n", userInput, userParams[4], userParams[4]); } else error = 1; else if(strncmp(userInput, "restart", 7) == 0) restart(); else if(strncmp(userInput, "pause", 5) == 0) pause(); else if(strncmp(userInput, "set adc", 7) == 0) { if(nParams == 4) { setADCParams(userParams[0], userParams[1], userParams[2], userParams[3]); } else error = 1; } else { error = 1; } // Invalid Command if(error == 1) printf("%s: Unknown Command. Type 'help' for list of commands.\n", userInput); } }
ULONG Hal4D13_GetIntEnable(void) { ULONG i; IOWR(USB_0_BASE,D13_COMMAND_PORT,D13CMD_DEV_RD_INTEN); i = IORD(USB_0_BASE,D13_DATA_PORT); i += (((ULONG)IORD(USB_0_BASE,D13_DATA_PORT)) << 16); return i; }
void init_timer() { ticks = 0; /* ajastimen keskeytys päälle */ IOWR(TIMER, TIMER_CONTROL, 1); write_irq_mask(1u << TIMER_IRQ); }
static void pulse_ISR(void* context, alt_u32 id) { if (IORD(PIO_PULSE_BASE, 0) == 0) { IOWR(PIO_RESPONSE_BASE, 0, 1); flag++; } //IOWR(PIO_RESPONSE_BASE, 0, 1); if (IORD(PIO_PULSE_BASE, 0) == 1) { IOWR(PIO_RESPONSE_BASE, 0, 0); flag++; } // clear interrupt //IOWR(PIO_PULSE_BASE, 0, 0); IOWR(PIO_PULSE_BASE, 3, 0x0); }
// Send dummy clock pulse void SD_Ncc() { IOWR(AVSDC_0_BASE, 0, AV_SDC_SEND_DUMMY); /*for (int i = 0; i < 8; i++) { SD_ClockPulse(); }*/ }
int main(void) { if (init_system() != 0) return(-1); indexed_file_count = build_file_index(files); printf("Indexed files: %d\n", indexed_file_count); IOWR(BUTTON_PIO_BASE, 2, 0xf); IOWR(BUTTON_PIO_BASE, 3, 0x0); alt_irq_register( BUTTON_PIO_IRQ, (void*)0, button_ISR ); IOWR(LED_PIO_BASE, 0, 0x00); player_state = PLAYER_STATE_DEFAULT; int length; data_file file; while(1){ if ((cur_file_index_update == 1) || (player_state_update == 1)) { if (cur_file_index_update) file = files[cur_file_index]; switch (player_state){ case PLAYER_STATE_PLAYING: LCD_File_Buffering(file.Name); length = 1 + ceil(file.FileSize/(BPB_BytsPerSec*BPB_SecPerClus)); build_cluster_chain(cluster_chain, length, &file); LCD_Display(file.Name, player_mode); play(&file, buffer, cluster_chain, player_mode); player_state = PLAYER_STATE_USER_INPUT; case PLAYER_STATE_USER_INPUT: LCD_Display(file.Name, player_mode); } player_state_update = 0; cur_file_index_update = 0; } } return(0); }
void phy_write(unsigned int reg, unsigned int value) { /* set PHY register address into EPAR REG. 0CH */ dm9000a_iow(0x0C, reg | 0x40); /* PHY register address setting, and DM9000_PHY offset = 0x40 */ /* fill PHY WRITE data into EPDR REG. 0EH & REG. 0DH */ dm9000a_iow(0x0E, ((value >> 8) & 0xFF)); /* PHY data high_byte */ dm9000a_iow(0x0D, value & 0xFF); /* PHY data low_byte */ /* issue PHY + WRITE command = 0xa into EPCR REG. 0BH */ dm9000a_iow(0x0B, 0x8); /* clear PHY command first */ IOWR(DM9000A_INST_BASE, IO_data, 0x0A); /* issue PHY + WRITE command */ usleep(STD_DELAY); IOWR(DM9000A_INST_BASE, IO_data, 0x08); /* clear PHY command again */ usleep(50); /* wait 1~30 us (>20 us) for PHY + WRITE completion */ }
static void timer_ISR(void* context, alt_u32 id) { // acknowledge the interrupt by clearing the TO bit in the status register IOWR(TIMER_0_BASE, 0, 0x0); // set the flag with a non zero value count_flag = 0xf; }
int main() { int i; unsigned long sw_time_1, sw_time_2; //enable the temperature sensor temp_sensor_init(); //enable uCProbe communication ProbeCom_Init(); ProbeRS232_Init(0); ProbeRS232_RxIntEn(); // turn off the LEDS IOWR(LED_PIO_BASE,0,0xFF); printf("BeMicro SDK Lab1: \n"); printf("-----------------\n\n"); // Create the input data waveform printf("Creating buffer source data\n\n"); for(i = 0; i < DATA_BUFFER_SIZE; i++) { source_databuffer[i] = input_data[i%INPUT_LENGTH]; } // record the value of the high resolution time-stamp timer at the entry and exit points of the software filter if(alt_timestamp_start() < 0) { printf("Please add the high resolution timer to the timestamp timer setting in the syslib properties page.\n"); return 0; } printf("Software filter is operating (please be patient)\n"); sw_time_1 = alt_timestamp(); FIR_SW(source_databuffer, DATA_BUFFER_SIZE, sw_destination_databuffer, T, coefficients[0], coefficients[1], coefficients[2], coefficients[3], coefficients[4], coefficients[5], coefficients[6], coefficients[7], DIVIDER_ORDER); sw_time_2 = alt_timestamp(); printf("Software filter is done\n\n"); sw_proc_time = ((double)(sw_time_2-sw_time_1))/((double)alt_timestamp_freq()); printf("Software processing time was: %f seconds\n\n", sw_proc_time); printf("Processing time will also be reported by uC-Probe:\n"); return 1; }
void VPG_Config(VPG_MODE Mode, COLOR_TYPE Color) { #ifndef TX_DISABLED //===== check whether vpg function is active if (!HDMITX_HPD()) return; #ifndef RX_DISABLED if (HDMIRX_IsVideoOn()) return; #endif //RX_DISABLED OS_PRINTF("===> Pattern Generator Mode: %d (%s)\n", gVpgMode, gszVicText[gVpgMode]); //===== updagte vpg mode & color IOWR(HDMI_TX_MODE_CHANGE_BASE, 0, 0); // change color mode of VPG if (gVpgColor == COLOR_RGB444) IOWR(HDMI_TX_VPG_COLOR_BASE, 0, VPG_RGB444); // RGB444 else if (gVpgColor == COLOR_YUV422) IOWR(HDMI_TX_VPG_COLOR_BASE, 0, VPG_YUV422); // YUV422 else if (gVpgColor == COLOR_YUV444) IOWR(HDMI_TX_VPG_COLOR_BASE, 0, VPG_YUV444); // YUV444 IOWR(HDMI_TX_DISP_MODE_BASE, 0, gVpgMode); IOWR(HDMI_TX_MODE_CHANGE_BASE, 0, 1); IOWR(HDMI_TX_MODE_CHANGE_BASE, 0, 0); // //HDMITX_EnableVideoOutput(); #endif //#ifndef TX_DISABLED }
// Function Name: phase2_periodicpolling // Function Purpose: Performs the necessary steps to set up timer_1 to // periodically poll the EGM for the current pulse at an // interval of 20us. When the interrupts are generated, // they are handled by the ISR called timer_ISR(). After the // timer is started and set to run continuously, the init() // function is called to set up the EGM. An infinite while // loop is used to run the background task. After 100 pulses // have been captured, the test results are outputted and // global variables used are reset for a clean testing // environment. // Function Parameters: // period: the period of each pulse outputted by the EGM (input*81.93us) // dutycycle: the duration for which the signal is held high (input*period/16) // granularity: the maximum number of task units to complete per each call to // background() void phase2_periodicpolling(int period, int dutycycle, int granularity) { #ifdef TIMER_1_BASE // only compile this code if timer_1 is defined // 32 bit period used for timer alt_u32 timerPeriod; // calculate timer period setting it at // 1s / 50000 = 20us. timerPeriod = TIMER_1_FREQ / 50000; // initialize timer interrupt vector alt_irq_register(TIMER_1_IRQ, (void*)0, timer_ISR); // initialize timer period IOWR(TIMER_1_BASE, 2, (alt_u16)timerPeriod); IOWR(TIMER_1_BASE, 3, (alt_u16)(timerPeriod >> 16)); // clear timer interrupt bit in status register IOWR(TIMER_1_BASE, 0, 0x0); // initialize timer control - start timer, run continuously, enable interrupts IOWR(TIMER_1_BASE, 1, 0x7); #endif // Call init() with the period and dutycycle parameters to set up the // EGM and run the background task with the granularity parameter as // long as the number of pulses is less than 100. After 100 pulses, // call finalize() to output the test results and reset the number of // edges and pulses and the state of the previous_pulse to provide the // next synchronization method test with a clean testing environment. init(period, dutycycle); while(numPulses < 100) { background(granularity); } printf("PERIODIC POLLING - PERIOD: %d\t DUTYCYCLE: %d\t GRANULARITY: %d\t\n", period, dutycycle, granularity); finalize(); numPulses = 0; numEdges = 0; previous_pulse = 0; // Make the thread sleep for 0.5s to provide enough time for the // finalize() method to output all of its data to the console. usleep(500000); }
static void timer_isr(void * context){ //el proceso que llama la interrupcion static unsigned short counter = 0; IOWR(LEDS_BASE, 0, counter); counter++; printf("Llego a la interrupcion\n"); //debe hacer clear de la interrupcion clr_timer_irq(); }
void PWM_Task(void* pData){ //generate PWM signal and send it through GPIO pins //keep going forward while path is clear double duty = 0; duty = 0.75; IOWR(PWM_0_BASE, 0, 0.5 * 31250); //100% usleep(1000000); while (1) { IOWR(PWM_0_BASE, 0, 1 * 31250); //100% usleep(4000000); } }
void LSM303_Task(void *pData){ bool bSuccess; // release i2c pio pin //IOWR_ALTERA_AVALON_PIO_DIRECTION(I2C_SCL_BASE, ALTERA_AVALON_PIO_DIRECTION_OUTPUT); //IOWR_ALTERA_AVALON_PIO_DIRECTION(I2C_SDA_BASE, ALTERA_AVALON_PIO_DIRECTION_INPUT); IOWR(SELECT_I2C_CLK_BASE, 0, 0x00); }
ULONG Hal4D13_ReadInterruptRegister(void) { ULONG j,i = 0; IOWR(USB_0_BASE,D13_COMMAND_PORT, D13CMD_DEV_INT_SRC); i = IORD(USB_0_BASE,D13_DATA_PORT); j = IORD(USB_0_BASE,D13_DATA_PORT); j = ((j<<16) & 0xffff0000 ) + (i & 0xffff); return i; }
static void button_ISR(void* context, alt_u32 id){ edge ^= 1; buttons = IORD(BUTTON_PIO_BASE, 3) & 0xf; if (edge == 1) { IOWR(LED_PIO_BASE, 0, buttons); } else { switch (player_state) { case PLAYER_STATE_USER_INPUT: switch (buttons) { case BTN_PLAY: player_state = PLAYER_STATE_PLAYING; player_mode = IORD(SWITCH_PIO_BASE, 0); player_state_update = 1; break; case BTN_FWD: cur_file_index = (cur_file_index < indexed_file_count - 1) ? (cur_file_index + 1) : 0; cur_file_index_update = 1; break; case BTN_BWD: cur_file_index = (cur_file_index > 0) ? (cur_file_index - 1) : (indexed_file_count - 1); cur_file_index_update = 1; break; } case PLAYER_STATE_PLAYING: switch (buttons) { case BTN_STOP: player_state = PLAYER_STATE_USER_INPUT; player_state_update = 1; break; } } IOWR(LED_PIO_BASE, 0, 0x00); } IOWR(BUTTON_PIO_BASE, 3, 0x0); }
void UsbPrintMem() { int i, code; IOWR(CY7C67200_BASE,HPI_ADDR,0x0500); //the start address for (i = 0; i <= 200; i += 2) { code = IORD(CY7C67200_BASE,HPI_DATA); printf("\naddr %x = %04x\n", 0x0500+i, code); } }
int main() { printf("Start main...\n"); init_button_irq(); printf("PB initialized...\n"); init_counter_irq(); printf("Counter IRQ initialized...\n"); IOWR(LED_GREEN_O_BASE, 0, 0x0); IOWR(LED_RED_O_BASE, 0, 0x0); printf("Switch value: %X\n", IORD(SWITCH_I_BASE, 0)); while (1); return 0; }
void serial_init(unsigned int baud) { //inhibit all UART IRQ sources IOWR(UART_0_BASE, 3, 0x00); //set Baud rate IOWR(UART_0_BASE, 4, baud); //flush any characters sitting in the holding register IORD(UART_0_BASE, 0); IORD(UART_0_BASE, 0); //reset most of the status register bits IOWR(UART_0_BASE, 2, 0x00); //install IRQ service routine alt_irq_register(UART_0_IRQ, 0, serial_irq_0); alt_irq_enable(UART_0_IRQ); //enable irq for Rx. IOWR(UART_0_BASE, 3, 0x0080); }
void readANT(){ unsigned char packet[MAXPACKETLEN]; int packetsRead; unsigned char msgId, msgSize; unsigned char *msgData; packetsRead = readPacket(packet, MAXPACKETLEN, PACKETREADTIMEOUT); if (packetsRead > 0) { msgId = packet[2]; msgSize = packet[1]; msgData = &packet[3]; switch (msgId) { case MESG_RESPONSE_EVENT_ID: printHeader("MESG_RESPONSE_EVENT_ID: "); printPacket(packet); break; case MESG_CAPABILITIES_ID: printHeader("MESG_CAPABILITIES_ID: "); printPacket(packet); break; case MESG_BROADCAST_DATA_ID: if (oldHeartRate != msgData[msgSize-1]) { oldHeartRate = msgData[msgSize-1]; #ifdef DEBUG printHeader("New Heart Rate: "); printf("%i \n", oldHeartRate); #endif IOWR(HEARTRATEOUT_BASE, 0, oldHeartRate); //write to parallel out IOWR(WDT_BASE, 2, 0xFF); //reset watchdog timer } break; default: printHeader("MESG_ID_UKNOWN: "); printPacket(packet); break; } } }