summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Sutter <edsutterjr@gmail.com>2015-07-13 22:11:27 -0400
committerEd Sutter <edsutterjr@gmail.com>2015-07-13 22:11:27 -0400
commitb8ffb40eaadaf34b218578b818ece0323430c756 (patch)
tree2075de1194f0a19d08974d6ee1f41592336f245c
parentreplace bashrc with envsetup to eliminate implication that it is bash specific (diff)
downloadumon-b8ffb40eaadaf34b218578b818ece0323430c756.tar.bz2
BBB: Changes to support runtime blinking LED.
-rw-r--r--main/dev/uart16550.c5
-rw-r--r--ports/beagleboneblack/am335x.h4
-rw-r--r--ports/beagleboneblack/config.h5
-rw-r--r--ports/beagleboneblack/cpuio.c126
-rw-r--r--ports/beagleboneblack/cpuio.h21
-rw-r--r--ports/beagleboneblack/xcmdtbl.h2
6 files changed, 146 insertions, 17 deletions
diff --git a/main/dev/uart16550.c b/main/dev/uart16550.c
index 0326d7a..48997af 100644
--- a/main/dev/uart16550.c
+++ b/main/dev/uart16550.c
@@ -185,6 +185,11 @@ target_getchar(void)
int
target_gotachar(void)
{
+#if INCLUDE_BLINKLED
+ extern void TARGET_BLINKLED(void);
+
+ TARGET_BLINKLED();
+#endif
if (CONSOLE(SIO_LSTAT) & SIO_LSTAT_RRDY)
return(1);
#ifdef MORE_GOTACHAR
diff --git a/ports/beagleboneblack/am335x.h b/ports/beagleboneblack/am335x.h
index 8e2b910..8768f24 100644
--- a/ports/beagleboneblack/am335x.h
+++ b/ports/beagleboneblack/am335x.h
@@ -250,6 +250,10 @@
/*===========================================================================*/
/* Control Module Registers */
/*===========================================================================*/
+#define CONF_GPMC_A5 0x0854
+#define CONF_GPMC_A6 0x0858
+#define CONF_GPMC_A7 0x085c
+#define CONF_GPMC_A8 0x0860
#define CONF_UART0_RXD 0x0970
#define CONF_UART0_TXD 0x0974
/*===========================================================================*/
diff --git a/ports/beagleboneblack/config.h b/ports/beagleboneblack/config.h
index a64493c..3635dde 100644
--- a/ports/beagleboneblack/config.h
+++ b/ports/beagleboneblack/config.h
@@ -144,9 +144,6 @@
#define ALLOCSIZE 1024 // (64*1024)
#define MONSTACKSIZE (16*1024)
-// Cogent specific options
-#define INCLUDE_I2C 0
-#define INCLUDE_LCD 0
/* Specify inclusion of subsystems within the monitor here.
* Refer to comments in common/monitor/inc_check.h for details on
@@ -195,6 +192,8 @@
#define INCLUDE_TSI 0
#define INCLUDE_SD 0
#define INCLUDE_DNS 0
+#define INCLUDE_BLINKLED 1
+#define TARGET_BLINKLED target_blinkled
/* Inclusion of this next file will make sure that all of the above
* inclusions are legal; and warn/adjust where necessary.
diff --git a/ports/beagleboneblack/cpuio.c b/ports/beagleboneblack/cpuio.c
index 75865e7..d1e8177 100644
--- a/ports/beagleboneblack/cpuio.c
+++ b/ports/beagleboneblack/cpuio.c
@@ -7,6 +7,7 @@
#include "timer.h"
#include "am335x.h"
#include "uart16550.h"
+#include "cli.h"
int
getUartDivisor(int baud, unsigned char *hi, unsigned char *lo)
@@ -137,11 +138,38 @@ ram_vector_install(void)
void
pinMuxInit(void)
{
- // Set pin mux configuration for UART0 RX/TX pins
- CNTL_MODULE_REG(CONF_UART0_RXD) = SLEWSLOW | RX_ON |
- PULL_OFF | MUXMODE_0;
- CNTL_MODULE_REG(CONF_UART0_TXD) = SLEWSLOW | RX_OFF |
- PULL_OFF | MUXMODE_0;
+ // Set pin mux configuration for UART0 RX/TX pins
+ CNTL_MODULE_REG(CONF_UART0_RXD) = SLEWSLOW | RX_ON |
+ PULL_OFF | MUXMODE_0;
+ CNTL_MODULE_REG(CONF_UART0_TXD) = SLEWSLOW | RX_OFF |
+ PULL_OFF | MUXMODE_0;
+
+ // Configure GPIO pins tied to four USR LEDS...
+ // GPIO1_21: USER0 LED (D2)
+ CNTL_MODULE_REG(CONF_GPMC_A5) = SLEWSLOW | RX_ON |
+ PULL_OFF | MUXMODE_7;
+ // GPIO1_22: USER1 LED (D3)
+ CNTL_MODULE_REG(CONF_GPMC_A6) = SLEWSLOW | RX_ON |
+ PULL_OFF | MUXMODE_7;
+ // GPIO1_23: USER2 LED (D4)
+ CNTL_MODULE_REG(CONF_GPMC_A7) = SLEWSLOW | RX_ON |
+ PULL_OFF | MUXMODE_7;
+ // GPIO1_24: USER3 LED (D5)
+ CNTL_MODULE_REG(CONF_GPMC_A8) = SLEWSLOW | RX_ON |
+ PULL_OFF | MUXMODE_7;
+}
+
+void
+InitGPIO1(void)
+{
+ // GPIO_CTRL: Enable GPIO1 module
+ GPIO1_REG(0x130) = 0;
+
+ // GPIO_OE: 25-24 are outputs...
+ GPIO1_REG(0x134) &= ~(USR0_LED | USR1_LED | USR2_LED | USR3_LED);
+
+ // All LEDs off...
+ GPIO1_REG(0x13c) &= ~(USR0_LED | USR1_LED | USR2_LED | USR3_LED);
}
/* If any CPU IO wasn't initialized in reset.S, do it here...
@@ -152,16 +180,88 @@ initCPUio(void)
{
ram_vector_install();
- // Enable the control module:
- CM_WKUP_REG(CM_WKUP_CONTROL_CLKCTRL) |= 2;
+ // Enable the control module:
+ CM_WKUP_REG(CM_WKUP_CONTROL_CLKCTRL) |= 2;
+
+ // Enable clock for UART0:
+ CM_WKUP_REG(CM_WKUP_UART0_CLKCTRL) |= 2;
+
+ // Enable clock for GPIO1:
+ CM_PER_REG(CM_DIV_M3_DPLL_PER) |= 2;
- // Enable clock for UART0:
- CM_WKUP_REG(CM_WKUP_UART0_CLKCTRL) |= 2;
+ pinMuxInit();
- pinMuxInit();
+ InitUART(DEFAULT_BAUD_RATE);
+ InitGPIO1();
+
+ // Set UART0 mode to 16x
+ UART0_REG(UART_MDR1) &= ~7;
+}
+
+int
+led(int num, int on)
+{
+ unsigned long bit;
+
+ switch(num) {
+ case 0: // D0
+ bit = USR0_LED;
+ break;
+ case 1: // D1
+ bit = USR1_LED;
+ break;
+ case 2: // D2
+ bit = USR2_LED;
+ break;
+ case 3: // D3
+ bit = USR3_LED;
+ break;
+ default:
+ return(-1);
+ }
+
+ // GPIO21-24:
+ if (on)
+ GPIO1_REG(0x13c) |= bit;
+ else
+ GPIO1_REG(0x13c) &= ~bit;
+ return(0);
+}
+
+void
+target_blinkled(void)
+{
+#if INCLUDE_BLINKLED
+ static uint8_t ledstate;
+ static struct elapsed_tmr tmr;
- InitUART(DEFAULT_BAUD_RATE);
+#define STATLED_ON() led(0,1)
+#define STATLED_OFF() led(0,0)
+#ifndef BLINKON_MSEC
+#define BLINKON_MSEC 10000
+#define BLINKOFF_MSEC 10000
+#endif
- // Set UART0 mode to 16x
- UART0_REG(UART_MDR1) &= ~7;
+ switch(ledstate) {
+ case 0:
+ startElapsedTimer(&tmr,BLINKON_MSEC);
+ STATLED_ON();
+ ledstate = 1;
+ break;
+ case 1:
+ if(msecElapsed(&tmr)) {
+ STATLED_OFF();
+ ledstate = 2;
+ startElapsedTimer(&tmr,BLINKOFF_MSEC);
+ }
+ break;
+ case 2:
+ if(msecElapsed(&tmr)) {
+ STATLED_ON();
+ ledstate = 1;
+ startElapsedTimer(&tmr,BLINKON_MSEC);
+ }
+ break;
+ }
+#endif
}
diff --git a/ports/beagleboneblack/cpuio.h b/ports/beagleboneblack/cpuio.h
index 2ae9891..d1c4fd7 100644
--- a/ports/beagleboneblack/cpuio.h
+++ b/ports/beagleboneblack/cpuio.h
@@ -1 +1,22 @@
#define DEFAULT_BAUD_RATE 115200
+
+#define HWREAD32(a) *(volatile unsigned long *)(a)
+#define HWREAD16(a) *(volatile unsigned short *)(a)
+#define HWREAD8(a) *(volatile unsigned char *)(a)
+
+#define HWWRITE32(a,b) *(volatile unsigned long *)(a) = (b)
+#define HWWRITE16(a,b) *(volatile unsigned short *)(a) = (b)
+#define HWWRITE8(a,b) *(volatile unsigned char *)(a) = (b)
+
+#define GPIO1_21 (1<<21)
+#define GPIO1_22 (1<<22)
+#define GPIO1_23 (1<<23)
+#define GPIO1_24 (1<<24)
+
+// Referring to BBB schematic...
+// Pg6 shows the 4 user leds, pg3 shows the pins on the Sitara
+// The four user leds are on GPIO1, pins 21-24
+#define USR0_LED GPIO1_21 // Ball V15: GPMC_A5 mode7 (D2)
+#define USR1_LED GPIO1_22 // Ball U15: GPMC_A6 mode7 (D3)
+#define USR2_LED GPIO1_23 // Ball T15: GPMC_A7 mode7 (D4)
+#define USR3_LED GPIO1_24 // Ball V16: GPMC_A8 mode7 (D5)
diff --git a/ports/beagleboneblack/xcmdtbl.h b/ports/beagleboneblack/xcmdtbl.h
index 120957e..488ddef 100644
--- a/ports/beagleboneblack/xcmdtbl.h
+++ b/ports/beagleboneblack/xcmdtbl.h
@@ -6,5 +6,5 @@
/* It is the entry in the command table representing the new command being */
/* added to the cmdtbl[] array. */
/* For example:
- "dummy", dummycmd, dummyHelp,
+ { "dummy", dummycmd, dummyHelp, 0 },
*/