From c34d47a17f4e3d0d9db25731ee585621f25e7892 Mon Sep 17 00:00:00 2001 From: Mike Bruno Date: Thu, 17 Aug 2017 14:37:09 -0400 Subject: [PATCH 1/6] Add support for 4-tile smart mic board --- .../api/mic_array_board_support.h | 22 ++++++++++++++++++- .../src/board_support.xc | 17 ++++++++++++++ lib_mic_array_board_support/src/pll.xc | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib_mic_array_board_support/api/mic_array_board_support.h b/lib_mic_array_board_support/api/mic_array_board_support.h index ce2e819..ea8aa48 100644 --- a/lib_mic_array_board_support/api/mic_array_board_support.h +++ b/lib_mic_array_board_support/api/mic_array_board_support.h @@ -10,11 +10,16 @@ #define MIC_BOARD_SUPPORT_BUTTON_PORTS PORT_BUT_A_TO_D + +#if defined(PORT_LED10_TO_12) #if defined(PORT_LED_OEN) #define MIC_BOARD_SUPPORT_LED_PORTS {PORT_LED0_TO_7, PORT_LED8, PORT_LED9, PORT_LED10_TO_12, PORT_LED_OEN} #else #define MIC_BOARD_SUPPORT_LED_PORTS {PORT_LED0_TO_7, PORT_LED8, PORT_LED9, PORT_LED10_TO_12} #endif +#else +#define MIC_BOARD_SUPPORT_LED_PORTS {PORT_LED0_TO_7, PORT_LED8_TO_11, PORT_LED_12} +#endif /** This type is used to describe an event on a button. */ @@ -29,10 +34,24 @@ typedef enum { /** Structure to describe the LED ports*/ typedef struct { +#if defined(PORT_LED0_TO_7) out port p_led0to7; /**>=(20-8); unsigned d=0; +#if defined(PORT_LED0_TO_7) for(unsigned i=0;i<8;i++) d=(d>>1)+(0x80*(led_brightness[i]<=elapsed)); leds.p_led0to7 <: d; +#endif +#if defined(PORT_LED8) leds.p_led8 <: (led_brightness[8]<=elapsed); +#endif +#if defined(PORT_LED9) leds.p_led9 <: (led_brightness[9]<=elapsed); +#endif +#if defined(PORT_LED8_TO_11) + d=0; + for(unsigned i=8;i<12;i++) + d=(d>>1)+(0x80*(led_brightness[i]<=elapsed)); + leds.p_led8to11 <: d; +#endif +#if defined(PORT_LED10_TO_12) d=0; for(unsigned i=10;i<13;i++) d=(d>>1)+(0x4*(led_brightness[i]<=elapsed)); leds.p_led10to12 <: d; +#endif +#if defined(PORT_LED_12) + leds.p_led12 <: (led_brightness[12]<=elapsed); +#endif break; } /* diff --git a/lib_mic_array_board_support/src/pll.xc b/lib_mic_array_board_support/src/pll.xc index 2f0ecdd..d5d970f 100644 --- a/lib_mic_array_board_support/src/pll.xc +++ b/lib_mic_array_board_support/src/pll.xc @@ -21,6 +21,7 @@ void mabs_init_pll(client i2c_master_if i2c, mabs_board_t board){ case SMART_MIC_BASE: case WIFI_MIC_ARRAY: + case SMART_MIC_BASE_4TILE: // SI5351A Register Addresses #define SI5351A_OE_CTRL (0x03) // Register 3 - Output Enable Control #define SI5351A_FANOUT_EN (0xBB) // Register 187 - Fanout Enable Control From ce7c0e431f9efa8f051c50da5d21acebb479632d Mon Sep 17 00:00:00 2001 From: Mike Bruno Date: Wed, 13 Sep 2017 11:46:11 -0400 Subject: [PATCH 2/6] Support the new quad tile bga device mic array board. LEDs not supported. --- lib_mic_array_board_support/api/mic_array_board_support.h | 7 ++++++- lib_mic_array_board_support/src/board_support.xc | 2 ++ lib_mic_array_board_support/src/pll.xc | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib_mic_array_board_support/api/mic_array_board_support.h b/lib_mic_array_board_support/api/mic_array_board_support.h index ea8aa48..16acac0 100644 --- a/lib_mic_array_board_support/api/mic_array_board_support.h +++ b/lib_mic_array_board_support/api/mic_array_board_support.h @@ -17,7 +17,7 @@ #else #define MIC_BOARD_SUPPORT_LED_PORTS {PORT_LED0_TO_7, PORT_LED8, PORT_LED9, PORT_LED10_TO_12} #endif -#else +#elif defined(PORT_LED_12) #define MIC_BOARD_SUPPORT_LED_PORTS {PORT_LED0_TO_7, PORT_LED8_TO_11, PORT_LED_12} #endif @@ -34,6 +34,9 @@ typedef enum { /** Structure to describe the LED ports*/ typedef struct { +#if !defined(MIC_BOARD_SUPPORT_LED_PORTS) + int unused; +#else #if defined(PORT_LED0_TO_7) out port p_led0to7; /** unsigned now :{ time = now + MIN_POLL_TIME_US; unsigned elapsed = (now-start_of_time)&LED_MAX_COUNT; @@ -116,6 +117,7 @@ void mabs_button_and_led_server(server interface mabs_led_button_if lb[n_lb], #endif break; } +#endif /* default:{ unsigned now; diff --git a/lib_mic_array_board_support/src/pll.xc b/lib_mic_array_board_support/src/pll.xc index d5d970f..b2cd6cd 100644 --- a/lib_mic_array_board_support/src/pll.xc +++ b/lib_mic_array_board_support/src/pll.xc @@ -22,6 +22,7 @@ void mabs_init_pll(client i2c_master_if i2c, mabs_board_t board){ case SMART_MIC_BASE: case WIFI_MIC_ARRAY: case SMART_MIC_BASE_4TILE: + case MIC_ARRAY_BASE_4TILE_BGA: // SI5351A Register Addresses #define SI5351A_OE_CTRL (0x03) // Register 3 - Output Enable Control #define SI5351A_FANOUT_EN (0xBB) // Register 187 - Fanout Enable Control From 9bffa605135a59e7d81e23661deeeefb44bbe4b1 Mon Sep 17 00:00:00 2001 From: Andrew Cavanaugh Date: Fri, 15 Sep 2017 10:57:01 -0400 Subject: [PATCH 3/6] Added wscript --- lib_mic_array_board_support/wscript | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 lib_mic_array_board_support/wscript diff --git a/lib_mic_array_board_support/wscript b/lib_mic_array_board_support/wscript new file mode 100644 index 0000000..5d06717 --- /dev/null +++ b/lib_mic_array_board_support/wscript @@ -0,0 +1,7 @@ +def use_module(bld): + source = bld.path.ant_glob('src/*') + bld.module( + source=source, + includes=['api'], + depends_on=['lib_i2c(>=4.0.0)'], + version='2.2.3') From deb307058c1cb6819c952164d25494eb6e69d4e3 Mon Sep 17 00:00:00 2001 From: Mike Bruno Date: Wed, 25 Oct 2017 14:55:42 -0400 Subject: [PATCH 4/6] Add LED support for the BGA167 mic array board --- .../api/mic_array_board_support.h | 35 +++-- .../src/board_support.xc | 18 ++- .../src/ma_bga167_led_driver.xc | 126 ++++++++++++++++++ 3 files changed, 166 insertions(+), 13 deletions(-) create mode 100644 lib_mic_array_board_support/src/ma_bga167_led_driver.xc diff --git a/lib_mic_array_board_support/api/mic_array_board_support.h b/lib_mic_array_board_support/api/mic_array_board_support.h index 16acac0..c0b214b 100644 --- a/lib_mic_array_board_support/api/mic_array_board_support.h +++ b/lib_mic_array_board_support/api/mic_array_board_support.h @@ -19,6 +19,10 @@ #endif #elif defined(PORT_LED_12) #define MIC_BOARD_SUPPORT_LED_PORTS {PORT_LED0_TO_7, PORT_LED8_TO_11, PORT_LED_12} +#else +#define MIC_BOARD_LED_STCP on tile[3] : XS1_PORT_1A +#define MIC_BOARD_LED_SHCP on tile[3] : XS1_PORT_1B +#define MIC_BOARD_LED_DATA on tile[3] : XS1_PORT_1E; #endif /** This type is used to describe an event on a button. @@ -33,10 +37,8 @@ typedef enum { #define BUTTON_EVENT_NONE (-1) /** Structure to describe the LED ports*/ +#ifndef MIC_BOARD_LED_STCP typedef struct { -#if !defined(MIC_BOARD_SUPPORT_LED_PORTS) - int unused; -#else #if defined(PORT_LED0_TO_7) out port p_led0to7; /** button_val; while(1){ -// #pragma ordered + //[[ordered]] select { case lb[int i].set_led_brightness(unsigned led, unsigned brightness):{ if(led < MIC_BOARD_SUPPORT_LED_COUNT) @@ -83,12 +88,17 @@ void mabs_button_and_led_server(server interface mabs_led_button_if lb[n_lb], break; } -#if defined(MIC_BOARD_SUPPORT_LED_PORTS) case t when timerafter(time) :> unsigned now :{ time = now + MIN_POLL_TIME_US; unsigned elapsed = (now-start_of_time)&LED_MAX_COUNT; elapsed>>=(20-8); unsigned d=0; +#if defined(MIC_BOARD_LED_STCP) + + for(unsigned i=0; i<13; i++) + d=(d>>1)+(0x1000*(led_brightness[i]<=elapsed)); + leds.set_leds(d); +#else #if defined(PORT_LED0_TO_7) for(unsigned i=0;i<8;i++) d=(d>>1)+(0x80*(led_brightness[i]<=elapsed)); @@ -114,10 +124,10 @@ void mabs_button_and_led_server(server interface mabs_led_button_if lb[n_lb], #endif #if defined(PORT_LED_12) leds.p_led12 <: (led_brightness[12]<=elapsed); +#endif #endif break; } -#endif /* default:{ unsigned now; diff --git a/lib_mic_array_board_support/src/ma_bga167_led_driver.xc b/lib_mic_array_board_support/src/ma_bga167_led_driver.xc new file mode 100644 index 0000000..95adc8b --- /dev/null +++ b/lib_mic_array_board_support/src/ma_bga167_led_driver.xc @@ -0,0 +1,126 @@ +#include "mic_array_board_support.h" + +#ifdef MIC_BOARD_LED_STCP + +out port p_led_stcp = MIC_BOARD_LED_STCP; +out port p_led_shcp = MIC_BOARD_LED_SHCP; +out port p_led_data = MIC_BOARD_LED_DATA; + +#define MAX(a,b) ((a) > (b) ? (a) : (b)) + +#define LED_COUNT MIC_BOARD_SUPPORT_LED_COUNT + +/* + * Timing data from: + * https://assets.nexperia.com/documents/data-sheet/74HC_HCT595.pdf + * + * Hold times are negligible (less than 1 tick) + */ + +/* + * The chip is really powered at 3.3V. The values for 4.5V + * seem to work fine, at least at room temperature. + */ +#define VCC 4 + +#if VCC==2 +/* + * Assuming Vcc = 2V, -40C to 85C + */ +#define T_DS_SHCP_SU 7 /* min setup time for DS before SHCP high */ +#define T_SHCP_Q7S_PD 20 /* max SHCP to Q7S propagation delay */ +#define T_CLK_PW 10 /* min pulse width for STCP and SHCP */ +#define T_CLK_PERIOD 21 /* min clock period for SHCP */ +#define T_SHCP_STCP_SU 10 /* min setup time for SHCP before SCTP high */ + +#elif VCC==4 +/* + * Assuming Vcc = 4.5V, -40C to 85C + */ +#define T_DS_SHCP_SU 2 /* min setup time for DS before SHCP high */ +#define T_SHCP_Q7S_PD 5 /* max SHCP to Q7S propagation delay */ +#define T_CLK_PW 2 /* min pulse width for STCP and SHCP */ +#define T_CLK_PERIOD 5 /* min clock period for SHCP */ +#define T_SHCP_STCP_SU 2 /* min setup time for SHCP before SCTP high */ + +#endif + +/* calculate minimum time that SHCP must be low for between high pulses */ +#define T_SHCP_LOW (MAX(T_CLK_PERIOD, (T_SHCP_Q7S_PD + T_DS_SHCP_SU)) - T_CLK_PW) + +static void wait_ticks(int ticks) +{ + timer tmr; + uint32_t t; + tmr :> t; + tmr when timerafter(t+ticks-1) :> void; +} + +/*************************************************************** +Numbers are for the VCC=2V, -40C to 85C case. + +shcp high for 10 ticks +shcp low for 17 ticks +ds change 7 ticks before clock high +ds changes every 27 ticks + + 270 100 170 + <----------------><-------><-------> + ________ ________ _______ +shcp _______| |________| |________| ... + + 70 (setup time) 70 + <--> <--> + __ ________________ ________________ ___________ +ds __/\________________\/________________/\___________... + + 200 70 (200ns is clk high to q7s valid, 70ns is setup time) + <------------><--> + _____________________ _________________ __________ +q7s _____________________/\_________________\/__________... + +***************************************************************/ + +static void led_driver(out port stcp, out port shcp, out port data, uint16_t led_value) +{ + stcp <: 0; + shcp <: 0; + data <: 0; + + data <: (uint32_t)led_value >> LED_COUNT-1; + wait_ticks(T_DS_SHCP_SU); + shcp <: 1; + + for (int i = 0; i < LED_COUNT-1; i++) { + wait_ticks(T_CLK_PW); + shcp <: 0; + wait_ticks(T_SHCP_LOW - T_DS_SHCP_SU); + + /* left shift led_value out (MSB first) */ + led_value <<= 1; + data <: (uint32_t)led_value >> LED_COUNT-1; + wait_ticks(T_DS_SHCP_SU); + shcp <: 1; + } + + wait_ticks(T_SHCP_STCP_SU); + stcp <: 1; + wait_ticks(T_CLK_PW); + shcp <: 0; + stcp <: 0; +} + +[[combinable]] +void ma_bga167_led_driver(server interface ma_bga167_led_if leds) +{ + while (1) { + select { + case leds.set_leds(uint16_t led_value): + led_driver(p_led_stcp, p_led_shcp, p_led_data, led_value); + break; + } + } +} + +#endif + From 9d3816a7ea035c082c5a8d1e5024fc471dc66526 Mon Sep 17 00:00:00 2001 From: Mike Bruno Date: Thu, 26 Oct 2017 16:52:38 -0400 Subject: [PATCH 5/6] Add comments, rename LED driver task, update version number --- .../api/mic_array_board_support.h | 20 +++++++++++++++++-- lib_mic_array_board_support/module_build_info | 2 +- .../src/ma_bga167_led_driver.xc | 4 +++- lib_mic_array_board_support/wscript | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib_mic_array_board_support/api/mic_array_board_support.h b/lib_mic_array_board_support/api/mic_array_board_support.h index c0b214b..47a0ab8 100644 --- a/lib_mic_array_board_support/api/mic_array_board_support.h +++ b/lib_mic_array_board_support/api/mic_array_board_support.h @@ -118,12 +118,27 @@ interface mabs_led_button_if { }; #ifdef MIC_BOARD_LED_STCP + +/** This interface is used to connect the mabs_button_and_led_server + * task to the ma_bga167_led_driver task, specifically for the + * BGA167 mic array board. This is necessary due to the fact that + * the buttons and LEDs are on different tiles. + */ interface ma_bga167_led_if { void set_leds(uint16_t led_value); }; +/** A task to drive the LEDs on the BGA167 mic array board. + * + * This task must be started in main on the tile that the LEDs + * are connected to. On the BGA167 mic array board this is + * tile 3. + * + * \param leds Interface to the mabs_button_and_led_server task. + * task. + */ [[combinable]] -void ma_bga167_led_driver(server interface ma_bga167_led_if led); +void mabs_bga167_led_driver(server interface ma_bga167_led_if led); #endif @@ -134,7 +149,8 @@ void ma_bga167_led_driver(server interface ma_bga167_led_if led); * \param lb An array of client interfaces. * \param n_lb The number of client tasks connected to this server. * \param leds The structure containing the ports used to drive the LEDs, - * or interface to the LED driver task if the BGA167 board. + * OR, when on the BGA167 mic array board, the interface to + * the ma_bga167_led_driver task. * \param p_buttons The port to which the buttons are mapped. */ [[combinable]] diff --git a/lib_mic_array_board_support/module_build_info b/lib_mic_array_board_support/module_build_info index 62debf8..df08243 100644 --- a/lib_mic_array_board_support/module_build_info +++ b/lib_mic_array_board_support/module_build_info @@ -2,4 +2,4 @@ MODULE_XCC_XC_FLAGS = $(XCC_XC_FLAGS) DEPENDENT_MODULES = lib_i2c(>=4.0.0) -VERSION = 2.2.3 +VERSION = 2.3.0 diff --git a/lib_mic_array_board_support/src/ma_bga167_led_driver.xc b/lib_mic_array_board_support/src/ma_bga167_led_driver.xc index 95adc8b..e13f3c2 100644 --- a/lib_mic_array_board_support/src/ma_bga167_led_driver.xc +++ b/lib_mic_array_board_support/src/ma_bga167_led_driver.xc @@ -1,3 +1,5 @@ +// Copyright (c) 2015-2017, XMOS Ltd, All rights reserved + #include "mic_array_board_support.h" #ifdef MIC_BOARD_LED_STCP @@ -111,7 +113,7 @@ static void led_driver(out port stcp, out port shcp, out port data, uint16_t led } [[combinable]] -void ma_bga167_led_driver(server interface ma_bga167_led_if leds) +void mabs_bga167_led_driver(server interface ma_bga167_led_if leds) { while (1) { select { diff --git a/lib_mic_array_board_support/wscript b/lib_mic_array_board_support/wscript index 5d06717..804f664 100644 --- a/lib_mic_array_board_support/wscript +++ b/lib_mic_array_board_support/wscript @@ -4,4 +4,4 @@ def use_module(bld): source=source, includes=['api'], depends_on=['lib_i2c(>=4.0.0)'], - version='2.2.3') + version='2.3.0') From e01d1d5e6c2259c49522d3679bd49bf13962557d Mon Sep 17 00:00:00 2001 From: astewart-xmos Date: Mon, 23 Apr 2018 13:25:19 -0400 Subject: [PATCH 6/6] Changed mabs timer to treat MIN_POLL_TIME_US as microseconds instead of 10's of nanoseconds (#3) The mabs button and LED server was updating the LEDs every MIN_POLL_TIME_US reference clock ticks. But, the macro name implies that it should be updating the LEDs every MIN_POLL_TIME_US microseconds, rather than reference clock ticks. So, this fixes that. This also fixes an issue with the BGA167 boards where the MABS server is broken when the core clock is 500 MHz, because the timer is firing so rapidly it's never able to service any other events. --- lib_mic_array_board_support/src/board_support.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_mic_array_board_support/src/board_support.xc b/lib_mic_array_board_support/src/board_support.xc index 8527a0d..6d22a5b 100644 --- a/lib_mic_array_board_support/src/board_support.xc +++ b/lib_mic_array_board_support/src/board_support.xc @@ -89,7 +89,7 @@ void mabs_button_and_led_server(server interface mabs_led_button_if lb[n_lb], } case t when timerafter(time) :> unsigned now :{ - time = now + MIN_POLL_TIME_US; + time = now + 100*MIN_POLL_TIME_US; unsigned elapsed = (now-start_of_time)&LED_MAX_COUNT; elapsed>>=(20-8); unsigned d=0;