-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
General changes - CAN, light codes #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ | |
* quanta which means the bit rate is 8MHz / 16 = 500KHz. | ||
*/ | ||
/* Nominal bit Baud Rate Prescaler */ | ||
#define CONF_CAN_NBTP_NBRP_VALUE 5 | ||
#define CONF_CAN_NBTP_NBRP_VALUE 1//This value has been changes from 5 to 1 | ||
/* Nominal bit (Re)Synchronization Jump Width */ | ||
#define CONF_CAN_NBTP_NSJW_VALUE 3 | ||
/* Nominal bit Time segment before sample point */ | ||
|
@@ -85,7 +85,7 @@ | |
* quanta which means the bit rate is 8MHz / 16 = 500KHz. | ||
*/ | ||
/* Data bit Baud Rate Prescaler */ | ||
#define CONF_CAN_DBTP_DBRP_VALUE 5 | ||
#define CONF_CAN_DBTP_DBRP_VALUE 1//This value has been changes from 5 to 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
/* Data bit (Re)Synchronization Jump Width */ | ||
#define CONF_CAN_DBTP_DSJW_VALUE 3 | ||
/* Data bit Time segment before sample point */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,10 @@ | |
// Function prototypes | ||
uint8_t get_pinstrap_id(void); | ||
inline float uint16ToC(uint16_t data); | ||
void flash_pinstrap_id(uint8_t pin_num); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While there is some benefit in using the LED for these diagnostic/error reporting codes, I think it's too specific of a usage to be included in the base code. Let's maybe drop this commit from this pull request, but definitely good use of the LED for your purposes! |
||
void flash_low(); | ||
void flash_high(); | ||
void quick_blink(); | ||
|
||
void configure_adc(void); | ||
void configure_can(void); | ||
|
@@ -49,6 +53,9 @@ uint8_t board_id = 255; | |
enum s2c_board_type board_type = S2C_BOARD_OTHER; | ||
struct s2c_board_config board_config; | ||
|
||
bool FLASH_BOARD_ID = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a resource constrained embedded system, every byte of flash or RAM is valuable. When statically configuring a behaviour, such as whether to flash the board ID or not, it's best to selectively include the code responsible for that feature, or to just not compile it in. You can do that with preprocessor macros. So:
And then later, instead of having an if statement around the code that implements this feature, you would have a conditional macro:
Now, if you need to turn this feature off, you simply set the macro to Obviously the firmware in this repo is not at all at the flash or RAM limit of the microcontroller, but it's good to have this mentality when working with embedded systems at any scale, because as your code becomes more and more complex, you will be sure that you're using your limited resources wisely. |
||
bool FLASH_CAN_ERROR = false; | ||
|
||
// ASF driver instances | ||
struct adc_module adc_instance; | ||
struct can_module can_instance; | ||
|
@@ -106,7 +113,61 @@ inline float uint16ToC(uint16_t data) { | |
return (float)data * 0.02 - 273.15; | ||
} | ||
|
||
/* | ||
Does a long blink on the user led | ||
Warning: 1000ms delay total | ||
*/ | ||
void flash_high(){ | ||
port_pin_set_output_level(LED_USER_PIN, true); | ||
delay_ms(600); | ||
port_pin_set_output_level(LED_USER_PIN, false); | ||
delay_ms(400); | ||
} | ||
|
||
/* | ||
does a short blink on the user led | ||
Warning: 500ms delay | ||
*/ | ||
void flash_low(){ | ||
port_pin_set_output_level(LED_USER_PIN, true); | ||
delay_ms(50); | ||
port_pin_set_output_level(LED_USER_PIN, false); | ||
delay_ms(450); | ||
} | ||
|
||
/* | ||
quick blink | ||
*/ | ||
void quick_blink(){ | ||
port_pin_toggle_output_level(LED_USER_PIN); | ||
delay_ms(30); | ||
port_pin_toggle_output_level(LED_USER_PIN); | ||
delay_ms(30); | ||
} | ||
|
||
/* | ||
flashes out the binary of the board ID | ||
Warning long delay | ||
*/ | ||
void flash_pinstrap_id(uint8_t pin_num){ | ||
int blink_amount = 5; | ||
for(int i =0; i <blink_amount; i++){ | ||
quick_blink(); | ||
} | ||
port_pin_set_output_level(LED_USER_PIN, false); | ||
delay_ms(1000); | ||
|
||
uint8_t temp_pin = pin_num; | ||
for(int i =0; i<4;i++){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to keep format consistent with the rest of the codebase: equal spacing between operators, spacing between open brace and statement/function signature |
||
if (temp_pin & 1) { | ||
flash_high(); | ||
} else { | ||
flash_low(); | ||
} | ||
temp_pin = temp_pin >> 1;//shift over | ||
} | ||
|
||
} | ||
|
||
// Configuration functions | ||
|
||
|
@@ -337,6 +398,10 @@ int main (void) | |
|
||
system_interrupt_enable_global(); | ||
|
||
if(FLASH_BOARD_ID){ | ||
flash_pinstrap_id(board_id); | ||
} | ||
|
||
// Turn on generic LED to indicate that config is done | ||
port_pin_set_output_level(LED_USER_PIN, true); | ||
|
||
|
@@ -366,5 +431,8 @@ void CAN0_Handler(void) | |
if ((status & CAN_PROTOCOL_ERROR_ARBITRATION) || (status & CAN_PROTOCOL_ERROR_DATA)) { | ||
can_clear_interrupt_status(&can_instance, CAN_PROTOCOL_ERROR_ARBITRATION | CAN_PROTOCOL_ERROR_DATA); | ||
//printf("Protocol error, please double check the clock in two boards. \r\n\r\n"); | ||
if(FLASH_CAN_ERROR){ | ||
quick_blink(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this comment. Value of 5 was a bug, no need to be reminded of that ;)