Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • card10/firmware
  • annejan/firmware
  • astro/firmware
  • fpletz/firmware
  • gerd/firmware
  • fleur/firmware
  • swym/firmware
  • l/firmware
  • uberardy/firmware
  • wink/firmware
  • madonius/firmware
  • mot/firmware
  • filid/firmware
  • q3k/firmware
  • hauke/firmware
  • Woazboat/firmware
  • pink/firmware
  • mossmann/firmware
  • omniskop/firmware
  • zenox/firmware
  • trilader/firmware
  • Danukeru/firmware
  • shoragan/firmware
  • zlatko/firmware
  • sistason/firmware
  • datenwolf/firmware
  • bene/firmware
  • amedee/firmware
  • martinling/firmware
  • griffon/firmware
  • chris007/firmware
  • adisbladis/firmware
  • dbrgn/firmware
  • jelly/firmware
  • rnestler/firmware
  • mh/firmware
  • ln/firmware
  • penguineer/firmware
  • monkeydom/firmware
  • jens/firmware
  • jnaulty/firmware
  • jeffmakes/firmware
  • marekventur/firmware
  • pete/firmware
  • h2obrain/firmware
  • DooMMasteR/firmware
  • jackie/firmware
  • prof_r/firmware
  • Draradech/firmware
  • Kartoffel/firmware
  • hinerk/firmware
  • abbradar/firmware
  • JustTB/firmware
  • LuKaRo/firmware
  • iggy/firmware
  • ente/firmware
  • flgr/firmware
  • Lorphos/firmware
  • matejo/firmware
  • ceddral7/firmware
  • danb/firmware
  • joshi/firmware
  • melle/firmware
  • fitch/firmware
  • deurknop/firmware
  • sargon/firmware
  • markus/firmware
  • kloenk/firmware
  • lucaswerkmeister/firmware
  • derf/firmware
  • meh/firmware
  • dx/card10-firmware
  • torben/firmware
  • yuvadm/firmware
  • AndyBS/firmware
  • klausdieter1/firmware
  • katzenparadoxon/firmware
  • xiretza/firmware
  • ole/firmware
  • techy/firmware
  • thor77/firmware
  • TilCreator/firmware
  • fuchsi/firmware
  • dos/firmware
  • yrlf/firmware
  • PetePriority/firmware
  • SuperVirus/firmware
  • sur5r/firmware
  • tazz/firmware
  • Alienmaster/firmware
  • flo_h/firmware
  • baldo/firmware
  • mmu_man/firmware
  • Foaly/firmware
  • sodoku/firmware
  • Guinness/firmware
  • ssp/firmware
  • led02/firmware
  • Stormwind/firmware
  • arist/firmware
  • coon/firmware
  • mdik/firmware
  • pippin/firmware
  • royrobotiks/firmware
  • zigot83/firmware
  • mo_k/firmware
