From db3b350e2980bdc445764496e2643c7229772d53 Mon Sep 17 00:00:00 2001 From: Michael DM Dryden <mdryden@chem.utoronto.ca> Date: Tue, 20 Jun 2017 17:15:12 -0400 Subject: [PATCH] =?UTF-8?q?Rename=20leds=20to=20usb.=20Put=20=E2=80=98DSTA?= =?UTF-8?q?T=E2=80=99=20and=20xmega=20lot=20number=20in=20USB=20serial=20s?= =?UTF-8?q?tring.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/conf_usb.h | 7 ++-- src/leds.c | 30 ----------------- src/main.c | 5 ++- src/usb.c | 77 +++++++++++++++++++++++++++++++++++++++++++ src/{leds.h => usb.h} | 12 ++++--- 5 files changed, 93 insertions(+), 38 deletions(-) delete mode 100644 src/leds.c create mode 100644 src/usb.c rename src/{leds.h => usb.h} (53%) diff --git a/src/config/conf_usb.h b/src/config/conf_usb.h index 89a3885..e914994 100644 --- a/src/config/conf_usb.h +++ b/src/config/conf_usb.h @@ -67,7 +67,10 @@ //! USB Device string definitions (Optional) #define USB_DEVICE_MANUFACTURE_NAME "Wheeler Lab" #define USB_DEVICE_PRODUCT_NAME "DStat" -#define USB_DEVICE_SERIAL_NAME "12...EF" +#define USB_DEVICE_SERIAL_NAME +#define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number +#define USB_DEVICE_GET_SERIAL_NAME_LENGTH 10 //DSTAT + 5 +extern uint8_t serial_number[]; /** @@ -164,6 +167,6 @@ extern void my_callback_cdc_set_rts(uint8_t port, uint8_t b_enable); //! The includes of classes and other headers must be done at the end of this file to avoid compile error #include "udi_cdc_conf.h" -#include "leds.h" +#include "usb.h" #endif // _CONF_USB_H_ diff --git a/src/leds.c b/src/leds.c deleted file mode 100644 index ab94e1e..0000000 --- a/src/leds.c +++ /dev/null @@ -1,30 +0,0 @@ -// -// leds.c -// dstat-firmware -// -// Created by Michael Dryden on 2017-05-04. -// Copyright © 2017 Michael Dryden. All rights reserved. -// - -#include "leds.h" -#include "config/conf_board.h" -#include <ioport.h> -#include <util/atomic.h> - -void my_callback_cdc_set_rts(uint8_t port, uint8_t b_enable){ - static uint8_t connected = 0; - - #if BOARD_VER_MAJOR >= 1 && BOARD_VER_MINOR >= 2 && BOARD_VER_MICRO >=3 - ioport_set_pin_level(LED2, b_enable); - #endif - - if (connected && !b_enable){ - ATOMIC_BLOCK(ATOMIC_RESTORESTATE){ - CCP = 0xD8; // Configuration change protection: allow protected IO regiser write - RST.CTRL = RST_SWRST_bm; // Request software reset by writing to protected IO register - } - } - connected = b_enable; -} - - diff --git a/src/main.c b/src/main.c index e6e5a33..4e259d9 100644 --- a/src/main.c +++ b/src/main.c @@ -15,6 +15,7 @@ #include <stdint.h> #include "conf_board.h" #include "ext_twi.h" +#include "usb.h" #include <util/atomic.h> //Internal function declarations @@ -119,7 +120,9 @@ int main(void){ sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_EVSYS); pmic_set_scheduling(PMIC_SCH_ROUND_ROBIN); - + + init_build_usb_serial_number(); + stdio_usb_init(); ads1255_init_pins(); diff --git a/src/usb.c b/src/usb.c new file mode 100644 index 0000000..a6dc4d6 --- /dev/null +++ b/src/usb.c @@ -0,0 +1,77 @@ +// +// leds.c +// dstat-firmware +// +// Created by Michael Dryden on 2017-05-04. +// Copyright © 2017 Michael Dryden. All rights reserved. +// + +#include "usb.h" +#include "config/conf_board.h" +#include <ioport.h> +#include <util/atomic.h> +#include <string.h> + +uint8_t ReadSignatureByte(uint16_t Address); +void NVM_GetGUID(uint8_t* bytearray); + +void my_callback_cdc_set_rts(uint8_t port, uint8_t b_enable){ + static uint8_t connected = 0; + + #if BOARD_VER_MAJOR >= 1 && BOARD_VER_MINOR >= 2 && BOARD_VER_MICRO >=3 + ioport_set_pin_level(LED2, b_enable); + #endif + + if (connected && !b_enable){ + ATOMIC_BLOCK(ATOMIC_RESTORESTATE){ + CCP = 0xD8; // Configuration change protection: allow protected IO regiser write + RST.CTRL = RST_SWRST_bm; // Request software reset by writing to protected IO register + } + } + connected = b_enable; +} + +void init_build_usb_serial_number(void) +{ + serial_number[0] = 'D'; + serial_number[1] = 'S'; + serial_number[2] = 'T'; + serial_number[3] = 'A'; + serial_number[4] = 'T'; + + NVM_GetGUID(&serial_number[5]); +} + +uint8_t ReadSignatureByte(uint16_t Address) { + NVM_CMD = NVM_CMD_READ_CALIB_ROW_gc; + uint8_t Result; + __asm__ ("lpm %0, Z\n" : "=r" (Result) : "z" (Address)); + // __asm__ ("lpm \n mov %0, r0 \n" : "=r" (Result) : "z" (Address) : "r0"); + NVM_CMD = NVM_CMD_NO_OPERATION_gc; + return Result; +} + +void NVM_GetGUID(uint8_t* b) { + enum { + LOTNUM0=8, // Lot Number Byte 0, ASCII + LOTNUM1, // Lot Number Byte 1, ASCII + LOTNUM2, // Lot Number Byte 2, ASCII + LOTNUM3, // Lot Number Byte 3, ASCII + LOTNUM4, // Lot Number Byte 4, ASCII + LOTNUM5, // Lot Number Byte 5, ASCII + WAFNUM =16, // Wafer Number + COORDX0=18, // Wafer Coordinate X Byte 0 + COORDX1, // Wafer Coordinate X Byte 1 + COORDY0, // Wafer Coordinate Y Byte 0 + COORDY1, // Wafer Coordinate Y Byte 1 + }; + + b[ 0]=ReadSignatureByte(LOTNUM0); + b[ 1]=ReadSignatureByte(LOTNUM1); + b[ 2]=ReadSignatureByte(LOTNUM2); + b[ 3]=ReadSignatureByte(LOTNUM3); + b[ 4]=ReadSignatureByte(LOTNUM4); + b[ 5]=ReadSignatureByte(LOTNUM5); + +} + diff --git a/src/leds.h b/src/usb.h similarity index 53% rename from src/leds.h rename to src/usb.h index 7eae012..13eadcb 100644 --- a/src/leds.h +++ b/src/usb.h @@ -1,17 +1,19 @@ // -// leds.h +// usb.h // dstat-firmware // // Created by Michael Dryden on 2017-05-04. // Copyright © 2017 Michael Dryden. All rights reserved. // -#ifndef leds_h -#define leds_h +#ifndef usb_h +#define usb_h #include <stdio.h> +#include "config/conf_usb.h" void my_callback_cdc_set_rts(uint8_t port, uint8_t b_enable); +uint8_t serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH]; +void init_build_usb_serial_number(void); - -#endif /* leds_h */ +#endif /* usb_h */ -- GitLab