int main(void) { // Configure cpu and mandatory peripherals systemInit(); uint32_t currentSecond, lastSecond; currentSecond = lastSecond = 0; while (1) { // Toggle LED once per second ... rollover = 136 years :) currentSecond = systickGetSecondsActive(); if (currentSecond != lastSecond) { lastSecond = currentSecond; if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN) == CFG_LED_OFF) { gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); } else { gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); } } // Poll for CLI input if CFG_INTERFACE is enabled in projectconfig.h #ifdef CFG_INTERFACE cmdPoll(); #endif } return 0; }
int main(void) { // Configure cpu and mandatory peripherals systemInit(); uint32_t currentSecond, lastSecond; currentSecond = lastSecond = 0; // uartInit(115200); prt(); while (1) { // Toggle LED once per second currentSecond = systickGetSecondsActive(); if (currentSecond != lastSecond) { lastSecond = currentSecond; gpioSetValue(CFG_LED_PORT, CFG_LED_PIN, !(gpioGetValue(CFG_LED_PORT, CFG_LED_PIN))); uartSendByte('*'); } // Poll for CLI input if CFG_INTERFACE is enabled in projectconfig.h #ifdef CFG_INTERFACE cmdPoll(); #endif } return 0; }
void cmd_sysinfo(uint8_t argc, char **argv) { IAP_return_t iap_return; printf("%-25s : %d.%d MHz %s", "System Clock", CFG_CPU_CCLK / 1000000, CFG_CPU_CCLK % 1000000, CFG_PRINTF_NEWLINE); printf("%-25s : v%d.%d.%d %s", "Firmware", CFG_FIRMWARE_VERSION_MAJOR, CFG_FIRMWARE_VERSION_MINOR, CFG_FIRMWARE_VERSION_REVISION, CFG_PRINTF_NEWLINE); // 128-bit MCU Serial Number iap_return = iapReadSerialNumber(); if(iap_return.ReturnCode == 0) { printf("%-25s : %08X %08X %08X %08X %s", "Serial Number", iap_return.Result[0],iap_return.Result[1],iap_return.Result[2],iap_return.Result[3], CFG_PRINTF_NEWLINE); } // CLI and buffer Settings #ifdef CFG_INTERFACE printf("%-25s : %d bytes %s", "Max CLI Command", CFG_INTERFACE_MAXMSGSIZE, CFG_PRINTF_NEWLINE); #endif #ifdef CFG_PRINTF_UART uart_pcb_t *pcb = uartGetPCB(); printf("%-25s : %d %s", "UART Baud Rate", pcb->baudrate, CFG_PRINTF_NEWLINE); #endif // TFT LCD Settings (if CFG_TFTLCD enabled) #ifdef CFG_TFTLCD printf("%-25s : %d %s", "LCD Width", (int)lcdGetWidth(), CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "LCD Height", (int)lcdGetHeight(), CFG_PRINTF_NEWLINE); #endif // Wireless Settings (if CFG_CHIBI enabled) #ifdef CFG_CHIBI chb_pcb_t *pcb = chb_get_pcb(); printf("%-25s : %s %s", "Wireless", "AT86RF212", CFG_PRINTF_NEWLINE); printf("%-25s : 0x%04X %s", "802.15.4 PAN ID", CFG_CHIBI_PANID, CFG_PRINTF_NEWLINE); printf("%-25s : 0x%04X %s", "802.15.4 Node Address", pcb->src_addr, CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "802.15.4 Channel", CFG_CHIBI_CHANNEL, CFG_PRINTF_NEWLINE); #endif // System Uptime (based on systick timer) printf("%-25s : %u s %s", "System Uptime", (unsigned int)systickGetSecondsActive(), CFG_PRINTF_NEWLINE); // System Temperature (if LM75B Present) #ifdef CFG_LM75B int32_t temp = 0; lm75bGetTemperature(&temp); temp *= 125; printf("%-25s : %d.%d C %s", "Temperature", temp / 1000, temp % 1000, CFG_PRINTF_NEWLINE); #endif #ifdef CFG_SDCARD printf("%-25s : %s %s", "SD Card Present", gpioGetValue(CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN) ? "True" : "False", CFG_PRINTF_NEWLINE); #endif }
int main(void) { #ifndef CFG_PWM #ERROR "CFG_PWM must be enabled in projectconfig.h for this example." #endif // Configure cpu and mandatory peripherals // PWM is initialised in systemInit and defaults to using P1.9 systemInit(); // Set duty cycle to 50% for square wave output pwmSetDutyCycle(50); // Frequency can be set anywhere from 2khz and 10khz (4khz is loudest) // Note: Since this is a 16-bit timer, make sure the delay is not // greater than 0xFFFF (65535), though anything 2khz and higher // is within an acceptable range // The piezo buzzer used for this example is the PS1240, available at // http://www.adafruit.com/index.php?main_page=product_info&cPath=35&products_id=160 pwmSetFrequencyInTicks(CFG_CPU_CCLK / 2000); uint32_t currentSecond, lastSecond; currentSecond = lastSecond = 0; while (1) { // Beep the piezo buzzer very briefly once per second, toggling the LED at the same time currentSecond = systickGetSecondsActive(); // Make sure that at least one second has passed if (currentSecond != lastSecond) { // Update the second tracker lastSecond = currentSecond; // Set the LED state and buzzer loudness depending on the current LED state if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN) == CFG_LED_OFF) { pwmSetFrequencyInTicks(CFG_CPU_CCLK / 4000); // 4khz (louder) pwmStartFixed(200); // 2x as long as @ 2khz since it's 2x faster gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); // Turn the LED on } else { pwmSetFrequencyInTicks(CFG_CPU_CCLK / 2000); // 2khz (softer) pwmStartFixed(100); gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); // Turn the LED off } } } return 0; }
int main(void) { uint32_t currentSecond, lastSecond; currentSecond = lastSecond = 0; /* Run project-specific 'main' loop (as defined in projectconfig.h) */ boardMain(); /* If we ever come back from boardMain() just do blinky */ while (1) { currentSecond = systickGetSecondsActive(); if (currentSecond != lastSecond) { lastSecond = currentSecond; /* Toggle LED once per second */ boardLED(lastSecond % 2); } } return 0; }
int main(void) { // Configure cpu and mandatory peripherals systemInit(); uint32_t currentSecond, lastSecond; currentSecond = lastSecond = 0; // Toggle LED once per second and constantly check CLI input while (1) { // Get the number of seconds the CPU has been active // If the value has changed we've advanced at least 1 second currentSecond = systickGetSecondsActive(); if (currentSecond != lastSecond) { lastSecond = currentSecond; // Toggle the LED if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN) == CFG_LED_OFF) { gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); } else { gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); } } // Poll for CLI input if CFG_INTERFACE is enabled in projectconfig.h #ifdef CFG_INTERFACE cmdPoll(); #endif } return 0; }
void cmd_sysinfo(uint8_t argc, char **argv) { IAP_return_t iap_return; /* Note: Certain values are only reported if CFG_INTERFACE_LONGSYSINFO is set to 1 in projectconfig.h. These extra values are more useful for debugging than real-world use, so there's no point wasiting flash space storing the code for them */ printf("%-25s : %d.%d.%d %s", "Firmware", CFG_FIRMWARE_VERSION_MAJOR, CFG_FIRMWARE_VERSION_MINOR, CFG_FIRMWARE_VERSION_REVISION, CFG_PRINTF_NEWLINE); printf("%-25s : %d.%d MHz %s", "System Clock", CFG_CPU_CCLK / 1000000, CFG_CPU_CCLK % 1000000, CFG_PRINTF_NEWLINE); // System Uptime (based on systick timer) printf("%-25s : %u s %s", "System Uptime", (unsigned int)systickGetSecondsActive(), CFG_PRINTF_NEWLINE); // 128-bit MCU Serial Number iap_return = iapReadSerialNumber(); if(iap_return.ReturnCode == 0) { printf("%-25s : %08X %08X %08X %08X %s", "Serial Number", iap_return.Result[0],iap_return.Result[1],iap_return.Result[2],iap_return.Result[3], CFG_PRINTF_NEWLINE); } #if CFG_INTERFACE_LONGSYSINFO #ifdef CFG_USBCDC printf("%-25s : %d ms %s", "USB Init Timeout", CFG_USBCDC_INITTIMEOUT, CFG_PRINTF_NEWLINE); #endif #endif // CLI and buffer Settings #if CFG_INTERFACE_LONGSYSINFO printf("%-25s : %d bytes %s", "CLI Max Command Size", CFG_INTERFACE_MAXMSGSIZE, CFG_PRINTF_NEWLINE); printf("%-25s : %s %s", "CLI IRQ Enabled", CFG_INTERFACE_ENABLEIRQ ? "True" : "False", CFG_PRINTF_NEWLINE); #if CFG_INTERFACE_ENABLEIRQ printf("%-25s : %d.%d %s", "CLI IRQ Location", CFG_INTERFACE_IRQPORT, CFG_INTERFACE_IRQPIN, CFG_PRINTF_NEWLINE); #endif #endif #if CFG_INTERFACE_LONGSYSINFO #ifdef CFG_I2CEEPROM printf("%-25s : %d bytes %s", "EEPROM Size", CFG_I2CEEPROM_SIZE, CFG_PRINTF_NEWLINE); #endif #endif #ifdef CFG_SDCARD printf("%-25s : %s %s", "SD Card Present", gpioGetValue(CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN) ? "True" : "False", CFG_PRINTF_NEWLINE); #if CFG_INTERFACE_LONGSYSINFO printf("%-25s : %s %s", "FAT File System", CFG_SDCARD_READONLY ? "Read Only" : "Read/Write", CFG_PRINTF_NEWLINE); #endif #endif #ifdef CFG_PRINTF_UART uart_pcb_t *pcb = uartGetPCB(); printf("%-25s : %u %s", "UART Baud Rate", (unsigned int)(pcb->baudrate), CFG_PRINTF_NEWLINE); #endif // TFT LCD Settings (if CFG_TFTLCD enabled) #ifdef CFG_TFTLCD printf("%-25s : %d %s", "LCD Width", (int)lcdGetWidth(), CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "LCD Height", (int)lcdGetHeight(), CFG_PRINTF_NEWLINE); #if CFG_INTERFACE_LONGSYSINFO printf("%-25s : %04X %s", "LCD Controller ID", (unsigned short)lcdGetControllerID(), CFG_PRINTF_NEWLINE); printf("%-25s : %s %s", "LCD Small Fonts", CFG_TFTLCD_INCLUDESMALLFONTS == 1 ? "True" : "False", CFG_PRINTF_NEWLINE); printf("%-25s : %s %s", "LCD AA Fonts", CFG_TFTLCD_USEAAFONTS == 1 ? "True" : "False", CFG_PRINTF_NEWLINE); lcdProperties_t lcdprops = lcdGetProperties(); printf("%-25s : %s %s", "Touch Screen", lcdprops.touchscreen ? "True" : "False", CFG_PRINTF_NEWLINE); if (lcdprops.touchscreen) { printf("%-25s : %s %s", "Touch Screen Calibrated", eepromReadU8(CFG_EEPROM_TOUCHSCREEN_CALIBRATED) == 1 ? "True" : "False", CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "Touch Screen Threshold", CFG_TFTLCD_TS_DEFAULTTHRESHOLD, CFG_PRINTF_NEWLINE); } #endif #endif // Wireless Settings (if CFG_CHIBI enabled) #ifdef CFG_CHIBI chb_pcb_t *pcb = chb_get_pcb(); printf("%-25s : %s %s", "Wireless", "AT86RF212", CFG_PRINTF_NEWLINE); printf("%-25s : 0x%04X %s", "802.15.4 PAN ID", CFG_CHIBI_PANID, CFG_PRINTF_NEWLINE); printf("%-25s : 0x%04X %s", "802.15.4 Node Address", pcb->src_addr, CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "802.15.4 Channel", CFG_CHIBI_CHANNEL, CFG_PRINTF_NEWLINE); #endif // System Temperature (if LM75B Present) #ifdef CFG_LM75B int32_t temp = 0; lm75bGetTemperature(&temp); temp *= 125; printf("%-25s : %d.%d C %s", "Temperature", temp / 1000, temp % 1000, CFG_PRINTF_NEWLINE); #endif // ADC Averaging #if CFG_INTERFACE_LONGSYSINFO printf("%-25s : %s %s", "ADC Averaging", ADC_AVERAGING_ENABLE ? "True" : "False", CFG_PRINTF_NEWLINE); #if ADC_AVERAGING_ENABLE printf("%-25s : %d %s", "ADC Averaging Samples", ADC_AVERAGING_SAMPLES, CFG_PRINTF_NEWLINE); #endif #endif // Debug LED #if CFG_INTERFACE_LONGSYSINFO printf("%-25s : %d.%d %s", "LED Location", CFG_LED_PORT, CFG_LED_PIN, CFG_PRINTF_NEWLINE); #endif }
void cmd_sysinfo(uint8_t argc, char **argv) { printf("%-25s : %d.%d MHz %s", "System Clock", CFG_CPU_CCLK / 1000000, CFG_CPU_CCLK % 1000000, CFG_PRINTF_NEWLINE); printf("%-25s : %d.%d.%d %s", "Firmware", CFG_FIRMWARE_VERSION_MAJOR, CFG_FIRMWARE_VERSION_MINOR, CFG_FIRMWARE_VERSION_REVISION, CFG_PRINTF_NEWLINE); // 128-bit MCU Serial Number IAP_return_t iap_return; iap_return = iapReadSerialNumber(); if(iap_return.ReturnCode == 0) { printf("%-25s : %08X %08X %08X %08X %s", "Serial Number", iap_return.Result[0],iap_return.Result[1],iap_return.Result[2],iap_return.Result[3], CFG_PRINTF_NEWLINE); } // Check the battery voltage #ifdef CFG_BAT uint32_t c; gpioSetDir(CFG_BAT_ENPORT, CFG_BAT_ENPIN, gpioDirection_Output ); gpioSetValue(CFG_BAT_ENPORT, CFG_BAT_ENPIN, 1 ); // Enable the voltage divider systickDelay(5); c = adcRead(CFG_BAT_ADC); // Pre-read ADC to warm it up systickDelay(10); c = adcRead(CFG_BAT_ADC); c = (c * CFG_VREG_VCC_MAIN) / 1000; // Value in millivolts relative to supply voltage c = (c * CFG_BAT_MULTIPLIER) / 1000; // Battery voltage in millivolts (depends on resistor values) gpioSetValue(CFG_BAT_ENPORT, CFG_BAT_ENPIN, 0 ); // Turn the voltage divider back off to save power printf("%-25s : %u.%u V %s", "Supply Voltage", (unsigned int)(c / 1000), (unsigned int)(c % 1000), CFG_PRINTF_NEWLINE); #endif // Wireless Settings (if CFG_CHIBI enabled) #ifdef CFG_CHIBI chb_pcb_t *pcb = chb_get_pcb(); printf("%-25s : %s %s", "RF Transceiver", "AT86RF212", CFG_PRINTF_NEWLINE); #if CFG_CHIBI_PROMISCUOUS == 1 printf("%-25s : %s %s", "RF Receive Mode", "Promiscuous", CFG_PRINTF_NEWLINE); #else printf("%-25s : %s %s", "RF Receive Mode", "Normal", CFG_PRINTF_NEWLINE); #endif printf("%-25s : 0x%04X (%d) %s", "802.15.4 PAN ID", CFG_CHIBI_PANID, CFG_CHIBI_PANID, CFG_PRINTF_NEWLINE); printf("%-25s : 0x%04X (%d) %s", "802.15.4 Node Address", pcb->src_addr, pcb->src_addr, CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "802.15.4 Channel", CFG_CHIBI_CHANNEL, CFG_PRINTF_NEWLINE); #endif // CLI and buffer Settings #ifdef CFG_INTERFACE printf("%-25s : %d bytes %s", "Max CLI Command", CFG_INTERFACE_MAXMSGSIZE, CFG_PRINTF_NEWLINE); #endif // System Uptime (based on systick timer) printf("%-25s : %u s %s", "System Uptime", (unsigned int)systickGetSecondsActive(), CFG_PRINTF_NEWLINE); // System Temperature (if LM75B Present) #ifdef CFG_LM75B int32_t temp = 0; lm75bGetTemperature(&temp); temp *= 125; printf("%-25s : %d.%d C %s", "Temperature", (int)(temp / 1000), (int)(temp % 1000), CFG_PRINTF_NEWLINE); #endif #ifdef CFG_SDCARD printf("%-25s : %s %s", "SD Card Present", gpioGetValue(CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN) ? "True" : "False", CFG_PRINTF_NEWLINE); #endif }