int rt_hw_cpu_init(void) { MAP_IntMasterDisable(); IntRegister(FAULT_HARD, HardFault_Handler); IntRegister(FAULT_PENDSV, PendSV_Handler); IntRegister(FAULT_SYSTICK, SysTick_Handler); // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. MAP_FPULazyStackingEnable(); // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. SysClock = MAP_SysCtlClockFreqSet( (SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), SYS_CLOCK_DEFAULT); MAP_SysTickDisable(); MAP_SysTickPeriodSet(SysClock/ RT_TICK_PER_SECOND - 1); MAP_SysTickIntEnable(); MAP_SysTickEnable(); return 0; }
void timerInit() { #ifdef TARGET_IS_BLIZZARD_RB1 // // Run at system clock at 80MHz // MAP_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #else // // Run at system clock at 120MHz // MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ|SYSCTL_OSC_MAIN|SYSCTL_USE_PLL|SYSCTL_CFG_VCO_480), F_CPU); #endif // // SysTick is used for delay() and delayMicroseconds() // MAP_SysTickPeriodSet(F_CPU / SYSTICKHZ); MAP_SysTickEnable(); MAP_IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY); MAP_SysTickIntEnable(); MAP_IntMasterEnable(); // PIOSC is used during Deep Sleep mode for wakeup MAP_SysCtlPIOSCCalibrate(SYSCTL_PIOSC_CAL_FACT); // Factory-supplied calibration used }
int platform_init() { // Set the clocking to run from PLL #if defined( FORLM3S9B92 ) || defined( FORLM3S9D92 ) MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #else MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); #endif // Setup PIO pios_init(); // Setup SSIs spis_init(); // Setup UARTs uarts_init(); // Setup timers timers_init(); // Setup PWMs pwms_init(); #ifdef BUILD_ADC // Setup ADCs adcs_init(); #endif #ifdef BUILD_CAN // Setup CANs cans_init(); #endif // Setup system timer cmn_systimer_set_base_freq( MAP_SysCtlClockGet() ); cmn_systimer_set_interrupt_freq( SYSTICKHZ ); // Setup ethernet (TCP/IP) eth_init(); // Common platform initialization code cmn_platform_init(); // Virtual timers // If the ethernet controller is used the timer is already initialized, so skip this sequence #if VTMR_NUM_TIMERS > 0 && !defined( BUILD_UIP ) // Configure SysTick for a periodic interrupt. MAP_SysTickPeriodSet( MAP_SysCtlClockGet() / SYSTICKHZ ); MAP_SysTickEnable(); MAP_SysTickIntEnable(); MAP_IntMasterEnable(); #endif // All done return PLATFORM_OK; }
void init_hardware() { // Set SysTick timer period (TN_SYS_TICK_FQ_HZ) MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /////////// MAP_SysTickDisable(); MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / TN_SYS_TICK_FQ_HZ); MAP_SysTickIntEnable(); MAP_SysTickEnable(); }
StellarisIO() : magic(gMagic) { MAP_FPULazyStackingEnable(); /* Set clock to PLL at 50MHz */ MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / (1000*10)); // 1us MAP_SysTickIntEnable(); MAP_SysTickEnable(); }
void platform_init(void) { /* Enable lazy stacking for interrupt handlers. This allows floating-point instructions to be used within interrupt * handlers, but at the expense of extra stack usage. */ MAP_FPULazyStackingEnable(); /* Set clock to PLL at 50MHz */ MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* Enable the GPIO pins for the LED (PF2 & PF3). */ MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_2); /* Enable the system tick. FIXME do we need this? */ MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKS_PER_SECOND); MAP_SysTickIntEnable(); MAP_SysTickEnable(); }
void suspend(void) { stay_asleep = true; HWREG(NVIC_SYS_CTRL) |= NVIC_SYS_CTRL_SLEEPDEEP; while(stay_asleep) { MAP_IntMasterDisable(); // Set PRIMASK so CPU wakes on IRQ but ISRs don't execute until PRIMASK is cleared MAP_SysTickDisable(); // Halt SysTick during suspend mode - millis will no longer increment CPUwfi_safe(); MAP_SysTickEnable(); // Re-enable SysTick before ISRs start (in case ISR uses millis/micros) MAP_IntMasterEnable(); // Clearing PRIMASK allows pending ISRs to run } HWREG(NVIC_SYS_CTRL) &= ~(NVIC_SYS_CTRL_SLEEPDEEP); }
void systick_init() { // // Configure SysTick for a periodic interrupt. // MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKHZ); MAP_SysTickEnable(); MAP_SysTickIntEnable(); //MAP_IntEnable(INT_GPIOA); MAP_IntEnable(INT_GPIOE); MAP_IntMasterEnable(); MAP_SysCtlPeripheralClockGating(false); MAP_GPIOIntTypeSet(GPIO_PORTE_BASE, ENC_INT, GPIO_FALLING_EDGE); MAP_GPIOPinIntClear(GPIO_PORTE_BASE, ENC_INT); MAP_GPIOPinIntEnable(GPIO_PORTE_BASE, ENC_INT); UARTprintf("int enabled\n"); }
void SystemTimer::initialize() { uint32_t clockRate; __counter = 0; #ifdef CLASS_IS_TM4C123 clockRate = MAP_SysCtlClockGet(); #else clockRate = MAP_SysCtlClockFreqGet(); #endif if (clockRate == 66666666 && MCU_CLOCK == CLK80) { // some boards reports the clock frequency incorrectly clockRate = 80000000; } MAP_SysTickPeriodSet(clockRate / 1000); MAP_SysTickIntEnable(); MAP_SysTickEnable(); }
/** * This function will initial LPC40xx board. */ void rt_hw_board_init() { MAP_IntMasterDisable(); IntRegister(FAULT_HARD, HardFault_Handler); IntRegister(FAULT_PENDSV, PendSV_Handler); IntRegister(FAULT_SYSTICK, SysTick_Handler); // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // MAP_FPULazyStackingEnable(); // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // SysClock = MAP_SysCtlClockFreqSet( (SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), SYS_CLOCK_DEFAULT); MAP_SysTickDisable(); MAP_SysTickPeriodSet(SysClock/ RT_TICK_PER_SECOND - 1); MAP_SysTickIntEnable(); MAP_SysTickEnable(); /* set pend exception priority */ //IntPrioritySet(FAULT_PENDSV, (1 << 5) - 1); /*init uart device*/ rt_hw_uart_init(); //redirect RTT stdio to CONSOLE device rt_console_set_device(RT_CONSOLE_DEVICE_NAME); // // Enable interrupts to the processor. // MAP_IntMasterEnable(); }
int main(void) { IntVTableBaseSet((unsigned long)&g_pfnVectors[0]); MAP_PRCMPeripheralClkEnable(PRCM_GPIOA0, PRCM_RUN_MODE_CLK); MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK); MAP_PRCMPeripheralClkEnable(PRCM_GPIOA2, PRCM_RUN_MODE_CLK); MAP_PRCMPeripheralClkEnable(PRCM_GPIOA3, PRCM_RUN_MODE_CLK); MAP_IntMasterEnable(); PRCMCC3200MCUInit(); MAP_SysTickIntEnable(); MAP_SysTickPeriodSet(F_CPU / 1000); MAP_SysTickEnable(); setup(); for (;;) { loop(); if (serialEventRun) serialEventRun(); } }
int main(void) { int delay; float fTemperature, fPressure, fAltitude, fK_Altitude, fAltitude_sum,fK_Altitude_sum; int count,i; // static float f_meas[VAR_COUNT], fAlt_Mean, fAlt_Var; unsigned short sw1_count, sw2_count; unsigned char sw1_was_cleared = 0, sw2_was_cleared = 0; // Set the clocking to run directly from the external crystal/oscillator. MAP_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | WRFL_XTAL); //init ports and peripherals PlatformInit(); Nokia5110_Init(); Nokia5110_Clear(); Nokia5110_DrawFullImage(gears_logo); for(delay=0; delay<1000000; delay=delay+1); Nokia5110_Clear(); Nokia5110_SetCursor(3, 1); Nokia5110_OutString("WRFL"); Nokia5110_SetCursor(1, 2); Nokia5110_OutString("Prototype"); Nokia5110_SetCursor(2, 4); Nokia5110_OutString("VER 0.1"); Nokia5110_SetCursor(0, 5); Nokia5110_OutString("NightMecanic"); for(delay=0; delay<1000000; delay=delay+1); Nokia5110_Clear(); // // Enable interrupts to the processor. // MAP_IntMasterEnable(); // // Initialize I2C1 peripheral. // I2CMInit(&g_sI2CInst, BMP180_I2C_BASE, BMP180_I2C_INT, 0xff, 0xff, MAP_SysCtlClockGet()); // // Initialize the BMP180 // BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS, BMP180AppCallback, &g_sBMP180Inst); // // Wait for initialization callback to indicate reset request is complete. // while(g_vui8DataFlag == 0) { // // Wait for I2C Transactions to complete. // } // // Reset the data ready flag // g_vui8DataFlag = 0; //set oversampling to 8x g_sBMP180Inst.ui8Mode = 0xC0; //Initialize the Kalman filter Kalman_Init(&Alt_KState, 0.0f, 1.0f, ALT_KALMAN_R, ALT_KALMAN_Q); // // Enable the system ticks at 10 hz. // MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / (40 * 3)); MAP_SysTickIntEnable(); MAP_SysTickEnable(); Nokia5110_SetCursor(0, 0); Nokia5110_OutString("SW1:"); Nokia5110_SetCursor(0, 2); Nokia5110_OutString("SW2:"); //config done count = 0; // // Begin the data collection and printing. Loop Forever. // while(1) { // SW1 if (sw_state & SW1){ if (sw1_was_cleared){ sw1_was_cleared = 0; sw1_count++; Nokia5110_SetCursor(5, 0); Nokia5110_OutUDec(sw1_count); } }else sw1_was_cleared = 1; //SW2 if (sw_state & SW2){ if (sw2_was_cleared){ sw2_was_cleared = 0; sw2_count++; Nokia5110_SetCursor(5, 2); Nokia5110_OutUDec(sw2_count); } }else sw2_was_cleared = 1; // handle BMP180 data (display average every 50 samples) if (g_vui8DataFlag ){ // // Reset the data ready flag. // g_vui8DataFlag = 0; // // Get a local copy of the latest temperature data in float format. // BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature); // // Print temperature with three digits of decimal precision. // //Nokia5110_SetCursor(0, 0); //Nokia5110_OutString("Temp:"); //Nokia5110_OutFloatp3(fTemperature); // // Get a local copy of the latest air pressure data in float format. // BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure); // // Print Pressure with three digits of decimal precision. // //Nokia5110_SetCursor(0, 1); // Nokia5110_OutString("Pres:"); //Nokia5110_SetCursor(0, 2); //display in hPa //Nokia5110_OutFloatp3((fPressure / 100.0f)); // // Calculate the altitude. // //fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f, // 1.0f / 5.255f)); //corrected: fAltitude = 44330.0f * (1.0f - powf(fPressure / LOC_ALT_P0, 1.0f / 5.255f)); // Kalman filtered altitude Kalman_Update (&Alt_KState, fAltitude); fK_Altitude = Alt_KState.X; fAltitude_sum += fAltitude; fK_Altitude_sum += fK_Altitude; count++; if (count>=50){ Nokia5110_SetCursor(0, 3); Nokia5110_OutString("Alt:"); Nokia5110_OutFloatp3(fAltitude_sum/50.0); Nokia5110_SetCursor(0, 5); Nokia5110_OutString("KAlt:"); Nokia5110_OutFloatp3(fK_Altitude_sum/50.0); fAltitude_sum = 0; fK_Altitude_sum = 0; count = 0; } /* //calculate variance f_meas[count]=fK_Altitude; count++; if (count>=VAR_COUNT){ fAlt_Mean = 0.0f; fAlt_Var = 0.0f; // calculate mean for(i=0; i<VAR_COUNT; i++){ fAlt_Mean = fAlt_Mean +f_meas[i]; } fAlt_Mean = fAlt_Mean/((float) VAR_COUNT); // Calculate Var for(i=0; i<VAR_COUNT; i++){ fAlt_Var = fAlt_Var + powf((f_meas[i] - fAlt_Mean),2.0f); } fAlt_Var = fAlt_Var/((float) VAR_COUNT); // // Print altitude with three digits of decimal precision. // Nokia5110_SetCursor(0, 4); Nokia5110_OutString("Var:"); Nokia5110_OutFloatp3(fAlt_Var); count = 0; } */ // // Delay to keep printing speed reasonable. About 100msec. // //MAP_SysCtlDelay(MAP_SysCtlClockGet() / (10 * 3)); } }//while end }
void main(void) { static struct uip_eth_addr eth_addr; uip_ipaddr_t ipaddr; cpu_init(); uart_init(); printf("Welcome\n"); spi_init(); enc28j60_comm_init(); printf("Welcome\n"); enc_init(mac_addr); // // Configure SysTick for a periodic interrupt. // MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKHZ); MAP_SysTickEnable(); MAP_SysTickIntEnable(); //MAP_IntEnable(INT_GPIOA); MAP_IntEnable(INT_GPIOE); MAP_IntMasterEnable(); MAP_SysCtlPeripheralClockGating(false); printf("int enabled\n"); MAP_GPIOIntTypeSet(GPIO_PORTE_BASE, ENC_INT, GPIO_FALLING_EDGE); MAP_GPIOPinIntClear(GPIO_PORTE_BASE, ENC_INT); MAP_GPIOPinIntEnable(GPIO_PORTE_BASE, ENC_INT); uip_init(); eth_addr.addr[0] = mac_addr[0]; eth_addr.addr[1] = mac_addr[1]; eth_addr.addr[2] = mac_addr[2]; eth_addr.addr[3] = mac_addr[3]; eth_addr.addr[4] = mac_addr[4]; eth_addr.addr[5] = mac_addr[5]; uip_setethaddr(eth_addr); #define DEFAULT_IPADDR0 10 #define DEFAULT_IPADDR1 0 #define DEFAULT_IPADDR2 0 #define DEFAULT_IPADDR3 201 #define DEFAULT_NETMASK0 255 #define DEFAULT_NETMASK1 255 #define DEFAULT_NETMASK2 255 #define DEFAULT_NETMASK3 0 #undef STATIC_IP #ifdef STATIC_IP uip_ipaddr(ipaddr, DEFAULT_IPADDR0, DEFAULT_IPADDR1, DEFAULT_IPADDR2, DEFAULT_IPADDR3); uip_sethostaddr(ipaddr); printf("IP: %d.%d.%d.%d\n", DEFAULT_IPADDR0, DEFAULT_IPADDR1, DEFAULT_IPADDR2, DEFAULT_IPADDR3); uip_ipaddr(ipaddr, DEFAULT_NETMASK0, DEFAULT_NETMASK1, DEFAULT_NETMASK2, DEFAULT_NETMASK3); uip_setnetmask(ipaddr); #else uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_sethostaddr(ipaddr); printf("Waiting for IP address...\n"); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setnetmask(ipaddr); #endif httpd_init(); #ifndef STATIC_IP dhcpc_init(mac_addr, 6); dhcpc_request(); #endif long lPeriodicTimer, lARPTimer; lPeriodicTimer = lARPTimer = 0; int i; // = MAP_GPIOPinRead(GPIO_PORTA_BASE, ENC_INT) & ENC_INT; while(true) { //MAP_IntDisable(INT_UART0); MAP_SysCtlSleep(); //MAP_IntEnable(INT_UART0); //i = MAP_GPIOPinRead(GPIO_PORTA_BASE, ENC_INT) & ENC_INT; /*while(i != 0 && g_ulFlags == 0) { i = MAP_GPIOPinRead(GPIO_PORTA_BASE, ENC_INT) & ENC_INT; }*/ if( HWREGBITW(&g_ulFlags, FLAG_ENC_INT) == 1 ) { HWREGBITW(&g_ulFlags, FLAG_ENC_INT) = 0; enc_action(); } if(HWREGBITW(&g_ulFlags, FLAG_SYSTICK) == 1) { HWREGBITW(&g_ulFlags, FLAG_SYSTICK) = 0; lPeriodicTimer += SYSTICKMS; lARPTimer += SYSTICKMS; //printf("%d %d\n", lPeriodicTimer, lARPTimer); } if( lPeriodicTimer > UIP_PERIODIC_TIMER_MS ) { lPeriodicTimer = 0; int l; for(l = 0; l < UIP_CONNS; l++) { uip_periodic(l); // // If the above function invocation resulted in data that // should be sent out on the network, the global variable // uip_len is set to a value > 0. // if(uip_len > 0) { uip_arp_out(); enc_send_packet(uip_buf, uip_len); uip_len = 0; } } for(l = 0; l < UIP_UDP_CONNS; l++) { uip_udp_periodic(l); if( uip_len > 0) { uip_arp_out(); enc_send_packet(uip_buf, uip_len); uip_len = 0; } } } if( lARPTimer > UIP_ARP_TIMER_MS) { lARPTimer = 0; uip_arp_timer(); } } }
void SetupSysTick(void) { MAP_SysTickPeriodSet(MAP_SysCtlClockGet()); MAP_SysTickIntEnable(); MAP_SysTickEnable(); }
int main() { // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // MAP_FPUEnable(); MAP_FPULazyStackingEnable(); // // Set the clocking to run from the PLL at 50MHZ, change to SYSCTL_SYSDIV_2_5 for 80MHz if neeeded // MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); MAP_IntMasterDisable(); // // Initialize the SW2 button // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Unlock PF0 so we can change it to a GPIO input // Once we have enabled (unlocked) the commit register then re-lock it // to prevent further changes. PF0 is muxed with NMI thus a special case. // HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; MAP_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0); MAP_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA , GPIO_PIN_TYPE_STD_WPU); // // Initialize the communication layer with a default UART setting // AbstractComm * comm = NULL; AbstractComm * uart_comm = new UARTComm(); purpinsComm communication(uart_comm); // // Initialize the robot object // purpinsRobot purpins; // // Initialize the EEPROM // purpinsSettings settings; // // Initialize the MPU6050-based IMU // mpudata_t mpu; //unsigned long sample_rate = 10 ; //mpu9150_init(0, sample_rate, 0); memset(&mpu, 0, sizeof(mpudata_t)); // // Get the current processor clock frequency. // ulClockMS = MAP_SysCtlClockGet() / (3 * 1000); //unsigned long loop_delay = (1000 / sample_rate) - 2; // // Configure SysTick to occur 1000 times per second // MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKS_PER_SECOND); MAP_SysTickIntEnable(); MAP_SysTickEnable(); MAP_IntMasterEnable(); // // Load the settings from EEPROM // // Load the robot's ID settings.get(PP_SETTING_ID, &id, sizeof(uint32_t)); // Load the motors' PID gains settings.get(PP_SETTING_LEFT_PID, purpins.leftPIDGains(), sizeof(PIDGains)); settings.get(PP_SETTING_RIGHT_PID, purpins.rightPIDGains(), sizeof(PIDGains)); // Load the communication type uint32_t comm_type; settings.get(PP_SETTING_COMM_TYPE, &comm_type, sizeof(uint32_t)); // Holding SW2 at startup forces USB Comm if(comm_type != PP_COMM_TYPE_USB && MAP_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) == 1) { if(comm_type == PP_COMM_TYPE_CC3000) { comm = new WiFiComm(); // Load network and server settings settings.get(PP_SETTING_NETWORK_DATA, (static_cast<WiFiComm*>(comm))->network(), sizeof(Network)); settings.get(PP_SETTING_SERVER_DATA, (static_cast<WiFiComm*>(comm))->server(), sizeof(Server)); // Set WiFiComm as the underlying communication layer communication.setCommLayer(comm); } else if(comm_type == PP_COMM_TYPE_ESP8266) { // TODO } else if(comm_type == PP_COMM_TYPE_XBEE) { // TODO } } // // Communication variables and stuff // uint8_t sensors_pack[SENSORS_PACK_SIZE]; bool send_pack = false; unsigned long sensor_streaming_millis = 0; unsigned long last_millis = millis(); uint8_t data[SERIAL_BUFFER_SIZE]; size_t data_size; uint8_t action; // // Main loop, just managing communications // while(1) { // // Check for a new action // action = communication.getMsg(data, data_size); // If we got an action... if(action > 0) { // Process it!!! if(action == PP_ACTION_GET_VERSION) { uint8_t version = VERSION; communication.sendMsg(PP_ACTION_GET_VERSION, (void*)(&version), 1); } else if(action == PP_ACTION_DRIVE) { RobotSpeed speed; memcpy(&speed, data, sizeof(speed)); purpins.setSpeed(&speed); communication.sendAck(PP_ACTION_DRIVE); } else if(action == PP_ACTION_DRIVE_MOTORS) { MotorSpeeds motor_speeds; memcpy(&motor_speeds, data, sizeof(motor_speeds)); purpins.setMotorSpeeds(&motor_speeds); communication.sendAck(PP_ACTION_DRIVE_MOTORS); } else if(action == PP_ACTION_DRIVE_PWM) { MotorPWMs motor_pwms; memcpy(&motor_pwms, data, sizeof(motor_pwms)); purpins.setPWM(&motor_pwms); communication.sendAck(PP_ACTION_DRIVE_PWM); } else if(action == PP_ACTION_GET_ODOMETRY) { Pose odometry; purpins.getOdometry(&odometry); communication.sendMsg(PP_ACTION_GET_ODOMETRY, (void*)(&odometry), sizeof(odometry)); } else if(action == PP_ACTION_GET_MOTOR_SPEEDS) { MotorSpeeds speed; purpins.getMotorSpeeds(&speed); communication.sendMsg(PP_ACTION_GET_MOTOR_SPEEDS, (void*)(&speed), sizeof(speed)); } else if(action == PP_ACTION_GET_ENCODER_PULSES) { EncoderPulses encoder_pulses; purpins.getEncoderTicks(&encoder_pulses); communication.sendMsg(PP_ACTION_GET_ENCODER_PULSES, (void*)(&encoder_pulses), sizeof(encoder_pulses)); } else if(action == PP_ACTION_GET_IMU) { IMU imu_data; imu_data.orientation_x = mpu.fusedQuat[0]; imu_data.orientation_y = mpu.fusedQuat[1]; imu_data.orientation_z = mpu.fusedQuat[2]; imu_data.orientation_w = mpu.fusedQuat[4]; imu_data.linear_acceleration_x = mpu.calibratedAccel[0]; imu_data.linear_acceleration_y = mpu.calibratedAccel[1]; imu_data.linear_acceleration_z = mpu.calibratedAccel[2]; imu_data.angular_velocity_x = mpu.calibratedMag[0]; imu_data.angular_velocity_y = mpu.calibratedMag[1]; imu_data.angular_velocity_z = mpu.calibratedMag[2]; communication.sendMsg(PP_ACTION_GET_IMU, (void*)(&imu_data), sizeof(imu_data)); } else if(action == PP_ACTION_GET_IR_SENSORS) { // TODO: Add the IR sensors } else if(action == PP_ACTION_GET_GAS_SENSOR) { // TODO: Add the gas sensor } else if(action == PP_ACTION_SET_SENSORS_PACK) { bool ok = true; memset(sensors_pack, 0, SENSORS_PACK_SIZE); if(data_size > SENSORS_PACK_SIZE) { communication.error(PP_ERROR_BUFFER_SIZE); ok = false; break; } for(unsigned int i=0 ; i<data_size ; i++) { if(data[i] < PP_ACTION_GET_ODOMETRY || data[i] > PP_ACTION_GET_GAS_SENSOR) { communication.error(PP_ERROR_SENSOR_UNKNOWN); ok = false; break; } } if(ok) { memcpy(sensors_pack, data, data_size); communication.sendAck(PP_ACTION_SET_SENSORS_PACK); } } else if(action == PP_ACTION_GET_SENSORS_PACK) { send_pack = true; } else if(action == PP_ACTION_SET_SENSOR_STREAMING) { float sensor_streaming_frequency; memcpy(&sensor_streaming_frequency, data, sizeof(sensor_streaming_frequency)); sensor_streaming_millis = 1/sensor_streaming_frequency * 1000; communication.sendAck(PP_ACTION_SET_SENSOR_STREAMING); } else if(action == PP_ACTION_SET_GLOBAL_POSE) { Pose pose; memcpy(&pose, data, sizeof(pose)); purpins.setGlobalPose(&pose); communication.sendAck(PP_ACTION_SET_GLOBAL_POSE); } else if(action == PP_ACTION_SET_NEIGHBORS_POSES) { // TODO: Finish this } else if(action == PP_ACTION_SET_ID) { memcpy(&id, data, sizeof(id)); settings.save(PP_SETTING_ID, data, sizeof(uint32_t)); communication.sendAck(PP_ACTION_SET_ID); } else if(action == PP_ACTION_GET_ID) { communication.sendMsg(PP_ACTION_GET_ID, (void*)(&id), sizeof(id)); } else if(action == PP_ACTION_SET_PID_GAINS) { memcpy(purpins.leftPIDGains(), data, sizeof(PIDGains)); memcpy(purpins.rightPIDGains(), data+sizeof(PIDGains), sizeof(PIDGains)); settings.save(PP_SETTING_LEFT_PID, data, sizeof(PIDGains)); settings.save(PP_SETTING_RIGHT_PID, data+sizeof(PIDGains), sizeof(PIDGains)); communication.sendAck(PP_ACTION_SET_PID_GAINS); } else if(action == PP_ACTION_GET_PID_GAINS) { memcpy(data, purpins.leftPIDGains(), sizeof(PIDGains)); memcpy(data+sizeof(PIDGains), purpins.rightPIDGains(), sizeof(PIDGains)); communication.sendMsg(PP_ACTION_GET_ID, (void*)(data), 2*sizeof(PIDGains)); } else if(action == PP_ACTION_SET_SERVER_DATA) { settings.save(PP_SETTING_SERVER_DATA, data, sizeof(Server)); communication.sendAck(PP_ACTION_SET_SERVER_DATA); } else if(action == PP_ACTION_GET_SERVER_DATA) { settings.get(PP_SETTING_SERVER_DATA, data, sizeof(Server)); communication.sendMsg(PP_ACTION_GET_SERVER_DATA, (void*)(data), sizeof(Server)); } else if(action == PP_ACTION_SET_NETWORK_DATA) { settings.save(PP_SETTING_NETWORK_DATA, data, sizeof(Network)); communication.sendAck(PP_ACTION_SET_NETWORK_DATA); } else if(action == PP_ACTION_GET_NETWORK_DATA) { settings.get(PP_SETTING_NETWORK_DATA, data, sizeof(Network)); communication.sendMsg(PP_ACTION_GET_NETWORK_DATA, (void*)(data), sizeof(Network)); } else if(action == PP_ACTION_SET_COMM_TYPE) { memcpy(&comm_type, data, sizeof(comm_type)); if(comm_type != communication.type()) { if(comm_type == PP_COMM_TYPE_USB) { communication.setCommLayer(uart_comm); if(comm != NULL) delete comm; } if(comm_type == PP_COMM_TYPE_CC3000) { if(comm != NULL) delete comm; comm = new WiFiComm(); // Load network and server settings settings.get(PP_SETTING_NETWORK_DATA, (static_cast<WiFiComm*>(comm))->network(), sizeof(Network)); settings.get(PP_SETTING_SERVER_DATA, (static_cast<WiFiComm*>(comm))->server(), sizeof(Server)); // Set WiFiComm as the underlying communication layer communication.setCommLayer(comm); } else if(comm_type == PP_COMM_TYPE_ESP8266) { // TODO } else if(comm_type == PP_COMM_TYPE_XBEE) { // TODO } else { communication.error(PP_ERROR_COMM_UNKNOWN); } communication.sendAck(PP_ACTION_SET_COMM_TYPE); } } } // if(action > 0) // // Manage sensor streaming // unsigned long current_millis = millis(); if(send_pack || (sensor_streaming_millis > 0 && (current_millis - last_millis) >= sensor_streaming_millis)) { size_t size = 0; for(int i=0 ; i<SENSORS_PACK_SIZE ; i++) { if(sensors_pack[i] == 0) break; if(sensors_pack[i] == PP_ACTION_GET_ODOMETRY) { Pose odometry; purpins.getOdometry(&odometry); memcpy(data+size, &odometry, sizeof(odometry)); size += sizeof(odometry); } else if(sensors_pack[i] == PP_ACTION_GET_MOTOR_SPEEDS) { MotorSpeeds speed; purpins.getMotorSpeeds(&speed); memcpy(data+size, &speed, sizeof(speed)); size += sizeof(speed); } else if(sensors_pack[i] == PP_ACTION_GET_ENCODER_PULSES) { EncoderPulses encoder_pulses; purpins.getEncoderTicks(&encoder_pulses); memcpy(data+size, &encoder_pulses, sizeof(encoder_pulses)); size += sizeof(encoder_pulses); } else if(sensors_pack[i] == PP_ACTION_GET_IMU) { IMU imu_data; imu_data.orientation_x = mpu.fusedQuat[0]; imu_data.orientation_y = mpu.fusedQuat[1]; imu_data.orientation_z = mpu.fusedQuat[2]; imu_data.orientation_w = mpu.fusedQuat[4]; imu_data.linear_acceleration_x = mpu.calibratedAccel[0]; imu_data.linear_acceleration_y = mpu.calibratedAccel[1]; imu_data.linear_acceleration_z = mpu.calibratedAccel[2]; imu_data.angular_velocity_x = mpu.calibratedMag[0]; imu_data.angular_velocity_y = mpu.calibratedMag[1]; imu_data.angular_velocity_z = mpu.calibratedMag[2]; memcpy(data+size, &imu_data, sizeof(imu_data)); size += sizeof(imu_data); } else if(sensors_pack[i] == PP_ACTION_GET_IR_SENSORS) { // TODO: Add the IR sensors } else if(sensors_pack[i] == PP_ACTION_GET_GAS_SENSOR) { // TODO: Add the gas sensor } } communication.sendMsg(PP_ACTION_GET_SENSORS_PACK, (void*)(data), size); last_millis = current_millis; send_pack = false; } // if(send_pack ... } // while(1) return 0; }
int main() { // // Make sure the main oscillator is enabled because this is required by // the PHY. The system must have a 25MHz crystal attached to the OSC // pins. The SYSCTL_MOSC_HIGHFREQ parameter is used when the crystal // frequency is 10MHz or higher. // SysCtlMOSCConfigSet(SYSCTL_MOSC_HIGHFREQ); // // Run from the PLL at 120 MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // Configure the device pins. // PinoutSet(true, false); // // Configure UART. // //UARTStdioConfig(0, 115200, g_ui32SysClock); // // Clear the terminal and print banner. // //UARTprintf("\033[2J\033[H"); //UARTprintf("Ethernet lwIP example\n\n"); // // Configure Port N1 for as an output for the animation LED. // MAP_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1); MAP_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); // // Initialize LED to OFF (0) // MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, ~GPIO_PIN_1); MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, ~GPIO_PIN_0); MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, ~GPIO_PIN_1); // // Configure SysTick for a periodic interrupt. // MAP_SysTickPeriodSet(g_ui32SysClock / SYSTICKHZ); MAP_SysTickEnable(); MAP_SysTickIntEnable(); // Init Onion Client client = new OnionClient("o8Ik6DuC","NfyGRECh3WSZw9xn"); client->registerFunction("/on",ledOn,0,0); client->registerFunction("/off",ledOff,0,0); char *params[1] = {"data"}; client->registerFunction("/pubTest",pubTest,params,1); client->init(g_ui32SysClock); // // Setup Onion Client // //httpd_init(); //client->begin(); // // Set the interrupt priorities. We set the SysTick interrupt to a higher // priority than the Ethernet interrupt to ensure that the file system // tick is processed if SysTick occurs while the Ethernet handler is being // processed. This is very likely since all the TCP/IP and HTTP work is // done in the context of the Ethernet interrupt. // MAP_IntPrioritySet(INT_EMAC0, ETHERNET_INT_PRIORITY); MAP_IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY); // // Loop forever. All the work is done in interrupt handlers. // uint32_t last_time = g_millis; bool led = false; while(1) { if ((g_millis - last_time) > 500) { if (led) { MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, ~GPIO_PIN_0); led = false; } else { MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0); led = true; } last_time = g_millis; } client->loop(); } return 0; }
int main(void) { MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_12MHZ); //50MHZ // // Enable peripherals to operate when CPU is in sleep. // MAP_SysCtlPeripheralClockGating(true); // // Configure SysTick to occur 1000 times per second, to use as a time // reference. Enable SysTick to generate interrupts. // MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKS_PER_SECOND); MAP_SysTickIntEnable(); MAP_SysTickEnable(); // // Get the current processor clock frequency. // ulClockMS = MAP_SysCtlClockGet() / (3 * 1000); // init Serial Comm initSerialComm(230400); // init SSI0 in slave mode initSPIComm(); #ifdef DEBUG UARTprintf("Setting up PID\n"); #endif initCarPID(); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef DEBUG UARTprintf("Setting up PWM ... \n"); #endif configurePWM(); configureGPIO(); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef DEBUG UARTprintf("Setting up Servo ... \n"); #endif servo_init(); servo_setPosition(90); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef DEBUG UARTprintf("Starting QEI..."); #endif encoder_init(); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef USE_I2C #ifdef DEBUG UARTprintf("Setting up I2C\n"); #endif //I2C MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); MAP_GPIOPinTypeI2C(GPIO_PORTB_AHB_BASE,GPIO_PIN_2 | GPIO_PIN_3); MAP_I2CMasterInitExpClk(I2C0_MASTER_BASE,SysCtlClockGet(),true); //false = 100khz , true = 400khz I2CMasterTimeoutSet(I2C0_MASTER_BASE, 1000); #ifdef DEBUG UARTprintf("done\n"); #endif #endif #ifdef USE_I2C #ifdef USE_INA226 #ifdef DEBUG UARTprintf("Setting up INA226\n"); #endif initINA226(); #ifdef DEBUG UARTprintf("done\n"); #endif #endif #endif while (1) { } }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { float fTemperature, fPressure, fAltitude; int32_t i32IntegerPart; int32_t i32FractionPart; tContext sContext; uint32_t ui32SysClock; char pcBuf[15]; // // Setup the system clock to run at 40 Mhz from PLL with crystal reference // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 40000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "bmp180"); // // Flush any cached drawing operations. // GrFlush(&sContext); // // Enable UART0 // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Initialize the UART for console I/O. // UARTStdioConfig(0, 115200, ui32SysClock); // // Print the welcome message to the terminal. // UARTprintf("\033[2JBMP180 Example\n"); // // The I2C3 peripheral must be enabled before use. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); // // Configure the pin muxing for I2C3 functions on port G4 and G5. // This step is not necessary if your part does not support pin muxing. // MAP_GPIOPinConfigure(GPIO_PG4_I2C3SCL); MAP_GPIOPinConfigure(GPIO_PG5_I2C3SDA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // MAP_GPIOPinTypeI2CSCL(GPIO_PORTG_BASE, GPIO_PIN_4); MAP_GPIOPinTypeI2C(GPIO_PORTG_BASE, GPIO_PIN_5); // // Enable interrupts to the processor. // MAP_IntMasterEnable(); // // Initialize I2C3 peripheral. // I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, ui32SysClock); // // Initialize the BMP180 // BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS, BMP180AppCallback, &g_sBMP180Inst); // // Wait for initialization callback to indicate reset request is complete. // while(g_vui8DataFlag == 0) { // // Wait for I2C Transactions to complete. // } // // Reset the data ready flag // g_vui8DataFlag = 0; // // Enable the system ticks at 10 hz. // MAP_SysTickPeriodSet(ui32SysClock / (10 * 3)); MAP_SysTickIntEnable(); MAP_SysTickEnable(); // // Configure PQ4 to control the blue LED. // MAP_GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_4); // // Print temperature, pressure and altitude labels once on the LCD. // GrStringDraw(&sContext, "Temperature", 11, ((GrContextDpyWidthGet(&sContext) / 2) - 96), ((GrContextDpyHeightGet(&sContext) - 32) / 2) - 24, 1); GrStringDraw(&sContext, "Pressure", 8, ((GrContextDpyWidthGet(&sContext) / 2) - 63), (GrContextDpyHeightGet(&sContext) - 32) / 2, 1); GrStringDraw(&sContext, "Altitude", 8, ((GrContextDpyWidthGet(&sContext) / 2) - 59), ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24, 1); // // Begin the data collection and printing. Loop Forever. // while(1) { // // Read the data from the BMP180 over I2C. This command starts a // temperature measurement. Then polls until temperature is ready. // Then automatically starts a pressure measurement and polls for that // to complete. When both measurement are complete and in the local // buffer then the application callback is called from the I2C // interrupt context. Polling is done on I2C interrupts allowing // processor to continue doing other tasks as needed. // BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst); while(g_vui8DataFlag == 0) { // // Wait for the new data set to be available. // } // // Reset the data ready flag. // g_vui8DataFlag = 0; // // Get a local copy of the latest temperature data in float format. // BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fTemperature; i32FractionPart =(int32_t) (fTemperature * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print temperature with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%03d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, 8, ((GrContextDpyWidthGet(&sContext) / 2) + 16), ((GrContextDpyHeightGet(&sContext) - 32) / 2) - 24, 1); UARTprintf("Temperature %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Get a local copy of the latest air pressure data in float format. // BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fPressure; i32FractionPart =(int32_t) (fPressure * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print Pressure with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%3d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, -1, ((GrContextDpyWidthGet(&sContext) / 2) + 16), (GrContextDpyHeightGet(&sContext) - 32) / 2, 1); UARTprintf("Pressure %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Calculate the altitude. // fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f, 1.0f / 5.255f)); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fAltitude; i32FractionPart =(int32_t) (fAltitude * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print altitude with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%3d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, 8, ((GrContextDpyWidthGet(&sContext) / 2) + 16), ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24, 1); UARTprintf("Altitude %3d.%03d", i32IntegerPart, i32FractionPart); // // Print new line. // UARTprintf("\n"); // // Delay to keep printing speed reasonable. About 100 milliseconds. // MAP_SysCtlDelay(ui32SysClock / (10 * 3)); } }
//***************************************************************************** // // Initialize and operate the data logger. // //***************************************************************************** int main(void) { tContext sDisplayContext, sBufferContext; uint32_t ui32HibIntStatus, ui32SysClock, ui32LastTickCount; bool bSkipSplash; uint8_t ui8ButtonState, ui8ButtonChanged; uint_fast8_t ui8X, ui8Y; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // MAP_FPULazyStackingEnable(); // // Set the clocking to run at 50 MHz. // MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); ui32SysClock = MAP_SysCtlClockGet(); // // Initialize locals. // bSkipSplash = false; ui32LastTickCount = 0; // // Initialize the data acquisition module. This initializes the ADC // hardware. // AcquireInit(); // // Enable access to the hibernate peripheral. If the hibernate peripheral // was already running then this will have no effect. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); // // Check to see if the hiberate module is already active and if so then // read the saved configuration state. If both are okay, then proceed // to check and see if we are logging data using sleep mode. // if(HibernateIsActive() && !GetSavedState(&g_sConfigState)) { // // Read the status of the hibernate module. // ui32HibIntStatus = HibernateIntStatus(1); // // If this is a pin wake, that means the user pressed the select // button and we should terminate the sleep logging. In this case // we will fall out of this conditional section, and go through the // normal startup below, but skipping the splash screen so the user // gets immediate response. // if(ui32HibIntStatus & HIBERNATE_INT_PIN_WAKE) { // // Clear the interrupt flag so it is not seen again until another // wake. // HibernateIntClear(HIBERNATE_INT_PIN_WAKE); bSkipSplash = true; } // // Otherwise if we are waking from hibernate and it was not a pin // wake, then it must be from RTC match. Check to see if we are // sleep logging and if so then go through an abbreviated startup // in order to collect the data and go back to sleep. // else if(g_sConfigState.ui32SleepLogging && (ui32HibIntStatus & HIBERNATE_INT_RTC_MATCH_0)) { // // Start logger and pass the configuration. The logger should // configure itself to take one sample. // AcquireStart(&g_sConfigState); g_iLoggerState = eSTATE_LOGGING; // // Enter a forever loop to run the acquisition. This will run // until a new sample has been taken and stored. // while(!AcquireRun()) { } // // Getting here means that a data acquisition was performed and we // can now go back to sleep. Save the configuration and then // activate the hibernate. // SetSavedState(&g_sConfigState); // // Set wake condition on pin-wake or RTC match. Then put the // processor in hibernation. // HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC); HibernateRequest(); // // Hibernating takes a finite amount of time to occur, so wait // here forever until hibernate activates and the processor // power is removed. // for(;;) { } } // // Otherwise, this was not a pin wake, and we were not sleep logging, // so just fall out of this conditional and go through the normal // startup below. // } else { // // In this case, either the hibernate module was not already active, or // the saved configuration was not valid. Initialize the configuration // to the default state and then go through the normal startup below. // GetDefaultState(&g_sConfigState); } // // Enable the Hibernate module to run. // HibernateEnableExpClk(SysCtlClockGet()); // // The hibernate peripheral trim register must be set per silicon // erratum 2.1 // HibernateRTCTrimSet(0x7FFF); // // Start the RTC running. If it was already running then this will have // no effect. // HibernateRTCEnable(); // // In case we were sleep logging and are now finished (due to user // pressing select button), then disable sleep logging so it doesnt // try to start up again. // g_sConfigState.ui32SleepLogging = 0; SetSavedState(&g_sConfigState); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the buttons driver. // ButtonsInit(); // // Pass the restored state to the menu system. // MenuSetState(&g_sConfigState); // // Enable the USB peripheral // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Configure the required pins for USB operation. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); MAP_GPIOPinConfigure(GPIO_PG4_USB0EPEN); MAP_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); MAP_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); MAP_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Erratum workaround for silicon revision A1. VBUS must have pull-down. // if(CLASS_IS_BLIZZARD && REVISION_IS_A1) { HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1; } // // Initialize the USB stack mode and pass in a mode callback. // USBStackModeSet(0, eUSBModeOTG, ModeCallback); // // Initialize the stack to be used with USB stick. // USBStickInit(); // // Initialize the stack to be used as a serial device. // USBSerialInit(); // // Initialize the USB controller for dual mode operation with a 2ms polling // rate. // USBOTGModeInit(0, 2000, g_pui8HCDPool, HCD_MEMORY_SIZE); // // Initialize the menus module. This module will control the user // interface menuing system. // MenuInit(WidgetActivated); // // Configure SysTick to periodically interrupt. // g_ui32TickCount = 0; MAP_SysTickPeriodSet(ui32SysClock / CLOCK_RATE); MAP_SysTickIntEnable(); MAP_SysTickEnable(); // // Initialize the display context and another context that is used // as an offscreen drawing buffer for display animation effect // GrContextInit(&sDisplayContext, &g_sCFAL96x64x16); GrContextInit(&sBufferContext, &g_sOffscreenDisplayA); // // Show the splash screen if we are not skipping it. The only reason to // skip it is if the application was in sleep-logging mode and the user // just waked it up with the select button. // if(!bSkipSplash) { const uint8_t *pui8SplashLogo = g_pui8Image_TI_Black; // // Draw the TI logo on the display. Use an animation effect where the // logo will "slide" onto the screen. Allow select button to break // out of animation. // for(ui8X = 0; ui8X < 96; ui8X++) { if(ButtonsPoll(0, 0) & SELECT_BUTTON) { break; } GrImageDraw(&sDisplayContext, pui8SplashLogo, 95 - ui8X, 0); } // // Leave the logo on the screen for a long duration. Monitor the // buttons so that if the user presses the select button, the logo // display is terminated and the application starts immediately. // while(g_ui32TickCount < 400) { if(ButtonsPoll(0, 0) & SELECT_BUTTON) { break; } } // // Extended splash sequence // if(ButtonsPoll(0, 0) & UP_BUTTON) { for(ui8X = 0; ui8X < 96; ui8X += 4) { GrImageDraw(&sDisplayContext, g_ppui8Image_Splash[(ui8X / 4) & 3], (int32_t)ui8X - 96L, 0); GrImageDraw(&sDisplayContext, pui8SplashLogo, ui8X, 0); MAP_SysCtlDelay(ui32SysClock / 12); } MAP_SysCtlDelay(ui32SysClock / 3); pui8SplashLogo = g_ppui8Image_Splash[4]; GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, 0); MAP_SysCtlDelay(ui32SysClock / 12); } // // Draw the initial menu into the offscreen buffer. // SlideMenuDraw(&g_sMenuWidget, &sBufferContext, 0); // // Now, draw both the TI logo splash screen (from above) and the initial // menu on the screen at the same time, moving the coordinates so that // the logo "slides" off the display and the menu "slides" onto the // display. // for(ui8Y = 0; ui8Y < 64; ui8Y++) { GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, -ui8Y); GrImageDraw(&sDisplayContext, g_pui8OffscreenBufA, 0, 63 - ui8Y); } } // // Add the menu widget to the widget tree and send an initial paint // request. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sMenuWidget); WidgetPaint(WIDGET_ROOT); // // Set the focus handle to the menu widget. Any button events will be // sent to this widget // g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget; // // Forever loop to run the application // while(1) { // // Each time the timer tick occurs, process any button events. // if(g_ui32TickCount != ui32LastTickCount) { // // Remember last tick count // ui32LastTickCount = g_ui32TickCount; // // Read the debounced state of the buttons. // ui8ButtonState = ButtonsPoll(&ui8ButtonChanged, 0); // // Pass any button presses through to the widget message // processing mechanism. The widget that has the button event // focus (probably the menu widget) will catch these button events. // if(BUTTON_PRESSED(SELECT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_SELECT); } if(BUTTON_PRESSED(UP_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_UP); } if(BUTTON_PRESSED(DOWN_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_DOWN); } if(BUTTON_PRESSED(LEFT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT); } if(BUTTON_PRESSED(RIGHT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_RIGHT); } } // // Tell the OTG library code how much time has passed in milliseconds // since the last call. // USBOTGMain(GetTickms()); // // Call functions as needed to keep the host or device mode running. // if(g_iCurrentUSBMode == eUSBModeDevice) { USBSerialRun(); } else if(g_iCurrentUSBMode == eUSBModeHost) { USBStickRun(); } // // If in the logging state, then call the logger run function. This // keeps the data acquisition running. // if((g_iLoggerState == eSTATE_LOGGING) || (g_iLoggerState == eSTATE_VIEWING)) { if(AcquireRun() && g_sConfigState.ui32SleepLogging) { // // If sleep logging is enabled, then at this point we have // stored the first data item, now save the state and start // hibernation. Wait for the power to be cut. // SetSavedState(&g_sConfigState); HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC); HibernateRequest(); for(;;) { } } // // If viewing instead of logging then request a repaint to keep // the viewing window updated. // if(g_iLoggerState == eSTATE_VIEWING) { WidgetPaint(WIDGET_ROOT); } } // // If in the saving state, then save data from flash storage to // USB stick. // if(g_iLoggerState == eSTATE_SAVING) { // // Save data from flash to USB // FlashStoreSave(); // // Return to idle state // g_iLoggerState = eSTATE_IDLE; } // // If in the erasing state, then erase the data stored in flash. // if(g_iLoggerState == eSTATE_ERASING) { // // Save data from flash to USB // FlashStoreErase(); // // Return to idle state // g_iLoggerState = eSTATE_IDLE; } // // If in the flash reporting state, then show the report of the amount // of used and free flash memory. // if(g_iLoggerState == eSTATE_FREEFLASH) { // // Report free flash space // FlashStoreReport(); // // Return to idle state // g_iLoggerState = eSTATE_IDLE; } // // If we are exiting the clock setting widget, that means that control // needs to be given back to the menu system. // if(g_iLoggerState == eSTATE_CLOCKEXIT) { // // Give the button event focus back to the menu system // g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget; // // Send a button event to the menu widget that means the left // key was pressed. This signals the menu widget to deactivate // the current child widget (which was the clock setting wigdet). // This will cause the menu widget to slide the clock set widget // off the screen and resume control of the display. // SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT); g_iLoggerState = eSTATE_IDLE; } // // Process any new messages that are in the widget queue. This keeps // the user interface running. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // The program main function. It performs initialization, then runs a command // processing loop to read commands from the console. // //***************************************************************************** int main(void) { // int nStatus; FRESULT iFResult; // tRectangle sRect; // // Enable the GPIO port that is used for the on-board LED. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // // Check if the peripheral access is enabled. // while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)) { } // // Enable the GPIO pin for the LED (PN0). Set the direction as output, and // enable the GPIO pin for digital function. // GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); volatile uint32_t ui32Loop; int counter = 2; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // MAP_FPULazyStackingEnable(); // // Set the system clock to run at 50MHz from the PLL. // g_ui32SysClock = SysCtlClockFreqSet (SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ,50000000); // // Enable the peripherals used by this example. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3); // // Configure SysTick for a 100Hz interrupt. The FatFs driver wants a 10 ms // tick. // MAP_SysTickPeriodSet(g_ui32SysClock / 100); MAP_SysTickEnable(); MAP_SysTickIntEnable(); // // Enable Interrupts // MAP_IntMasterEnable(); // Mount the file system, using logical disk 0. // iFResult = f_mount(0, &g_sFatFs); iFResult = f_open(&g_sFileObject, "testFile.txt", (FA_OPEN_ALWAYS | FA_WRITE)); while(counter > 0){ GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0); for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++) { } // // Turn off the LED. // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0); // // Delay for a bit. // for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++) { } counter--; } if(iFResult != FR_OK) { return(1); } }