Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:27:58 2016 +0000
Revision:
0:6c56fb4bc5f0
Moving to library for sharing updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:6c56fb4bc5f0 1 #include "mbed.h"
nexpaq 0:6c56fb4bc5f0 2 #include "test_env.h"
nexpaq 0:6c56fb4bc5f0 3
nexpaq 0:6c56fb4bc5f0 4 #if defined(TARGET_VK_RZ_A1H)
nexpaq 0:6c56fb4bc5f0 5 #define LOOPCNT 1
nexpaq 0:6c56fb4bc5f0 6 namespace {
nexpaq 0:6c56fb4bc5f0 7 BusOut bus_out(LED1);
nexpaq 0:6c56fb4bc5f0 8 PinName led_pins[1] = {LED1}; // Temp, used to map pins in bus_out
nexpaq 0:6c56fb4bc5f0 9 }
nexpaq 0:6c56fb4bc5f0 10 #elif defined(TARGET_DISCO_F429ZI)
nexpaq 0:6c56fb4bc5f0 11 #define LOOPCNT 2
nexpaq 0:6c56fb4bc5f0 12 namespace {
nexpaq 0:6c56fb4bc5f0 13 BusOut bus_out(LED1, LED2);
nexpaq 0:6c56fb4bc5f0 14 PinName led_pins[2] = {LED1, LED2}; // Temp, used to map pins in bus_out
nexpaq 0:6c56fb4bc5f0 15 }
nexpaq 0:6c56fb4bc5f0 16 #else
nexpaq 0:6c56fb4bc5f0 17 #define LOOPCNT 4
nexpaq 0:6c56fb4bc5f0 18 namespace {
nexpaq 0:6c56fb4bc5f0 19 BusOut bus_out(LED1, LED2, LED3, LED4);
nexpaq 0:6c56fb4bc5f0 20 PinName led_pins[4] = {LED1, LED2, LED3, LED4}; // Temp, used to map pins in bus_out
nexpaq 0:6c56fb4bc5f0 21 }
nexpaq 0:6c56fb4bc5f0 22 #endif
nexpaq 0:6c56fb4bc5f0 23
nexpaq 0:6c56fb4bc5f0 24 int main()
nexpaq 0:6c56fb4bc5f0 25 {
nexpaq 0:6c56fb4bc5f0 26 notify_start();
nexpaq 0:6c56fb4bc5f0 27
nexpaq 0:6c56fb4bc5f0 28 bool result = false;
nexpaq 0:6c56fb4bc5f0 29
nexpaq 0:6c56fb4bc5f0 30 for (;;) {
nexpaq 0:6c56fb4bc5f0 31 const int mask = bus_out.mask();
nexpaq 0:6c56fb4bc5f0 32 int led_mask = 0x00;
nexpaq 0:6c56fb4bc5f0 33 if (LED1 != NC) led_mask |= 0x01;
nexpaq 0:6c56fb4bc5f0 34 #if !defined(TARGET_VK_RZ_A1H)
nexpaq 0:6c56fb4bc5f0 35 if (LED2 != NC) led_mask |= 0x02;
nexpaq 0:6c56fb4bc5f0 36 #if !defined(TARGET_DISCO_F429ZI)
nexpaq 0:6c56fb4bc5f0 37 if (LED3 != NC) led_mask |= 0x04;
nexpaq 0:6c56fb4bc5f0 38 if (LED4 != NC) led_mask |= 0x08;
nexpaq 0:6c56fb4bc5f0 39 #endif
nexpaq 0:6c56fb4bc5f0 40 #endif
nexpaq 0:6c56fb4bc5f0 41
nexpaq 0:6c56fb4bc5f0 42 printf("MBED: BusIn mask: 0x%X\r\n", mask);
nexpaq 0:6c56fb4bc5f0 43 printf("MBED: BusIn LED mask: 0x%X\r\n", led_mask);
nexpaq 0:6c56fb4bc5f0 44
nexpaq 0:6c56fb4bc5f0 45 // Let's check bus's connected pins mask
nexpaq 0:6c56fb4bc5f0 46 if (mask != led_mask) {
nexpaq 0:6c56fb4bc5f0 47 break;
nexpaq 0:6c56fb4bc5f0 48 }
nexpaq 0:6c56fb4bc5f0 49
nexpaq 0:6c56fb4bc5f0 50 // Checking if DigitalOut is correctly set as connected
nexpaq 0:6c56fb4bc5f0 51 for (int i=0; i < LOOPCNT; i++) {
nexpaq 0:6c56fb4bc5f0 52 printf("MBED: BusOut.bit[%d] is %s\r\n",
nexpaq 0:6c56fb4bc5f0 53 i,
nexpaq 0:6c56fb4bc5f0 54 (led_pins[i] != NC && bus_out[i].is_connected())
nexpaq 0:6c56fb4bc5f0 55 ? "connected"
nexpaq 0:6c56fb4bc5f0 56 : "not connected");
nexpaq 0:6c56fb4bc5f0 57 }
nexpaq 0:6c56fb4bc5f0 58
nexpaq 0:6c56fb4bc5f0 59 for (int i=0; i < LOOPCNT; i++) {
nexpaq 0:6c56fb4bc5f0 60 if (led_pins[i] != NC && bus_out[0].is_connected() == 0) {
nexpaq 0:6c56fb4bc5f0 61 break;
nexpaq 0:6c56fb4bc5f0 62 }
nexpaq 0:6c56fb4bc5f0 63 }
nexpaq 0:6c56fb4bc5f0 64
nexpaq 0:6c56fb4bc5f0 65 // Write mask all LEDs
nexpaq 0:6c56fb4bc5f0 66 bus_out.write(mask); // Set all LED's pins in high state
nexpaq 0:6c56fb4bc5f0 67 if (bus_out.read() != mask) {
nexpaq 0:6c56fb4bc5f0 68 break;
nexpaq 0:6c56fb4bc5f0 69 }
nexpaq 0:6c56fb4bc5f0 70 // Zero all LEDs and see if mask is correctly cleared on all bits
nexpaq 0:6c56fb4bc5f0 71 bus_out.write(~mask);
nexpaq 0:6c56fb4bc5f0 72 if (bus_out.read() != 0x00) {
nexpaq 0:6c56fb4bc5f0 73 break;
nexpaq 0:6c56fb4bc5f0 74 }
nexpaq 0:6c56fb4bc5f0 75
nexpaq 0:6c56fb4bc5f0 76 result = true;
nexpaq 0:6c56fb4bc5f0 77 break;
nexpaq 0:6c56fb4bc5f0 78 }
nexpaq 0:6c56fb4bc5f0 79
nexpaq 0:6c56fb4bc5f0 80 printf("MBED: Blinking LEDs: \r\n");
nexpaq 0:6c56fb4bc5f0 81
nexpaq 0:6c56fb4bc5f0 82 // Just a quick LED blinking...
nexpaq 0:6c56fb4bc5f0 83 for (int i=0; i<LOOPCNT; i++) {
nexpaq 0:6c56fb4bc5f0 84 if (led_pins[i] != NC && bus_out[i].is_connected()) {
nexpaq 0:6c56fb4bc5f0 85 bus_out[i] = 1;
nexpaq 0:6c56fb4bc5f0 86 printf("%c", 'A' + i);
nexpaq 0:6c56fb4bc5f0 87 } else {
nexpaq 0:6c56fb4bc5f0 88 printf(".");
nexpaq 0:6c56fb4bc5f0 89 }
nexpaq 0:6c56fb4bc5f0 90 wait(0.2);
nexpaq 0:6c56fb4bc5f0 91 if (led_pins[i] != NC && bus_out[i].is_connected()) {
nexpaq 0:6c56fb4bc5f0 92 bus_out[i] = 0;
nexpaq 0:6c56fb4bc5f0 93 printf("%c", 'a' + i);
nexpaq 0:6c56fb4bc5f0 94 } else {
nexpaq 0:6c56fb4bc5f0 95 printf(".");
nexpaq 0:6c56fb4bc5f0 96 }
nexpaq 0:6c56fb4bc5f0 97 }
nexpaq 0:6c56fb4bc5f0 98 printf("\r\n");
nexpaq 0:6c56fb4bc5f0 99
nexpaq 0:6c56fb4bc5f0 100 notify_completion(result);
nexpaq 0:6c56fb4bc5f0 101 }