Skip to content

Commit

Permalink
Merge pull request #57 from WattRex/feature/HAL_SYS
Browse files Browse the repository at this point in the history
Feature/hal sys
  • Loading branch information
pastorpflores authored Jun 12, 2023
2 parents 916104e + 0ef5a66 commit 2001eb2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
60 changes: 31 additions & 29 deletions firmware/Sources/HAL/HAL_SYS/hal_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,49 +100,47 @@ HAL_SYS_result_e HAL_SysInit(void){
}else{

/* Initialize all configured peripherals */
#ifdef EPC_CONF_PWM_ENABLED
if (HAL_PwmInit() != HAL_PWM_RESULT_SUCCESS){
res = HAL_SYS_RESULT_ERROR_CRIT;
}else{
#endif

#ifdef EPC_CONF_GPIO_ENABLED
if(HAL_GpioInit() != HAL_GPIO_RESULT_SUCCESS){
res = HAL_SYS_RESULT_ERROR_GPIO;
res = HAL_SYS_RESULT_ERROR_CRIT;
}else{
#endif

#ifdef EPC_CONF_ADC_DMA_ENABLED
if(HAL_AdcInit() != HAL_ADC_RESULT_SUCCESS){
res = HAL_SYS_RESULT_ERROR_ADC;
// TODO: add dma
#ifdef EPC_CONF_CAN_ENABLED
if (HAL_CanInit() != HAL_CAN_RESULT_SUCCESS){
res = HAL_SYS_RESULT_ERROR_COMM;
}else{
#endif

#ifdef EPC_CONF_STS_ENABLED
if (HAL_StsInit () != HAL_STS_RESULT_SUCCESS){
res |= HAL_SYS_RESULT_ERROR_STS;
}
else{
#endif

#ifdef EPC_CONF_TMR_ENABLED
HAL_TMR_result_e tmr_res = HAL_TmrInit(HAL_TMR_CLOCK_RT);
tmr_res |= HAL_TmrInit(HAL_TMR_CLOCK_PWR_MEAS);
if (tmr_res != HAL_TMR_RESULT_SUCCESS){
res = HAL_SYS_RESULT_ERROR_CRIT;
res = HAL_SYS_RESULT_ERROR_CRIT_PERIPH;
}else{
#endif

#ifdef EPC_CONF_CAN_ENABLED
if (HAL_CanInit() != HAL_CAN_RESULT_SUCCESS){
res = HAL_SYS_RESULT_ERROR_COMM;
#ifdef EPC_CONF_ADC_DMA_ENABLED
if(HAL_AdcInit() != HAL_ADC_RESULT_SUCCESS){
res = HAL_SYS_RESULT_ERROR_CRIT_PERIPH;
}else{
#endif

#ifdef EPC_CONF_PWM_ENABLED
if (HAL_PwmInit() != HAL_PWM_RESULT_SUCCESS){
res = HAL_SYS_RESULT_ERROR_CRIT_PERIPH;
}else{
#endif

#ifdef EPC_CONF_STS_ENABLED
if (HAL_StsInit () != HAL_STS_RESULT_SUCCESS){
res |= HAL_SYS_RESULT_ERROR_CRIT_PERIPH;
} else{
#endif

#ifdef EPC_CONF_WDG_ENABLED
if (HAL_WdgInit() != HAL_WDG_RESULT_SUCCESS){
res = HAL_SYS_RESULT_ERROR_COMM;
res = HAL_SYS_RESULT_ERROR_CRIT_PERIPH;
}else{
#endif

Expand All @@ -151,27 +149,27 @@ HAL_SYS_result_e HAL_SysInit(void){
}
#endif

#ifdef EPC_CONF_CAN_ENABLED
#ifdef EPC_CONF_STS_ENABLED
}
#endif

#ifdef EPC_CONF_TMR_ENABLED
#ifdef EPC_CONF_PWM_ENABLED
}
#endif

#ifdef EPC_CONF_STS_ENABLED
#ifdef EPC_CONF_ADC_DMA_ENABLED
}
#endif

#ifdef EPC_CONF_ADC_DMA_ENABLED
#ifdef EPC_CONF_TMR_ENABLED
}
#endif

#ifdef EPC_CONF_GPIO_ENABLED
#ifdef EPC_CONF_CAN_ENABLED
}
#endif

#ifdef EPC_CONF_PWM_ENABLED
#ifdef EPC_CONF_GPIO_ENABLED
}
#endif

Expand All @@ -180,6 +178,10 @@ HAL_SYS_result_e HAL_SysInit(void){
return res;
}

void HAL_SysResume(void){
HAL_ResumeTick();
}

HAL_SYS_result_e HAL_SysPwrMode(const HAL_SYS_mode_e mode){
HAL_SYS_result_e res = HAL_SYS_RESULT_SUCCESS;
if(mode == HAL_SYS_MODE_SLEEP){
Expand Down
16 changes: 10 additions & 6 deletions firmware/Sources/HAL/HAL_SYS/hal_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ typedef enum
*/
typedef enum
{
HAL_SYS_RESULT_SUCCESS = 0x0U, /**< HAL_SYS success operation result **/
HAL_SYS_RESULT_ERROR_GPIO = 0x01U, /**< HAL_SYS error on GPIO operation **/
HAL_SYS_RESULT_ERROR_ADC = 0x02U, /**< HAL_SYS error on ADC operation **/
HAL_SYS_RESULT_ERROR_STS = 0x03U, /**< HAL_SYS error on I2C operation **/
HAL_SYS_RESULT_ERROR_COMM = 0x04U, /**< HAL_SYS error on communication process, CAN or UART **/
HAL_SYS_RESULT_ERROR_CRIT = 0x05U, /**< HAL_SYS critical error result **/
HAL_SYS_RESULT_SUCCESS = 0x0U, /**< HAL_SYS success operation result **/
HAL_SYS_RESULT_ERROR_CRIT = 0x01U, /**< HAL_SYS critical error result **/
HAL_SYS_RESULT_ERROR_CAN = 0x02U, /**< HAL_SYS error on communication process, CAN **/
HAL_SYS_RESULT_ERROR_CRIT_PERIPH = 0x03U, /**< HAL_SYS error on operation with critical peripherals **/
}HAL_SYS_result_e;


Expand Down Expand Up @@ -84,6 +82,12 @@ typedef enum
*/
HAL_SYS_result_e HAL_SysInit(void);

/**
* @fn void HAL_SysResume(void)
* @brief Resume the uC after a low power mode
* */
void HAL_SysResume(void);

/**
* @fn HAL_SYS_result_e HAL_SysPwrMode(HAL_SYS_mode_e)
* @brief The micro enters on power save mode.
Expand Down

0 comments on commit 2001eb2

Please sign in to comment.