Skip to content
Snippets Groups Projects
Verified Commit a83b0b51 authored by rahix's avatar rahix
Browse files

chore: Format all hw-tests & libcard10


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 6d1686e0
Branches
No related tags found
No related merge requests found
Showing
with 1210 additions and 1124 deletions
......@@ -6,7 +6,8 @@
void *api_call_start(uint32_t id, void *args, uint32_t size)
{
// aquire semaphore
while (E_BUSY == SEMA_GetSema (API_CALL_SEMA)) ;
while (E_BUSY == SEMA_GetSema(API_CALL_SEMA))
;
ApiCallSpace->id = id;
ApiCallSpace->returning = 0;
......@@ -20,7 +21,8 @@ void* api_call_bother_dispatcher (void* buf)
while (1) {
// aquire semaphore
while (E_BUSY == SEMA_GetSema (API_CALL_SEMA)) ;
while (E_BUSY == SEMA_GetSema(API_CALL_SEMA))
;
if (ApiCallSpace->returning == 1) {
break;
}
......
......@@ -17,7 +17,8 @@ void __api_dispatch_call(uint32_t id, void*buffer);
void api_dispatcher()
{
while (SEMA_GetSema(API_CALL_SEMA) == E_BUSY) {}
while (SEMA_GetSema(API_CALL_SEMA) == E_BUSY) {
}
if (ApiCallSpace->returning == 1) {
SEMA_FreeSema(API_CALL_SEMA);
......
......@@ -7,7 +7,9 @@
#include "api/api_dispatcher.h"
static const gpio_cfg_t motor_pin = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE};
static const gpio_cfg_t motor_pin = {
PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE
};
void api_set_buzzer(uint8_t state)
{
......@@ -23,7 +25,10 @@ void api_set_buzzer(uint8_t state)
void api_set_led(uint8_t led, led_color_t color)
{
printf("API: Changing color of led %d.\n", led);
printf("Color { r: %3d, g: %3d, b: %3d }\n", color.red, color.green, color.blue);
printf("Color { r: %3d, g: %3d, b: %3d }\n",
color.red,
color.green,
color.blue);
leds_set(led, color.red, color.green, color.blue);
leds_update();
}
......@@ -31,7 +36,10 @@ void api_set_led(uint8_t led, led_color_t color)
void api_test(char test0, short test1, int test2, long test3)
{
printf("test0: %x, test1: %d, test2: %x, test3: %lx\n",
test0, (int)test1, test2, test3);
test0,
(int)test1,
test2,
test3);
}
int main(void)
......@@ -44,7 +52,6 @@ int main(void)
TMR_Delay(MXC_TMR1, MSEC(100), 0);
}
#if 0
// Enable rxev on core1
MXC_GCR->evten |= 0x20;
......
......@@ -50,18 +50,19 @@ def main():
f_client = cx.enter_context(open(args.client, "w"))
f_server = cx.enter_context(open(args.server, "w"))
print('#include "{}"\n'.format(
os.path.basename(args.header)
), file=f_client)
print('#include "{}"\n'.format(os.path.basename(args.header)), file=f_client)
print("""\
print(
"""\
#include "{}"
void __api_dispatch_call(uint32_t id, void*buffer)
{{
switch (id) {{""".format(
os.path.basename(args.header)
), file=f_server)
),
file=f_server,
)
for match in matcher.finditer(source):
api_id = match.group("id")
......@@ -100,9 +101,12 @@ void {cdecl}({cargs})
file=f_client,
)
print("""\
print(
"""\
case {id}:
{cdecl}(""".format(id=api_id, cdecl=api_decl),
{cdecl}(""".format(
id=api_id, cdecl=api_decl
),
file=f_server,
)
......@@ -122,18 +126,17 @@ void {cdecl}({cargs})
print(
"""\
*({type}*)(buffer + {offset})""".format(
type=ty,
offset=" + ".join(api_args_sizes[:i]) if i > 0 else "0",
type=ty, offset=" + ".join(api_args_sizes[:i]) if i > 0 else "0"
),
file=f_server,
end="",
)
print("""
print(
"""
);
break;""".format(
cdecl=api_decl,
args=", ".join(api_args_names),
cdecl=api_decl, args=", ".join(api_args_names)
),
file=f_server,
)
......@@ -154,14 +157,17 @@ void {cdecl}({cargs})
file=f_client,
)
print("""\
print(
"""\
default:
printf("Error: API function %x is unknown!!\\n", {id});
break;
}}
}}""".format(
id=api_id,
), file=f_server)
id=api_id
),
file=f_server,
)
if __name__ == "__main__":
......
......@@ -64,7 +64,6 @@ int main(void)
uint32_t poll_period = 5, test_dur_ms = 30000;
uint16_t int_status;
bma.intf_ptr = NULL; /* To attach your interface device reference */
bma.delay_ms = card10_bosch_delay;
bma.dev_id = BMA400_I2C_ADDRESS_SDO_LOW;
......@@ -77,7 +76,6 @@ int main(void)
printf("BMA400 found with chip ID 0x%X\r\n", bma.chip_id);
}
print_rslt(rslt);
rslt = bma400_soft_reset(&bma);
......@@ -138,6 +136,5 @@ int main(void)
test_dur_ms -= poll_period;
}
}
}
......@@ -63,8 +63,9 @@ int main(void)
gas_sensor.power_mode = BME680_FORCED_MODE;
/* Set the required sensor settings needed */
set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_FILTER_SEL
| BME680_GAS_SENSOR_SEL;
set_required_settings = BME680_OST_SEL | BME680_OSP_SEL |
BME680_OSH_SEL | BME680_FILTER_SEL |
BME680_GAS_SENSOR_SEL;
/* Set the desired sensor configuration */
rslt = bme680_set_sensor_settings(set_required_settings, &gas_sensor);
......@@ -72,15 +73,16 @@ int main(void)
/* Set the power mode */
rslt = bme680_set_sensor_mode(&gas_sensor);
while (1) {
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
struct bme680_field_data data;
rslt = bme680_get_sensor_data(&data, &gas_sensor);
printf("T: %.2Lf degC, P: %.2Lf hPa, H %.2Lf %%rH ", data.temperature / 100.0l,
data.pressure / 100.0l, data.humidity / 1000.0l );
printf("T: %.2Lf degC, P: %.2Lf hPa, H %.2Lf %%rH ",
data.temperature / 100.0l,
data.pressure / 100.0l,
data.humidity / 1000.0l);
char buf[128];
sprintf(buf, "T: %.2Lf degC", data.temperature / 100.0l);
......@@ -98,7 +100,9 @@ int main(void)
if (data.status & BME680_GASM_VALID_MSK) {
printf(", G: %ld ohms", data.gas_resistance);
sprintf(buf, "G: %ld ohms", data.gas_resistance);
Paint_DrawString_EN(0, 48, buf, &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0, 48, buf, &Font16, 0x0000, 0xffff
);
}
LCD_Update();
......
......@@ -9,7 +9,6 @@
#include "GUI_Paint.h"
#include "pmic.h"
#include "flc.h"
#include "icc.h"
#include "tmr_utils.h"
......@@ -37,15 +36,15 @@ static void pmic_button(bool falling)
}
}
int main(void)
{
card10_init();
pmic_set_button_callback(pmic_button);
printf("Erasing bootloader.\n");
Paint_DrawString_EN(0, 16*0, "Erasing bootloader", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0, 16 * 0, "Erasing bootloader", &Font16, 0x0000, 0xffff
);
LCD_Update();
ICC_Disable();
......@@ -53,28 +52,41 @@ int main(void)
int ret = FLC_MultiPageErase(0x10000000, 0x10000000 + 1024 * 64 - 1);
if (ret != E_NO_ERROR) {
printf("FLC_MultiPageErase failed with %d\n", ret);
Paint_DrawString_EN(0, 16*1, "Fail.", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0, 16 * 1, "Fail.", &Font16, 0x0000, 0xffff
);
LCD_Update();
while(1);
while (1)
;
}
printf("Writing bootloader.\n");
Paint_DrawString_EN(0, 16*0, "Writing bootloader ", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0, 16 * 0, "Writing bootloader ", &Font16, 0x0000, 0xffff
);
LCD_Update();
ret = FLC_Write(0x10000000, sizeof(bootloader_data), (uint32_t *)bootloader_data);
ret = FLC_Write(
0x10000000,
sizeof(bootloader_data),
(uint32_t *)bootloader_data
);
if (ret != E_NO_ERROR) {
printf("FLC_Write failed with %d\n", ret);
Paint_DrawString_EN(0, 16*1, "Fail.", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0, 16 * 1, "Fail.", &Font16, 0x0000, 0xffff
);
LCD_Update();
while(1);
while (1)
;
}
ICC_Enable();
printf("Done.\n");
Paint_DrawString_EN(0, 16 * 1, "Done.", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(0, 16*2, "Please restart", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0, 16 * 2, "Please restart", &Font16, 0x0000, 0xffff
);
LCD_Update();
while (1) {
......
......@@ -2,7 +2,8 @@
#include "gpio.h"
#include "mxc_delay.h"
static const __attribute__((unused)) 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)
{
......
......@@ -56,7 +56,9 @@ static void ecg_write_reg(uint8_t reg, uint32_t data)
{
printf("write %02x %06lx\n", reg, data);
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 };
req.tx_data = tx_data;
req.rx_data = rx_data;
......@@ -81,12 +83,16 @@ static void ecg_config(bool enable_internal_pull)
union GeneralConfiguration_u CNFG_GEN_r;
CNFG_GEN_r.bits.en_ecg = 1; // Enable ECG channel
if (enable_internal_pull) {
CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input
CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input
CNFG_GEN_r.bits.rbiasn =
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
} else {
CNFG_GEN_r.bits.rbiasn = 0; // Enable resistive bias on negative input
CNFG_GEN_r.bits.rbiasp = 0; // Enable resistive bias on positive input
CNFG_GEN_r.bits.rbiasn =
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
}
......@@ -94,7 +100,6 @@ static void ecg_config(bool enable_internal_pull)
CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection
ecg_write_reg(CNFG_GEN, CNFG_GEN_r.all);
// ECG Config register setting
union ECGConfiguration_u CNFG_ECG_r;
CNFG_ECG_r.bits.dlpf = 1; // Digital LPF cutoff = 40Hz
......@@ -105,20 +110,17 @@ static void ecg_config(bool enable_internal_pull)
//CNFG_ECG_r.bits.rate = 1; // Sample rate = 256 sps
ecg_write_reg(CNFG_ECG, CNFG_ECG_r.all);
//R-to-R configuration
union RtoR1Configuration_u CNFG_RTOR_r;
CNFG_RTOR_r.bits.en_rtor = 1; // Enable R-to-R detection
ecg_write_reg(CNFG_RTOR1, CNFG_RTOR_r.all);
//Manage interrupts register setting
union ManageInterrupts_u MNG_INT_r;
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
ecg_write_reg(MNGR_INT, MNG_INT_r.all);
//Enable interrupts register setting
union EnableInterrupts_u EN_INT_r;
EN_INT_r.all = 0;
......@@ -127,7 +129,6 @@ static void ecg_config(bool enable_internal_pull)
EN_INT_r.bits.intb_type = 3; // Open-drain NMOS with internal pullup
ecg_write_reg(EN_INT, EN_INT_r.all);
//Dyanmic modes config
union ManageDynamicModes_u MNG_DYN_r;
MNG_DYN_r.bits.fast = 0; // Fast recovery mode disabled
......@@ -153,12 +154,12 @@ static void clear(void)
prev = Y_OFFSET;
}
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 < -Y_SCALE)
val = -Y_SCALE;
if (val > Y_SCALE)
val = Y_SCALE;
int8_t pos = Y_OFFSET + val;
......@@ -193,10 +194,13 @@ void update(void)
int16_t scale = max / Y_SCALE + 1;
char buf[128];
sprintf(buf, "Switch: %d Pull: %d Scale: %d", ecg_switch, internal_pull, scale);
sprintf(buf,
"Switch: %d Pull: %d Scale: %d",
ecg_switch,
internal_pull,
scale);
Paint_DrawString_EN(0, 0, buf, &Font8, 0x0000, 0xffff);
for (int i = 0; i < SIZE_X; i++) {
set(i, (samples[i] / scale));
//set(i, ((samples[i*2] + samples[i*2 + 1]) / scale) / 2);
......@@ -274,76 +278,41 @@ sampling frequency: 200 Hz
#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, 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
......@@ -376,28 +345,31 @@ static void add_sample(int16_t sample)
}
static volatile bool ecgFIFOIntFlag = false;
static void ecgFIFO_callback(void *data) {
static void ecgFIFO_callback(void *data)
{
ecgFIFOIntFlag = true;
}
// *****************************************************************************
int main(void)
{
card10_init();
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_RegisterCallback(&interrupt_pin, ecgFIFO_callback, NULL);
GPIO_IntConfig(&interrupt_pin, GPIO_INT_EDGE, GPIO_INT_FALLING);
GPIO_IntEnable(&interrupt_pin);
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);
ecg_switch = false;
GPIO_OutClr(&analog_switch); // Wrist
......@@ -417,7 +389,6 @@ int main(void)
max86150_setup(0x1F, 4, 3, 400, 411, 4096);
#endif
uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status;
int16_t ecgSample[32];
const int EINT_STATUS_MASK = 1 << 23;
......@@ -426,8 +397,6 @@ int main(void)
const int FIFO_FAST_SAMPLE_MASK = 0x1;
const int ETAG_BITS_MASK = 0x7;
while (1) {
#if 1
// Read back ECG samples from the FIFO
......@@ -436,7 +405,8 @@ int main(void)
if (PB_Get(3)) {
ecg_switch = !ecg_switch;
while(PB_Get(0));
while (PB_Get(0))
;
if (ecg_switch) {
GPIO_OutSet(&analog_switch); // USB
} else {
......@@ -446,31 +416,40 @@ int main(void)
if (PB_Get(4)) {
internal_pull = !internal_pull;
while(PB_Get(2));
while (PB_Get(2))
;
ecg_config(internal_pull);
}
//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
if ((status & EINT_STATUS_MASK) == EINT_STATUS_MASK) {
readECGSamples = 0; // Reset sample counter
do {
ecgFIFO = ecg_read_reg(ECG_FIFO ); // Read FIFO
ecgSample[readECGSamples] = ecgFIFO >> 8; // Isolate voltage data
ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & ETAG_BITS_MASK; // Isolate ETAG
ecgFIFO = ecg_read_reg(
ECG_FIFO); // Read FIFO
ecgSample[readECGSamples] =
ecgFIFO >>
8; // Isolate voltage data
ETAG[readECGSamples] =
(ecgFIFO >> 3) &
ETAG_BITS_MASK; // Isolate ETAG
readECGSamples++; // Increment sample counter
// Check that sample is not last sample in FIFO
} while ( ETAG[readECGSamples-1] == FIFO_VALID_SAMPLE_MASK ||
ETAG[readECGSamples-1] == FIFO_FAST_SAMPLE_MASK );
} while (ETAG[readECGSamples - 1] ==
FIFO_VALID_SAMPLE_MASK ||
ETAG[readECGSamples - 1] ==
FIFO_FAST_SAMPLE_MASK);
// Check if FIFO has overflowed
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");
// notifies the user that an over flow occured
//LED_On(0);
......
......@@ -187,7 +187,8 @@ void vTickTockTask(void *pvParameters)
while (1) {
ticks = xTaskGetTickCount();
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");
vTaskDelayUntil(&xLastWakeTime, (configTICK_RATE_HZ * 60));
}
......@@ -274,7 +275,8 @@ void vCmdLineTask(void *pvParameters)
fflush(stdout);
while (1) {
/* 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");
vTaskDelay(portMAX_DELAY);
}
......@@ -297,18 +299,26 @@ void vCmdLineTask(void *pvParameters)
printf("^C");
printf("\ncmd> ");
fflush(stdout);
} else if ((tmp == '\r') ||
(tmp == '\n')) {
} else if ((tmp == '\r') || (tmp == '\n')) {
printf("\r\n");
/* Null terminate for safety */
buffer[index] = 0x00;
/* Evaluate */
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
* 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));
}
} while (xMore != pdFALSE);
......@@ -326,8 +336,14 @@ void vCmdLineTask(void *pvParameters)
fflush(stdout);
}
/* If more characters are ready, process them here */
} while ((UART_NumReadAvail(MXC_UART_GET_UART(CONSOLE_UART)) > 0) &&
UART_Read(MXC_UART_GET_UART(CONSOLE_UART), (uint8_t *)&tmp, 1, NULL));
} while ((UART_NumReadAvail(MXC_UART_GET_UART(
CONSOLE_UART)) > 0) &&
UART_Read(
MXC_UART_GET_UART(CONSOLE_UART),
(uint8_t *)&tmp,
1,
NULL)
);
}
}
}
......@@ -365,15 +381,13 @@ void RTC_IRQHandler(void)
int main(void)
{
#if configUSE_TICKLESS_IDLE
uart_cfg_t uart_cfg = {
.parity = UART_PARITY_DISABLE,
uart_cfg_t uart_cfg = { .parity = UART_PARITY_DISABLE,
.size = UART_DATA_SIZE_8_BITS,
.stop = UART_STOP_1,
.flow = UART_FLOW_CTRL_DIS,
.pol = UART_FLOW_POL_DIS,
.baud = 115200,
.clksel = UART_CLKSEL_SYSTEM
};
.clksel = UART_CLKSEL_SYSTEM };
sys_cfg_uart_t uart_sys_cfg = { MAP_A, Enable };
/* The RTC must be enabled for tickless operation */
......@@ -389,7 +403,9 @@ int main(void)
#endif
/* 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
printf("Tickless idle is configured. Type 'tickless 1' to enable.\n");
#endif
......@@ -400,14 +416,35 @@ int main(void)
printf("xSemaphoreCreateMutex failed to create a mutex.\n");
} else {
/* Configure task */
if ((xTaskCreate(vTask0, (const char *)"Task0",
configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL) != 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)) {
if ((xTaskCreate(
vTask0,
(const char *)"Task0",
configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY + 1,
NULL) != 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");
} else {
/* Start scheduler */
......
......@@ -19,7 +19,8 @@
/***** Definitions *****/
/***** Globals *****/
static __attribute__((unused)) 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)
{
......
......@@ -32,9 +32,9 @@
#define MAX_PACKET_LENGTH 18
#define OUT_BUFFER_SIZE 60
/***** Globals *****/
char out_buffer[OUT_BUFFER_SIZE] = " W: 0.999 X: 0.999 Y: 0.999 Z: 0.999 \r";
char out_buffer[OUT_BUFFER_SIZE] =
" W: 0.999 X: 0.999 Y: 0.999 Z: 0.999 \r";
uint8_t fifo[FIFO_SIZE];
void draw_arrow(int angle, int color)
......@@ -68,15 +68,15 @@ void draw_arrow(int angle, int color)
}
/***** Functions *****/
static void sensors_callback_orientation(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
static void sensors_callback_orientation(
bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
) {
static int prev = -1;
printf("azimuth=%05d, pitch=%05d, roll=%05d status=%d\n",
sensor_data->data_vector.x * 360 / 32768,
sensor_data->data_vector.y * 360 / 32768,
sensor_data->data_vector.z * 360 / 32768,
sensor_data->data_vector.status
);
sensor_data->data_vector.status);
int angle = sensor_data->data_vector.x * 360 / 32768;
......@@ -92,44 +92,44 @@ static void sensors_callback_orientation(bhy_data_generic_t * sensor_data, bhy_v
sprintf(buf, "%3d", angle);
Paint_DrawString_EN(0, 30, buf, &Font24, BLACK, color);
Paint_DrawCircle(57,35, 4, color, DRAW_FILL_EMPTY, DOT_PIXEL_1X1);
Paint_DrawCircle(
57, 35, 4, color, DRAW_FILL_EMPTY, DOT_PIXEL_1X1
);
LCD_Update();
prev = angle;
}
}
static __attribute__((unused)) void sensors_callback_vector(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
static __attribute__((unused)) void sensors_callback_vector(
bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
) {
printf("x=%05d, y=%05d, z=%05d status=%d\n",
sensor_data->data_vector.x,
sensor_data->data_vector.y,
sensor_data->data_vector.z,
sensor_data->data_vector.status
);
sensor_data->data_vector.status);
}
static __attribute__((unused)) void sensors_callback_vector_uncalib(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
static __attribute__((unused)) void sensors_callback_vector_uncalib(
bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
) {
printf("x=%05d, y=%05d, z=%05d status=%d\n",
sensor_data->data_uncalib_vector.x,
sensor_data->data_uncalib_vector.y,
sensor_data->data_uncalib_vector.z,
sensor_data->data_uncalib_vector.status
);
sensor_data->data_uncalib_vector.status);
}
/*!
* @brief This function is callback function for acquring sensor datas
*
* @param[in] sensor_data
* @param[in] sensor_id
*/
static __attribute__((unused)) void sensors_callback_rotation_vector(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
static __attribute__((unused)) void sensors_callback_rotation_vector(
bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
) {
#if 0
float temp;
uint8_t index;
......@@ -183,8 +183,7 @@ static __attribute__((unused)) void sensors_callback_rotation_vector(bhy_data_ge
sensor_data->data_quaternion.x,
sensor_data->data_quaternion.y,
sensor_data->data_quaternion.z,
sensor_data->data_quaternion.w
);
sensor_data->data_quaternion.w);
}
// *****************************************************************************
......@@ -214,8 +213,10 @@ int main(void)
//if(bhy_install_sensor_callback(VS_TYPE_GRAVITY, VS_WAKEUP, sensors_callback_vector))
//if(bhy_install_sensor_callback(VS_TYPE_ACCELEROMETER, VS_WAKEUP, sensors_callback_vector))
//if(bhy_install_sensor_callback(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED, VS_WAKEUP, sensors_callback_vector_uncalib))
if(bhy_install_sensor_callback(VS_TYPE_ORIENTATION, VS_WAKEUP, sensors_callback_orientation))
{
if (bhy_install_sensor_callback(
VS_TYPE_ORIENTATION,
VS_WAKEUP,
sensors_callback_orientation)) {
printf("Fail to install sensor callback\n");
}
......@@ -227,52 +228,67 @@ int main(void)
}
#endif
/* enables the virtual sensor */
//if(bhy_enable_virtual_sensor(VS_TYPE_GEOMAGNETIC_FIELD, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
//if(bhy_enable_virtual_sensor(VS_TYPE_GRAVITY, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
//if(bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
//if(bhy_enable_virtual_sensor(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
if(bhy_enable_virtual_sensor(VS_TYPE_ORIENTATION, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
{
printf("Fail to enable sensor id=%d\n", VS_TYPE_GEOMAGNETIC_FIELD);
if (bhy_enable_virtual_sensor(
VS_TYPE_ORIENTATION,
VS_WAKEUP,
ROTATION_VECTOR_SAMPLE_RATE,
0,
VS_FLUSH_NONE,
0,
0)) {
printf("Fail to enable sensor id=%d\n",
VS_TYPE_GEOMAGNETIC_FIELD);
}
while(1)
{
while (1) {
/* wait until the interrupt fires */
/* unless we already know there are bytes remaining in the fifo */
while (!GPIO_InGet(&bhi_interrupt_pin) && !bytes_remaining);
bhy_read_fifo(fifo + bytes_left_in_fifo, FIFO_SIZE - bytes_left_in_fifo, &bytes_read, &bytes_remaining);
while (!GPIO_InGet(&bhi_interrupt_pin) && !bytes_remaining)
;
bhy_read_fifo(
fifo + bytes_left_in_fifo,
FIFO_SIZE - bytes_left_in_fifo,
&bytes_read,
&bytes_remaining
);
bytes_read += bytes_left_in_fifo;
fifoptr = fifo;
packet_type = BHY_DATA_TYPE_PADDING;
do
{
do {
/* this function will call callbacks that are registered */
result = bhy_parse_next_fifo_packet(&fifoptr, &bytes_read, &fifo_packet, &packet_type);
result = bhy_parse_next_fifo_packet(
&fifoptr,
&bytes_read,
&fifo_packet,
&packet_type
);
/* prints all the debug packets */
if (packet_type == BHY_DATA_TYPE_DEBUG)
{
bhy_print_debug_packet(&fifo_packet.data_debug, bhy_printf);
if (packet_type == BHY_DATA_TYPE_DEBUG) {
bhy_print_debug_packet(
&fifo_packet.data_debug, bhy_printf
);
}
/* the logic here is that if doing a partial parsing of the fifo, then we should not parse */
/* the last 18 bytes (max length of a packet) so that we don't try to parse an incomplete */
/* packet */
} while ((result == BHY_SUCCESS) && (bytes_read > (bytes_remaining ? MAX_PACKET_LENGTH : 0)));
} while ((result == BHY_SUCCESS) &&
(bytes_read >
(bytes_remaining ? MAX_PACKET_LENGTH : 0)));
bytes_left_in_fifo = 0;
if (bytes_remaining)
{
if (bytes_remaining) {
/* shifts the remaining bytes to the beginning of the buffer */
while (bytes_left_in_fifo < bytes_read)
{
while (bytes_left_in_fifo < bytes_read) {
fifo[bytes_left_in_fifo++] = *(fifoptr++);
}
}
......
......@@ -16,7 +16,6 @@
#include <stdint.h>
#include <string.h>
// *****************************************************************************
int main(void)
{
......@@ -28,9 +27,15 @@ int main(void)
Paint_DrawString_EN(0, 0, "123", &Font24, 0x000f, 0xfff0);
Paint_DrawString_EN(0, 23, "ABC", &Font24, BLUE, CYAN);
Paint_DrawString_CN(20, 42, "΢ѩµç×Ó", &Font24CN, WHITE, RED);
Paint_DrawRectangle(70, 10, 100, 40, RED,DRAW_FILL_EMPTY, DOT_PIXEL_2X2 );
Paint_DrawLine(70, 10, 100, 40, MAGENTA, LINE_STYLE_SOLID, DOT_PIXEL_2X2);
Paint_DrawLine(100, 10, 70, 40, MAGENTA, LINE_STYLE_SOLID, DOT_PIXEL_2X2);
Paint_DrawRectangle(
70, 10, 100, 40, RED, DRAW_FILL_EMPTY, DOT_PIXEL_2X2
);
Paint_DrawLine(
70, 10, 100, 40, MAGENTA, LINE_STYLE_SOLID, DOT_PIXEL_2X2
);
Paint_DrawLine(
100, 10, 70, 40, MAGENTA, LINE_STYLE_SOLID, DOT_PIXEL_2X2
);
Paint_DrawCircle(85, 25, 22, GREEN, DRAW_FILL_EMPTY, DOT_PIXEL_2X2);
Paint_DrawImage(gImage_40X40, 120, 0, 40, 40);
......
......@@ -18,7 +18,8 @@ static char heap[4096];
int mp_hal_stdin_rx_chr(void);
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
int stack_dummy;
stack_top = (char *)&stack_dummy;
leds_init();
......@@ -33,39 +34,52 @@ int main(int argc, char **argv) {
return 0;
}
void gc_collect(void) {
void gc_collect(void)
{
// WARNING: This gc_collect implementation doesn't try to get root
// pointers from CPU registers, and thus may function incorrectly.
void *dummy;
gc_collect_start();
gc_collect_root(&dummy, ((mp_uint_t)stack_top - (mp_uint_t)&dummy) / sizeof(mp_uint_t));
gc_collect_root(
&dummy,
((mp_uint_t)stack_top - (mp_uint_t)&dummy) / sizeof(mp_uint_t)
);
gc_collect_end();
gc_dump_info();
}
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
mp_lexer_t *mp_lexer_new_from_file(const char *filename)
{
mp_raise_OSError(MP_ENOENT);
}
mp_import_stat_t mp_import_stat(const char *path) {
mp_import_stat_t mp_import_stat(const char *path)
{
return MP_IMPORT_STAT_NO_EXIST;
}
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
{
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
void nlr_jump_fail(void *val) {
while (1);
void nlr_jump_fail(void *val)
{
while (1)
;
}
void NORETURN __fatal_error(const char *msg) {
while (1);
void NORETURN __fatal_error(const char *msg)
{
while (1)
;
}
#ifndef NDEBUG
void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) {
void MP_WEAK
__assert_func(const char *file, int line, const char *func, const char *expr)
{
printf("Assertion '%s' failed, at file %s:%d\n", expr, file, line);
__fatal_error("Assertion failed");
}
......
......@@ -11,11 +11,8 @@ STATIC mp_obj_t mp_leds_set(size_t n_args, const mp_obj_t *args)
int g = mp_obj_get_int(args[2]);
int b = mp_obj_get_int(args[3]);
if ( (0 > led || 256 < led) &&
(0 > r || 256 < r) &&
(0 > g || 256 < g) &&
(0 > b || 256 < b) )
{
if ((0 > led || 256 < led) && (0 > r || 256 < r) &&
(0 > g || 256 < g) && (0 > b || 256 < b)) {
mp_raise_ValueError("out of bounds");
}
printf("Set %u to (%x %x %x)\n", led, r, g, b);
......@@ -31,9 +28,7 @@ STATIC mp_obj_t mp_leds_set_dim(mp_obj_t led_obj, mp_obj_t dim_obj)
int led = mp_obj_get_int(led_obj);
int dim = mp_obj_get_int(dim_obj);
if ( (0 > led || 256 < led) &&
(0 > dim || 256 < dim) )
{
if ((0 > led || 256 < led) && (0 > dim || 256 < dim)) {
mp_raise_ValueError("out of bounds");
}
leds_set_dim(led, dim);
......
......@@ -16,7 +16,8 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_diff),
MP_ROM_PTR(&mp_utime_ticks_diff_obj) },
};
STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);
......
#include "py/mpconfig.h"
#include "mxc_delay.h"
void mp_hal_delay_ms(mp_uint_t ms) {
void mp_hal_delay_ms(mp_uint_t ms)
{
mxc_delay(ms * 1000); // TODO check return value
}
void mp_hal_delay_us(mp_uint_t us) {
void mp_hal_delay_us(mp_uint_t us)
{
mxc_delay(us); // TODO check return value
}
mp_uint_t mp_hal_ticks_ms(void) {
mp_uint_t mp_hal_ticks_ms(void)
{
return 0;
}
mp_uint_t mp_hal_ticks_us(void) {
mp_uint_t mp_hal_ticks_us(void)
{
return 0;
}
mp_uint_t mp_hal_ticks_cpu(void) {
mp_uint_t mp_hal_ticks_cpu(void)
{
return 0;
}
......@@ -9,15 +9,18 @@
extern mxc_uart_regs_t *ConsoleUart;
// Receive single character
int mp_hal_stdin_rx_chr(void) {
int mp_hal_stdin_rx_chr(void)
{
return UART_ReadByte(ConsoleUart);
}
// Send string of given length
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len)
{
UART_Write(ConsoleUart, (uint8_t *)str, len);
}
void mp_hal_set_interrupt_char(char c) {
void mp_hal_set_interrupt_char(char c)
{
return;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment