Sonochan II 0.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
brd_driver_hw_03.c File Reference

Board driver for "Sonochan mkII" HW version 03. More...

`#include "brd_driver_hw_03.h"`

## Macros
#define | BRD_DRV_MAX_CMD_ID 10
| Maximum command ID (is defined by last command) More...
#define | BRD_DRV_ADC_SAVE_VOL_MIN 320
| Define ADC level when on connector side is save voltage (minimum) More...
#define | BRD_DRV_ADC_HIGH_VOL_MIN 42
| Define ADC level when on connector side is high voltage. More...

## Functions
GD_RES_CODE | brd_drv_TLV_default (void)
| Set TLV codec to default configuration. More...
GD_RES_CODE | brd_drv_adc_init (void)
| Prepare ADC. More...
void | brd_drv_process_mute_button (void)
| Easily process MUTE_BTN signal. More...
void | brd_drv_process_mute_signal (void)
| Scan MUTE signal. More...
void | brd_drv_process_rst_i2s_button (void)
| Scan RESET_I2S_BTN and set/clear reset I2S signals. More...
void | brd_drv_process_rst_i2s_signal (void)
| Scan RESET_I2S signal. More...
void | brd_drv_task_FreeRTOS (void *pvParameters)
| Board driver FreeRTOS task. More...
GD_RES_CODE | brd_drv_pre_init (void)
| Initialization that MUST be done as soon as possible. More...
GD_RES_CODE | brd_drv_init (void)
| Basic initialization of board components. More...
void | brd_drv_task (void)
| Board driver task. Watch ADC and buttons. More...
GD_RES_CODE | brd_drv_reset_i2s (void)
| Preset I2S connector to default state. Also reset codec. More...
GD_RES_CODE | brd_drv_show_volume (void)
| Show volume value on LCD. More...
void | brd_drv_send_msg (const char *p_msg, uint8_t i_write_to_DBG, uint8_t i_write_to_LCD, uint8_t i_LCD_line)
| Write message to selected outputs. More...
GD_RES_CODE | brd_drv_draw_logo (void)
| Draw Sonochan mk II logo on display. More...
void | brd_drv_send_warning_msg (const char *p_msg, uint8_t i_write_to_DBG, uint8_t i_write_to_LCD)
| Write warning message. More...
void | brd_drv_send_error_msg (const char *p_msg, uint8_t i_write_to_DBG, uint8_t i_write_to_LCD)
| Write error message and turn on ERROR LED. More...
GD_RES_CODE | brd_drv_set_isolators_to_HiZ (void)
| Set pins, that control signal direction at digital isolators, to low. More...
GD_RES_CODE | brd_drv_set_mute_dir (e_brd_drv_dir_t e_mute_dir)
| Allow set MUTE pin direction. More...
GD_RES_CODE | brd_drv_set_mute (uint8_t i_mute_flag)
| Set mute flag. More...
GD_RES_CODE | brd_drv_set_rst_i2s_dir (e_brd_drv_dir_t e_rst_i2s_dir)
| Allow set RESET_I2S pin direction. More...
GD_RES_CODE | brd_drv_set_rst_i2s (uint8_t i_reset_i2s_flag)
| Set RESET_I2S pin if configured as output. More...
GD_RES_CODE | brd_drv_set_tx_data_dir (e_brd_drv_dir_t e_tx_data_dir)
| Set TX_DATA direction (OUT/Hi-Z) More...
GD_RES_CODE | brd_drv_set_rx_data_dir (e_brd_drv_dir_t e_rx_data_dir)
| Set RX_DATA direction (IN/Hi-Z) More...
GD_RES_CODE | brd_drv_set_mclk_dir (e_brd_drv_dir_t e_mclk_dir)
| Set direction of MCLK. More...
GD_RES_CODE | brd_drv_set_bclk_dir (e_brd_drv_dir_t e_bclk_dir)
| Set BCLK direction. More...
GD_RES_CODE | brd_drv_set_frame_sync_dir (e_brd_drv_dir_t e_frame_sync_dir)
| Set direction of FRAME_SYNC. More...

