[stm32f429-discovery] General sweep to fix style according to make stylecheck.
This commit is contained in:
@@ -33,18 +33,21 @@
|
||||
static volatile uint32_t system_millis;
|
||||
|
||||
/* Called when systick fires */
|
||||
void sys_tick_handler(void) {
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
system_millis++;
|
||||
}
|
||||
|
||||
/* simple sleep for delay milliseconds */
|
||||
void msleep(uint32_t delay) {
|
||||
void msleep(uint32_t delay)
|
||||
{
|
||||
uint32_t wake = system_millis + delay;
|
||||
while (wake > system_millis) ;
|
||||
while (wake > system_millis);
|
||||
}
|
||||
|
||||
/* Getter function for the current time */
|
||||
uint32_t mtime(void) {
|
||||
uint32_t mtime(void)
|
||||
{
|
||||
return system_millis;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,29 +37,26 @@
|
||||
#include <libopencm3/cm3/cortex.h>
|
||||
#include "console.h"
|
||||
|
||||
|
||||
/*
|
||||
* Some definitions of our console "functions" attached to the
|
||||
* Some definitions of our console "functions" attached to the
|
||||
* USART.
|
||||
*
|
||||
* These define sort of the minimum "library" of functions which
|
||||
* we can use on a serial port.
|
||||
*/
|
||||
|
||||
|
||||
#define CONSOLE_UART USART1
|
||||
|
||||
|
||||
/* This is a ring buffer to holding characters as they are typed
|
||||
* it maintains both the place to put the next character received
|
||||
* from the UART, and the place where the last character was
|
||||
* read by the program. See the README file for a discussion of
|
||||
* the failure semantics.
|
||||
*/
|
||||
#define RECV_BUF_SIZE 128 // Arbitrary buffer size
|
||||
#define RECV_BUF_SIZE 128 /* Arbitrary buffer size */
|
||||
char recv_buf[RECV_BUF_SIZE];
|
||||
volatile int recv_ndx_nxt; // Next place to store
|
||||
volatile int recv_ndx_cur; // Next place to read
|
||||
volatile int recv_ndx_nxt; /* Next place to store */
|
||||
volatile int recv_ndx_cur; /* Next place to read */
|
||||
|
||||
/* For interrupt handling we add a new function which is called
|
||||
* when recieve interrupts happen. The name (usart1_isr) is created
|
||||
@@ -72,7 +69,8 @@ volatile int recv_ndx_cur; // Next place to read
|
||||
* right or it won't work. And you'll wonder where your interrupts
|
||||
* are going.
|
||||
*/
|
||||
void usart1_isr(void) {
|
||||
void usart1_isr(void)
|
||||
{
|
||||
uint32_t reg;
|
||||
int i;
|
||||
|
||||
@@ -84,10 +82,13 @@ void usart1_isr(void) {
|
||||
/* Check for "reset" */
|
||||
if (recv_buf[recv_ndx_nxt] == '\003') {
|
||||
/* reset the system */
|
||||
volatile uint32_t *ret = (®) + 7; // Return address on stack
|
||||
|
||||
*ret = (uint32_t) &reset_handler; // force system reset
|
||||
return; // go to new address
|
||||
/* Return address on stack */
|
||||
volatile uint32_t *ret = (®) + 7;
|
||||
|
||||
/* force system reset */
|
||||
*ret = (uint32_t) &reset_handler;
|
||||
/* go to new address */
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
/* Check for "overrun" */
|
||||
@@ -96,7 +97,8 @@ void usart1_isr(void) {
|
||||
recv_ndx_nxt = i;
|
||||
}
|
||||
}
|
||||
} while ((reg & USART_SR_RXNE) != 0); // can read back-to-back interrupts
|
||||
/* can read back-to-back interrupts */
|
||||
} while ((reg & USART_SR_RXNE) != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -105,7 +107,8 @@ void usart1_isr(void) {
|
||||
* Send the character 'c' to the USART, wait for the USART
|
||||
* transmit buffer to be empty first.
|
||||
*/
|
||||
void console_putc(char c) {
|
||||
void console_putc(char c)
|
||||
{
|
||||
uint32_t reg;
|
||||
do {
|
||||
reg = USART_SR(CONSOLE_UART);
|
||||
@@ -123,10 +126,11 @@ void console_putc(char c) {
|
||||
* The implementation is a bit different however, now it looks
|
||||
* in the ring buffer to see if a character has arrived.
|
||||
*/
|
||||
char console_getc(int wait) {
|
||||
char console_getc(int wait)
|
||||
{
|
||||
char c = 0;
|
||||
|
||||
while ((wait != 0) && (recv_ndx_cur == recv_ndx_nxt)) ;
|
||||
while ((wait != 0) && (recv_ndx_cur == recv_ndx_nxt));
|
||||
if (recv_ndx_cur != recv_ndx_nxt) {
|
||||
c = recv_buf[recv_ndx_cur];
|
||||
recv_ndx_cur = (recv_ndx_cur + 1) % RECV_BUF_SIZE;
|
||||
@@ -141,7 +145,8 @@ char console_getc(int wait) {
|
||||
* after the last character, as indicated by a NUL character, is
|
||||
* reached.
|
||||
*/
|
||||
void console_puts(char *s) {
|
||||
void console_puts(char *s)
|
||||
{
|
||||
while (*s != '\000') {
|
||||
console_putc(*s);
|
||||
/* Add in a carraige return, after sending line feed */
|
||||
@@ -159,7 +164,8 @@ void console_puts(char *s) {
|
||||
* support for editing characters (back space and delete)
|
||||
* end when a <CR> character is received.
|
||||
*/
|
||||
int console_gets(char *s, int len) {
|
||||
int console_gets(char *s, int len)
|
||||
{
|
||||
char *t = s;
|
||||
char c;
|
||||
|
||||
@@ -182,7 +188,7 @@ int console_gets(char *s, int len) {
|
||||
/* update end of string with NUL */
|
||||
*t = '\000';
|
||||
}
|
||||
return (t - s);
|
||||
return t - s;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -190,7 +196,8 @@ int console_gets(char *s, int len) {
|
||||
* on some of the pins, in this case connected to a
|
||||
* USART.
|
||||
*/
|
||||
void console_setup(void) {
|
||||
void console_setup(void)
|
||||
{
|
||||
|
||||
/* MUST enable the GPIO clock in ADDITION to the USART clock */
|
||||
rcc_periph_clock_enable(RCC_GPIOA);
|
||||
|
||||
@@ -49,7 +49,7 @@ static struct {
|
||||
GPIO11 | GPIO12 | GPIO13 | GPIO14 | GPIO15 },
|
||||
{GPIOF, GPIO0 | GPIO1 | GPIO2 | GPIO3 | GPIO4 | GPIO5 | GPIO11 |
|
||||
GPIO12 | GPIO13 | GPIO14 | GPIO15 },
|
||||
{GPIOG, GPIO0 | GPIO1 | GPIO4 | GPIO5 |GPIO8 | GPIO15}
|
||||
{GPIOG, GPIO0 | GPIO1 | GPIO4 | GPIO5 | GPIO8 | GPIO15}
|
||||
};
|
||||
|
||||
static struct sdram_timing timing = {
|
||||
@@ -66,9 +66,10 @@ static struct sdram_timing timing = {
|
||||
* Initialize the SD RAM controller.
|
||||
*/
|
||||
void
|
||||
sdram_init(void) {
|
||||
sdram_init(void)
|
||||
{
|
||||
int i;
|
||||
uint32_t cr_tmp, tr_tmp; // control, timing registers
|
||||
uint32_t cr_tmp, tr_tmp; /* control, timing registers */
|
||||
|
||||
/*
|
||||
* First all the GPIO pins that end up as SDRAM pins
|
||||
@@ -81,15 +82,15 @@ sdram_init(void) {
|
||||
rcc_periph_clock_enable(RCC_GPIOG);
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
gpio_mode_setup(sdram_pins[i].gpio, GPIO_MODE_AF, GPIO_PUPD_NONE,
|
||||
sdram_pins[i].pins);
|
||||
gpio_mode_setup(sdram_pins[i].gpio, GPIO_MODE_AF,
|
||||
GPIO_PUPD_NONE, sdram_pins[i].pins);
|
||||
gpio_set_output_options(sdram_pins[i].gpio, GPIO_OTYPE_PP,
|
||||
GPIO_OSPEED_50MHZ, sdram_pins[i].pins);
|
||||
GPIO_OSPEED_50MHZ, sdram_pins[i].pins);
|
||||
gpio_set_af(sdram_pins[i].gpio, GPIO_AF12, sdram_pins[i].pins);
|
||||
}
|
||||
|
||||
/* Enable the SDRAM Controller */
|
||||
rcc_periph_clock_enable(RCC_FSMC);
|
||||
rcc_periph_clock_enable(RCC_FSMC);
|
||||
|
||||
/* Note the STM32F429-DISCO board has the ram attached to bank 2 */
|
||||
/* Timing parameters computed for a 168Mhz clock */
|
||||
@@ -109,7 +110,7 @@ sdram_init(void) {
|
||||
*/
|
||||
FMC_SDCR1 |= (cr_tmp & FMC_SDCR_DNC_MASK);
|
||||
FMC_SDCR2 = cr_tmp;
|
||||
|
||||
|
||||
tr_tmp = sdram_timing(&timing);
|
||||
FMC_SDTR1 |= (tr_tmp & FMC_SDTR_DNC_MASK);
|
||||
FMC_SDTR2 = tr_tmp;
|
||||
@@ -121,12 +122,12 @@ sdram_init(void) {
|
||||
* - Load the Mode Register
|
||||
*/
|
||||
sdram_command(SDRAM_BANK2, SDRAM_CLK_CONF, 1, 0);
|
||||
msleep(1); // sleep at least 100uS
|
||||
msleep(1); /* sleep at least 100uS */
|
||||
sdram_command(SDRAM_BANK2, SDRAM_PALL, 1, 0);
|
||||
sdram_command(SDRAM_BANK2, SDRAM_AUTO_REFRESH, 4, 0);
|
||||
tr_tmp = SDRAM_MODE_BURST_LENGTH_2 |
|
||||
SDRAM_MODE_BURST_TYPE_SEQUENTIAL |
|
||||
SDRAM_MODE_CAS_LATENCY_3 |
|
||||
SDRAM_MODE_CAS_LATENCY_3 |
|
||||
SDRAM_MODE_OPERATING_MODE_STANDARD |
|
||||
SDRAM_MODE_WRITEBURST_MODE_SINGLE;
|
||||
sdram_command(SDRAM_BANK2, SDRAM_LOAD_MODE, 1, tr_tmp);
|
||||
@@ -154,13 +155,15 @@ uint8_t *dump_page(uint8_t *, uint8_t *);
|
||||
#define HEX_CHAR(x) ((((x) + '0') > '9') ? ((x) + '7') : ((x) + '0'))
|
||||
|
||||
/* send an 8 bit byte as two HEX characters to the console */
|
||||
void dump_byte(uint8_t b) {
|
||||
void dump_byte(uint8_t b)
|
||||
{
|
||||
console_putc(HEX_CHAR((b >> 4) & 0xf));
|
||||
console_putc(HEX_CHAR(b & 0xf));
|
||||
}
|
||||
|
||||
/* send a 32 bit value as 8 hex characters to the console */
|
||||
void dump_long(uint32_t l) {
|
||||
void dump_long(uint32_t l)
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < 8; i++) {
|
||||
console_putc(HEX_CHAR((l >> (28 - i * 4)) & 0xf));
|
||||
@@ -177,7 +180,8 @@ void dump_long(uint32_t l) {
|
||||
* next 16 bytes out.
|
||||
*/
|
||||
uint8_t *
|
||||
dump_line(uint8_t *addr, uint8_t *base) {
|
||||
dump_line(uint8_t *addr, uint8_t *base)
|
||||
{
|
||||
uint8_t *line_addr;
|
||||
uint8_t b;
|
||||
uint32_t tmp;
|
||||
@@ -211,7 +215,8 @@ dump_line(uint8_t *addr, uint8_t *base) {
|
||||
* on the screen with some other information.
|
||||
*/
|
||||
uint8_t *
|
||||
dump_page(uint8_t *addr, uint8_t *base) {
|
||||
dump_page(uint8_t *addr, uint8_t *base)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 16; i++) {
|
||||
addr = dump_line(addr, base);
|
||||
@@ -227,7 +232,8 @@ dump_page(uint8_t *addr, uint8_t *base) {
|
||||
* (PL) previous line, and (?) for help.
|
||||
*/
|
||||
int
|
||||
main(void) {
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
uint8_t *addr;
|
||||
char c;
|
||||
@@ -246,93 +252,93 @@ main(void) {
|
||||
}
|
||||
console_puts("Modified data (with Fill Increment)\n");
|
||||
addr = SDRAM_BASE_ADDRESS;
|
||||
addr = dump_page( addr, NULL);
|
||||
addr = dump_page(addr, NULL);
|
||||
while (1) {
|
||||
console_puts("CMD> ");
|
||||
switch (c = console_getc(1)) {
|
||||
case 'f':
|
||||
case 'F':
|
||||
console_puts("Fill ");
|
||||
switch (c = console_getc(1)) {
|
||||
case 'i':
|
||||
case 'I':
|
||||
console_puts("Increment\n");
|
||||
for (i = 0; i < 256; i++) {
|
||||
*(addr+i) = i;
|
||||
}
|
||||
dump_page(addr, NULL);
|
||||
break;
|
||||
case '0':
|
||||
console_puts("Zero\n");
|
||||
for (i = 0; i < 256; i++) {
|
||||
*(addr+i) = 0;
|
||||
}
|
||||
dump_page(addr, NULL);
|
||||
break;
|
||||
case 'f':
|
||||
case 'F':
|
||||
console_puts("Fill ");
|
||||
switch (c = console_getc(1)) {
|
||||
case 'i':
|
||||
case 'I':
|
||||
console_puts("Increment\n");
|
||||
for (i = 0; i < 256; i++) {
|
||||
*(addr+i) = i;
|
||||
}
|
||||
dump_page(addr, NULL);
|
||||
break;
|
||||
case '0':
|
||||
console_puts("Zero\n");
|
||||
for (i = 0; i < 256; i++) {
|
||||
*(addr+i) = 0;
|
||||
}
|
||||
dump_page(addr, NULL);
|
||||
break;
|
||||
case 'f':
|
||||
case 'F':
|
||||
console_puts("Ones (0xff)\n");
|
||||
for (i = 0; i < 256; i++) {
|
||||
*(addr+i) = 0xff;
|
||||
}
|
||||
dump_page(addr, NULL);
|
||||
break;
|
||||
default:
|
||||
console_puts("Unrecognized Command, press ? for help\n");
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
case 'N':
|
||||
console_puts("Next ");
|
||||
switch (c = console_getc(1)) {
|
||||
case 'p':
|
||||
case 'P':
|
||||
console_puts("Page\n");
|
||||
addr += 256;
|
||||
dump_page(addr, NULL);
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
console_puts("Line\n");
|
||||
addr += 16;
|
||||
dump_line(addr, NULL);
|
||||
break;
|
||||
default:
|
||||
console_puts("Unrecognized Command, press ? for help\n");
|
||||
console_puts("Ones (0xff)\n");
|
||||
for (i = 0; i < 256; i++) {
|
||||
*(addr+i) = 0xff;
|
||||
}
|
||||
dump_page(addr, NULL);
|
||||
break;
|
||||
default:
|
||||
console_puts("Unrecognized Command, press ? for help\n");
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
case 'N':
|
||||
console_puts("Next ");
|
||||
switch (c = console_getc(1)) {
|
||||
case 'p':
|
||||
case 'P':
|
||||
console_puts("Previous ");
|
||||
switch (c = console_getc(1)) {
|
||||
case 'p':
|
||||
case 'P':
|
||||
console_puts("Page\n");
|
||||
addr -= 256;
|
||||
dump_page(addr, NULL);
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
console_puts("Line\n");
|
||||
addr -= 16;
|
||||
dump_line(addr, NULL);
|
||||
break;
|
||||
default:
|
||||
console_puts("Unrecognized Command, press ? for help\n");
|
||||
}
|
||||
console_puts("Page\n");
|
||||
addr += 256;
|
||||
dump_page(addr, NULL);
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
console_puts("Line\n");
|
||||
addr += 16;
|
||||
dump_line(addr, NULL);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
console_puts("Help\n");
|
||||
console_puts(" n p - dump next page\n");
|
||||
console_puts(" n l - dump next line\n");
|
||||
console_puts(" p p - dump previous page\n");
|
||||
console_puts(" p l - dump previous line\n");
|
||||
console_puts(" f 0 - fill current page with 0\n");
|
||||
console_puts(" f i - fill current page with 0 to 255\n");
|
||||
console_puts(" f f - fill current page with 0xff\n");
|
||||
console_puts(" ? - this message\n");
|
||||
console_puts("Unrecognized Command, press ? for help\n");
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
console_puts("Previous ");
|
||||
switch (c = console_getc(1)) {
|
||||
case 'p':
|
||||
case 'P':
|
||||
console_puts("Page\n");
|
||||
addr -= 256;
|
||||
dump_page(addr, NULL);
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
console_puts("Line\n");
|
||||
addr -= 16;
|
||||
dump_line(addr, NULL);
|
||||
break;
|
||||
default:
|
||||
console_puts("Unrecognized Command, press ? for help\n");
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
console_puts("Help\n");
|
||||
console_puts(" n p - dump next page\n");
|
||||
console_puts(" n l - dump next line\n");
|
||||
console_puts(" p p - dump previous page\n");
|
||||
console_puts(" p l - dump previous line\n");
|
||||
console_puts(" f 0 - fill current page with 0\n");
|
||||
console_puts(" f i - fill current page with 0 to 255\n");
|
||||
console_puts(" f f - fill current page with 0xff\n");
|
||||
console_puts(" ? - this message\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user