contrib/firmware/angie: add dev-board power detection
Add a check if i2c SDA pin state is HIGH. if its HIGH, the dev-board is ON, we receive number of Ack. in its LOW, the board is OFF, we send this information back to driver. Change-Id: Ia40d3910675cc10e0208d8bc0060a19c12b1409d Signed-off-by: Ahmed BOUDJELIDA <aboudjelida@nanoxplore.com> Reviewed-on: https://review.openocd.org/c/openocd/+/8716 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
committed by
Antonio Borneo
parent
ceaa47a2aa
commit
9a150e326a
@@ -14,6 +14,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
bool get_status(void);
|
||||||
void start_cd(void);
|
void start_cd(void);
|
||||||
void repeated_start(void);
|
void repeated_start(void);
|
||||||
void stop_cd(void);
|
void stop_cd(void);
|
||||||
|
|||||||
@@ -12,6 +12,19 @@
|
|||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
#include "reg_ezusb.h"
|
#include "reg_ezusb.h"
|
||||||
|
|
||||||
|
bool get_status(void)
|
||||||
|
{
|
||||||
|
PIN_SDA_DIR = 1;
|
||||||
|
OEA = 0xF7;
|
||||||
|
delay_us(1);
|
||||||
|
bool sda_state = PIN_SDA;
|
||||||
|
PIN_T0 = sda_state;
|
||||||
|
delay_us(1);
|
||||||
|
OEA = 0xFF;
|
||||||
|
delay_us(1);
|
||||||
|
return sda_state;
|
||||||
|
}
|
||||||
|
|
||||||
void start_cd(void)
|
void start_cd(void)
|
||||||
{
|
{
|
||||||
PIN_SDA_DIR = 0; // SP6 SDA: OUT
|
PIN_SDA_DIR = 0; // SP6 SDA: OUT
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
#include "serial.h"
|
||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
#include "reg_ezusb.h"
|
#include "reg_ezusb.h"
|
||||||
#include <serial.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
extern void sudav_isr(void)__interrupt SUDAV_ISR;
|
extern void sudav_isr(void)__interrupt SUDAV_ISR;
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ __code struct usb_config_descriptor config_descriptor = {
|
|||||||
((NUM_ENDPOINTS * 2) * sizeof(struct usb_endpoint_descriptor)),
|
((NUM_ENDPOINTS * 2) * sizeof(struct usb_endpoint_descriptor)),
|
||||||
.bnuminterfaces = 2,
|
.bnuminterfaces = 2,
|
||||||
.bconfigurationvalue = 1,
|
.bconfigurationvalue = 1,
|
||||||
.iconfiguration = 4, /* String describing this configuration */
|
.iconfiguration = 2, /* String describing this configuration */
|
||||||
.bmattributes = 0x80, /* Only MSB set according to USB spec */
|
.bmattributes = 0x80, /* Only MSB set according to USB spec */
|
||||||
.maxpower = 50 /* 100 mA */
|
.maxpower = 50 /* 100 mA */
|
||||||
};
|
};
|
||||||
@@ -69,7 +69,7 @@ __code struct usb_interface_descriptor interface_descriptor00 = {
|
|||||||
.binterfaceclass = 0XFF,
|
.binterfaceclass = 0XFF,
|
||||||
.binterfacesubclass = 0x00,
|
.binterfacesubclass = 0x00,
|
||||||
.binterfaceprotocol = 0x00,
|
.binterfaceprotocol = 0x00,
|
||||||
.iinterface = 5
|
.iinterface = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
__code struct usb_endpoint_descriptor bulk_ep2_endpoint_descriptor = {
|
__code struct usb_endpoint_descriptor bulk_ep2_endpoint_descriptor = {
|
||||||
@@ -99,7 +99,7 @@ __code struct usb_interface_descriptor interface_descriptor01 = {
|
|||||||
.binterfaceclass = 0x0A,
|
.binterfaceclass = 0x0A,
|
||||||
.binterfacesubclass = 0x00,
|
.binterfacesubclass = 0x00,
|
||||||
.binterfaceprotocol = 0x00,
|
.binterfaceprotocol = 0x00,
|
||||||
.iinterface = 6
|
.iinterface = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
__code struct usb_endpoint_descriptor bulk_ep6_out_endpoint_descriptor = {
|
__code struct usb_endpoint_descriptor bulk_ep6_out_endpoint_descriptor = {
|
||||||
@@ -761,16 +761,16 @@ void ep_init(void)
|
|||||||
|
|
||||||
void i2c_recieve(void)
|
void i2c_recieve(void)
|
||||||
{
|
{
|
||||||
PIN_SDA_DIR = 0;
|
|
||||||
if (EP6FIFOBUF[0] == 1) {
|
if (EP6FIFOBUF[0] == 1) {
|
||||||
uint8_t rdwr = EP6FIFOBUF[0]; //read
|
uint8_t rdwr = EP6FIFOBUF[0]; //read: 1
|
||||||
uint8_t data_count = EP6FIFOBUF[1]; //data sent count
|
uint8_t reg_byte_check = EP6FIFOBUF[1]; //register given: 1 else: 0
|
||||||
uint8_t count = EP6FIFOBUF[2]; //requested data count
|
uint8_t count = EP6FIFOBUF[2]; //requested data count
|
||||||
uint8_t adr = EP6FIFOBUF[3]; //address
|
uint8_t adr = EP6FIFOBUF[3]; //address
|
||||||
uint8_t address = get_address(adr, rdwr); //address byte (read command)
|
uint8_t address = get_address(adr, rdwr); //address byte (read command)
|
||||||
uint8_t address_2 = get_address(adr, 0); //address byte 2 (write command)
|
uint8_t address_2 = get_address(adr, 0); //address byte 2 (write command)
|
||||||
|
|
||||||
printf("%d\n", address - 1);
|
/* i2c bus state byte */
|
||||||
|
EP8FIFOBUF[0] = get_status();
|
||||||
|
|
||||||
/* start: */
|
/* start: */
|
||||||
start_cd();
|
start_cd();
|
||||||
@@ -780,13 +780,11 @@ void i2c_recieve(void)
|
|||||||
uint8_t ack = get_ack();
|
uint8_t ack = get_ack();
|
||||||
|
|
||||||
/* send data */
|
/* send data */
|
||||||
if (data_count) { //if there is a byte reg
|
for (int i = 0; i < reg_byte_check; i++) {
|
||||||
for (uint8_t i = 0; i < data_count; i++) {
|
|
||||||
send_byte(EP6FIFOBUF[i + 4]);
|
send_byte(EP6FIFOBUF[i + 4]);
|
||||||
/* ack(): */
|
/* ack(): */
|
||||||
ack = get_ack();
|
ack = get_ack();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* repeated start: */
|
/* repeated start: */
|
||||||
repeated_start();
|
repeated_start();
|
||||||
@@ -796,14 +794,14 @@ void i2c_recieve(void)
|
|||||||
ack = get_ack();
|
ack = get_ack();
|
||||||
|
|
||||||
/* receive data */
|
/* receive data */
|
||||||
for (uint8_t i = 0; i < count - 1; i++) {
|
for (int i = 1; i < count; i++) {
|
||||||
EP8FIFOBUF[i] = receive_byte();
|
EP8FIFOBUF[i] = receive_byte();
|
||||||
|
|
||||||
/* send ack: */
|
/* send ack: */
|
||||||
send_ack();
|
send_ack();
|
||||||
}
|
}
|
||||||
|
|
||||||
EP8FIFOBUF[count - 1] = receive_byte();
|
EP8FIFOBUF[count] = receive_byte();
|
||||||
|
|
||||||
/* send Nack: */
|
/* send Nack: */
|
||||||
send_nack();
|
send_nack();
|
||||||
@@ -811,20 +809,23 @@ void i2c_recieve(void)
|
|||||||
/* stop */
|
/* stop */
|
||||||
stop_cd();
|
stop_cd();
|
||||||
|
|
||||||
EP8BCH = 0; //EP8
|
EP8BCH = (count + 1) >> 8; //EP8
|
||||||
syncdelay(3);
|
syncdelay(3);
|
||||||
EP8BCL = count; //EP8
|
EP8BCL = count + 1; //EP8
|
||||||
|
|
||||||
EP6BCL = 0x80; //EP6
|
EP6BCL = 0x80; //EP6
|
||||||
syncdelay(3);
|
syncdelay(3);
|
||||||
EP6BCL = 0x80; //EP6
|
EP6BCL = 0x80; //EP6
|
||||||
} else {
|
} else {
|
||||||
uint8_t rdwr = EP6FIFOBUF[0]; //write
|
uint8_t rdwr = EP6FIFOBUF[0]; //write: 0
|
||||||
uint8_t count = EP6FIFOBUF[1]; //data count
|
uint8_t count = EP6FIFOBUF[1]; //data count
|
||||||
uint8_t adr = EP6FIFOBUF[2]; //address
|
uint8_t adr = EP6FIFOBUF[2]; //address
|
||||||
uint8_t address = get_address(adr, rdwr); //address byte (read command)
|
uint8_t address = get_address(adr, rdwr); //address byte (read command)
|
||||||
uint8_t ack_cnt = 0;
|
uint8_t ack_cnt = 0;
|
||||||
|
|
||||||
|
// i2c bus state byte
|
||||||
|
EP8FIFOBUF[0] = get_status();
|
||||||
|
|
||||||
/* start(): */
|
/* start(): */
|
||||||
start_cd();
|
start_cd();
|
||||||
/* address: */
|
/* address: */
|
||||||
@@ -833,9 +834,8 @@ void i2c_recieve(void)
|
|||||||
if (!get_ack())
|
if (!get_ack())
|
||||||
ack_cnt++;
|
ack_cnt++;
|
||||||
/* send data */
|
/* send data */
|
||||||
for (uint8_t i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
send_byte(EP6FIFOBUF[i + 3]);
|
send_byte(EP6FIFOBUF[i + 3]);
|
||||||
|
|
||||||
/* get ack: */
|
/* get ack: */
|
||||||
if (!get_ack())
|
if (!get_ack())
|
||||||
ack_cnt++;
|
ack_cnt++;
|
||||||
@@ -844,11 +844,11 @@ void i2c_recieve(void)
|
|||||||
/* stop */
|
/* stop */
|
||||||
stop_cd();
|
stop_cd();
|
||||||
|
|
||||||
EP8FIFOBUF[0] = ack_cnt;
|
EP8FIFOBUF[1] = ack_cnt;
|
||||||
|
|
||||||
EP8BCH = 0; //EP8
|
EP8BCH = 0; //EP8
|
||||||
syncdelay(3);
|
syncdelay(3);
|
||||||
EP8BCL = 1; //EP8
|
EP8BCL = 2; //EP8
|
||||||
|
|
||||||
EP6BCL = 0x80; //EP6
|
EP6BCL = 0x80; //EP6
|
||||||
syncdelay(3);
|
syncdelay(3);
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user