106 results
Select Git revision
Loading items
Show changes
Showing
with 9885 additions and 555 deletions
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
/*******************************************************************************
* License: TBD
******************************************************************************/
/***** Includes *****/
#include "card10.h"
#include "bootloader-9251ea6.h"
#include "display.h"
#include "gfx.h"
#include "pmic.h"
#include "flc.h"
#include "icc.h"
#include "tmr_utils.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
/***** Definitions *****/
/***** Globals *****/
static void pmic_button(bool falling)
{
if (falling) {
printf("Resetting ...\n");
/*
* Give the UART fifo time to clear.
* TODO: Do this properly
*/
for (int i = 0; i < 0x1000000; i++) {
__asm volatile("nop");
}
MXC_GCR->rstr0 = MXC_F_GCR_RSTR0_SYSTEM;
}
}
int main(void)
{
card10_init();
pmic_set_button_callback(pmic_button);
printf("Erasing bootloader.\n");
txt_puts(&display_textb, "Erasing bootloader.\n");
ICC_Disable();
int ret = FLC_MultiPageErase(0x10000000, 0x10000000 + 1024 * 64 - 1);
if (ret != E_NO_ERROR) {
printf("FLC_MultiPageErase failed with %d\n", ret);
txt_puts(&display_textb, "Fail.\n");
while (1)
;
}
printf("Writing bootloader.\n");
txt_puts(&display_textb, "Writing bootloader.\n");
ret = FLC_Write(
0x10000000,
sizeof(bootloader_data),
(uint32_t *)bootloader_data
);
if (ret != E_NO_ERROR) {
printf("FLC_Write failed with %d\n", ret);
txt_puts(&display_textb, "Fail.\n");
while (1)
;
}
ICC_Enable();
printf("Done.\n");
txt_puts(&display_textb, "Done.\n");
txt_puts(&display_textb, "Please restart.\n");
while (1) {
card10_poll();
}
}
name = 'bootloader-update'
elf = executable(
name + '.elf',
'main.c',
dependencies: [libcard10, max32665_startup],
link_whole: [max32665_startup_lib, board_card10_lib],
link_args: [
'-Wl,-Map=' + meson.current_build_dir() + '/' + name + '.map',
],
)
custom_target(
name + '.bin',
build_by_default: true,
output: name + '.bin',
input: elf,
command: [build_image, '@INPUT@', '@OUTPUT0@'],
)
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
#include "gpio.h" #include "gpio.h"
#include "mxc_delay.h" #include "mxc_delay.h"
static const gpio_cfg_t motor_pin = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE}; static const __attribute__((unused))
gpio_cfg_t motor_pin = { PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE };
int main(void) int main(void)
{ {
......
source ../../.gdbinit source ../../init.gdb
set confirm off set confirm off
......
...@@ -3,45 +3,42 @@ ...@@ -3,45 +3,42 @@
******************************************************************************/ ******************************************************************************/
/***** Includes *****/ /***** Includes *****/
#include "pmic.h"
#include "leds.h"
#include "card10.h" #include "card10.h"
#include "leds.h"
#include "pmic.h"
#include "GUI_Paint.h" #include "display.h"
#include "gfx.h"
#include "tmr_utils.h" #include "tmr_utils.h"
#include <stdio.h> #include <Heart.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <Heart.h>
int main(void) int main(void)
{ {
card10_init(); card10_init();
card10_diag(); card10_diag();
Paint_DrawImage(Heart, 0, 0, 160, 80); gfx_copy_region(
LCD_Update(); &display_screen,
0,
for(int i=0; i<11; i++) { 0,
leds_set_dim(i, 1); 160,
} 80,
GFX_RGB565,
int h = 0; (const void *)(Heart)
);
gfx_update(&display_screen);
// Release core1 // Release core1
core1_start(); core1_start((void *)0x10080000);
int h = 0;
while (1) { while (1) {
#define NUM 15 #define NUM 15
for(int i=0; i<NUM; i++) {
if(i < 12) {
leds_set_hsv(i, (h + 360/NUM * i) % 360, 1., 1./8);
} else {
leds_set_hsv(i, (h + 360/NUM * i) % 360, 1., 1.);
}
}
leds_update(); leds_update();
TMR_Delay(MXC_TMR0, MSEC(10), 0); TMR_Delay(MXC_TMR0, MSEC(10), 0);
......
...@@ -3,7 +3,7 @@ executable( ...@@ -3,7 +3,7 @@ executable(
name + '.elf', name + '.elf',
'main.c', 'main.c',
dependencies: [libcard10, max32665_startup_core0], dependencies: [libcard10, max32665_startup_core0],
link_whole: [max32665_startup_core0_lib, board_card10_lib], link_whole: [max32665_startup_core0_lib, board_card10_lib, newlib_heap_lib],
link_args: [ link_args: [
'-Wl,-Map=' + meson.current_build_dir() + '/' + name + '.map', '-Wl,-Map=' + meson.current_build_dir() + '/' + name + '.map',
], ],
...@@ -14,7 +14,7 @@ executable( ...@@ -14,7 +14,7 @@ executable(
name + '.elf', name + '.elf',
'core1.c', 'core1.c',
dependencies: [periphdriver, board_card10, max32665_startup_core1], dependencies: [periphdriver, board_card10, max32665_startup_core1],
link_whole: [max32665_startup_core1_lib, board_card10_lib], link_whole: [max32665_startup_core1_lib, board_card10_lib, newlib_heap_lib],
link_args: [ link_args: [
'-Wl,-Map=' + meson.current_build_dir() + '/' + name + '.map', '-Wl,-Map=' + meson.current_build_dir() + '/' + name + '.map',
], ],
......
file ../../build/hw-tests/ecgtest/ecgtest.elf
source ../../.gdbinit
source ../../init.gdb
file ../../build/hw-tests/ecgtest/ecgtest.elf
...@@ -14,8 +14,11 @@ ...@@ -14,8 +14,11 @@
#include "i2c.h" #include "i2c.h"
#include "rtc.h" #include "rtc.h"
#include "spi.h" #include "spi.h"
#include "pb.h"
#include "MAX30003.h" #include "MAX30003.h"
#include "GUI_DEV/GUI_Paint.h" #include "gfx.h"
#include "LCD_Driver.h"
#include "display.h"
#include "pmic.h" #include "pmic.h"
#include "card10.h" #include "card10.h"
#include <stdbool.h> #include <stdbool.h>
...@@ -26,6 +29,8 @@ ...@@ -26,6 +29,8 @@
static bool ecg_switch; static bool ecg_switch;
static bool internal_pull; static bool internal_pull;
#define Y_OFFSET 36
#define Y_SCALE 35
/***** Functions *****/ /***** Functions *****/
static uint32_t ecg_read_reg(uint8_t reg) static uint32_t ecg_read_reg(uint8_t reg)
...@@ -51,9 +56,11 @@ static uint32_t ecg_read_reg(uint8_t reg) ...@@ -51,9 +56,11 @@ static uint32_t ecg_read_reg(uint8_t reg)
static void ecg_write_reg(uint8_t reg, uint32_t data) static void ecg_write_reg(uint8_t reg, uint32_t data)
{ {
printf("write %02x %06x\n", reg, data); printf("write %02x %06lx\n", reg, data);
spi_req_t req; spi_req_t req;
uint8_t tx_data[] = {(reg << 1) | 0 , data >> 16, (data >> 8 ) & 0xFF, data & 0xFF}; uint8_t tx_data[] = {
(reg << 1) | 0, data >> 16, (data >> 8) & 0xFF, data & 0xFF
};
uint8_t rx_data[] = { 0, 0, 0, 0 }; uint8_t rx_data[] = { 0, 0, 0, 0 };
req.tx_data = tx_data; req.tx_data = tx_data;
req.rx_data = rx_data; req.rx_data = rx_data;
...@@ -78,12 +85,16 @@ static void ecg_config(bool enable_internal_pull) ...@@ -78,12 +85,16 @@ static void ecg_config(bool enable_internal_pull)
union GeneralConfiguration_u CNFG_GEN_r; union GeneralConfiguration_u CNFG_GEN_r;
CNFG_GEN_r.bits.en_ecg = 1; // Enable ECG channel CNFG_GEN_r.bits.en_ecg = 1; // Enable ECG channel
if (enable_internal_pull) { if (enable_internal_pull) {
CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input CNFG_GEN_r.bits.rbiasn =
CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input 1; // Enable resistive bias on negative input
CNFG_GEN_r.bits.rbiasp =
1; // Enable resistive bias on positive input
CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias
} else { } else {
CNFG_GEN_r.bits.rbiasn = 0; // Enable resistive bias on negative input CNFG_GEN_r.bits.rbiasn =
CNFG_GEN_r.bits.rbiasp = 0; // Enable resistive bias on positive input 0; // Enable resistive bias on negative input
CNFG_GEN_r.bits.rbiasp =
0; // Enable resistive bias on positive input
CNFG_GEN_r.bits.en_rbias = 0; // Enable resistive bias CNFG_GEN_r.bits.en_rbias = 0; // Enable resistive bias
} }
...@@ -91,7 +102,6 @@ static void ecg_config(bool enable_internal_pull) ...@@ -91,7 +102,6 @@ static void ecg_config(bool enable_internal_pull)
CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection
ecg_write_reg(CNFG_GEN, CNFG_GEN_r.all); ecg_write_reg(CNFG_GEN, CNFG_GEN_r.all);
// ECG Config register setting // ECG Config register setting
union ECGConfiguration_u CNFG_ECG_r; union ECGConfiguration_u CNFG_ECG_r;
CNFG_ECG_r.bits.dlpf = 1; // Digital LPF cutoff = 40Hz CNFG_ECG_r.bits.dlpf = 1; // Digital LPF cutoff = 40Hz
...@@ -99,22 +109,20 @@ static void ecg_config(bool enable_internal_pull) ...@@ -99,22 +109,20 @@ static void ecg_config(bool enable_internal_pull)
//CNFG_ECG_r.bits.gain = 3; // ECG gain = 160V/V //CNFG_ECG_r.bits.gain = 3; // ECG gain = 160V/V
CNFG_ECG_r.bits.gain = 0; CNFG_ECG_r.bits.gain = 0;
CNFG_ECG_r.bits.rate = 2; // Sample rate = 128 sps CNFG_ECG_r.bits.rate = 2; // Sample rate = 128 sps
//CNFG_ECG_r.bits.rate = 1; // Sample rate = 256 sps
ecg_write_reg(CNFG_ECG, CNFG_ECG_r.all); ecg_write_reg(CNFG_ECG, CNFG_ECG_r.all);
//R-to-R configuration //R-to-R configuration
union RtoR1Configuration_u CNFG_RTOR_r; union RtoR1Configuration_u CNFG_RTOR_r;
CNFG_RTOR_r.bits.en_rtor = 1; // Enable R-to-R detection CNFG_RTOR_r.bits.en_rtor = 1; // Enable R-to-R detection
ecg_write_reg(CNFG_RTOR1, CNFG_RTOR_r.all); ecg_write_reg(CNFG_RTOR1, CNFG_RTOR_r.all);
//Manage interrupts register setting //Manage interrupts register setting
union ManageInterrupts_u MNG_INT_r; union ManageInterrupts_u MNG_INT_r;
MNG_INT_r.bits.efit = 0b00011; // Assert EINT w/ 4 unread samples MNG_INT_r.bits.efit = 0b00011; // Assert EINT w/ 4 unread samples
MNG_INT_r.bits.clr_rrint = 0b01; // Clear R-to-R on RTOR reg. read back MNG_INT_r.bits.clr_rrint = 0b01; // Clear R-to-R on RTOR reg. read back
ecg_write_reg(MNGR_INT, MNG_INT_r.all); ecg_write_reg(MNGR_INT, MNG_INT_r.all);
//Enable interrupts register setting //Enable interrupts register setting
union EnableInterrupts_u EN_INT_r; union EnableInterrupts_u EN_INT_r;
EN_INT_r.all = 0; EN_INT_r.all = 0;
...@@ -123,7 +131,6 @@ static void ecg_config(bool enable_internal_pull) ...@@ -123,7 +131,6 @@ static void ecg_config(bool enable_internal_pull)
EN_INT_r.bits.intb_type = 3; // Open-drain NMOS with internal pullup EN_INT_r.bits.intb_type = 3; // Open-drain NMOS with internal pullup
ecg_write_reg(EN_INT, EN_INT_r.all); ecg_write_reg(EN_INT, EN_INT_r.all);
//Dyanmic modes config //Dyanmic modes config
union ManageDynamicModes_u MNG_DYN_r; union ManageDynamicModes_u MNG_DYN_r;
MNG_DYN_r.bits.fast = 0; // Fast recovery mode disabled MNG_DYN_r.bits.fast = 0; // Fast recovery mode disabled
...@@ -145,18 +152,18 @@ static uint8_t prev; ...@@ -145,18 +152,18 @@ static uint8_t prev;
static void clear(void) static void clear(void)
{ {
Paint_Clear(BLACK); gfx_clear(&display_screen);
prev = 32; prev = Y_OFFSET;
} }
static void set(uint8_t index, int8_t val) static void set(uint8_t index, int8_t val)
{ {
if (val < -Y_SCALE)
val = -Y_SCALE;
if (val > Y_SCALE)
val = Y_SCALE;
if(val < -31) val = -31; int8_t pos = Y_OFFSET + val;
if(val > 32) val = 32;
int8_t pos = 32 + val;
int min, max; int min, max;
if (prev < pos) { if (prev < pos) {
...@@ -168,7 +175,7 @@ static void set(uint8_t index, int8_t val) ...@@ -168,7 +175,7 @@ static void set(uint8_t index, int8_t val)
} }
for (int i = min; i < max + 1; i++) { for (int i = min; i < max + 1; i++) {
LCD_SetUWORD(SIZE_X - index - 1, i, RED); LCD_SetUWORD(SIZE_X - index - 1, i, 0xf800);
} }
prev = pos; prev = pos;
...@@ -179,11 +186,6 @@ void update(void) ...@@ -179,11 +186,6 @@ void update(void)
{ {
clear(); clear();
char buf[128];
sprintf(buf, "Switch: %d Pull: %d", ecg_switch, internal_pull);
Paint_DrawString_EN(0, 0, buf, &Font8, 0x0000, 0xffff);
int16_t max = 0; int16_t max = 0;
for (int i = 0; i < SIZE_X; i++) { for (int i = 0; i < SIZE_X; i++) {
if (abs(samples[i]) > max) { if (abs(samples[i]) > max) {
...@@ -191,7 +193,23 @@ void update(void) ...@@ -191,7 +193,23 @@ void update(void)
} }
} }
int16_t scale = max / 32; int16_t scale = max / Y_SCALE + 1;
char buf[128];
sprintf(buf,
"Switch: %d Pull: %d Scale: %d",
ecg_switch,
internal_pull,
scale);
gfx_puts(
&Font8,
&display_screen,
0,
0,
buf,
gfx_color(&display_screen, WHITE),
gfx_color(&display_screen, BLACK)
);
for (int i = 0; i < SIZE_X; i++) { for (int i = 0; i < SIZE_X; i++) {
set(i, (samples[i] / scale)); set(i, (samples[i] / scale));
...@@ -201,6 +219,127 @@ void update(void) ...@@ -201,6 +219,127 @@ void update(void)
LCD_Update(); LCD_Update();
} }
#if 0
/*
FIR filter designed with
http://t-filter.appspot.com
sampling frequency: 200 Hz
* 0 Hz - 40 Hz
gain = 1
desired ripple = 5 dB
actual ripple = 4.1393894966071585 dB
* 50 Hz - 100 Hz
gain = 0
desired attenuation = -40 dB
actual attenuation = -40.07355419274887 dB
*/
#define FILTER_TAP_NUM 21
static double filter_taps[FILTER_TAP_NUM] = {
-0.02010411882885732,
-0.05842798004352509,
-0.061178403647821976,
-0.010939393385338943,
0.05125096443534972,
0.033220867678947885,
-0.05655276971833928,
-0.08565500737264514,
0.0633795996605449,
0.310854403656636,
0.4344309124179415,
0.310854403656636,
0.0633795996605449,
-0.08565500737264514,
-0.05655276971833928,
0.033220867678947885,
0.05125096443534972,
-0.010939393385338943,
-0.061178403647821976,
-0.05842798004352509,
-0.02010411882885732
};
#endif
#if 1
/*
FIR filter designed with
http://t-filter.appspot.com
sampling frequency: 200 Hz
* 0 Hz - 40 Hz
gain = 1
desired ripple = 0.5 dB
actual ripple = 0.3562617633495587 dB
* 45 Hz - 100 Hz
gain = 0
desired attenuation = -40 dB
actual attenuation = -40.37207584888854 dB
*/
#define FILTER_TAP_NUM 71
static double filter_taps[FILTER_TAP_NUM] = {
0.0057445089465822975, 0.007451288673767406,
-0.0011523652638272097, -0.0030609271459832005,
-0.002596310763437956, 0.004452951934981218,
0.003740429140762826, -0.002351310203707235,
-0.00638990322759006, 0.000013108391204023357,
0.007226767366250225, 0.003994033360879168,
-0.00665189327484351, -0.008058131222070393,
0.0035814528837470965, 0.011450459869389184,
0.0016796020911726648, -0.012657785603199918,
-0.008611714082779583, 0.010587105712461298,
0.01581354994840992, -0.0044174953741535905,
-0.021419548904285074, -0.005927897725436821,
0.023159558089340265, 0.01973520678092361,
-0.018604692334579287, -0.035495574517452874,
0.004958680854279203, 0.05116349477789529,
0.02244341207607204, -0.06449371846227892,
-0.0790927656214483, 0.07342794634140555,
0.3089023630319309, 0.42341742792869774,
0.3089023630319309, 0.07342794634140555,
-0.0790927656214483, -0.06449371846227892,
0.02244341207607204, 0.05116349477789529,
0.004958680854279203, -0.035495574517452874,
-0.018604692334579287, 0.01973520678092361,
0.023159558089340265, -0.005927897725436821,
-0.021419548904285074, -0.0044174953741535905,
0.01581354994840992, 0.010587105712461298,
-0.008611714082779583, -0.012657785603199918,
0.0016796020911726648, 0.011450459869389184,
0.0035814528837470965, -0.008058131222070393,
-0.00665189327484351, 0.003994033360879168,
0.007226767366250225, 0.000013108391204023357,
-0.00638990322759006, -0.002351310203707235,
0.003740429140762826, 0.004452951934981218,
-0.002596310763437956, -0.0030609271459832005,
-0.0011523652638272097, 0.007451288673767406,
0.0057445089465822975
};
#endif
int32_t fir(int32_t a)
{
static int32_t x[FILTER_TAP_NUM];
memmove(x + 1, x, sizeof(*x) * (FILTER_TAP_NUM - 1));
x[0] = a;
int32_t y = 0;
int i;
for (i = 0; i < FILTER_TAP_NUM; i++) {
y += filter_taps[i] * x[i];
}
return y;
}
static uint8_t sample_count = 0; static uint8_t sample_count = 0;
static void add_sample(int16_t sample) static void add_sample(int16_t sample)
...@@ -216,58 +355,68 @@ static void add_sample(int16_t sample) ...@@ -216,58 +355,68 @@ static void add_sample(int16_t sample)
} }
static volatile bool ecgFIFOIntFlag = false; static volatile bool ecgFIFOIntFlag = false;
static void ecgFIFO_callback(void *data) { static void ecgFIFO_callback(void *data)
{
ecgFIFOIntFlag = true; ecgFIFOIntFlag = true;
} }
// ***************************************************************************** // *****************************************************************************
int main(void) int main(void)
{ {
card10_init(); card10_init();
card10_diag(); card10_diag();
const gpio_cfg_t interrupt_pin = {PORT_1, PIN_12, GPIO_FUNC_IN, GPIO_PAD_PULL_UP}; const gpio_cfg_t interrupt_pin = {
PORT_1, PIN_12, GPIO_FUNC_IN, GPIO_PAD_PULL_UP
};
GPIO_Config(&interrupt_pin); GPIO_Config(&interrupt_pin);
GPIO_RegisterCallback(&interrupt_pin, ecgFIFO_callback, NULL); GPIO_RegisterCallback(&interrupt_pin, ecgFIFO_callback, NULL);
GPIO_IntConfig(&interrupt_pin, GPIO_INT_EDGE, GPIO_INT_FALLING); GPIO_IntConfig(&interrupt_pin, GPIO_INT_EDGE, GPIO_INT_FALLING);
GPIO_IntEnable(&interrupt_pin); GPIO_IntEnable(&interrupt_pin);
NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(PORT_1)); NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(PORT_1));
const gpio_cfg_t analog_switch = {PORT_0, PIN_31, GPIO_FUNC_OUT, GPIO_PAD_NONE}; const gpio_cfg_t analog_switch = {
PORT_0, PIN_31, GPIO_FUNC_OUT, GPIO_PAD_NONE
};
GPIO_Config(&analog_switch); GPIO_Config(&analog_switch);
ecg_switch = false; ecg_switch = false;
GPIO_OutClr(&analog_switch); // Wrist GPIO_OutClr(&analog_switch); // Wrist
internal_pull = true; internal_pull = true;
#if 1
ecg_config(internal_pull); ecg_config(internal_pull);
for (int i = 0; i < 0x20; i++) { for (int i = 0; i < 0x20; i++) {
uint32_t val = ecg_read_reg(i); uint32_t val = ecg_read_reg(i);
printf("%02x: 0x%06x\n", i, val); printf("%02x: 0x%06lx\n", i, val);
} }
ecg_write_reg(SYNCH, 0); ecg_write_reg(SYNCH, 0);
#else
max86150_begin();
max86150_setup(0x1F, 4, 3, 400, 411, 4096);
#endif
uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status; uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status;
int16_t ecgSample[32]; int16_t ecgSample[32];
const int EINT_STATUS_MASK = 1 << 23; const uint32_t EINT_STATUS_MASK = 1 << 23;
const int FIFO_OVF_MASK = 0x7; const uint32_t FIFO_OVF_MASK = 0x7;
const int FIFO_VALID_SAMPLE_MASK = 0x0; const uint32_t FIFO_VALID_SAMPLE_MASK = 0x0;
const int FIFO_FAST_SAMPLE_MASK = 0x1; const uint32_t FIFO_FAST_SAMPLE_MASK = 0x1;
const int ETAG_BITS_MASK = 0x7; const uint32_t ETAG_BITS_MASK = 0x7;
while (1) { while (1) {
#if 1
// Read back ECG samples from the FIFO // Read back ECG samples from the FIFO
if (ecgFIFOIntFlag) { if (ecgFIFOIntFlag) {
ecgFIFOIntFlag = false; ecgFIFOIntFlag = false;
if(PB_Get(0)) { if (PB_Get(3)) {
ecg_switch = !ecg_switch; ecg_switch = !ecg_switch;
while(PB_Get(0)); while (PB_Get(0))
;
if (ecg_switch) { if (ecg_switch) {
GPIO_OutSet(&analog_switch); // USB GPIO_OutSet(&analog_switch); // USB
} else { } else {
...@@ -275,33 +424,42 @@ int main(void) ...@@ -275,33 +424,42 @@ int main(void)
} }
} }
if(PB_Get(2)) { if (PB_Get(4)) {
internal_pull = !internal_pull; internal_pull = !internal_pull;
while(PB_Get(2)); while (PB_Get(2))
;
ecg_config(internal_pull); ecg_config(internal_pull);
} }
//printf("Int\n"); //printf("Int\n");
status = ecg_read_reg( STATUS ); // Read the STATUS register status = ecg_read_reg(
STATUS); // Read the STATUS register
// Check if EINT interrupt asserted // Check if EINT interrupt asserted
if ((status & EINT_STATUS_MASK) == EINT_STATUS_MASK) { if ((status & EINT_STATUS_MASK) == EINT_STATUS_MASK) {
readECGSamples = 0; // Reset sample counter readECGSamples = 0; // Reset sample counter
do { do {
ecgFIFO = ecg_read_reg(ECG_FIFO ); // Read FIFO ecgFIFO = ecg_read_reg(
ecgSample[readECGSamples] = ecgFIFO >> 8; // Isolate voltage data ECG_FIFO); // Read FIFO
ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & ETAG_BITS_MASK; // Isolate ETAG ecgSample[readECGSamples] =
ecgFIFO >>
8; // Isolate voltage data
ETAG[readECGSamples] =
(ecgFIFO >> 3) &
ETAG_BITS_MASK; // Isolate ETAG
readECGSamples++; // Increment sample counter readECGSamples++; // Increment sample counter
// Check that sample is not last sample in FIFO // Check that sample is not last sample in FIFO
} while ( ETAG[readECGSamples-1] == FIFO_VALID_SAMPLE_MASK || } while (ETAG[readECGSamples - 1] ==
ETAG[readECGSamples-1] == FIFO_FAST_SAMPLE_MASK ); FIFO_VALID_SAMPLE_MASK ||
ETAG[readECGSamples - 1] ==
FIFO_FAST_SAMPLE_MASK);
// Check if FIFO has overflowed // Check if FIFO has overflowed
if (ETAG[readECGSamples - 1] == FIFO_OVF_MASK) { if (ETAG[readECGSamples - 1] == FIFO_OVF_MASK) {
ecg_write_reg(FIFO_RST , 0); // Reset FIFO ecg_write_reg(
FIFO_RST, 0); // Reset FIFO
//printf("OV\n"); //printf("OV\n");
// notifies the user that an over flow occured // notifies the user that an over flow occured
//LED_On(0); //LED_On(0);
...@@ -315,5 +473,35 @@ int main(void) ...@@ -315,5 +473,35 @@ int main(void)
} }
} }
} }
#else
static float y1, y2, y3;
static const float alpha = 0.001;
if (max86150_check() > 0) {
while (max86150_available()) {
uint32_t a = max86150_getFIFORed();
uint32_t b = max86150_getFIFOIR();
//if( a & (0x1 << 17) ) {
// a |= 0xFFFC0000;
//}
//int32_t b = (int32_t)a;
//int32_t b = (int16_t)max86150_getFIFOEcg();
int16_t c = (int16_t)max86150_getFIFOECG();
c = fir(c);
y1 = (1. - alpha) * y1 + alpha * a;
y2 = (1. - alpha) * y2 + alpha * b;
y3 = (1. - alpha) * y3 + alpha * c;
//printf("%d,%d,%d\n", a - y1, b - y2, c - y3);
//printf("%d,%d,%d\n", a, b, c);
add_sample(c - y3);
max86150_nextSample();
}
}
#endif
} }
} }
...@@ -200,11 +200,11 @@ static BaseType_t prvUptimeCommand(char *pcWriteBuffer, size_t xWriteBufferLen, ...@@ -200,11 +200,11 @@ static BaseType_t prvUptimeCommand(char *pcWriteBuffer, size_t xWriteBufferLen,
#if configUSE_TICKLESS_IDLE #if configUSE_TICKLESS_IDLE
pcWriteBuffer += snprintf(pcWriteBuffer, xWriteBufferLen, pcWriteBuffer += snprintf(pcWriteBuffer, xWriteBufferLen,
"Uptime is 0x%08x (%u ms)\r\nMXC_RTCTMR->timer is %u\r\n", "Uptime is 0x%08lx (%lu ms)\r\nMXC_RTCTMR->timer is %lu\r\n",
ticks, ticks / portTICK_PERIOD_MS, MXC_RTC->sec); ticks, ticks / portTICK_PERIOD_MS, MXC_RTC->sec);
#else #else
pcWriteBuffer += snprintf(pcWriteBuffer, xWriteBufferLen, pcWriteBuffer += snprintf(pcWriteBuffer, xWriteBufferLen,
"Uptime is 0x%08x (%u ms)\r\n", "Uptime is 0x%08lx (%lu ms)\r\n",
ticks, ticks / portTICK_PERIOD_MS); ticks, ticks / portTICK_PERIOD_MS);
#endif #endif
...@@ -257,7 +257,7 @@ static BaseType_t lParameterNumber = 0; ...@@ -257,7 +257,7 @@ static BaseType_t lParameterNumber = 0;
memset( pcWriteBuffer, 0x00, xWriteBufferLen ); memset( pcWriteBuffer, 0x00, xWriteBufferLen );
sprintf( pcWriteBuffer, "%d: ", (int)lParameterNumber ); sprintf( pcWriteBuffer, "%d: ", (int)lParameterNumber );
strncat( pcWriteBuffer, pcParameter, lParameterStringLength ); strncat( pcWriteBuffer, pcParameter, lParameterStringLength );
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) ); strcat( pcWriteBuffer, "\r\n");
/* If this is the last of the three parameters then there are no more /* If this is the last of the three parameters then there are no more
strings to return after this one. */ strings to return after this one. */
...@@ -323,7 +323,7 @@ static BaseType_t lParameterNumber = 0; ...@@ -323,7 +323,7 @@ static BaseType_t lParameterNumber = 0;
memset( pcWriteBuffer, 0x00, xWriteBufferLen ); memset( pcWriteBuffer, 0x00, xWriteBufferLen );
sprintf( pcWriteBuffer, "%d: ", (int)lParameterNumber ); sprintf( pcWriteBuffer, "%d: ", (int)lParameterNumber );
strncat( pcWriteBuffer, pcParameter, lParameterStringLength ); strncat( pcWriteBuffer, pcParameter, lParameterStringLength );
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) ); strcat( pcWriteBuffer, "\r\n");
/* There might be more parameters to return after this one. */ /* There might be more parameters to return after this one. */
xReturn = pdTRUE; xReturn = pdTRUE;
......
source ../../init.gdb
file ../../build/hw-tests/hello-freertos/hello-freertos.elf
...@@ -186,8 +186,9 @@ void vTickTockTask(void *pvParameters) ...@@ -186,8 +186,9 @@ void vTickTockTask(void *pvParameters)
while (1) { while (1) {
ticks = xTaskGetTickCount(); ticks = xTaskGetTickCount();
printf("Uptime is 0x%08x (%u seconds), tickless-idle is %s\n", printf("Uptime is 0x%08lx (%lu seconds), tickless-idle is %s\n",
ticks, ticks / configTICK_RATE_HZ, ticks,
ticks / configTICK_RATE_HZ,
disable_tickless ? "disabled" : "ENABLED"); disable_tickless ? "disabled" : "ENABLED");
vTaskDelayUntil(&xLastWakeTime, (configTICK_RATE_HZ * 60)); vTaskDelayUntil(&xLastWakeTime, (configTICK_RATE_HZ * 60));
} }
...@@ -274,7 +275,8 @@ void vCmdLineTask(void *pvParameters) ...@@ -274,7 +275,8 @@ void vCmdLineTask(void *pvParameters)
fflush(stdout); fflush(stdout);
while (1) { while (1) {
/* Register async read request */ /* Register async read request */
if (UART_ReadAsync(ConsoleUART, &async_read_req) != E_NO_ERROR) { if (UART_ReadAsync(ConsoleUART, &async_read_req) !=
E_NO_ERROR) {
printf("Error registering async request. Command line unavailable.\n"); printf("Error registering async request. Command line unavailable.\n");
vTaskDelay(portMAX_DELAY); vTaskDelay(portMAX_DELAY);
} }
...@@ -297,18 +299,26 @@ void vCmdLineTask(void *pvParameters) ...@@ -297,18 +299,26 @@ void vCmdLineTask(void *pvParameters)
printf("^C"); printf("^C");
printf("\ncmd> "); printf("\ncmd> ");
fflush(stdout); fflush(stdout);
} else if ((tmp == '\r') || } else if ((tmp == '\r') || (tmp == '\n')) {
(tmp == '\n')) {
printf("\r\n"); printf("\r\n");
/* Null terminate for safety */ /* Null terminate for safety */
buffer[index] = 0x00; buffer[index] = 0x00;
/* Evaluate */ /* Evaluate */
do { do {
xMore = FreeRTOS_CLIProcessCommand(buffer, output, OUTPUT_BUF_SIZE); xMore = FreeRTOS_CLIProcessCommand(
buffer,
output,
OUTPUT_BUF_SIZE
);
/* If xMore == pdTRUE, then output buffer contains no null termination, so /* If xMore == pdTRUE, then output buffer contains no null termination, so
* we know it is OUTPUT_BUF_SIZE. If pdFALSE, we can use strlen. * we know it is OUTPUT_BUF_SIZE. If pdFALSE, we can use strlen.
*/ */
for (x = 0; x < (xMore == pdTRUE ? OUTPUT_BUF_SIZE : strlen(output)) ; x++) { for (x = 0;
x <
(xMore == pdTRUE ?
OUTPUT_BUF_SIZE :
strlen(output));
x++) {
putchar(*(output + x)); putchar(*(output + x));
} }
} while (xMore != pdFALSE); } while (xMore != pdFALSE);
...@@ -326,8 +336,14 @@ void vCmdLineTask(void *pvParameters) ...@@ -326,8 +336,14 @@ void vCmdLineTask(void *pvParameters)
fflush(stdout); fflush(stdout);
} }
/* If more characters are ready, process them here */ /* If more characters are ready, process them here */
} while ((UART_NumReadAvail(MXC_UART_GET_UART(CONSOLE_UART)) > 0) && } while ((UART_NumReadAvail(MXC_UART_GET_UART(
UART_Read(MXC_UART_GET_UART(CONSOLE_UART), (uint8_t *)&tmp, 1, NULL)); CONSOLE_UART)) > 0) &&
UART_Read(
MXC_UART_GET_UART(CONSOLE_UART),
(uint8_t *)&tmp,
1,
NULL)
);
} }
} }
} }
...@@ -365,15 +381,13 @@ void RTC_IRQHandler(void) ...@@ -365,15 +381,13 @@ void RTC_IRQHandler(void)
int main(void) int main(void)
{ {
#if configUSE_TICKLESS_IDLE #if configUSE_TICKLESS_IDLE
uart_cfg_t uart_cfg = { uart_cfg_t uart_cfg = { .parity = UART_PARITY_DISABLE,
.parity = UART_PARITY_DISABLE,
.size = UART_DATA_SIZE_8_BITS, .size = UART_DATA_SIZE_8_BITS,
.stop = UART_STOP_1, .stop = UART_STOP_1,
.flow = UART_FLOW_CTRL_DIS, .flow = UART_FLOW_CTRL_DIS,
.pol = UART_FLOW_POL_DIS, .pol = UART_FLOW_POL_DIS,
.baud = 115200, .baud = 115200,
.clksel = UART_CLKSEL_SYSTEM .clksel = UART_CLKSEL_SYSTEM };
};
sys_cfg_uart_t uart_sys_cfg = { MAP_A, Enable }; sys_cfg_uart_t uart_sys_cfg = { MAP_A, Enable };
/* The RTC must be enabled for tickless operation */ /* The RTC must be enabled for tickless operation */
...@@ -389,7 +403,9 @@ int main(void) ...@@ -389,7 +403,9 @@ int main(void)
#endif #endif
/* Print banner (RTOS scheduler not running) */ /* Print banner (RTOS scheduler not running) */
printf("\n-=- %s FreeRTOS (%s) Demo -=-\n", STRING(TARGET), tskKERNEL_VERSION_NUMBER); printf("\n-=- %s FreeRTOS (%s) Demo -=-\n",
STRING(TARGET),
tskKERNEL_VERSION_NUMBER);
#if configUSE_TICKLESS_IDLE #if configUSE_TICKLESS_IDLE
printf("Tickless idle is configured. Type 'tickless 1' to enable.\n"); printf("Tickless idle is configured. Type 'tickless 1' to enable.\n");
#endif #endif
...@@ -400,14 +416,35 @@ int main(void) ...@@ -400,14 +416,35 @@ int main(void)
printf("xSemaphoreCreateMutex failed to create a mutex.\n"); printf("xSemaphoreCreateMutex failed to create a mutex.\n");
} else { } else {
/* Configure task */ /* Configure task */
if ((xTaskCreate(vTask0, (const char *)"Task0", if ((xTaskCreate(
configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL) != pdPASS) || vTask0,
(xTaskCreate(vTask1, (const char *)"Task1", (const char *)"Task0",
configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL) != pdPASS) || configMINIMAL_STACK_SIZE,
(xTaskCreate(vTickTockTask, (const char *)"TickTock", NULL,
2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+2, NULL) != pdPASS) || tskIDLE_PRIORITY + 1,
(xTaskCreate(vCmdLineTask, (const char *)"CmdLineTask", NULL) != pdPASS) ||
configMINIMAL_STACK_SIZE+CMD_LINE_BUF_SIZE+OUTPUT_BUF_SIZE, NULL, tskIDLE_PRIORITY+1, &cmd_task_id) != pdPASS)) { (xTaskCreate(
vTask1,
(const char *)"Task1",
configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY + 1,
NULL) != pdPASS) ||
(xTaskCreate(
vTickTockTask,
(const char *)"TickTock",
2 * configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY + 2,
NULL) != pdPASS) ||
(xTaskCreate(
vCmdLineTask,
(const char *)"CmdLineTask",
configMINIMAL_STACK_SIZE + CMD_LINE_BUF_SIZE +
OUTPUT_BUF_SIZE,
NULL,
tskIDLE_PRIORITY + 1,
&cmd_task_id) != pdPASS)) {
printf("xTaskCreate() failed to create a task.\n"); printf("xTaskCreate() failed to create a task.\n");
} else { } else {
/* Start scheduler */ /* Start scheduler */
......
name = 'hello-freertos' name = 'hello-freertos'
freertos = static_library( freertos = static_library(
'freertos-sdk', 'freertos',
freertos_sdk_sources, freertos_sources,
freertos_heap2,
freertos_cli_sources,
dependencies: periphdriver, dependencies: periphdriver,
include_directories: [ include_directories: [
freertos_sdk_includes, freertos_includes,
freertos_cli_includes,
include_directories('./'), include_directories('./'),
] ]
) )
...@@ -19,7 +22,7 @@ sources = files( ...@@ -19,7 +22,7 @@ sources = files(
elf = executable( elf = executable(
name + '.elf', name + '.elf',
sources, sources,
include_directories: freertos_sdk_includes, include_directories: [freertos_includes, freertos_cli_includes],
dependencies: [libcard10, max32665_startup], dependencies: [libcard10, max32665_startup],
link_with: freertos, link_with: freertos,
link_whole: [max32665_startup_lib, board_card10_lib], link_whole: [max32665_startup_lib, board_card10_lib],
......
file ../../build/hw-tests/hello-world/hello-world.elf
source ../../.gdbinit
source ../../init.gdb
file ../../build/hw-tests/hello-world/hello-world.elf
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
#include "leds.h" #include "leds.h"
#include "card10.h" #include "card10.h"
#include "GUI_Paint.h" #include "gfx.h"
#include "display.h"
#include "tmr_utils.h" #include "tmr_utils.h"
...@@ -19,7 +20,8 @@ ...@@ -19,7 +20,8 @@
/***** Definitions *****/ /***** Definitions *****/
/***** Globals *****/ /***** Globals *****/
static const gpio_cfg_t motor_pin = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE}; static __attribute__((unused))
const gpio_cfg_t motor_pin = { PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE };
int main(void) int main(void)
{ {
...@@ -28,14 +30,22 @@ int main(void) ...@@ -28,14 +30,22 @@ int main(void)
card10_init(); card10_init();
card10_diag(); card10_diag();
Paint_DrawImage(Heart, 0, 0, 160, 80); gfx_copy_region(
LCD_Update(); &display_screen,
0,
0,
160,
80,
GFX_RGB565,
(const void *)(Heart)
);
gfx_update(&display_screen);
for (int i = 0; i < 11; i++) { for (int i = 0; i < 11; i++) {
leds_set_dim(i, 1); // leds_set_dim(i, 1);
} }
int h = 0; int __attribute__((unused)) h = 0;
while (1) { while (1) {
#if 0 #if 0
......
file ../../build/hw-tests/imutest/imutest.elf
source ../../.gdbinit
source ../../init.gdb
file ../../build/hw-tests/imutest/imutest.elf