static void main_task(void *param) { (void)param; for(;;) { GPIO_DRV_TogglePinOutput(LED_RED); /* toggle red LED */ vTaskDelay(500/portTICK_RATE_MS); /* wait for 500 ms */ } /* for */ }
static void BlinkyTask(void *pvParameters) { (void)pvParameters; /* parameter not used */ for(;;) { GPIO_DRV_TogglePinOutput(LEDRGB_RED); vTaskDelay(100/portTICK_RATE_MS); } }
/*! * \brief Kinetis SDK task, toggles a LED every 1 second. * \param param task parameter */ static void sdk_task(task_param_t param) { (void)param; /* unused parameter */ for(;;) { GPIO_DRV_TogglePinOutput(LED_RED); /* toggle blue LED */ OSA_TimeDelay(1000); /* wait 1000 ms */ } }
/* ** =================================================================== ** Interrupt handler : PIT0_IRQHandler ** ** Description : ** User interrupt service routine. ** Parameters : None ** Returns : Nothing ** =================================================================== */ void PIT0_IRQHandler(void) { /* Clear interrupt flag.*/ PIT_HAL_ClearIntFlag(g_pitBase[pitTimer1_IDX], pitTimer1_CHANNEL); /* Write your code here ... */ GPIO_DRV_TogglePinOutput( PTE24 ); ECU_Timer_Event(); // printf("TRIANGLES APPLES AND ORANGES!\n"); }
/** * turn the screen on by switching on the power supply * and sending the command */ void power_TurnScreenON() { if ( false == isPowerActive_OLED ) { GPIO_DRV_TogglePinOutput( KW40_WU ); OSA_TimeDelay(10); GPIO_DRV_SetPinOutput( KW40_GPIO ); PWR_OLED_TurnON(); while ( OLED_STATUS_SUCCESS != OLED_SendCmd( OLED_CMD_DISPLAYON, FIRST_BYTE ) ) {} } }
static void AppTaskGreen (void *p_arg) { OS_ERR os_err; CPU_TS ts; (void)p_arg; APP_TRACE_DBG(("listening on kgpiosw2, toggling green led...\n\r")); while (DEF_TRUE) { /* Task body, always written as an infinite loop. */ OSSemPend(&MySem2, 0, OS_OPT_PEND_BLOCKING, &ts, &os_err); GPIO_DRV_TogglePinOutput(BOARD_GPIO_LED_GREEN); } }
/*lint -save -e970 Disable MISRA rule (6.3) checking. */ int main(void) /*lint -restore Enable MISRA rule (6.3) checking. */ { /* Write your local variable definition here */ uint32_t currentCounter = 0; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ hw_average_config.hwAverageCountMode = kAdc16HwAverageCountOf32; //enable hardware average. ADC16_DRV_ConfigHwAverage(FSL_ADCONV1,&hw_average_config); ADC16_DRV_GetAutoCalibrationParam(FSL_ADCONV1,&calibration_param); calibrateParams(); //ADC16_DRV_Init(FSL_ADCONV1, &adConv1_InitConfig0); LPTMR_DRV_SetTimerPeriodUs(FSL_LPTMR1,1000000); // Set lptmr period printf("\r\nLPTMR is running!!\r\n"); LPTMR_DRV_Start(FSL_LPTMR1); /* Write your code here */ /* For example: for(;;) { } */ while(1) { if(currentCounter != lptmrCounter) { currentCounter = lptmrCounter; printf("\r\nLPTMR interrupt No.%d \r\n",currentCounter); GPIO_DRV_TogglePinOutput(LEDRGB_GREEN); } } /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
static void AppTaskStart (void *p_arg) { OS_ERR err; CPU_ERR cpu_err; uint32_t value; static uint32_t pulse_flag = 0; CPU_TS64 before, after; char tmp[80]; (void)p_arg; CPU_Init(); Mem_Init(); Math_Init(); BSP_Ser_Init(115200u); while (DEF_ON) { GPIO_DRV_TogglePinOutput( outPTB23 ); value = GPIO_DRV_ReadPinInput( inPTB9 ); if( value ){ if(pulse_flag == 0) before = CPU_TS_Get64(); // in cpu_cfg.h must set: #define CPU_CFG_TS_64_EN DEF_ENABLED pulse_flag = 1; GPIO_DRV_ClearPinOutput( BOARD_GPIO_LED_BLUE ); } else{ GPIO_DRV_SetPinOutput( BOARD_GPIO_LED_BLUE ); if(pulse_flag == 1) { after = CPU_TS_Get64(); // see comment above sprintf( tmp, "Elapsed time in Task R = %f s\n\r", (float)((1.0*(after-before))/CPU_TS_TmrFreqGet( &cpu_err )) ); APP_TRACE_DBG(( tmp )); } pulse_flag = 0; } OSTimeDlyHMSM(0u, 0u, 0u, 200u, OS_OPT_TIME_HMSM_STRICT, &err); } }
/** * send data packet * @param pHostInterface_packet [description] */ static void HostInterface_FlushPacket(hostInterface_packet_t * pHostInterface_packet) { osa_status_t status = OSA_MutexLock(&uartTxAccessMutex, OSA_WAIT_FOREVER ); if ( kStatus_OSA_Success == status ) { #if defined( SEND_VIA_UART_INT ) GPIO_DRV_TogglePinOutput( PROBE_PIN ); UART_DRV_SendDataBlocking( gHostInterface_instance, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, 10 ); #elif defined( SEND_VIA_UART_DMA ) UART_DRV_EdmaSendDataBlocking( gHostInterface_instance, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, 100 ); #endif #if defined( HEXIWEAR_DEBUG ) UART_DRV_SendDataBlocking( HEXIWEAR_DEBUG_INSTANCE, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, 100 ); } #endif OSA_MutexUnlock(&uartTxAccessMutex); }
void log_accel_values(int16_t x, int16_t y, int16_t z) { FRESULT fr; /* FatFs functions return code */ FIL fil; /* File object */ uint32_t bytes_written; char str_number[10]; char aux_string[100]; off_t new_line; GPIO_DRV_WritePinOutput(testPin.pinName, 1); /* Open a text file */ fr = f_open(&fil, "log_data.txt", FA_WRITE | FA_OPEN_ALWAYS); if(fr) { PRINTF("\nError opening text file\r\n"); for(;;){} } //GPIO_DRV_TogglePinOutput(testPin.pinName); new_line = f_size(&fil); /* Set file pointer to the start of new line in text file */ fr = f_lseek(&fil, new_line); //GPIO_DRV_TogglePinOutput(testPin.pinName); aux_string[0] = '\0'; /* Append x value */ int16tostr(x, str_number); strcat(aux_string, str_number); strcat(aux_string, "\t"); /* Append y value */ int16tostr(y, str_number); strcat(aux_string, str_number); strcat(aux_string, "\t"); /* Append z value */ int16tostr(z, str_number); strcat(aux_string, str_number); strcat(aux_string, "\r\n"); GPIO_DRV_TogglePinOutput(testPin.pinName); /* Write the constructed string to the new line in text file */ fr = f_write(&fil, aux_string, strlen(aux_string), &bytes_written); GPIO_DRV_TogglePinOutput(testPin.pinName); if(fr) { PRINTF("\nError logging data\r\n"); for(;;){} } /* Close the text file */ fr = f_close(&fil); //GPIO_DRV_TogglePinOutput(testPin.pinName); GPIO_DRV_WritePinOutput(testPin.pinName, 0); }
void Application() { uint32_t minutes=0, hours=0, samples=0, arrayIndex=0; static state_t currentState = RECEIVE_CONFIG; static uint32_t sendPeriodHours, samplesPerHour,minutesLeaveIdle; static uint32_t distanceSamplesArray[MAX_ALLOWED_SEND_PERIOD_HOURS]; static message_t messageType = SAMPLES; static uint16_t distance; static uint8_t HTTP_BUFFER[256]; static float temperature; static SIM800L_error_t exitCode; static MMA8451_state_t boardState; uint8_t fullAlarmSent = 0, fireAlarmSent = 0, fallAlarmSent = 0; while(1) { switch(currentState) { case RECEIVE_CONFIG: RECEIVE_CONFIG_TASK(&sendPeriodHours,&samplesPerHour,&minutesLeaveIdle); currentState = IDLE; break; case IDLE: LPTMR_DRV_SetTimerPeriodUs(LPTMR_0_IDX,LPTMR_INTERRUPT_PERIOD_US); LPTMR_DRV_Start(LPTMR_0_IDX); CONSOLE_INIT(); CONSOLE_SEND("TO IDLE...\r\n",12); /*PROCESSOR IN LOW POWER MODE*/ POWER_SYS_SetWakeupModule(kLlwuWakeupModule0,true); if( POWER_SYS_SetMode(1,kPowerManagerPolicyAgreement) != kPowerManagerSuccess) { GPIO_DRV_ClearPinOutput(LEDRGB_RED); } /*AFTER LLWU INTERRUPT*/ GPIO_DRV_TogglePinOutput(LEDRGB_BLUE); minutes++; currentState = MEASURE_TEMPERATURE; break; case MEASURE_TEMPERATURE: /*EVERY MINUTE*/ LM35_INIT(); temperature = LM35_GET_TEMPERATURE_CELSIUS(); LM35_DEINIT(); MMA8451Q_INIT(); /*TIME TO MEASURE DISTANCE*/ if(minutes == minutesLeaveIdle) { minutes=0; currentState = MEASURE_DISTANCE; } else { currentState = IDLE; } /*CONTAINER FALL*/ if ( (boardState = MMA8451_GET_STATE(MMA8451_VERTICAL)) == MMA8451_FALL) { if(!fallAlarmSent) { messageType = FALL_ALARM; currentState = SEND_DATA; } } else { /*CONTAINER AGAIN IN ITS RIGHT PLACE*/ if(fallAlarmSent) { fallAlarmSent = 0; } } /*EXTREME CASE: SET FIRE ALARM*/ if(temperature > TEMPERATURE_THRESHOLD) { if(!fireAlarmSent) { messageType = FIRE_ALARM; currentState = SEND_DATA; } } else { /*TEMPERATURE WENT DOWN*/ if(fireAlarmSent) { fireAlarmSent = 0; } } break; case MEASURE_DISTANCE: MB7360_INIT(); MB7360_START_RANGING(); distance = MB7360_GET_DISTANCE_MM(); MB7360_DEINIT(); /*ONE HOUR LAPSE*/ if (++samples == samplesPerHour) { samples = 0; distanceSamplesArray[arrayIndex++] = distance; /*SEND PERIOD HOUR LAPSE: TIME TO SEND DATA*/ if(++hours == sendPeriodHours) { hours = 0; arrayIndex = 0; LPTMR_DRV_Stop(LPTMR_0_IDX); messageType = SAMPLES; currentState = SEND_DATA; } else { currentState = IDLE; } } else { currentState = IDLE; } /*EXTREME CASE: SET FULL ALARM*/ if(distance < DISTANCE_THRESHOLD) { if(!fullAlarmSent) { messageType = FULL_ALARM; currentState = SEND_DATA; } } else { /*COINTAINER EMPTY AGAIN, PREPARE FOR NEXT FULL ALARM*/ if(fullAlarmSent) { fullAlarmSent = 0; } } break; case SEND_DATA: switch( exitCode = SEND_DATA_GPRS_TASK(messageType, distanceSamplesArray,sendPeriodHours) ) { case SIM800L_SUCCESS_GPRS: switch(messageType) { case SAMPLES: CONSOLE_SEND("SAMPLES SENT - GPRS\r\n",21); break; case FULL_ALARM: CONSOLE_SEND("FULL ALARM SENT - GPRS\r\n",24); fullAlarmSent = 1; break; case FIRE_ALARM: CONSOLE_SEND("FIRE ALARM SENT - GPRS\r\n",24); fireAlarmSent = 1; break; case FALL_ALARM: CONSOLE_SEND("FALL ALARM SENT - GPRS\r\n",24); fallAlarmSent = 1; break; default: break; } break; case SIM800L_NO_GPRS: switch( exitCode = SEND_DATA_SMS_TASK(messageType, distanceSamplesArray,sendPeriodHours)) { case SIM800L_SUCCESS_SMS: switch(messageType) { case SAMPLES: CONSOLE_SEND("SAMPLES SENT - SMS\r\n",2); break; case FULL_ALARM: CONSOLE_SEND("FULL ALARM SENT - SMS\r\n",23); fullAlarmSent = 1; break; case FIRE_ALARM: CONSOLE_SEND("FIRE ALARM SENT - SMS\r\n",23); fireAlarmSent = 1; break; case FALL_ALARM: CONSOLE_SEND("FALL ALARM SENT - SMS\r\n",23); fallAlarmSent = 1; break; default: break; } break; default: CONSOLE_SEND("COULD NOT SEND SMS\r\n",20); break; } break; /*NO GPRS OR SMS*/ default: CONSOLE_SEND("COULD NOT SEND DATA\r\n",21); break; } currentState = IDLE; break; default: break; } } }
void APP_Run(void) { int i; uint8_t red, green, blue; uint8_t dimmPercent = 50; NEO_Init(); for(;;) { GPIO_DRV_TogglePinOutput(LEDRGB_BLUE); if (start) { NEO_ClearAllPixel(); NEO_TransferPixels(); for(i=0;i<NEO_NOF_PIXEL;i++) { red = 0x10+(i*0x10); if (red==0) { red = 0x10; } green = 0x20+(i*0x20); if (green==0) { green = 0x10; } blue = 0x30+(i*0x30); if (blue==0) { blue = 0x10; } NEO_SetPixelRGB(i, red, green, blue); NEO_TransferPixels(); OSA_TimeDelay(50); } NEO_ClearAllPixel(); NEO_TransferPixels(); for(i=0;i<=7;i++) { NEO_SetPixelRGB(i, 0x00, 0x00, (i+1)*10); NEO_DimmPercentPixel(i, i*10); } for(i=8;i<=15;i++) { NEO_SetPixelRGB(i, 0x00, i-7*10, 0x00); NEO_DimmPercentPixel(i, (i-8)*10); } for(i=16;i<=23;i++) { NEO_SetPixelRGB(i, i-15*10, 0x00, 0x00); NEO_DimmPercentPixel(i, (i-16)*10); } for(i=24;i<=31;i++) { NEO_SetPixelRGB(i, 0x00, 0x00, (i-23)*10); NEO_DimmPercentPixel(i, (i-23)*10); } for(i=32;i<=39;i++) { NEO_SetPixelRGB(i, 0x00, i-31*10, 0x00); NEO_DimmPercentPixel(i, (i-31)*10); } for(i=40;i<=47;i++) { NEO_SetPixelRGB(i, i-40*10, 0, 0x00); NEO_DimmPercentPixel(i, (i-39)*10); } for(i=48;i<=55;i++) { NEO_SetPixelRGB(i, 0, 0, i-47*10); NEO_DimmPercentPixel(i, (i-47)*10); } for(i=56;i<=63;i++) { NEO_SetPixelRGB(i, 0, 0, i-55*10); NEO_DimmPercentPixel(i, (i-55)*10); } NEO_TransferPixels(); for(i=0;i<NEO_NOF_PIXEL;i++) { green = 0x5+(i*0x10); if (red==0) { red = 0x5; } blue = 0x5+(i*0x15); if (green==0) { green = 0x5; } red = 0x5+(i*0x20); if (blue==0) { blue = 0x5; } NEO_SetPixelRGB(i, red, green, blue); NEO_DimmPercentPixel(i, dimmPercent); } NEO_TransferPixels(); NEOL_PixelTrail(0xff, 0x00, 0x00, NEO_PIXEL_FIRST, NEO_PIXEL_LAST, 12, 50, 10*2); NEOL_PixelTrail(0xff, 0xff, 0x00, NEO_PIXEL_FIRST, NEO_PIXEL_LAST, 12, 50, 10*2); NEOL_PixelTrail(0x00, 0xff, 0x00, NEO_PIXEL_FIRST, NEO_PIXEL_LAST, 12, 50, 10*2); NEOL_PixelTrail(0x00, 0xff, 0xff, NEO_PIXEL_FIRST, NEO_PIXEL_LAST, 12, 50, 10*2); NEO_ClearAllPixel(); NEOL_PixelTrail(0x00, 0x00, 0xff, NEO_PIXEL_FIRST, NEO_PIXEL_LAST, 12, 50, 10*2); NEO_ClearAllPixel(); NEOL_PixelTrail(0xff, 0x00, 0xff, NEO_PIXEL_FIRST, NEO_PIXEL_LAST, 12, 50, 10*2); } } }
static void LED_toggle_master(void) { GPIO_DRV_TogglePinOutput(kGpioLED1); }
static void LED_toggle_slave(void) { GPIO_DRV_TogglePinOutput(kGpioLED2); }