unify the "systems" functionality. Also, make the embeddedlinux tool more versatile.

This commit is contained in:
cnlohr 2015-07-23 00:52:52 -04:00
parent f1a75267fb
commit ca4c90b1a8
7 changed files with 224 additions and 75 deletions

View file

@ -14,7 +14,10 @@
#define NUM_LIN_LEDS 296
#endif
#define LIN_WRAPAROUND 0 //Whether the output lights wrap around.
#ifndef LIN_WRAPAROUND
#define LIN_WRAPAROUND 0 //Whether the output lights wrap around. (Can't easily run on embedded systems)
#endif
#define SORT_NOTES 0 //Whether the notes will be sorted.
extern uint8_t ledArray[];

View file

@ -1,13 +1,13 @@
all : embeddedcc
CFLAGS:=-Ofast -DCCEMBEDDED -I.. -flto -m32 -DDFREQ=11025 -I../embeddedcommon
CFLAGS:=-Ofast -DCCEMBEDDED -I.. -flto -m32 -DDFREQ=11025 -I../embeddedcommon -DNUM_LIN_LEDS=20
LDFLAGS:=-ffunction-sections -Wl,--gc-sections -fno-asynchronous-unwind-tables -Wl,--strip-all
embeddedcc : ../embeddedcommon/embeddednf.c ../embeddedcommon/DFT32.c embeddedcc.c ../embeddedcommon/embeddedout.c
gcc -o $@ $^ $(CFLAGS) $(LDFLAGS)
runembedded : embeddedcc
parec --format=u8 --rate=11025 --channels=1 --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor --latency=128 | ./embeddedcc
parec --format=u8 --rate=11025 --channels=1 --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor --latency=128 | ./embeddedcc 192.168.4.1 0
clean :
rm -rf embeddedcc *~

View file

