int main() { led1 = 0; led2 = 0; uint32_t initial_handler, final_handler; Counter c; // Test chaining inside Serial class flipper_1.attach(&flip_1, 1.0); // the address of the function to be attached (flip) and the interval (1 second) flipper_2.attach(&flip_2, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds) // Test global chaining (InterruptManager) printf("Handler initially: %08X\n", initial_handler = NVIC_GetVector(TIMER_IRQ)); InterruptManager *pManager = InterruptManager::get(); pFunctionPointer_t ptm = pManager->add_handler(testme, TIMER_IRQ); pFunctionPointer_t pinc = pManager->add_handler_front(&c, &Counter::inc, TIMER_IRQ); printf("Handler after calling InterruptManager: %08X\n", NVIC_GetVector(TIMER_IRQ)); wait(4.0); if (!pManager->remove_handler(ptm, TIMER_IRQ) || !pManager->remove_handler(pinc, TIMER_IRQ)) { printf ("remove handler failed.\n"); notify_completion(false); } printf("Interrupt handler calls: %d\n", c.get_count()); printf("Handler after removing previously added functions: %08X\n", final_handler = NVIC_GetVector(TIMER_IRQ)); if (initial_handler != final_handler) { printf( "InteruptManager test failed.\n"); notify_completion(false); } while(1); }
int main() { initialize_spifi(); // Make sure that cube_image is placed in SPIFI if (!IS_ADDR_IN_SPIFI(cube_image)) { notify_completion(false); } // Make sure that cube_image_ref is in IFLASH if (IS_ADDR_IN_SPIFI(cube_image_ref)) { notify_completion(false); } // Compare content if (cube_image_sz != cube_image_ref_sz) { notify_completion(false); } else { int i = 0; for (; i < cube_image_sz; i++) { if (cube_image[i] != cube_image_ref[i]) { notify_completion(false); } } } notify_completion(true); }
int main() { SDFileSystem sd(p11, p12, p13, p14, "sd"); FILE *f; char* str = TEST_STRING; char* buffer = (char*) malloc(sizeof(unsigned char)*strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); printf("Write files\n"); char filename[32]; for (int i=0; i<10; i++) { sprintf(filename, "/sd/test_%d.txt", i); printf("Creating file: %s\n", filename); f = test_open(filename, "w"); test_write(f, str); test_close(f); } printf("List files:\n"); DIR *d = opendir("/sd"); if (d == NULL) { printf("Error opening directory\n"); notify_completion(false); } struct dirent *p; while((p = readdir(d)) != NULL) { printf("%s\n", p->d_name); } closedir(d); notify_completion(true); }
int main() { out = 0; myled = 0; //Test falling edges first in.rise(NULL); in.fall(in_handler); flipper(); if(checks != 5) { printf("falling edges test failed: %d\n",checks); notify_completion(false); } //Now test rising edges in.rise(in_handler); in.fall(NULL); flipper(); if (checks != 10) { printf("raising edges test failed: %d\n",checks); notify_completion(false); } //Finally test both in.rise(in_handler); in.fall(in_handler); flipper(); if (checks != 20) { printf("Simultaneous rising and falling edges failed\n"); notify_completion(false); } notify_completion(true); return 0; }
int main() { EthernetInterface eth; NTPClient ntp; eth.init(); //Use DHCP eth.connect(); // NTP set time { bool result = true; const char *url_ntp_server = "0.pool.ntp.org"; printf("NTP_SETTIME: Trying to update time... \r\n"); const int ret = ntp.setTime(url_ntp_server); if (ret == 0) { time_t ctTime = time(NULL); printf("NTP_SETTIME: UTC Time read successfully ... [OK]\r\n"); printf("NTP_SETTIME: %s\r\n", ctime(&ctTime)); } else { printf("NTP_SETTIME: Error(%d) ... [FAIL]\r\n", ret); result = false; } if (result == false) { notify_completion(false); exit(ret); } } eth.disconnect(); notify_completion(true); return 0; }
int main() { char sent = 'T', received; master.frequency(FREQ); slave.frequency(FREQ); slave.address(ADDR); // First transfer: master to slave master.start(); master.write(ADDR); master.write(sent); while(slave.receive() != I2CSlave::WriteAddressed); slave.read(&received, 1); if(sent != received) { notify_completion(false); return 1; } master.stop(); // Second transfer: slave to master master.start(); master.write(ADDR | 1); while(slave.receive() != I2CSlave::ReadAddressed); slave.write(received); received = master.read(0); master.stop(); notify_completion(received == sent); }
int main() { const int addr = 0xA0; const char mark = 0x66; char data[3]; int fw = 0, fr = 0, fc = 0; int i2c_stat; i2c.frequency(i2c_freq_hz); // Data write data[0] = data[1] = 0; data[2] = mark; if((i2c_stat = i2c.write(addr, data, 3)) != 0) { dprintf("Unable to write data to EEPROM (i2c_stat = 0x%02X), aborting\r\n", i2c_stat); notify_completion(false); return 1; } // ACK polling (assumes write will be successful eventually) while(i2c.write(addr, data, 0) != 0); // Data read (actual test) for(int i = 0; i < ntests; i ++) { data[0] = data[1] = 0; if((i2c_stat = i2c.write(addr, data, 2, true)) != 0) { dprintf("Test %d failed at write, i2c_stat is 0x%02X\r\n", i, i2c_stat); fw ++; continue; } if(i2c_delay_us != 0) wait_us(i2c_delay_us); if((i2c_stat = i2c.read(addr, data, 1)) != 0) { dprintf("Test %d failed at read, i2c_stat is 0x%02X\r\n", i, i2c_stat); fr ++; continue; } if(data[0] != mark) { dprintf("Test %d failed at data match\r\n", i); fc ++; } } dprintf("Test finished.\r\n"); if(fw + fr + fc == 0) dprintf("No failures in %d tests.\r\n", ntests); else { dprintf("Statistics:\r\n"); dprintf(" Total tests: %d\r\n", ntests); dprintf(" Failed at write: %d\r\n", fw); dprintf(" Failed at read: %d\r\n", fr); dprintf(" Data mismatch: %d\r\n", fc); dprintf(" Total failures: %d\r\n", fw + fr + fc); notify_completion(false); } notify_completion(true); }
static void initialize_spifi(void) { SPIFIobj* obj = (SPIFIobj*)malloc(sizeof(SPIFIobj)); if (obj == NULL) { // Failed to allocate memory for ROM data notify_completion(false); } // Turn on SPIFI block as it is disabled on reset LPC_SC->PCONP |= 0x00010000; // pinsel for SPIFI LPC_IOCON->P2_7 = 5; /* SPIFI_CSN @ P2.7 */ LPC_IOCON->P0_22 = 5; /* SPIFI_CLK @ P0.22 */ LPC_IOCON->P0_15 = 5; /* SPIFI_IO2 @ P0.15 */ LPC_IOCON->P0_16 = 5; /* SPIFI_IO3 @ P0.16 */ LPC_IOCON->P0_17 = 5; /* SPIFI_IO1 @ P0.17 */ LPC_IOCON->P0_18 = 5; /* SPIFI_IO0 @ P0.18 */ uint32_t spifi_clk_div = (*((volatile uint32_t*)0x400FC1B4)) & 0x1f; uint32_t spifi_clk_mhz = (SystemCoreClock / spifi_clk_div) / 1000000; const SPIFI_RTNS* _spifi = ROM_DRIVERS_PTR->pSPIFID; /* Typical time tCS is 20 ns min, we give 200 ns to be on safer side */ int rc = _spifi->spifi_init (obj, spifi_clk_mhz/5, S_FULLCLK+S_RCVCLK, spifi_clk_mhz); if (rc) { // Failed to initialize SPIFI notify_completion(false); } }
int main() { #if defined(TARGET_KL25Z) SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); #elif defined(TARGET_nRF51822) //SDFileSystem sd(p20, p22, p25, p24, "sd"); SDFileSystem sd(p12, p13, p15, p14, "sd"); #elif defined(TARGET_NUCLEO_F030R8) || \ defined(TARGET_NUCLEO_F072RB) || \ defined(TARGET_NUCLEO_F091RC) || \ defined(TARGET_NUCLEO_F103RB) || \ defined(TARGET_NUCLEO_F302R8) || \ defined(TARGET_NUCLEO_F303RE) || \ defined(TARGET_NUCLEO_F334R8) || \ defined(TARGET_NUCLEO_F401RE) || \ defined(TARGET_NUCLEO_F411RE) || \ defined(TARGET_NUCLEO_L053R8) || \ defined(TARGET_NUCLEO_L152RE) SDFileSystem sd(D11, D12, D13, D10, "sd"); #elif defined(TARGET_LPC1768_MINI_DK2) SDFileSystem sd(SD_SDI, SD_SDO, SD_SCK, SD_CS, "sd"); #else SDFileSystem sd(p11, p12, p13, p14, "sd"); #endif led2 = 1; wait(0.5); FILE *f; char *str = TEST_STRING; char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); printf("Write files\n"); char filename[32]; for (int i = 0; i < 10; i++) { sprintf(filename, "/sd/test_%d.txt", i); printf("Creating file: %s\n", filename); f = test_open(filename, "w"); led2 = 0; test_write(f, str); test_close(f); } printf("List files:\n"); DIR *d = opendir("/sd"); if (d == NULL) { printf("Error opening directory\n"); notify_completion(false); } struct dirent *p; while ((p = readdir(d)) != NULL) printf("%s\n", p->d_name); closedir(d); notify_completion(true); }
int main() { #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088) PwmOut pwm_p25(p25); PwmOut pwm_p26(p26); pwm_p25.write(0.75); pwm_p26.write(0.50); printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read()); printf("Initialize PWM on pin 26 with duty cycle: %.2f\n", pwm_p26.read()); #elif defined(TARGET_KL25Z) PwmOut pwm_d2(D2); pwm_d2.period_ms(10); pwm_d2.write(0.75); printf("%.2f\n", pwm_d2.read()); #elif defined(TARGET_KL05Z) PwmOut pwm_d2(D3); pwm_d2.period_ms(10); pwm_d2.write(0.75); printf("%.2f\n", pwm_d2.read()); #endif notify_completion(true); }
int main (void) { Thread thread(send_thread); bool result = true; int result_counter = 0; while (true) { osEvent evt = queue.get(); if (evt.status == osEventMessage) { message_t *message = (message_t*)evt.value.p; const float expected_voltage = CREATE_VOLTAGE(message->counter); const float expected_current = CREATE_CURRENT(message->counter); // Check using macros if received values correspond to values sent via queue bool expected_values = (expected_voltage == message->voltage) && (expected_current == message->current); result = result && expected_values; const char *result_msg = expected_values ? "OK" : "FAIL"; printf("%3d %.2fV %.2fA ... [%s]\r\n", message->counter, message->voltage, message->current, result_msg); mpool.free(message); if (result == false || ++result_counter == QUEUE_SIZE) { break; } } } notify_completion(result); return 0; }
int main() { bool check = true; port1.output(); port2.input(); port1 = MASK_1; wait(0.1); if (port2 != MASK_2) check = false; port1 = 0; wait(0.1); if (port2 != 0) check = false; port1.input(); port2.output(); port2 = MASK_2; wait(0.1); if (port1 != MASK_1) check = false; port2 = 0; wait(0.1); if (port1 != 0) check = false; notify_completion(check); }
int main() { pc.printf("Test the Stream class\n"); printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No")); char mac[16]; mbed_mac_address(mac); printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); LocalFileSystem local("local"); FILE *f; char* str = TEST_STRING; char* buffer = (char*) malloc(sizeof(unsigned char)*strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); // Write f = test_open("w"); test_write(f, str, str_len); test_close(f); // Read f = test_open("r"); test_read(f, buffer, str_len); test_close(f); // Check the two strings are equal notify_completion((strncmp(buffer, str, str_len) == 0)); }
void test_read(FILE* f, char* str, int str_len) { int n = fread(str, sizeof(unsigned char), str_len, f); if (n != str_len) { printf("Error reading file"NL); notify_completion(false); } }
void test_write(FILE* f, char* str, int str_len) { int n = fprintf(f, str); if (n != str_len) { printf("Error writing file"NL); notify_completion(false); } }
void test(void const*) { VodafoneUSBModem modem; bool test = run(modem); if(test) { printf("Test successful\n"); notify_completion(true); } else { printf("Test failed\n"); notify_completion(false); } //notify_completion() blocks indefinitely }
int main() { char uid[DEVICE_ID_LENGTH + 1] = {0}; bool result = true; const int ret = mbed_interface_uid(uid); if (ret == 0) { printf("UID: %s\r\n", uid); } else { result = false; } char mac[6] = {0}; // @param mac A 6-byte array to write the MAC address mbed_mac_address(mac); printf("MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); if (mac[0] == MAC_VENDOR_ARM_0 && mac[1] == MAC_VENDOR_ARM_1 && mac[2] == MAC_VENDOR_ARM_2) { printf("MAC Address Prefix: 00:02:F7, Vendor: ARM\r\n"); } notify_completion(result); return 0; }
int main() { out = 0; wait(0.1); if (in != 0) { printf("ERROR: in != 0\n"); notify_completion(false); } out = 1; wait(0.1); if (in != 1) { printf("ERROR: in != 1\n"); notify_completion(false); } notify_completion(true); }
int main() { bool success = true; char buf[] = {3, 2, 1, 4, 5, 6, 7, 8, 9, 10}; char res[SIZE]; i2c.write(ADDR, buf, SIZE); i2c.read(ADDR, res, SIZE); // here should be buf[all]++ i2c.write(ADDR, res, SIZE); i2c.read(ADDR, res, SIZE); // here should be buf[all]+=2 i2c.write(ADDR, res, SIZE); i2c.write(ADDR, res, SIZE); // here should be buf[all]+=3 i2c.read(ADDR, res, SIZE); i2c.read(ADDR, res, SIZE); for(int i = 0; i < SIZE; i++) { if (res[i] != (buf[i] + 3)) { success = false; break; } } notify_completion(success); }
void test_close(FILE* f) { int rc = fclose(f); if (rc != 0) { printf("Error closing file\n"); notify_completion(false); } }
void test_write(FILE* f, const char* str) { int n = fprintf(f, str); if (n != strlen(str)) { printf("Error writing file\n"); notify_completion(false); } }
int main() { printf("MBED: re-routing stdout to /null\n"); freopen("/null", "w", stdout); printf("MBED: printf redirected to /null\n"); // This shouldn't appear // If failure message can be seen test should fail :) notify_completion(false); // This is 'false' on purpose return 0; }
FILE *test_open(const char *mode) { FILE *f = fopen(FILENAME, mode); if (f == NULL) { printf("Error opening file"NL); notify_completion(false); } return f; }
int main() { int data = 0; int res = 0; for(int i = 0; i < 30; i++) { cs = 0; res = spi.write(data++); cs = 1; wait_ms(0.001); if ((i > 1) && ((res + 2) != data)) notify_completion(false); } notify_completion(true); }
int main() { port_out = MASK_1; wait(0.1); int value = port_in.read(); if (value != MASK_2) { printf("[Test high] expected (0x%x) received (0x%x)\n", MASK_2, value); notify_completion(false); } port_out = 0; wait(0.1); value = port_in.read(); if (value != 0) { printf("[Test low] expected (0x%x) received (0x%x)\n", 0, value); notify_completion(false); } notify_completion(true); }
int main() { float t = temperature.read(); printf("TMP102: Temperature: %f\n\r", t); // In our test environment (ARM office) we should get a temperature within // the range ]15, 30[C bool result = (t > 15.0) && (t < 30.0); notify_completion(result); }
FILE* test_open(char* path, const char* mode) { FILE *f; f = fopen(path, mode); if (f == NULL) { printf("Error opening file\n"); notify_completion(false); } return f; }
int main (void) { char c; initial_stack_p = &c; initial_heap_p = (char*)malloc(1); if (initial_heap_p == NULL) { printf("Unable to malloc a single byte\n"); notify_completion(false); } printf("Initial stack/heap geometry:\n"); printf(" stack pointer:V %p\n", initial_stack_p); printf(" heap pointer :^ %p\n", initial_heap_p); initial_heap_p++; stack_test(initial_heap_p); notify_completion(true); }
void sd_thread(void const *argument) { #if defined(TARGET_KL25Z) SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); #else SDFileSystem sd(p11, p12, p13, p14, "sd"); #endif FILE *f = fopen("/sd/out.txt", "w"); // allocate buffers uint8_t data_written[SIZE]; uint8_t data_read[SIZE]; // fill data_written buffer with random data // write these data into the file printf("written: ["); for (int i = 0; i < SIZE; i++) { data_written[i] = rand() % 0xff; fprintf(f, "%c", data_written[i]); printf("%d ", data_written[i]); } printf("]\r\nclosing\r\n"); fclose(f); // read back the data from the file and store them in data_read f = fopen("/sd/out.txt", "r"); printf("read: ["); for (int i=0; i<SIZE; i++) { data_read[i] = fgetc(f); printf("%d ", data_read[i]); } printf("]\r\nclosing\r\n"); fclose(f); // check that the data written == data read for (int i = 0; i < SIZE; i++) { if (data_written[i] != data_read[i]) { notify_completion(false); } } notify_completion(true); }
int main() { notify_start(); for (i=0; i<=65535; i++) { bus1 = i; bus2 = i; wait(0.0001); } notify_completion(true); }