clean up + Add utilities to the system.c/.h

+Fix filter
This commit is contained in:
cnlohr 2015-07-22 09:12:21 -04:00
parent 560db48adf
commit f1a75267fb
10 changed files with 150 additions and 72 deletions

View file

@ -43,6 +43,7 @@ SECTIONS
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH

View file

@ -33,13 +33,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,17 +71,87 @@ void _delay_us(uint32_t us) {
}
void ConfigureLED()
{
ConfigureGPIO( GetGPIOFromString( "PB8" ), INOUT_OUT );
}
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;
}
}
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 */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_AHBPeriphClockCmd( 1<<(17+(gpio>>4)), ENABLE);
if( parameters & DEFAULT_VALUE_FLAG )
{
GPIOOn( gpio );
}
else
{
GPIOOff( gpio );
}
/* 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_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 = GPIO_PuPd_UP;
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);
}

View file

@ -5,6 +5,34 @@ void send_openocd_command(int command, void *message);
void send_text( const char * text );
void _delay_us(uint32_t us);
typedef uint8_t gpio;
gpio GetGPIOFromString( const char * str );
#define DEFAULT_VALUE_FLAG 0x00000001
#define DEFAULT_ON 0x00000001
#define DEFAULT_OFF 0x00000000
#define INOUT_FLAG 0x00000002
#define INOUT_OUT 0x00000002
#define INOUT_IN 0x00000000
#define PUPD_FLAG 0x0000000C
#define PUPD_NONE 0x00000000
#define PUPD_UP 0x00000004
#define PUPD_DOWN 0x00000008
void ConfigureGPIO( gpio gpio, int parameters );
#define GPIOOf(x) ((GPIO_TypeDef *) ((((x)>>4)<=6)?(AHB2PERIPH_BASE+0x400*((x)>>4)):0x60000000) )
#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));
void ConfigureLED();
#define LED_TOGGLE {GPIOB->ODR ^= GPIO_Pin_8;}
#define LED_ON {GPIOB->BSRR ^= GPIO_Pin_8;}