]> git.gag.com Git - fw/altos/commitdiff
clone usbrelay code, seems to compile now
authorBdale Garbee <bdale@gag.com>
Sun, 28 Apr 2024 08:01:03 +0000 (01:01 -0700)
committerBdale Garbee <bdale@gag.com>
Sun, 28 Apr 2024 08:01:03 +0000 (01:01 -0700)
src/fctester-v0.1/Makefile
src/fctester-v0.1/ao_fctester.c
src/fctester-v0.1/ao_pins.h

index 11bfc896890430208ab42212d3bb55d6a75d6b3d..bd6f350d43cdfe298f40074d502d38cecae21391 100644 (file)
@@ -16,35 +16,28 @@ INC = \
 #
 # Common AltOS sources
 #
-
 ALTOS_SRC = \
-       ao_led_lpc.c \
        ao_interrupt.c \
        ao_boot_chain.c \
-       ao_romconfig.c \
        ao_product.c \
+       ao_romconfig.c \
        ao_mutex.c \
        ao_panic.c \
        ao_stdio.c \
-       ao_data.c \
-       ao_convert_volt.c \
        ao_task.c \
-       ao_log.c \
        ao_cmd.c \
-       ao_config.c \
        ao_timer_lpc.c \
        ao_exti_lpc.c \
-       ao_adc_lpc.c \
        ao_usb_lpc.c \
-       ao_beep_lpc.c
+       ao_led_lpc.c
 
-PRODUCT=FCtester-v0.1
+PRODUCT=fctester-v0.1
 PRODUCT_DEF=-DFCTESTER_V_0_1
 IDPRODUCT=0x000a
 
 CFLAGS = $(PRODUCT_DEF) $(LPC_CFLAGS)
 
-PROGNAME=fctester-v3
+PROGNAME=fctester-v0.1
 PROG=$(PROGNAME)-$(VERSION).elf
 HEX=$(PROGNAME)-$(VERSION).ihx
 
@@ -53,16 +46,18 @@ OBJ=$(SRC:.c=.o)
 
 all: $(PROG) $(HEX)
 
-$(PROG): Makefile $(OBJ)
+$(PROG): Makefile $(OBJ) altos.ld
        $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS)
 
 $(OBJ): $(INC)
 
+load: $(PROG)
+       lpc-load $(PROG)
+
 distclean:     clean
 
 clean:
-       rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx $(PROGNAME)-*.map
-       rm -f ao_product.h
+       rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx $(PROGNAME)-*.map ao_product.h
 
 install:
 
index 7f001718ecae70dc8a84fd025d202f4aae3d20e3..6e8ba18f9c4914161dbf02230003280c99cc05f1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2024 Bdale Garbee <bdale@gag.com>
+ * Copyright © 2014 Bdale Garbee <bdale@gag.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  */
 
 #include <ao.h>
-#include <ao_led.h>
 
-/*
- * define the FET outputs
- */
+uint8_t                relay_output;
 
-#define NUM_FETS       7
-int on_count = 0;
+void ao_relay_init(void);
 
-typedef struct 
+void
+ao_relay_init(void)
 {
-       int     port;
-       int     pin;
-} fet;
-
-fet outputs[] = {
-       {0, 11},                /* test_a */
-       {0, 22},                /* test_b */
-       {0, 12},                /* test_c */
-       {0, 9},                 /* test_d */
-       {0, 13},                /* test_e */
-       {0, 16},                /* test_f */
-       {1, 19},                /* short  */
-};
-
-static void
-ao_fet_control(uint32_t output, uint8_t value)
-{
-       /* map output to corresponding GPIO port and pin, set to value */
-       ao_gpio_set(outputs[output].port, outputs[output].pin, value);
+       lpc_scb.sysahbclkctrl |= (1 << LPC_SCB_SYSAHBCLKCTRL_GPIO);
+        lpc_gpio.dir[RELAY_PORT] |= RELAY_BIT;
 }
 
+// switch relay to selected output, turn correct LED on as a side effect
 static void