@ -14,7 +14,9 @@
struct sockaddr_in servaddr;
int sock;
#define expected_lights 296
#define expected_lights NUM_LIN_LEDS
int toskip = 1;
void NewFrame()
{
@ -30,24 +32,32 @@ void NewFrame()
for( i = 0; i < expected_lights * 3; i++ )
{
buffer[i+3] = ledOut[i];
buffer[i+toskip*3] = ledOut[i];
}
int r = send(sock,buffer,expected_lights*3+3,0);
}
int main()
int main( int argc, char ** argv )
{
int wf = 0;
int ci;
if( argc < 2 )
{
fprintf( stderr, "Error: usage: [tool] [ip address] [num to skip, default 0]\n" );
return -1;
}
printf( "%d\n", argc );
toskip = (argc > 2)?atoi(argv[2]):0;
sock = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
printf( "%d\n", sock );
memset(&servaddr,0,sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("192.168.0.245");
servaddr.sin_addr.s_addr = inet_addr(argv[1]);
servaddr.sin_port=htons(7777);
connect( sock, (struct sockaddr *)&servaddr, sizeof(servaddr) );

View file

@ -1,9 +1,15 @@
#include <stdint.h>
#include "systems.h"
#include <string.h>
#ifdef STM32F30X
#include <stm32f30x.h>
#include <stm32f30x_rcc.h>
#include <stm32f30x_gpio.h>
#elif defined( STM32F40_41xxx )
#include <stm32f4xx.h>
#include <stm32f4xx_rcc.h>
#include <stm32f4xx_gpio.h>
#endif
#include <core_cm4.h>
#include <core_cmFunc.h>
@ -72,7 +78,7 @@ void _delay_us(uint32_t us) {
void ConfigureLED()
{
ConfigureGPIO( GetGPIOFromString( "PB8" ), INOUT_OUT );
ConfigureGPIO( LEDPIN, INOUT_OUT );
}
uint8_t GetGPIOFromString( const char * str )
@ -135,6 +141,8 @@ void ConfigureGPIO( uint8_t gpio, int parameters )
{
GPIO_InitTypeDef GPIO_InitStructure;
#ifdef STM32F30X
/* Enable the GPIO_LED Clock */
RCC_AHBPeriphClockCmd( 1<<(17+(gpio>>4)), ENABLE);
@ -153,6 +161,32 @@ void ConfigureGPIO( uint8_t gpio, int parameters )
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = (parameters&PUPD_FLAG)?( (parameters&PUPD_UP)?GPIO_PuPd_UP:GPIO_PuPd_DOWN ):GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_Init(GPIOOf(gpio), &GPIO_InitStructure);
#elif defined( STM32F40_41xxx )
/* Enable the GPIO_LED Clock */
RCC_AHB1PeriphClockCmd( 1<<((gpio>>4)), ENABLE);
if( parameters & DEFAULT_VALUE_FLAG )
{
GPIOOn( gpio );
}
else
{
GPIOOff( gpio );
}
/* Configure the GPIO_LED pin */
GPIO_InitStructure.GPIO_Pin = 1<<(gpio&0xf);
GPIO_InitStructure.GPIO_Mode = (parameters&INOUT_FLAG)?GPIO_Mode_OUT:GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = (parameters&PUPD_FLAG)?( (parameters&PUPD_UP)?GPIO_PuPd_UP:GPIO_PuPd_DOWN ):GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOOf(gpio), &GPIO_InitStructure);
#endif
}

View file

@ -26,18 +26,38 @@ gpio GetGPIOFromString( const char * str );
void ConfigureGPIO( gpio gpio, int parameters );
#ifdef STM32F30X
#define GPIOOf(x) ((GPIO_TypeDef *) ((((x)>>4)<=6)?(AHB2PERIPH_BASE+0x400*((x)>>4)):0x60000000) )
#elif defined( STM32F40_41xxx )
#define GPIOOf(x) ((GPIO_TypeDef *) ((((x)>>4)<=6)?(AHB1PERIPH_BASE+0x400*((x)>>4)):0x60000000) )
#endif
#define GPIOPin(x) ((1<<((x)&0x0f)))
#define GPIOLatch(x) GPIOOf(x)->ODR
#define GPIOOff(x) GPIOOf(x)->BRR = (1<<((x)&0x0f));
#define GPIOOn(x) GPIOOf(x)->BSRR = (1<<((x)&0x0f));
#ifdef STM32F30X
#define GPIOOn(x) GPIOOf(x)->BSRR = (1<<((x)&0x0f));
#define GPIOOff(x) GPIOOf(x)->BRR = (1<<((x)&0x0f));
#elif defined( STM32F40_41xxx )
#define GPIOOn(x) GPIOOf(x)->BSRRH = (1<<((x)&0x0f));
#define GPIOOff(x) GPIOOf(x)->BSRRL = (1<<((x)&0x0f));
#endif
#ifdef STM32F30X
#define LEDPIN 0x18
#elif defined( STM32F40_41xxx )
#define LEDPIN 0x3f
#endif
void ConfigureLED();
#define LED_TOGGLE {GPIOB->ODR ^= GPIO_Pin_8;}
#define LED_ON {GPIOB->BSRR ^= GPIO_Pin_8;}
#define LED_OFF {GPIOB->BRR ^= GPIO_Pin_8;}
//General notes:
#define LED_TOGGLE {GPIOOf(LEDPIN)->ODR^=(1<<((LEDPIN)&0x0f));}
#define LED_ON GPIOOn(LEDPIN)
#define LED_OFF GPIOOff(LEDPIN)
#endif

View file

@ -1,8 +1,15 @@
#include <stdint.h>
#include "systems.h"
#include <string.h>
#ifdef STM32F30X
#include <stm32f30x.h>
#include <stm32f30x_rcc.h>
#include <stm32f30x_gpio.h>
#elif defined( STM32F40_41xxx )
#include <stm32f4xx.h>
#include <stm32f4xx_rcc.h>
#include <stm32f4xx_gpio.h>
#endif
#include <core_cm4.h>
#include <core_cmFunc.h>
@ -32,13 +39,13 @@ void send_text( const char * text )
send_openocd_command(0x05, m);
}
int _write (int fd, const void *buf, size_t count)
int __attribute__((used)) _write (int fd, const void *buf, size_t count)
{
uint32_t m[] = { 2, (uint32_t)buf, count };
send_openocd_command(0x05, m);
}
void * _sbrk(int incr) {
void __attribute__((used)) * _sbrk(int incr) {
extern char _ebss; // Defined by the linker
static char *heap_end;
char *prev_heap_end;
@ -71,32 +78,97 @@ void _delay_us(uint32_t us) {
void ConfigureLED()
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable the GPIO_LED Clock */
ConfigureGPIO( LEDPIN, INOUT_OUT );
}
#ifdef STM32F30X
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
uint8_t GetGPIOFromString( const char * str )
{
int mode = 0;
int port = -1;
int pin = -1;
const char * st = str;
for( ; *st; st++ )
{
char c = *st;
if( mode == 0 )
{
if( c >= 'A' && c <= 'F' )
{
port = c - 'A';
mode = 2;
}
else if( c >= 'a' && c <= 'f' )
{
port = c - 'a';
mode = 2;
}
}
else if( mode == 2 )
{
if( c >= '0' && c <= '9' )
{
pin = 0;
mode = 3;
}
}
/* Configure the GPIO_LED pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //| GPIO_Pin_15 (15 = CTS)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
#elif defined( STM32F40_41xxx )
RCC_AHB1PeriphClockCmd( LED_AHB_PORT, ENABLE);
/* Configure the GPIO_LED pin */
GPIO_InitStructure.GPIO_Pin = (1<<LEDPIN);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(LEDPORT, &GPIO_InitStructure);
#endif
if( mode == 3 )
{
if( c >= '0' && c <= '9' )
{
pin = pin * 10;
pin+= c - '0';
}
else
{
break;
}
}
}
if( port > 0 && pin > 0 && port <= 6 && pin <= 15)
{
return (port<<4)|pin;
}
else
{
return 0xff;
}
}
void ConfigureGPIO( uint8_t gpio, int parameters )
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable the GPIO_LED Clock */
#ifdef STM32F30X
RCC_AHBPeriphClockCmd( 1<<(17+(gpio>>4)), ENABLE);
#elif defined( STM32F40_41xxx )
RCC_AHB1PeriphClockCmd( 1<<((gpio>>4)), ENABLE);
#endif
if( parameters & DEFAULT_VALUE_FLAG )
{
GPIOOn( gpio );
}
else
{
GPIOOff( gpio );
}
/* Configure the GPIO_LED pin */
GPIO_InitStructure.GPIO_Pin = 1<<(gpio&0xf);
GPIO_InitStructure.GPIO_Mode = (parameters&INOUT_FLAG)?GPIO_Mode_OUT:GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = (parameters&PUPD_FLAG)?( (parameters&PUPD_UP)?GPIO_PuPd_UP:GPIO_PuPd_DOWN ):GPIO_PuPd_NOPULL;
#ifdef STM32F30X
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
#elif defined( STM32F40_41xxx )
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
#endif
GPIO_Init(GPIOOf(gpio), &GPIO_InitStructure);
}

View file

@ -1,53 +1,63 @@
#ifndef _SYSTEMS_H
#define _SYSTEMS_H
#ifdef STM32F30X
#include <stm32f30x.h>
#include <stm32f30x_rcc.h>
#include <stm32f30x_gpio.h>
#define LEDPORT GPIOB
#define LEDPIN 8
#elif defined( STM32F40_41xxx )
#include <stm32f4xx.h>
#include <stm32f4xx_rcc.h>
#include <stm32f4xx_gpio.h>
#define LED_AHB_PORT RCC_AHB1Periph_GPIOD
#define LEDPORT GPIOD
#define LEDPIN 15
#else
#error Unsupported device.
#endif
void send_openocd_command(int command, void *message);
void send_text( const char * text );
void _delay_us(uint32_t us);
void ConfigureLED();
typedef uint8_t gpio;
gpio GetGPIOFromString( const char * str );
#define LED_TOGGLE {LEDPORT->ODR ^= (1<<LEDPIN);}
#define DEFAULT_VALUE_FLAG 0x00000001
#define DEFAULT_ON 0x00000001
#define DEFAULT_OFF 0x00000000
#ifdef STM32F30X
#define INOUT_FLAG 0x00000002
#define INOUT_OUT 0x00000002
#define INOUT_IN 0x00000000
#define LED_ON {LEDPORT->BSRR = (1<<LEDPIN);}
#define LED_OFF {LEDPORT->BRR = (1<<LEDPIN);}
#define PUPD_FLAG 0x0000000C
#define PUPD_NONE 0x00000000
#define PUPD_UP 0x00000004
#define PUPD_DOWN 0x00000008
void ConfigureGPIO( gpio gpio, int parameters );
#ifdef STM32F30X
#define GPIOOf(x) ((GPIO_TypeDef *) ((((x)>>4)<=6)?(AHB2PERIPH_BASE+0x400*((x)>>4)):0x60000000) )
#elif defined( STM32F40_41xxx )
#define GPIOOf(x) ((GPIO_TypeDef *) ((((x)>>4)<=6)?(AHB1PERIPH_BASE+0x400*((x)>>4)):0x60000000) )
#endif
#define LED_ON {LEDPORT->BSRRL = (1<<LEDPIN);}
#define LED_OFF {LEDPORT->BSRRH = (1<<LEDPIN);}
#define GPIOPin(x) ((1<<((x)&0x0f)))
#define GPIOLatch(x) GPIOOf(x)->ODR
#ifdef STM32F30X
#define GPIOOn(x) GPIOOf(x)->BSRR = (1<<((x)&0x0f));
#define GPIOOff(x) GPIOOf(x)->BRR = (1<<((x)&0x0f));
#elif defined( STM32F40_41xxx )
#define GPIOOn(x) GPIOOf(x)->BSRRH = (1<<((x)&0x0f));
#define GPIOOff(x) GPIOOf(x)->BSRRL = (1<<((x)&0x0f));
#endif
//General notes:
#ifdef STM32F30X
#define LEDPIN 0x18
#elif defined( STM32F40_41xxx )
#define LEDPIN 0x3f
#endif
void ConfigureLED();
#define LED_TOGGLE {GPIOOf(LEDPIN)->ODR^=(1<<((LEDPIN)&0x0f));}
#define LED_ON GPIOOn(LEDPIN)
#define LED_OFF GPIOOff(LEDPIN)
#endif