Skip to content

Commit

Permalink
Additional fixes and cosmetic updates for status codes
Browse files Browse the repository at this point in the history
Issue: #265
  • Loading branch information
akashkollipara committed Jan 1, 2024
1 parent 4ca5849 commit ce87773
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/driver/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ status_t driver_register(device_t *dev _UNUSED)

ret = dev->driver_setup();
(ret == success) ? syslog(pass, "Started %s\n", dev->name) :
syslog(fail, "Couldn't start %s (Err: -%p)\n", dev->name, -ret);
syslog(fail, "Couldn't start %s (Err: %p)\n", dev->name, ret);
exit:
return ret;
}
Expand Down
6 changes: 5 additions & 1 deletion src/include/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

typedef enum status
{
success = 0x0000,
success = 0x0000,
/* Generic error */
error_generic = 0x0001,
error_func_inval = 0x0002,
Expand Down Expand Up @@ -62,6 +62,7 @@ typedef enum status
error_system_irq_unlink_fail = 0x0b02,
error_system_clk_caliberation = 0x0b03,
error_system_prog_fail = 0x0b04,
error_system_inval_cpu = 0x0b05,
/* Network related error */
error_net = 0x0c00,
error_net_con_timeout = 0x0c01,
Expand All @@ -88,3 +89,6 @@ typedef enum status
error_list_node_exists = 0x1101,
error_list_node_not_found = 0x1102,
} status_t;

#define STATUS_CHECK_POINTER(x) RET_ON_FAIL(x, error_inval_pointer)
#define STATUS_CHECK_COREID(x) RET_ON_FAIL((x <= N_CORES), error_system_inval_cpu)
14 changes: 7 additions & 7 deletions src/platform/mega_avr/common/hal/adc/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static inline status_t _adc_config_vref(adc_port_t *port, adc_ref_t vref)
status_t adc_setup(adc_port_t *port)
{
status_t ret = success;
RET_ON_FAIL(port, error_inval_pointer);
STATUS_CHECK_POINTER(port);
ret |= platform_clk_en(port->clk_id);
_adc_enable(port);
ret |= _adc_set_prescaler(port);
Expand All @@ -132,7 +132,7 @@ status_t adc_setup(adc_port_t *port)
status_t adc_shutdown(adc_port_t *port)
{
status_t ret = success;
RET_ON_FAIL(port, error_inval_pointer);
STATUS_CHECK_POINTER(port);
ret |= adc_int_dis(port);
_adc_disable(port);
ret |= platform_clk_dis(port->clk_id);
Expand All @@ -149,22 +149,22 @@ bool adc_busy(adc_port_t *port)

status_t adc_int_en(adc_port_t *port)
{
RET_ON_FAIL(port, error_inval_pointer);
STATUS_CHECK_POINTER(port);
MMIO8(port->baddr + ADCSRA_OFFSET) |= (1 << ADIE);
return success;
}

status_t adc_int_dis(adc_port_t *port)
{
RET_ON_FAIL(port, error_inval_pointer);
STATUS_CHECK_POINTER(port);
MMIO8(port->baddr + ADCSRA_OFFSET) &= ~(1 << ADIE);
return success;
}

status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8_t resolution, adc_ref_t vref)
{
status_t ret = success;
RET_ON_FAIL(port, error_inval_pointer);
STATUS_CHECK_POINTER(port);
if(pin > N_ADC_PINS)
return error_func_inval_arg;
ret |= _adc_config_vref(port, vref);
Expand All @@ -178,8 +178,8 @@ status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8
status_t adc_read(adc_port_t *port, uint16_t *adc_val)
{
status_t ret = success;
RET_ON_FAIL(port, error_inval_pointer);
RET_ON_FAIL(adc_val, error_inval_pointer);
STATUS_CHECK_POINTER(port);
STATUS_CHECK_POINTER(adc_val);
if(MMIO8(port->baddr + ADMUX_OFFSET) & (1 << ADLAR))
{
*adc_val = MMIO8(port->baddr + ADCH_OFFSET);
Expand Down
13 changes: 7 additions & 6 deletions src/platform/mega_avr/common/hal/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ status_t spi_master_setup(spi_port_t *port, dataframe_format_t df_format, clk_po
status_t ret = success;
uint8_t spcr_value = 0;
gpio_port_t spi_mosi, spi_miso, spi_sck, spi_ss;
RET_ON_FAIL(port, error_inval_pointer);
STATUS_CHECK_POINTER(port);
platform_clk_en(port->clk_id);
spcr_value |= (1 << SPE) | (1 << MSTR);
switch(port->fdiv)
Expand Down Expand Up @@ -69,7 +69,7 @@ status_t spi_slave_setup(spi_port_t *port, dataframe_format_t df_format, clk_pol
status_t ret = success;
uint8_t spcr_value = 0;
gpio_port_t spi_mosi, spi_miso, spi_sck, spi_ss;
RET_ON_FAIL(port, error_inval_pointer);
STATUS_CHECK_POINTER(port);
platform_clk_en(port->clk_id);
spcr_value |= (1 << SPE);
switch(port->fdiv)
Expand Down Expand Up @@ -121,28 +121,29 @@ bool spi_trx_done(spi_port_t *port)

status_t spi_int_en(spi_port_t *port)
{
RET_ON_FAIL(port, error_inval_pointer);
STATUS_CHECK_POINTER(port);
MMIO8(port->baddr + SPCR_OFFSET) |= (1 << SPIE);
return success;
}

status_t spi_int_dis(spi_port_t * port)
{
RET_ON_FAIL(port, error_inval_pointer);
STATUS_CHECK_POINTER(port);
MMIO8(port->baddr + SPCR_OFFSET) &= ~(1 << SPIE);
return success;
}

status_t spi_tx(spi_port_t *port, char data)
{
RET_ON_FAIL(port, error_inval_pointer);
STATUS_CHECK_POINTER(port);
MMIO8(port->baddr + SPDR_OFFSET) = data;
return success;
}

status_t spi_rx(spi_port_t *port, char *data)
{
RET_ON_FAIL(port, error_inval_pointer);
STATUS_CHECK_POINTER(port);
STATUS_CHECK_POINTER(data);
*data = MMIO8(port->baddr + SPDR_OFFSET);
return success;
}
6 changes: 2 additions & 4 deletions src/platform/sifive/common_fe310/hal/clint/clint.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,15 @@ static status_t clint_exit()

status_t clint_send_softirq(size_t core_id)
{
if(core_id >= N_CORES)
return error_func_inval_arg;
STATUS_CHECK_COREID(core_id);
MMIO32(port->baddr + MSIP_OFFSET(core_id)) = 1;
arch_dsb();
return success;
}

status_t clint_config_tcmp(size_t core_id, uint64_t value)
{
if(core_id >= N_CORES)
return error_func_inval_arg;
STATUS_CHECK_COREID(core_id);
MMIO64(port->baddr + MTCMP_OFFSET(core_id)) = value;
arch_dsb();
return success;
Expand Down
4 changes: 2 additions & 2 deletions src/visor/terravisor/services/driver/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ status_t timer_release_device()
* programs to link timer event call back functions.
*
* @brief This is a helper function which lets other programs to link
* timer event call back functions. It allows to link onlt 1 callback
* which will be exeuted as part of timer ISR handler.
* timer event call back functions. It allows to link only 1 callback
* which will be executed as part of timer ISR handler.
*
* @param[in] p: period of timer irq
* @param[in] cb: call back function pointer
Expand Down

0 comments on commit ce87773

Please sign in to comment.