-ao_fet_init(void)
+ao_relay_control(uint8_t output)
 {
-       int i;
-
-       /* initialize GPIO outputs and turn them all off */
-       for (i = 0; i < NUM_FETS; i++) 
-       {
-               ao_enable_output(outputs[i].port, outputs[i].pin, 0);
+       switch (output) {
+       case 1:
+               lpc_gpio.pin[RELAY_PORT] |= RELAY_BIT;
+               ao_led_on(AO_LED_RED);
+               ao_led_off(AO_LED_GREEN);
+               break;
+       default:
+               lpc_gpio.pin[RELAY_PORT] &= (uint8_t) ~RELAY_BIT;
+               ao_led_off(AO_LED_RED);
+               ao_led_on(AO_LED_GREEN);
        }
 }
 
 static void
-ao_fet_on(void)
+ao_relay_select(void) 
 {
-       uint32_t output;
+       uint8_t output;
 
-       output = ao_cmd_decimal();
+       output = (uint8_t) ao_cmd_decimal();
         if (ao_cmd_status != ao_cmd_success)
                 return;
-       if (output > NUM_FETS-1)        /* can't be < 0 since unsigned! */
-               printf ("Invalid FET %lu, must be 0..%u\n", output, NUM_FETS);
-       else {
-               ao_fet_control(output, 1);
-               on_count++;
-       }
-       if (on_count > 0) ao_led_on(AO_LED_RED);
+       if (output > 1) 
+               printf ("Invalid relay position %u\n", output);
+       else
+               ao_relay_control(output);
 }
 
-static void
-ao_fet_off(void)
-{
-       uint32_t output;
-
-       output = ao_cmd_decimal();
-        if (ao_cmd_status != ao_cmd_success)
-                return;
-       if (output > NUM_FETS-1)        /* can't be < 0 since unsigned! */
-               printf ("Invalid FET %lu, must be 0..%u\n", output, NUM_FETS);
-       else {
-               ao_fet_control(output, 0);
-               on_count--;
-       }
-       if (on_count == 0) ao_led_off(AO_LED_RED);
-}
-
-static const struct ao_cmds ao_fet_cmds[] = {
-       { ao_fet_on,  "S <output>\0Set (turn on) FET" },
-       { ao_fet_off, "R <output>\0Reset (turn off) FET" },
+static const struct ao_cmds ao_relay_cmds[] = {
+       { ao_relay_select, "R <output>\0Select relay output" },
        { 0, NULL }
 };
 
 int
 main(void)
 {
-       ao_fet_init();          /* turn all outputs off ASAP */
        ao_clock_init();
-
        ao_task_init();
+       ao_timer_init();
+
+       ao_usb_init();
+
        ao_led_init();
 
-       /* both LEDs on briefly as system test */
-       ao_led_on(LEDS_AVAILABLE);
+       ao_relay_init();
 
-       ao_timer_init();
-       ao_adc_init();
-       ao_cmd_init();
-       ao_usb_init();
+       // initialize to default output
+       relay_output = 0;
+       ao_relay_control(relay_output);
 
-       ao_cmd_register(ao_fet_cmds);
+       ao_cmd_init();
 
-       /* turn red off, leave green on as a "power indicator" */
-       ao_led_off(AO_LED_RED);
+       ao_cmd_register(ao_relay_cmds);
 
        ao_start_scheduler();
 }
index 386c0b822ef679bb78fc5d05aa0702749b47ed24..06921626b4d6cfb8d970d97025515119ca343b04 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2024 Bdale Garbee <bdale@gag.com>
+ * Copyright © 2014 Bdale Garbee <bdale@gag.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-#ifndef _AO_PINS_H_
-#define _AO_PINS_H_
+#define HAS_BEEP       0
 
-#define AO_STACK_SIZE           352
-#define SLEEP_HASH_SIZE         3
-#define AO_NUM_TASKS            6
+#define AO_STACK_SIZE  384
 
-#define HAS_TASK_QUEUE         1
-#define IS_FLASH_LOADER                0
+#define IS_FLASH_LOADER        0
 
 /* Crystal on the board */
-#define AO_LPC_CLKIN    12000000
+#define AO_LPC_CLKIN   12000000
 
 /* Main clock frequency. 48MHz for USB so we don't use the USB PLL */
-#define AO_LPC_CLKOUT   48000000
+#define AO_LPC_CLKOUT  48000000
 
 /* System clock frequency */
-#define AO_LPC_SYSCLK   24000000
-
-#define HAS_USB                        1
-#define HAS_USB_CONNECT                0
-#define HAS_USB_VBUS           0
-#define HAS_USB_PULLUP         1
-#define AO_USB_PULLUP_PORT      0
-#define AO_USB_PULLUP_PIN       20
-
-#define PACKET_HAS_SLAVE       0
-
-#define HAS_SERIAL             0
-
-#define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX       (1984 * 1024)
-#define AO_CONFIG_MAX_SIZE                     1024
-#define LOG_ERASE_MARK                         0x55
-#define LOG_MAX_ERASE                          128
-#define AO_LOG_FORMAT                          AO_LOG_FORMAT_EASYMOTOR
-
-#define HAS_EEPROM             1
-#define USE_INTERNAL_FLASH     0
-#define USE_EEPROM_CONFIG      0
-#define USE_STORAGE_CONFIG     1
-#define AO_PA11_PA12_RMP       1
-#define HAS_BEEP               1
-#define HAS_BATTERY_REPORT     0
-#define HAS_PAD_REPORT         0
-
-/* Beeper is on pio0_1 ct32b0_mat2 .. requires wire mod on board! */
-#define AO_LPC_BEEP_PORT       0
-#define AO_LPC_BEEP_PIN                1
-#define AO_LPC_BEEP_TIMER      0
-#define AO_LPC_BEEP_CHANNEL    2
-
-#define LOW_LEVEL_DEBUG                0
+#define AO_LPC_SYSCLK  24000000
 
-/*
- * ADC
- */
-#define HAS_ADC                        1
+#define HAS_USB                1
 
-#define AO_NUM_ADC             1
+#define HAS_USB_CONNECT        0
+#define HAS_USB_VBUS   0
+#define HAS_USB_PULLUP 1
+#define AO_USB_PULLUP_PORT     0
+#define AO_USB_PULLUP_PIN      6
 
-#define AO_ADC_0               3
+/* USART */
 
-#define AO_DATA_RING           32
+#define HAS_SERIAL             1
+#define USE_SERIAL_0_STDIN     0
+#define SERIAL_0_18_19         1
+#define SERIAL_0_14_15         0
+#define SERIAL_0_17_18         0
+#define SERIAL_0_26_27         0
 
-#define AO_ADC_DUMP(p) \
-       printf("tick: %5lu pyro_current: %5d\n", \
-              (p)->tick, \
-              (p)->adc.pyro_current); 
+/* SPI */
 
-struct ao_adc {
-       int16_t                 pyro_current;
-};
+#define HAS_SPI_0              0
+#define SPI_SCK0_P0_6          0
+#define HAS_SPI_1              0
+#define SPI_SCK1_P1_15         0
+#define SPI_MISO1_P0_22                0
+#define SPI_MOSI1_P0_21                0
 
-/*
- * ADC reference in decivolts
- */
-#define AO_ADC_REFERENCE_DV    33
+/* LED */
 
-/* LEDs */
 #define LED_PORT               0
-#define LED_PIN_RED            7
+#define LED_PIN_RED            23
+#define LED_PIN_GREEN          7
 #define AO_LED_RED             (1 << LED_PIN_RED)
-#define LED_PIN_GREEN          8
 #define AO_LED_GREEN           (1 << LED_PIN_GREEN)
 
 #define LEDS_AVAILABLE         (AO_LED_RED | AO_LED_GREEN)
 
-#endif /* _AO_PINS_H_ */
+/* RELAY */
+
+#define RELAY_PORT             0
+#define RELAY_PIN              3
+#define RELAY_BIT              (1 << RELAY_PIN)
+
+/* Kludge the SPI driver to not configure any
+ * pin for SCK or MOSI
+ */
+#define HAS_SCK1               0
+#define HAS_MOSI1              0