Verified Commit a83b0b51 authored by Rahix's avatar Rahix
Browse files

chore: Format all hw-tests & libcard10


Signed-off-by: Rahix's avatarRahix <rahix@rahix.de>
parent 6d1686e0
......@@ -3,24 +3,26 @@
#include "api/api_caller.h"
#include "tmr_utils.h"
void* api_call_start (uint32_t id, void* args, uint32_t size)
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->id = id;
ApiCallSpace->returning = 0;
return ApiCallSpace->buf;
}
void* api_call_bother_dispatcher (void* buf)
void *api_call_bother_dispatcher(void *buf)
{
SEMA_FreeSema (API_CALL_SEMA);
SEMA_FreeSema(API_CALL_SEMA);
// TODO: set event
while(1) {
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;
}
......
#include "api_dispatcher.h"
int api_init (sys_cfg_sema_t *sys_cfg)
int api_init(sys_cfg_sema_t *sys_cfg)
{
int ret;
ret = SEMA_Init (sys_cfg);
ret = SEMA_Init(sys_cfg);
/* Set the status of the flag to a valid initial state (right before
* api-calls are made) */
ApiCallSpace->returning = 1;
......@@ -13,11 +13,12 @@ int api_init (sys_cfg_sema_t *sys_cfg)
}
/* Generated function */
void __api_dispatch_call(uint32_t id, void*buffer);
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,15 +25,21 @@ 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();
}
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);
printf("test0: %x, test1: %d, test2: %x, test3: %lx\n",
test0,
(int)test1,
test2,
test3);
}
int main(void)
......@@ -41,10 +49,9 @@ int main(void)
while (1) {
api_dispatcher();
TMR_Delay(MXC_TMR1, MSEC(100), 0);
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)
os.path.basename(args.header)
),
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__":
......
......@@ -8,26 +8,26 @@
int main(void)
{
int count = 0;
led_color_t red = {0x10, 0, 0};
int count = 0;
led_color_t red = { 0x10, 0, 0 };
card10_init();
card10_diag();
card10_init();
card10_diag();
printf("API Test.\n");
printf("core0: Starting dispatcher on core1\n");
core1_start();
TMR_Delay(MXC_TMR0, MSEC(100), 0);
printf("API Test.\n");
printf("core0: Starting dispatcher on core1\n");
core1_start();
TMR_Delay(MXC_TMR0, MSEC(100), 0);
api_set_buzzer(1);
TMR_Delay(MXC_TMR0, MSEC(300), 0);
api_set_buzzer(0);
api_set_led(5, red);
api_test(0xAB, 0x7DEF, 0x01, 0x02);
api_set_buzzer(1);
TMR_Delay(MXC_TMR0, MSEC(300), 0);
api_set_buzzer(0);
api_set_led(5, red);
api_test(0xAB, 0x7DEF, 0x01, 0x02);
while(1) {
printf("count = %d\n", count++);
while (1) {
printf("count = %d\n", count++);
TMR_Delay(MXC_TMR0, SEC(1), 0);
}
TMR_Delay(MXC_TMR0, SEC(1), 0);
}
}
......@@ -27,117 +27,114 @@
/***** Functions *****/
void print_rslt(int8_t rslt)
{
switch (rslt) {
case BMA400_OK:
/* Do nothing */
break;
case BMA400_E_NULL_PTR:
printf("Error [%d] : Null pointer\r\n", rslt);
break;
case BMA400_E_COM_FAIL:
printf("Error [%d] : Communication failure\r\n", rslt);
break;
case BMA400_E_DEV_NOT_FOUND:
printf("Error [%d] : Device not found\r\n", rslt);
break;
case BMA400_E_INVALID_CONFIG:
printf("Error [%d] : Invalid configuration\r\n", rslt);
break;
case BMA400_W_SELF_TEST_FAIL:
printf("Warning [%d] : Self test failed\r\n", rslt);
break;
default:
printf("Error [%d] : Unknown error code\r\n", rslt);
break;
}
switch (rslt) {
case BMA400_OK:
/* Do nothing */
break;
case BMA400_E_NULL_PTR:
printf("Error [%d] : Null pointer\r\n", rslt);
break;
case BMA400_E_COM_FAIL:
printf("Error [%d] : Communication failure\r\n", rslt);
break;
case BMA400_E_DEV_NOT_FOUND:
printf("Error [%d] : Device not found\r\n", rslt);
break;
case BMA400_E_INVALID_CONFIG:
printf("Error [%d] : Invalid configuration\r\n", rslt);
break;
case BMA400_W_SELF_TEST_FAIL:
printf("Warning [%d] : Self test failed\r\n", rslt);
break;
default:
printf("Error [%d] : Unknown error code\r\n", rslt);
break;
}
}
// *****************************************************************************
int main(void)
{
card10_init();
card10_diag();
card10_init();
card10_diag();
struct bma400_dev bma;
struct bma400_int_enable tap_int[2];
struct bma400_sensor_conf conf[2];
int8_t rslt;
uint32_t poll_period = 5, test_dur_ms = 30000;
uint16_t int_status;
struct bma400_dev bma;
struct bma400_int_enable tap_int[2];
struct bma400_sensor_conf conf[2];
int8_t rslt;
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;
bma.read = card10_bosch_i2c_read_ex;
bma.write = card10_bosch_i2c_write_ex;
bma.intf = BMA400_I2C_INTF;
bma.intf_ptr = NULL; /* To attach your interface device reference */
bma.delay_ms = card10_bosch_delay;
bma.dev_id = BMA400_I2C_ADDRESS_SDO_LOW;
bma.read = card10_bosch_i2c_read_ex;
bma.write = card10_bosch_i2c_write_ex;
bma.intf = BMA400_I2C_INTF;
rslt = bma400_init(&bma);
if (rslt == BMA400_OK) {
printf("BMA400 found with chip ID 0x%X\r\n", bma.chip_id);
}
rslt = bma400_init(&bma);
if (rslt == BMA400_OK) {
printf("BMA400 found with chip ID 0x%X\r\n", bma.chip_id);
}
print_rslt(rslt);
rslt = bma400_soft_reset(&bma);
print_rslt(rslt);
print_rslt(rslt);
conf[0].type = BMA400_ACCEL;
conf[1].type = BMA400_TAP_INT;
rslt = bma400_soft_reset(&bma);
print_rslt(rslt);
rslt = bma400_get_sensor_conf(conf, 2, &bma);
print_rslt(rslt);
conf[0].type = BMA400_ACCEL;
conf[1].type = BMA400_TAP_INT;
conf[0].param.accel.odr = BMA400_ODR_200HZ;
conf[0].param.accel.range = BMA400_4G_RANGE;
conf[0].param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1;
conf[0].param.accel.filt1_bw = BMA400_ACCEL_FILT1_BW_1;
rslt = bma400_get_sensor_conf(conf, 2, &bma);
print_rslt(rslt);
conf[1].param.tap.int_chan = BMA400_UNMAP_INT_PIN;
conf[1].param.tap.axes_sel = BMA400_Z_AXIS_EN_TAP;
conf[1].param.tap.sensitivity = BMA400_TAP_SENSITIVITY_0;
conf[0].param.accel.odr = BMA400_ODR_200HZ;
conf[0].param.accel.range = BMA400_4G_RANGE;
conf[0].param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1;
conf[0].param.accel.filt1_bw = BMA400_ACCEL_FILT1_BW_1;
rslt = bma400_set_sensor_conf(conf, 2, &bma);
print_rslt(rslt);
conf[1].param.tap.int_chan = BMA400_UNMAP_INT_PIN;
conf[1].param.tap.axes_sel = BMA400_Z_AXIS_EN_TAP;
conf[1].param.tap.sensitivity = BMA400_TAP_SENSITIVITY_0;
bma.delay_ms(100);
rslt = bma400_set_sensor_conf(conf, 2, &bma);
print_rslt(rslt);
tap_int[0].type = BMA400_SINGLE_TAP_INT_EN;
tap_int[0].conf = BMA400_ENABLE;
bma.delay_ms(100);
tap_int[1].type = BMA400_DOUBLE_TAP_INT_EN;
tap_int[1].conf = BMA400_ENABLE;
tap_int[0].type = BMA400_SINGLE_TAP_INT_EN;
tap_int[0].conf = BMA400_ENABLE;
rslt = bma400_enable_interrupt(tap_int, 2, &bma);
print_rslt(rslt);
tap_int[1].type = BMA400_DOUBLE_TAP_INT_EN;
tap_int[1].conf = BMA400_ENABLE;
bma.delay_ms(100);
rslt = bma400_enable_interrupt(tap_int, 2, &bma);
print_rslt(rslt);
rslt = bma400_set_power_mode(BMA400_NORMAL_MODE, &bma);
print_rslt(rslt);
bma.delay_ms(100);
bma.delay_ms(100);
rslt = bma400_set_power_mode(BMA400_NORMAL_MODE, &bma);
print_rslt(rslt);
if (rslt == BMA400_OK) {
printf("Tap configured.\r\n");
bma.delay_ms(100);
while (test_dur_ms) {
bma.delay_ms(poll_period);
if (rslt == BMA400_OK) {
printf("Tap configured.\r\n");
rslt = bma400_get_interrupt_status(&int_status, &bma);
print_rslt(rslt);
while (test_dur_ms) {
bma.delay_ms(poll_period);
if (int_status & BMA400_S_TAP_INT_ASSERTED) {
printf("Single tap detected!\r\n");
}
rslt = bma400_get_interrupt_status(&int_status, &bma);
print_rslt(rslt);
if (int_status & BMA400_D_TAP_INT_ASSERTED) {
printf("Double tap detected!\r\n");
}
if (int_status & BMA400_S_TAP_INT_ASSERTED) {
printf("Single tap detected!\r\n");
}
if (int_status & BMA400_D_TAP_INT_ASSERTED) {
printf("Double tap detected!\r\n");
}
test_dur_ms -= poll_period;
}
}
test_dur_ms -= poll_period;
}
}
}
......@@ -24,90 +24,94 @@
// *****************************************************************************
int main(void)
{
card10_init();
card10_diag();
struct bme680_dev gas_sensor;
gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
gas_sensor.intf = BME680_I2C_INTF;
gas_sensor.read = card10_bosch_i2c_read;
gas_sensor.write = card10_bosch_i2c_write;
gas_sensor.delay_ms = card10_bosch_delay;
/* amb_temp can be set to 25 prior to configuring the gas sensor
card10_init();
card10_diag();
struct bme680_dev gas_sensor;
gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
gas_sensor.intf = BME680_I2C_INTF;
gas_sensor.read = card10_bosch_i2c_read;
gas_sensor.write = card10_bosch_i2c_write;
gas_sensor.delay_ms = card10_bosch_delay;
/* amb_temp can be set to 25 prior to configuring the gas sensor
* or by performing a few temperature readings without operating the gas sensor.
*/
gas_sensor.amb_temp = 25;
int8_t rslt = BME680_OK;
rslt = bme680_init(&gas_sensor);
if(rslt != BME680_OK) {
printf("Failed to init BME680\n");
}
uint8_t set_required_settings;
/* Set the temperature, pressure and humidity settings */
gas_sensor.tph_sett.os_hum = BME680_OS_2X;
gas_sensor.tph_sett.os_pres = BME680_OS_4X;
gas_sensor.tph_sett.os_temp = BME680_OS_8X;
gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3;
/* Set the remaining gas sensor settings and link the heating profile */
gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
/* Create a ramp heat waveform in 3 steps */
gas_sensor.gas_sett.heatr_temp = 320; /* degree Celsius */
gas_sensor.gas_sett.heatr_dur = 150; /* milliseconds */
/* Select the power mode */
/* Must be set before writing the sensor configuration */
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 the desired sensor configuration */
rslt = bme680_set_sensor_settings(set_required_settings,&gas_sensor);
/* 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 );
char buf[128];
sprintf(buf, "T: %.2Lf degC", data.temperature / 100.0l);
Paint_DrawString_EN(0, 0, buf, &Font16, 0x0000, 0xffff);
sprintf(buf, "P: %.2Lf hPa", data.pressure / 100.0l);
Paint_DrawString_EN(0, 16, buf, &Font16, 0x0000, 0xffff);
sprintf(buf, "H: %.2Lf %%rH", data.humidity / 1000.0l);
Paint_DrawString_EN(0, 32, buf, &Font16, 0x0000, 0xffff);
//printf("%.2f,%.2f,%.2f\n", data.temperature / 100.0f,
// data.pressure / 100.0f, data.humidity / 1000.0f );
/* Avoid using measurements from an unstable heating setup */
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);
}
LCD_Update();
printf("\n");
/* Trigger the next measurement if you would like to read data out continuously */
if (gas_sensor.power_mode == BME680_FORCED_MODE) {
rslt = bme680_set_sensor_mode(&gas_sensor);
}
}
gas_sensor.amb_temp = 25;
int8_t rslt = BME680_OK;
rslt = bme680_init(&gas_sensor);
if (rslt != BME680_OK) {
printf("Failed to init BME680\n");
}
uint8_t set_required_settings;
/* Set the temperature, pressure and humidity settings */
gas_sensor.tph_sett.os_hum = BME680_OS_2X;
gas_sensor.tph_sett.os_pres = BME680_OS_4X;
gas_sensor.tph_sett.os_temp = BME680_OS_8X;
gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3;
/* Set the remaining gas sensor settings and link the heating profile */
gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
/* Create a ramp heat waveform in 3 steps */
gas_sensor.gas_sett.heatr_temp = 320; /* degree Celsius */
gas_sensor.gas_sett.heatr_dur = 150; /* milliseconds */
/* Select the power mode */
/* Must be set before writing the sensor configuration */
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 the desired sensor configuration */
rslt = bme680_set_sensor_settings(set_required_settings, &gas_sensor);
/* 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);
char buf[128];
sprintf(buf, "T: %.2Lf degC", data.temperature / 100.0l);
Paint_DrawString_EN(0, 0, buf, &Font16, 0x0000, 0xffff);
sprintf(buf, "P: %.2Lf hPa", data.pressure / 100.0l);
Paint_DrawString_EN(0, 16, buf, &Font16, 0x0000, 0xffff);
sprintf(buf, "H: %.2Lf %%rH", data.humidity / 1000.0l);
Paint_DrawString_EN(0, 32, buf, &Font16, 0x0000, 0xffff);
//printf("%.2f,%.2f,%.2f\n", data.temperature / 100.0f,
// data.pressure / 100.0f, data.humidity / 1000.0f );
/* Avoid using measurements from an unstable heating setup */
if (data.status & BME680_GASM_VALID_MSK) {