Skip to content
Permalink
Browse files

stability improvements

  • Loading branch information
scanner-darkly committed Jun 12, 2017
1 parent c594713 commit 9adf6b79d34814f9cfb7aeaf2a08542f98b94db9
@@ -5,7 +5,7 @@
//====== IRQ priorities
#define SYS_IRQ_PRIORITY 1
#define APP_TC_IRQ_PRIORITY 2
#define UI_IRQ_PRIORITY 3
#define UI_IRQ_PRIORITY 1

//==============================================
//==== timers
@@ -169,7 +169,7 @@
#define TWI_DATA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
#define TWI_CLOCK_PIN AVR32_TWI_SCL_0_0_PIN
#define TWI_CLOCK_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
#define TWI_SPEED 132000;
#define TWI_SPEED 100000;

#define MOD_TELETYPE

@@ -160,7 +160,7 @@
#define TWI_DATA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
#define TWI_CLOCK_PIN AVR32_TWI_SCL_0_0_PIN
#define TWI_CLOCK_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
#define TWI_SPEED 132000
#define TWI_SPEED 100000

#define MOD_TRILOGY

@@ -9,6 +9,7 @@
#include "events.h"
#include "types.h"
#include "adc.h"
#include "interrupts.h"

// ad7923 control register
#define AD7923_CTL_WRITE (1 << 11)
@@ -40,6 +41,8 @@
void adc_convert(U16 (*dst)[4]) {
U16 cmd, val;

u8 irq_flags = irqs_pause();

// data into AD7923 is a left-justified 12-bit value in a 16-bit word
// so, always lshift the command before sending
cmd = ( AD7923_CMD_BASE ) << 4;
@@ -79,6 +82,7 @@ void adc_convert(U16 (*dst)[4]) {
spi_unselectChip(ADC_SPI, ADC_SPI_NPCS);
(*dst)[3] = val & 0xfff;

irqs_resume(irq_flags);
}

// setup ad7923
@@ -7,7 +7,7 @@

#include "euclidean/euclidean.h"

#include "conf_tc_irq.h"
#include "interrupts.h"

// this
#include "arp.h"
@@ -132,16 +132,16 @@ void arp_seq_init(arp_seq_t* s) {
}

bool arp_seq_set_state(arp_seq_t *s, arp_seq_state state) {
bool result = false;
// disable timer interrupts
u8 irq_flags = irqs_pause();

// disable timer interrupts
timers_pause();
bool result = false;

s->state = state;
result = true;

// enable timer interrupts
timers_resume();
// enable timer interrupts
irqs_resume(irq_flags);

return result;
}
@@ -5,7 +5,7 @@
#include "dac.h"

#include "conf_board.h"
#include "conf_tc_irq.h"
#include "interrupts.h"


struct {
@@ -130,6 +130,8 @@ void dac_timer_update(void) {
}

if (r) {
u8 irq_flags = irqs_pause();

spi_selectChip(DAC_SPI, DAC_SPI_NPCS);
spi_write(SPI, 0x31);
a = aout[2].now >> 2;
@@ -151,6 +153,8 @@ void dac_timer_update(void) {
spi_write(SPI, a >> 4);
spi_write(SPI, a << 4);
spi_unselectChip(DAC_SPI, DAC_SPI_NPCS);

irqs_resume(irq_flags);
}
}

@@ -9,7 +9,7 @@
#include "compiler.h"
#include "print_funcs.h"

#include "conf_tc_irq.h"
#include "interrupts.h"
#include "events.h"

static void handler_Ignore(s32 data) { }
@@ -27,11 +27,11 @@
#define INCR_EVENT_INDEX( x ) { if ( ++x == MAX_EVENTS ) x = 0; }

// et/Put indexes inxto sysEvents[] array
static int putIdx = 0;
static int getIdx = 0;
volatile static int putIdx = 0;
volatile static int getIdx = 0;

// The system event queue is a circular array of event records.
static event_t sysEvents[ MAX_EVENTS ];
volatile static event_t sysEvents[ MAX_EVENTS ];

// initializes (or re-initializes) the system event queue.
void init_events( void ) {
@@ -53,7 +53,7 @@
u8 event_next( event_t *e ) {
u8 status;

irqflags_t flags = cpu_irq_save();
u8 flags = irqs_pause();

// if pointers are equal, the queue is empty... don't allow idx's to wrap!
if ( getIdx != putIdx ) {
@@ -67,24 +67,22 @@ u8 event_next( event_t *e ) {
status = false;
}

cpu_irq_restore(flags);
irqs_resume(flags);

return status;
}


// add event to queue, return success status
u8 event_post( event_t *e ) {
u8 status = false;
int saveIndex;

// print_dbg("\r\n posting event, type: ");
// print_dbg_ulong(e->type);

irqflags_t flags = cpu_irq_save();
u8 flags = irqs_pause();
u8 status = false;

// increment write idx, posbily wrapping
saveIndex = putIdx;
int saveIndex = putIdx;
INCR_EVENT_INDEX( putIdx );
if ( putIdx != getIdx ) {
sysEvents[ putIdx ].type = e->type;
@@ -95,10 +93,10 @@ u8 event_post( event_t *e ) {
putIdx = saveIndex;
}

cpu_irq_restore(flags);
irqs_resume(flags);

if (!status)
print_dbg("\r\n event queue full!");
//if (!status)
// print_dbg("\r\n event queue full!");

return status;
}
@@ -268,3 +268,7 @@ extern void init_spi (void) {

// spi_enable(SPI);
}

extern u64 get_ticks(void) {
return tcTicks;
}
@@ -16,4 +16,6 @@ extern void register_interrupts(void);
extern void init_gpio(void);
extern void init_spi(void);

extern u64 get_ticks(void);

#endif
@@ -228,3 +228,7 @@ extern void init_spi (void) {

spi_setupChipReg( SPI, &spiOptions, FPBA_HZ );
}

extern u64 get_ticks(void) {
return tcTicks;
}
@@ -7,4 +7,6 @@ extern void register_interrupts(void);
extern void init_gpio(void);
extern void init_spi(void);

extern u64 get_ticks(void);

#endif
@@ -226,3 +226,7 @@ extern void init_spi (void) {

// spi_enable(SPI);
}

extern u64 get_ticks(void) {
return tcTicks;
}
@@ -16,4 +16,6 @@ extern void register_interrupts(void);
extern void init_gpio(void);
extern void init_spi(void);

extern u64 get_ticks(void);

#endif
@@ -0,0 +1,33 @@
#include "interrupt.h"
#include "conf_tc_irq.h"
#include "interrupts.h"
#include "types.h"

u8 irqs_pause( void ) {
u8 irq_flags = 0;
if (cpu_irq_level_is_enabled(SYS_IRQ_PRIORITY)) {
irq_flags |= 1 << SYS_IRQ_PRIORITY;
cpu_irq_disable_level(SYS_IRQ_PRIORITY);
}
if (cpu_irq_level_is_enabled(UI_IRQ_PRIORITY)) {
irq_flags |= 1 << UI_IRQ_PRIORITY;
cpu_irq_disable_level(UI_IRQ_PRIORITY);
}
if (cpu_irq_level_is_enabled(APP_TC_IRQ_PRIORITY)) {
irq_flags |= 1 << APP_TC_IRQ_PRIORITY;
cpu_irq_disable_level(APP_TC_IRQ_PRIORITY);
}
return irq_flags;
}

void irqs_resume( u8 irq_flags ) {
if (irq_flags & (1 << APP_TC_IRQ_PRIORITY)) {
cpu_irq_enable_level(APP_TC_IRQ_PRIORITY);
}
if (irq_flags & (1 << UI_IRQ_PRIORITY)) {
cpu_irq_enable_level(UI_IRQ_PRIORITY);
}
if (irq_flags & (1 << SYS_IRQ_PRIORITY)) {
cpu_irq_enable_level(SYS_IRQ_PRIORITY);
}
}
@@ -0,0 +1,9 @@
#ifndef _INTERRUPTS_H_
#define _INTERRUPTS_H_

#include "types.h"

u8 irqs_pause(void);
void irqs_resume(u8 irq_flags);

#endif
@@ -9,6 +9,7 @@
// libavr32
#include "font.h"
#include "screen.h"
#include "interrupts.h"

//-----------------------------
//---- variables
@@ -23,11 +24,13 @@ static u32 nb; // count of destination bytes

static void write_command(U8 c);
static void write_command(U8 c) {
u8 irq_flags = irqs_pause();
spi_selectChip(OLED_SPI, OLED_SPI_NPCS);
// pull register select low to write a command
gpio_clr_gpio_pin(OLED_DC_PIN);
spi_write(OLED_SPI, c);
spi_unselectChip(OLED_SPI, OLED_SPI_NPCS);
irqs_resume(irq_flags);
}

// set the current drawing area of the physical screen (hopefully)
@@ -120,6 +123,9 @@ void init_oled(void) {
static void writeScreenBuffer(u8 x, u8 y, u8 w, u8 h) {
// set drawing region
screen_set_rect(x, y, w, h);

u8 irq_flags = irqs_pause();

// select chip for data
spi_selectChip(OLED_SPI, OLED_SPI_NPCS);
// register select high for data
@@ -129,6 +135,8 @@ static void writeScreenBuffer(u8 x, u8 y, u8 w, u8 h) {
spi_write(OLED_SPI, screenBuf[i]);
}
spi_unselectChip(OLED_SPI, OLED_SPI_NPCS);

irqs_resume(irq_flags);
}

// draw data given target rect
@@ -232,6 +240,7 @@ void screen_draw_region_offset(u8 x, u8 y, u8 w, u8 h, u32 len, u8* data, u32 of

// clear OLED RAM and local screenbuffer
void screen_clear(void) {
u8 irq_flags = irqs_pause();
spi_selectChip(OLED_SPI, OLED_SPI_NPCS);
// pull register select high to write data
gpio_set_gpio_pin(OLED_DC_PIN);
@@ -240,4 +249,5 @@ void screen_clear(void) {
spi_write(OLED_SPI, 0);
}
spi_unselectChip(OLED_SPI, OLED_SPI_NPCS);
irqs_resume(irq_flags);
}

0 comments on commit 9adf6b7

Please sign in to comment.