## Variables
static s_brd_drv_mute_t | s_brd_drv_mute
| Mute structure. More...
static s_brd_drv_rst_i2s_t | s_brd_drv_rst_i2s
| Reset I2S structure. More...
static s_brd_drv_pure_i2s_dir_t | s_brd_drv_pure_i2s_dir
| Store directions for MCLK, BCLK, FRAME_SYNC, TX_DATA, RX_DATA. More...
static uint8_t | i_error_occurred
| Store information if error occurred. More...
const gd_config_struct | BRD_DRV_config_table []
| Configure table for device. More...
const gd_metadata | BRD_DRV_metadata
portBASE_TYPE | xStatus
xSemaphoreHandle | mutexADC

## Detailed Description

Board driver for "Sonochan mkII" HW version 03.

Allow set basic settings on board. Also support "generic driver"

Created: 23.04.2014
Modified: 07.05.2014

Version
  0.1

Author
  Martin Stejskal

## Macro Definition Documentation

#define BRD_DRV_ADC_HIGH_VOL_MIN 42

Define ADC level when on connector side is high voltage.

#define BRD_DRV_ADC_SAVE_VOL_MIN 320

Define ADC level when on connector side is save voltage (minimum)

#define BRD_DRV_MAX_CMD_ID 10

Maximum command ID (is defined by last command)

## Function Documentation

GD_RES_CODE brd_drv_adc_init | ( | void | ) |  |
| inline

Prepare ADC.

Set I/O, enable clock to ADC module (thru PM), reset ADC settings, set
active channels, prescaller and so on.

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE brd_drv_draw_logo | ( | void | ) |  |
| inline

Draw Sonochan mk II logo on display.

Function assume, that LCD_init() od LCD_clear() was called

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE brd_drv_init | ( | void | ) |  |

Basic initialization of board components.

This function initialize rest of hardware on board. It assume, that debug
print output, clock and I/O pins have been initialized by
brd_drv_pre_init() function.

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_pre_init | ( | void | ) |  |

Initialization that MUST be done as soon as possible.

Because some parts should be set as soon as possible (I/O pins, set clock
for MCU) this function should be called in main on first line.

Returns
  GD_SUCCESS (0) if all right

void brd_drv_process_mute_button | ( | void | ) |  |
| inline

Easily process MUTE_BTN signal.

Process only if changes on button (rising/falling edge)

void brd_drv_process_mute_signal | ( | void | ) |  |
| inline

Scan MUTE signal.

Process only if rising/falling edge

void brd_drv_process_rst_i2s_button | ( | void | ) |  |
| inline

Scan RESET_I2S_BTN and set/clear reset I2S signals.

void brd_drv_process_rst_i2s_signal | ( | void | ) |  |
| inline

Scan RESET_I2S signal.

Process only if rising/falling edge

GD_RES_CODE brd_drv_reset_i2s | ( | void | ) |  |

Preset I2S connector to default state. Also reset codec.

Returns
  GD_SUCCESS (0) if all OK

Todo:
  Complete this function. it need functions to set I/O for isolators

void brd_drv_send_error_msg | ( | const char * | p_msg,
|  | uint8_t | i_write_to_DBG,
|  | uint8_t | i_write_to_LCD
| ) |  |
| inline

Write error message and turn on ERROR LED.

Function do not return any return code. Just hope, that everything else
will work.

Parameters

  p_msg | Pointer to message
  i_write_to_DBG | Options: 0 - do not write to debug output ; 1 - write to debug output
  i_write_to_LCD | 0 - do not write to LCD ; 1 - write to LCD

void brd_drv_send_msg | ( | const char * | p_msg,
|  | uint8_t | i_write_to_DBG,
|  | uint8_t | i_write_to_LCD,
|  | uint8_t | i_LCD_line
| ) |  |
| inline

Write message to selected outputs.

Function do not return any return code. Just hope, that everything
will work.

Parameters

  p_msg | Pointer to message
  i_write_to_DBG | Options: 0 - do not write to debug output ; 1 - write to debug output
  i_write_to_LCD | 0 - do not write to LCD ; 1 - write to LCD
  i_LCD_line | Define on which line should be message placed. If value is 255 (-1), or invalid (higher than 5) then just write message message on the following line.

void brd_drv_send_warning_msg | ( | const char * | p_msg,
|  | uint8_t | i_write_to_DBG,
|  | uint8_t | i_write_to_LCD
| ) |  |
| inline

Write warning message.

When writing warning message on LCD, then is there reserved 2 lines for
message. It can be longer, but 2 lines will be cleared. First line is
defined in .h file as BRD_DRV_LCD_WARN_MSG_LINE

