void APP_Run(void) { int cnt=0; /* counter to slow down LED blinking */ for(;;) { WAIT1_Waitms(10); cnt++; if (HIDM1_App_Task()==ERR_BUSOFF) { if ((cnt%128)==0) { /* just slow down blinking */ LEDG_Off(); LEDR_Neg(); } } else { if ((cnt%128)==0) { /* just slow down blinking */ LEDR_Off(); LEDG_Neg(); } if (SW2_GetVal()==0) { /* button pressed */ WAIT1_Waitms(100); /* wait for debouncing */ if (SW2_GetVal()==0) { /* still pressed */ //(void)HIDM1_Send(0, 8, 8); /* raw move message */ //(void)HIDM1_Send(HIDM1_MOUSE_LEFT, 0, 0); /* send left mouse button */ //(void)HIDM1_Send(0, 0, 0); /* send release button message */ //(void)HIDM1_Move(-8, 0); /* moving the cursor up */ //HIDM1_Click(HIDM1_MOUSE_LEFT); /* left mouse click */ HIDM1_Click(HIDM1_MOUSE_RIGHT); /* right mouse click */ } while(SW2_GetVal()==0) {} /* wait until button is released */ } } } }
void APP_Run(void) { int value; char buffer[64]; #if 0 for(;;) { printf("Hello world!\r\n"); LEDR_On(); WAIT1_Waitms(500); LEDR_Off(); LEDG_On(); WAIT1_Waitms(500); LEDG_Off(); } #endif for(;;) { printf("Hello world!\r\n"); printf("Please enter a name:\n\r"); scanf("%s", buffer); printf(" I have received: '%s'\r\n", buffer); printf("Please enter a number:\r\n"); scanf("%i", &value); printf(" I have received: '%i'\r\n", value); } }
static void CheckStatus(void) { switch (FsMSD1_GetDeviceStatus()) { case USB_DEVICE_IDLE: break; case USB_DEVICE_ATTACHED: LEDR_Off(); LEDG_On(); print((unsigned char*)"Mass Storage Device Attached\n" ); break; case USB_DEVICE_SET_INTERFACE_STARTED: break; case USB_DEVICE_INTERFACED: break; case USB_DEVICE_DETACHED: LEDR_On(); LEDG_Off(); print((unsigned char*)"\nMass Storage Device Detached\n" ); break; case USB_DEVICE_OTHER: break; default: print((unsigned char*)"Unknown Mass Storage Device State\n"); break; } /* switch */ }
static void CDC_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 */ LEDR_Neg(); LEDG_Off(); WAIT1_Waitms(10); } LEDR_Off(); LEDG_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); } } }
static void CDC_Run(void) { int i; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LEDR_Neg(); LEDG_Off(); WAIT1_Waitms(10); } LEDR_Off(); LEDG_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); } } }
/*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 */ SD_GreenLed_ClrVal(NULL); SD_RedLed_ClrVal(NULL); for(;;) { LEDR_Off(); LEDG_Off(); Test(); } /*** 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 portTASK_FUNCTION(Task3, pvParameters) { (void) pvParameters; //parameter not used for (;;) { LEDR_Off(); LEDG_Off(); LEDB_On(); //FRTOS1_vTaskDelay(500/portTICK_RATE_MS); } }
/* ** =================================================================== ** Method : LEDG_SetRatio16 (component LED) ** Description : ** Method to specify the duty cycle. If using a PWM pin, this ** means the duty cycle is set. For On/off pins, values smaller ** 0x7FFF means off, while values greater means on. ** Parameters : ** NAME - DESCRIPTION ** ratio - Ratio value, where 0 means 'off' and ** 0xffff means 'on' ** Returns : Nothing ** =================================================================== */ void LEDG_SetRatio16(word ratio) { /* on/off LED: binary on or off */ if (ratio<(0xffff/2)) { LEDG_Off(); } else { LEDG_On(); } }
void blink_green(const int n) { int i; i = 0; for (i = 0; i < (2*n); i++) { LEDG_Neg(); WAIT1_Waitms(BLINKTIME); } LEDG_Off(); }
static void StateMachine(bool buttonPress) { static uint8_t cnt; switch (appState) { case APP_STATE_INIT: LEDG_Off(); LEDR_On(); if (buttonPress) { APP_StateStartCalibrate(); } break; case APP_STATE_CALIBRATE: cnt++; if (cnt>50) { cnt = 0; LEDR_Neg(); } if (buttonPress) { APP_StateStopCalibrate(); } break; case APP_STATE_IDLE: LEDR_Off(); LEDG_On(); if (buttonPress) { LF_StartFollowing(); appState = APP_STATE_FOLLOW; } break; case APP_STATE_FOLLOW: LEDR_Off(); LEDG_Off(); if (!LF_IsFollowing()) { appState = APP_STATE_IDLE; } if (buttonPress) { LF_StopFollowing(); appState = APP_STATE_IDLE; } break; } /* switch */ }
static void CDC_Run(void) { int i, cnt = 0; uint32_t val = 0; unsigned char buf[16]; (void)CDC1_SendString((unsigned char*)"Hello world from the KL25Z with USB CDC\r\n"); for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LEDR_Neg(); LEDG_Off(); WAIT1_Waitms(10); } LEDR_Off(); LEDG_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); cnt++; if ((cnt%1024)==0) { /* from time to time, write some text */ (void)CDC1_SendString((unsigned char*)"Type some text and it will echo.\r\n"); CDC1_SendBlock((unsigned char*)"hello?\r\n", sizeof("hello?\r\n")-1); } } } }
static void CDC_Run(void) { unsigned char buf[32]; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LEDR_Neg(); LEDG_Off(); WAIT1_Waitms(10); } LEDR_Off(); LEDG_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { CDC1_ClearRxBuffer(); /* discard incoming buffer */ UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"time on hours: "); UTIL1_strcatNum32u(buf, sizeof(buf), Time_On_Hours); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n"); (void)CDC1_SendString(buf); Time_On_Hours++; } else { WAIT1_Waitms(10); } } }
void APP_Run(void) { int cnt=0; /* counter to slow down LED blinking */ for(;;) { WAIT1_Waitms(10); cnt++; if (SW1_GetVal()==0) { /* button pressed */ WAIT1_Waitms(100); /* wait for debouncing */ if (SW1_GetVal()==0) { /* still pressed */ #if 1 /* send a string */ //(void)HIDK1_SendStr((unsigned char*)"SW1 press "); /* send a string */ #endif #if 0 /* send print screen */ //HIDK1_Send(MODIFERKEYS_NONE, KEY_PRINTSCREEN); //HIDK1_Send(MODIFERKEYS_NONE, KEY_NONE); /* release key */ #endif #if 0 /* send CTRL+ALT+DELETE */ HIDK1_Send(MODIFERKEYS_LEFT_CTRL|MODIFERKEYS_RIGHT_ALT, KEY_DELETE); HIDK1_Send(MODIFERKEYS_NONE, KEY_NONE); /* release key */ #endif } while(SW1_GetVal()==0) {} /* wait until button is released */ } if (HIDK1_App_Task()==ERR_OK) { /* run the USB application task: this will send the buffer */ if ((cnt%100)==0) { LEDR_Off(); LEDG_Neg(); /* blink green LED if connected */ } } else { if ((cnt%200)==0) { LEDG_Off(); LEDR_Neg(); /* blink red LED if not connected */ } } } }
static void StateMachine(bool buttonPress) { #if PL_APP_FOLLOW_OBSTACLE || PL_APP_LINE_FOLLOWING || PL_APP_LINE_MAZE static uint8_t cnt; #endif switch (appState) { case APP_STATE_INIT: LEDG_Off(); LEDR_On(); #if PL_APP_LINE_FOLLOWING || PL_APP_LINE_MAZE if (buttonPress) { APP_StateStartCalibrate(); } #elif PL_APP_FOLLOW_OBSTACLE appState = APP_STATE_IDLE; #endif break; #if PL_APP_FOLLOW_OBSTACLE case APP_STATE_FOLLOW_OBSTACLE: cnt++; if (cnt>50) { cnt = 0; LEDR_Neg(); } if (buttonPress) { followObstacle = FALSE; appState = APP_STATE_IDLE; } break; #endif #if PL_APP_LINE_FOLLOWING || PL_APP_LINE_MAZE case APP_STATE_CALIBRATE: cnt++; if (cnt>50) { cnt = 0; LEDR_Neg(); } if (buttonPress) { APP_StateStopCalibrate(); } break; #endif case APP_STATE_IDLE: LEDR_Off(); LEDG_On(); if (buttonPress) { #if PL_APP_LINE_FOLLOWING || PL_APP_LINE_MAZE LF_StartFollowing(); appState = APP_STATE_FOLLOW_LINE; #elif PL_APP_FOLLOW_OBSTACLE followObstacle = TRUE; appState = APP_STATE_FOLLOW_OBSTACLE; #endif } break; #if PL_APP_LINE_FOLLOWING || PL_APP_LINE_MAZE case APP_STATE_FOLLOW_LINE: LEDR_Off(); LEDG_Off(); if (!LF_IsFollowing()) { appState = APP_STATE_IDLE; } if (buttonPress) { LF_StopFollowing(); appState = APP_STATE_IDLE; } break; #endif } /* switch */ }
static void Run(void) { bool doSampling = FALSE; bool triggered = FALSE; uint32_t heartBeat; frequencyDivider freqDivider; // supported from V1.02 unsigned long data; unsigned char cmd; int i = 0; // prepare SUMP variables triggerData[0].mask = 0; triggerData[0].values = 0; triggerData[0].configuration = 0; triggerData[1].mask = 0; triggerData[1].values = 0; triggerData[1].configuration = 0; triggerData[2].mask = 0; triggerData[2].values = 0; triggerData[2].configuration = 0; triggerData[3].mask = 0; triggerData[3].values = 0; triggerData[3].configuration = 0; // and preset Timer setSampleFrequency(DEFAULT_CLOCK_DIVIDER); heartBeat = DEFAULT_HEARTBEAT_COUNTER; for(;;) { i++; if (i > heartBeat) { /* heartbeat LED (red) if not sampling */ if (!doSampling) { LEDR_Neg(); } i = 0; } if (finishedSampling) { finishedSampling = FALSE; doSampling = FALSE; triggered = FALSE; SendData(); LEDR_Off(); LEDG_Off(); } if (AS1_GetCharsInRxBuf()!=0) { cmd = GetChar(); switch (cmd) { case SUMP_RESET: finishedSampling = FALSE; doSampling = FALSE; triggered = FALSE; LEDR_Off(); LEDG_Off(); break; case SUMP_RUN: bufferSize = BUFFERSIZE; finishedSampling = FALSE; doSampling = TRUE; if (triggerData[0].mask==0) { // no trigger active, simply start sampling LEDR_Off(); //LEDB_On(); triggered = TRUE; TransferDMA(); } else { LEDR_Off(); LEDG_On(); while (!triggered) { // Use short (fast) loop to detect trigger data = (Byte1_GetVal() & 0xFF); /* for now, we support only reading from 8 Probes data = ( Byte2_GetVal() & 0xFF ) << 8; data = ( Byte3_GetVal() & 0xFF ) << 16; data = ( Byte4_GetVal() & 0xFF ) << 24; */ /* use this, if single condition mask (AND) needed */ if (!triggered && triggerData[0].mask != 0) { if ((data & triggerData[0].mask) == triggerData[0].values) { /* matching trigger */ /* use this, if multiple conditions (OR) are needed for (i = 0; i < DEVICE_NOF_PROBES; i++) { // we can handle all supported 32 Bits if ((triggerData[0].mask & 1 << i) > 0) { // if mask bit is set, check if values bit meets the probe bit if ((triggerData[0].values & 1 << i) == (data & 1 << i)) { // yes, we start if any trigger bit meets condition (primitive trigger only) */ LEDG_Off(); //LEDB_On(); triggered = TRUE; // enable DMA AND Trigger first transfer to pick up Trigger // port value from Port // TODO: replace trigger handling by GPIO external trigger // for Level and Edge TransferDMA(); break; } /* if */ } /* if */ // BUT : do not lockup the analyzer!!! if (AS1_GetCharsInRxBuf()!= 0 && GetChar() == SUMP_RESET) { finishedSampling = FALSE; doSampling = FALSE; triggered = FALSE; //LEDB_Off(); LEDG_Off(); break; // leave the While(!triggered) loop } /* while */ } /* while */ } /* if-else */ break; case SUMP_ID: PutString("1ALS"); break; case SUMP_GET_METADATA: /* device name: */ PutChar(0x01); PutString(DEVICE_NAME); PutChar(0x00); /* 'Firmware version: */ PutChar(0x02); PutString(DEVICE_FW_VERSION); PutChar(0x00); /* 'Ancillary' version: */ PutChar(0x03); PutString(DEVICE_ANCILLARY); PutChar(0x00); /* amount of sample memory available (bytes) */ SUMP_sendmeta_uint32(0x21, BUFFERSIZE); /* maximum sample rate (Hz) */ SUMP_sendmeta_uint32(0x23, MAX_SAMPLERATE); /* number of usable probes (short) */ SUMP_sendmeta_uint8(0x40, DEVICE_NOF_PROBES); /* protocol version (short) */ SUMP_sendmeta_uint8(0x41, DEVICE_PROTOCOL_VERSION); /* end of meta data */ PutChar(0x00); break; /* long commands.. consume bytes from UART, NYI */ /* Set Trigger Mask*/ case 0xC0: triggerData[0].mask = GetChar(); triggerData[0].mask |= GetChar() << 8; triggerData[0].mask |= GetChar() << 16; triggerData[0].mask |= GetChar() << 24; break; case 0xC4: triggerData[1].mask = GetChar(); triggerData[1].mask |= GetChar() << 8; triggerData[1].mask |= GetChar() << 16; triggerData[1].mask |= GetChar() << 24; break; case 0xC8: triggerData[2].mask = GetChar(); triggerData[2].mask |= GetChar() << 8; triggerData[2].mask |= GetChar() << 16; triggerData[2].mask |= GetChar() << 24; break; case 0xCC: triggerData[3].mask = GetChar(); triggerData[3].mask |= GetChar() << 8; triggerData[3].mask |= GetChar() << 16; triggerData[3].mask |= GetChar() << 24; break; /* Set Trigger Values */ case 0xC1: triggerData[0].values = GetChar(); triggerData[0].values |= GetChar() << 8; triggerData[0].values |= GetChar() << 16; triggerData[0].values |= GetChar() << 24; break; case 0xC5: triggerData[1].values = GetChar(); triggerData[1].values |= GetChar() << 8; triggerData[1].values |= GetChar() << 16; triggerData[1].values |= GetChar() << 24; break; case 0xC9: triggerData[2].values = GetChar(); triggerData[2].values |= GetChar() << 8; triggerData[2].values |= GetChar() << 16; triggerData[2].values |= GetChar() << 24; break; case 0xCD: triggerData[3].values = GetChar(); triggerData[3].values |= GetChar() << 8; triggerData[3].values |= GetChar() << 16; triggerData[3].values |= GetChar() << 24; break; /* Set Trigger Configuration */ case 0xC2: triggerData[0].configuration = GetChar(); triggerData[0].configuration |= GetChar() << 8; triggerData[0].configuration |= GetChar() << 16; triggerData[0].configuration |= GetChar() << 24; break; case 0xC6: triggerData[1].configuration = GetChar(); triggerData[1].configuration |= GetChar() << 8; triggerData[1].configuration |= GetChar() << 16; triggerData[1].configuration |= GetChar() << 24; break; case 0xCA: triggerData[2].configuration = GetChar(); triggerData[2].configuration |= GetChar() << 8; triggerData[2].configuration |= GetChar() << 16; triggerData[2].configuration |= GetChar() << 24; break; case 0xCE: triggerData[3].configuration = GetChar(); triggerData[3].configuration |= GetChar() << 8; triggerData[3].configuration |= GetChar() << 16; triggerData[3].configuration |= GetChar() << 24; break; case SUMP_SET_DIVIDER: // preliminary; received divider values seems to need more testing freqDivider = GetChar(); freqDivider |= GetChar() << 8; freqDivider |= GetChar() << 16; (void)GetChar(); setSampleFrequency(freqDivider); break; case SUMP_SET_READ_DELAY_COUNT: rdCount = GetChar(); rdCount |= GetChar() << 8; rdCount |= GetChar() << 16; rdCount |= GetChar() << 24; break; /* Set Flag */ case SUMP_SET_FLAGS: flags = GetChar(); flags |= (GetChar() << 8); flags |= (GetChar() << 16); flags |= (GetChar() << 24); break; default: break; } /* switch */ } } }
void APP_Run(void) { int cnt=0; /* counter to slow down LED blinking */ uint8_t res; int16_t xyz[3]; res = MMA1_Init(); if (res!=ERR_OK) { Err(); } res = MMA1_SetFastMode(FALSE); if (res!=ERR_OK) { Err(); } res = MMA1_Enable(); /* enable accelerometer */ if (res!=ERR_OK) { Err(); } for(;;) { WAIT1_Waitms(10); /* implement 'air-mouse' movement */ xyz[0] = MMA1_GetX(); xyz[1] = MMA1_GetY(); xyz[3] = MMA1_GetZ(); /* y axis */ if (xyz[1]>AIR_THRESHOLD) { (void)HIDK2_Move(0, 2); /* moving the cursor left */ } else if (xyz[1]<-AIR_THRESHOLD) { (void)HIDK2_Move(0, -2); /* moving the cursor right */ } /* x axis */ if (xyz[0]>AIR_THRESHOLD) { (void)HIDK2_Move(-2, 0); /* moving the cursor up */ } else if (xyz[0]<-AIR_THRESHOLD) { (void)HIDK2_Move(2, 0); /* moving the cursor down */ } cnt++; if (HIDK2_App_Task()==ERR_BUSOFF) { if ((cnt%128)==0) { /* just slow down blinking */ LEDG_Off(); LEDR_Neg(); } } else { if ((cnt%128)==0) { /* just slow down blinking */ LEDR_Off(); LEDG_Neg(); } if (SW1_GetVal()==0) { /* button pressed */ WAIT1_Waitms(100); /* wait for debouncing */ if (SW1_GetVal()==0) { /* still pressed */ //(void)HIDK2_Send(0, 8, 8); /* raw move message */ //(void)HIDK2_Send(HIDK2_MOUSE_LEFT, 0, 0); /* send left mouse button */ //(void)HIDK2_Send(0, 0, 0); /* send release button message */ //(void)HIDK2_Move(-8, 0); /* moving the cursor up */ //HIDK2_Click(HIDK2_MOUSE_LEFT); /* left mouse click */ HIDK2_Click(HIDK2_MOUSE_RIGHT); /* right mouse click */ } while(SW1_GetVal()==0) {} /* wait until button is released */ } } } }