<commit_before>#ifdef __LPC17XX__

#include "canutil.h"
#include "signals.h"
#include "log.h"
#include "lpc17xx_can.h"
#include "lpc17xx_pinsel.h"

#define CAN_CTRL(BUS) (BUS == LPC_CAN1 ? 0 : 1)

CAN_ERROR configureFilters(CanBus* bus, CanFilter* filters, int filterCount) {
    debug("Configuring %d filters...", filterCount);
    CAN_ERROR result = CAN_OK;
    for(int i = 0; i < filterCount; i++) {
        result = CAN_LoadFullCANEntry(bus->controller, filters[i].value);
    }
    debug("Done.\r\n");
    return result;
}

void initializeCan(CanBus* bus) {
    queue_init(&bus->sendQueue);

    // TODO need to store pin configurations in the struct
    /* Pin configuration
     * CAN1: select P0.0 as RD1. P0.1 as TD1
     */
    PINSEL_CFG_Type PinCfg;
    PinCfg.Funcnum = 1;
    PinCfg.OpenDrain = 0;
    PinCfg.Pinmode = 0;
    PinCfg.Pinnum = 0;
    PinCfg.Portnum = 0;
    PINSEL_ConfigPin(&PinCfg);
    PinCfg.Pinnum = 1;
    PINSEL_ConfigPin(&PinCfg);

    // the bus is coming up as 0 in the struct for some reason<commit_msg>Add pin configuration for CAN2 on LPC1768.<commit_after>#ifdef __LPC17XX__

#include "canutil.h"
#include "signals.h"
#include "log.h"
#include "lpc17xx_can.h"
#include "lpc17xx_pinsel.h"

#define CAN_CTRL(BUS) (BUS == LPC_CAN1 ? 0 : 1)

// CAN1: select P0.0 as RD1. P0.1 as TD1
// CAN2: select P2.7 as RD2, P2.8 as RD2
#define CAN_RX_PIN_NUM(BUS) (BUS == LPC_CAN1 ? 0 : 7)
#define CAN_TX_PIN_NUM(BUS) (BUS == LPC_CAN1 ? 1 : 8)
#define CAN_PORT_NUM(BUS) (BUS == LPC_CAN1 ? 0 : 2)

CAN_ERROR configureFilters(CanBus* bus, CanFilter* filters, int filterCount) {
    debug("Configuring %d filters...", filterCount);
    CAN_ERROR result = CAN_OK;
    for(int i = 0; i < filterCount; i++) {
        result = CAN_LoadFullCANEntry(bus->controller, filters[i].value);
    }
    debug("Done.\r\n");
    return result;
}

void configureCanControllerPins(LPC_CAN_TypeDef* controller) {
    PINSEL_CFG_Type PinCfg;
    PinCfg.Funcnum = 1;
    PinCfg.OpenDrain = 0;
    PinCfg.Pinmode = 0;
    PinCfg.Pinnum = CAN_RX_PIN_NUM(controller);
    PinCfg.Portnum = CAN_PORT_NUM(controller);
    PINSEL_ConfigPin(&PinCfg);

    PinCfg.Pinnum = CAN_TX_PIN_NUM(controller);
    PINSEL_ConfigPin(&PinCfg);
}

void initializeCan(CanBus* bus) {
    queue_init(&bus->sendQueue);

    configureCanControllerPins(bus->controller);

    // the bus is coming up as 0 in the struct for some reason
{'fraction_non_alphanumeric': 0.12821576763485476, 'fraction_numerical': 0.027385892116182572, 'mean_word_length': 3.6187739463601534, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1968076', 'n_tokens_mistral': 940, 'n_tokens_neox': 896, 'n_words': 216}