void APP_Run(void) { int i; uint32_t val = 0; unsigned char buf[16]; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LED1_Neg(); LED2_Off(); WAIT1_Waitms(10); } LED2_Off(); LED1_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while( i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK ) { i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"val: "); UTIL1_strcatNum32u(buf, sizeof(buf), val); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n"); (void)CDC1_SendString(buf); val++; } else { WAIT1_Waitms(10); } } }
void APP_Start(void) { LED1_Neg(); LED2_Neg(); LED3_Neg(); LED4_Neg(); LED5_Neg(); LED6_Neg(); LED7_Neg(); LED8_Neg(); if (FRTOS1_xTaskCreate( MainTask, /* pointer to the task */ (unsigned char *)"Main", /* task name for kernel awareness debugging */ configMINIMAL_STACK_SIZE, /* task stack size */ (void*)NULL, /* optional task startup argument */ tskIDLE_PRIORITY+1, /* initial priority */ (xTaskHandle*)NULL /* optional task handle to create */ ) != pdPASS) { /*lint -e527 */ for(;;){} /* error! probably out of memory */ /*lint +e527 */ } FRTOS1_vTaskStartScheduler(); #if 0 for(;;) { LED1_Neg(); WAIT1_Waitms(200); } #endif }
void RADIO_DataIndicationPacket(tRxPacket *sRxPacket) { if (sRxPacket->u8Status==SMAC1_TIMEOUT) { /* Put timeout condition code here */ LED1_Neg(); LED2_Neg(); /* indicator for bad or no communication */ EVNT_SetEvent(EVNT_RADIO_TIMEOUT); } else if (sRxPacket->u8Status == SMAC1_SUCCESS) { /* good packet received: handle it. */ if (RADIO_isSniffing) { QueueMessage(RADIO_QUEUE_MSG_SNIFF, (const char*)sRxPacket->pu8Data, sRxPacket->u8DataLength); } /* check if it is the packet we expect...*/ if ( RADIO_AppStatus==RADIO_WAITING_FOR_ACK && UTIL1_strncmp((char*)sRxPacket->pu8Data, RADIO_PREFIX_STR RADIO_ACK_STR, sizeof(RADIO_PREFIX_STR RADIO_ACK_STR)-1)==0 ) /* is it our acknowledge packet? */ { EVNT_SetEvent(EVNT_RADIO_ACK); } else if (UTIL1_strncmp((char*)sRxPacket->pu8Data, RADIO_PREFIX_STR, sizeof(RADIO_PREFIX_STR)-1)==0) { #if PL_HAS_REMOTE && PL_HAS_MOTOR /*! \todo Implement your own message handling */ if (UTIL1_strncmp((char*)sRxPacket->pu8Data, RADIO_PREFIX_STR REMOTE_ACCEL_PREFIX, sizeof(RADIO_PREFIX_STR REMOTE_ACCEL_PREFIX)-1)==0) { QueueMessage(RADIO_QUEUE_MSG_ACCEL, (const char*)sRxPacket->pu8Data, sRxPacket->u8DataLength); } #endif EVNT_SetEvent(EVNT_RADIO_DATA); } else { /* unknown packet? */ EVNT_SetEvent(EVNT_RADIO_UNKNOWN); } } else if (sRxPacket->u8Status==SMAC1_OVERFLOW) { /* received packet, but it was longer than what we expect. */ EVNT_SetEvent(EVNT_RADIO_OVERFLOW); LED1_Neg(); LED2_Neg(); /* indicator for bad or no communication */ } }
void main(void) { /* Write your local variable definition here */ /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ if (FRTOS1_xTaskCreate( Task1, /* pointer to the task */ (signed portCHAR *)"Task1", /* task name for kernel awareness debugging */ configMINIMAL_STACK_SIZE, /* task stack size */ /* note: 250 without 'copy' command */ (void*)NULL, /* optional task startup argument */ tskIDLE_PRIORITY+1, /* initial priority */ (xTaskHandle*)NULL /* optional task handle to create */ ) != pdPASS) { for(;;){}; /* error! probably out of memory */ } FRTOS1_vTaskStartScheduler(); for(;;) { WAIT1_Waitms(1000); LED1_Neg(); } /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** 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!!! ***/
/*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 */ /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ #if 0 for(;;) { LED1_Neg(); WAIT1_Waitms(100); LED2_Neg(); WAIT1_Waitms(100); LED3_Neg(); WAIT1_Waitms(100); } #else APP_Start(); #endif /* For example: for(;;) { } */ /*** 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!!! ***/
void APP_Start(void) { uint8_t val=0; uint8_t range, res; uint16_t ambient; CLS1_ConstStdIOType *io = CLS1_GetStdio(); VL_Init(); /* initialize sensor driver */ for(;;) { res = VL_ReadRangeSingle(&range); if (res!=ERR_OK) { CLS1_SendStr("ERROR Range: ", io->stdErr); CLS1_SendNum8u(res, io->stdErr); } else { CLS1_SendStr("Range: ", io->stdOut); CLS1_SendNum8u(range, io->stdOut); } res = VL_ReadAmbientSingle(&ambient); if (res!=ERR_OK) { CLS1_SendStr(" ERROR Ambient: ", io->stdErr); CLS1_SendNum8u(res, io->stdErr); } else { CLS1_SendStr(" Ambient: ", io->stdOut); CLS1_SendNum16u(ambient, io->stdOut); } CLS1_SendStr("\r\n", io->stdOut); LED1_Neg(); WAIT1_Waitms(500); } }
static void CDC_Run(void) { int i; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LED1_Neg(); LED2_Off(); WAIT1_Waitms(10); } LED1_Off(); LED2_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while( i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK ) { i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); (void)CDC1_SendString((unsigned char*)"\r\n"); } else { WAIT1_Waitms(10); } } }
static portTASK_FUNCTION(Task1, pvParameters) { (void)pvParameters; /* parameter not used */ for(;;) { LED1_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } }
static portTASK_FUNCTION(MainTask, pvParameters) { (void)pvParameters; for(;;) { LED1_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } }
static void CDC_Run(void) { int i; SendStr((unsigned char*)"Hello World to Kinetis SCI3!\r\n"); for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LED1_Neg(); LED2_Off(); // WAIT1_Waitms(1); /* just give back some CPU time. */ SendStr((unsigned char*)"waiting to enumerate...\r\n"); } LED1_Off(); LED2_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while( i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK ) { i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); (void)CDC1_SendString((unsigned char*)"\r\n"); SendStr((unsigned char*)"echo to SCI3: "); SendStr(in_buffer); SendStr((unsigned char*)"\r\n"); } else { // WAIT1_Waitms(5); } } }
static void AppTask(void *pvParameters) { (void)pvParameters; /* parameter not used */ for(;;) { LED1_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } }
static portTASK_FUNCTION(AppTask, pvParameters) { (void)pvParameters; /* not used */ for(;;) { LED1_Neg(); FRTOS1_vTaskDelay(500/portTICK_RATE_MS); } /* for */ }
/*! \brief A simple state machine iterating through different transceiver states */ static void RADIO_HandleState(void) { tTxPacket ackTxPacket; /* SMAC structure for TX packets */ static uint8_t ackTxDataBuffer[SMAC1_RADIO_BUF_SIZE]; /*Data buffer to hold TX data */ switch (RADIO_AppStatus) { case RADIO_INITIAL_STATE: RADIO_AppStatus = RADIO_RECEIVER_ALWAYS_ON; break; case RADIO_RECEIVER_ALWAYS_ON: RADIO_AppStatus = RADIO_READY_FOR_TX_RX_DATA; (void)SMAC1_MLMERXEnableRequest(0); /* Zero means wait forever with RX ON. */ break; case RADIO_READY_FOR_TX_RX_DATA: /* we are ready to receive/send data data */ break; case RADIO_TRANSMIT_DATA: if (SMAC1_MLMERXDisableRequest() != SMAC1_SUCCESS) { /* Turn off the RX forever mode. */ RADIO_AppStatus = RADIO_TRANSMIT_DATA; /* retry */ break; } LED1_Neg(); if ((SMAC1_MCPSDataRequest(&RADIO_TxPacket) == SMAC1_SUCCESS)) { /* transmit data */ RADIO_AppStatus = RADIO_WAITING_FOR_ACK; (void)SMAC1_MLMERXEnableRequest(RADIO_TIMEOUT_COUNT); } else { RADIO_AppStatus = RADIO_RECEIVER_ALWAYS_ON; /* what should we otherwise do? */ } break; case RADIO_TRANSMIT_ACK: /*Initialize the packet.*/ /*! \todo RADIO: Below we send back the acknowledge message: * check that your RADIO_ACK_STR is what you want and need. * Notice the implicit string concatenation for efficiency and reduced code size. */ UTIL1_strcpy(ackTxDataBuffer, sizeof(ackTxDataBuffer), (unsigned char*)RADIO_PREFIX_STR RADIO_ACK_STR); ackTxPacket.pu8Data = &ackTxDataBuffer[0]; /* Load the address of our txbuffer into the tx structure*/ ackTxPacket.u8DataLength = (byte)(UTIL1_strlen((char*)ackTxDataBuffer)+1); /* set the size of the packet */ (void)SMAC1_MCPSDataRequest(&ackTxPacket); /* transmit data */ RADIO_AppStatus = RADIO_RECEIVER_ALWAYS_ON; break; case RADIO_RESET_STATE: /* MC13192 Reset, reinitialize and return to default state. */ SMAC1_RadioInit(); RADIO_AppStatus = RADIO_INITIAL_STATE; break; case RADIO_WAITING_FOR_ACK: /* At this point only two things happen, 1-we receive the ack packet or 2-timeout. * Either way the TX will leave this state and continue. Low power mode could be placed here * because both 1 and 2 are interrupt driven, in this case we keep it simple */ break; default: break; } }
static void CDC_Run(void) { int i; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LED1_Neg(); LED2_Off(); // WAIT1_Waitms(1); /* just give back some CPU time. S08JM60 does not allow much spare time here! */ } LED1_Off(); LED2_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while( i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK ) { i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); (void)CDC1_SendString((unsigned char*)"\r\n"); } else { //WAIT1_Waitms(5); } } }
void APP_Run(void) { LED1_Neg(); LED2_Neg(); LED3_Neg(); LED4_Neg(); DiskTest(); }
void main(void) { /* Write your local variable definition here */ int i = 0; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ /* For example: for(;;) { } */ for(;;) { i++; if ((i%5)==0) { data[0]++; /* change data */ TestFlash(); } LED1_Neg(); WAIT1_Waitms(250); } /*** 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!!! ***/
/*! * \brief LED test routine. * This routine tests if: * - we can turn the LEDs properly on and off * - if we can negate them * - if we can set an LED value * - if we can get the LED value * If the test fails, the program will hanging in an endless loop */ void LED_Test(void) { bool isOn = TRUE; LED1_On(); LED2_On(); LED3_On(); LED1_Off(); LED2_Off(); LED3_Off(); LED1_Neg(); LED2_Neg(); LED3_Neg(); LED1_On(); /* if (!LED1_Get()) { LED3_Off(); } LED1_Off(); if (LED1_Get()) { for(;;){}; /* error } LED1_Put(isOn); if (!LED1_Get()) { for(;;){}; /* error } */ }
/** * \brief FreeRTOS task * \param pvParameters Task startup parameter */ static portTASK_FUNCTION(MainTask, pvParameters) { (void)pvParameters; /* parameter not used */ for(;;) { LED1_Neg(); EVNT1_HandleEvent(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } }
static void T2(void* param) { TickType_t xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); for(;;) { LED1_Neg(); FRTOS1_vTaskDelayUntil(&xLastWakeTime, 1000*portTICK_RATE_MS); } }
static portTASK_FUNCTION(MainTask, pvParameters) { (void)pvParameters; /* parameter not used */ TRACE_Init(); MMA1_Init(); /* enable accelerometer, if not already enabled */ SHELL_Init(); for(;;) { LED1_Neg(); FRTOS1_vTaskDelay(1000/portTICK_RATE_MS); } }
/* User includes (#include below this line is not maintained by Processor Expert) */ static portTASK_FUNCTION(LedTask, pvParameters) { (void)pvParameters; /* parameter not used */ LED1_Off(); LED2_Off(); LED3_Off(); for(;;) { LED1_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } }
void APP_Run(void) { for(;;) { SHM1_Clear(); SpeedTest(); Test(); TestSingleLine(); TestDoVCOM(); LED1_Neg(); WAIT1_Waitms(100); } }
static portTASK_FUNCTION(ShellTask, pvParameters) { static unsigned char cmd_buf[32]; uint8_t buf[USB1_DATA_BUFF_SIZE]; bool startup = TRUE; (void)pvParameters; cmd_buf[0]='\0'; for(;;) { if (CDC1_App_Task(buf, sizeof(buf))!=ERR_OK) { /* Call the USB application task, wait until enumeration has finished */ while(CDC1_App_Task(buf, sizeof(buf))!=ERR_OK) { LED1_Neg(); /* flash LED fast to indicate that we are not communicating */ FRTOS1_vTaskDelay(20/portTICK_RATE_MS); } } LED1_Neg(); (void)FSSH1_ReadAndParseLine(cmd_buf, sizeof(cmd_buf), FSSH1_GetStdio(), ParseCommand); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } }
static portTASK_FUNCTION(ShellTask, pvParameters) { unsigned char buf[48]; (void)pvParameters; /* not used */ buf[0] = '\0'; (void)CLS1_ParseWithCommandTable((unsigned char*)CLS1_CMD_HELP, CLS1_GetStdio(), CmdParserTable); for(;;) { (void)CLS1_ReadAndParseWithCommandTable(buf, sizeof(buf), CLS1_GetStdio(), CmdParserTable); FRTOS1_vTaskDelay(50/portTICK_RATE_MS); LED1_Neg(); } }
static portTASK_FUNCTION(vSlaveTask, pvParameters) { xSemaphoreHandle sem; sem = (xSemaphoreHandle)pvParameters; for(;;) { if (sem != NULL) { if (FRTOS1_xSemaphoreTake(sem, portMAX_DELAY)==pdTRUE) { LED1_Neg(); } } } }
void APP_Run(void) { if (FRTOS1_xTaskCreate(MainTask, (signed portCHAR *)"Main", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL) != pdPASS) { for(;;){} /* error */ } //(void)RTOSTICK1_Enable(); //FRTOS1_taskENABLE_INTERRUPTS(); for(;;) { LED1_Neg(); WAIT1_Waitms(1000); } FRTOS1_vTaskStartScheduler(); }
/** * \brief FreeRTOS task */ static portTASK_FUNCTION(MyTask, pvParameters) { (void)pvParameters; /* parameter not used */ for(;;) { LED1_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); LED2_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); LED3_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); LED4_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } /* for */ }
static void APP_HandleEvent(EVNT_Handle event) { switch(event) { case EVNT_INIT: LED1_On(); WAIT1_Waitms(500); LED1_Off(); break; #if PL_NOF_KEYS>=1 case EVNT_SW1_PRESSED: LED1_Neg(); #if PL_HAS_BUZZER (void)BUZ_Beep(300, 500); #endif #if PL_HAS_REMOTE if (REMOTE_GetOnOff()) { REMOTE_SetOnOff(FALSE); } else { REMOTE_SetOnOff(TRUE); } #endif break; #endif #if PL_NOF_KEYS>=2 case EVNT_SW2_PRESSED: LED2_Neg(); #if PL_HAS_REMOTE && PL_APP_ACCEL_CONTROL_SENDER //(void)RSTDIO_SendToTxStdio(RSTDIO_QUEUE_TX_IN, "buzzer buz 800 400\r\n", sizeof("buzzer buz 800 400\r\n")-1); #endif break; #endif #if PL_NOF_KEYS>=3 case EVNT_SW3_PRESSED: LED3_Neg(); break; #endif #if PL_NOF_KEYS>=4 case EVNT_SW4_PRESSED: LED4_Neg(); break; #endif #if PL_HAS_LED_HEARTBEAT case EVNT_LED_HEARTBEAT: LED4_Neg(); break; #endif default: #if PL_HAS_RADIO //RADIO_AppHandleEvent(event); #endif break; } }
void TMR_OnInterrupt(void) { /* this one gets called from an interrupt!!!! */ static int cntr=0; cntr++; if (cntr==(1000/TMR_TICK_MS)) { #if 1 /* setting an event */ EVNT_SetEvent(EVENT_LED_HEARTBEAT); #else /* toggling directly the LED */ LED1_Neg(); #endif cntr = 0; } #if PL_HAS_TRIGGER TRG_IncTick(); //Increment the Trigger (10ms are over) #endif }
/*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 */ float temperature, humidity; uint8_t res; unsigned char buf[32]; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ CLS1_SendStr("\r\n-----------------------\r\nSHT11 Example\r\n-----------------------\r\n", CLS1_GetStdio()->stdOut); res = SHT11_SoftReset(); if (res!=ERR_OK) { CLS1_SendStr("FAILED to reset device\r\n ", CLS1_GetStdio()->stdErr); for(;;){} } for(;;) { SHT11_Read(&temperature, &humidity); CLS1_SendStr("Temperature ", CLS1_GetStdio()->stdOut); buf[0] = '\0'; UTIL1_strcatNum32sDotValue100(buf, sizeof(buf), temperature*100); CLS1_SendStr(buf, CLS1_GetStdio()->stdOut); CLS1_SendStr("°C, Humidity ", CLS1_GetStdio()->stdOut); buf[0] = '\0'; UTIL1_strcatNum32sDotValue100(buf, sizeof(buf), humidity*100); CLS1_SendStr(buf, CLS1_GetStdio()->stdOut); CLS1_SendStr("%\r\n", CLS1_GetStdio()->stdOut); WAIT1_Waitms(1000); LED1_Neg(); } /* For example: for(;;) { } */ /*** 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!!! ***/