Added a function to set the multiplexer input line.

This commit is contained in:
klaute 2016-08-23 09:48:37 +02:00
parent 46a5668818
commit 728e2af5bf
4 changed files with 98 additions and 0 deletions

View file

@ -24,24 +24,28 @@
void cc_setBaudrate(void);
void cc_getBaudrate(void);
void cc_setMuxLine(void);
void cc_startBootloader(void);
/*****************************************************************************/
#define CC_CMD_SET_BAUDRATE 0x0A
#define CC_CMD_GET_BAUDRATE 0x14
#define CC_CMD_SET_MUX_LINE 0x1E
#define CC_CMD_START_BTLDR 0x32
/*****************************************************************************/
#define CC_CMD_SET_BAUDRATE_FUNC &cc_setBaudrate
#define CC_CMD_GET_BAUDRATE_FUNC &cc_getBaudrate
#define CC_CMD_SET_MUX_LINE_FUNC &cc_setMuxLine
#define CC_CMD_START_BTLDR_FUNC &cc_startBootloader
/*****************************************************************************/
#define CC_CMD_SET_BAUDRATE_DATA_TO_READ 4 // set baudrate
#define CC_CMD_GET_BAUDRATE_DATA_TO_READ 0 // get baudrate
#define CC_CMD_SET_MUX_LINE_DATA_TO_READ 1 // set mux line
#define CC_CMD_START_BTLDR_DATA_TO_READ 0 // start bootloader
/*****************************************************************************/
@ -53,18 +57,21 @@ void cc_startBootloader(void);
uint8_t cc_commands[] = {
CC_CMD_SET_BAUDRATE,
CC_CMD_GET_BAUDRATE,
CC_CMD_SET_MUX_LINE,
CC_CMD_START_BTLDR,
};
void (*cc_cmd_functions[])() = {
CC_CMD_SET_BAUDRATE_FUNC,
CC_CMD_GET_BAUDRATE_FUNC,
CC_CMD_SET_MUX_LINE_FUNC,
CC_CMD_START_BTLDR_FUNC,
};
uint8_t cc_cmd_data_to_read[] = {
CC_CMD_SET_BAUDRATE_DATA_TO_READ,
CC_CMD_GET_BAUDRATE_DATA_TO_READ,
CC_CMD_SET_MUX_LINE_DATA_TO_READ,
CC_CMD_START_BTLDR_DATA_TO_READ,
};

View file

@ -60,3 +60,47 @@ void cc_startBootloader()
/*****************************************************************************/
void cc_setMuxLine()
{
switch(cc_read_data[0])
{
case 0:;
EN_MUX_LINE0;
break;
case 1:;
EN_MUX_LINE1;
break;
case 2:;
EN_MUX_LINE2;
break;
case 3:;
EN_MUX_LINE3;
break;
case 4:;
EN_MUX_LINE4;
break;
case 5:;
EN_MUX_LINE5;
break;
case 6:;
EN_MUX_LINE6;
break;
case 7:;
EN_MUX_LINE7;
break;
default:;
EN_MUX_LINE0;
char* sBody = " ";
sprintf(sBody, "%c%c%c%c%c", MSG_SOM1, MSG_SOM2, MSG_TYPE_ANSWER_NOK, MSG_EOM1, MSG_EOM2);
USB_serialStreamWriteC(sBody, strlen(sBody));
return;
}
char* sBody = " ";
sprintf(sBody, "%c%c%c%c%c", MSG_SOM1, MSG_SOM2, MSG_TYPE_ANSWER_OK, MSG_EOM1, MSG_EOM2);
USB_serialStreamWriteC(sBody, strlen(sBody));
}
/*****************************************************************************/

View file

@ -11,5 +11,47 @@
#define MSG_TYPE_ANSWER_NOK 0x02
#define MSG_TYPE_BAUDRATE 0x03
/*****************************************************************************/
#define EN_MUX_LINE0 \
PORTB &= ~(1 << PIN4); \
PORTB &= ~(1 << PIN5); \
PORTB &= ~(1 << PIN6); \
#define EN_MUX_LINE1 \
PORTB &= ~(1 << PIN4); \
PORTB &= ~(1 << PIN5); \
PORTB |= (1 << PIN6); \
#define EN_MUX_LINE2 \
PORTB &= ~(1 << PIN4); \
PORTB |= (1 << PIN5); \
PORTB &= ~(1 << PIN6); \
#define EN_MUX_LINE3 \
PORTB &= ~(1 << PIN4); \
PORTB |= (1 << PIN5); \
PORTB |= (1 << PIN6); \
#define EN_MUX_LINE4 \
PORTB |= (1 << PIN4); \
PORTB &= ~(1 << PIN5); \
PORTB &= ~(1 << PIN6); \
#define EN_MUX_LINE5 \
PORTB |= (1 << PIN4); \
PORTB &= ~(1 << PIN5); \
PORTB |= (1 << PIN6); \
#define EN_MUX_LINE6 \
PORTB |= (1 << PIN4); \
PORTB |= (1 << PIN5); \
PORTB &= ~(1 << PIN6); \
#define EN_MUX_LINE7 \
PORTB |= (1 << PIN4); \
PORTB |= (1 << PIN5); \
PORTB |= (1 << PIN6); \
/*****************************************************************************/

View file

@ -126,6 +126,11 @@ void SetupHardware(void)
PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
#endif
// set the three MUX control lines to output
DDRB |= (1 << PIN4) | (1 << PIN5) | (1 << PIN6);
// set every pin to low
EN_MUX_LINE0;
/* UART Hardware Initialization */
uart_init( UART_BAUD_SELECT(baudrate, F_CPU) );