void hardware_init(void) { uint8_t i; /* enable clock for PORTs */ for (i = 0; i < HW_PORT_INSTANCE_COUNT; i++) { CLOCK_SYS_EnablePortClock(i); } /* Setup board clock source. */ g_xtal0ClkFreq = 50000000U; // g_xtalRtcClkFreq = 32768U; for (i = 0; i < HW_PORT_INSTANCE_COUNT; i++) { configure_gpio_pins(i); } configure_i2c_pins(0);//FXO8700 & L3G4200d // configure_adc_pins_for_quadcopter(); configure_remote_control_pins_for_quadcopter() ; configure_sensors_interrupt_pins_for_quadcopter(); configure_ftm_pins_for_quadcopter(); configure_uart_pins(BOARD_DEBUG_UART_INSTANCE); }
static void __init setup_early_console(char port, int baud) { if (configure_uart_pins(port)) return; console_port = port; configure_uart(console_port, baud); }
OSStatus internal_uart_init( mico_uart_t uart, const mico_uart_config_t* config, ring_buffer_t* optional_rx_buffer ) { #ifndef NO_MICO_RTOS mico_rtos_init_semaphore(&uart_interfaces[uart].tx_complete, 1); mico_rtos_init_semaphore(&uart_interfaces[uart].rx_complete, 1); #else uart_interfaces[uart].tx_complete = false; uart_interfaces[uart].rx_complete = false; #endif MicoMcuPowerSaveConfig(false); /* Configure the UART TX/RX pins */ configure_uart_pins(BOARD_APP_UART_INSTANCE); #if ADD_OS_CODE #ifndef NO_MICO_RTOS if(config->flags & UART_WAKEUP_ENABLE){ current_uart = uart; mico_rtos_init_semaphore( &uart_interfaces[uart].sem_wakeup, 1 ); mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART_WAKEUP", thread_wakeup, 0x100, ¤t_uart); } #endif #endif //OSA_Init(); #ifdef UART_IRQ_APP /****************************************************************/ uartConfig.baudRate = 115200; uartConfig.bitCountPerChar = kUart8BitsPerChar; uartConfig.parityMode = kUartParityDisabled; uartConfig.stopBitCount = kUartOneStopBit; /***************************************************************/ UART_DRV_Init(BOARD_APP_UART_INSTANCE, &uartState, &uartConfig); #else userConfig_app.chnArbitration = kEDMAChnArbitrationRoundrobin; userConfig_app.notHaltOnError = false; uartConfig_app.bitCountPerChar = kUart8BitsPerChar; uartConfig_app.parityMode = kUartParityDisabled; uartConfig_app.stopBitCount = kUartOneStopBit; uartConfig_app.baudRate = 115200; EDMA_DRV_Init(&state_app, &userConfig_app); UART_DRV_EdmaInit(BOARD_APP_UART_INSTANCE, &uartStateEdma_app, &uartConfig_app); INT_SYS_EnableIRQ(g_uartRxTxIrqId[BOARD_APP_UART_INSTANCE]); #endif #if RING_BUFF_ON if (optional_rx_buffer != NULL) { // Note that the ring_buffer should've been initialised first uart_interfaces[uart].rx_buffer = optional_rx_buffer; uart_interfaces[uart].rx_size = 0; platform_uart_receive_bytes( uart, optional_rx_buffer->buffer, optional_rx_buffer->size, 0 ); } #endif MicoMcuPowerSaveConfig(true); return kNoErr; }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); CLOCK_SYS_EnablePortClock(PORTB_IDX); /* Init board clock */ BOARD_ClockInit(); configure_uart_pins(0); }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); CLOCK_SYS_EnablePortClock(PORTE_IDX); /* Init board clock */ BOARD_ClockInit(); configure_uart_pins(BOARD_DEBUG_UART_INSTANCE); }
void dbg_uart_init(void) { configure_uart_pins(BOARD_DEBUG_UART_INSTANCE); #if (CLOCK_SETUP == 1) CLOCK_SYS_SetLpuartSrc(0, kClockLpuartSrcIrc48M); #else CLOCK_SYS_SetLpuartSrc(0, kClockLpuartSrcMcgIrClk); #endif DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUD, kDebugConsoleLPUART); }
int main(void) { uart_state_t uartState; // user provides memory for the driver state structure uart_user_config_t uartConfig; long int x; char AT[] = "\nAT"; char rxBuff[10]; uint32_t byteCountBuff = 0; //Initialise the FRDM-KL26Z Board hardware_init(); configure_uart_pins(0); //instance 0 is UART1??? // Call OSA_Init to setup LP Timer for timeout OSA_Init(); uartConfig.baudRate = 9600; uartConfig.bitCountPerChar = kUart8BitsPerChar; uartConfig.parityMode = kUartParityDisabled; uartConfig.stopBitCount = kUartOneStopBit; UART_DRV_Init(1, &uartState,&uartConfig); //Print message to serial terminal PRINTF("First Embedded Systems Lab_Aonghus\r\n"); PRINTF("Type a character and it will be echoed back\r\n\n"); int i = 0; byteCountBuff = sizeof(AT); while(1) { //UART_DRV_SendDataBlocking(1, AT, byteCountBuff, 16000u); while(UART_DRV_ReceiveDataBlocking ( 1, rxBuff, sizeof(rxBuff),16000u) == kStatus_UART_Success ) { for(i=0;i<sizeof(rxBuff);i++) PRINTF("%c",rxBuff[i]); } // if(UART_DRV_GetTransmitStatus (1,sizeof(rxBuff)) == kStatus_UART_Success ){ // } for(x=0;x<10000000;x++); } /* Never leave main */ return 0; }
/////////////////////////////////////////////////////////////////////////////// //Function to configure UART2 /////////////////////////////////////////////////////////////////////////////// void UART2_config(unsigned int BAUD_RATE) { long int uart_clock, BR; unsigned int SBR, OSR; unsigned char temp; //enable Port A and UART 0 clocks SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK; SIM_SCGC4 |= SIM_SCGC4_UART2_MASK; //configure UART 0 pins configure_uart_pins(1); //configure baud rate uart_clock = CLOCK_SYS_GetBusClockFreq(); SBR = uart_clock/(16 * BAUD_RATE); UART2_BDL = SBR & 0xFF; UART2_BDH |= ((SBR & 0xFF00)>>8); UART2_C1 = 0; UART2_C2 |= 0x0C; //enable transmitter and receiver UART2_C3 = 0; //Function to configure UART2 }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTC_IDX); CLOCK_SYS_EnablePortClock(PORTD_IDX); CLOCK_SYS_EnablePortClock(PORTE_IDX); CLOCK_SYS_EnablePortClock(PORTF_IDX); CLOCK_SYS_EnablePortClock(PORTI_IDX); CLOCK_SYS_EnablePortClock(PORTJ_IDX); /* Init board clock */ BOARD_ClockInit(); configure_gpio_pins(PORTC_IDX); configure_gpio_pins(PORTD_IDX); configure_gpio_pins(PORTE_IDX); configure_gpio_pins(PORTF_IDX); configure_gpio_pins(PORTJ_IDX); /* Configure the UART TX/RX pins */ configure_uart_pins(2U); }
/*! * \cond DOXYGEN_PRIVATE * \brief Pre initialization - initializing requested modules for basic run of MQX. */ int _bsp_pre_init(void) { uint32_t result; /****************************************************************************** Init gpio platform pins for LEDs, setup board clock source ******************************************************************************/ /* Macro PEX_MQX_KSDK used by PEX team */ #ifndef PEX_MQX_KSDK hardware_init(); /* Configure PINS for default UART instance */ #if defined(BOARD_USE_LPSCI) configure_lpsci_pins(BOARD_DEBUG_UART_INSTANCE); #elif defined(BOARD_USE_LPUART) configure_lpuart_pins(BOARD_DEBUG_UART_INSTANCE); #elif defined(BOARD_USE_UART) configure_uart_pins(BOARD_DEBUG_UART_INSTANCE); #else #error Default serial module is unsupported or undefined. #endif #endif #if MQX_EXIT_ENABLED extern void _bsp_exit_handler(void); /* Set the bsp exit handler, called by _mqx_exit */ _mqx_set_exit_handler(_bsp_exit_handler); #endif result = _psp_int_init(BSP_FIRST_INTERRUPT_VECTOR_USED, BSP_LAST_INTERRUPT_VECTOR_USED); if (result != MQX_OK) { return result; } /****************************************************************************** Init MQX tick timer ******************************************************************************/ /* Initialize , set and run system hwtimer */ result = HWTIMER_SYS_Init(&systimer, &BSP_SYSTIMER_DEV, BSP_SYSTIMER_ID, NULL); if (kStatus_OSA_Success != result) { return MQX_INVALID_POINTER; } /* Set isr for timer*/ if (NULL == OSA_InstallIntHandler(BSP_SYSTIMER_INTERRUPT_VECTOR, HWTIMER_SYS_SystickIsrAction)) { return kHwtimerRegisterHandlerError; } /* Set interrupt priority */ NVIC_SetPriority(BSP_SYSTIMER_INTERRUPT_VECTOR, MQX_TO_NVIC_PRIOR(BSP_SYSTIMER_ISR_PRIOR)); /* Disable interrupts to ensure ticks are not active until call of _sched_start_internal */ _int_disable(); result = HWTIMER_SYS_SetPeriod(&systimer, BSP_ALARM_PERIOD); if (kStatus_OSA_Success != result) { HWTIMER_SYS_Deinit(&systimer); return MQX_INVALID_POINTER; } result = HWTIMER_SYS_RegisterCallback(&systimer,(hwtimer_callback_t)_time_notify_kernel, NULL); if (kStatus_OSA_Success != result) { HWTIMER_SYS_Deinit(&systimer); return MQX_INVALID_POINTER; } result = HWTIMER_SYS_Start(&systimer); if (kStatus_OSA_Success != result) { HWTIMER_SYS_Deinit(&systimer); return MQX_INVALID_POINTER; } /* Initialize the system ticks */ _time_set_ticks_per_sec(BSP_ALARM_FREQUENCY); _time_set_hwticks_per_tick(HWTIMER_SYS_GetModulo(&systimer)); _time_set_hwtick_function(_bsp_get_hwticks, (void *)NULL); return MQX_OK; }
int main (void) { /*************************************************************************** * RX buffers **************************************************************************/ /*! @param receiveBuff Buffer used to hold received data */ uint8_t receiveBuff[19] = {0}; /* Initialize standard SDK demo application pins */ hardware_init(); /* Configure the UART TX/RX pins */ configure_uart_pins(BOARD_DEBUG_UART_INSTANCE); #ifdef USE_STDIO_FUNCTIONS /* Call this function to initialize the console UART. This function enables the use of STDIO functions (printf, scanf, etc.) */ dbg_uart_init(); /* Print the initial banner */ printf("\r\nHello World!\n\n\r"); while(1) { /******************************************** * Main routine that simply echoes received * characters forever *********************************************/ /* First, get character. */ receiveBuff[0] = getchar(); /* Now echo the received character */ putchar(receiveBuff[0]); } #else /*************************************************************************** * UART configuration and state structures **************************************************************************/ /*! @param uartConfig UART configuration structure */ /*! @param uartState UARt state structure which is used internally by the*/ /*! by the UART driver to keep track of the UART states */ uart_user_config_t uartConfig; uart_state_t uartState; /*************************************************************************** * TX buffers **************************************************************************/ /*! @param sourceBuff Buffer used to hold the string to be transmitted */ uint8_t sourceBuff[19] = {"\r\nHello World!\n\n\r"}; /* Configure the UART for 115200, 8 data bits, No parity, and one stop bit*/ uartConfig.baudRate = 115200; uartConfig.bitCountPerChar = kUart8BitsPerChar; uartConfig.parityMode = kUartParityDisabled; uartConfig.stopBitCount = kUartOneStopBit; /* Must call the OSA Init function to use Communication drivers */ OSA_Init(); /* Initialize the UART module */ UART_DRV_Init(BOARD_DEBUG_UART_INSTANCE, &uartState, &uartConfig); /* Print the initial banner */ UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 17, 200); while(1) { /******************************************** * Main routine that simply echoes received * characters forever *********************************************/ /* First, get character. */ UART_DRV_ReceiveDataBlocking(BOARD_DEBUG_UART_INSTANCE, receiveBuff, 1, OSA_WAIT_FOREVER); /* Now, stuff the buffer for the TX side and send the character*/ sourceBuff[0] = receiveBuff[0]; /* Now echo the received character */ UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 1, 200); } #endif }
void dbg_uart_init(void) { configure_uart_pins(BOARD_DEBUG_UART_INSTANCE); DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUD, kDebugConsoleUART); }
/******************************************************************************* * Main function for application. ******************************************************************************/ void lab2_power(void) { demo_power_modes_t testVal = kDemoRun; volatile uint8_t powerMode; uint8_t clockManagerMode = CLOCK_RUN; uint32_t freq = 0; //******************************************************* //* Step 1: Initialize the Clock Manager configurations. //******************************************************* // Create list of supported clock configurations. These are taken from the // board.c file and will be passed into CLOCK_SYS_Init(). clock_manager_user_config_t const *clockConfigs[] = { NULL, &g_defaultClockConfigVlpr, &g_defaultClockConfigRun, &g_defaultClockConfigHsrun, }; //***************************************************** //* Step 2: Configure Clock Manager callback function. //***************************************************** // Clock Manager callback function. clock_manager_callback_user_config_t clockManagerCallbackCfg = { .callback = clockManagerCallback, .callbackType = kClockManagerCallbackBeforeAfter, .callbackData = NULL }; clock_manager_callback_user_config_t *clockCallbacks[] = { &clockManagerCallbackCfg }; //***************************************************** //* Step 3: Initialize the Clock Manager. //***************************************************** // Pass in configuration and callback data to Clock Manager. CLOCK_SYS_Init(clockConfigs, CLOCK_NUMBER_OF_CONFIGURATIONS, clockCallbacks, ARRAY_SIZE(clockCallbacks)); // Set to RUN mode. CLOCK_SYS_UpdateConfiguration(CLOCK_RUN, kClockManagerPolicyForcible); //***************************************************** //* Step 4: Set up supported power mode structures. //***************************************************** const power_manager_user_config_t runConfig = { .mode = kPowerManagerRun, .sleepOnExitValue = false, }; power_manager_user_config_t hsrunConfig = runConfig; hsrunConfig.mode = kPowerManagerHsrun; power_manager_user_config_t waitConfig = runConfig; waitConfig.mode = kPowerManagerWait; power_manager_user_config_t stopConfig = runConfig; stopConfig.mode = kPowerManagerStop; power_manager_user_config_t vlprConfig = runConfig; vlprConfig.mode = kPowerManagerVlpr; power_manager_user_config_t vlpwConfig = runConfig; vlpwConfig.mode = kPowerManagerVlpw; power_manager_user_config_t vlpsConfig = runConfig; vlpsConfig.mode = kPowerManagerVlps; power_manager_user_config_t lls3Config = runConfig; lls3Config.mode = kPowerManagerLls3; power_manager_user_config_t vlls0Config = runConfig; vlls0Config.mode = kPowerManagerVlls0; //*********************************************************** //* Step 5: Configure managed power configurations structure. //*********************************************************** // Create the list of supported modes to pass into the Power Manager. power_manager_user_config_t const *powerConfigs[] = { &runConfig, &hsrunConfig, &waitConfig, &stopConfig, &vlprConfig, &vlpwConfig, &vlpsConfig, &lls3Config, &vlls0Config }; //***************************************************** //* Step 6: Configure Power Manager callback function. //***************************************************** // Initializes callback configuration structure for the Power Manager. power_manager_callback_user_config_t powerManagerCallbackCfg = { .callback = powerManagerCallback, .callbackType = kPowerManagerCallbackBeforeAfter, .callbackData = NULL }; // Initializes array of pointers to power manager callbacks. power_manager_callback_user_config_t *powerCallbacks[] = { &powerManagerCallbackCfg }; //***************************************************** //* Step 7: Initialize the Power Manager. //***************************************************** // Pass power configurations and callback info to Power Manager. POWER_SYS_Init(powerConfigs, sizeof(powerConfigs) / sizeof(power_manager_user_config_t *), powerCallbacks, ARRAY_SIZE(powerCallbacks)); // Initialize system to RUN mode. powerMode = kDemoRun - kDemoMin - 1; POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement); //************************************************************** //* Step 8: Configure the rest of the chip for this application. //************************************************************** // Configure pin mux for UART functionality. configure_uart_pins(BOARD_DEBUG_UART_INSTANCE); // Initializes GPIO driver for LEDs and buttons GPIO_DRV_Init(switchPins, ledPins); // Initialize the debug UART console. DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_LOW_POWER_UART_BAUD, kDebugConsoleUART); // Enable PORTC clock for GPIO/LLWU interrupt. CLOCK_SYS_EnablePortClock(2); // Enables falling edge interrupt for switch SW2. PORT_HAL_SetMuxMode(BOARD_SW_LLWU_BASE, BOARD_SW_LLWU_PIN, kPortMuxAsGpio); PORT_HAL_SetPinIntMode(BOARD_SW_LLWU_BASE, BOARD_SW_LLWU_PIN, kPortIntFallingEdge); // Enable GPIO interrupt. INT_SYS_EnableIRQ(PORTC_IRQn); // Configure the LLWU. LLWU_HAL_ClearExternalPinWakeupFlag(LLWU, BOARD_SW_LLWU_EXT_PIN); LLWU_HAL_SetExternalInputPinMode(LLWU, kLlwuExternalPinFallingEdge, BOARD_SW_LLWU_EXT_PIN); // Enable LLWU interrupt. INT_SYS_EnableIRQ(LLWU_IRQn); // Main loop. while (1) { // Get the system clock frequency and current clock configuration to print out. CLOCK_SYS_GetFreq(kCoreClock, &freq); clockManagerMode = CLOCK_SYS_GetCurrentConfiguration(); PRINTF("\n\r#################### Power Manager Demo ####################\n\n\r"); PRINTF(" Core Clock = %d MHz \n\r", freq / 1000000); PRINTF(" Current Mode = "); switch(clockManagerMode) { case CLOCK_RUN: PRINTF("RUN\n\r"); break; case CLOCK_VLPR: PRINTF("VLPR\n\r"); break; case CLOCK_HSRUN: PRINTF("HSRUN\n\r"); break; } PRINTF("\n\rSelect the desired operation \n\n\r"); PRINTF("Press %c for enter: RUN - Normal RUN mode\n\r", kDemoRun); PRINTF("Press %c for enter: HSRUN - High Speed RUN mode\n\r", kDemoHsRun); PRINTF("Press %c for enter: Wait - Wait mode\n\r", kDemoWait); PRINTF("Press %c for enter: Stop - Stop mode\n\r", kDemoStop); PRINTF("Press %c for enter: VLPR - Very Low Power Run mode\n\r", kDemoVlpr); PRINTF("Press %c for enter: VLPW - Very Low Power Wait mode\n\r", kDemoVlpw); PRINTF("Press %c for enter: VLPS - Very Low Power Stop mode\n\r", kDemoVlps); PRINTF("Press %c for enter: LLS3 - Low Leakage Stop mode\n\r", kDemoLls3); PRINTF("Press %c for enter: VLLS0 - Very Low Leakage Stop mode 0\n\r", kDemoVlls0); //PRINTF("Press %c for enter: VLLS3 - Very Low Leakage Stop mode 3\n\r", kDemoVlls3); PRINTF("\n\rWaiting for key press...\n\r\n\r"); // Wait for user input. testVal = (demo_power_modes_t)GETCHAR(); if ((testVal >= 'a') && (testVal <= 'z')) { testVal -= 'a' - 'A'; } if (testVal > kDemoMin && testVal < kDemoMax) { // Obtain Power Manager readable version of the value passed in. powerMode = testVal - kDemoMin - 1; // Switch to selected mode. switch (testVal) { case kDemoRun: if (POWER_SYS_GetCurrentMode() == kPowerManagerRun) { PRINTF("Run mode already active.\n\r"); break; } // Update the power configuration. POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement); // Update the clock configuration. CLOCK_SYS_UpdateConfiguration(CLOCK_RUN, kClockManagerPolicyAgreement); break; case kDemoHsRun: if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun) { PRINTF("High Speed Run mode already active.\n\r"); break; } // Update the power configuration. POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement); // Update the clock configuration. CLOCK_SYS_UpdateConfiguration(CLOCK_HSRUN, kClockManagerPolicyAgreement); break; case kDemoWait: if (POWER_SYS_GetCurrentMode() == kPowerManagerVlpr) { PRINTF("Cannot go from VLPR to WAIT directly...\n\r"); break; } if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun) { PRINTF("Cannot go from HSRUN to WAIT directly...\n\r"); break; } PRINTF("Entering WAIT mode. Press SW2 to wake...\n\r"); // Update the power configuration. POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement); break; case kDemoStop: if (POWER_SYS_GetCurrentMode() == kPowerManagerVlpr) { PRINTF("Cannot go from VLPR to STOP directly...\n\r"); break; } if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun) { PRINTF("Cannot go from HSRUN to STOP directly...\n\r"); break; } PRINTF("Entering STOP mode. Press SW2 to wake...\n\r"); // Update the power configuration. POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement); // Update the clock configuration. CLOCK_SYS_UpdateConfiguration(clockManagerMode, kClockManagerPolicyAgreement); break; case kDemoVlpr: if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun) { PRINTF("Cannot go from HSRUN to VLPR directly...\n\r"); break; } if(POWER_SYS_GetCurrentMode() != kPowerManagerVlpr) { // Update the clock configuration PRIOR to entering VLPR. CLOCK_SYS_UpdateConfiguration(CLOCK_VLPR, kClockManagerPolicyAgreement); // Update the power configuration. POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement); } else { PRINTF("Very Low Power Run mode already active.\n\r"); } break; case kDemoVlpw: if (POWER_SYS_GetCurrentMode() == kPowerManagerRun) { PRINTF("Cannot go from RUN to VLPW directly...\n\r"); break; } if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun) { PRINTF("Cannot go from HSRUN to VLPW directly...\n\r"); break; } PRINTF("Entering VLPW mode. Press SW2 to wake...\n\r"); // Update the power configuration. POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement); break; case kDemoVlps: if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun) { PRINTF("Cannot go from HSRUN to VLPS directly...\n\r"); break; } PRINTF("Entering VLPS mode. Press SW2 to wake...\n\r"); // Update the power configuration. POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement); // If we entered via RUN mode, restore clock settings. if (POWER_SYS_GetCurrentMode() == kPowerManagerRun) { CLOCK_SYS_UpdateConfiguration(clockManagerMode, kClockManagerPolicyAgreement); } break; case kDemoLls3: if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun) { PRINTF("Cannot go from HSRUN to LLSx directly...\n\r"); break; } PRINTF("Entering LLS3 mode. Press SW2 to wake...\n\r"); // Update the power configuration. POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement); // Check the mode active mode prior to LLS3 entry. if(POWER_SYS_GetCurrentMode() != kPowerManagerVlpr) { CLOCK_SYS_UpdateConfiguration(clockManagerMode, kClockManagerPolicyAgreement); } break; case kDemoVlls0: if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun) { PRINTF("Cannot go from HSRUN to VLLSx directly...\n\r"); break; } PRINTF("Press SW2 to wake. VLLSx wake goes through RESET sequence.\n\r"); // Update the power configuration. POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement); break; default: PRINTF("Bad value."); break; } PRINTF("\n\rNext loop\n\r"); } } }
int main() { char * AT = "\r\nAT\r\n";//Setting up a char variable AT for the a long string char * PIN_CHECK = "\r\nAT+CPIN?\r\n";//Setting up a char variable PIN_CHECK for the a long string char * ENTER_PIN = "\r\nAT+CPIN=\"1234\"\r\n";//Setting up a char variable ENTER_PIN for the a long string char * CREG = "\r\nAT+CREG?\r\n";//Setting up a char variable CREG for the a long string char response[20]; //A character buffer called response that can hold 20 characters int result = 0; //int result to check the value of the response sent back int transmit_send = 0; volatile int CurrentTick; //Volitile interger to hold the current tick count of the current time char * ptr; //Character char * stat; enum STATES {INIT, CHECK_PIN, SEND_PIN, CHECK_NETWORK_REG, SEND_SMS, CONNECTED}; enum STATES CurrentState = INIT; uart_state_t uartState; // user provides memory for the driver state structure uart_user_config_t uartConfig; buffer_init(); hardware_init(); //UART0_config(); PIT_Configure_interrupt_mode(1); configure_uart_pins(0); //instance 0 is UART1??? // Call OSA_Init to setup LP Timer for timeout OSA_Init(); uartConfig.baudRate = 9600; uartConfig.bitCountPerChar = kUart8BitsPerChar; uartConfig.parityMode = kUartParityDisabled; uartConfig.stopBitCount = kUartOneStopBit; UART_DRV_Init(1, &uartState,&uartConfig); //PRINTF("UART0 Test Code\n\r"); //PRINTF("Any entered character will be echoed\r\n\n"); while(1) { switch(CurrentState) { case INIT: //Check connection to MODEM by sending AT. Expected response is OK printf("Testing Modem Connection\n"); result = send_command(AT, response, sizeof(response), 2000); if(result == SUCCESS || result == ERROR) { //printf_response(response); } if(result == SUCCESS) //"OK" was returned by MODEM CurrentState = CHECK_PIN; else //incorrect response or timeout. Delay and try again { CurrentTick = tick_count; while((tick_count - CurrentTick) < 5) {} } break; case CHECK_PIN: //Check if SIM card is ready result = send_command(PIN_CHECK, response, sizeof(response), 10); if(result == SUCCESS || result == ERROR) { //printf_response(response); } if(result == SUCCESS) //"OK" returned, check response string for "READY" or "SIM_PIN" { if(strstr(response, "READY")) { CurrentState = CHECK_NETWORK_REG; } else if(strstr(response, "SIM PIN")) { CurrentState = SEND_PIN; } } else CurrentState = INIT; break; case SEND_PIN: //Send PIN code. "OK" response if PIN is correct result = send_command(ENTER_PIN, response, sizeof(response),10); if(result == SUCCESS || result == ERROR) { //printf_response(response); } if(result == SUCCESS) //"OK" returned, check response string for "READY" or "SIM_PIN" { CurrentState = CHECK_NETWORK_REG; } else CurrentState = INIT; break; case CHECK_NETWORK_REG: //check if registered on mobile network result = send_command(CREG, response, sizeof(response), 20); if(strstr(response, "+CREG")) { stat = (char *)strstr(response,":"); stat += 4; switch(*stat) { case '0': CurrentState = INIT; break; case '1': CurrentState = SEND_SMS; break; case '2': CurrentTick = tick_count; while((tick_count - CurrentTick) < 5) {} CurrentState = CHECK_NETWORK_REG; break; case '3': CurrentState = INIT; break; case '4': CurrentState = CONNECTED; break; case '5': CurrentState = SEND_SMS; break; } } case SEND_SMS: //Send a text message transmit_send = send_sms("\"0877763894\"","\"Testing 123 \""); if(transmit_send == SUCCESS) { CurrentState = CONNECTED; } else if(transmit_send == FAIL) { printf("A transmission fail has been detected or you have timed out\r\n"); CurrentState = SEND_SMS; } else if(transmit_send == ERROR) { printf("A transmission ERROR has been detected,rebooting\r\n"); CurrentState = INIT; } break; case CONNECTED: printf("\nInside Connected \r\n"); while(1) //dummy loop {} break; default: break; }//end switch-case } }
int main(void) { uart_state_t uartState; // user provides memory for the driver state structure uart_user_config_t uartConfig; long int x; int recieve_size=0; char AT[] = "AT\r"; char CMGF[] = "AT+CMGF=1\r"; char CMGS[] = "AT+CMGS=\"+353877763894\"\r"; char MESSAGE[] = "HELLO AONGHUS KL26Z \x1A"; char response[200]; enum STATES {INIT,TXT_MODE,SEND_SMS,SEND_MSG}; enum STATES CurrentState = INIT; uint32_t byteCountBuff = 0; //Initialise the FRDM-KL26Z Board hardware_init(); configure_uart_pins(0); //instance 0 is UART1??? // Call OSA_Init to setup LP Timer for timeout OSA_Init(); uartConfig.baudRate = 9600; uartConfig.bitCountPerChar = kUart8BitsPerChar; uartConfig.parityMode = kUartParityDisabled; uartConfig.stopBitCount = kUartOneStopBit; UART_DRV_Init(1, &uartState,&uartConfig); PRINTF("Full test of send/recieve on UART1\r\n"); int i = 0,y; for(y=0;y<=sizeof(response);y++) response[i]='c'; byteCountBuff = sizeof(AT); wait_time = 16000u; while(1){ switch(CurrentState){ case INIT: //Check connection to MODEM by sending AT. Expected response is OK recieve_size =4; byteCountBuff = sizeof(AT); result = send_command(1,AT,byteCountBuff,wait_time,response,recieve_size); if(result == SUCCESS){ printf("returned INIT\r\n");//"OK" was returned by MODEM CurrentState = TXT_MODE; } break; case TXT_MODE: //Check connection to MODEM by sending AT. Expected response is OK recieve_size =4; byteCountBuff = sizeof(CMGF); result = send_command(1,CMGF,byteCountBuff,wait_time,response,recieve_size); if(result == SUCCESS){ printf("returned TXT_MODE\r\n");//"OK" was returned by MODEM CurrentState = SEND_SMS; } break; case SEND_SMS: //Check connection to MODEM by sending AT. Expected response is OK recieve_size = 2; byteCountBuff = sizeof(CMGS); result = send_command(1,CMGS,byteCountBuff,wait_time,response,recieve_size); if(result == SUCCESS){ printf("returned SEND_SMS\r\n");//"OK" was returned by MODEM CurrentState = SEND_MSG; } break; case SEND_MSG: //Check connection to MODEM by sending AT. Expected response is OK recieve_size =8; byteCountBuff = sizeof(MESSAGE); result = send_command(1,MESSAGE,byteCountBuff,wait_time,response,recieve_size); if(result == SUCCESS){ printf("returned SEND_MSG\r\n");//"OK" was returned by MODEM //CurrentState = CHECK_PIN; } break; default: break; }//end switch-case } /* Never leave main */ return 0; }