Parameters

  p_msg | Pointer to message
  i_write_to_DBG | Options: 0 - do not write to debug output ; 1 - write to debug output
  i_write_to_LCD | 0 - do not write to LCD ; 1 - write to LCD

GD_RES_CODE brd_drv_set_bclk_dir | ( | e_brd_drv_dir_t | e_bclk_dir) |  |

Set BCLK direction.

Parameters

  e_bclk_dir | Options: 0 (input) ; 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_frame_sync_dir | ( | e_brd_drv_dir_t | e_frame_sync_dir) |  |

Set direction of FRAME_SYNC.

Parameters

  e_frame_sync_dir | Options: 0 (input) ; 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_isolators_to_HiZ | ( | void | ) |  |

Set pins, that control signal direction at digital isolators, to low.

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE brd_drv_set_mclk_dir | ( | e_brd_drv_dir_t | e_mclk_dir) |  |

Set direction of MCLK.

Parameters

  e_mclk_dir | Options: 0 (input) ; 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_mute | ( | uint8_t | i_mute_flag) |  |

Set mute flag.

If signal MUTE is input, then just MUTE MCU output. If MUTE signal is
output then set MUTE signal and MUTE MCU output.

Parameters

  i_mute_flag | 0 - mute off ; 1 - mute on

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE brd_drv_set_mute_dir | ( | e_brd_drv_dir_t | e_mute_dir) |  |

Allow set MUTE pin direction.

Parameters

  e_mute_dir | Options: 0 (input) ; 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_rst_i2s | ( | uint8_t | i_reset_i2s_flag) |  |

Set RESET_I2S pin if configured as output.

If signal RESET_I2S is set as output, then just set signal RESET_I2S.
If signal RESET_I2S is set as input, then reset I2S bus on AVR side.

Parameters

  i_reset_i2s_flag | 0 - disable ; 1 - enable reset

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_rst_i2s_dir | ( | e_brd_drv_dir_t | e_rst_i2s_dir) |  |

Allow set RESET_I2S pin direction.

Parameters

  e_rst_i2s_dir | Options: 0 (input) ; 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_rx_data_dir | ( | e_brd_drv_dir_t | e_rx_data_dir) |  |

Set RX_DATA direction (IN/Hi-Z)

Parameters

  e_rx_data_dir | Options: 0 (input) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE brd_drv_set_tx_data_dir | ( | e_brd_drv_dir_t | e_tx_data_dir) |  |

Set TX_DATA direction (OUT/Hi-Z)

Long story short: allow set as output or Hi-Z.

Parameters

  e_tx_data_dir | Options: 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE brd_drv_show_volume | ( | void | ) |  |
| inline

Show volume value on LCD.

Returns
  GD_SUCCESS (0) if all right

void brd_drv_task | ( | void | ) |  |

Board driver task. Watch ADC and buttons.

If detected some change, then start processing. Else return

void brd_drv_task_FreeRTOS | ( | void * | pvParameters) |  |

Board driver FreeRTOS task.

Instead of complicating brd_drv_task() we just make function, that is ready
for FreeRTOS stuff, so code will be still easy to use.

GD_RES_CODE brd_drv_TLV_default | ( | void | ) |  |
| inline

Set TLV codec to default configuration.

Returns
  GD_SUCCESS (0) if all OK

## Variable Documentation

const gd_config_struct BRD_DRV_config_table[]

Configure table for device.

const gd_metadata BRD_DRV_metadata

Initial value:
=
{
BRD_DRV_MAX_CMD_ID,
"Board driver for Sonochan mkII v0.1",
(gd_config_struct*)&BRD_DRV_config_table[0],
0x0F
}

uint8_t i_error_occurred
| static

Store information if error occurred.

Values: 0 - not error ; else error occurred

xSemaphoreHandle mutexADC

s_brd_drv_mute_t s_brd_drv_mute
| static

Mute structure.

Contains mute direction and mute value

s_brd_drv_pure_i2s_dir_t s_brd_drv_pure_i2s_dir
| static

Store directions for MCLK, BCLK, FRAME_SYNC, TX_DATA, RX_DATA.

s_brd_drv_rst_i2s_t s_brd_drv_rst_i2s
| static

Reset I2S structure.

Contains reset I2S direction and value

portBASE_TYPE xStatus